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 #if CONFIG_WRITE_HIGH_TABLES==1
41 #define HIGH_TABLES_SIZE 64 // maximum size of high tables in KB
42 extern uint64_t high_tables_base, high_tables_size;
45 static void pci_domain_set_resources(device_t dev)
50 pci_tolm = find_pci_tolm(dev->link_list);
53 printk(BIOS_DEBUG, "PCI mem marker = %x\n", pci_tolm);
55 /* FIXME Me temporary hack */
56 if(pci_tolm > 0xe0000000)
57 pci_tolm = 0xe0000000;
58 /* Ensure pci_tolm is 128M aligned */
59 pci_tolm &= 0xf8000000;
60 mc_dev = dev->link_list->children;
62 /* Figure out which areas are/should be occupied by RAM.
63 * This is all computed in kilobytes and converted to/from
64 * the memory controller right at the edges.
65 * Having different variables in different units is
66 * too confusing to get right. Kilobytes are good up to
67 * 4 Terabytes of RAM...
69 u16 tolm_r, remapbase_r, remaplimit_r, remapoffset_r;
71 u32 remapbasek, remaplimitk, remapoffsetk;
73 /* Get the Top of Memory address, units are 128M */
74 tomk = ((u32)pci_read_config16(mc_dev, TOM)) << 17;
75 /* Compute the Top of Low Memory */
76 tolmk = (pci_tolm & 0xf8000000) >> 10;
79 /* The PCI hole does not overlap memory
80 * we won't use the remap window.
83 remapbasek = 0x3ff << 16;
84 remaplimitk = 0 << 16;
85 remapoffsetk = 0 << 16;
88 /* The PCI memory hole overlaps memory
89 * setup the remap window.
91 /* Find the bottom of the remap window
94 remapbasek = 4*1024*1024;
95 if (tomk > remapbasek) {
98 /* Find the limit of the remap window */
99 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
100 /* Find the offset of the remap window from tolm */
101 remapoffsetk = remapbasek - tolmk;
103 /* Write the ram configruation registers,
104 * preserving the reserved bits.
106 tolm_r = pci_read_config16(mc_dev, 0xc4);
107 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
108 pci_write_config16(mc_dev, 0xc4, tolm_r);
110 remapbase_r = pci_read_config16(mc_dev, 0xc6);
111 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
112 pci_write_config16(mc_dev, 0xc6, remapbase_r);
114 remaplimit_r = pci_read_config16(mc_dev, 0xc8);
115 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
116 pci_write_config16(mc_dev, 0xc8, remaplimit_r);
118 remapoffset_r = pci_read_config16(mc_dev, 0xca);
119 remapoffset_r = (remapoffsetk >> 16) | (remapoffset_r & 0xfc00);
120 pci_write_config16(mc_dev, 0xca, remapoffset_r);
122 /* Report the memory regions */
123 ram_resource(dev, 3, 0, 640);
124 ram_resource(dev, 4, 768, (tolmk - 768));
125 if (tomk > 4*1024*1024) {
126 ram_resource(dev, 5, 4096*1024, tomk - 4*1024*1024);
128 if (remaplimitk >= remapbasek) {
129 ram_resource(dev, 6, remapbasek,
130 (remaplimitk + 64*1024) - remapbasek);
133 #if CONFIG_WRITE_HIGH_TABLES==1
134 /* Leave some space for ACPI, PIRQ and MP tables */
135 high_tables_base = (tolmk - HIGH_TABLES_SIZE) * 1024;
136 high_tables_size = HIGH_TABLES_SIZE * 1024;
139 assign_resources(dev->link_list);
142 static u32 i3100_domain_scan_bus(device_t dev, u32 max)
144 max_bus = pci_domain_scan_bus(dev, max);
148 static struct device_operations pci_domain_ops = {
149 .read_resources = pci_domain_read_resources,
150 .set_resources = pci_domain_set_resources,
151 .enable_resources = NULL,
153 .scan_bus = i3100_domain_scan_bus,
154 .ops_pci_bus = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */
157 static void mc_read_resources(device_t dev)
159 struct resource *resource;
161 pci_dev_read_resources(dev);
163 resource = new_resource(dev, 0xcf);
164 resource->base = 0xe0000000;
165 resource->size = max_bus * 4096*256;
166 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
169 static void mc_set_resources(device_t dev)
171 struct resource *resource;
173 resource = find_resource(dev, 0xcf);
175 report_resource_stored(dev, resource, "<mmconfig>");
177 pci_dev_set_resources(dev);
180 static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
182 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
183 ((device & 0xffff) << 16) | (vendor & 0xffff));
186 static struct pci_operations intel_pci_ops = {
187 .set_subsystem = intel_set_subsystem,
190 static struct device_operations mc_ops = {
191 .read_resources = mc_read_resources,
192 .set_resources = mc_set_resources,
193 .enable_resources = pci_dev_enable_resources,
196 .ops_pci = &intel_pci_ops,
199 static const struct pci_driver mc_driver __pci_driver = {
201 .vendor = PCI_VENDOR_ID_INTEL,
202 .device = PCI_DEVICE_ID_INTEL_3100_MC,
205 static void cpu_bus_init(device_t dev)
207 initialize_cpus(dev->link_list);
210 static void cpu_bus_noop(device_t dev)
214 static struct device_operations cpu_bus_ops = {
215 .read_resources = cpu_bus_noop,
216 .set_resources = cpu_bus_noop,
217 .enable_resources = cpu_bus_noop,
218 .init = cpu_bus_init,
223 static void enable_dev(device_t dev)
225 /* Set the operations if it is a special bus type */
226 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
227 dev->ops = &pci_domain_ops;
229 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
230 dev->ops = &cpu_bus_ops;
234 struct chip_operations northbridge_intel_i3100_ops = {
235 CHIP_NAME("Intel 3100 Northbridge")
236 .enable_dev = enable_dev,