Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
| 2 | #include <arch/io.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 3 | #include <arch/ioapic.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 4 | #include <stdint.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | #include <bitops.h> |
| 10 | #include "chip.h" |
Myles Watson | 2e67273 | 2009-11-12 16:38:03 +0000 | [diff] [blame] | 11 | #include <delay.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 12 | |
Myles Watson | b8e2027 | 2009-10-15 13:35:47 +0000 | [diff] [blame] | 13 | #if CONFIG_WRITE_HIGH_TABLES==1 |
Rudolf Marek | 97be27e | 2010-12-13 19:50:25 +0000 | [diff] [blame^] | 14 | #include <cbmem.h> |
Myles Watson | 0520d55 | 2009-05-11 22:44:14 +0000 | [diff] [blame] | 15 | #endif |
| 16 | |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 17 | #define CMOS_ADDR_PORT 0x70 |
| 18 | #define CMOS_DATA_PORT 0x71 |
| 19 | #define HIGH_RAM_ADDR 0x35 |
| 20 | #define LOW_RAM_ADDR 0x34 |
| 21 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 22 | static void cpu_pci_domain_set_resources(device_t dev) |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 23 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 24 | u32 pci_tolm = find_pci_tolm(dev->link_list); |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 25 | unsigned long tomk = 0, tolmk; |
| 26 | int idx; |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 27 | |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 28 | outb (HIGH_RAM_ADDR, CMOS_ADDR_PORT); |
| 29 | tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14; |
| 30 | outb (LOW_RAM_ADDR, CMOS_ADDR_PORT); |
| 31 | tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6; |
| 32 | tomk += 16 * 1024; |
Ronald G. Minnich | 9cf642b | 2006-09-13 04:12:35 +0000 | [diff] [blame] | 33 | |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 34 | printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n", |
| 35 | tomk, tomk / 1024); |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 36 | |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 37 | /* Compute the top of Low memory */ |
| 38 | tolmk = pci_tolm >> 10; |
| 39 | if (tolmk >= tomk) { |
| 40 | /* The PCI hole does not overlap the memory. */ |
| 41 | tolmk = tomk; |
| 42 | } |
| 43 | |
| 44 | /* Report the memory regions. */ |
| 45 | idx = 10; |
| 46 | ram_resource(dev, idx++, 0, 640); |
| 47 | ram_resource(dev, idx++, 768, tolmk - 768); |
Myles Watson | 0520d55 | 2009-05-11 22:44:14 +0000 | [diff] [blame] | 48 | |
Myles Watson | b8e2027 | 2009-10-15 13:35:47 +0000 | [diff] [blame] | 49 | #if CONFIG_WRITE_HIGH_TABLES==1 |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 50 | /* Leave some space for ACPI, PIRQ and MP tables */ |
Rudolf Marek | 97be27e | 2010-12-13 19:50:25 +0000 | [diff] [blame^] | 51 | high_tables_base = (tomk * 1024) - HIGH_MEMORY_SIZE; |
| 52 | high_tables_size = HIGH_MEMORY_SIZE; |
Myles Watson | 0520d55 | 2009-05-11 22:44:14 +0000 | [diff] [blame] | 53 | #endif |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 54 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 55 | assign_resources(dev->link_list); |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 56 | } |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 57 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 58 | static void cpu_pci_domain_read_resources(struct device *dev) |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 59 | { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 60 | struct resource *res; |
| 61 | |
| 62 | pci_domain_read_resources(dev); |
| 63 | |
| 64 | /* Reserve space for the IOAPIC. This should be in the Southbridge, |
| 65 | * but I couldn't tell which device to put it in. */ |
| 66 | res = new_resource(dev, 2); |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 67 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 68 | res->size = 0x100000UL; |
| 69 | res->limit = 0xffffffffUL; |
| 70 | res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | |
| 71 | IORESOURCE_ASSIGNED; |
| 72 | |
| 73 | /* Reserve space for the LAPIC. There's one in every processor, but |
| 74 | * the space only needs to be reserved once, so we do it here. */ |
| 75 | res = new_resource(dev, 3); |
| 76 | res->base = 0xfee00000UL; |
| 77 | res->size = 0x10000UL; |
| 78 | res->limit = 0xffffffffUL; |
| 79 | res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | |
| 80 | IORESOURCE_ASSIGNED; |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static struct device_operations pci_domain_ops = { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 84 | .read_resources = cpu_pci_domain_read_resources, |
| 85 | .set_resources = cpu_pci_domain_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 86 | .enable_resources = NULL, |
| 87 | .init = NULL, |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 88 | .scan_bus = pci_domain_scan_bus, |
| 89 | }; |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 90 | |
| 91 | static void enable_dev(struct device *dev) |
| 92 | { |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 93 | /* Set the operations if it is a special bus type */ |
| 94 | if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) { |
| 95 | dev->ops = &pci_domain_ops; |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 96 | pci_set_method(dev); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 97 | } |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Patrick Georgi | 35784b6 | 2010-04-08 12:47:35 +0000 | [diff] [blame] | 100 | struct chip_operations mainboard_emulation_qemu_x86_ops = { |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 101 | CHIP_NAME("QEMU Northbridge") |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 102 | .enable_dev = enable_dev, |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 103 | }; |