blob: 3245a288dbc7563cff84e34e7ab86f2a717997d8 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
Lee Leahy32471722015-04-20 15:20:28 -07005 * Copyright (C) 2015 Intel Corp.
Lee Leahy77ff0b12015-05-05 15:07:29 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070015 */
16
Lee Leahy32471722015-04-20 15:20:28 -070017#include <arch/acpi.h>
18#include <cbmem.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070019#include <console/console.h>
20#include <cpu/x86/smm.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
Lee Leahy94b856e2015-10-15 12:07:03 -070024#include <fsp/memmap.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050025#include <fsp/util.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070026#include <soc/iomap.h>
27#include <soc/iosf.h>
28#include <soc/pci_devs.h>
29#include <soc/ramstage.h>
Lee Leahy32471722015-04-20 15:20:28 -070030#include <soc/smm.h>
31#include <vendorcode/google/chromeos/chromeos.h>
Harry Pan43dcbfd2016-08-11 14:35:04 +080032#include <stddef.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070033
Lee Leahy32471722015-04-20 15:20:28 -070034/*
35 * Host Memory Map:
Lee Leahy77ff0b12015-05-05 15:07:29 -070036 *
37 * +--------------------------+ BMBOUND_HI
38 * | Usable DRAM |
39 * +--------------------------+ 4GiB
40 * | PCI Address Space |
41 * +--------------------------+ BMBOUND
42 * | TPM |
43 * +--------------------------+ IMR2
44 * | TXE |
45 * +--------------------------+ IMR1
46 * | iGD |
47 * +--------------------------+
48 * | GTT |
49 * +--------------------------+ SMMRRH, IRM0
50 * | TSEG |
51 * +--------------------------+ SMMRRL
52 * | Usable DRAM |
53 * +--------------------------+ 0
54 *
55 * Note that there are really only a few regions that need to enumerated w.r.t.
Lee Leahy32471722015-04-20 15:20:28 -070056 * coreboot's resrouce model:
Lee Leahy77ff0b12015-05-05 15:07:29 -070057 *
58 * +--------------------------+ BMBOUND_HI
59 * | Cacheable/Usable |
60 * +--------------------------+ 4GiB
61 *
62 * +--------------------------+ BMBOUND
63 * | Uncacheable/Reserved |
64 * +--------------------------+ SMMRRH
65 * | Cacheable/Reserved |
66 * +--------------------------+ SMMRRL
67 * | Cacheable/Usable |
68 * +--------------------------+ 0
69 */
Lee Leahy32471722015-04-20 15:20:28 -070070#define RES_IN_KIB(r) ((r) >> 10)
Lee Leahy77ff0b12015-05-05 15:07:29 -070071
72uint32_t nc_read_top_of_low_memory(void)
73{
Harry Pan43dcbfd2016-08-11 14:35:04 +080074 MAYBE_STATIC uint32_t tolm = 0;
75
76 if (tolm)
77 return tolm;
78
79 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
80
81 return tolm;
Lee Leahy77ff0b12015-05-05 15:07:29 -070082}
83
Elyes HAOUASb13fac32018-05-24 22:29:44 +020084static void nc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070085{
86 unsigned long mmconf;
Lee Leahy32471722015-04-20 15:20:28 -070087 unsigned long bmbound_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070088 unsigned long bmbound_hi;
Lee Leahy32471722015-04-20 15:20:28 -070089 void *smm_base;
90 size_t smm_size;
91 unsigned long tseg_base_k;
92 unsigned long tseg_top_k;
93 unsigned long fsp_res_base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070094 unsigned long base_k, size_k;
95 const unsigned long four_gig_kib = (4 << (30 - 10));
96 int index = 0;
97
98 /* Read standard PCI resources. */
99 pci_dev_read_resources(dev);
100
Lee Leahy32471722015-04-20 15:20:28 -0700101 /* Determine TSEG data */
102 smm_region(&smm_base, &smm_size);
103 tseg_base_k = RES_IN_KIB((unsigned long) smm_base);
104 tseg_top_k = tseg_base_k + RES_IN_KIB(smm_size);
105
106 /* Determine the base of the FSP reserved memory */
107 fsp_res_base_k = RES_IN_KIB((unsigned long) cbmem_top());
108
Lee Leahy77ff0b12015-05-05 15:07:29 -0700109 /* PCIe memory-mapped config space access - 256 MiB. */
110 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
Lee Leahy32471722015-04-20 15:20:28 -0700111 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KIB(mmconf), 256 * 1024);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700112
113 /* 0 -> 0xa0000 */
Lee Leahy32471722015-04-20 15:20:28 -0700114 base_k = RES_IN_KIB(0);
115 size_k = RES_IN_KIB(0xa0000) - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700116 ram_resource(dev, index++, base_k, size_k);
117
Lee Leahy32471722015-04-20 15:20:28 -0700118 /* 0xc0000 -> fsp_res_base - cacheable and usable */
119 base_k = RES_IN_KIB(0xc0000);
120 size_k = fsp_res_base_k - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700121 ram_resource(dev, index++, base_k, size_k);
122
Lee Leahy32471722015-04-20 15:20:28 -0700123 /* fsp_res_base -> tseg_top - Reserved */
124 base_k = fsp_res_base_k;
125 size_k = tseg_top_k - base_k;
126 reserved_ram_resource(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700127
Lee Leahy32471722015-04-20 15:20:28 -0700128 /* TSEG TOP -> bmbound is memory backed mmio. */
129 bmbound_k = RES_IN_KIB(nc_read_top_of_low_memory());
130 mmio_resource(dev, index++, tseg_top_k, bmbound_k - tseg_top_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700131
Lee Leahy32471722015-04-20 15:20:28 -0700132 /*
133 * The BMBOUND_HI register matches register bits of 31:24 with address
134 * bits of 35:28. Therefore, shift register to align properly.
135 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700136 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
Lee Leahy32471722015-04-20 15:20:28 -0700137 bmbound_hi = RES_IN_KIB(bmbound_hi) << 4;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700138 if (bmbound_hi > four_gig_kib)
139 ram_resource(dev, index++, four_gig_kib,
Lee Leahy32471722015-04-20 15:20:28 -0700140 bmbound_hi - four_gig_kib);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700141
Lee Leahy32471722015-04-20 15:20:28 -0700142 /*
143 * Reserve everything between A segment and 1MB:
Lee Leahy77ff0b12015-05-05 15:07:29 -0700144 *
145 * 0xa0000 - 0xbffff: legacy VGA
146 * 0xc0000 - 0xfffff: RAM
147 */
148 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
149 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
Lee Leahy32471722015-04-20 15:20:28 -0700150 (0x100000 - 0xc0000) >> 10);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700151
152 chromeos_reserve_ram_oops(dev, index++);
153}
154
155static struct device_operations nc_ops = {
Lee Leahy32471722015-04-20 15:20:28 -0700156 .acpi_fill_ssdt_generator = generate_cpu_entries,
157 .read_resources = nc_read_resources,
158 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700159};
160
161static const struct pci_driver nc_driver __pci_driver = {
162 .ops = &nc_ops,
163 .vendor = PCI_VENDOR_ID_INTEL,
164 .device = SOC_DEVID,
165};