blob: 7c36c0a469b1ebf477fa6e35484ef7fc874c4ff4 [file] [log] [blame]
Stefan Reinauere2b53e12004-06-28 11:59:45 +00001#include <console/console.h>
Patrick Georgic8feedd2012-02-16 18:43:25 +01002#include <cpu/x86/lapic_def.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00003#include <arch/io.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +00004#include <arch/ioapic.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00005#include <stdint.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00006#include <device/device.h>
7#include <device/pci.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +00008#include <stdlib.h>
9#include <string.h>
Myles Watson2e672732009-11-12 16:38:03 +000010#include <delay.h>
Sven Schnelle164bcfd2011-08-14 20:56:34 +020011#include <smbios.h>
Stefan Reinauere2b53e12004-06-28 11:59:45 +000012
Patrick Georgie1667822012-05-05 15:29:32 +020013#if CONFIG_WRITE_HIGH_TABLES
Rudolf Marek97be27e2010-12-13 19:50:25 +000014#include <cbmem.h>
Myles Watson0520d552009-05-11 22:44:14 +000015#endif
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 u32 pci_tolm = find_pci_tolm(dev->link_list);
Valdimir Serbinenko7339f362010-05-03 16:21:52 +000022 unsigned long tomk = 0, tolmk;
23 int idx;
Eric Biederman6e53f502004-10-27 08:53:57 +000024
Sven Schnelle164bcfd2011-08-14 20:56:34 +020025 tomk = qemu_get_memory_size();
Valdimir Serbinenko7339f362010-05-03 16:21:52 +000026 printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n",
27 tomk, tomk / 1024);
Myles Watson032a9652009-05-11 22:24:53 +000028
Valdimir Serbinenko7339f362010-05-03 16:21:52 +000029 /* 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 Watson0520d552009-05-11 22:44:14 +000040
Patrick Georgie1667822012-05-05 15:29:32 +020041#if CONFIG_WRITE_HIGH_TABLES
Valdimir Serbinenko7339f362010-05-03 16:21:52 +000042 /* Leave some space for ACPI, PIRQ and MP tables */
Rudolf Marek97be27e2010-12-13 19:50:25 +000043 high_tables_base = (tomk * 1024) - HIGH_MEMORY_SIZE;
44 high_tables_size = HIGH_MEMORY_SIZE;
Myles Watson0520d552009-05-11 22:44:14 +000045#endif
Valdimir Serbinenko7339f362010-05-03 16:21:52 +000046
Myles Watson894a3472010-06-09 22:41:35 +000047 assign_resources(dev->link_list);
Eric Biederman6e53f502004-10-27 08:53:57 +000048}
Stefan Reinauere2b53e12004-06-28 11:59:45 +000049
Myles Watson29cc9ed2009-07-02 18:56:24 +000050static void cpu_pci_domain_read_resources(struct device *dev)
Eric Biederman6e53f502004-10-27 08:53:57 +000051{
Myles Watson29cc9ed2009-07-02 18:56:24 +000052 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 Hermann74d1a6e2010-10-12 17:34:08 +000059 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +000060 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 Georgic8feedd2012-02-16 18:43:25 +010068 res->base = LOCAL_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +000069 res->size = 0x10000UL;
70 res->limit = 0xffffffffUL;
71 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
72 IORESOURCE_ASSIGNED;
Eric Biederman6e53f502004-10-27 08:53:57 +000073}
74
Sven Schnelle164bcfd2011-08-14 20:56:34 +020075#if CONFIG_GENERATE_SMBIOS_TABLES
76static 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
93static 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
118static 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 Biederman6e53f502004-10-27 08:53:57 +0000127static struct device_operations pci_domain_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000128 .read_resources = cpu_pci_domain_read_resources,
129 .set_resources = cpu_pci_domain_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +0000130 .enable_resources = NULL,
131 .init = NULL,
Myles Watson032a9652009-05-11 22:24:53 +0000132 .scan_bus = pci_domain_scan_bus,
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200133#if CONFIG_GENERATE_SMBIOS_TABLES
134 .get_smbios_data = qemu_get_smbios_data,
135#endif
Myles Watson032a9652009-05-11 22:24:53 +0000136};
Eric Biederman6e53f502004-10-27 08:53:57 +0000137
138static void enable_dev(struct device *dev)
139{
Eric Biederman018d8dd2004-11-04 11:04:33 +0000140 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800141 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Eric Biederman018d8dd2004-11-04 11:04:33 +0000142 dev->ops = &pci_domain_ops;
Eric Biedermana9e632c2004-11-18 22:38:08 +0000143 pci_set_method(dev);
Eric Biederman018d8dd2004-11-04 11:04:33 +0000144 }
Stefan Reinauere2b53e12004-06-28 11:59:45 +0000145}
146
Patrick Georgi35784b62010-04-08 12:47:35 +0000147struct chip_operations mainboard_emulation_qemu_x86_ops = {
Eric Biederman018d8dd2004-11-04 11:04:33 +0000148 CHIP_NAME("QEMU Northbridge")
Eric Biederman6e53f502004-10-27 08:53:57 +0000149 .enable_dev = enable_dev,
Stefan Reinauere2b53e12004-06-28 11:59:45 +0000150};