Kerry Sheh | 3439bba | 2012-02-01 13:55:13 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2012 Advanced Micro Devices, Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 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. |
| 16 | * |
| 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. |
| 27 | * |
| 28 | * |
| 29 | ***************************************************************************/ |
| 30 | |
| 31 | |
| 32 | #include "Platform.h" |
| 33 | |
Kerry Sheh | 3439bba | 2012-02-01 13:55:13 +0800 | [diff] [blame] | 34 | BUILDPARAM DfltStaticOptions={ |
| 35 | BIOS_SIZE, // BIOS Size |
| 36 | LEGACY_FREE, // Legacy Free Option |
| 37 | 0x00, // Dummy space holder |
| 38 | |
| 39 | 0x00, // ECKbd disable/enable |
| 40 | 0x00, // EcChannel0 disable/enable |
| 41 | 0x00, // Dummy space holder1 |
| 42 | |
| 43 | SMBUS0_BASE_ADDRESS, // Smbus Base Address; |
| 44 | SMBUS1_BASE_ADDRESS, // Smbus Base Address; |
| 45 | SIO_PME_BASE_ADDRESS, // SIO PME Base Address |
| 46 | WATCHDOG_TIMER_BASE_ADDRESS, // Watchdog Timer Base Address |
| 47 | SPI_BASE_ADDRESS, |
| 48 | |
| 49 | PM1_EVT_BLK_ADDRESS, // AcpiPm1EvtBlkAddr; |
| 50 | PM1_CNT_BLK_ADDRESS, // AcpiPm1CntBlkAddr; |
| 51 | PM1_TMR_BLK_ADDRESS, // AcpiPmTmrBlkAddr; |
| 52 | CPU_CNT_BLK_ADDRESS, // CpuControlBlkAddr; |
| 53 | GPE0_BLK_ADDRESS, // AcpiGpe0BlkAddr; |
| 54 | SMI_CMD_PORT, // SmiCmdPortAddr; |
| 55 | ACPI_PMA_CNT_BLK_ADDRESS, // AcpiPmaCntBlkAddr; |
| 56 | |
| 57 | EC_LDN5_MAILBOX_ADDRESS, |
| 58 | EC_LDN5_IRQ, |
| 59 | EC_LDN9_MAILBOX_ADDRESS, // EC LDN9 Mailbox address |
| 60 | RESERVED_VALUE, |
| 61 | RESERVED_VALUE, |
| 62 | RESERVED_VALUE, |
| 63 | RESERVED_VALUE, |
| 64 | |
| 65 | HPET_BASE_ADDRESS, // HPET Base address |
| 66 | |
| 67 | SATA_IDE_MODE_SSID, |
| 68 | SATA_RAID_MODE_SSID, |
| 69 | SATA_RAID5_MODE_SSID, |
| 70 | SATA_AHCI_SSID, |
| 71 | |
| 72 | OHCI0_SSID, |
| 73 | OHCI1_SSID, |
| 74 | EHCI0_SSID, |
| 75 | OHCI2_SSID, |
| 76 | OHCI3_SSID, |
| 77 | EHCI1_SSID, |
| 78 | OHCI4_SSID, |
| 79 | SMBUS_SSID, |
| 80 | IDE_SSID, |
| 81 | AZALIA_SSID, |
| 82 | LPC_SSID, |
| 83 | P2P_SSID, |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | /********************************************************************************* |
| 88 | * |
| 89 | * Routine Description: Config SB Before PCI INIT |
| 90 | * |
| 91 | * Arguments: |
| 92 | * |
| 93 | * pConfig - SBconfiguration |
| 94 | * |
| 95 | * Returns: |
| 96 | * |
| 97 | * void |
| 98 | * |
| 99 | **********************************************************************************/ |
| 100 | void sbBeforePciInit (AMDSBCFG* pConfig){ |
| 101 | BUILDPARAM *pStaticOptions; |
| 102 | |
| 103 | pStaticOptions = &pConfig->BuildParameters; |
| 104 | TRACE((DMSG_SB_TRACE, "CIMx - Entering sbBeforePciInit \n")); |
| 105 | commonInitEarlyBoot(pConfig); |
| 106 | commonInitEarlyPost(pConfig); |
| 107 | #ifndef NO_EC_SUPPORT |
| 108 | ecInitBeforePciEnum(pConfig); |
| 109 | #endif |
| 110 | usbInitBeforePciEnum(pConfig); // USB POST TIME Only |
| 111 | fcInitBeforePciEnum(pConfig); // Preinit flash controller |
| 112 | sataInitBeforePciEnum(pConfig); // Init SATA class code and PHY |
| 113 | programSubSystemIDs(pConfig, pStaticOptions); // Set subsystem/vendor ID |
| 114 | |
| 115 | TRACE((DMSG_SB_TRACE, "CIMx - Exiting sbBeforePciInit \n")); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | /********************************************************************************* |
| 120 | * |
| 121 | * Routine Description: Config SB After PCI INIT |
| 122 | * |
| 123 | * Arguments: |
| 124 | * |
| 125 | * pConfig - SBconfiguration |
| 126 | * |
| 127 | * Returns: void |
| 128 | * |
| 129 | * Reference: atiSbAfterPciInit |
| 130 | * |
| 131 | **********************************************************************************/ |
| 132 | void sbAfterPciInit(AMDSBCFG* pConfig){ |
| 133 | BUILDPARAM *pStaticOptions; |
| 134 | |
| 135 | TRACE((DMSG_SB_TRACE, "CIMx - Entering sbAfterPciInit \n")); |
| 136 | |
| 137 | pStaticOptions = &pConfig->BuildParameters; |
| 138 | usbInitMidPost(pConfig); //usb initialization which is required only during post |
| 139 | usbInitAfterPciInit(pConfig); // Init USB MMIO |
| 140 | sataInitAfterPciEnum(pConfig); // SATA port enumeration |
| 141 | azaliaInitAfterPciEnum(pConfig); // Detect and configure High Definition Audio |
| 142 | |
| 143 | TRACE((DMSG_SB_TRACE, "CIMx - Exiting sbAfterPciInit \n")); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | /********************************************************************************* |
| 148 | * |
| 149 | * Routine Description: Config SB during late POST |
| 150 | * |
| 151 | * Arguments: |
| 152 | * |
| 153 | * pConfig - SBconfiguration |
| 154 | * |
| 155 | * Returns: void |
| 156 | * |
| 157 | * Reference: atiSbLatePost |
| 158 | * |
| 159 | **********************************************************************************/ |
| 160 | void sbLatePost(AMDSBCFG* pConfig){ |
| 161 | UINT16 dwVar; |
| 162 | BUILDPARAM *pStaticOptions; |
| 163 | pStaticOptions = &pConfig->BuildParameters; |
| 164 | TRACE((DMSG_SB_TRACE, "CIMx - Entering sbLatePost \n")); |
| 165 | ReadPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG02, AccWidthUint16, &dwVar); |
| 166 | if (dwVar != SB7XX_DEVICE_ID){ |
| 167 | // Display message that the SB is wrong and stop the system |
| 168 | TRACE((DMSG_SB_TRACE, "Current system does not have SB700 chipset. Stopping\n")); |
| 169 | for(;;); |
| 170 | } |
| 171 | commonInitLateBoot(pConfig); |
| 172 | sataInitLatePost(pConfig); |
| 173 | hpetInit(pConfig, pStaticOptions); // SB Configure HPET base and enable bit |
| 174 | #ifndef NO_EC_SUPPORT |
| 175 | ecInitLatePost(pConfig); |
| 176 | #endif |
| 177 | } |
| 178 | |
| 179 | /********************************************************************************* |
| 180 | * |
| 181 | * Routine Description: Config SB before ACPI S3 resume PCI config device restore |
| 182 | * |
| 183 | * Arguments: |
| 184 | * |
| 185 | * pConfig - SBconfiguration |
| 186 | * |
| 187 | * Returns: void |
| 188 | * |
| 189 | * Reference: AtiSbBfPciRestore |
| 190 | * |
| 191 | **********************************************************************************/ |
| 192 | void sbBeforePciRestoreInit(AMDSBCFG* pConfig){ |
| 193 | BUILDPARAM *pStaticOptions; |
| 194 | |
| 195 | TRACE((DMSG_SB_TRACE, "CIMx - Entering sbBeforePciRestoreInit \n")); |
| 196 | |
| 197 | pConfig->S3Resume = 1; |
| 198 | |
| 199 | pStaticOptions = &pConfig->BuildParameters; |
| 200 | commonInitEarlyBoot(pConfig); // set /SMBUS/ACPI/IDE/LPC/PCIB |
| 201 | abLinkInitBeforePciEnum(pConfig); // Set ABCFG registers |
| 202 | usbInitBeforePciEnum(pConfig); // USB POST TIME Only |
| 203 | fcInitBeforePciEnum(pConfig); // Preinit flash controller |
| 204 | sataInitBeforePciEnum(pConfig); |
| 205 | programSubSystemIDs(pConfig, pStaticOptions); // Set subsystem/vendor ID |
| 206 | } |
| 207 | |
| 208 | |
| 209 | /********************************************************************************* |
| 210 | * |
| 211 | * Routine Description: Config SB after ACPI S3 resume PCI config device restore |
| 212 | * |
| 213 | * Arguments: |
| 214 | * |
| 215 | * pConfig - SBconfiguration |
| 216 | * |
| 217 | * Returns: void |
| 218 | * |
| 219 | * Reference: AtiSbAfPciRestore |
| 220 | * |
| 221 | **********************************************************************************/ |
| 222 | void sbAfterPciRestoreInit(AMDSBCFG* pConfig){ |
| 223 | BUILDPARAM *pStaticOptions; |
| 224 | |
| 225 | pConfig->S3Resume = 1; |
| 226 | |
| 227 | pStaticOptions = &pConfig->BuildParameters; |
| 228 | TRACE((DMSG_SB_TRACE, "CIMx - Entering sbAfterPciRestoreInit \n")); |
| 229 | |
| 230 | commonInitLateBoot(pConfig); |
| 231 | sataInitAfterPciEnum(pConfig); |
| 232 | azaliaInitAfterPciEnum(pConfig); // Detect and configure High Definition Audio |
| 233 | hpetInit(pConfig, pStaticOptions); // SB Configure HPET base and enable bit |
| 234 | sataInitLatePost(pConfig); |
| 235 | sbSmmAcpiOn(pConfig); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /*++ |
| 240 | |
| 241 | Routine Description: |
| 242 | |
| 243 | SB config hook during ACPI_ON |
| 244 | |
| 245 | Arguments: |
| 246 | |
| 247 | pConfig - SBconfiguration |
| 248 | |
| 249 | Returns: |
| 250 | |
| 251 | void |
| 252 | |
| 253 | --*/ |
| 254 | |
| 255 | void sbSmmAcpiOn(AMDSBCFG* pConfig){ |
| 256 | UINT32 ddBar5; |
| 257 | UINT8 dbPort; |
| 258 | |
| 259 | //RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG60+2, AccWidthUint8 | S3_SAVE, ~(UINT32)(BIT1+BIT0), 0); |
| 260 | if (getRevisionID() >= SB700_A13) |
| 261 | RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG43, AccWidthUint8 | S3_SAVE, 0xFF, BIT0); //Enable Legacy DMA prefetch enhancement |
| 262 | |
| 263 | RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG60+2, AccWidthUint8 | S3_SAVE, ~(UINT32)(BIT1+BIT0), 0); |
| 264 | RWPCI((SMBUS_BUS_DEV_FUN << 16) + SB_SMBUS_REG64+3, AccWidthUint8| S3_SAVE, ~(UINT32)BIT7, 0); |
| 265 | programOhciMmioForEmulation(); |
| 266 | |
| 267 | // For IDE_TO_AHCI_MODE and IDE_TO_AMD_AHCI_MODE, clear Interrupt Status register for all ports |
| 268 | ReadPCI( ((SATA_BUS_DEV_FUN << 16) + SB_SATA_REG24), AccWidthUint32, &ddBar5); |
| 269 | if ((pConfig->SataClass == IDE_TO_AHCI_MODE) || (pConfig->SataClass == IDE_TO_AMD_AHCI_MODE)){ |
| 270 | for (dbPort = 0; dbPort <= 5; dbPort++) { |
| 271 | RWMEM(ddBar5 + SB_SATA_BAR5_REG110 + dbPort * 0x80, AccWidthUint32, 0x00, 0xFFFFFFFF); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | |
| 277 | UINT32 CallBackToOEM(UINT32 Func, UINTN Data,AMDSBCFG* pConfig){ |
| 278 | UINT32 Result=0; |
| 279 | TRACE((DMSG_SB_TRACE,"OEM Call Back Func [%x] Data [%x]\n",Func,Data)); |
| 280 | if (pConfig->StdHeader.pCallBack==NULL) |
| 281 | return Result; |
| 282 | Result = (*(pConfig->StdHeader.pCallBack))(Func,Data,pConfig); |
| 283 | TRACE((DMSG_SB_TRACE,"SB Hook Status [%x]\n",Result)); |
| 284 | return Result; |
| 285 | } |