2004-06-28 13:59:45 +02:00
|
|
|
#include <console/console.h>
|
2012-02-16 18:43:25 +01:00
|
|
|
#include <cpu/x86/lapic_def.h>
|
2004-06-28 13:59:45 +02:00
|
|
|
#include <arch/io.h>
|
2010-10-12 19:34:08 +02:00
|
|
|
#include <arch/ioapic.h>
|
2004-06-28 13:59:45 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-11-12 17:38:03 +01:00
|
|
|
#include <delay.h>
|
2011-08-14 20:56:34 +02:00
|
|
|
#include <smbios.h>
|
2004-06-28 13:59:45 +02:00
|
|
|
|
Clean up #ifs
Replace #if CONFIG_FOO==1 with #if CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*1[[:space:]]*\$,#if \1," {} +
Replace #if (CONFIG_FOO==1) with #if CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*(\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*1)[[:space:]]*\$,#if \1," {} +
Replace #if CONFIG_FOO==0 with #if !CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*0[[:space:]]*\$,#if \!\1," {} +
Replace #if (CONFIG_FOO==0) with #if !CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*(\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*0)[[:space:]]*\$,#if \!\1," {} +
(and some manual changes to fix false positives)
Change-Id: Iac6ca7605a5f99885258cf1a9a2473a92de27c42
Signed-off-by: Patrick Georgi <patrick@georgi-clan.de>
Reviewed-on: http://review.coreboot.org/1004
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-by: Martin Roth <martin@se-eng.com>
2012-05-05 15:29:32 +02:00
|
|
|
#if CONFIG_WRITE_HIGH_TABLES
|
2010-12-13 20:50:25 +01:00
|
|
|
#include <cbmem.h>
|
2009-05-12 00:44:14 +02:00
|
|
|
#endif
|
|
|
|
|
2010-05-03 18:21:52 +02:00
|
|
|
#define CMOS_ADDR_PORT 0x70
|
|
|
|
#define CMOS_DATA_PORT 0x71
|
|
|
|
#define HIGH_RAM_ADDR 0x35
|
|
|
|
#define LOW_RAM_ADDR 0x34
|
|
|
|
|
2011-08-14 20:56:34 +02:00
|
|
|
static unsigned long qemu_get_memory_size(void)
|
2004-10-27 10:53:57 +02:00
|
|
|
{
|
2011-08-14 20:56:34 +02:00
|
|
|
unsigned long tomk;
|
2010-05-03 18:21:52 +02:00
|
|
|
outb (HIGH_RAM_ADDR, CMOS_ADDR_PORT);
|
|
|
|
tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14;
|
|
|
|
outb (LOW_RAM_ADDR, CMOS_ADDR_PORT);
|
|
|
|
tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6;
|
|
|
|
tomk += 16 * 1024;
|
2011-08-14 20:56:34 +02:00
|
|
|
return tomk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_pci_domain_set_resources(device_t dev)
|
|
|
|
{
|
|
|
|
u32 pci_tolm = find_pci_tolm(dev->link_list);
|
|
|
|
unsigned long tomk = 0, tolmk;
|
|
|
|
int idx;
|
2010-05-03 18:21:52 +02:00
|
|
|
|
2011-08-14 20:56:34 +02:00
|
|
|
tomk = qemu_get_memory_size();
|
2010-05-03 18:21:52 +02:00
|
|
|
printk(BIOS_DEBUG, "Detected %lu Kbytes (%lu MiB) RAM.\n",
|
|
|
|
tomk, tomk / 1024);
|
|
|
|
|
|
|
|
/* Compute the top of Low memory */
|
|
|
|
tolmk = pci_tolm >> 10;
|
|
|
|
if (tolmk >= tomk) {
|
|
|
|
/* The PCI hole does not overlap the memory. */
|
|
|
|
tolmk = tomk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Report the memory regions. */
|
|
|
|
idx = 10;
|
|
|
|
ram_resource(dev, idx++, 0, 640);
|
|
|
|
ram_resource(dev, idx++, 768, tolmk - 768);
|
2009-05-12 00:44:14 +02:00
|
|
|
|
Clean up #ifs
Replace #if CONFIG_FOO==1 with #if CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*1[[:space:]]*\$,#if \1," {} +
Replace #if (CONFIG_FOO==1) with #if CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*(\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*1)[[:space:]]*\$,#if \1," {} +
Replace #if CONFIG_FOO==0 with #if !CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*0[[:space:]]*\$,#if \!\1," {} +
Replace #if (CONFIG_FOO==0) with #if !CONFIG_FOO:
find src -name \*.[ch] -exec sed -i "s,#if[[:space:]]*(\(CONFIG_[A-Z0-9_]*\)[[:space:]]*==[[:space:]]*0)[[:space:]]*\$,#if \!\1," {} +
(and some manual changes to fix false positives)
Change-Id: Iac6ca7605a5f99885258cf1a9a2473a92de27c42
Signed-off-by: Patrick Georgi <patrick@georgi-clan.de>
Reviewed-on: http://review.coreboot.org/1004
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-by: Martin Roth <martin@se-eng.com>
2012-05-05 15:29:32 +02:00
|
|
|
#if CONFIG_WRITE_HIGH_TABLES
|
2010-05-03 18:21:52 +02:00
|
|
|
/* Leave some space for ACPI, PIRQ and MP tables */
|
2010-12-13 20:50:25 +01:00
|
|
|
high_tables_base = (tomk * 1024) - HIGH_MEMORY_SIZE;
|
|
|
|
high_tables_size = HIGH_MEMORY_SIZE;
|
2009-05-12 00:44:14 +02:00
|
|
|
#endif
|
2010-05-03 18:21:52 +02:00
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
assign_resources(dev->link_list);
|
2004-10-27 10:53:57 +02:00
|
|
|
}
|
|
|
|
|
2009-07-02 20:56:24 +02:00
|
|
|
static void cpu_pci_domain_read_resources(struct device *dev)
|
2004-10-27 10:53:57 +02:00
|
|
|
{
|
2009-07-02 20:56:24 +02:00
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
pci_domain_read_resources(dev);
|
|
|
|
|
|
|
|
/* Reserve space for the IOAPIC. This should be in the Southbridge,
|
|
|
|
* but I couldn't tell which device to put it in. */
|
|
|
|
res = new_resource(dev, 2);
|
2010-10-12 19:34:08 +02:00
|
|
|
res->base = IO_APIC_ADDR;
|
2009-07-02 20:56:24 +02:00
|
|
|
res->size = 0x100000UL;
|
|
|
|
res->limit = 0xffffffffUL;
|
|
|
|
res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
|
|
|
|
IORESOURCE_ASSIGNED;
|
|
|
|
|
|
|
|
/* Reserve space for the LAPIC. There's one in every processor, but
|
|
|
|
* the space only needs to be reserved once, so we do it here. */
|
|
|
|
res = new_resource(dev, 3);
|
2012-02-16 18:43:25 +01:00
|
|
|
res->base = LOCAL_APIC_ADDR;
|
2009-07-02 20:56:24 +02:00
|
|
|
res->size = 0x10000UL;
|
|
|
|
res->limit = 0xffffffffUL;
|
|
|
|
res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
|
|
|
|
IORESOURCE_ASSIGNED;
|
2004-10-27 10:53:57 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 20:56:34 +02:00
|
|
|
#if CONFIG_GENERATE_SMBIOS_TABLES
|
|
|
|
static int qemu_get_smbios_data16(int handle, unsigned long *current)
|
|
|
|
{
|
|
|
|
struct smbios_type16 *t = (struct smbios_type16 *)*current;
|
|
|
|
int len = sizeof(struct smbios_type16);
|
|
|
|
|
|
|
|
memset(t, 0, sizeof(struct smbios_type16));
|
|
|
|
t->type = SMBIOS_PHYS_MEMORY_ARRAY;
|
|
|
|
t->handle = handle;
|
|
|
|
t->length = len - 2;
|
|
|
|
t->location = 3; /* Location: System Board */
|
|
|
|
t->use = 3; /* System memory */
|
|
|
|
t->memory_error_correction = 3; /* No error correction */
|
|
|
|
t->maximum_capacity = qemu_get_memory_size();
|
|
|
|
*current += len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qemu_get_smbios_data17(int handle, int parent_handle, unsigned long *current)
|
|
|
|
{
|
|
|
|
struct smbios_type17 *t = (struct smbios_type17 *)*current;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
memset(t, 0, sizeof(struct smbios_type17));
|
|
|
|
t->type = SMBIOS_MEMORY_DEVICE;
|
|
|
|
t->handle = handle;
|
|
|
|
t->phys_memory_array_handle = parent_handle;
|
|
|
|
t->length = sizeof(struct smbios_type17) - 2;
|
|
|
|
t->size = qemu_get_memory_size() / 1024;
|
|
|
|
t->data_width = 64;
|
|
|
|
t->total_width = 64;
|
|
|
|
t->form_factor = 9; /* DIMM */
|
|
|
|
t->device_locator = smbios_add_string(t->eos, "Virtual");
|
|
|
|
t->memory_type = 0x12; /* DDR */
|
|
|
|
t->type_detail = 0x80; /* Synchronous */
|
|
|
|
t->speed = 200;
|
|
|
|
t->clock_speed = 200;
|
|
|
|
t->manufacturer = smbios_add_string(t->eos, CONFIG_MAINBOARD_VENDOR);
|
|
|
|
len = t->length + smbios_string_table_len(t->eos);
|
|
|
|
*current += len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qemu_get_smbios_data(device_t dev, int *handle, unsigned long *current)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
len = qemu_get_smbios_data16(*handle, current);
|
|
|
|
len += qemu_get_smbios_data17(*handle+1, *handle, current);
|
|
|
|
*handle += 2;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif
|
2004-10-27 10:53:57 +02:00
|
|
|
static struct device_operations pci_domain_ops = {
|
2009-07-02 20:56:24 +02:00
|
|
|
.read_resources = cpu_pci_domain_read_resources,
|
|
|
|
.set_resources = cpu_pci_domain_set_resources,
|
2010-06-17 18:16:56 +02:00
|
|
|
.enable_resources = NULL,
|
|
|
|
.init = NULL,
|
2009-05-12 00:24:53 +02:00
|
|
|
.scan_bus = pci_domain_scan_bus,
|
2011-08-14 20:56:34 +02:00
|
|
|
#if CONFIG_GENERATE_SMBIOS_TABLES
|
|
|
|
.get_smbios_data = qemu_get_smbios_data,
|
|
|
|
#endif
|
2009-05-12 00:24:53 +02:00
|
|
|
};
|
2004-10-27 10:53:57 +02:00
|
|
|
|
|
|
|
static void enable_dev(struct device *dev)
|
|
|
|
{
|
2004-11-04 12:04:33 +01:00
|
|
|
/* Set the operations if it is a special bus type */
|
|
|
|
if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
|
|
|
|
dev->ops = &pci_domain_ops;
|
2004-11-18 23:38:08 +01:00
|
|
|
pci_set_method(dev);
|
2004-11-04 12:04:33 +01:00
|
|
|
}
|
2004-06-28 13:59:45 +02:00
|
|
|
}
|
|
|
|
|
2010-04-08 14:47:35 +02:00
|
|
|
struct chip_operations mainboard_emulation_qemu_x86_ops = {
|
2004-11-04 12:04:33 +01:00
|
|
|
CHIP_NAME("QEMU Northbridge")
|
2004-10-27 10:53:57 +02:00
|
|
|
.enable_dev = enable_dev,
|
2004-06-28 13:59:45 +02:00
|
|
|
};
|