1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
12 static void pci_domain_read_resources(device_t dev)
14 struct resource *resource;
17 /* Initialize the system wide io space constraints */
18 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
19 resource->base = 0x400; //yhlu
20 resource->limit = 0xffffUL;
21 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
23 /* 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;
29 static void ram_resource(device_t dev, unsigned long index,
30 unsigned long basek, unsigned long sizek)
32 struct resource *resource;
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;
44 static void tolm_test(void *gp, struct device *dev, struct resource *new)
46 struct resource **best_p = gp;
47 struct resource *best;
49 if (!best || (best->base > new->base)) {
55 static uint32_t find_pci_tolm(struct bus *bus)
60 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
62 if (min && tolm > min->base) {
68 static void pci_domain_set_resources(device_t dev)
73 pci_tolm = find_pci_tolm(&dev->link[0]);
74 mc_dev = dev->link[0].children;
76 /* Figure out which areas are/should be occupied by RAM.
77 * This is all computed in kilobytes and converted to/from
78 * the memory controller right at the edges.
79 * Having different variables in different units is
80 * too confusing to get right. Kilobytes are good up to
81 * 4 Terabytes of RAM...
83 uint16_t tolm_r, remapbase_r, remaplimit_r;
84 unsigned long tomk, tolmk;
85 unsigned long remapbasek, remaplimitk;
88 /* Get the value of the highest DRB. This tells the end of
89 * the physical memory. The units are ticks of 64MB
92 tomk = ((unsigned long)pci_read_config8(mc_dev, 0x67)) << 16;
93 /* Compute the top of Low memory */
94 tolmk = pci_tolm >> 10;
96 /* The PCI hole does not overlap memory
97 * we won't use the remap window.
100 remapbasek = 0x3ff << 16;
101 remaplimitk = 0 << 16;
104 /* The PCI memory hole overlaps memory
105 * setup the remap window.
107 /* Find the bottom of the remap window
110 remapbasek = 4*1024*1024;
111 if (tomk > remapbasek) {
114 /* Find the limit of the remap window */
115 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
117 /* Write the ram configuration registers,
118 * preserving the reserved bits.
120 tolm_r = pci_read_config16(mc_dev, 0xc4);
121 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
122 pci_write_config16(mc_dev, 0xc4, tolm_r);
124 remapbase_r = pci_read_config16(mc_dev, 0xc6);
125 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
126 pci_write_config16(mc_dev, 0xc6, remapbase_r);
128 remaplimit_r = pci_read_config16(mc_dev, 0xc8);
129 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
130 pci_write_config16(mc_dev, 0xc8, remaplimit_r);
132 /* Report the memory regions */
134 ram_resource(dev, idx++, 0, 640);
135 ram_resource(dev, idx++, 768, tolmk - 768);
136 if (tomk > 4*1024*1024) {
137 ram_resource(dev, idx++, 4096*1024, tomk - 4*1024*1024);
139 if (remaplimitk >= remapbasek) {
140 ram_resource(dev, idx++, remapbasek,
141 (remaplimitk + 64*1024) - remapbasek);
144 assign_resources(&dev->link[0]);
147 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
149 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
153 static struct device_operations pci_domain_ops = {
154 .read_resources = pci_domain_read_resources,
155 .set_resources = pci_domain_set_resources,
156 .enable_resources = enable_childrens_resources,
158 .scan_bus = pci_domain_scan_bus,
159 .ops_pci_bus = &pci_cf8_conf1,
162 static void cpu_bus_init(device_t dev)
164 initialize_cpus(&dev->link[0]);
167 static void cpu_bus_noop(device_t dev)
171 static struct device_operations cpu_bus_ops = {
172 .read_resources = cpu_bus_noop,
173 .set_resources = cpu_bus_noop,
174 .enable_resources = cpu_bus_noop,
175 .init = cpu_bus_init,
179 static void enable_dev(struct device *dev)
181 /* Set the operations if it is a special bus type */
182 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
183 dev->ops = &pci_domain_ops;
185 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
186 dev->ops = &cpu_bus_ops;
190 struct chip_operations northbridge_intel_e7501_ops = {
191 CHIP_NAME("Intel E7501 Northbridge")
192 .enable_dev = enable_dev,