blob: 1da55a77f8504400280d3e35393049fb4524e90f [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
Felix Held928a9c82022-02-24 00:51:11 +01003#include <arch/hpet.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
Kyösti Mälkki48518f02014-11-25 14:20:57 +020010void 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);
Felix Held928a9c82022-02-24 00:51:11 +010031 PciData = (HPET_BASE_ADDRESS >> 8) | 3; // lowest NP address is HPET at FED00000
Kyösti Mälkki48518f02014-11-25 14:20:57 +020032 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 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;
40 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x88);
Elyes Haouas287048a2022-05-29 15:44:11 +020041 PciData = (UINT32)MsrReg;
Kyösti Mälkki48518f02014-11-25 14:20:57 +020042 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älkki4a08e152014-12-14 19:41:54 +020053void 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 HAOUAS79ccc692020-02-24 13:43:39 +010092 /* Initialize GMM Base Address for PCIe Mode
Kyösti Mälkki4a08e152014-12-14 19:41:54 +020093 * 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 HAOUAS79ccc692020-02-24 13:43:39 +0100104 /* Initialize FB Base Address for PCIe Mode
Kyösti Mälkki4a08e152014-12-14 19:41:54 +0200105 * 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}