coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
fixme.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/hpet.h>
4 #include <cpu/x86/mtrr.h>
5 #include <cpu/amd/msr.h>
6 #include <cpu/amd/mtrr.h>
8 #include <AGESA.h>
9 #include <amdlib.h>
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 */
19  PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xF4);
20  PciData = 1;
21  LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
22 
23  /* The platform BIOS needs to ensure the memory ranges of SB800 legacy
24  * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are
25  * set to non-posted regions.
26  */
27  PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x84);
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);
31  PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x80);
32  PciData = (HPET_BASE_ADDRESS >> 8) | 3; // lowest NP address is HPET at FED00000
33  LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
34 
35  /* Map the remaining PCI hole as posted MMIO */
36  PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x8C);
37  PciData = 0x00FECF00; // last address before non-posted range
38  LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
39  LibAmdMsrRead(TOP_MEM, &MsrReg, &StdHeader);
40  MsrReg = (MsrReg >> 8) | 3;
41  PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x88);
42  PciData = (UINT32) MsrReg;
43  LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
44 
45  /* Send all IO (0000-FFFF) to southbridge. */
46  PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC4);
47  PciData = 0x0000F000;
48  LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
49  PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC0);
50  PciData = 0x00000003;
51  LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
52 }
53 
54 void amd_initenv(void)
55 {
56  AMD_INTERFACE_PARAMS AmdParamStruct;
57  PCI_ADDR PciAddress;
58  UINT32 PciValue;
59 
60  /* Initialize Subordinate Bus Number and Secondary Bus Number
61  * In platform BIOS this address is allocated by PCI enumeration code
62  Modify D1F0x18
63  */
64  PciAddress.Address.Bus = 0;
65  PciAddress.Address.Device = 1;
66  PciAddress.Address.Function = 0;
67  PciAddress.Address.Register = 0x18;
68  /* Write to D1F0x18 */
69  LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
70  PciValue |= 0x00010100;
71  LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
72 
73  /* Initialize GMM Base Address for Legacy Bridge Mode
74  * Modify B1D5F0x18
75  */
76  PciAddress.Address.Bus = 1;
77  PciAddress.Address.Device = 5;
78  PciAddress.Address.Function = 0;
79  PciAddress.Address.Register = 0x18;
80 
81  LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
82  PciValue |= 0x96000000;
83  LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
84 
85  /* Initialize FB Base Address for Legacy Bridge Mode
86  * Modify B1D5F0x10
87  */
88  PciAddress.Address.Register = 0x10;
89  LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
90  PciValue |= 0x80000000;
91  LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
92 
93  /* Initialize GMM Base Address for PCIe Mode
94  * Modify B0D1F0x18
95  */
96  PciAddress.Address.Bus = 0;
97  PciAddress.Address.Device = 1;
98  PciAddress.Address.Function = 0;
99  PciAddress.Address.Register = 0x18;
100 
101  LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
102  PciValue |= 0x96000000;
103  LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
104 
105  /* Initialize FB Base Address for PCIe Mode
106  * Modify B0D1F0x10
107  */
108  PciAddress.Address.Register = 0x10;
109  LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
110  PciValue |= 0x80000000;
111  LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
112 
113  /* Initialize MMIO Base and Limit Address
114  * Modify B0D1F0x20
115  */
116  PciAddress.Address.Bus = 0;
117  PciAddress.Address.Device = 1;
118  PciAddress.Address.Function = 0;
119  PciAddress.Address.Register = 0x20;
120 
121  LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
122  PciValue |= 0x96009600;
123  LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
124 
125  /* Initialize MMIO Prefetchable Memory Limit and Base
126  * Modify B0D1F0x24
127  */
128  PciAddress.Address.Register = 0x24;
129  LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
130  PciValue |= 0x8FF18001;
131  LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
132 }
@ AccessWidth32
Access width is 32 bits.
Definition: Amd.h:62
void amd_initenv(void)
Definition: fixme.c:54
void amd_initcpuio(void)
Definition: fixme.c:11
#define TOP_MEM
Definition: mtrr.h:34
#define HPET_BASE_ADDRESS
Definition: hpet.h:6
The standard header for all AGESA services.
Definition: Amd.h:74