blob: 404a8f18c19b2dc8fa762df946977c33cf6aae2c [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>
Lee Leahy77ff0b12015-05-05 15:07:29 -070032
Lee Leahy32471722015-04-20 15:20:28 -070033/*
34 * Host Memory Map:
Lee Leahy77ff0b12015-05-05 15:07:29 -070035 *
36 * +--------------------------+ BMBOUND_HI
37 * | Usable DRAM |
38 * +--------------------------+ 4GiB
39 * | PCI Address Space |
40 * +--------------------------+ BMBOUND
41 * | TPM |
42 * +--------------------------+ IMR2
43 * | TXE |
44 * +--------------------------+ IMR1
45 * | iGD |
46 * +--------------------------+
47 * | GTT |
48 * +--------------------------+ SMMRRH, IRM0
49 * | TSEG |
50 * +--------------------------+ SMMRRL
51 * | Usable DRAM |
52 * +--------------------------+ 0
53 *
54 * Note that there are really only a few regions that need to enumerated w.r.t.
Lee Leahy32471722015-04-20 15:20:28 -070055 * coreboot's resrouce model:
Lee Leahy77ff0b12015-05-05 15:07:29 -070056 *
57 * +--------------------------+ BMBOUND_HI
58 * | Cacheable/Usable |
59 * +--------------------------+ 4GiB
60 *
61 * +--------------------------+ BMBOUND
62 * | Uncacheable/Reserved |
63 * +--------------------------+ SMMRRH
64 * | Cacheable/Reserved |
65 * +--------------------------+ SMMRRL
66 * | Cacheable/Usable |
67 * +--------------------------+ 0
68 */
Lee Leahy32471722015-04-20 15:20:28 -070069#define RES_IN_KIB(r) ((r) >> 10)
Lee Leahy77ff0b12015-05-05 15:07:29 -070070
71uint32_t nc_read_top_of_low_memory(void)
72{
73 return iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
74}
75
76static void nc_read_resources(device_t dev)
77{
78 unsigned long mmconf;
Lee Leahy32471722015-04-20 15:20:28 -070079 unsigned long bmbound_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070080 unsigned long bmbound_hi;
Lee Leahy32471722015-04-20 15:20:28 -070081 void *smm_base;
82 size_t smm_size;
83 unsigned long tseg_base_k;
84 unsigned long tseg_top_k;
85 unsigned long fsp_res_base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070086 unsigned long base_k, size_k;
87 const unsigned long four_gig_kib = (4 << (30 - 10));
88 int index = 0;
89
90 /* Read standard PCI resources. */
91 pci_dev_read_resources(dev);
92
Lee Leahy32471722015-04-20 15:20:28 -070093 /* Determine TSEG data */
94 smm_region(&smm_base, &smm_size);
95 tseg_base_k = RES_IN_KIB((unsigned long) smm_base);
96 tseg_top_k = tseg_base_k + RES_IN_KIB(smm_size);
97
98 /* Determine the base of the FSP reserved memory */
99 fsp_res_base_k = RES_IN_KIB((unsigned long) cbmem_top());
100
Lee Leahy77ff0b12015-05-05 15:07:29 -0700101 /* PCIe memory-mapped config space access - 256 MiB. */
102 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
Lee Leahy32471722015-04-20 15:20:28 -0700103 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KIB(mmconf), 256 * 1024);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700104
105 /* 0 -> 0xa0000 */
Lee Leahy32471722015-04-20 15:20:28 -0700106 base_k = RES_IN_KIB(0);
107 size_k = RES_IN_KIB(0xa0000) - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700108 ram_resource(dev, index++, base_k, size_k);
109
Lee Leahy32471722015-04-20 15:20:28 -0700110 /* 0xc0000 -> fsp_res_base - cacheable and usable */
111 base_k = RES_IN_KIB(0xc0000);
112 size_k = fsp_res_base_k - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700113 ram_resource(dev, index++, base_k, size_k);
114
Lee Leahy32471722015-04-20 15:20:28 -0700115 /* fsp_res_base -> tseg_top - Reserved */
116 base_k = fsp_res_base_k;
117 size_k = tseg_top_k - base_k;
118 reserved_ram_resource(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700119
Lee Leahy32471722015-04-20 15:20:28 -0700120 /* TSEG TOP -> bmbound is memory backed mmio. */
121 bmbound_k = RES_IN_KIB(nc_read_top_of_low_memory());
122 mmio_resource(dev, index++, tseg_top_k, bmbound_k - tseg_top_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700123
Lee Leahy32471722015-04-20 15:20:28 -0700124 /*
125 * The BMBOUND_HI register matches register bits of 31:24 with address
126 * bits of 35:28. Therefore, shift register to align properly.
127 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700128 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
Lee Leahy32471722015-04-20 15:20:28 -0700129 bmbound_hi = RES_IN_KIB(bmbound_hi) << 4;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700130 if (bmbound_hi > four_gig_kib)
131 ram_resource(dev, index++, four_gig_kib,
Lee Leahy32471722015-04-20 15:20:28 -0700132 bmbound_hi - four_gig_kib);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700133
Lee Leahy32471722015-04-20 15:20:28 -0700134 /*
135 * Reserve everything between A segment and 1MB:
Lee Leahy77ff0b12015-05-05 15:07:29 -0700136 *
137 * 0xa0000 - 0xbffff: legacy VGA
138 * 0xc0000 - 0xfffff: RAM
139 */
140 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
141 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
Lee Leahy32471722015-04-20 15:20:28 -0700142 (0x100000 - 0xc0000) >> 10);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700143
144 chromeos_reserve_ram_oops(dev, index++);
145}
146
147static struct device_operations nc_ops = {
Lee Leahy32471722015-04-20 15:20:28 -0700148 .acpi_fill_ssdt_generator = generate_cpu_entries,
149 .read_resources = nc_read_resources,
150 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700151};
152
153static const struct pci_driver nc_driver __pci_driver = {
154 .ops = &nc_ops,
155 .vendor = PCI_VENDOR_ID_INTEL,
156 .device = SOC_DEVID,
157};