blob: 772ab1c8f3d98853cb81004806c061cd13b5bd81 [file] [log] [blame]
Richard Smithcb8eab42006-07-24 04:25:47 +00001#include <console/console.h>
2#include <arch/io.h>
3#include <stdint.h>
4#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
7#include <stdlib.h>
8#include <string.h>
9#include <bitops.h>
Corey Osgoode562f722008-12-19 03:36:48 +000010#include <cpu/cpu.h>
11#include <pc80/keyboard.h>
Richard Smithcb8eab42006-07-24 04:25:47 +000012#include "chip.h"
13#include "northbridge.h"
Uwe Hermann1a9c8922007-04-01 17:24:03 +000014#include "i440bx.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000015
Myles Watson032a9652009-05-11 22:24:53 +000016static void northbridge_init(device_t dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000017{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000018 printk(BIOS_SPEW, "Northbridge Init\n");
Richard Smithcb8eab42006-07-24 04:25:47 +000019}
20
Richard Smithcb8eab42006-07-24 04:25:47 +000021static struct device_operations northbridge_operations = {
22 .read_resources = pci_dev_read_resources,
23 .set_resources = pci_dev_set_resources,
24 .enable_resources = pci_dev_enable_resources,
25 .init = northbridge_init,
26 .enable = 0,
27 .ops_pci = 0,
28};
29
Stefan Reinauerf1cf1f72007-10-24 09:08:58 +000030static const struct pci_driver northbridge_driver __pci_driver = {
Richard Smithcb8eab42006-07-24 04:25:47 +000031 .ops = &northbridge_operations,
32 .vendor = PCI_VENDOR_ID_INTEL,
Myles Watson032a9652009-05-11 22:24:53 +000033 .device = 0x7190,
Richard Smithcb8eab42006-07-24 04:25:47 +000034};
35
Richard Smithcb8eab42006-07-24 04:25:47 +000036static void ram_resource(device_t dev, unsigned long index,
Myles Watson032a9652009-05-11 22:24:53 +000037 unsigned long basek, unsigned long sizek)
Richard Smithcb8eab42006-07-24 04:25:47 +000038{
Myles Watson032a9652009-05-11 22:24:53 +000039 struct resource *resource;
Richard Smithcb8eab42006-07-24 04:25:47 +000040
Myles Watson032a9652009-05-11 22:24:53 +000041 if (!sizek) {
42 return;
43 }
44 resource = new_resource(dev, index);
45 resource->base = ((resource_t)basek) << 10;
46 resource->size = ((resource_t)sizek) << 10;
47 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
48 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
Richard Smithcb8eab42006-07-24 04:25:47 +000049}
50
51static void tolm_test(void *gp, struct device *dev, struct resource *new)
52{
53 struct resource **best_p = gp;
54 struct resource *best;
55 best = *best_p;
56 if (!best || (best->base > new->base)) {
57 best = new;
58 }
59 *best_p = best;
60}
61
62static uint32_t find_pci_tolm(struct bus *bus)
63{
64 struct resource *min;
65 uint32_t tolm;
66 min = 0;
67 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
68 tolm = 0xffffffffUL;
69 if (min && tolm > min->base) {
70 tolm = min->base;
71 }
72 return tolm;
73}
74
Myles Watsonb8e20272009-10-15 13:35:47 +000075#if CONFIG_WRITE_HIGH_TABLES==1
Stefan Reinauerb5fb0c52009-04-30 13:58:42 +000076#define HIGH_TABLES_SIZE 64 // maximum size of high tables in KB
77extern uint64_t high_tables_base, high_tables_size;
78#endif
Myles Watson032a9652009-05-11 22:24:53 +000079
Myles Watson29cc9ed2009-07-02 18:56:24 +000080static void i440bx_domain_set_resources(device_t dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000081{
Richard Smithcb8eab42006-07-24 04:25:47 +000082 device_t mc_dev;
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000083 uint32_t pci_tolm;
Richard Smithcb8eab42006-07-24 04:25:47 +000084
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000085 pci_tolm = find_pci_tolm(&dev->link[0]);
Richard Smithcb8eab42006-07-24 04:25:47 +000086 mc_dev = dev->link[0].children;
87 if (mc_dev) {
88 unsigned long tomk, tolmk;
Uwe Hermann1a9c8922007-04-01 17:24:03 +000089 int idx;
Richard Smithcb8eab42006-07-24 04:25:47 +000090
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000091 /* Figure out which areas are/should be occupied by RAM. The
92 * value of the highest DRB denotes the end of the physical
93 * memory (in units of 8MB).
Uwe Hermann1a9c8922007-04-01 17:24:03 +000094 */
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000095 tomk = ((unsigned long)pci_read_config8(mc_dev, DRB7));
Uwe Hermannf03e4e92007-05-10 23:59:20 +000096
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000097 /* Convert to KB. */
98 tomk *= (8 * 1024);
99
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000100 printk(BIOS_DEBUG, "Setting RAM size to %ld MB\n", tomk / 1024);
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000101
102 /* Compute the top of low memory. */
103 tolmk = pci_tolm / 1024;
104
Richard Smithcb8eab42006-07-24 04:25:47 +0000105 if (tolmk >= tomk) {
Myles Watson032a9652009-05-11 22:24:53 +0000106 /* The PCI hole does not overlap the memory. */
Richard Smithcb8eab42006-07-24 04:25:47 +0000107 tolmk = tomk;
108 }
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000109
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000110 /* Report the memory regions. */
Richard Smithcb8eab42006-07-24 04:25:47 +0000111 idx = 10;
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000112 ram_resource(dev, idx++, 0, 640);
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000113 ram_resource(dev, idx++, 768, tolmk - 768);
Myles Watson032a9652009-05-11 22:24:53 +0000114
Myles Watsonb8e20272009-10-15 13:35:47 +0000115#if CONFIG_WRITE_HIGH_TABLES==1
Stefan Reinauerb5fb0c52009-04-30 13:58:42 +0000116 /* Leave some space for ACPI, PIRQ and MP tables */
117 high_tables_base = (tomk - HIGH_TABLES_SIZE) * 1024;
118 high_tables_size = HIGH_TABLES_SIZE * 1024;
119#endif
Richard Smithcb8eab42006-07-24 04:25:47 +0000120 }
121 assign_resources(&dev->link[0]);
122}
123
Richard Smithcb8eab42006-07-24 04:25:47 +0000124static struct device_operations pci_domain_ops = {
Myles Watson032a9652009-05-11 22:24:53 +0000125 .read_resources = pci_domain_read_resources,
Myles Watson29cc9ed2009-07-02 18:56:24 +0000126 .set_resources = i440bx_domain_set_resources,
Myles Watson032a9652009-05-11 22:24:53 +0000127 .enable_resources = enable_childrens_resources,
128 .init = 0,
129 .scan_bus = pci_domain_scan_bus,
130};
Richard Smithcb8eab42006-07-24 04:25:47 +0000131
132static void cpu_bus_init(device_t dev)
133{
Myles Watson032a9652009-05-11 22:24:53 +0000134 initialize_cpus(&dev->link[0]);
Richard Smithcb8eab42006-07-24 04:25:47 +0000135}
136
137static void cpu_bus_noop(device_t dev)
138{
139}
140
141static struct device_operations cpu_bus_ops = {
Myles Watson032a9652009-05-11 22:24:53 +0000142 .read_resources = cpu_bus_noop,
143 .set_resources = cpu_bus_noop,
144 .enable_resources = cpu_bus_noop,
145 .init = cpu_bus_init,
146 .scan_bus = 0,
Richard Smithcb8eab42006-07-24 04:25:47 +0000147};
148
149static void enable_dev(struct device *dev)
150{
Myles Watson032a9652009-05-11 22:24:53 +0000151 /* Set the operations if it is a special bus type */
152 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
153 dev->ops = &pci_domain_ops;
Richard Smithcb8eab42006-07-24 04:25:47 +0000154 pci_set_method(dev);
Myles Watson032a9652009-05-11 22:24:53 +0000155 }
156 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
157 dev->ops = &cpu_bus_ops;
158 }
Richard Smithcb8eab42006-07-24 04:25:47 +0000159}
160
161struct chip_operations northbridge_intel_i440bx_ops = {
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000162 CHIP_NAME("Intel 82443BX (440BX) Northbridge")
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000163 .enable_dev = enable_dev,
Richard Smithcb8eab42006-07-24 04:25:47 +0000164};