1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
11 #include "northbridge.h"
14 static void northbridge_init(device_t dev)
16 printk_spew("Northbridge Init\n");
19 static struct device_operations northbridge_operations = {
20 .read_resources = pci_dev_read_resources,
21 .set_resources = pci_dev_set_resources,
22 .enable_resources = pci_dev_enable_resources,
23 .init = northbridge_init,
28 static struct pci_driver northbridge_driver __pci_driver = {
29 .ops = &northbridge_operations,
30 .vendor = PCI_VENDOR_ID_INTEL,
35 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM)
37 static void pci_domain_read_resources(device_t dev)
39 struct resource *resource;
42 /* Initialize the system wide io space constraints */
43 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
44 resource->limit = 0xffffUL;
45 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
47 /* Initialize the system wide memory resources constraints */
48 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
49 resource->limit = 0xffffffffULL;
50 resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
53 static void ram_resource(device_t dev, unsigned long index,
54 unsigned long basek, unsigned long sizek)
56 struct resource *resource;
61 resource = new_resource(dev, index);
62 resource->base = ((resource_t)basek) << 10;
63 resource->size = ((resource_t)sizek) << 10;
64 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
65 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
68 static void tolm_test(void *gp, struct device *dev, struct resource *new)
70 struct resource **best_p = gp;
71 struct resource *best;
73 if (!best || (best->base > new->base)) {
79 static uint32_t find_pci_tolm(struct bus *bus)
84 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
86 if (min && tolm > min->base) {
92 static void pci_domain_set_resources(device_t dev)
97 pci_tolm = find_pci_tolm(&dev->link[0]);
98 mc_dev = dev->link[0].children;
101 /* Figure out which areas are/should be occupied by RAM.
102 * This is all computed in kilobytes and converted to/from
103 * the memory controller right at the edges.
104 * Having different variables in different units is
105 * too confusing to get right. Kilobytes are good up to
106 * 4 Terabytes of RAM...
109 unsigned long tomk, tolmk;
112 /* Get the value of the highest DRB. This tells the end of
113 * the physical memory. The units are ticks of 8MB
116 tomk = ((unsigned long)pci_read_config8(mc_dev, DRB7)) << 13;
117 printk_debug("Setting RAM size to %d MB\n", tomk >> 10);
119 /* Compute the top of Low memory */
120 tolmk = pci_tolm >> 10;
122 /* The PCI hole does does not overlap the memory.
127 /* Report the memory regions */
129 ram_resource(dev, idx++, 0, 640);
130 // ram_resource(dev, idx++, 768, tolmk - 768);
131 ram_resource(dev, idx++, 1024, tolmk - 1024);
133 assign_resources(&dev->link[0]);
136 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
138 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
142 static struct device_operations pci_domain_ops = {
143 .read_resources = pci_domain_read_resources,
144 .set_resources = pci_domain_set_resources,
145 .enable_resources = enable_childrens_resources,
147 .scan_bus = pci_domain_scan_bus,
150 static void cpu_bus_init(device_t dev)
152 initialize_cpus(&dev->link[0]);
155 static void cpu_bus_noop(device_t dev)
159 static struct device_operations cpu_bus_ops = {
160 .read_resources = cpu_bus_noop,
161 .set_resources = cpu_bus_noop,
162 .enable_resources = cpu_bus_noop,
163 .init = cpu_bus_init,
167 static void enable_dev(struct device *dev)
169 struct device_path path;
171 /* Set the operations if it is a special bus type */
172 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
173 dev->ops = &pci_domain_ops;
176 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
177 dev->ops = &cpu_bus_ops;
181 struct chip_operations northbridge_intel_i440bx_ops = {
182 CHIP_NAME("Intel 440BX Northbridge")
183 .enable_dev = enable_dev,