blob: ed372b6a9f6a9e75d6c577a94c0d2507ca8b11ae [file] [log] [blame]
Stefan Reinauere2b53e12004-06-28 11:59:45 +00001#include <console/console.h>
Gerd Hoffmannaa588e02013-05-31 09:26:55 +02002#include <cpu/cpu.h>
Patrick Georgic8feedd2012-02-16 18:43:25 +01003#include <cpu/x86/lapic_def.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00004#include <arch/io.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +00005#include <arch/ioapic.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00006#include <stdint.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00007#include <device/device.h>
8#include <device/pci.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00009#include <stdlib.h>
10#include <string.h>
Myles Watson2e672732009-11-12 16:38:03 +000011#include <delay.h>
Sven Schnelle164bcfd2011-08-14 20:56:34 +020012#include <smbios.h>
Rudolf Marek97be27e2010-12-13 19:50:25 +000013#include <cbmem.h>
Myles Watson0520d552009-05-11 22:44:14 +000014
Gerd Hoffmannaa588e02013-05-31 09:26:55 +020015#include "fw_cfg.h"
16
Stefan Reinauer597ff872013-01-07 13:21:22 -080017#include "memory.c"
Sven Schnelle164bcfd2011-08-14 20:56:34 +020018
Myles Watson29cc9ed2009-07-02 18:56:24 +000019static void cpu_pci_domain_set_resources(device_t dev)
Eric Biederman6e53f502004-10-27 08:53:57 +000020{
Myles Watson894a3472010-06-09 22:41:35 +000021 assign_resources(dev->link_list);
Eric Biederman6e53f502004-10-27 08:53:57 +000022}
Stefan Reinauere2b53e12004-06-28 11:59:45 +000023
Myles Watson29cc9ed2009-07-02 18:56:24 +000024static void cpu_pci_domain_read_resources(struct device *dev)
Eric Biederman6e53f502004-10-27 08:53:57 +000025{
Myles Watson29cc9ed2009-07-02 18:56:24 +000026 struct resource *res;
Gerd Hoffmann44b11f22013-06-17 13:30:50 +020027 unsigned long tomk = 0;
28 int idx = 10;
Myles Watson29cc9ed2009-07-02 18:56:24 +000029
30 pci_domain_read_resources(dev);
31
Gerd Hoffmann44b11f22013-06-17 13:30:50 +020032 tomk = qemu_get_memory_size();
33 printk(BIOS_DEBUG, "Detected %lu MiB RAM.\n", tomk / 1024);
34
35 /* Report the memory regions. */
36 idx = 10;
37 ram_resource(dev, idx++, 0, 640);
38 ram_resource(dev, idx++, 768, tomk - 768);
39
40 /* Leave some space for ACPI, PIRQ and MP tables */
41 high_tables_base = (tomk * 1024) - HIGH_MEMORY_SIZE;
42 high_tables_size = HIGH_MEMORY_SIZE;
43
Myles Watson29cc9ed2009-07-02 18:56:24 +000044 /* Reserve space for the IOAPIC. This should be in the Southbridge,
45 * but I couldn't tell which device to put it in. */
46 res = new_resource(dev, 2);
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000047 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +000048 res->size = 0x100000UL;
49 res->limit = 0xffffffffUL;
50 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
51 IORESOURCE_ASSIGNED;
52
53 /* Reserve space for the LAPIC. There's one in every processor, but
54 * the space only needs to be reserved once, so we do it here. */
55 res = new_resource(dev, 3);
Patrick Georgic8feedd2012-02-16 18:43:25 +010056 res->base = LOCAL_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +000057 res->size = 0x10000UL;
58 res->limit = 0xffffffffUL;
59 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
60 IORESOURCE_ASSIGNED;
Eric Biederman6e53f502004-10-27 08:53:57 +000061}
62
Sven Schnelle164bcfd2011-08-14 20:56:34 +020063#if CONFIG_GENERATE_SMBIOS_TABLES
64static int qemu_get_smbios_data16(int handle, unsigned long *current)
65{
66 struct smbios_type16 *t = (struct smbios_type16 *)*current;
67 int len = sizeof(struct smbios_type16);
68
69 memset(t, 0, sizeof(struct smbios_type16));
70 t->type = SMBIOS_PHYS_MEMORY_ARRAY;
71 t->handle = handle;
72 t->length = len - 2;
73 t->location = 3; /* Location: System Board */
74 t->use = 3; /* System memory */
75 t->memory_error_correction = 3; /* No error correction */
76 t->maximum_capacity = qemu_get_memory_size();
77 *current += len;
78 return len;
79}
80
81static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *current)
82{
83 struct smbios_type17 *t = (struct smbios_type17 *)*current;
84 int len;
85
86 memset(t, 0, sizeof(struct smbios_type17));
87 t->type = SMBIOS_MEMORY_DEVICE;
88 t->handle = handle;
89 t->phys_memory_array_handle = parent_handle;
90 t->length = sizeof(struct smbios_type17) - 2;
91 t->size = qemu_get_memory_size() / 1024;
92 t->data_width = 64;
93 t->total_width = 64;
94 t->form_factor = 9; /* DIMM */
95 t->device_locator = smbios_add_string(t->eos, "Virtual");
96 t->memory_type = 0x12; /* DDR */
97 t->type_detail = 0x80; /* Synchronous */
98 t->speed = 200;
99 t->clock_speed = 200;
100 t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
101 len = t->length + smbios_string_table_len(t->eos);
102 *current += len;
103 return len;
104}
105
106static int qemu_get_smbios_data(device_t dev, int *handle, unsigned long *current)
107{
108 int len;
109 len = qemu_get_smbios_data16(*handle, current);
110 len += qemu_get_smbios_data17(*handle+1, *handle, current);
111 *handle += 2;
112 return len;
113}
114#endif
Eric Biederman6e53f502004-10-27 08:53:57 +0000115static struct device_operations pci_domain_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000116 .read_resources = cpu_pci_domain_read_resources,
117 .set_resources = cpu_pci_domain_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +0000118 .enable_resources = NULL,
119 .init = NULL,
Myles Watson032a9652009-05-11 22:24:53 +0000120 .scan_bus = pci_domain_scan_bus,
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200121#if CONFIG_GENERATE_SMBIOS_TABLES
122 .get_smbios_data = qemu_get_smbios_data,
123#endif
Myles Watson032a9652009-05-11 22:24:53 +0000124};
Eric Biederman6e53f502004-10-27 08:53:57 +0000125
Gerd Hoffmannaa588e02013-05-31 09:26:55 +0200126static void cpu_bus_init(device_t dev)
127{
128 initialize_cpus(dev->link_list);
129}
130
131static unsigned int cpu_bus_scan(device_t bus, unsigned int max)
132{
133 int max_cpus = fw_cfg_max_cpus();
134 device_t cpu;
135 int i;
136
137 if (max_cpus < 0)
138 return 0;
139
140 /*
141 * TODO: This only handles the simple "qemu -smp $nr" case
142 * correctly. qemu also allows to specify the number of
143 * cores, threads & sockets.
144 */
145 printk(BIOS_INFO, "QEMU: max_cpus is %d\n", max_cpus);
146 for (i = 0; i < max_cpus; i++) {
147 cpu = add_cpu_device(bus->link_list, i, 1);
148 if (cpu)
149 set_cpu_topology(cpu, 1, 0, i, 0);
150 }
151 return max_cpus;
152}
153
154static void cpu_bus_noop(device_t dev)
155{
156}
157
158static struct device_operations cpu_bus_ops = {
159 .read_resources = cpu_bus_noop,
160 .set_resources = cpu_bus_noop,
161 .enable_resources = cpu_bus_noop,
162 .init = cpu_bus_init,
163 .scan_bus = cpu_bus_scan,
164};
165
Paul Menzel5f20b352013-02-24 14:27:03 +0100166static void northbridge_enable(struct device *dev)
Eric Biederman6e53f502004-10-27 08:53:57 +0000167{
Eric Biederman018d8dd2004-11-04 11:04:33 +0000168 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800169 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Eric Biederman018d8dd2004-11-04 11:04:33 +0000170 dev->ops = &pci_domain_ops;
Eric Biedermana9e632c2004-11-18 22:38:08 +0000171 pci_set_method(dev);
Eric Biederman018d8dd2004-11-04 11:04:33 +0000172 }
Gerd Hoffmannaa588e02013-05-31 09:26:55 +0200173 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
174 dev->ops = &cpu_bus_ops;
175 }
Stefan Reinauere2b53e12004-06-28 11:59:45 +0000176}
177
Gerd Hoffmann00cc7f432013-06-07 15:46:23 +0200178struct chip_operations mainboard_emulation_qemu_i440fx_ops = {
179 CHIP_NAME("QEMU Northbridge i440fx")
Paul Menzel5f20b352013-02-24 14:27:03 +0100180 .enable_dev = northbridge_enable,
Stefan Reinauere2b53e12004-06-28 11:59:45 +0000181};