blob: b119e243fec323f9a8938c94fe218ebf866b98f8 [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.
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 <console/console.h>
21#include <cpu/x86/smm.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
Kein Yuan35110232014-02-22 12:26:55 -080025#include <vendorcode/google/chromeos/chromeos.h>
Aaron Durbin191570d2013-09-24 12:41:08 -050026
Duncan Laurie1f52f512013-11-04 17:02:45 -080027#include <baytrail/iomap.h>
Aaron Durbin191570d2013-09-24 12:41:08 -050028#include <baytrail/iosf.h>
29#include <baytrail/pci_devs.h>
30#include <baytrail/ramstage.h>
31
32/* Host Memory Map:
33 *
34 * +--------------------------+ BMBOUND_HI
35 * | Usable DRAM |
36 * +--------------------------+ 4GiB
37 * | PCI Address Space |
38 * +--------------------------+ BMBOUND
39 * | TPM |
40 * +--------------------------+ IMR2
41 * | TXE |
42 * +--------------------------+ IMR1
43 * | iGD |
44 * +--------------------------+
45 * | GTT |
46 * +--------------------------+ SMMRRH, IRM0
47 * | TSEG |
48 * +--------------------------+ SMMRRL
49 * | Usable DRAM |
50 * +--------------------------+ 0
51 *
52 * Note that there are really only a few regions that need to enumerated w.r.t.
53 * coreboot's resrouce model:
54 *
55 * +--------------------------+ BMBOUND_HI
56 * | Cacheable/Usable |
57 * +--------------------------+ 4GiB
58 *
59 * +--------------------------+ BMBOUND
60 * | Uncacheable/Reserved |
61 * +--------------------------+ SMMRRH
62 * | Cacheable/Reserved |
63 * +--------------------------+ SMMRRL
64 * | Cacheable/Usable |
65 * +--------------------------+ 0
66 */
67#define RES_IN_KiB(r) ((r) >> 10)
68
Duncan Laurie1f52f512013-11-04 17:02:45 -080069uint32_t nc_read_top_of_low_memory(void)
70{
71 return iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
72}
73
Aaron Durbineb2eedf2013-10-25 09:12:45 -050074static void nc_read_resources(device_t dev)
Aaron Durbin191570d2013-09-24 12:41:08 -050075{
76 unsigned long mmconf;
77 unsigned long bmbound;
78 unsigned long bmbound_hi;
79 unsigned long smmrrh;
80 unsigned long smmrrl;
81 unsigned long base_k, size_k;
82 const unsigned long four_gig_kib = (4 << (30 - 10));
83 int index = 0;
84
85 /* Read standard PCI resources. */
86 pci_dev_read_resources(dev);
87
88 /* PCIe memory-mapped config space access - 256 MiB. */
89 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
90 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
91
Kein Yuan35110232014-02-22 12:26:55 -080092 /* 0 -> 0xa0000 */
93 base_k = RES_IN_KiB(0);
Aaron Durbin191570d2013-09-24 12:41:08 -050094 size_k = RES_IN_KiB(0xa0000) - base_k;
95 ram_resource(dev, index++, base_k, size_k);
96
97 /* The SMMRR registers are 1MiB granularity with smmrrh being
98 * inclusive of the SMM region. */
99 smmrrl = (iosf_bunit_read(BUNIT_SMRRL) & 0xffff) << 10;
100 smmrrh = ((iosf_bunit_read(BUNIT_SMRRH) & 0xffff) + 1) << 10;
101
102 /* 0xc0000 -> smrrl - cacheable and usable */
103 base_k = RES_IN_KiB(0xc0000);
104 size_k = smmrrl - base_k;
105 ram_resource(dev, index++, base_k, size_k);
106
107 if (smmrrh > smmrrl)
108 reserved_ram_resource(dev, index++, smmrrl, smmrrh - smmrrl);
109
110 /* All address space between bmbound and smmrrh is unusable. */
Duncan Laurie1f52f512013-11-04 17:02:45 -0800111 bmbound = RES_IN_KiB(nc_read_top_of_low_memory());
Aaron Durbin191570d2013-09-24 12:41:08 -0500112 mmio_resource(dev, index++, smmrrh, bmbound - smmrrh);
113
114 /* The BMBOUND_HI register matches register bits of 31:24 with address
115 * bits of 35:28. Therefore, shift register to align properly. */
116 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
117 bmbound_hi = RES_IN_KiB(bmbound_hi) << 4;
118 if (bmbound_hi > four_gig_kib)
119 ram_resource(dev, index++, four_gig_kib,
120 bmbound_hi - four_gig_kib);
Duncan Lauriee7e78d62013-11-03 19:38:12 -0800121
122 /* Reserve everything between A segment and 1MB:
123 *
124 * 0xa0000 - 0xbffff: legacy VGA
125 * 0xc0000 - 0xfffff: RAM
126 */
127 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
128 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
129 (0x100000 - 0xc0000) >> 10);
Kein Yuan35110232014-02-22 12:26:55 -0800130
131 chromeos_reserve_ram_oops(dev, index++);
Aaron Durbin191570d2013-09-24 12:41:08 -0500132}
133
Aaron Durbin191570d2013-09-24 12:41:08 -0500134static struct device_operations nc_ops = {
135 .read_resources = nc_read_resources,
136 .set_resources = NULL,
137 .enable_resources = NULL,
138 .init = NULL,
139 .enable = NULL,
140 .scan_bus = NULL,
141 .ops_pci = &soc_pci_ops,
142};
143
144static const struct pci_driver nc_driver __pci_driver = {
145 .ops = &nc_ops,
146 .vendor = PCI_VENDOR_ID_INTEL,
147 .device = SOC_DEVID,
148};