1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
11 static void pci_domain_read_resources(device_t dev)
13 struct resource *resource;
16 /* Initialize the system wide io space constraints */
17 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
18 resource->base = 0x400; //yhlu
19 resource->limit = 0xffffUL;
20 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
22 /* Initialize the system wide memory resources constraints */
23 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
24 resource->limit = 0xffffffffULL;
25 resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
28 static void ram_resource(device_t dev, unsigned long index,
29 unsigned long basek, unsigned long sizek)
31 struct resource *resource;
36 resource = new_resource(dev, index);
37 resource->base = ((resource_t)basek) << 10;
38 resource->size = ((resource_t)sizek) << 10;
39 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
40 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
43 static void tolm_test(void *gp, struct device *dev, struct resource *new)
45 struct resource **best_p = gp;
46 struct resource *best;
48 if (!best || (best->base > new->base)) {
54 static uint32_t find_pci_tolm(struct bus *bus)
59 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
61 if (min && tolm > min->base) {
67 static void pci_domain_set_resources(device_t dev)
72 pci_tolm = find_pci_tolm(&dev->link[0]);
73 mc_dev = dev->link[0].children;
75 /* Figure out which areas are/should be occupied by RAM.
76 * This is all computed in kilobytes and converted to/from
77 * the memory controller right at the edges.
78 * Having different variables in different units is
79 * too confusing to get right. Kilobytes are good up to
80 * 4 Terabytes of RAM...
82 uint16_t tolm_r, remapbase_r, remaplimit_r;
83 unsigned long tomk, tolmk;
84 unsigned long remapbasek, remaplimitk;
87 /* Get the value of the highest DRB. This tells the end of
88 * the physical memory. The units are ticks of 64MB
91 tomk = ((unsigned long)pci_read_config8(mc_dev, 0x67)) << 16;
92 /* Compute the top of Low memory */
93 tolmk = pci_tolm >> 10;
95 /* The PCI hole does not overlap memory
96 * we won't use the remap window.
99 remapbasek = 0x3ff << 16;
100 remaplimitk = 0 << 16;
103 /* The PCI memory hole overlaps memory
104 * setup the remap window.
106 /* Find the bottom of the remap window
109 remapbasek = 4*1024*1024;
110 if (tomk > remapbasek) {
113 /* Find the limit of the remap window */
114 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
116 /* Write the ram configuration registers,
117 * preserving the reserved bits.
119 tolm_r = pci_read_config16(mc_dev, 0xc4);
120 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
121 pci_write_config16(mc_dev, 0xc4, tolm_r);
123 remapbase_r = pci_read_config16(mc_dev, 0xc6);
124 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
125 pci_write_config16(mc_dev, 0xc6, remapbase_r);
127 remaplimit_r = pci_read_config16(mc_dev, 0xc8);
128 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
129 pci_write_config16(mc_dev, 0xc8, remaplimit_r);
131 /* Report the memory regions */
133 ram_resource(dev, idx++, 0, 640);
134 ram_resource(dev, idx++, 768, tolmk - 768);
135 if (tomk > 4*1024*1024) {
136 ram_resource(dev, idx++, 4096*1024, tomk - 4*1024*1024);
138 if (remaplimitk >= remapbasek) {
139 ram_resource(dev, idx++, remapbasek,
140 (remaplimitk + 64*1024) - remapbasek);
143 assign_resources(&dev->link[0]);
146 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
148 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
152 static struct device_operations pci_domain_ops = {
153 .read_resources = pci_domain_read_resources,
154 .set_resources = pci_domain_set_resources,
155 .enable_resources = enable_childrens_resources,
157 .scan_bus = pci_domain_scan_bus,
158 .ops_pci_bus = &pci_cf8_conf1,
161 static void cpu_bus_init(device_t dev)
163 initialize_cpus(&dev->link[0]);
166 static void cpu_bus_noop(device_t dev)
170 static struct device_operations cpu_bus_ops = {
171 .read_resources = cpu_bus_noop,
172 .set_resources = cpu_bus_noop,
173 .enable_resources = cpu_bus_noop,
174 .init = cpu_bus_init,
178 static void enable_dev(struct device *dev)
180 /* Set the operations if it is a special bus type */
181 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
182 dev->ops = &pci_domain_ops;
184 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
185 dev->ops = &cpu_bus_ops;
189 struct chip_operations northbridge_intel_e7501_ops = {
190 CHIP_NAME("Intel E7501 Northbridge")
191 .enable_dev = enable_dev,