blob: a3767674d8577ac5724b06e14b62f5fd7d7ad1c1 [file] [log] [blame]
Kyösti Mälkki48518f02014-11-25 14:20:57 +02001/*
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.
Kyösti Mälkki48518f02014-11-25 14:20:57 +020014 */
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älkkid610c582017-03-05 06:28:18 +020019#include <northbridge/amd/agesa/agesa_helper.h>
20#include <AGESA.h>
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +020021#include <amdlib.h>
Kyösti Mälkki48518f02014-11-25 14:20:57 +020022
23void amd_initcpuio(void)
24{
25 UINT64 MsrReg;
26 UINT32 PciData;
27 PCI_ADDR PciAddress;
28 AMD_CONFIG_PARAMS StdHeader;
29
30 /* Enable legacy video routing: D18F1xF4 VGA Enable */
31 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0xF4);
32 PciData = 1;
33 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
34
35 /* The platform BIOS needs to ensure the memory ranges of Hudson legacy
36 * devices (TPM, HPET, BIOS RAM, Watchdog Timer, I/O APIC and ACPI) are
37 * set to non-posted regions.
38 */
39 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0x84);
40 PciData = 0x00FEDF00; /* last address before processor local APIC at FEE00000 */
41 PciData |= 1 << 7; /* set NP (non-posted) bit */
42 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
43 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0x80);
44 PciData = (0xFED00000 >> 8) | 3; /* lowest NP address is HPET at FED00000 */
45 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
46
47 /* Map the remaining PCI hole as posted MMIO */
48 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0x8C);
49 PciData = 0x00FECF00; /* last address before non-posted range */
50 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
Elyes HAOUAS8a643702018-10-23 17:10:27 +020051 LibAmdMsrRead(TOP_MEM, &MsrReg, &StdHeader);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020052 MsrReg = (MsrReg >> 8) | 3;
53 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0x88);
54 PciData = (UINT32)MsrReg;
55 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
56
57 /* Send all IO (0000-FFFF) to southbridge. */
58 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0xC4);
59 PciData = 0x0000F000;
60 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
61 PciAddress.AddressValue = MAKE_SBDFO (0, 0, 0x18, 1, 0xC0);
62 PciData = 0x00000003;
63 LibAmdPciWrite(AccessWidth32, PciAddress, &PciData, &StdHeader);
64}
65
66void amd_initmmio(void)
67{
68 UINT64 MsrReg;
69 AMD_CONFIG_PARAMS StdHeader;
70
71 /*
72 Set the MMIO Configuration Base Address and Bus Range onto MMIO configuration base
73 Address MSR register.
74 */
75 MsrReg = CONFIG_MMCONF_BASE_ADDRESS | (LibAmdBitScanReverse (CONFIG_MMCONF_BUS_NUMBER) << 2) | 1;
Elyes HAOUAS400ce552018-10-12 10:54:30 +020076 LibAmdMsrWrite(MMIO_CONF_BASE, &MsrReg, &StdHeader);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020077
Kyösti Mälkki48518f02014-11-25 14:20:57 +020078 /* Set ROM cache onto WP to decrease post time */
79 MsrReg = (0x0100000000ull - CACHE_ROM_SIZE) | 5ull;
Elyes HAOUASd50cf232018-10-17 20:18:17 +020080 LibAmdMsrWrite(MTRR_PHYS_BASE(6), &MsrReg, &StdHeader);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020081 MsrReg = ((1ULL << CONFIG_CPU_ADDR_BITS) - CACHE_ROM_SIZE) | 0x800ull;
Elyes HAOUASd50cf232018-10-17 20:18:17 +020082 LibAmdMsrWrite(MTRR_PHYS_MASK(6), &MsrReg, &StdHeader);
Kyösti Mälkki48518f02014-11-25 14:20:57 +020083}