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