blob: 70ccc21f8bbc29acc499e5f108c74470252a4f75 [file] [log] [blame]
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -05001/*
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,
11 * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <arch/io.h>
Aaron Durbinba170b472013-09-23 14:15:42 -050021#include <cpu/x86/cache.h>
22#include <cpu/x86/msr.h>
23#include <cpu/x86/mtrr.h>
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050024#include <baytrail/iosf.h>
25
Aaron Durbinba170b472013-09-23 14:15:42 -050026static void set_var_mtrr(int reg, uint32_t base, uint32_t size, int type)
27{
28 msr_t basem, maskm;
29 basem.lo = base | type;
30 basem.hi = 0;
31 wrmsr(MTRRphysBase_MSR(reg), basem);
32 maskm.lo = ~(size - 1) | MTRRphysMaskValid;
33 maskm.hi = (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1;
34 wrmsr(MTRRphysMask_MSR(reg), maskm);
35}
36
37static void enable_rom_caching(void)
38{
39 msr_t msr;
40
41 disable_cache();
42 /* Why only top 4MiB ? */
43 set_var_mtrr(1, 0xffc00000, 4*1024*1024, MTRR_TYPE_WRPROT);
44 enable_cache();
45
46 /* Enable Variable MTRRs */
47 msr.hi = 0x00000000;
48 msr.lo = 0x00000800;
49 wrmsr(MTRRdefType_MSR, msr);
50}
51
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050052static void bootblock_cpu_init(void)
53{
54 uint32_t reg;
55
Aaron Durbinba170b472013-09-23 14:15:42 -050056 enable_rom_caching();
57
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050058 /* Set up the MMCONF range. The register lives in the BUNIT. The
59 * IO variant of the config access needs to be used initially to
60 * properly configure as the IOSF access registers live in PCI
61 * config space. */
62 reg = 0;
63 /* Clear the extended register. */
64 pci_io_write_config32(IOSF_PCI_DEV, MCRX_REG, reg);
65 reg = CONFIG_MMCONF_BASE_ADDRESS | 1;
66 pci_io_write_config32(IOSF_PCI_DEV, MDR_REG, reg);
67 reg = IOSF_OPCODE(IOSF_OP_WRITE_BUNIT) | IOSF_PORT(IOSF_PORT_BUNIT) |
68 IOSF_REG(BUNIT_MMCONF_REG) | IOSF_BYTE_EN;
69 pci_io_write_config32(IOSF_PCI_DEV, MCR_REG, reg);
70}