1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
13 * pci_domain_read_resources needs to create two resource regions,
14 * one for memory and one for I/O. These are required for the
15 * resource allocation code to function correctly. The regions should
16 * be large enough to hold all expected resources for all PCI
19 static void pci_domain_read_resources(device_t dev)
21 struct resource *resource;
23 /* Initialize the system wide io space constraints */
24 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
26 resource->limit = 0xffffUL;
27 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
29 /* Initialize the system wide memory resources constraints */
30 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
31 resource->base = 0x80000000ULL;
32 resource->limit = 0xfeffffffULL; /* We can put pci resources in the system controll area */
33 resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
37 * pci_domain_set_resources creates memory resources describing the
38 * fixed memory on the system. This is not actually used anywhere
39 * except when the linuxbios table is generated.
41 static void pci_domain_set_resources(device_t dev)
45 /* Get the memory controller device */
46 mc_dev = dev->link[0].children;
48 /* Figure out which areas occupied by ram. */
50 uint32_t memstart1, memstart2, extmemstart1, extmemstart2;
51 uint32_t memend1, memend2, extmemend1, extmemend2;
53 unsigned long start, end, size;
55 /* Find the memory setup */
56 memstart1 = pci_read_config32(mc_dev, 0x80);
57 memstart2 = pci_read_config32(mc_dev, 0x84);
58 extmemstart1 = pci_read_config32(mc_dev, 0x88);
59 extmemstart2 = pci_read_config32(mc_dev, 0x8c);
60 memend1 = pci_read_config32(mc_dev, 0x90);
61 memend2 = pci_read_config32(mc_dev, 0x94);
62 extmemend1 = pci_read_config32(mc_dev, 0x98);
63 extmemend2 = pci_read_config32(mc_dev, 0x9c);
64 bank_enable = pci_read_config32(mc_dev, 0xa0);
66 /* Report the memory regions */
67 idx = 10; /* Why does idx start at 10? */
69 for(i = 0; i < 8; i++) {
71 /* Ignore banks that are not enabled */
72 if (!(bank_enable & (1 << i))) {
75 /* Find the start and end of each bank */
78 start = ((memstart1 >> shift) & 0xff) << 20;
79 start |= ((extmemstart1 >> shift) & 0xff) << 28;
80 end = ((memend1 >> shift) & 0xff) << 20;
81 end |= ((extmemend1 >> shift) & 0xff) << 28;
83 int shift = (8*(i - 4));
84 start = ((memstart2 >> shift) & 0xff) << 20;
85 start |= ((extmemstart2 >> shift) & 0xff) << 28;
86 end = ((memend2 >> shift) & 0xff) << 20;
87 end |= ((extmemend2 >> shift) & 0xff) << 28;
89 /* Comput the size of the bank */
90 size = (end + (1 << 20)) - start;
92 /* And now report the memory region */
93 res = new_resource(dev, idx++);
96 res->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
97 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
100 /* And assign the resources */
101 assign_resources(&dev->link[0]);
105 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
107 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
111 static struct device_operations pci_domain_ops = {
112 .read_resources = pci_domain_read_resources,
113 .set_resources = pci_domain_set_resources,
114 .enable_resources = enable_childrens_resources,
116 .scan_bus = pci_domain_scan_bus,
117 .ops_pci_bus = &pci_ppc_conf1,
120 static void cpu_bus_init(device_t dev)
122 initialize_cpus(&dev->link[0]);
125 static void cpu_bus_noop(device_t dev)
129 static struct device_operations cpu_bus_ops = {
130 .read_resources = cpu_bus_noop,
131 .set_resources = cpu_bus_noop,
132 .enable_resources = cpu_bus_noop,
133 .init = cpu_bus_init,
137 static void enable_dev(struct device *dev)
139 /* Set the operations if it is a special bus type */
140 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
141 dev->ops = &pci_domain_ops;
143 else if (dev->path.type == DEVICE_PATH_CPU_BUS) {
144 dev->ops = &cpu_bus_ops;
148 struct chip_operations northbridge_motorola_mpc107_ops = {
149 CHIP_NAME("Motorola MPC107 Northbridge")
150 .enable_dev = enable_dev,