Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google, 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, |
Aaron Durbin | 2c4aab3 | 2015-03-06 23:26:06 -0600 | [diff] [blame] | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame^] | 17 | #include <device/pci_ops.h> |
Aaron Durbin | ba170b47 | 2013-09-23 14:15:42 -0500 | [diff] [blame] | 18 | #include <cpu/x86/cache.h> |
| 19 | #include <cpu/x86/msr.h> |
| 20 | #include <cpu/x86/mtrr.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 21 | #include <soc/iosf.h> |
Aaron Durbin | c0270aa | 2013-10-04 11:15:48 -0500 | [diff] [blame] | 22 | #include <cpu/intel/microcode/microcode.c> |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 23 | |
Aaron Durbin | ba170b47 | 2013-09-23 14:15:42 -0500 | [diff] [blame] | 24 | static void set_var_mtrr(int reg, uint32_t base, uint32_t size, int type) |
| 25 | { |
| 26 | msr_t basem, maskm; |
| 27 | basem.lo = base | type; |
| 28 | basem.hi = 0; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 29 | wrmsr(MTRR_PHYS_BASE(reg), basem); |
| 30 | maskm.lo = ~(size - 1) | MTRR_PHYS_MASK_VALID; |
Aaron Durbin | ba170b47 | 2013-09-23 14:15:42 -0500 | [diff] [blame] | 31 | maskm.hi = (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 32 | wrmsr(MTRR_PHYS_MASK(reg), maskm); |
Aaron Durbin | ba170b47 | 2013-09-23 14:15:42 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static void enable_rom_caching(void) |
| 36 | { |
| 37 | msr_t msr; |
| 38 | |
| 39 | disable_cache(); |
| 40 | /* Why only top 4MiB ? */ |
| 41 | set_var_mtrr(1, 0xffc00000, 4*1024*1024, MTRR_TYPE_WRPROT); |
| 42 | enable_cache(); |
| 43 | |
| 44 | /* Enable Variable MTRRs */ |
| 45 | msr.hi = 0x00000000; |
| 46 | msr.lo = 0x00000800; |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 47 | wrmsr(MTRR_DEF_TYPE_MSR, msr); |
Aaron Durbin | ba170b47 | 2013-09-23 14:15:42 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Aaron Durbin | c0270aa | 2013-10-04 11:15:48 -0500 | [diff] [blame] | 50 | static void setup_mmconfig(void) |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 51 | { |
| 52 | uint32_t reg; |
| 53 | |
Aaron Durbin | 9a7d7bc | 2013-09-07 00:41:48 -0500 | [diff] [blame] | 54 | /* Set up the MMCONF range. The register lives in the BUNIT. The |
| 55 | * IO variant of the config access needs to be used initially to |
| 56 | * properly configure as the IOSF access registers live in PCI |
| 57 | * config space. */ |
| 58 | reg = 0; |
| 59 | /* Clear the extended register. */ |
| 60 | pci_io_write_config32(IOSF_PCI_DEV, MCRX_REG, reg); |
| 61 | reg = CONFIG_MMCONF_BASE_ADDRESS | 1; |
| 62 | pci_io_write_config32(IOSF_PCI_DEV, MDR_REG, reg); |
| 63 | reg = IOSF_OPCODE(IOSF_OP_WRITE_BUNIT) | IOSF_PORT(IOSF_PORT_BUNIT) | |
| 64 | IOSF_REG(BUNIT_MMCONF_REG) | IOSF_BYTE_EN; |
| 65 | pci_io_write_config32(IOSF_PCI_DEV, MCR_REG, reg); |
| 66 | } |
Aaron Durbin | c0270aa | 2013-10-04 11:15:48 -0500 | [diff] [blame] | 67 | |
| 68 | static void bootblock_cpu_init(void) |
| 69 | { |
| 70 | /* Allow memory-mapped PCI config access. */ |
| 71 | setup_mmconfig(); |
| 72 | |
| 73 | /* Load microcode before any caching. */ |
| 74 | intel_update_microcode_from_cbfs(); |
| 75 | enable_rom_caching(); |
| 76 | } |