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