blob: 658434d2c8d67d3ae1616d7d6019f5a7661f1c7a [file] [log] [blame]
Kyösti Mälkki48518f02014-11-25 14:20:57 +02001/*
2 * This file is part of the coreboot project.
3 *
Kyösti Mälkki48518f02014-11-25 14:20:57 +02004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Kyösti Mälkki48518f02014-11-25 14:20:57 +020012 */
13
14#include <cpu/x86/mtrr.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +020015#include <cpu/amd/msr.h>
Elyes HAOUAS8a643702018-10-23 17:10:27 +020016#include <cpu/amd/mtrr.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020017#include <northbridge/amd/agesa/agesa_helper.h>
18#include <AGESA.h>
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +020019#include <amdlib.h>
Kyösti Mälkki48518f02014-11-25 14:20:57 +020020
Kyösti Mälkki48518f02014-11-25 14:20:57 +020021void amd_initcpuio(void)
22{
23 UINT64 MsrReg;
24 UINT32 PciData;
25 PCI_ADDR PciAddress;
26 AMD_CONFIG_PARAMS StdHeader;
27
28 /* Enable legacy video routing: D18F1xF4 VGA Enable */
29 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xF4);
30 PciData = 1;
31 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
32
33 /* The platform BIOS needs to ensure the memory ranges of SB800 legacy
34 * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are
35 * set to non-posted regions.
36 */
37 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x84);
38 PciData = 0x00FEDF00; // last address before processor local APIC at FEE00000
39 PciData |= 1 << 7; // set NP (non-posted) bit
40 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
41 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x80);
42 PciData = (0xFED00000 >> 8) | 3; // lowest NP address is HPET at FED00000
43 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
44
45 /* Map the remaining PCI hole as posted MMIO */
46 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x8C);
47 PciData = 0x00FECF00; // last address before non-posted range
48 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
Elyes HAOUAS8a643702018-10-23 17:10:27 +020049 LibAmdMsrRead(TOP_MEM, &MsrReg, &StdHeader);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020050 MsrReg = (MsrReg >> 8) | 3;
51 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x88);
52 PciData = (UINT32) MsrReg;
53 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
54
55 /* Send all IO (0000-FFFF) to southbridge. */
56 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC4);
57 PciData = 0x0000F000;
58 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
59 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC0);
60 PciData = 0x00000003;
61 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
62}
63
Kyösti Mälkki4a08e152014-12-14 19:41:54 +020064void amd_initenv(void)
65{
66 AMD_INTERFACE_PARAMS AmdParamStruct;
67 PCI_ADDR PciAddress;
68 UINT32 PciValue;
69
70 /* Initialize Subordinate Bus Number and Secondary Bus Number
71 * In platform BIOS this address is allocated by PCI enumeration code
72 Modify D1F0x18
73 */
74 PciAddress.Address.Bus = 0;
75 PciAddress.Address.Device = 1;
76 PciAddress.Address.Function = 0;
77 PciAddress.Address.Register = 0x18;
78 /* Write to D1F0x18 */
79 LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
80 PciValue |= 0x00010100;
81 LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
82
83 /* Initialize GMM Base Address for Legacy Bridge Mode
84 * Modify B1D5F0x18
85 */
86 PciAddress.Address.Bus = 1;
87 PciAddress.Address.Device = 5;
88 PciAddress.Address.Function = 0;
89 PciAddress.Address.Register = 0x18;
90
91 LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
92 PciValue |= 0x96000000;
93 LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
94
95 /* Initialize FB Base Address for Legacy Bridge Mode
96 * Modify B1D5F0x10
97 */
98 PciAddress.Address.Register = 0x10;
99 LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
100 PciValue |= 0x80000000;
101 LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
102
Elyes HAOUAS79ccc692020-02-24 13:43:39 +0100103 /* Initialize GMM Base Address for PCIe Mode
Kyösti Mälkki4a08e152014-12-14 19:41:54 +0200104 * Modify B0D1F0x18
105 */
106 PciAddress.Address.Bus = 0;
107 PciAddress.Address.Device = 1;
108 PciAddress.Address.Function = 0;
109 PciAddress.Address.Register = 0x18;
110
111 LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
112 PciValue |= 0x96000000;
113 LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
114
Elyes HAOUAS79ccc692020-02-24 13:43:39 +0100115 /* Initialize FB Base Address for PCIe Mode
Kyösti Mälkki4a08e152014-12-14 19:41:54 +0200116 * Modify B0D1F0x10
117 */
118 PciAddress.Address.Register = 0x10;
119 LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
120 PciValue |= 0x80000000;
121 LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
122
123 /* Initialize MMIO Base and Limit Address
124 * Modify B0D1F0x20
125 */
126 PciAddress.Address.Bus = 0;
127 PciAddress.Address.Device = 1;
128 PciAddress.Address.Function = 0;
129 PciAddress.Address.Register = 0x20;
130
131 LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
132 PciValue |= 0x96009600;
133 LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
134
135 /* Initialize MMIO Prefetchable Memory Limit and Base
136 * Modify B0D1F0x24
137 */
138 PciAddress.Address.Register = 0x24;
139 LibAmdPciRead(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
140 PciValue |= 0x8FF18001;
141 LibAmdPciWrite(AccessWidth32, PciAddress, &PciValue, &AmdParamStruct.StdHeader);
142}