blob: 163066b6d86e4ca13b89628d35dbe4e2c8469527 [file] [log] [blame]
Dave Frodin4b45dd32015-03-13 09:29:20 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 - 2012 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Dave Frodin4b45dd32015-03-13 09:29:20 -060014 */
15
16#include <cpu/x86/mtrr.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +020017#include <cpu/amd/msr.h>
Elyes HAOUAS8a643702018-10-23 17:10:27 +020018#include <cpu/amd/mtrr.h>
Kyösti Mälkkied8d2772017-07-15 17:12:44 +030019#include <northbridge/amd/agesa/agesa_helper.h>
Kyösti Mälkki42865022017-09-28 16:42:41 +030020#include <Porting.h>
21#include <AGESA.h>
22#include <amdlib.h>
Dave Frodin4b45dd32015-03-13 09:29:20 -060023
24void amd_initcpuio(void)
25{
26 UINT64 MsrReg;
27 UINT32 PciData;
28 PCI_ADDR PciAddress;
29 AMD_CONFIG_PARAMS StdHeader;
30
31 /* Enable legacy video routing: D18F1xF4 VGA Enable */
Evelyn Huang0182aea22017-06-07 14:20:09 -060032 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xF4);
Dave Frodin4b45dd32015-03-13 09:29:20 -060033 PciData = 1;
34 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
35
36 /* The platform BIOS needs to ensure the memory ranges of SB800 legacy
37 * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are
38 * set to non-posted regions.
39 */
Evelyn Huang0182aea22017-06-07 14:20:09 -060040 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x84);
41 /* last address before processor local APIC at FEE00000 */
42 PciData = 0x00FEDF00;
43 /* set NP (non-posted) bit */
44 PciData |= 1 << 7;
Dave Frodin4b45dd32015-03-13 09:29:20 -060045 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
Evelyn Huang0182aea22017-06-07 14:20:09 -060046 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x80);
47 /* lowest NP address is HPET at FED00000 */
48 PciData = (0xFED00000 >> 8) | 3;
Dave Frodin4b45dd32015-03-13 09:29:20 -060049 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
50
51 /* Map the remaining PCI hole as posted MMIO */
Evelyn Huang0182aea22017-06-07 14:20:09 -060052 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x8C);
Dave Frodin4b45dd32015-03-13 09:29:20 -060053 PciData = 0x00FECF00; /* last address before non-posted range */
54 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
Elyes HAOUAS8a643702018-10-23 17:10:27 +020055 LibAmdMsrRead(TOP_MEM, &MsrReg, &StdHeader);
Dave Frodin4b45dd32015-03-13 09:29:20 -060056 MsrReg = (MsrReg >> 8) | 3;
Evelyn Huang0182aea22017-06-07 14:20:09 -060057 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0x88);
Dave Frodin4b45dd32015-03-13 09:29:20 -060058 PciData = (UINT32)MsrReg;
59 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
60
61 /* Send all IO (0000-FFFF) to southbridge. */
Evelyn Huang0182aea22017-06-07 14:20:09 -060062 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC4);
Dave Frodin4b45dd32015-03-13 09:29:20 -060063 PciData = 0x0000F000;
64 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
Evelyn Huang0182aea22017-06-07 14:20:09 -060065 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x18, 1, 0xC0);
Dave Frodin4b45dd32015-03-13 09:29:20 -060066 PciData = 0x00000003;
67 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
68}
69
70void amd_initmmio(void)
71{
72 UINT64 MsrReg;
73 UINT32 PciData;
74 PCI_ADDR PciAddress;
75 AMD_CONFIG_PARAMS StdHeader;
76
77 /*
Evelyn Huang0182aea22017-06-07 14:20:09 -060078 * Set the MMIO Configuration Base Address and
79 * Bus Range onto MMIO configuration base
80 * Address MSR register.
81 */
82 MsrReg = CONFIG_MMCONF_BASE_ADDRESS |
83 (LibAmdBitScanReverse(CONFIG_MMCONF_BUS_NUMBER) << 2) | 1;
Elyes HAOUAS400ce552018-10-12 10:54:30 +020084 LibAmdMsrWrite(MMIO_CONF_BASE, &MsrReg, &StdHeader);
Dave Frodin4b45dd32015-03-13 09:29:20 -060085
Dave Frodin4b45dd32015-03-13 09:29:20 -060086 /* For serial port */
87 PciData = 0xFF03FFD5;
Evelyn Huang0182aea22017-06-07 14:20:09 -060088 PciAddress.AddressValue = MAKE_SBDFO(0, 0, 0x14, 0x3, 0x44);
Dave Frodin4b45dd32015-03-13 09:29:20 -060089 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
90
91 /* PSP */
92 //PciData = 0xD;
93 //PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x8, 0x0, 0x48);
94 //LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
95
96 /* Set ROM cache onto WP to decrease post time */
97 MsrReg = (0x0100000000ull - CACHE_ROM_SIZE) | 5ull;
Elyes HAOUASd50cf232018-10-17 20:18:17 +020098 LibAmdMsrWrite(MTRR_PHYS_BASE(6), &MsrReg, &StdHeader);
Dave Frodin4b45dd32015-03-13 09:29:20 -060099 MsrReg = ((1ULL << CONFIG_CPU_ADDR_BITS) - CACHE_ROM_SIZE) | 0x800ull;
Elyes HAOUASd50cf232018-10-17 20:18:17 +0200100 LibAmdMsrWrite(MTRR_PHYS_MASK(6), &MsrReg, &StdHeader);
Marshall Dawson03e6a452017-02-12 10:31:15 -0700101
Evelyn Huang0182aea22017-06-07 14:20:09 -0600102 if (IS_ENABLED(CONFIG_UDELAY_LAPIC)) {
Marshall Dawson03e6a452017-02-12 10:31:15 -0700103 LibAmdMsrRead(0x1B, &MsrReg, &StdHeader);
104 MsrReg |= 1 << 11;
105 LibAmdMsrWrite(0x1B, &MsrReg, &StdHeader);
106 }
Dave Frodin4b45dd32015-03-13 09:29:20 -0600107}