2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 Arastra, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
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.
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
21 /* This code is based on src/northbridge/intel/e7520/northbridge.c */
23 #include <console/console.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <device/pci_ids.h>
29 #include <device/hypertransport.h>
40 static void ram_resource(device_t dev, u32 index,
43 struct resource *resource;
45 resource = new_resource(dev, index);
46 resource->base = ((resource_t)basek) << 10;
47 resource->size = ((resource_t)sizek) << 10;
48 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
49 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
52 static void tolm_test(void *gp, struct device *dev, struct resource *new)
54 struct resource **best_p = gp;
55 struct resource *best;
57 if (!best || (best->base > new->base)) {
63 static u32 find_pci_tolm(struct bus *bus)
68 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
70 if (min && tolm > min->base) {
76 #if CONFIG_WRITE_HIGH_TABLES==1
77 #define HIGH_TABLES_SIZE 64 // maximum size of high tables in KB
78 extern uint64_t high_tables_base, high_tables_size;
81 static void pci_domain_set_resources(device_t dev)
86 pci_tolm = find_pci_tolm(dev->link_list);
89 printk(BIOS_DEBUG, "PCI mem marker = %x\n", pci_tolm);
91 /* FIXME Me temporary hack */
92 if(pci_tolm > 0xe0000000)
93 pci_tolm = 0xe0000000;
94 /* Ensure pci_tolm is 128M aligned */
95 pci_tolm &= 0xf8000000;
96 mc_dev = dev->link_list->children;
98 /* Figure out which areas are/should be occupied by RAM.
99 * This is all computed in kilobytes and converted to/from
100 * the memory controller right at the edges.
101 * Having different variables in different units is
102 * too confusing to get right. Kilobytes are good up to
103 * 4 Terabytes of RAM...
105 u16 tolm_r, remapbase_r, remaplimit_r, remapoffset_r;
107 u32 remapbasek, remaplimitk, remapoffsetk;
109 /* Get the Top of Memory address, units are 128M */
110 tomk = ((u32)pci_read_config16(mc_dev, TOM)) << 17;
111 /* Compute the Top of Low Memory */
112 tolmk = (pci_tolm & 0xf8000000) >> 10;
115 /* The PCI hole does not overlap memory
116 * we won't use the remap window.
119 remapbasek = 0x3ff << 16;
120 remaplimitk = 0 << 16;
121 remapoffsetk = 0 << 16;
124 /* The PCI memory hole overlaps memory
125 * setup the remap window.
127 /* Find the bottom of the remap window
130 remapbasek = 4*1024*1024;
131 if (tomk > remapbasek) {
134 /* Find the limit of the remap window */
135 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
136 /* Find the offset of the remap window from tolm */
137 remapoffsetk = remapbasek - tolmk;
139 /* Write the ram configruation registers,
140 * preserving the reserved bits.
142 tolm_r = pci_read_config16(mc_dev, 0xc4);
143 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
144 pci_write_config16(mc_dev, 0xc4, tolm_r);
146 remapbase_r = pci_read_config16(mc_dev, 0xc6);
147 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
148 pci_write_config16(mc_dev, 0xc6, remapbase_r);
150 remaplimit_r = pci_read_config16(mc_dev, 0xc8);
151 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
152 pci_write_config16(mc_dev, 0xc8, remaplimit_r);
154 remapoffset_r = pci_read_config16(mc_dev, 0xca);
155 remapoffset_r = (remapoffsetk >> 16) | (remapoffset_r & 0xfc00);
156 pci_write_config16(mc_dev, 0xca, remapoffset_r);
158 /* Report the memory regions */
159 ram_resource(dev, 3, 0, 640);
160 ram_resource(dev, 4, 768, (tolmk - 768));
161 if (tomk > 4*1024*1024) {
162 ram_resource(dev, 5, 4096*1024, tomk - 4*1024*1024);
164 if (remaplimitk >= remapbasek) {
165 ram_resource(dev, 6, remapbasek,
166 (remaplimitk + 64*1024) - remapbasek);
169 #if CONFIG_WRITE_HIGH_TABLES==1
170 /* Leave some space for ACPI, PIRQ and MP tables */
171 high_tables_base = (tolmk - HIGH_TABLES_SIZE) * 1024;
172 high_tables_size = HIGH_TABLES_SIZE * 1024;
175 assign_resources(dev->link_list);
178 static u32 i3100_domain_scan_bus(device_t dev, u32 max)
180 max_bus = pci_domain_scan_bus(dev, max);
184 static struct device_operations pci_domain_ops = {
185 .read_resources = pci_domain_read_resources,
186 .set_resources = pci_domain_set_resources,
187 .enable_resources = NULL,
189 .scan_bus = i3100_domain_scan_bus,
190 .ops_pci_bus = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */
193 static void mc_read_resources(device_t dev)
195 struct resource *resource;
197 pci_dev_read_resources(dev);
199 resource = new_resource(dev, 0xcf);
200 resource->base = 0xe0000000;
201 resource->size = max_bus * 4096*256;
202 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
205 static void mc_set_resources(device_t dev)
207 struct resource *resource;
209 resource = find_resource(dev, 0xcf);
211 report_resource_stored(dev, resource, "<mmconfig>");
213 pci_dev_set_resources(dev);
216 static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
218 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
219 ((device & 0xffff) << 16) | (vendor & 0xffff));
222 static struct pci_operations intel_pci_ops = {
223 .set_subsystem = intel_set_subsystem,
226 static struct device_operations mc_ops = {
227 .read_resources = mc_read_resources,
228 .set_resources = mc_set_resources,
229 .enable_resources = pci_dev_enable_resources,
232 .ops_pci = &intel_pci_ops,
235 static const struct pci_driver mc_driver __pci_driver = {
237 .vendor = PCI_VENDOR_ID_INTEL,
238 .device = PCI_DEVICE_ID_INTEL_3100_MC,
241 static void cpu_bus_init(device_t dev)
243 initialize_cpus(dev->link_list);
246 static void cpu_bus_noop(device_t dev)
250 static struct device_operations cpu_bus_ops = {
251 .read_resources = cpu_bus_noop,
252 .set_resources = cpu_bus_noop,
253 .enable_resources = cpu_bus_noop,
254 .init = cpu_bus_init,
259 static void enable_dev(device_t dev)
261 /* Set the operations if it is a special bus type */
262 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
263 dev->ops = &pci_domain_ops;
265 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
266 dev->ops = &cpu_bus_ops;
270 struct chip_operations northbridge_intel_i3100_ops = {
271 CHIP_NAME("Intel 3100 Northbridge")
272 .enable_dev = enable_dev,