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
44 static void pci_domain_set_resources(device_t dev)
49 pci_tolm = find_pci_tolm(dev->link_list);
52 printk(BIOS_DEBUG, "PCI mem marker = %x\n", pci_tolm);
54 /* FIXME Me temporary hack */
55 if(pci_tolm > 0xe0000000)
56 pci_tolm = 0xe0000000;
57 /* Ensure pci_tolm is 128M aligned */
58 pci_tolm &= 0xf8000000;
59 mc_dev = dev->link_list->children;
61 /* Figure out which areas are/should be occupied by RAM.
62 * This is all computed in kilobytes and converted to/from
63 * the memory controller right at the edges.
64 * Having different variables in different units is
65 * too confusing to get right. Kilobytes are good up to
66 * 4 Terabytes of RAM...
68 u16 tolm_r, remapbase_r, remaplimit_r, remapoffset_r;
70 u32 remapbasek, remaplimitk, remapoffsetk;
72 /* Get the Top of Memory address, units are 128M */
73 tomk = ((u32)pci_read_config16(mc_dev, TOM)) << 17;
74 /* Compute the Top of Low Memory */
75 tolmk = (pci_tolm & 0xf8000000) >> 10;
78 /* The PCI hole does not overlap memory
79 * we won't use the remap window.
82 remapbasek = 0x3ff << 16;
83 remaplimitk = 0 << 16;
84 remapoffsetk = 0 << 16;
87 /* The PCI memory hole overlaps memory
88 * setup the remap window.
90 /* Find the bottom of the remap window
93 remapbasek = 4*1024*1024;
94 if (tomk > remapbasek) {
97 /* Find the limit of the remap window */
98 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
99 /* Find the offset of the remap window from tolm */
100 remapoffsetk = remapbasek - tolmk;
102 /* Write the ram configruation registers,
103 * preserving the reserved bits.
105 tolm_r = pci_read_config16(mc_dev, 0xc4);
106 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
107 pci_write_config16(mc_dev, 0xc4, tolm_r);
109 remapbase_r = pci_read_config16(mc_dev, 0xc6);
110 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
111 pci_write_config16(mc_dev, 0xc6, remapbase_r);
113 remaplimit_r = pci_read_config16(mc_dev, 0xc8);
114 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
115 pci_write_config16(mc_dev, 0xc8, remaplimit_r);
117 remapoffset_r = pci_read_config16(mc_dev, 0xca);
118 remapoffset_r = (remapoffsetk >> 16) | (remapoffset_r & 0xfc00);
119 pci_write_config16(mc_dev, 0xca, remapoffset_r);
121 /* Report the memory regions */
122 ram_resource(dev, 3, 0, 640);
123 ram_resource(dev, 4, 768, (tolmk - 768));
124 if (tomk > 4*1024*1024) {
125 ram_resource(dev, 5, 4096*1024, tomk - 4*1024*1024);
127 if (remaplimitk >= remapbasek) {
128 ram_resource(dev, 6, remapbasek,
129 (remaplimitk + 64*1024) - remapbasek);
132 #if CONFIG_WRITE_HIGH_TABLES==1
133 /* Leave some space for ACPI, PIRQ and MP tables */
134 high_tables_base = (tolmk * 1024) - HIGH_MEMORY_SIZE;
135 high_tables_size = HIGH_MEMORY_SIZE;
138 assign_resources(dev->link_list);
141 static u32 i3100_domain_scan_bus(device_t dev, u32 max)
143 max_bus = pci_domain_scan_bus(dev, max);
147 static struct device_operations pci_domain_ops = {
148 .read_resources = pci_domain_read_resources,
149 .set_resources = pci_domain_set_resources,
150 .enable_resources = NULL,
152 .scan_bus = i3100_domain_scan_bus,
153 .ops_pci_bus = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */
156 static void mc_read_resources(device_t dev)
158 struct resource *resource;
160 pci_dev_read_resources(dev);
162 resource = new_resource(dev, 0xcf);
163 resource->base = 0xe0000000;
164 resource->size = max_bus * 4096*256;
165 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
168 static void mc_set_resources(device_t dev)
170 struct resource *resource;
172 resource = find_resource(dev, 0xcf);
174 report_resource_stored(dev, resource, "<mmconfig>");
176 pci_dev_set_resources(dev);
179 static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
181 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
182 ((device & 0xffff) << 16) | (vendor & 0xffff));
185 static struct pci_operations intel_pci_ops = {
186 .set_subsystem = intel_set_subsystem,
189 static struct device_operations mc_ops = {
190 .read_resources = mc_read_resources,
191 .set_resources = mc_set_resources,
192 .enable_resources = pci_dev_enable_resources,
195 .ops_pci = &intel_pci_ops,
198 static const struct pci_driver mc_driver __pci_driver = {
200 .vendor = PCI_VENDOR_ID_INTEL,
201 .device = PCI_DEVICE_ID_INTEL_3100_MC,
204 static void cpu_bus_init(device_t dev)
206 initialize_cpus(dev->link_list);
209 static void cpu_bus_noop(device_t dev)
213 static struct device_operations cpu_bus_ops = {
214 .read_resources = cpu_bus_noop,
215 .set_resources = cpu_bus_noop,
216 .enable_resources = cpu_bus_noop,
217 .init = cpu_bus_init,
222 static void enable_dev(device_t dev)
224 /* Set the operations if it is a special bus type */
225 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
226 dev->ops = &pci_domain_ops;
228 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
229 dev->ops = &cpu_bus_ops;
233 struct chip_operations northbridge_intel_i3100_ops = {
234 CHIP_NAME("Intel 3100 Northbridge")
235 .enable_dev = enable_dev,