2 * This file is part of the coreboot project.
4 * Copyright (C) 2003 Ronald G. Minnich
5 * Copyright (C) 2003-2004 Eric W. Biederman
6 * Copyright (C) 2006 Jon Dufresne <jon.dufresne@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <console/console.h>
26 #include <device/device.h>
27 #include <device/pci.h>
31 #include <cpu/x86/cache.h>
34 static void ram_resource(device_t dev, unsigned long index,
35 unsigned long basek, unsigned long sizek)
37 struct resource *resource;
42 resource = new_resource(dev, index);
43 resource->base = ((resource_t)basek) << 10;
44 resource->size = ((resource_t)sizek) << 10;
45 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
46 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
49 static void tolm_test(void *gp, struct device *dev, struct resource *new)
51 struct resource **best_p = gp;
52 struct resource *best;
54 if (!best || (best->base > new->base)) {
60 static uint32_t find_pci_tolm(struct bus *bus)
65 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
67 if (min && tolm > min->base) {
73 #if CONFIG_HAVE_HIGH_TABLES==1
74 #define HIGH_TABLES_SIZE 64 // maximum size of high tables in KB
75 extern uint64_t high_tables_base, high_tables_size;
77 static void pci_domain_set_resources(device_t dev)
82 printk_debug("Entered with dev vid = %x\n", dev->vendor);
83 printk_debug("Entered with dev did = %x\n", dev->device);
85 pci_tolm = find_pci_tolm(&dev->link[0]);
86 mc_dev = dev->link[0].children->sibling;
87 printk_debug("MC dev vendor = %x\n", mc_dev->vendor);
88 printk_debug("MC dev device = %x\n", mc_dev->device);
91 /* Figure out which areas are/should be occupied by RAM.
92 * This is all computed in kilobytes and converted to/from
93 * the memory controller right at the edges.
94 * Having different variables in different units is
95 * too confusing to get right. Kilobytes are good up to
96 * 4 Terabytes of RAM...
98 uint16_t tolm_r, vga_mem;
99 unsigned long tomk, tolmk;
100 unsigned long remapbasek, remaplimitk;
103 /* Get the value of the highest DRB. This tells the end of
104 * the physical memory. The units are ticks of 32MB
107 tomk = (unsigned long)pci_read_config8(mc_dev, 0x43);
108 tomk = tomk * 32 * 1024;
109 /* add vga_mem detection */
110 tomk = tomk - 16 * 1024;
111 /* Compute the top of Low memory */
112 tolmk = pci_tolm >> 10;
114 /* The PCI hole does not overlap memory
118 /* Write the ram configuration registers,
119 * preserving the reserved bits.
122 /* Report the memory regions */
123 printk_debug("tomk = %d\n", tomk);
124 printk_debug("tolmk = %d\n", tolmk);
127 /* avoid pam region */
128 ram_resource(dev, idx++, 0, 640);
129 /* ram_resource(dev, idx++, 1024, tolmk - 1024); */
130 ram_resource(dev, idx++, 768, tolmk - 768);
132 #if CONFIG_HAVE_HIGH_TABLES==1
133 /* Leave some space for ACPI, PIRQ and MP tables */
134 high_tables_base = (tomk - HIGH_TABLES_SIZE) * 1024;
135 high_tables_size = HIGH_TABLES_SIZE * 1024;
138 assign_resources(&dev->link[0]);
141 static struct device_operations pci_domain_ops = {
142 .read_resources = pci_domain_read_resources,
143 .set_resources = pci_domain_set_resources,
144 .enable_resources = enable_childrens_resources,
146 .scan_bus = pci_domain_scan_bus,
149 static void cpu_bus_init(device_t dev)
151 initialize_cpus(&dev->link[0]);
154 static void cpu_bus_noop(device_t dev)
158 static struct device_operations cpu_bus_ops = {
159 .read_resources = cpu_bus_noop,
160 .set_resources = cpu_bus_noop,
161 .enable_resources = cpu_bus_noop,
162 .init = cpu_bus_init,
166 static void enable_dev(struct device *dev)
168 struct device_path path;
170 /* Set the operations if it is a special bus type */
171 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
172 dev->ops = &pci_domain_ops;
175 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
176 dev->ops = &cpu_bus_ops;
180 struct chip_operations northbridge_intel_i855gme_ops = {
181 CHIP_NAME("Intel 855GME Northbridge")
182 .enable_dev = enable_dev,