Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
Gerd Hoffmann | aa588e0 | 2013-05-31 09:26:55 +0200 | [diff] [blame] | 2 | #include <cpu/cpu.h> |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 3 | #include <cpu/x86/lapic_def.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 4 | #include <arch/io.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 5 | #include <arch/ioapic.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 6 | #include <stdint.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 9 | #include <stdlib.h> |
| 10 | #include <string.h> |
Myles Watson | 2e67273 | 2009-11-12 16:38:03 +0000 | [diff] [blame] | 11 | #include <delay.h> |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 12 | #include <smbios.h> |
Rudolf Marek | 97be27e | 2010-12-13 19:50:25 +0000 | [diff] [blame] | 13 | #include <cbmem.h> |
Myles Watson | 0520d55 | 2009-05-11 22:44:14 +0000 | [diff] [blame] | 14 | |
Gerd Hoffmann | aa588e0 | 2013-05-31 09:26:55 +0200 | [diff] [blame] | 15 | #include "fw_cfg.h" |
| 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 | |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 41 | /* Leave some space for ACPI, PIRQ and MP tables */ |
Rudolf Marek | 97be27e | 2010-12-13 19:50:25 +0000 | [diff] [blame] | 42 | high_tables_base = (tomk * 1024) - HIGH_MEMORY_SIZE; |
| 43 | high_tables_size = HIGH_MEMORY_SIZE; |
Valdimir Serbinenko | 7339f36 | 2010-05-03 16:21:52 +0000 | [diff] [blame] | 44 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 45 | assign_resources(dev->link_list); |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 46 | } |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 47 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 48 | static void cpu_pci_domain_read_resources(struct device *dev) |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 49 | { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 50 | struct resource *res; |
| 51 | |
| 52 | pci_domain_read_resources(dev); |
| 53 | |
| 54 | /* Reserve space for the IOAPIC. This should be in the Southbridge, |
| 55 | * but I couldn't tell which device to put it in. */ |
| 56 | res = new_resource(dev, 2); |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 57 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 58 | res->size = 0x100000UL; |
| 59 | res->limit = 0xffffffffUL; |
| 60 | res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | |
| 61 | IORESOURCE_ASSIGNED; |
| 62 | |
| 63 | /* Reserve space for the LAPIC. There's one in every processor, but |
| 64 | * the space only needs to be reserved once, so we do it here. */ |
| 65 | res = new_resource(dev, 3); |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 66 | res->base = LOCAL_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 67 | res->size = 0x10000UL; |
| 68 | res->limit = 0xffffffffUL; |
| 69 | res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | |
| 70 | IORESOURCE_ASSIGNED; |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 73 | #if CONFIG_GENERATE_SMBIOS_TABLES |
| 74 | static int qemu_get_smbios_data16(int handle, unsigned long *current) |
| 75 | { |
| 76 | struct smbios_type16 *t = (struct smbios_type16 *)*current; |
| 77 | int len = sizeof(struct smbios_type16); |
| 78 | |
| 79 | memset(t, 0, sizeof(struct smbios_type16)); |
| 80 | t->type = SMBIOS_PHYS_MEMORY_ARRAY; |
| 81 | t->handle = handle; |
| 82 | t->length = len - 2; |
| 83 | t->location = 3; /* Location: System Board */ |
| 84 | t->use = 3; /* System memory */ |
| 85 | t->memory_error_correction = 3; /* No error correction */ |
| 86 | t->maximum_capacity = qemu_get_memory_size(); |
| 87 | *current += len; |
| 88 | return len; |
| 89 | } |
| 90 | |
| 91 | static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *current) |
| 92 | { |
| 93 | struct smbios_type17 *t = (struct smbios_type17 *)*current; |
| 94 | int len; |
| 95 | |
| 96 | memset(t, 0, sizeof(struct smbios_type17)); |
| 97 | t->type = SMBIOS_MEMORY_DEVICE; |
| 98 | t->handle = handle; |
| 99 | t->phys_memory_array_handle = parent_handle; |
| 100 | t->length = sizeof(struct smbios_type17) - 2; |
| 101 | t->size = qemu_get_memory_size() / 1024; |
| 102 | t->data_width = 64; |
| 103 | t->total_width = 64; |
| 104 | t->form_factor = 9; /* DIMM */ |
| 105 | t->device_locator = smbios_add_string(t->eos, "Virtual"); |
| 106 | t->memory_type = 0x12; /* DDR */ |
| 107 | t->type_detail = 0x80; /* Synchronous */ |
| 108 | t->speed = 200; |
| 109 | t->clock_speed = 200; |
| 110 | t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR); |
| 111 | len = t->length + smbios_string_table_len(t->eos); |
| 112 | *current += len; |
| 113 | return len; |
| 114 | } |
| 115 | |
| 116 | static int qemu_get_smbios_data(device_t dev, int *handle, unsigned long *current) |
| 117 | { |
| 118 | int len; |
| 119 | len = qemu_get_smbios_data16(*handle, current); |
| 120 | len += qemu_get_smbios_data17(*handle+1, *handle, current); |
| 121 | *handle += 2; |
| 122 | return len; |
| 123 | } |
| 124 | #endif |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 125 | static struct device_operations pci_domain_ops = { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 126 | .read_resources = cpu_pci_domain_read_resources, |
| 127 | .set_resources = cpu_pci_domain_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 128 | .enable_resources = NULL, |
| 129 | .init = NULL, |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 130 | .scan_bus = pci_domain_scan_bus, |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 131 | #if CONFIG_GENERATE_SMBIOS_TABLES |
| 132 | .get_smbios_data = qemu_get_smbios_data, |
| 133 | #endif |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 134 | }; |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 135 | |
Gerd Hoffmann | aa588e0 | 2013-05-31 09:26:55 +0200 | [diff] [blame] | 136 | static void cpu_bus_init(device_t dev) |
| 137 | { |
| 138 | initialize_cpus(dev->link_list); |
| 139 | } |
| 140 | |
| 141 | static unsigned int cpu_bus_scan(device_t bus, unsigned int max) |
| 142 | { |
| 143 | int max_cpus = fw_cfg_max_cpus(); |
| 144 | device_t cpu; |
| 145 | int i; |
| 146 | |
| 147 | if (max_cpus < 0) |
| 148 | return 0; |
| 149 | |
| 150 | /* |
| 151 | * TODO: This only handles the simple "qemu -smp $nr" case |
| 152 | * correctly. qemu also allows to specify the number of |
| 153 | * cores, threads & sockets. |
| 154 | */ |
| 155 | printk(BIOS_INFO, "QEMU: max_cpus is %d\n", max_cpus); |
| 156 | for (i = 0; i < max_cpus; i++) { |
| 157 | cpu = add_cpu_device(bus->link_list, i, 1); |
| 158 | if (cpu) |
| 159 | set_cpu_topology(cpu, 1, 0, i, 0); |
| 160 | } |
| 161 | return max_cpus; |
| 162 | } |
| 163 | |
| 164 | static void cpu_bus_noop(device_t dev) |
| 165 | { |
| 166 | } |
| 167 | |
| 168 | static struct device_operations cpu_bus_ops = { |
| 169 | .read_resources = cpu_bus_noop, |
| 170 | .set_resources = cpu_bus_noop, |
| 171 | .enable_resources = cpu_bus_noop, |
| 172 | .init = cpu_bus_init, |
| 173 | .scan_bus = cpu_bus_scan, |
| 174 | }; |
| 175 | |
Paul Menzel | 5f20b35 | 2013-02-24 14:27:03 +0100 | [diff] [blame] | 176 | static void northbridge_enable(struct device *dev) |
Eric Biederman | 6e53f50 | 2004-10-27 08:53:57 +0000 | [diff] [blame] | 177 | { |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 178 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 179 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 180 | dev->ops = &pci_domain_ops; |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 181 | pci_set_method(dev); |
Eric Biederman | 018d8dd | 2004-11-04 11:04:33 +0000 | [diff] [blame] | 182 | } |
Gerd Hoffmann | aa588e0 | 2013-05-31 09:26:55 +0200 | [diff] [blame] | 183 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 184 | dev->ops = &cpu_bus_ops; |
| 185 | } |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Gerd Hoffmann | 00cc7f43 | 2013-06-07 15:46:23 +0200 | [diff] [blame^] | 188 | struct chip_operations mainboard_emulation_qemu_i440fx_ops = { |
| 189 | CHIP_NAME("QEMU Northbridge i440fx") |
Paul Menzel | 5f20b35 | 2013-02-24 14:27:03 +0100 | [diff] [blame] | 190 | .enable_dev = northbridge_enable, |
Stefan Reinauer | e2b53e1 | 2004-06-28 11:59:45 +0000 | [diff] [blame] | 191 | }; |