1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
7 #include <device/hypertransport.h>
13 #include "northbridge.h"
17 static unsigned int max_bus;
19 #if CONFIG_WRITE_HIGH_TABLES==1
20 #define HIGH_TABLES_SIZE 64 // maximum size of high tables in KB
21 extern uint64_t high_tables_base, high_tables_size;
24 static void pci_domain_set_resources(device_t dev)
29 pci_tolm = find_pci_tolm(dev->link_list);
32 printk(BIOS_DEBUG, "PCI mem marker = %x\n", pci_tolm);
34 /* FIXME Me temporary hack */
35 if(pci_tolm > 0xe0000000)
36 pci_tolm = 0xe0000000;
37 /* Ensure pci_tolm is 128M aligned */
38 pci_tolm &= 0xf8000000;
39 mc_dev = dev->link_list->children;
41 /* Figure out which areas are/should be occupied by RAM.
42 * This is all computed in kilobytes and converted to/from
43 * the memory controller right at the edges.
44 * Having different variables in different units is
45 * too confusing to get right. Kilobytes are good up to
46 * 4 Terabytes of RAM...
48 uint16_t tolm_r, remapbase_r, remaplimit_r, remapoffset_r;
49 unsigned long tomk, tolmk;
50 unsigned long remapbasek, remaplimitk, remapoffsetk;
52 /* Get the Top of Memory address, units are 128M */
53 tomk = ((unsigned long)pci_read_config16(mc_dev, TOM)) << 17;
54 /* Compute the Top of Low Memory */
55 tolmk = (pci_tolm & 0xf8000000) >> 10;
58 /* The PCI hole does not overlap memory
59 * we won't use the remap window.
62 remapbasek = 0x3ff << 16;
63 remaplimitk = 0 << 16;
64 remapoffsetk = 0 << 16;
67 /* The PCI memory hole overlaps memory
68 * setup the remap window.
70 /* Find the bottom of the remap window
73 remapbasek = 4*1024*1024;
74 if (tomk > remapbasek) {
77 /* Find the limit of the remap window */
78 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
79 /* Find the offset of the remap window from tolm */
80 remapoffsetk = remapbasek - tolmk;
82 /* Write the ram configruation registers,
83 * preserving the reserved bits.
85 tolm_r = pci_read_config16(mc_dev, 0xc4);
86 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
87 pci_write_config16(mc_dev, 0xc4, tolm_r);
89 remapbase_r = pci_read_config16(mc_dev, 0xc6);
90 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
91 pci_write_config16(mc_dev, 0xc6, remapbase_r);
93 remaplimit_r = pci_read_config16(mc_dev, 0xc8);
94 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
95 pci_write_config16(mc_dev, 0xc8, remaplimit_r);
97 remapoffset_r = pci_read_config16(mc_dev, 0xca);
98 remapoffset_r = (remapoffsetk >> 16) | (remapoffset_r & 0xfc00);
99 pci_write_config16(mc_dev, 0xca, remapoffset_r);
101 /* Report the memory regions */
102 ram_resource(dev, 3, 0, 640);
103 ram_resource(dev, 4, 768, (tolmk - 768));
104 if (tomk > 4*1024*1024) {
105 ram_resource(dev, 5, 4096*1024, tomk - 4*1024*1024);
107 if (remaplimitk >= remapbasek) {
108 ram_resource(dev, 6, remapbasek,
109 (remaplimitk + 64*1024) - remapbasek);
112 #if CONFIG_WRITE_HIGH_TABLES==1
113 /* Leave some space for ACPI, PIRQ and MP tables */
114 high_tables_base = (tolmk - HIGH_TABLES_SIZE) * 1024;
115 high_tables_size = HIGH_TABLES_SIZE * 1024;
118 assign_resources(dev->link_list);
121 static u32 e7525_domain_scan_bus(device_t dev, u32 max)
123 max_bus = pci_domain_scan_bus(dev, max);
127 static struct device_operations pci_domain_ops = {
128 .read_resources = pci_domain_read_resources,
129 .set_resources = pci_domain_set_resources,
130 .enable_resources = NULL,
132 .scan_bus = e7525_domain_scan_bus,
133 .ops_pci_bus = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */
136 static void mc_read_resources(device_t dev)
138 struct resource *resource;
140 pci_dev_read_resources(dev);
142 resource = new_resource(dev, 0xcf);
143 resource->base = 0xe0000000;
144 resource->size = max_bus * 4096*256;
145 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
148 static void mc_set_resources(device_t dev)
150 struct resource *resource;
152 resource = find_resource(dev, 0xcf);
154 report_resource_stored(dev, resource, "<mmconfig>");
156 pci_dev_set_resources(dev);
159 static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
161 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
162 ((device & 0xffff) << 16) | (vendor & 0xffff));
165 static struct pci_operations intel_pci_ops = {
166 .set_subsystem = intel_set_subsystem,
169 static struct device_operations mc_ops = {
170 .read_resources = mc_read_resources,
171 .set_resources = mc_set_resources,
172 .enable_resources = pci_dev_enable_resources,
175 .ops_pci = &intel_pci_ops,
178 static const struct pci_driver mc_driver __pci_driver = {
180 .vendor = PCI_VENDOR_ID_INTEL,
184 static void cpu_bus_init(device_t dev)
186 initialize_cpus(dev->link_list);
189 static void cpu_bus_noop(device_t dev)
193 static struct device_operations cpu_bus_ops = {
194 .read_resources = cpu_bus_noop,
195 .set_resources = cpu_bus_noop,
196 .enable_resources = cpu_bus_noop,
197 .init = cpu_bus_init,
202 static void enable_dev(device_t dev)
204 /* Set the operations if it is a special bus type */
205 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
206 dev->ops = &pci_domain_ops;
208 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
209 dev->ops = &cpu_bus_ops;
213 struct chip_operations northbridge_intel_e7525_ops = {
214 CHIP_NAME("Intel E7525 Northbridge")
215 .enable_dev = enable_dev,