blob: ebfa07da08a1f08121f88c246b1c234de84a8319 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkki48518f02014-11-25 14:20:57 +02002
3#include <cpu/x86/mtrr.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +02004#include <cpu/amd/msr.h>
Elyes HAOUAS8a643702018-10-23 17:10:27 +02005#include <cpu/amd/mtrr.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +02006#include <northbridge/amd/agesa/agesa_helper.h>
7#include <AGESA.h>
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02008#include <amdlib.h>
Kyösti Mälkki48518f02014-11-25 14:20:57 +02009
10void 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 */
Frans Hendrikse5aafb62021-01-27 09:17:59 +010018 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xF4);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020019 PciData = 1;
20 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
21
22 /* The platform BIOS needs to ensure the memory ranges of Hudson legacy
23 * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are
24 * set to non-posted regions.
25 */
Frans Hendrikse5aafb62021-01-27 09:17:59 +010026 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x84);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020027 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);
Frans Hendrikse5aafb62021-01-27 09:17:59 +010030 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x80);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020031 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 */
Frans Hendrikse5aafb62021-01-27 09:17:59 +010035 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x8C);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020036 PciData = 0x00FECF00; /* last address before non-posted range */
37 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
Elyes HAOUAS8a643702018-10-23 17:10:27 +020038 LibAmdMsrRead(TOP_MEM, &MsrReg, &StdHeader);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020039 MsrReg = (MsrReg >> 8) | 3;
Frans Hendrikse5aafb62021-01-27 09:17:59 +010040 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x88);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020041 PciData = (UINT32)MsrReg;
42 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
43
44 /* Send all IO (0000-FFFF) to southbridge. */
Frans Hendrikse5aafb62021-01-27 09:17:59 +010045 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC4);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020046 PciData = 0x0000F000;
47 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
Frans Hendrikse5aafb62021-01-27 09:17:59 +010048 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC0);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020049 PciData = 0x00000003;
50 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
51}