Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 2 | #include <cpu/x86/lapic_def.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 3 | #include <arch/io.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 4 | #include <arch/ioapic.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 5 | #include <stdint.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 6 | #include <device/device.h> |
| 7 | #include <device/pci.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
Myles Watson | 2e67273 | 2009-11-12 16:38:03 +0000 | [diff] [blame] | 10 | #include <delay.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 11 | #include <smbios.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 12 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 13 | #if CONFIG_WRITE_HIGH_TABLES |
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 | |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 17 | #include "memory.c" |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 18 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 19 | static void cpu_pci_domain_set_resources(device_t dev) |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 20 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 21 | u32 pci_tolm = find_pci_tolm(dev->link_list); |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 22 | unsigned long tomk = 0, tolmk; |
| 23 | int idx; |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 24 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 25 | tomk = qemu_get_memory_size(); |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 26 | printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n", |
| 27 | tomk, tomk / 1024); |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 28 | |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 29 | /* Compute the top of Low memory */ |
| 30 | tolmk = pci_tolm >> 10; |
| 31 | if (tolmk >= tomk) { |
| 32 | /* The PCI hole does not overlap the memory. */ |
| 33 | tolmk = tomk; |
| 34 | } |
| 35 | |
| 36 | /* Report the memory regions. */ |
| 37 | idx = 10; |
| 38 | ram_resource(dev, idx++, 0, 640); |
| 39 | ram_resource(dev, idx++, 768, tolmk - 768); |
Myles Watson | 0520d55 | 2009-05-11 22:44:14 +0000 | [diff] [blame] | 40 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 41 | #if CONFIG_WRITE_HIGH_TABLES |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 42 | /* Leave some space for ACPI, PIRQ and MP tables */ |
Rudolf Marek | 97be27e | 2010-12-13 19:50:25 +0000 | [diff] [blame] | 43 | high_tables_base = (tomk * 1024) - HIGH_MEMORY_SIZE; |
| 44 | high_tables_size = HIGH_MEMORY_SIZE; |
Myles Watson | 0520d55 | 2009-05-11 22:44:14 +0000 | [diff] [blame] | 45 | #endif |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 46 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 47 | assign_resources(dev->link_list); |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 48 | } |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 49 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 50 | static void cpu_pci_domain_read_resources(struct device *dev) |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 51 | { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 52 | struct resource *res; |
| 53 | |
| 54 | pci_domain_read_resources(dev); |
| 55 | |
| 56 | /* Reserve space for the IOAPIC. This should be in the Southbridge, |
| 57 | * but I couldn't tell which device to put it in. */ |
| 58 | res = new_resource(dev, 2); |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 59 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 60 | res->size = 0x100000UL; |
| 61 | res->limit = 0xffffffffUL; |
| 62 | res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | |
| 63 | IORESOURCE_ASSIGNED; |
| 64 | |
| 65 | /* Reserve space for the LAPIC. There's one in every processor, but |
| 66 | * the space only needs to be reserved once, so we do it here. */ |
| 67 | res = new_resource(dev, 3); |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 68 | res->base = LOCAL_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 69 | res->size = 0x10000UL; |
| 70 | res->limit = 0xffffffffUL; |
| 71 | res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | |
| 72 | IORESOURCE_ASSIGNED; |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 75 | #if CONFIG_GENERATE_SMBIOS_TABLES |
| 76 | static int qemu_get_smbios_data16(int handle, unsigned long *current) |
| 77 | { |
| 78 | struct smbios_type16 *t = (struct smbios_type16 *)*current; |
| 79 | int len = sizeof(struct smbios_type16); |
| 80 | |
| 81 | memset(t, 0, sizeof(struct smbios_type16)); |
| 82 | t->type = SMBIOS_PHYS_MEMORY_ARRAY; |
| 83 | t->handle = handle; |
| 84 | t->length = len - 2; |
| 85 | t->location = 3; /* Location: System Board */ |
| 86 | t->use = 3; /* System memory */ |
| 87 | t->memory_error_correction = 3; /* No error correction */ |
| 88 | t->maximum_capacity = qemu_get_memory_size(); |
| 89 | *current += len; |
| 90 | return len; |
| 91 | } |
| 92 | |
| 93 | static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *current) |
| 94 | { |
| 95 | struct smbios_type17 *t = (struct smbios_type17 *)*current; |
| 96 | int len; |
| 97 | |
| 98 | memset(t, 0, sizeof(struct smbios_type17)); |
| 99 | t->type = SMBIOS_MEMORY_DEVICE; |
| 100 | t->handle = handle; |
| 101 | t->phys_memory_array_handle = parent_handle; |
| 102 | t->length = sizeof(struct smbios_type17) - 2; |
| 103 | t->size = qemu_get_memory_size() / 1024; |
| 104 | t->data_width = 64; |
| 105 | t->total_width = 64; |
| 106 | t->form_factor = 9; /* DIMM */ |
| 107 | t->device_locator = smbios_add_string(t->eos, "Virtual"); |
| 108 | t->memory_type = 0x12; /* DDR */ |
| 109 | t->type_detail = 0x80; /* Synchronous */ |
| 110 | t->speed = 200; |
| 111 | t->clock_speed = 200; |
| 112 | t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR); |
| 113 | len = t->length + smbios_string_table_len(t->eos); |
| 114 | *current += len; |
| 115 | return len; |
| 116 | } |
| 117 | |
| 118 | static int qemu_get_smbios_data(device_t dev, int *handle, unsigned long *current) |
| 119 | { |
| 120 | int len; |
| 121 | len = qemu_get_smbios_data16(*handle, current); |
| 122 | len += qemu_get_smbios_data17(*handle+1, *handle, current); |
| 123 | *handle += 2; |
| 124 | return len; |
| 125 | } |
| 126 | #endif |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 127 | static struct device_operations pci_domain_ops = { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 128 | .read_resources = cpu_pci_domain_read_resources, |
| 129 | .set_resources = cpu_pci_domain_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 130 | .enable_resources = NULL, |
| 131 | .init = NULL, |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 132 | .scan_bus = pci_domain_scan_bus, |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 133 | #if CONFIG_GENERATE_SMBIOS_TABLES |
| 134 | .get_smbios_data = qemu_get_smbios_data, |
| 135 | #endif |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 136 | }; |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 137 | |
| 138 | static void enable_dev(struct device *dev) |
| 139 | { |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 140 | /* Set the operations if it is a special bus type */ |
| 141 | if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) { |
| 142 | dev->ops = &pci_domain_ops; |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 143 | pci_set_method(dev); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 144 | } |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Patrick Georgi | 35784b6 | 2010-04-08 12:47:35 +0000 | [diff] [blame] | 147 | struct chip_operations mainboard_emulation_qemu_x86_ops = { |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 148 | CHIP_NAME("QEMU Northbridge") |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 149 | .enable_dev = enable_dev, |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 150 | }; |