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
23 static void pci_domain_set_resources(device_t dev)
28 pci_tolm = find_pci_tolm(dev->link_list);
31 printk(BIOS_DEBUG, "PCI mem marker = %x\n", pci_tolm);
33 /* FIXME Me temporary hack */
34 if(pci_tolm > 0xe0000000)
35 pci_tolm = 0xe0000000;
36 /* Ensure pci_tolm is 128M aligned */
37 pci_tolm &= 0xf8000000;
38 mc_dev = dev->link_list->children;
40 /* Figure out which areas are/should be occupied by RAM.
41 * This is all computed in kilobytes and converted to/from
42 * the memory controller right at the edges.
43 * Having different variables in different units is
44 * too confusing to get right. Kilobytes are good up to
45 * 4 Terabytes of RAM...
47 uint16_t tolm_r, remapbase_r, remaplimit_r, remapoffset_r;
48 unsigned long tomk, tolmk;
49 unsigned long remapbasek, remaplimitk, remapoffsetk;
51 /* Get the Top of Memory address, units are 128M */
52 tomk = ((unsigned long)pci_read_config16(mc_dev, TOM)) << 17;
53 /* Compute the Top of Low Memory */
54 tolmk = (pci_tolm & 0xf8000000) >> 10;
57 /* The PCI hole does not overlap memory
58 * we won't use the remap window.
61 remapbasek = 0x3ff << 16;
62 remaplimitk = 0 << 16;
63 remapoffsetk = 0 << 16;
66 /* The PCI memory hole overlaps memory
67 * setup the remap window.
69 /* Find the bottom of the remap window
72 remapbasek = 4*1024*1024;
73 if (tomk > remapbasek) {
76 /* Find the limit of the remap window */
77 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
78 /* Find the offset of the remap window from tolm */
79 remapoffsetk = remapbasek - tolmk;
81 /* Write the ram configruation registers,
82 * preserving the reserved bits.
84 tolm_r = pci_read_config16(mc_dev, 0xc4);
85 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
86 pci_write_config16(mc_dev, 0xc4, tolm_r);
88 remapbase_r = pci_read_config16(mc_dev, 0xc6);
89 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
90 pci_write_config16(mc_dev, 0xc6, remapbase_r);
92 remaplimit_r = pci_read_config16(mc_dev, 0xc8);
93 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
94 pci_write_config16(mc_dev, 0xc8, remaplimit_r);
96 remapoffset_r = pci_read_config16(mc_dev, 0xca);
97 remapoffset_r = (remapoffsetk >> 16) | (remapoffset_r & 0xfc00);
98 pci_write_config16(mc_dev, 0xca, remapoffset_r);
100 /* Report the memory regions */
101 ram_resource(dev, 3, 0, 640);
102 ram_resource(dev, 4, 768, (tolmk - 768));
103 if (tomk > 4*1024*1024) {
104 ram_resource(dev, 5, 4096*1024, tomk - 4*1024*1024);
106 if (remaplimitk >= remapbasek) {
107 ram_resource(dev, 6, remapbasek,
108 (remaplimitk + 64*1024) - remapbasek);
111 #if CONFIG_WRITE_HIGH_TABLES==1
112 /* Leave some space for ACPI, PIRQ and MP tables */
113 high_tables_base = (tolmk * 1024) - HIGH_MEMORY_SIZE;
114 high_tables_size = HIGH_MEMORY_SIZE;
117 assign_resources(dev->link_list);
120 static u32 e7520_domain_scan_bus(device_t dev, u32 max)
122 max_bus = pci_domain_scan_bus(dev, max);
126 static struct device_operations pci_domain_ops = {
127 .read_resources = pci_domain_read_resources,
128 .set_resources = pci_domain_set_resources,
129 .enable_resources = NULL,
131 .scan_bus = e7520_domain_scan_bus,
132 .ops_pci_bus = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */
135 static void mc_read_resources(device_t dev)
137 struct resource *resource;
139 pci_dev_read_resources(dev);
141 resource = new_resource(dev, 0xcf);
142 resource->base = 0xe0000000;
143 resource->size = max_bus * 4096*256;
144 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
147 static void mc_set_resources(device_t dev)
149 struct resource *resource;
151 resource = find_resource(dev, 0xcf);
153 report_resource_stored(dev, resource, "<mmconfig>");
155 pci_dev_set_resources(dev);
158 static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
160 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
161 ((device & 0xffff) << 16) | (vendor & 0xffff));
164 static struct pci_operations intel_pci_ops = {
165 .set_subsystem = intel_set_subsystem,
168 static struct device_operations mc_ops = {
169 .read_resources = mc_read_resources,
170 .set_resources = mc_set_resources,
171 .enable_resources = pci_dev_enable_resources,
174 .ops_pci = &intel_pci_ops,
177 static const struct pci_driver mc_driver __pci_driver = {
179 .vendor = PCI_VENDOR_ID_INTEL,
183 static void cpu_bus_init(device_t dev)
185 initialize_cpus(dev->link_list);
188 static void cpu_bus_noop(device_t dev)
192 static struct device_operations cpu_bus_ops = {
193 .read_resources = cpu_bus_noop,
194 .set_resources = cpu_bus_noop,
195 .enable_resources = cpu_bus_noop,
196 .init = cpu_bus_init,
201 static void enable_dev(device_t dev)
203 /* Set the operations if it is a special bus type */
204 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
205 dev->ops = &pci_domain_ops;
207 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
208 dev->ops = &cpu_bus_ops;
212 struct chip_operations northbridge_intel_e7520_ops = {
213 CHIP_NAME("Intel E7520 Northbridge")
214 .enable_dev = enable_dev,