Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 1 | /* |
| 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älkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <cpu/x86/mtrr.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 17 | #include <cpu/amd/msr.h> |
Elyes HAOUAS | 8a64370 | 2018-10-23 17:10:27 +0200 | [diff] [blame] | 18 | #include <cpu/amd/mtrr.h> |
Kyösti Mälkki | d610c58 | 2017-03-05 06:28:18 +0200 | [diff] [blame] | 19 | #include <northbridge/amd/agesa/agesa_helper.h> |
| 20 | #include <AGESA.h> |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame^] | 21 | #include <amdlib.h> |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 22 | |
| 23 | void 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 HAOUAS | 8a64370 | 2018-10-23 17:10:27 +0200 | [diff] [blame] | 51 | LibAmdMsrRead(TOP_MEM, &MsrReg, &StdHeader); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 52 | 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 | |
| 66 | void 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 HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 76 | LibAmdMsrWrite(MMIO_CONF_BASE, &MsrReg, &StdHeader); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 77 | |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 78 | /* Set ROM cache onto WP to decrease post time */ |
| 79 | MsrReg = (0x0100000000ull - CACHE_ROM_SIZE) | 5ull; |
Elyes HAOUAS | d50cf23 | 2018-10-17 20:18:17 +0200 | [diff] [blame] | 80 | LibAmdMsrWrite(MTRR_PHYS_BASE(6), &MsrReg, &StdHeader); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 81 | MsrReg = ((1ULL << CONFIG_CPU_ADDR_BITS) - CACHE_ROM_SIZE) | 0x800ull; |
Elyes HAOUAS | d50cf23 | 2018-10-17 20:18:17 +0200 | [diff] [blame] | 82 | LibAmdMsrWrite(MTRR_PHYS_MASK(6), &MsrReg, &StdHeader); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 83 | } |