blob: 0869c7b656bb677b0959efb2c9885a1bed1582b8 [file] [log] [blame]
Aaron Durbin191570d2013-09-24 12:41:08 -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 warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Aaron Durbin191570d2013-09-24 12:41:08 -050014 */
15
Aaron Durbin191570d2013-09-24 12:41:08 -050016#include <cpu/x86/smm.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
Kein Yuan35110232014-02-22 12:26:55 -080020#include <vendorcode/google/chromeos/chromeos.h>
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +020021#include <arch/acpi.h>
Matt DeVillierf05d2e12017-06-06 23:56:18 -050022#include <stddef.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070023#include <soc/iomap.h>
24#include <soc/iosf.h>
25#include <soc/pci_devs.h>
26#include <soc/ramstage.h>
Aaron Durbin191570d2013-09-24 12:41:08 -050027
28/* Host Memory Map:
29 *
30 * +--------------------------+ BMBOUND_HI
31 * | Usable DRAM |
32 * +--------------------------+ 4GiB
33 * | PCI Address Space |
34 * +--------------------------+ BMBOUND
35 * | TPM |
36 * +--------------------------+ IMR2
37 * | TXE |
38 * +--------------------------+ IMR1
39 * | iGD |
40 * +--------------------------+
41 * | GTT |
42 * +--------------------------+ SMMRRH, IRM0
43 * | TSEG |
44 * +--------------------------+ SMMRRL
45 * | Usable DRAM |
46 * +--------------------------+ 0
47 *
48 * Note that there are really only a few regions that need to enumerated w.r.t.
Martin Roth99a3bba2014-12-07 14:57:26 -070049 * coreboot's resource model:
Aaron Durbin191570d2013-09-24 12:41:08 -050050 *
51 * +--------------------------+ BMBOUND_HI
52 * | Cacheable/Usable |
53 * +--------------------------+ 4GiB
54 *
55 * +--------------------------+ BMBOUND
56 * | Uncacheable/Reserved |
57 * +--------------------------+ SMMRRH
58 * | Cacheable/Reserved |
59 * +--------------------------+ SMMRRL
60 * | Cacheable/Usable |
61 * +--------------------------+ 0
62 */
63#define RES_IN_KiB(r) ((r) >> 10)
64
Duncan Laurie1f52f512013-11-04 17:02:45 -080065uint32_t nc_read_top_of_low_memory(void)
66{
Matt DeVillierf05d2e12017-06-06 23:56:18 -050067 MAYBE_STATIC uint32_t tolm = 0;
68
69 if (tolm)
70 return tolm;
71
72 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
73
74 return tolm;
Duncan Laurie1f52f512013-11-04 17:02:45 -080075}
76
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020077static void nc_read_resources(struct device *dev)
Aaron Durbin191570d2013-09-24 12:41:08 -050078{
79 unsigned long mmconf;
80 unsigned long bmbound;
81 unsigned long bmbound_hi;
82 unsigned long smmrrh;
83 unsigned long smmrrl;
84 unsigned long base_k, size_k;
85 const unsigned long four_gig_kib = (4 << (30 - 10));
86 int index = 0;
87
88 /* Read standard PCI resources. */
89 pci_dev_read_resources(dev);
90
91 /* PCIe memory-mapped config space access - 256 MiB. */
92 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
93 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
94
Kein Yuan35110232014-02-22 12:26:55 -080095 /* 0 -> 0xa0000 */
96 base_k = RES_IN_KiB(0);
Aaron Durbin191570d2013-09-24 12:41:08 -050097 size_k = RES_IN_KiB(0xa0000) - base_k;
98 ram_resource(dev, index++, base_k, size_k);
99
100 /* The SMMRR registers are 1MiB granularity with smmrrh being
101 * inclusive of the SMM region. */
102 smmrrl = (iosf_bunit_read(BUNIT_SMRRL) & 0xffff) << 10;
103 smmrrh = ((iosf_bunit_read(BUNIT_SMRRH) & 0xffff) + 1) << 10;
104
105 /* 0xc0000 -> smrrl - cacheable and usable */
106 base_k = RES_IN_KiB(0xc0000);
107 size_k = smmrrl - base_k;
108 ram_resource(dev, index++, base_k, size_k);
109
110 if (smmrrh > smmrrl)
111 reserved_ram_resource(dev, index++, smmrrl, smmrrh - smmrrl);
112
113 /* All address space between bmbound and smmrrh is unusable. */
Duncan Laurie1f52f512013-11-04 17:02:45 -0800114 bmbound = RES_IN_KiB(nc_read_top_of_low_memory());
Aaron Durbin191570d2013-09-24 12:41:08 -0500115 mmio_resource(dev, index++, smmrrh, bmbound - smmrrh);
116
117 /* The BMBOUND_HI register matches register bits of 31:24 with address
118 * bits of 35:28. Therefore, shift register to align properly. */
119 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
120 bmbound_hi = RES_IN_KiB(bmbound_hi) << 4;
121 if (bmbound_hi > four_gig_kib)
122 ram_resource(dev, index++, four_gig_kib,
123 bmbound_hi - four_gig_kib);
Duncan Lauriee7e78d62013-11-03 19:38:12 -0800124
125 /* Reserve everything between A segment and 1MB:
126 *
127 * 0xa0000 - 0xbffff: legacy VGA
128 * 0xc0000 - 0xfffff: RAM
129 */
130 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
131 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
132 (0x100000 - 0xc0000) >> 10);
Kein Yuan35110232014-02-22 12:26:55 -0800133
Frans Hendriksef05dc82018-11-27 10:35:16 +0100134 if (IS_ENABLED(CONFIG_CHROMEOS))
135 chromeos_reserve_ram_oops(dev, index++);
Aaron Durbin191570d2013-09-24 12:41:08 -0500136}
137
Aaron Durbin191570d2013-09-24 12:41:08 -0500138static struct device_operations nc_ops = {
139 .read_resources = nc_read_resources,
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200140 .acpi_fill_ssdt_generator = generate_cpu_entries,
Aaron Durbin191570d2013-09-24 12:41:08 -0500141 .set_resources = NULL,
142 .enable_resources = NULL,
143 .init = NULL,
144 .enable = NULL,
145 .scan_bus = NULL,
146 .ops_pci = &soc_pci_ops,
147};
148
149static const struct pci_driver nc_driver __pci_driver = {
150 .ops = &nc_ops,
151 .vendor = PCI_VENDOR_ID_INTEL,
152 .device = SOC_DEVID,
153};