Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 - 2012 Advanced Micro Devices, Inc. |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <cpu/x86/mtrr.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame^] | 17 | #include <cpu/amd/msr.h> |
Kyösti Mälkki | d610c58 | 2017-03-05 06:28:18 +0200 | [diff] [blame] | 18 | #include <northbridge/amd/agesa/agesa_helper.h> |
| 19 | #include <AGESA.h> |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 20 | #include "amdlib.h" |
| 21 | |
| 22 | /* Define AMD Ontario APPU SSID/SVID */ |
| 23 | #define AMD_APU_SVID 0x1022 |
| 24 | #define AMD_APU_SSID 0x1234 |
| 25 | |
| 26 | void amd_initcpuio(void) |
| 27 | { |
| 28 | UINT64 MsrReg; |
| 29 | UINT32 PciData; |
| 30 | PCI_ADDR PciAddress; |
| 31 | AMD_CONFIG_PARAMS StdHeader; |
| 32 | |
| 33 | /* Enable legacy video routing: D18F1xF4 VGA Enable */ |
| 34 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xF4); |
| 35 | PciData = 1; |
| 36 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 37 | |
| 38 | /* The platform BIOS needs to ensure the memory ranges of SB800 legacy |
| 39 | * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are |
| 40 | * set to non-posted regions. |
| 41 | */ |
| 42 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x84); |
| 43 | PciData = 0x00FEDF00; // last address before processor local APIC at FEE00000 |
| 44 | PciData |= 1 << 7; // set NP (non-posted) bit |
| 45 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 46 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x80); |
| 47 | PciData = (0xFED00000 >> 8) | 3; // lowest NP address is HPET at FED00000 |
| 48 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 49 | |
| 50 | /* Map the remaining PCI hole as posted MMIO */ |
| 51 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x8C); |
| 52 | PciData = 0x00FECF00; // last address before non-posted range |
| 53 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 54 | LibAmdMsrRead(0xC001001A, &MsrReg, &StdHeader); |
| 55 | MsrReg = (MsrReg >> 8) | 3; |
| 56 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x88); |
| 57 | PciData = (UINT32) MsrReg; |
| 58 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 59 | |
| 60 | /* Send all IO (0000-FFFF) to southbridge. */ |
| 61 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC4); |
| 62 | PciData = 0x0000F000; |
| 63 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 64 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC0); |
| 65 | PciData = 0x00000003; |
| 66 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 67 | } |
| 68 | |
| 69 | void amd_initmmio(void) |
| 70 | { |
| 71 | UINT64 MsrReg; |
| 72 | UINT32 PciData; |
| 73 | PCI_ADDR PciAddress; |
| 74 | AMD_CONFIG_PARAMS StdHeader; |
| 75 | |
| 76 | /* |
| 77 | Set the MMIO Configuration Base Address and Bus Range onto MMIO configuration base |
| 78 | Address MSR register. |
| 79 | */ |
| 80 | MsrReg = CONFIG_MMCONF_BASE_ADDRESS | (LibAmdBitScanReverse(CONFIG_MMCONF_BUS_NUMBER) << 2) | 1; |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame^] | 81 | LibAmdMsrWrite(MMIO_CONF_BASE, &MsrReg, &StdHeader); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 82 | |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 83 | /* Set Ontario Link Data */ |
| 84 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0, 0, 0xE0); |
| 85 | PciData = 0x01308002; |
| 86 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 87 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0, 0, 0xE4); |
| 88 | PciData = (AMD_APU_SSID << 0x10) | AMD_APU_SVID; |
| 89 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
Kyösti Mälkki | 036a581 | 2016-11-20 07:45:17 +0200 | [diff] [blame] | 90 | |
| 91 | /* Set ROM cache onto WP to decrease post time */ |
| 92 | MsrReg = (0x0100000000ull - CACHE_ROM_SIZE) | MTRR_TYPE_WRPROT; |
| 93 | LibAmdMsrWrite (0x20C, &MsrReg, &StdHeader); |
| 94 | MsrReg = ((1ULL << CONFIG_CPU_ADDR_BITS) - CACHE_ROM_SIZE) | MTRR_PHYS_MASK_VALID; |
| 95 | LibAmdMsrWrite (0x20D, &MsrReg, &StdHeader); |
Kyösti Mälkki | 7d25651 | 2016-11-20 08:03:49 +0200 | [diff] [blame] | 96 | |
| 97 | /* Set P-state 0 (1600 MHz) early to save a few ms of boot time */ |
| 98 | MsrReg = 0; |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame^] | 99 | LibAmdMsrWrite(PS_CTL_REG, &MsrReg, &StdHeader); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 100 | } |
Kyösti Mälkki | 4a08e15 | 2014-12-14 19:41:54 +0200 | [diff] [blame] | 101 | |
| 102 | void amd_initenv(void) |
| 103 | { |
| 104 | AMD_INTERFACE_PARAMS AmdParamStruct; |
| 105 | PCI_ADDR PciAddress; |
| 106 | UINT32 PciValue; |
| 107 | |
| 108 | /* Initialize Subordinate Bus Number and Secondary Bus Number |
| 109 | * In platform BIOS this address is allocated by PCI enumeration code |
| 110 | Modify D1F0x18 |
| 111 | */ |
| 112 | PciAddress.Address.Bus = 0; |
| 113 | PciAddress.Address.Device = 1; |
| 114 | PciAddress.Address.Function = 0; |
| 115 | PciAddress.Address.Register = 0x18; |
| 116 | /* Write to D1F0x18 */ |
| 117 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 118 | PciValue |= 0x00010100; |
| 119 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 120 | |
| 121 | /* Initialize GMM Base Address for Legacy Bridge Mode |
| 122 | * Modify B1D5F0x18 |
| 123 | */ |
| 124 | PciAddress.Address.Bus = 1; |
| 125 | PciAddress.Address.Device = 5; |
| 126 | PciAddress.Address.Function = 0; |
| 127 | PciAddress.Address.Register = 0x18; |
| 128 | |
| 129 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 130 | PciValue |= 0x96000000; |
| 131 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 132 | |
| 133 | /* Initialize FB Base Address for Legacy Bridge Mode |
| 134 | * Modify B1D5F0x10 |
| 135 | */ |
| 136 | PciAddress.Address.Register = 0x10; |
| 137 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 138 | PciValue |= 0x80000000; |
| 139 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 140 | |
| 141 | /* Initialize GMM Base Address for Pcie Mode |
| 142 | * Modify B0D1F0x18 |
| 143 | */ |
| 144 | PciAddress.Address.Bus = 0; |
| 145 | PciAddress.Address.Device = 1; |
| 146 | PciAddress.Address.Function = 0; |
| 147 | PciAddress.Address.Register = 0x18; |
| 148 | |
| 149 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 150 | PciValue |= 0x96000000; |
| 151 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 152 | |
| 153 | /* Initialize FB Base Address for Pcie Mode |
| 154 | * Modify B0D1F0x10 |
| 155 | */ |
| 156 | PciAddress.Address.Register = 0x10; |
| 157 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 158 | PciValue |= 0x80000000; |
| 159 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 160 | |
| 161 | /* Initialize MMIO Base and Limit Address |
| 162 | * Modify B0D1F0x20 |
| 163 | */ |
| 164 | PciAddress.Address.Bus = 0; |
| 165 | PciAddress.Address.Device = 1; |
| 166 | PciAddress.Address.Function = 0; |
| 167 | PciAddress.Address.Register = 0x20; |
| 168 | |
| 169 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 170 | PciValue |= 0x96009600; |
| 171 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 172 | |
| 173 | /* Initialize MMIO Prefetchable Memory Limit and Base |
| 174 | * Modify B0D1F0x24 |
| 175 | */ |
| 176 | PciAddress.Address.Register = 0x24; |
| 177 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 178 | PciValue |= 0x8FF18001; |
| 179 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 180 | } |