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 | |
Felix Held | 928a9c8 | 2022-02-24 00:51:11 +0100 | [diff] [blame^] | 3 | #include <arch/hpet.h> |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 4 | #include <cpu/x86/mtrr.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 5 | #include <cpu/amd/msr.h> |
Elyes HAOUAS | 8a64370 | 2018-10-23 17:10:27 +0200 | [diff] [blame] | 6 | #include <cpu/amd/mtrr.h> |
Kyösti Mälkki | d610c58 | 2017-03-05 06:28:18 +0200 | [diff] [blame] | 7 | #include <northbridge/amd/agesa/agesa_helper.h> |
| 8 | #include <AGESA.h> |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 9 | #include <amdlib.h> |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 10 | |
| 11 | void amd_initcpuio(void) |
| 12 | { |
| 13 | UINT64 MsrReg; |
| 14 | UINT32 PciData; |
| 15 | PCI_ADDR PciAddress; |
| 16 | AMD_CONFIG_PARAMS StdHeader; |
| 17 | |
| 18 | /* Enable legacy video routing: D18F1xF4 VGA Enable */ |
Frans Hendriks | e5aafb6 | 2021-01-27 09:17:59 +0100 | [diff] [blame] | 19 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xF4); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 20 | PciData = 1; |
| 21 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 22 | |
| 23 | /* The platform BIOS needs to ensure the memory ranges of Hudson legacy |
| 24 | * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are |
| 25 | * set to non-posted regions. |
| 26 | */ |
Frans Hendriks | e5aafb6 | 2021-01-27 09:17:59 +0100 | [diff] [blame] | 27 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x84); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 28 | PciData = 0x00FEDF00; /* last address before processor local APIC at FEE00000 */ |
| 29 | PciData |= 1 << 7; /* set NP (non-posted) bit */ |
| 30 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
Frans Hendriks | e5aafb6 | 2021-01-27 09:17:59 +0100 | [diff] [blame] | 31 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x80); |
Felix Held | 928a9c8 | 2022-02-24 00:51:11 +0100 | [diff] [blame^] | 32 | PciData = (HPET_BASE_ADDRESS >> 8) | 3; /* lowest NP address is HPET at FED00000 */ |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 33 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 34 | |
| 35 | /* Map the remaining PCI hole as posted MMIO */ |
Frans Hendriks | e5aafb6 | 2021-01-27 09:17:59 +0100 | [diff] [blame] | 36 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x8C); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 37 | PciData = 0x00FECF00; /* last address before non-posted range */ |
| 38 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
Elyes HAOUAS | 8a64370 | 2018-10-23 17:10:27 +0200 | [diff] [blame] | 39 | LibAmdMsrRead(TOP_MEM, &MsrReg, &StdHeader); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 40 | MsrReg = (MsrReg >> 8) | 3; |
Frans Hendriks | e5aafb6 | 2021-01-27 09:17:59 +0100 | [diff] [blame] | 41 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x88); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 42 | PciData = (UINT32)MsrReg; |
| 43 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 44 | |
| 45 | /* Send all IO (0000-FFFF) to southbridge. */ |
Frans Hendriks | e5aafb6 | 2021-01-27 09:17:59 +0100 | [diff] [blame] | 46 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC4); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 47 | PciData = 0x0000F000; |
| 48 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
Frans Hendriks | e5aafb6 | 2021-01-27 09:17:59 +0100 | [diff] [blame] | 49 | PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC0); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 50 | PciData = 0x00000003; |
| 51 | LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader); |
| 52 | } |