1 /*****************************************************************************
3 * Copyright (C) 2012 Advanced Micro Devices, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ***************************************************************************/
35 REG8MASK sbEarlyPostByteInitTable[]={
36 // SMBUS Device(Bus 0, Dev 20, Func 0)
37 {0x00, SMBUS_BUS_DEV_FUN, 0},
38 {SB_SMBUS_REG43, ~(UINT8)BIT3, 0x00}, //Make BAR registers of smbus visible.
39 {SB_SMBUS_REG24, 0X00, (CIMx_Version & 0xFF)}, //Program the version information
40 {SB_SMBUS_REG24+1, 0x00, (CIMx_Version >> 8)},
41 {SB_SMBUS_REG24+2, 0x00, RC_Information},
42 {SB_SMBUS_REG24+3, 0x00, Additional_Changes_Indicator},
43 {SB_SMBUS_REG43, ~(UINT8)BIT3, BIT3}, //Make BAR registers of smbus invisible.
44 {SB_SMBUS_REGAE, ~(UINT8)(BIT6 + BIT5), BIT6 + BIT5}, //Disable Timer IRQ enhancement for proper operation of the 8254 timer.
45 // [6] - IoApicPicArbEn, set 1 to enable arbiter between APIC and PIC interrupts
46 {SB_SMBUS_REGAD, ~(UINT8)(BIT0+BIT1+BIT2+BIT4), BIT0+BIT3}, // Initialize SATA to default values, SATA Enabled,
47 // Combined mode enabled, SATA as primary, power saving enable
48 {SB_SMBUS_REGAF, 0xE3, 6 << 2}, // Set SATA Interrupt to INTG#
49 {SB_SMBUS_REG68, BIT3, 0 }, // First disable all usb controllers and then enable then according to setup selection
52 // IDE Device(Bus 0, Dev 20, Func 1)
53 {0x00, IDE_BUS_DEV_FUN, 0},
54 {SB_IDE_REG62+1, ~(UINT8)BIT0, BIT5}, // Enabling IDE Explicit Pre-Fetch IDE PCI Config 0x62[8]=0
55 // Allow MSI capability of IDE controller to be visible. IDE PCI Config 0x62[13]=1
58 // Azalia Device(Bus 0, Dev 20, Func 2)
59 {0x00, AZALIA_BUS_DEV_FUN, 0},
60 {SB_AZ_REG4C, ~(UINT8)BIT0, BIT0},
63 // LPC Device(Bus 0, Dev 20, Func 3)
64 {0x00, LPC_BUS_DEV_FUN, 0},
66 {SB_LPC_REG40, ~(UINT8)BIT2, BIT2}, // Enabling LPC DMA Function 0x40[2]
67 {SB_LPC_REG78, ~(UINT8)BIT1, 00}, // Disables MSI capability
70 // P2P Bridge(Bus 0, Dev 20, Func 4)
71 {0x00, SBP2P_BUS_DEV_FUN, 0},
73 {SB_P2P_REG64+1, 0xFF, BIT7+BIT6}, //Adjusting CLKRUN#, PCIB_PCI_Config 0x64[15]=01
74 //Enabling arbiter fix, PCIB_PCI_Config 0x64[14]=01
75 {SB_P2P_REG64+2, 0xFF, BIT4}, //Enabling One-Prefetch-Channel Mode, PCIB_PCI_config 0x64 [20]
77 {SB_P2P_REG0D, 0x00, 0x40}, //Setting Latency Timers to 0x40, Enables the PCIB to retain ownership
78 {SB_P2P_REG1B, 0x00, 0x40}, // of the bus on the Primary side and on the Secondary side when GNT# is deasserted.
82 // SATA Device(Bus 0, Dev 17, Func 0)
83 {0x00, SATA_BUS_DEV_FUN, 0},
84 {SB_SATA_REG44, 0xff, BIT0}, // Enables the SATA watchdog timer register prior to the SATA BIOS post
85 {SB_SATA_REG40+3, 0xff, BIT5}, // RPR setting: Disable the testing/enhancement mode SATA_PCI_config 0x40 [29] = 1
86 {SB_SATA_REG48+2, 0xff, BIT5}, // RPR setting: Disable the testing/enhancement mode SATA_PCI_config 0x48 [24] = 1, [21] = 1
87 {SB_SATA_REG48+3, 0xff, BIT0},
88 {SB_SATA_REG44 + 2, 0, 0x10}, // Program watchdog timer with 16 retries before timer time-out.
93 REG8MASK sbEarlyPostPmioInitTbl[]={
94 // index andmask ormask
95 {SB_PMIO_REG55, ~(UINT8)(BIT3+BIT4+BIT5), BIT5+BIT3}, //BIT3(PcieNative)=1b, BIT4(Pcie_Wak_Mask)=0b, BIT5(Pcie_WAK_Sci)=1b
96 {SB_PMIO_REG01, 0xff, BIT1},
97 {SB_PMIO_REG0E, 0xff, BIT2 + BIT3},
98 {SB_PMIO_REG10, 0x3E, (BIT6+BIT5+BIT3+BIT1)}, // RTC_En_En + TMR_En_En + GLB_EN_EN and clear EOS_EN + PciExpWakeDisEn
99 {SB_PMIO_REG61, 0xFF, 0x40}, // USB Device Support to Wakeup System from S3/S4 state, USB PME & PCI Act from NB
100 {SB_PMIO_REG59, 0xFC, 0x00 }, // Clear the flash controller bits BIT1:0
101 {SB_PMIO_REG01, 0xFF, 0x97 }, // Clear all the status
102 {SB_PMIO_REG05, 0xFF, 0xFF },
103 {SB_PMIO_REG06, 0xFF, 0xFF },
104 {SB_PMIO_REG07, 0xFF, 0xFF },
105 {SB_PMIO_REG0F, 0xFF, 0x1F },
106 {SB_PMIO_REG1D, 0xFF, 0xFF },
107 {SB_PMIO_REG39, 0xFF, 0xFF },
108 {SB_PMIO_REG7C, ~(UINT8)(BIT5+BIT3+BIT2), BIT3+BIT2}, //Turn on BLink LED
109 {SB_PMIO_REG67, 0xFF, 0x06}, // C State enable, must be set in order to exercise C state
110 {SB_PMIO_REG68, 0x38, 0x84},
111 {SB_PMIO_REG8D, 0xFF, 0x01}, // Set PM_Reg_0x8D[0] to enable PmeTurnOff/PmeMsgAck handshake to fix PCIE LAN S3/S4 wake failure
112 {SB_PMIO_REG84, 0xFD, BIT3+BIT0},
113 {SB_PMIO_REG53, 0xFF, BIT7+BIT6}, //ACPI System Clock setting, PMIO Reg 0x53[6]=1. Our reference clock
114 //is either 25 or 100Mhz and so the default acpi clock is actually
115 //running at 12.5Mhz and so the system time will run slow. We have
116 //generated another internal clock which runs at 14.318Mhz which is the
117 //correct frequency. We should set this bit to turn on this feature PMIO_REG53[6]=1
118 //PCI Clock Period, PM_IO 0x53 [7] = 1. By setting this, PCI clock period
119 //increase to 30.8 ns.
120 {SB_PMIO_REG95, ~(UINT8)(BIT2+BIT1+BIT0), BIT2+BIT1}, //USB Advanced Sleep Control, Enables USB EHCI controller
121 //to sleep for 6 uframes in stead of the standard 10us to
122 //improve power saving.
123 {SB_PMIO_REGD7, 0xFF, BIT6+BIT1},
128 // commonInitEarlyBoot - set /SMBUS/ACPI/IDE/LPC/PCIB. This settings should be done during S3 resume also
129 void commonInitEarlyBoot(AMDSBCFG* pConfig) {
132 CPUID_DATA CpuId_Brand;
135 UINT8 Family, Model, Stepping;
137 TRACE((DMSG_SB_TRACE, "CIMx - Entering commonInitEarlyBoot \n"));
138 CpuidRead (0x01, &CpuId);
139 CpuidRead (0x80000001, &CpuId_Brand); //BrandID
141 //Early post initialization of pci config space
142 programPciByteTable( (REG8MASK*)FIXUP_PTR(&sbEarlyPostByteInitTable[0]), sizeof(sbEarlyPostByteInitTable)/sizeof(REG8MASK) );
144 // RPR 5.5 Clear PM_IO 0x65[4] UsbResetByPciRstEnable, Set this bit so that usb gets reset whenever there is PCIRST.
145 RWPMIO(SB_PMIO_REG65, AccWidthUint8 | S3_SAVE, ~(UINT32)BIT4, BIT4);
148 #if 0 //KZ [083011]-It's used wrong BIOS SIZE for Coreboot.
149 //For being compatible with earlier revision, check whether ROM decoding is changed already outside CIMx before
151 ReadPCI((LPC_BUS_DEV_FUN << 16) + SB_LPC_REG68, AccWidthUint16 | S3_SAVE, &dwTempVar);
152 if ( (dwTempVar == 0x08) || (dwTempVar == 0x00))
153 RWPCI((LPC_BUS_DEV_FUN << 16) + SB_LPC_REG68, AccWidthUint8 | S3_SAVE, 0, 0x0E);// Change the 1Mb below ROM decoding range to 0xE0000 to 0xFFFFF
156 if (pConfig->AzaliaController == 1)
157 RWPMIO(SB_PMIO_REG59, AccWidthUint8 | S3_SAVE, ~(UINT32)BIT3, 0);
159 RWPMIO(SB_PMIO_REG59, AccWidthUint8 | S3_SAVE, 0xFF, BIT3);
161 //Disable or Enable PCI Clks based on input
162 RWPCI((SBP2P_BUS_DEV_FUN << 16) + SB_P2P_REG42, AccWidthUint8 | S3_SAVE, ~(UINT32)(BIT5+BIT4+BIT3+BIT2), ((pConfig->PciClks) & 0x0F) << 2 );
163 RWPCI((SBP2P_BUS_DEV_FUN << 16) + SB_P2P_REG4A, AccWidthUint8 | S3_SAVE, ~(UINT32)(BIT1+BIT0), ((pConfig->PciClks) >> 4) | ((pConfig->PciClk5) << 1) );
164 ReadPMIO(SB_PMIO_REG2C, AccWidthUint16, &dwTempVar); // Read Arbiter address, Arbiter address is in PMIO 2Ch
165 RWIO(dwTempVar, AccWidthUint8, 0, 0); // Write 0 to enable the arbiter
167 abLinkInitBeforePciEnum(pConfig); // Set ABCFG registers
168 // Set LDTSTP# duration to 10us for HydraD CPU model 8, 9 or A; or when HT link is 200MHz; or Family15 Orochi CPU C32/G34 package
169 ddValue = CpuId.REG_EAX & 0x00FF00F0;
172 if((CpuId.REG_EAX & 0x00F00F00) == 0x00600F00) {
173 if(((CpuId_Brand.REG_EBX & 0xF0000000) == 0x30000000) || ((CpuId_Brand.REG_EBX & 0xF0000000) == 0x50000000)) {
174 //Orochi processor G34/C32, set to 10us
178 // Orochi processor AM3, set to 5us
183 if ((pConfig->AnyHT200MhzLink) || (ddValue == 0x100080) || (ddValue == 0x100090) || (ddValue == 0x1000A0)) {
184 //any kind of CPU run HT at 200Mhz , or HydraD CPU model 8, 9 or A, set to 10us
189 RWPMIO(SB_PMIO_REG8B, AccWidthUint8 | S3_SAVE, 0x00, dbValue);
191 // Enable/Disable watchdog timer
192 RWPMIO(SB_PMIO_REG69, AccWidthUint8 | S3_SAVE, ~(UINT32)BIT0, (UINT8)(!pConfig->WatchDogTimerEnable));
194 // Per SB700/SP5100 RPR 2.5
196 // Enable C1e stutter timer for any system with chip revision >= A14
197 // Set SMBUS:0x5c[22:16] = 16 -- Set amount of idle time to 16ms
200 if (getRevisionID() >= SB700_A14) {
203 // Set PMIO:0xcb[5] = 1 -- AutoStutterTimerEn, set 1 to enable
204 // Set PMIO:0xcb[6] = 1 -- AutoStutterTimeSel, 1=1ms timer tick increment; 0=2us increment
205 RWPMIO(SB_PMIO_REGCB, AccWidthUint8 | S3_SAVE, 0xff, BIT6 + BIT5);
207 Family = (UINT8)((CpuId.REG_EAX & 0x00ff0000)>> 16);
208 Model = (UINT8)((CpuId.REG_EAX & 0x000000f0)>> 4);
209 Stepping = (UINT8) (CpuId.REG_EAX & 0x0000000f);
211 // For Server system (SP5100) with CPU type = Family 10h with LS2 mode enabled:
212 // Model=6 && Stepping=2 || Model=(4I5|6) && Stepping >=3 || Model=(8|9) && Stepping >= 1 || Model Ah
213 // Set SMBUS:0x5c[22:16] = 20 -- Set amount of idle time to 20ms
214 if (IsLs2Mode() && (Family == 0x10)) {
218 if( Stepping >= 3 ) dwTempVar = 0x14;
221 if( Stepping >= 2 ) dwTempVar = 0x14;
224 if( Stepping >= 1 ) dwTempVar = 0x14;
227 if( Stepping >= 1 ) dwTempVar = 0x14;
234 // Set SMBUS:0x5c[7] = 1 -- CheckC3, set 1 to check for C3 state
235 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG5C, AccWidthUint32 | S3_SAVE, ~(0x7F << 16), (dwTempVar << 16) + BIT7);
238 //Message-Triggered C1E is not supported in Family 10h G34r1 HY-D0 (0x00100F90) and Family 10h C32 HY-D0 (0x00100F80) processor.
239 ddValue = CpuId.REG_EAX;
240 if ((getRevisionID() == SB700_A15) && (pConfig->MTC1e == CIMX_OPTION_ENABLED) && (ddValue != 0x00100F90) && (ddValue != 0x00100F80)) {
242 // MTC1e: For A15 (server only) - The settings here borrow the existing legacy ACPI BM_STS and BM_RLD bits as a
243 // mechanism to break out from C1e under a non-OS controlled C3 state. Under this scheme, the logic will automatically
244 // clear the BM_STS bit whenever it enters C1e state. Whenever BM_REQ#/IDLE_EXIT# is detected, it will cause the
245 // BM_STS bit to be set and therefore causing the C state logic to exit.
247 // Set BMReqEnable (SMBUS:0x64[5]=1) to enable the pin as BM_REQ#/IDLE_EXIT# to the C state logic
248 // Set CheckOwnReq (SMBUS:0x64[4]=0) to force IDLE_EXIT# to set BM_STS and wake from C3
249 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG64, AccWidthUint8 | S3_SAVE, 0xEF, BIT5);
251 // Set PCI_Active_enable (PMIO:0x61[2]=1), the secondary enable bit for SB to monitor BM_REQ#/IDLE_EXIT#
252 RWPMIO(SB_PMIO_REG61, AccWidthUint8 | S3_SAVE, 0xff, BIT2);
254 // Set auto_bm_rld (PMIO:0x9a[4]=1) so that assertion on BM_REQ#/IDLE_EXIT# pin will cause C state logic to break out from C1e
255 // Set auto_clr_bm_sts (PMIO:0x9a[5]=1) will cause the C state logic to automatically clear the BM_STS bit whenever it sees a C1e entry
256 RWPMIO(SB_PMIO_REG9A, AccWidthUint8 | S3_SAVE, 0xff, BIT5 + BIT4);
259 // MTC1e: The logic basically counts the number of HALT_ENTER messages. When it has received the number of HALT_ENTER
260 // messages equal to NumOfCpu (PMIO:0xc9[3:0]), it will generate an internal C1e command to the C state logic.
261 // The count increments when it sees HALT_ENTER message after it has generated the C1e command, and it treats the
262 // HALT_EXIT message as a break event.
265 RWPMIO(SB_PMIO_REGBB, AccWidthUint8 | S3_SAVE, 0xFF, BIT7);
267 // Enable counting HALT
268 // PMIO:0xc9[4] = CountHaltMsgEn
269 // PMIO:0xc9[3:0] = NumOfCpu, set to 1 since CPU logic will coordinate among cores and only generate one HALT message
270 RWPMIO(SB_PMIO_REGC9, AccWidthUint8 | S3_SAVE, 0xE0, BIT4 + 1);
273 c3PopupSetting(pConfig);
275 TRACE((DMSG_SB_TRACE, "CIMx - Exiting commonInitEarlyBoot \n"));
279 void commonInitEarlyPost(AMDSBCFG* pConfig){
280 //early post initialization of pmio space
281 programPmioByteTable( (REG8MASK *)FIXUP_PTR(&sbEarlyPostPmioInitTbl[0]), (sizeof(sbEarlyPostPmioInitTbl)/sizeof(REG8MASK)) );
282 CallBackToOEM(PULL_UP_PULL_DOWN_SETTINGS, NULL, pConfig);
286 // AB-Link Configuration Table
287 ABTBLENTRY abTblEntry600[]={
288 // Enabling Downstream Posted Transactions to Pass Non-Posted Transactions for the K8 Platform ABCFG 0x10090[8] = 1
289 // ABCFG 0x10090 [16] = 1, ensures the SMI# message to be sent before the IO command is completed. The ordering of
290 // SMI# and IO is important for the IO trap to work properly.
291 {ABCFG,SB_AB_REG10090 ,BIT16+BIT8 ,BIT16+BIT8 },
292 // Enabling UpStream DMA Access AXCFG: 0x04[2]=1
293 {AXCFG,SB_AB_REG04 ,BIT2 ,BIT2 },
294 // Setting B-Link Prefetch Mode ABCFG 0x80 [17] = 1 ABCFG 0x80 [18] = 1
295 {ABCFG,SB_AB_REG80 ,BIT17+BIT18 ,BIT17+BIT18 },
296 // Disable B-Link client's credit variable in downstream arbitration equation (for All Revisions)
297 // ABCFG 0x9C[0] = 1 Disable credit variable in downstream arbitration equation
298 // Enabling Additional Address Bits Checking in Downstream Register Programming
300 {ABCFG,SB_AB_REG9C ,BIT8+BIT1+BIT0 ,BIT8+BIT1+BIT0 },
301 // Enabling IDE/PCIB Prefetch for Performance Enhancement
302 // IDE prefetch ABCFG 0x10060 [17] = 1 ABCFG 0x10064 [17] = 1
303 // PCIB prefetch ABCFG 0x10060 [20] = 1 ABCFG 0x10064 [20] = 1
304 {ABCFG,SB_AB_REG10060 ,BIT17+BIT20 ,BIT17+BIT20 }, // IDE+PCIB prefetch enable
305 {ABCFG,SB_AB_REG10064 ,BIT17+BIT20 ,BIT17+BIT20 }, // IDE+PCIB prefetch enable
306 // Enabling Detection of Upstream Interrupts ABCFG 0x94 [20] = 1
307 // ABCFG 0x94 [19:0] = cpu interrupt delivery address [39:20]
308 {ABCFG,SB_AB_REG94 ,BIT20 ,BIT20+0x00FEE },
309 // Programming cycle delay for AB and BIF clock gating
310 // Enabling AB and BIF Clock Gating
311 // Enabling AB Int_Arbiter Enhancement
312 // Enabling Requester ID
313 {ABCFG,SB_AB_REG10054, 0x00FFFFFF , 0x010407FF },
314 {ABCFG,SB_AB_REG98 , 0xFFFF00FF , 0x00014700 }, // Enable the requestor ID for upstream traffic ABCFG 0x98[16]=1
315 // {ABCFG,SB_AB_REG54 , 0x00FF0000 , 0x01040000 },
316 {ABCFG,SB_AB_REG54 , 0x00FF0000 , 0x00040000 },
318 {ABCFG,0,0,-1}, // This dummy entry is to clear ab index
323 // AB-Link Configuration Table
324 ABTBLENTRY abTblForA15[]={
327 {ABCFG, SB_AB_REG90 ,BIT21 , BIT21 },
328 {ABCFG, SB_AB_REG9C ,BIT15+BIT9+BIT5 ,BIT15+BIT9+BIT5},
330 //Posted pass NP Downstream feature
331 {AX_INDXC, SB_AB_REG02, BIT9 ,BIT9 },
332 {ABCFG, SB_AB_REG9C, BIT14+BIT13+BIT12+BIT11+BIT10+BIT7+BIT6 , BIT14+BIT13+BIT12+BIT11+BIT10+BIT7+BIT6},
333 {ABCFG, SB_AB_REG1009C, BIT5+BIT4 , BIT5+BIT4},
335 //Posted pass NP upstream feature
336 {ABCFG, SB_AB_REG58, BIT15+BIT14+BIT13+BIT12+BIT11, BIT15+BIT14+BIT13+BIT11},
338 //64 bit Non-posted memory write support
339 {AX_INDXC, SB_AB_REG02, BIT10 ,BIT10 },
341 {ABCFG, SB_AB_REG10090, BIT12+BIT11+BIT10+BIT9 , BIT12+BIT11+BIT10+BIT9},
343 {ABCFG,0,0,-1}, // This dummy entry is to clear ab index
348 // abLinkInitBeforePciEnum - Set ABCFG registers
349 void abLinkInitBeforePciEnum(AMDSBCFG* pConfig){
350 ABTBLENTRY *pAbTblPtr;
352 // disable PMIO decoding when AB is set
353 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG64, AccWidthUint8 | S3_SAVE, ~(UINT32)BIT2, 0);
355 pAbTblPtr = (ABTBLENTRY *)FIXUP_PTR(&abTblEntry600[0]);
358 if (getRevisionID() > SB700_A11){
359 //Enable OHCI Prefetch
360 writeAlink( (SB_AB_REG80 | (ABCFG << 30)), (readAlink((SB_AB_REG80 | (ABCFG << 30)))) | BIT0);
361 //Register bit to maintain correct ordering of SMI and IO write completion
362 writeAlink( (SB_AB_REG8C | (ABCFG << 30)), (readAlink((SB_AB_REG8C | (ABCFG << 30)))) | BIT8);
365 if (getRevisionID() >= SB700_A14){
366 //Enable fix for TT SB01345
367 writeAlink( (SB_AB_REG90 | (ABCFG << 30)), (readAlink((SB_AB_REG90 | (ABCFG << 30)))) | BIT17);
368 //Disable IO Write and SMI ordering enhancement
369 writeAlink( (SB_AB_REG9C | (ABCFG << 30)), (readAlink((SB_AB_REG9C | (ABCFG << 30)))) & (0xFFFFFEFF));
372 if (getRevisionID() >= SB700_A15) {
373 pAbTblPtr = (ABTBLENTRY *)FIXUP_PTR(&abTblForA15[0]);
378 // enable pmio decoding after ab is configured
379 // or BYTE PTR es:[ebp+SMBUS_BUS_DEV_FUN shl 12 + SB_SMBUS_REG64], BIT2
380 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG64, AccWidthUint8 | S3_SAVE, ~(UINT32)BIT2, BIT2);
384 void abcfgTbl(ABTBLENTRY* pABTbl){
387 while ((pABTbl->regType) != 0xFF){
388 TRACE((DMSG_SB_TRACE, "RegType: %X, RegNumber:%X, AndMask=%X, OrMask=%X \n",pABTbl->regType , pABTbl->regIndex, pABTbl->regMask, pABTbl->regData));
389 if (pABTbl->regType > AX_INDXP){
390 ddValue = pABTbl->regIndex | (pABTbl->regType << 30);
391 writeAlink(ddValue, ((readAlink(ddValue)) & (0xFFFFFFFF^(pABTbl->regMask)))|pABTbl->regData);
394 ddValue = 0x30 | (pABTbl->regType << 30);
395 writeAlink(ddValue, pABTbl->regIndex);
396 ddValue = 0x34 | (pABTbl->regType << 30);
397 writeAlink(ddValue, ((readAlink(ddValue)) & (0xFFFFFFFF^(pABTbl->regMask)))|pABTbl->regData);
402 //Clear ALink Access Index
404 WriteIO(ALINK_ACCESS_INDEX, AccWidthUint32 | S3_SAVE, &ddValue);
405 TRACE((DMSG_SB_TRACE, "Exiting abcfgTbl\n"));
409 // programSubSystemIDs - Config Subsystem ID for all SB devices.
410 void programSubSystemIDs(AMDSBCFG* pConfig, BUILDPARAM *pStaticOptions){
414 RWPCI((USB1_OHCI0_BUS_DEV_FUN << 16) + SB_OHCI_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->Ohci0Ssid);
415 RWPCI((USB1_OHCI1_BUS_DEV_FUN << 16) + SB_OHCI_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->Ohci1Ssid);
416 RWPCI((USB2_OHCI0_BUS_DEV_FUN << 16) + SB_OHCI_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->Ohci2Ssid);
417 RWPCI((USB2_OHCI1_BUS_DEV_FUN << 16) + SB_OHCI_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->Ohci3Ssid);
418 RWPCI((USB3_OHCI_BUS_DEV_FUN << 16) + SB_OHCI_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->Ohci4Ssid);
420 RWPCI((USB1_EHCI_BUS_DEV_FUN << 16) + SB_EHCI_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->Ehci0Ssid);
421 RWPCI((USB2_EHCI_BUS_DEV_FUN << 16) + SB_EHCI_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->Ehci1Ssid);
423 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->SmbusSsid);
424 RWPCI((IDE_BUS_DEV_FUN << 16) + SB_IDE_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->IdeSsid);
425 RWPCI((LPC_BUS_DEV_FUN << 16) + SB_LPC_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->LpcSsid);
426 RWPCI((AZALIA_BUS_DEV_FUN << 16) + SB_AZ_REG2C, AccWidthUint32 | S3_SAVE, 0x00, pStaticOptions->AzaliaSsid);
428 ddTempVar = pStaticOptions->SataIDESsid;
429 if ( ((pConfig->SataClass) == AHCI_MODE) || ((pConfig->SataClass)== IDE_TO_AHCI_MODE) )
430 ddTempVar = pStaticOptions->SataAHCISsid;
432 ReadPCI(((SATA_BUS_DEV_FUN << 16) + SB_SATA_REG02), AccWidthUint16 | S3_SAVE, &dwDeviceId);
433 if ((pConfig->SataClass) == RAID_MODE){
434 ddTempVar = pStaticOptions->SataRAIDSsid;
435 if (dwDeviceId==SB750_SATA_DEFAULT_DEVICE_ID)
436 ddTempVar = pStaticOptions->SataRAID5Ssid;
439 if ( ((pConfig->SataClass) == AMD_AHCI_MODE) || ((pConfig->SataClass) == IDE_TO_AMD_AHCI_MODE) ) {
440 ddTempVar = pStaticOptions->SataAHCISsid;
442 RWPCI((SATA_BUS_DEV_FUN << 16) + SB_SATA_REG2C, AccWidthUint32 | S3_SAVE, 0x00, ddTempVar);
445 void commonInitLateBoot(AMDSBCFG* pConfig){
449 // We need to do the following setting in late post also because some bios core pci enumeration changes these values
450 // programmed during early post.
451 // RPR 4.5 Master Latency Timer
452 // Master Latency Timer PCIB_PCI_config 0x0D/0x1B = 0x40
453 // Enables the PCIB to retain ownership of the bus on the
454 // Primary side and on the Secondary side when GNT# is deasserted.
455 //mov BYTE PTR es:[ebp+SBP2P_BUS_DEV_FUN shl 12 + SB_P2P_REG0D], 40h
456 //mov BYTE PTR es:[ebp+SBP2P_BUS_DEV_FUN shl 12 + SB_P2P_REG1B], 40h
458 WritePCI((SBP2P_BUS_DEV_FUN << 16) + SB_P2P_REG0D, AccWidthUint8, &dbValue);
459 WritePCI((SBP2P_BUS_DEV_FUN << 16) + SB_P2P_REG1B, AccWidthUint8, &dbValue);
461 //SB P2P AutoClock control settings.
462 ddVar = (pConfig->PcibAutoClkCtrlLow) | (pConfig->PcibAutoClkCtrlLow);
463 WritePCI((SBP2P_BUS_DEV_FUN << 16) + SB_P2P_REG4C, AccWidthUint32, &ddVar);
464 ddVar = (pConfig->PcibClkStopOverride);
465 RWPCI((SBP2P_BUS_DEV_FUN << 16) + SB_P2P_REG50, AccWidthUint16, 0x3F, (UINT16) (ddVar << 6));
467 if (pConfig->MobilePowerSavings){
468 //If RTC clock is not driven to any chip, it should be shut-off. If system uses external RTC, then SB needs to
469 //drive out RTC clk to external RTC chip. If system uses internal RTC, then this clk can be shut off.
470 RWPMIO(SB_PMIO_REG68, AccWidthUint8, ~(UINT32)BIT4, (pConfig->ExternalRTCClock)<<4);
471 if (!getClockMode()){
472 if (!(pConfig->UsbIntClock) ){
473 //If the external clock is used, the second PLL should be shut down
474 RWPMIO(SB_PMIO_REGD0, AccWidthUint8, 0xFF, BIT0);
475 // If external clock mode is used, the 25Mhz oscillator buffer can be turned-off by setting PMIO 0xD4[7]=1
476 RWPMIO(SB_PMIO_REGD4, AccWidthUint8, 0xFF, BIT7);
477 //Disable unused clocks
478 RWPMIO(SB_PMIO_REGCA, AccWidthUint8, 0xFF, 0x7E);
481 writeAlink(0x30, SB_AB_REG40);
482 writeAlink(0x34, ((readAlink(0x34)) & 0xFFFF0000) | 0x008A);
486 //Don't shutoff RTC clock
487 RWPMIO(SB_PMIO_REG68, AccWidthUint8, ~(UINT32)BIT4, 0);
488 //Dont disable second PLL
489 RWPMIO(SB_PMIO_REGD0, AccWidthUint8, ~(UINT32)BIT0, 0);
490 //Enable the 25Mhz oscillator
491 RWPMIO(SB_PMIO_REGD4, AccWidthUint8, ~(UINT32)BIT7, 0);
492 RWPMIO(SB_PMIO_REGCA, AccWidthUint8, 0xFF, 0x00);
498 hpetInit (AMDSBCFG* pConfig, BUILDPARAM *pStaticOptions)
500 DESCRIPTION_HEADER* pHpetTable;
502 if (pConfig->HpetTimer == 1) {
505 RWPMIO(SB_PMIO_REG9A, AccWidthUint8, 0xFF, BIT7);
506 // Program the HPET BAR address
507 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REGB4, AccWidthUint32 | S3_SAVE, 0, pStaticOptions->HpetBase);
509 // Enable HPET MMIO decoding: SMBUS:0x43[4] = 1
510 // Enable HPET MSI support only when HpetMsiDis == 0
511 dbTemp = (pConfig->HpetMsiDis)? BIT4 : BIT7 + BIT6 + BIT5 + BIT4;
512 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG43, AccWidthUint8 | S3_SAVE, ~(UINT32)BIT3, dbTemp);
513 // Program HPET default clock period
514 if (getRevisionID() >= SB700_A13) {
515 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG34, AccWidthUint32 | S3_SAVE, 0x00, 0x429B17E);
517 RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG43, AccWidthUint8 | S3_SAVE, 0xFF, BIT3);
518 // Enable High Precision Event Timer (also called Multimedia Timer) interrupt
519 RWPCI((SMBUS_BUS_DEV_FUN << 16) + (SB_SMBUS_REG64+1), AccWidthUint8 | S3_SAVE, ~(UINT32)BIT2, BIT2);
522 if (!(pConfig->S3Resume)) {
523 // pHpetTable = (DESCRIPTION_HEADER*)ACPI_LocateTable('TEPH');
524 pHpetTable = (DESCRIPTION_HEADER*)ACPI_LocateTable(Int32FromChar ('T', 'E', 'P', 'H'));
525 if (pHpetTable != NULL) {
526 // pHpetTable->Signature = 'HPET';
527 pHpetTable->Signature = Int32FromChar ('T', 'E', 'P', 'H');
534 void c3PopupSetting(AMDSBCFG* pConfig){
538 CpuidRead (0x01, &CpuId);
539 //RPR 2.3 C-State and VID/FID Change
540 dbTemp = GetNumberOfCpuCores();
542 //PM_IO 0x9A[5]=1, For system with dual core CPU, set this bit to 1 to automatically clear BM_STS when the C3 state is being initiated.
543 //PM_IO 0x9A[4]=1, For system with dual core CPU, set this bit to 1 and BM_STS will cause C3 to wakeup regardless of BM_RLD
544 //PM_IO 0x9A[2]=1, Enable pop-up for C3. For internal bus mastering or BmReq# from the NB, the SB will de-assert
545 //LDTSTP# (pop-up) to allow DMA traffic, then assert LDTSTP# again after some idle time.
546 RWPMIO(SB_PMIO_REG9A, AccWidthUint8, 0xFF, BIT5+BIT4+BIT2);
549 //SB700 needs to changed for RD790 support
550 //PM_IO 0x8F [4] = 0 for system with RS690
551 //Note: RS690 north bridge has AllowLdtStop built for both display and PCIE traffic to wake up the HT link.
552 //BmReq# needs to be ignored otherwise may cause LDTSTP# not to toggle.
553 //PM_IO 0x8F[5]=1, Ignore BM_STS_SET message from NB
554 RWPMIO(SB_PMIO_REG8F, AccWidthUint8, ~(UINT32)(BIT5+BIT4), BIT5);
556 //LdtStartTime = 10h for minimum LDTSTP# de-assertion duration of 16us in StutterMode. This is to guarantee that
557 //the HT link has been safely reconnected before it can be disconnected again. If C3 pop-up is enabled, the 16us also
558 //serves as the minimum idle time before LDTSTP# can be asserted again. This allows DMA to finish before the HT
559 //link is disconnected.
560 //Increase LDTSTOP Deassertion time for SP5100 to 20us, SB700 remains the same
561 dbTemp = (IsServer())? 0x14 : 0x10;
562 RWPMIO(SB_PMIO_REG88, AccWidthUint8, 0x00, dbTemp);
564 //This setting provides 16us delay before the assertion of LDTSTOP# when C3 is entered. The
565 //delay will allow USB DMA to go on in a continous manner
566 RWPMIO(SB_PMIO_REG89, AccWidthUint8, 0x00, 0x10);
568 //Set this bit to allow pop-up request being latched during the minimum LDTSTP# assertion time
569 RWPMIO(SB_PMIO_REG52, AccWidthUint8, 0xFF, BIT7);