We define IO_APIC_ADDR in <arch/ioapic.h>, let's use it.
[coreboot.git] / src / mainboard / emulation / qemu-x86 / northbridge.c
1 #include <console/console.h>
2 #include <arch/io.h>
3 #include <arch/ioapic.h>
4 #include <stdint.h>
5 #include <device/device.h>
6 #include <device/pci.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <bitops.h>
10 #include "chip.h"
11 #include <delay.h>
12
13 #if CONFIG_WRITE_HIGH_TABLES==1
14 #define HIGH_TABLES_SIZE 64     // maximum size of high tables in KB
15 extern uint64_t high_tables_base, high_tables_size;
16 #endif
17
18 #define CMOS_ADDR_PORT 0x70
19 #define CMOS_DATA_PORT 0x71
20 #define HIGH_RAM_ADDR 0x35
21 #define LOW_RAM_ADDR 0x34
22
23 static void cpu_pci_domain_set_resources(device_t dev)
24 {
25         u32 pci_tolm = find_pci_tolm(dev->link_list);
26         unsigned long tomk = 0, tolmk;
27         int idx;
28
29         outb (HIGH_RAM_ADDR, CMOS_ADDR_PORT);
30         tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14;
31         outb (LOW_RAM_ADDR, CMOS_ADDR_PORT);
32         tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6;
33         tomk += 16 * 1024;
34
35         printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n",
36                tomk, tomk / 1024);
37
38         /* Compute the top of Low memory */
39         tolmk = pci_tolm >> 10;
40         if (tolmk >= tomk) {
41                 /* The PCI hole does not overlap the memory. */
42                 tolmk = tomk;
43         }
44
45         /* Report the memory regions. */
46         idx = 10;
47         ram_resource(dev, idx++, 0, 640);
48         ram_resource(dev, idx++, 768, tolmk - 768);
49
50 #if CONFIG_WRITE_HIGH_TABLES==1
51         /* Leave some space for ACPI, PIRQ and MP tables */
52         high_tables_base = (tomk - HIGH_TABLES_SIZE) * 1024;
53         high_tables_size = HIGH_TABLES_SIZE * 1024;
54 #endif
55
56         assign_resources(dev->link_list);
57 }
58
59 static void cpu_pci_domain_read_resources(struct device *dev)
60 {
61         struct resource *res;
62
63         pci_domain_read_resources(dev);
64
65         /* Reserve space for the IOAPIC.  This should be in the Southbridge,
66          * but I couldn't tell which device to put it in. */
67         res = new_resource(dev, 2);
68         res->base = IO_APIC_ADDR;
69         res->size = 0x100000UL;
70         res->limit = 0xffffffffUL;
71         res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
72                      IORESOURCE_ASSIGNED;
73
74         /* Reserve space for the LAPIC.  There's one in every processor, but
75          * the space only needs to be reserved once, so we do it here. */
76         res = new_resource(dev, 3);
77         res->base = 0xfee00000UL;
78         res->size = 0x10000UL;
79         res->limit = 0xffffffffUL;
80         res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
81                      IORESOURCE_ASSIGNED;
82 }
83
84 static struct device_operations pci_domain_ops = {
85         .read_resources         = cpu_pci_domain_read_resources,
86         .set_resources          = cpu_pci_domain_set_resources,
87         .enable_resources       = NULL,
88         .init                   = NULL,
89         .scan_bus               = pci_domain_scan_bus,
90 };
91
92 static void enable_dev(struct device *dev)
93 {
94         /* Set the operations if it is a special bus type */
95         if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
96                 dev->ops = &pci_domain_ops;
97                 pci_set_method(dev);
98         }
99 }
100
101 struct chip_operations mainboard_emulation_qemu_x86_ops = {
102         CHIP_NAME("QEMU Northbridge")
103         .enable_dev = enable_dev,
104 };