1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
12 static void ram_resource(device_t dev, unsigned long index,
13 unsigned long basek, unsigned long sizek)
15 struct resource *resource;
20 resource = new_resource(dev, index);
21 resource->base = ((resource_t)basek) << 10;
22 resource->size = ((resource_t)sizek) << 10;
23 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
24 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
27 static void tolm_test(void *gp, struct device *dev, struct resource *new)
29 struct resource **best_p = gp;
30 struct resource *best;
32 if (!best || (best->base > new->base)) {
38 static uint32_t find_pci_tolm(struct bus *bus)
43 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
45 if (min && tolm > min->base) {
51 #if CONFIG_WRITE_HIGH_TABLES==1
52 #define HIGH_TABLES_SIZE 64 // maximum size of high tables in KB
53 extern uint64_t high_tables_base, high_tables_size;
56 #define CMOS_ADDR_PORT 0x70
57 #define CMOS_DATA_PORT 0x71
58 #define HIGH_RAM_ADDR 0x35
59 #define LOW_RAM_ADDR 0x34
61 static void cpu_pci_domain_set_resources(device_t dev)
63 u32 pci_tolm = find_pci_tolm(dev->link_list);
64 unsigned long tomk = 0, tolmk;
67 outb (HIGH_RAM_ADDR, CMOS_ADDR_PORT);
68 tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14;
69 outb (LOW_RAM_ADDR, CMOS_ADDR_PORT);
70 tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6;
73 printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n",
76 /* Compute the top of Low memory */
77 tolmk = pci_tolm >> 10;
79 /* The PCI hole does not overlap the memory. */
83 /* Report the memory regions. */
85 ram_resource(dev, idx++, 0, 640);
86 ram_resource(dev, idx++, 768, tolmk - 768);
88 #if CONFIG_WRITE_HIGH_TABLES==1
89 /* Leave some space for ACPI, PIRQ and MP tables */
90 high_tables_base = (tomk - HIGH_TABLES_SIZE) * 1024;
91 high_tables_size = HIGH_TABLES_SIZE * 1024;
94 assign_resources(dev->link_list);
97 static void cpu_pci_domain_read_resources(struct device *dev)
101 pci_domain_read_resources(dev);
103 /* Reserve space for the IOAPIC. This should be in the Southbridge,
104 * but I couldn't tell which device to put it in. */
105 res = new_resource(dev, 2);
106 res->base = 0xfec00000UL;
107 res->size = 0x100000UL;
108 res->limit = 0xffffffffUL;
109 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
112 /* Reserve space for the LAPIC. There's one in every processor, but
113 * the space only needs to be reserved once, so we do it here. */
114 res = new_resource(dev, 3);
115 res->base = 0xfee00000UL;
116 res->size = 0x10000UL;
117 res->limit = 0xffffffffUL;
118 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
122 static struct device_operations pci_domain_ops = {
123 .read_resources = cpu_pci_domain_read_resources,
124 .set_resources = cpu_pci_domain_set_resources,
125 .enable_resources = NULL,
127 .scan_bus = pci_domain_scan_bus,
130 static void enable_dev(struct device *dev)
132 /* Set the operations if it is a special bus type */
133 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
134 dev->ops = &pci_domain_ops;
139 struct chip_operations mainboard_emulation_qemu_x86_ops = {
140 CHIP_NAME("QEMU Northbridge")
141 .enable_dev = enable_dev,