Fix some CHIP_NAME() entries to use canonical names.
[coreboot.git] / src / northbridge / motorola / mpc107 / mpc107_northbridge.c
1 #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 <stdlib.h>
7 #include <string.h>
8 #include <bitops.h>
9 #include <cpu/cpu.h>
10 #include "chip.h"
11
12 /*
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
17  * devices.
18  */
19 static void pci_domain_read_resources(device_t dev)
20 {
21         struct resource *resource;
22
23         /* Initialize the system wide io space constraints */
24         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
25         resource->base  = 0;
26         resource->limit = 0xffffUL;
27         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
28
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;
34 }
35
36 /*
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.
40  */
41 static void pci_domain_set_resources(device_t dev)
42 {
43         device_t mc_dev;
44
45         /* Get the memory controller device */
46         mc_dev = dev->link[0].children;
47         if (mc_dev) {
48                 /* Figure out which areas occupied by ram. */
49                 int i, idx;
50                 uint32_t memstart1, memstart2, extmemstart1, extmemstart2;
51                 uint32_t memend1, memend2, extmemend1, extmemend2;
52                 uint8_t bank_enable;
53                 unsigned long start, end, size;
54
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);
65         
66                 /* Report the memory regions */
67                 idx = 10; /* Why does idx start at 10? */
68
69                 for(i = 0; i < 8; i++) {
70                         struct resource *res;
71                         /* Ignore banks that are not enabled */
72                         if (!(bank_enable & (1 << i))) {
73                                 continue;
74                         }
75                         /* Find the start and end of each bank */
76                         if (i < 4) {
77                                 int shift = (8*i);
78                                 start =  ((memstart1    >> shift) & 0xff) << 20;
79                                 start |= ((extmemstart1 >> shift) & 0xff) << 28;
80                                 end   =  ((memend1      >> shift) & 0xff) << 20;
81                                 end   |= ((extmemend1   >> shift) & 0xff) << 28;
82                         } else {
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;
88                         }
89                         /* Comput the size of the bank */
90                         size = (end + (1 << 20)) - start;
91
92                         /* And now report the memory region */
93                         res = new_resource(dev, idx++);
94                         res->base = start;
95                         res->size = size;
96                         res->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
97                                 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
98                 }
99         }
100         /* And assign the resources */
101         assign_resources(&dev->link[0]);
102 }
103
104
105 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
106 {
107         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
108         return max;
109 }
110
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,
115         .init             = 0,
116         .scan_bus         = pci_domain_scan_bus,
117         .ops_pci_bus      = &pci_ppc_conf1,
118 };  
119
120 static void cpu_bus_init(device_t dev)
121 {
122         initialize_cpus(&dev->link[0]);
123 }
124
125 static void cpu_bus_noop(device_t dev)
126 {
127 }
128
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,
134         .scan_bus         = 0,
135 };
136
137 static void enable_dev(struct device *dev)
138 {
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;
142         }
143         else if (dev->path.type == DEVICE_PATH_CPU_BUS) {
144                 dev->ops = &cpu_bus_ops;
145         }
146 }
147
148 struct chip_operations northbridge_motorola_mpc107_ops = {
149         CHIP_NAME("Motorola MPC107 Northbridge")
150         .enable_dev = enable_dev,
151 };