blob: 0a8ed5c1d8c6d2e9ad2d9d384ef31385924aa367 [file] [log] [blame]
Stefan Reinauere2b53e12004-06-28 11:59:45 +00001#include <console/console.h>
2#include <arch/io.h>
3#include <stdint.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00004#include <device/device.h>
5#include <device/pci.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00006#include <stdlib.h>
7#include <string.h>
8#include <bitops.h>
9#include "chip.h"
10#include "northbridge.h"
11
Eric Biederman6e53f502004-10-27 08:53:57 +000012#define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM)
13
14static void pci_domain_read_resources(device_t dev)
Stefan Reinauere2b53e12004-06-28 11:59:45 +000015{
Eric Biederman018d8dd2004-11-04 11:04:33 +000016 struct resource *resource;
Stefan Reinauere2b53e12004-06-28 11:59:45 +000017
Eric Biederman018d8dd2004-11-04 11:04:33 +000018 /* Initialize the system wide io space constraints */
19 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0));
20 resource->limit = 0xffffUL;
21 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
Eric Biederman6e53f502004-10-27 08:53:57 +000022
Eric Biederman018d8dd2004-11-04 11:04:33 +000023 /* Initialize the system wide memory resources constraints */
24 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0));
25 resource->limit = 0xffffffffULL;
26 resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
Eric Biederman6e53f502004-10-27 08:53:57 +000027}
28
Stefan Reinauere4932dc2004-11-02 20:33:12 +000029static void ram_resource(device_t dev, unsigned long index,
Eric Biederman018d8dd2004-11-04 11:04:33 +000030 unsigned long basek, unsigned long sizek)
Stefan Reinauere4932dc2004-11-02 20:33:12 +000031{
Eric Biederman018d8dd2004-11-04 11:04:33 +000032 struct resource *resource;
Stefan Reinauere4932dc2004-11-02 20:33:12 +000033
Eric Biederman018d8dd2004-11-04 11:04:33 +000034 if (!sizek) {
35 return;
36 }
37 resource = new_resource(dev, index);
38 resource->base = ((resource_t)basek) << 10;
39 resource->size = ((resource_t)sizek) << 10;
40 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
41 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
Stefan Reinauere4932dc2004-11-02 20:33:12 +000042}
43
Eric Biederman018d8dd2004-11-04 11:04:33 +000044static void tolm_test(void *gp, struct device *dev, struct resource *new)
45{
46 struct resource **best_p = gp;
47 struct resource *best;
48 best = *best_p;
49 if (!best || (best->base > new->base)) {
50 best = new;
51 }
52 *best_p = best;
53}
54
55static uint32_t find_pci_tolm(struct bus *bus)
56{
57 struct resource *min;
58 uint32_t tolm;
59 min = 0;
60 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
61 tolm = 0xffffffffUL;
62 if (min && tolm > min->base) {
63 tolm = min->base;
64 }
65 return tolm;
66}
Stefan Reinauere4932dc2004-11-02 20:33:12 +000067
Eric Biederman6e53f502004-10-27 08:53:57 +000068static void pci_domain_set_resources(device_t dev)
69{
Eric Biederman6e53f502004-10-27 08:53:57 +000070 device_t mc_dev;
Eric Biederman018d8dd2004-11-04 11:04:33 +000071 uint32_t pci_tolm;
Stefan Reinauere4932dc2004-11-02 20:33:12 +000072 uint32_t idx;
Eric Biederman6e53f502004-10-27 08:53:57 +000073
Eric Biederman018d8dd2004-11-04 11:04:33 +000074 pci_tolm = find_pci_tolm(&dev->link[0]);
Eric Biederman6e53f502004-10-27 08:53:57 +000075 mc_dev = dev->link[0].children;
76 if (mc_dev) {
77 unsigned long tomk, tolmk;
78 /* Hard code the Top of memory for now */
79 tomk = 65536;
80 /* Compute the top of Low memory */
81 tolmk = pci_tolm >> 10;
82 if (tolmk >= tomk) {
83 /* The PCI hole does not overlap memory.
84 */
85 tolmk = tomk;
86 }
87
88 /* Report the memory regions */
89 idx = 10;
90 ram_resource(dev, idx++, 0, 640);
91 ram_resource(dev, idx++, 768, tolmk - 768);
92 if (tomk > 4*1024*1024) {
93 ram_resource(dev, idx++, 4096*1024, tomk - 4*1024*1024);
94 }
Stefan Reinauere2b53e12004-06-28 11:59:45 +000095 }
Eric Biederman6e53f502004-10-27 08:53:57 +000096 assign_resources(&dev->link[0]);
97}
Stefan Reinauere2b53e12004-06-28 11:59:45 +000098
Eric Biederman6e53f502004-10-27 08:53:57 +000099static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
100{
Eric Biederman018d8dd2004-11-04 11:04:33 +0000101 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
102 return max;
Eric Biederman6e53f502004-10-27 08:53:57 +0000103}
104
105static struct device_operations pci_domain_ops = {
Eric Biederman018d8dd2004-11-04 11:04:33 +0000106 .read_resources = pci_domain_read_resources,
107 .set_resources = pci_domain_set_resources,
108 .enable_resources = enable_childrens_resources,
109 .init = 0,
110 .scan_bus = pci_domain_scan_bus,
Eric Biederman6e53f502004-10-27 08:53:57 +0000111};
112
113static void enable_dev(struct device *dev)
114{
Eric Biederman018d8dd2004-11-04 11:04:33 +0000115 /* Set the operations if it is a special bus type */
116 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
117 dev->ops = &pci_domain_ops;
118 pci_set_method();
119 }
Stefan Reinauere2b53e12004-06-28 11:59:45 +0000120}
121
Stefan Reinauere4932dc2004-11-02 20:33:12 +0000122struct chip_operations northbridge_emulation_qemu_i386_ops = {
Eric Biederman018d8dd2004-11-04 11:04:33 +0000123 CHIP_NAME("QEMU Northbridge")
Eric Biederman6e53f502004-10-27 08:53:57 +0000124 .enable_dev = enable_dev,
Stefan Reinauere2b53e12004-06-28 11:59:45 +0000125};