Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 2 | |
| 3 | #include <cpu/x86/mtrr.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 4 | #include <cpu/amd/msr.h> |
Elyes HAOUAS | 8a64370 | 2018-10-23 17:10:27 +0200 | [diff] [blame] | 5 | #include <cpu/amd/mtrr.h> |
Kyösti Mälkki | d610c58 | 2017-03-05 06:28:18 +0200 | [diff] [blame] | 6 | #include <northbridge/amd/agesa/agesa_helper.h> |
| 7 | #include <AGESA.h> |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 8 | #include <amdlib.h> |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 9 | |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 10 | void amd_initcpuio(void) |
| 11 | { |
| 12 | UINT64 MsrReg; |
| 13 | UINT32 PciData; |
| 14 | PCI_ADDR PciAddress; |
| 15 | AMD_CONFIG_PARAMS StdHeader; |
| 16 | |
| 17 | /* Enable legacy video routing: D18F1xF4 VGA Enable */ |
| 18 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xF4); |
| 19 | PciData = 1; |
| 20 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 21 | |
| 22 | /* The platform BIOS needs to ensure the memory ranges of SB800 legacy |
| 23 | * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are |
| 24 | * set to non-posted regions. |
| 25 | */ |
| 26 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x84); |
| 27 | PciData = 0x00FEDF00; // last address before processor local APIC at FEE00000 |
| 28 | PciData |= 1 << 7; // set NP (non-posted) bit |
| 29 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 30 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x80); |
| 31 | PciData = (0xFED00000 >> 8) | 3; // lowest NP address is HPET at FED00000 |
| 32 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 33 | |
| 34 | /* Map the remaining PCI hole as posted MMIO */ |
| 35 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x8C); |
| 36 | PciData = 0x00FECF00; // last address before non-posted range |
| 37 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
Elyes HAOUAS | 8a64370 | 2018-10-23 17:10:27 +0200 | [diff] [blame] | 38 | LibAmdMsrRead(TOP_MEM, &MsrReg, &StdHeader); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 39 | MsrReg = (MsrReg >> 8) | 3; |
| 40 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x88); |
| 41 | PciData = (UINT32) MsrReg; |
| 42 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 43 | |
| 44 | /* Send all IO (0000-FFFF) to southbridge. */ |
| 45 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC4); |
| 46 | PciData = 0x0000F000; |
| 47 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 48 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC0); |
| 49 | PciData = 0x00000003; |
| 50 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 51 | } |
| 52 | |
Kyösti Mälkki | 4a08e15 | 2014-12-14 19:41:54 +0200 | [diff] [blame] | 53 | void amd_initenv(void) |
| 54 | { |
| 55 | AMD_INTERFACE_PARAMS AmdParamStruct; |
| 56 | PCI_ADDR PciAddress; |
| 57 | UINT32 PciValue; |
| 58 | |
| 59 | /* Initialize Subordinate Bus Number and Secondary Bus Number |
| 60 | * In platform BIOS this address is allocated by PCI enumeration code |
| 61 | Modify D1F0x18 |
| 62 | */ |
| 63 | PciAddress.Address.Bus = 0; |
| 64 | PciAddress.Address.Device = 1; |
| 65 | PciAddress.Address.Function = 0; |
| 66 | PciAddress.Address.Register = 0x18; |
| 67 | /* Write to D1F0x18 */ |
| 68 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 69 | PciValue |= 0x00010100; |
| 70 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 71 | |
| 72 | /* Initialize GMM Base Address for Legacy Bridge Mode |
| 73 | * Modify B1D5F0x18 |
| 74 | */ |
| 75 | PciAddress.Address.Bus = 1; |
| 76 | PciAddress.Address.Device = 5; |
| 77 | PciAddress.Address.Function = 0; |
| 78 | PciAddress.Address.Register = 0x18; |
| 79 | |
| 80 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 81 | PciValue |= 0x96000000; |
| 82 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 83 | |
| 84 | /* Initialize FB Base Address for Legacy Bridge Mode |
| 85 | * Modify B1D5F0x10 |
| 86 | */ |
| 87 | PciAddress.Address.Register = 0x10; |
| 88 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 89 | PciValue |= 0x80000000; |
| 90 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 91 | |
Elyes HAOUAS | 79ccc69 | 2020-02-24 13:43:39 +0100 | [diff] [blame] | 92 | /* Initialize GMM Base Address for PCIe Mode |
Kyösti Mälkki | 4a08e15 | 2014-12-14 19:41:54 +0200 | [diff] [blame] | 93 | * Modify B0D1F0x18 |
| 94 | */ |
| 95 | PciAddress.Address.Bus = 0; |
| 96 | PciAddress.Address.Device = 1; |
| 97 | PciAddress.Address.Function = 0; |
| 98 | PciAddress.Address.Register = 0x18; |
| 99 | |
| 100 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 101 | PciValue |= 0x96000000; |
| 102 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 103 | |
Elyes HAOUAS | 79ccc69 | 2020-02-24 13:43:39 +0100 | [diff] [blame] | 104 | /* Initialize FB Base Address for PCIe Mode |
Kyösti Mälkki | 4a08e15 | 2014-12-14 19:41:54 +0200 | [diff] [blame] | 105 | * Modify B0D1F0x10 |
| 106 | */ |
| 107 | PciAddress.Address.Register = 0x10; |
| 108 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 109 | PciValue |= 0x80000000; |
| 110 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 111 | |
| 112 | /* Initialize MMIO Base and Limit Address |
| 113 | * Modify B0D1F0x20 |
| 114 | */ |
| 115 | PciAddress.Address.Bus = 0; |
| 116 | PciAddress.Address.Device = 1; |
| 117 | PciAddress.Address.Function = 0; |
| 118 | PciAddress.Address.Register = 0x20; |
| 119 | |
| 120 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 121 | PciValue |= 0x96009600; |
| 122 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 123 | |
| 124 | /* Initialize MMIO Prefetchable Memory Limit and Base |
| 125 | * Modify B0D1F0x24 |
| 126 | */ |
| 127 | PciAddress.Address.Register = 0x24; |
| 128 | LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 129 | PciValue |= 0x8FF18001; |
| 130 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader); |
| 131 | } |