2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <device/pci_ids.h>
26 #include "rs780_rev.h"
28 #define NBMISC_INDEX 0x60
29 #define NBHTIU_INDEX 0x94
30 #define NBMC_INDEX 0xE8
31 #define NBPCIE_INDEX 0xE0
32 #define EXT_CONF_BASE_ADDRESS 0xE0000000
33 #define TEMP_MMIO_BASE_ADDRESS 0xC0000000
35 #define get_nb_rev(dev) pci_read_config8((dev), 0x89)
37 typedef struct __PCIE_CFG__ {
45 u8 PortHp; /* hot plug */
57 /* The Integrated Info Table */
62 typedef struct _ATOM_COMMON_TABLE_HEADER
64 USHORT usStructureSize;
65 UCHAR ucTableFormatRevision;
66 UCHAR ucTableContentRevision;
67 }ATOM_COMMON_TABLE_HEADER;
69 typedef struct _ATOM_INTEGRATED_SYSTEM_INFO_V2
71 ATOM_COMMON_TABLE_HEADER sHeader;
72 ULONG ulBootUpEngineClock; //in 10kHz unit
73 ULONG ulReserved1[2]; //must be 0x0 for the reserved
74 ULONG ulBootUpUMAClock; //in 10kHz unit
75 ULONG ulBootUpSidePortClock; //in 10kHz unit
76 ULONG ulMinSidePortClock; //in 10kHz unit
77 ULONG ulReserved2[6]; //must be 0x0 for the reserved
79 //[0]=1: PowerExpress mode
80 // =0 Non-PowerExpress mode;
81 //[1]=1: system boots up at AMD overdrived state or user customized mode. In this case, driver will disable other power state in VBIOS table.
82 // =0: system boots up at driver control state. Power state depends on VBIOS PP table.
83 //[2]=1: PWM method is used on NB voltage control.
84 // =0: GPIO method is used.
85 //[3]=1: Only one power state(Performance) will be supported.
86 // =0: Number of power states supported is from VBIOS PP table.
87 //[4]=1: CLMC is supported and enabled on current system.
88 // =0: CLMC is not supported or enabled on current system. SBIOS need to support HT link/freq change through ATIF interface.
89 //[5]=1: Enable CDLW for all driver control power states. Max HT width is from SBIOS, while Min HT width is determined by display requirement.
90 // =0: CDLW is disabled. If CLMC is enabled case, Min HT width will be set equal to Max HT width. If CLMC disabled case, Max HT width will be applied.
91 //[6]=1: High Voltage requested for all power states. In this case, voltage will be forced at 1.1v and VBIOS PP table voltage drop/throttling request will be ignored.
92 // =0: Voltage settings is determined by VBIOS PP table.
93 //[7]=1: Enable CLMC Hybird Mode. CDLD and CILR will be disabled in this case and we're using legacy C1E. This is workaround for CPU(Griffin) performance issue.
94 // =0: Enable regular CLMC mode, CDLD and CILR will be enabled.
95 //[8]=1: CDLF is supported and enabled by fuse //CHP 914
96 // =0: CDLF is not supported and not enabled by fuses
97 ULONG ulBootUpReqDisplayVector;
98 ULONG ulOtherDisplayMisc;
99 ULONG ulDDISlot1Config;
100 ULONG ulDDISlot2Config;
101 UCHAR ucMemoryType; //[3:0]=1:DDR1;=2:DDR2;=3:DDR3.[7:4] is reserved
102 UCHAR ucUMAChannelNumber;
103 UCHAR ucDockingPinBit;
104 UCHAR ucDockingPinPolarity;
105 ULONG ulDockingPinCFGInfo;
107 USHORT usNumberOfCyclesInPeriod; //usNumberOfCyclesInPeriod[15] = 0 - invert waveform
108 // 1 - non inverted waveform
109 USHORT usMaxNBVoltage;
110 USHORT usMinNBVoltage;
111 USHORT usBootUpNBVoltage;
112 ULONG ulHTLinkFreq; //in 10Khz
113 USHORT usMinHTLinkWidth; // if no CLMC, usMinHTLinkWidth should be equal to usMaxHTLinkWidth??
114 USHORT usMaxHTLinkWidth;
115 USHORT usUMASyncStartDelay; // will be same as usK8SyncStartDelay on RS690
116 USHORT usUMADataReturnTime; // will be same as usK8DataReturnTime on RS690
117 USHORT usLinkStatusZeroTime;
119 ULONG ulHighVoltageHTLinkFreq; // in 10Khz
120 ULONG ulLowVoltageHTLinkFreq; // in 10Khz
121 USHORT usMaxUpStreamHTLinkWidth;
122 USHORT usMaxDownStreamHTLinkWidth;
123 USHORT usMinUpStreamHTLinkWidth;
124 USHORT usMinDownStreamHTLinkWidth;
125 ULONG ulReserved3[97]; //must be 0x0
126 } ATOM_INTEGRATED_SYSTEM_INFO_V2;
128 /* PCIE config flags */
129 #define PCIE_DUALSLOT_CONFIG (1 << 0)
130 #define PCIE_OVERCLOCK_ENABLE (1 << 1)
131 #define PCIE_GPP_CLK_GATING (1 << 2)
132 #define PCIE_ENABLE_STATIC_DEV_REMAP (1 << 3)
133 #define PCIE_OFF_UNUSED_GFX_LANES (1 << 4)
134 #define PCIE_OFF_UNUSED_GPP_LANES (1 << 5)
135 #define PCIE_DISABLE_HIDE_UNUSED_PORTS (1 << 7)
136 #define PCIE_GFX_CLK_GATING (1 << 11)
137 #define PCIE_GFX_COMPLIANCE (1 << 14)
138 #define PCIE_GPP_COMPLIANCE (1 << 15)
140 /* -------------------- ----------------------
142 ------------------- -----------------------*/
143 #define PCIE_LINK_CFG 0x8
144 #define PCIE_NBCFG_REG7 0x37
145 #define STRAPS_OUTPUT_MUX_7 0x67
146 #define STRAPS_OUTPUT_MUX_A 0x6a
148 /* -------------------- ----------------------
150 ------------------- -----------------------*/
151 #define PCIE_CI_CNTL 0x20
152 #define PCIE_LC_LINK_WIDTH 0xa2
153 #define PCIE_LC_STATE0 0xa5
154 #define PCIE_VC0_RESOURCE_STATUS 0x12a /* 16bit read only */
156 #define PCIE_CORE_INDEX_GFX (0x00 << 16) /* see 5.2.2 */
157 #define PCIE_CORE_INDEX_GPPSB (0x01 << 16)
158 #define PCIE_CORE_INDEX_GPP (0x02 << 16)
159 #define PCIE_CORE_INDEX_BRDCST (0x03 << 16)
161 /* contents of PCIE_NBCFG_REG7 */
162 #define RECONFIG_GPPSB_EN (1 << 12)
163 #define RECONFIG_GPPSB_GPPSB (1 << 14)
164 #define RECONFIG_GPPSB_LINK_CONFIG (1 << 15)
165 #define RECONFIG_GPPSB_ATOMIC_RESET (1 << 17)
167 /* contents of PCIE_VC0_RESOURCE_STATUS */
168 #define VC_NEGOTIATION_PENDING (1 << 1)
170 #define LC_STATE_RECONFIG_GPPSB 0x10
172 /* ------------------------------------------------
174 * ------------------------------------------------- */
175 extern PCIE_CFG AtiPcieCfg;
177 /* ----------------- export funtions ----------------- */
178 u32 nbmisc_read_index(device_t nb_dev, u32 index);
179 void nbmisc_write_index(device_t nb_dev, u32 index, u32 data);
180 u32 nbpcie_p_read_index(device_t dev, u32 index);
181 void nbpcie_p_write_index(device_t dev, u32 index, u32 data);
182 u32 nbpcie_ind_read_index(device_t nb_dev, u32 index);
183 void nbpcie_ind_write_index(device_t nb_dev, u32 index, u32 data);
184 u32 htiu_read_index(device_t nb_dev, u32 index);
185 void htiu_write_index(device_t nb_dev, u32 index, u32 data);
186 u32 nbmc_read_index(device_t nb_dev, u32 index);
187 void nbmc_write_index(device_t nb_dev, u32 index, u32 data);
189 u32 pci_ext_read_config32(device_t nb_dev, device_t dev, u32 reg);
190 void pci_ext_write_config32(device_t nb_dev, device_t dev, u32 reg, u32 mask, u32 val);
192 void set_nbcfg_enable_bits(device_t nb_dev, u32 reg_pos, u32 mask, u32 val);
193 void set_nbcfg_enable_bits_8(device_t nb_dev, u32 reg_pos, u8 mask, u8 val);
194 void set_nbmc_enable_bits(device_t nb_dev, u32 reg_pos, u32 mask, u32 val);
195 void set_htiu_enable_bits(device_t nb_dev, u32 reg_pos, u32 mask, u32 val);
196 void set_nbmisc_enable_bits(device_t nb_dev, u32 reg_pos, u32 mask, u32 val);
197 void set_pcie_enable_bits(device_t dev, u32 reg_pos, u32 mask, u32 val);
198 void rs780_set_tom(device_t nb_dev);
200 void ProgK8TempMmioBase(u8 in_out, u32 pcie_base_add, u32 mmio_base_add);
201 void enable_pcie_bar3(device_t nb_dev);
202 void disable_pcie_bar3(device_t nb_dev);
204 void rs780_enable(device_t dev);
205 void rs780_gpp_sb_init(device_t nb_dev, device_t dev, u32 port);
206 void rs780_gfx_init(device_t nb_dev, device_t dev, u32 port);
207 void avoid_lpc_dma_deadlock(device_t nb_dev, device_t sb_dev);
208 void config_gpp_core(device_t nb_dev, device_t sb_dev);
209 void PcieReleasePortTraining(device_t nb_dev, device_t dev, u32 port);
210 u8 PcieTrainPort(device_t nb_dev, device_t dev, u32 port);
211 u32 extractbit(u32 data, int bit_number);
212 u32 extractbits(u32 source, int lsb, int msb);
213 int cpuidFamily(void);
214 int is_family0Fh(void);
215 int is_family10h(void);