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