X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=hw%2Facpi.c;h=6e3f69eac569b555b156fe85017dfe65fdb10260;hb=cd346349b45ef056f138a184f660b8c34c3213cc;hp=8fb054428dc038c51eacbe65958d0739a427ce46;hpb=502a53952d574717bdb626b651b16cadacab46f4;p=qemu diff --git a/hw/acpi.c b/hw/acpi.c index 8fb0544..6e3f69e 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -1,8 +1,8 @@ /* * ACPI implementation - * + * * Copyright (c) 2006 Fabrice Bellard - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2 as published by the Free Software Foundation. @@ -23,9 +23,6 @@ /* i82731AB (PIIX4) compatible power management function */ #define PM_FREQ 3579545 -/* XXX: make them variable */ -#define PM_IO_BASE 0xb000 -#define SMI_CMD_IO_ADDR 0xb040 #define ACPI_DBG_IO_ADDR 0xb044 typedef struct PIIX4PMState { @@ -33,8 +30,19 @@ typedef struct PIIX4PMState { uint16_t pmsts; uint16_t pmen; uint16_t pmcntrl; + uint8_t apmc; + uint8_t apms; QEMUTimer *tmr_timer; int64_t tmr_overflow_time; + i2c_bus *smbus; + uint8_t smb_stat; + uint8_t smb_ctl; + uint8_t smb_cmd; + uint8_t smb_addr; + uint8_t smb_data0; + uint8_t smb_data1; + uint8_t smb_data[32]; + uint8_t smb_index; } PIIX4PMState; #define RTC_EN (1 << 10) @@ -46,9 +54,16 @@ typedef struct PIIX4PMState { #define SUS_EN (1 << 13) -/* Note: only used for ACPI bios init. Could be deleted when ACPI init - is integrated in Bochs BIOS */ -static PIIX4PMState *piix4_pm_state; +#define ACPI_ENABLE 0xf1 +#define ACPI_DISABLE 0xf0 + +#define SMBHSTSTS 0x00 +#define SMBHSTCNT 0x02 +#define SMBHSTCMD 0x03 +#define SMBHSTADD 0x04 +#define SMBHSTDAT0 0x05 +#define SMBHSTDAT1 0x06 +#define SMBBLKDAT 0x07 static uint32_t get_pmtmr(PIIX4PMState *s) { @@ -72,11 +87,11 @@ static void pm_update_sci(PIIX4PMState *s) { int sci_level, pmsts; int64_t expire_time; - + pmsts = get_pmsts(s); - sci_level = (((pmsts & s->pmen) & + sci_level = (((pmsts & s->pmen) & (RTC_EN | PWRBTN_EN | GBL_EN | TMROF_EN)) != 0); - pci_set_irq(&s->dev, 0, sci_level); + qemu_set_irq(s->dev.irq[0], sci_level); /* schedule a timer interruption if needed */ if ((s->pmen & TMROF_EN) && !(pmsts & TMROF_EN)) { expire_time = muldiv64(s->tmr_overflow_time, ticks_per_sec, PM_FREQ); @@ -195,20 +210,46 @@ static uint32_t pm_ioport_readl(void *opaque, uint32_t addr) return val; } -static void smi_cmd_writeb(void *opaque, uint32_t addr, uint32_t val) +static void pm_smi_writeb(void *opaque, uint32_t addr, uint32_t val) { PIIX4PMState *s = opaque; + addr &= 1; #ifdef DEBUG - printf("SMI cmd val=0x%02x\n", val); + printf("pm_smi_writeb addr=0x%x val=0x%02x\n", addr, val); #endif - switch(val) { - case 0xf0: /* ACPI disable */ - s->pmcntrl &= ~SCI_EN; - break; - case 0xf1: /* ACPI enable */ - s->pmcntrl |= SCI_EN; - break; + if (addr == 0) { + s->apmc = val; + + /* ACPI specs 3.0, 4.7.2.5 */ + if (val == ACPI_ENABLE) { + s->pmcntrl |= SCI_EN; + } else if (val == ACPI_DISABLE) { + s->pmcntrl &= ~SCI_EN; + } + + if (s->dev.config[0x5b] & (1 << 1)) { + cpu_interrupt(first_cpu, CPU_INTERRUPT_SMI); + } + } else { + s->apms = val; + } +} + +static uint32_t pm_smi_readb(void *opaque, uint32_t addr) +{ + PIIX4PMState *s = opaque; + uint32_t val; + + addr &= 1; + if (addr == 0) { + val = s->apmc; + } else { + val = s->apms; } +#ifdef DEBUG + printf("pm_smi_readb addr=0x%x val=0x%02x\n", addr, val); +#endif + return val; } static void acpi_dbg_writel(void *opaque, uint32_t addr, uint32_t val) @@ -218,392 +259,254 @@ static void acpi_dbg_writel(void *opaque, uint32_t addr, uint32_t val) #endif } -/* XXX: we still add it to the PIIX3 and we count on the fact that - OSes are smart enough to accept this strange configuration */ -void piix4_pm_init(PCIBus *bus, int devfn) +static void smb_transaction(PIIX4PMState *s) { - PIIX4PMState *s; - uint8_t *pci_conf; - uint32_t pm_io_base; + uint8_t prot = (s->smb_ctl >> 2) & 0x07; + uint8_t read = s->smb_addr & 0x01; + uint8_t cmd = s->smb_cmd; + uint8_t addr = s->smb_addr >> 1; + i2c_bus *bus = s->smbus; - s = (PIIX4PMState *)pci_register_device(bus, - "PM", sizeof(PIIX4PMState), - devfn, NULL, NULL); - pci_conf = s->dev.config; - pci_conf[0x00] = 0x86; - pci_conf[0x01] = 0x80; - pci_conf[0x02] = 0x13; - pci_conf[0x03] = 0x71; - pci_conf[0x08] = 0x00; // revision number - pci_conf[0x09] = 0x00; - pci_conf[0x0a] = 0x80; // other bridge device - pci_conf[0x0b] = 0x06; // bridge device - pci_conf[0x0e] = 0x00; // header_type - pci_conf[0x3d] = 0x01; // interrupt pin 1 - pci_conf[0x60] = 0x10; // release number - - pm_io_base = PM_IO_BASE; - pci_conf[0x40] = pm_io_base | 1; - pci_conf[0x41] = pm_io_base >> 8; - register_ioport_write(pm_io_base, 64, 2, pm_ioport_writew, s); - register_ioport_read(pm_io_base, 64, 2, pm_ioport_readw, s); - register_ioport_write(pm_io_base, 64, 4, pm_ioport_writel, s); - register_ioport_read(pm_io_base, 64, 4, pm_ioport_readl, s); - - register_ioport_write(SMI_CMD_IO_ADDR, 1, 1, smi_cmd_writeb, s); - register_ioport_write(ACPI_DBG_IO_ADDR, 4, 4, acpi_dbg_writel, s); +#ifdef DEBUG + printf("SMBus trans addr=0x%02x prot=0x%02x\n", addr, prot); +#endif + switch(prot) { + case 0x0: + smbus_quick_command(bus, addr, read); + break; + case 0x1: + if (read) { + s->smb_data0 = smbus_receive_byte(bus, addr); + } else { + smbus_send_byte(bus, addr, cmd); + } + break; + case 0x2: + if (read) { + s->smb_data0 = smbus_read_byte(bus, addr, cmd); + } else { + smbus_write_byte(bus, addr, cmd, s->smb_data0); + } + break; + case 0x3: + if (read) { + uint16_t val; + val = smbus_read_word(bus, addr, cmd); + s->smb_data0 = val; + s->smb_data1 = val >> 8; + } else { + smbus_write_word(bus, addr, cmd, (s->smb_data1 << 8) | s->smb_data0); + } + break; + case 0x5: + if (read) { + s->smb_data0 = smbus_read_block(bus, addr, cmd, s->smb_data); + } else { + smbus_write_block(bus, addr, cmd, s->smb_data, s->smb_data0); + } + break; + default: + goto error; + } + return; - s->tmr_timer = qemu_new_timer(vm_clock, pm_tmr_timer, s); - piix4_pm_state = s; + error: + s->smb_stat |= 0x04; } -/* ACPI tables */ -/* XXX: move them in the Bochs BIOS ? */ +static void smb_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) +{ + PIIX4PMState *s = opaque; + addr &= 0x3f; +#ifdef DEBUG + printf("SMB writeb port=0x%04x val=0x%02x\n", addr, val); +#endif + switch(addr) { + case SMBHSTSTS: + s->smb_stat = 0; + s->smb_index = 0; + break; + case SMBHSTCNT: + s->smb_ctl = val; + if (val & 0x40) + smb_transaction(s); + break; + case SMBHSTCMD: + s->smb_cmd = val; + break; + case SMBHSTADD: + s->smb_addr = val; + break; + case SMBHSTDAT0: + s->smb_data0 = val; + break; + case SMBHSTDAT1: + s->smb_data1 = val; + break; + case SMBBLKDAT: + s->smb_data[s->smb_index++] = val; + if (s->smb_index > 31) + s->smb_index = 0; + break; + default: + break; + } +} -/*************************************************/ +static uint32_t smb_ioport_readb(void *opaque, uint32_t addr) +{ + PIIX4PMState *s = opaque; + uint32_t val; -/* Table structure from Linux kernel (the ACPI tables are under the - BSD license) */ + addr &= 0x3f; + switch(addr) { + case SMBHSTSTS: + val = s->smb_stat; + break; + case SMBHSTCNT: + s->smb_index = 0; + val = s->smb_ctl & 0x1f; + break; + case SMBHSTCMD: + val = s->smb_cmd; + break; + case SMBHSTADD: + val = s->smb_addr; + break; + case SMBHSTDAT0: + val = s->smb_data0; + break; + case SMBHSTDAT1: + val = s->smb_data1; + break; + case SMBBLKDAT: + val = s->smb_data[s->smb_index++]; + if (s->smb_index > 31) + s->smb_index = 0; + break; + default: + val = 0; + break; + } +#ifdef DEBUG + printf("SMB readb port=0x%04x val=0x%02x\n", addr, val); +#endif + return val; +} -#define ACPI_TABLE_HEADER_DEF /* ACPI common table header */ \ - uint8_t signature [4]; /* ACPI signature (4 ASCII characters) */\ - uint32_t length; /* Length of table, in bytes, including header */\ - uint8_t revision; /* ACPI Specification minor version # */\ - uint8_t checksum; /* To make sum of entire table == 0 */\ - uint8_t oem_id [6]; /* OEM identification */\ - uint8_t oem_table_id [8]; /* OEM table identification */\ - uint32_t oem_revision; /* OEM revision number */\ - uint8_t asl_compiler_id [4]; /* ASL compiler vendor ID */\ - uint32_t asl_compiler_revision; /* ASL compiler revision number */ +static void pm_io_space_update(PIIX4PMState *s) +{ + uint32_t pm_io_base; + if (s->dev.config[0x80] & 1) { + pm_io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x40)); + pm_io_base &= 0xffc0; -struct acpi_table_header /* ACPI common table header */ -{ - ACPI_TABLE_HEADER_DEF -}; + /* XXX: need to improve memory and ioport allocation */ +#if defined(DEBUG) + printf("PM: mapping to 0x%x\n", pm_io_base); +#endif + register_ioport_write(pm_io_base, 64, 2, pm_ioport_writew, s); + register_ioport_read(pm_io_base, 64, 2, pm_ioport_readw, s); + register_ioport_write(pm_io_base, 64, 4, pm_ioport_writel, s); + register_ioport_read(pm_io_base, 64, 4, pm_ioport_readl, s); + } +} -struct rsdp_descriptor /* Root System Descriptor Pointer */ +static void pm_write_config(PCIDevice *d, + uint32_t address, uint32_t val, int len) { - uint8_t signature [8]; /* ACPI signature, contains "RSD PTR " */ - uint8_t checksum; /* To make sum of struct == 0 */ - uint8_t oem_id [6]; /* OEM identification */ - uint8_t revision; /* Must be 0 for 1.0, 2 for 2.0 */ - uint32_t rsdt_physical_address; /* 32-bit physical address of RSDT */ - uint32_t length; /* XSDT Length in bytes including hdr */ - uint64_t xsdt_physical_address; /* 64-bit physical address of XSDT */ - uint8_t extended_checksum; /* Checksum of entire table */ - uint8_t reserved [3]; /* Reserved field must be 0 */ -}; + pci_default_write_config(d, address, val, len); + if (address == 0x80) + pm_io_space_update((PIIX4PMState *)d); +} -/* - * ACPI 1.0 Root System Description Table (RSDT) - */ -struct rsdt_descriptor_rev1 +static void pm_save(QEMUFile* f,void *opaque) { - ACPI_TABLE_HEADER_DEF /* ACPI common table header */ - uint32_t table_offset_entry [2]; /* Array of pointers to other */ - /* ACPI tables */ -}; + PIIX4PMState *s = opaque; -/* - * ACPI 1.0 Firmware ACPI Control Structure (FACS) - */ -struct facs_descriptor_rev1 -{ - uint8_t signature[4]; /* ACPI Signature */ - uint32_t length; /* Length of structure, in bytes */ - uint32_t hardware_signature; /* Hardware configuration signature */ - uint32_t firmware_waking_vector; /* ACPI OS waking vector */ - uint32_t global_lock; /* Global Lock */ - uint32_t S4bios_f : 1; /* Indicates if S4BIOS support is present */ - uint32_t reserved1 : 31; /* Must be 0 */ - uint8_t resverved3 [40]; /* Reserved - must be zero */ -}; + pci_device_save(&s->dev, f); + qemu_put_be16s(f, &s->pmsts); + qemu_put_be16s(f, &s->pmen); + qemu_put_be16s(f, &s->pmcntrl); + qemu_put_8s(f, &s->apmc); + qemu_put_8s(f, &s->apms); + qemu_put_timer(f, s->tmr_timer); + qemu_put_be64s(f, &s->tmr_overflow_time); +} -/* - * ACPI 1.0 Fixed ACPI Description Table (FADT) - */ -struct fadt_descriptor_rev1 +static int pm_load(QEMUFile* f,void* opaque,int version_id) { - ACPI_TABLE_HEADER_DEF /* ACPI common table header */ - uint32_t firmware_ctrl; /* Physical address of FACS */ - uint32_t dsdt; /* Physical address of DSDT */ - uint8_t model; /* System Interrupt Model */ - uint8_t reserved1; /* Reserved */ - uint16_t sci_int; /* System vector of SCI interrupt */ - uint32_t smi_cmd; /* Port address of SMI command port */ - uint8_t acpi_enable; /* Value to write to smi_cmd to enable ACPI */ - uint8_t acpi_disable; /* Value to write to smi_cmd to disable ACPI */ - uint8_t S4bios_req; /* Value to write to SMI CMD to enter S4BIOS state */ - uint8_t reserved2; /* Reserved - must be zero */ - uint32_t pm1a_evt_blk; /* Port address of Power Mgt 1a acpi_event Reg Blk */ - uint32_t pm1b_evt_blk; /* Port address of Power Mgt 1b acpi_event Reg Blk */ - uint32_t pm1a_cnt_blk; /* Port address of Power Mgt 1a Control Reg Blk */ - uint32_t pm1b_cnt_blk; /* Port address of Power Mgt 1b Control Reg Blk */ - uint32_t pm2_cnt_blk; /* Port address of Power Mgt 2 Control Reg Blk */ - uint32_t pm_tmr_blk; /* Port address of Power Mgt Timer Ctrl Reg Blk */ - uint32_t gpe0_blk; /* Port addr of General Purpose acpi_event 0 Reg Blk */ - uint32_t gpe1_blk; /* Port addr of General Purpose acpi_event 1 Reg Blk */ - uint8_t pm1_evt_len; /* Byte length of ports at pm1_x_evt_blk */ - uint8_t pm1_cnt_len; /* Byte length of ports at pm1_x_cnt_blk */ - uint8_t pm2_cnt_len; /* Byte Length of ports at pm2_cnt_blk */ - uint8_t pm_tmr_len; /* Byte Length of ports at pm_tm_blk */ - uint8_t gpe0_blk_len; /* Byte Length of ports at gpe0_blk */ - uint8_t gpe1_blk_len; /* Byte Length of ports at gpe1_blk */ - uint8_t gpe1_base; /* Offset in gpe model where gpe1 events start */ - uint8_t reserved3; /* Reserved */ - uint16_t plvl2_lat; /* Worst case HW latency to enter/exit C2 state */ - uint16_t plvl3_lat; /* Worst case HW latency to enter/exit C3 state */ - uint16_t flush_size; /* Size of area read to flush caches */ - uint16_t flush_stride; /* Stride used in flushing caches */ - uint8_t duty_offset; /* Bit location of duty cycle field in p_cnt reg */ - uint8_t duty_width; /* Bit width of duty cycle field in p_cnt reg */ - uint8_t day_alrm; /* Index to day-of-month alarm in RTC CMOS RAM */ - uint8_t mon_alrm; /* Index to month-of-year alarm in RTC CMOS RAM */ - uint8_t century; /* Index to century in RTC CMOS RAM */ - uint8_t reserved4; /* Reserved */ - uint8_t reserved4a; /* Reserved */ - uint8_t reserved4b; /* Reserved */ -#if 0 - uint32_t wb_invd : 1; /* The wbinvd instruction works properly */ - uint32_t wb_invd_flush : 1; /* The wbinvd flushes but does not invalidate */ - uint32_t proc_c1 : 1; /* All processors support C1 state */ - uint32_t plvl2_up : 1; /* C2 state works on MP system */ - uint32_t pwr_button : 1; /* Power button is handled as a generic feature */ - uint32_t sleep_button : 1; /* Sleep button is handled as a generic feature, or not present */ - uint32_t fixed_rTC : 1; /* RTC wakeup stat not in fixed register space */ - uint32_t rtcs4 : 1; /* RTC wakeup stat not possible from S4 */ - uint32_t tmr_val_ext : 1; /* The tmr_val width is 32 bits (0 = 24 bits) */ - uint32_t reserved5 : 23; /* Reserved - must be zero */ -#else - uint32_t flags; -#endif -}; + PIIX4PMState *s = opaque; + int ret; -/* - * MADT values and structures - */ + if (version_id > 1) + return -EINVAL; -/* Values for MADT PCATCompat */ + ret = pci_device_load(&s->dev, f); + if (ret < 0) + return ret; -#define DUAL_PIC 0 -#define MULTIPLE_APIC 1 + qemu_get_be16s(f, &s->pmsts); + qemu_get_be16s(f, &s->pmen); + qemu_get_be16s(f, &s->pmcntrl); + qemu_get_8s(f, &s->apmc); + qemu_get_8s(f, &s->apms); + qemu_get_timer(f, s->tmr_timer); + qemu_get_be64s(f, &s->tmr_overflow_time); + pm_io_space_update(s); -/* Master MADT */ + return 0; +} -struct multiple_apic_table +i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base) { - ACPI_TABLE_HEADER_DEF /* ACPI common table header */ - uint32_t local_apic_address; /* Physical address of local APIC */ -#if 0 - uint32_t PCATcompat : 1; /* A one indicates system also has dual 8259s */ - uint32_t reserved1 : 31; -#else - uint32_t flags; -#endif -}; - - -/* Values for Type in APIC_HEADER_DEF */ - -#define APIC_PROCESSOR 0 -#define APIC_IO 1 -#define APIC_XRUPT_OVERRIDE 2 -#define APIC_NMI 3 -#define APIC_LOCAL_NMI 4 -#define APIC_ADDRESS_OVERRIDE 5 -#define APIC_IO_SAPIC 6 -#define APIC_LOCAL_SAPIC 7 -#define APIC_XRUPT_SOURCE 8 -#define APIC_RESERVED 9 /* 9 and greater are reserved */ + PIIX4PMState *s; + uint8_t *pci_conf; -/* - * MADT sub-structures (Follow MULTIPLE_APIC_DESCRIPTION_TABLE) - */ -#define APIC_HEADER_DEF /* Common APIC sub-structure header */\ - uint8_t type; \ - uint8_t length; + s = (PIIX4PMState *)pci_register_device(bus, + "PM", sizeof(PIIX4PMState), + devfn, NULL, pm_write_config); + pci_conf = s->dev.config; + pci_conf[0x00] = 0x86; + pci_conf[0x01] = 0x80; + pci_conf[0x02] = 0x13; + pci_conf[0x03] = 0x71; + pci_conf[0x06] = 0x80; + pci_conf[0x07] = 0x02; + pci_conf[0x08] = 0x00; // revision number + pci_conf[0x09] = 0x00; + pci_conf[0x0a] = 0x80; // other bridge device + pci_conf[0x0b] = 0x06; // bridge device + pci_conf[0x0e] = 0x00; // header_type + pci_conf[0x3d] = 0x01; // interrupt pin 1 -/* Sub-structures for MADT */ + pci_conf[0x40] = 0x01; /* PM io base read only bit */ -struct madt_processor_apic -{ - APIC_HEADER_DEF - uint8_t processor_id; /* ACPI processor id */ - uint8_t local_apic_id; /* Processor's local APIC id */ -#if 0 - uint32_t processor_enabled: 1; /* Processor is usable if set */ - uint32_t reserved2 : 31; /* Reserved, must be zero */ -#else - uint32_t flags; -#endif -}; + register_ioport_write(0xb2, 2, 1, pm_smi_writeb, s); + register_ioport_read(0xb2, 2, 1, pm_smi_readb, s); -struct madt_io_apic -{ - APIC_HEADER_DEF - uint8_t io_apic_id; /* I/O APIC ID */ - uint8_t reserved; /* Reserved - must be zero */ - uint32_t address; /* APIC physical address */ - uint32_t interrupt; /* Global system interrupt where INTI - * lines start */ -}; + register_ioport_write(ACPI_DBG_IO_ADDR, 4, 4, acpi_dbg_writel, s); -#include "acpi-dsdt.hex" + /* XXX: which specification is used ? The i82731AB has different + mappings */ + pci_conf[0x5f] = (parallel_hds[0] != NULL ? 0x80 : 0) | 0x10; + pci_conf[0x63] = 0x60; + pci_conf[0x67] = (serial_hds[0] != NULL ? 0x08 : 0) | + (serial_hds[1] != NULL ? 0x90 : 0); -static int acpi_checksum(const uint8_t *data, int len) -{ - int sum, i; - sum = 0; - for(i = 0; i < len; i++) - sum += data[i]; - return (-sum) & 0xff; -} + pci_conf[0x90] = smb_io_base | 1; + pci_conf[0x91] = smb_io_base >> 8; + pci_conf[0xd2] = 0x09; + register_ioport_write(smb_io_base, 64, 1, smb_ioport_writeb, s); + register_ioport_read(smb_io_base, 64, 1, smb_ioport_readb, s); -static void acpi_build_table_header(struct acpi_table_header *h, - char *sig, int len) -{ - memcpy(h->signature, sig, 4); - h->length = cpu_to_le32(len); - h->revision = 0; - memcpy(h->oem_id, "QEMU ", 6); - memcpy(h->oem_table_id, "QEMU", 4); - memcpy(h->oem_table_id + 4, sig, 4); - h->oem_revision = cpu_to_le32(1); - memcpy(h->asl_compiler_id, "QEMU", 4); - h->asl_compiler_revision = cpu_to_le32(1); - h->checksum = acpi_checksum((void *)h, len); -} + s->tmr_timer = qemu_new_timer(vm_clock, pm_tmr_timer, s); -#define ACPI_TABLES_BASE 0x000e8000 + register_savevm("piix4_pm", 0, 1, pm_save, pm_load, s); -/* base_addr must be a multiple of 4KB */ -void acpi_bios_init(void) -{ - struct rsdp_descriptor *rsdp; - struct rsdt_descriptor_rev1 *rsdt; - struct fadt_descriptor_rev1 *fadt; - struct facs_descriptor_rev1 *facs; - struct multiple_apic_table *madt; - uint8_t *dsdt; - uint32_t base_addr, rsdt_addr, fadt_addr, addr, facs_addr, dsdt_addr; - uint32_t pm_io_base, acpi_tables_size, madt_addr, madt_size; - int i; - - /* compute PCI I/O addresses */ - pm_io_base = (piix4_pm_state->dev.config[0x40] | - (piix4_pm_state->dev.config[0x41] << 8)) & ~0x3f; - - base_addr = ACPI_TABLES_BASE; - - /* reserve memory space for tables */ - addr = base_addr; - rsdp = (void *)(phys_ram_base + addr); - addr += sizeof(*rsdp); - - rsdt_addr = addr; - rsdt = (void *)(phys_ram_base + addr); - addr += sizeof(*rsdt); - - fadt_addr = addr; - fadt = (void *)(phys_ram_base + addr); - addr += sizeof(*fadt); - - /* XXX: FACS should be in RAM */ - addr = (addr + 63) & ~63; /* 64 byte alignment for FACS */ - facs_addr = addr; - facs = (void *)(phys_ram_base + addr); - addr += sizeof(*facs); - - dsdt_addr = addr; - dsdt = (void *)(phys_ram_base + addr); - addr += sizeof(AmlCode); - - addr = (addr + 7) & ~7; - madt_addr = addr; - madt_size = sizeof(*madt) + - sizeof(struct madt_processor_apic) * smp_cpus + - sizeof(struct madt_io_apic); - madt = (void *)(phys_ram_base + addr); - addr += madt_size; - - acpi_tables_size = addr - base_addr; - - cpu_register_physical_memory(base_addr, acpi_tables_size, - base_addr | IO_MEM_ROM); - - /* RSDP */ - memset(rsdp, 0, sizeof(*rsdp)); - memcpy(rsdp->signature, "RSD PTR ", 8); - memcpy(rsdp->oem_id, "QEMU ", 6); - rsdp->rsdt_physical_address = cpu_to_le32(rsdt_addr); - rsdp->checksum = acpi_checksum((void *)rsdp, 20); - - /* RSDT */ - rsdt->table_offset_entry[0] = cpu_to_le32(fadt_addr); - rsdt->table_offset_entry[1] = cpu_to_le32(madt_addr); - acpi_build_table_header((struct acpi_table_header *)rsdt, - "RSDT", sizeof(*rsdt)); - - /* FADT */ - memset(fadt, 0, sizeof(*fadt)); - fadt->firmware_ctrl = cpu_to_le32(facs_addr); - fadt->dsdt = cpu_to_le32(dsdt_addr); - fadt->model = 1; - fadt->reserved1 = 0; - fadt->sci_int = cpu_to_le16(piix4_pm_state->dev.config[0x3c]); - fadt->smi_cmd = cpu_to_le32(SMI_CMD_IO_ADDR); - fadt->acpi_enable = 0xf1; - fadt->acpi_disable = 0xf0; - fadt->pm1a_evt_blk = cpu_to_le32(pm_io_base); - fadt->pm1a_cnt_blk = cpu_to_le32(pm_io_base + 0x04); - fadt->pm_tmr_blk = cpu_to_le32(pm_io_base + 0x08); - fadt->pm1_evt_len = 4; - fadt->pm1_cnt_len = 2; - fadt->pm_tmr_len = 4; - fadt->plvl2_lat = cpu_to_le16(50); - fadt->plvl3_lat = cpu_to_le16(50); - fadt->plvl3_lat = cpu_to_le16(50); - /* WBINVD + PROC_C1 + PWR_BUTTON + SLP_BUTTON + FIX_RTC */ - fadt->flags = cpu_to_le32((1 << 0) | (1 << 2) | (1 << 4) | (1 << 5) | (1 << 6)); - acpi_build_table_header((struct acpi_table_header *)fadt, "FACP", - sizeof(*fadt)); - - /* FACS */ - memset(facs, 0, sizeof(*facs)); - memcpy(facs->signature, "FACS", 4); - facs->length = cpu_to_le32(sizeof(*facs)); - - /* DSDT */ - memcpy(dsdt, AmlCode, sizeof(AmlCode)); - - /* MADT */ - { - struct madt_processor_apic *apic; - struct madt_io_apic *io_apic; - - memset(madt, 0, madt_size); - madt->local_apic_address = cpu_to_le32(0xfee00000); - madt->flags = cpu_to_le32(1); - apic = (void *)(madt + 1); - for(i=0;itype = APIC_PROCESSOR; - apic->length = sizeof(*apic); - apic->processor_id = i; - apic->local_apic_id = i; - apic->flags = cpu_to_le32(1); - apic++; - } - io_apic = (void *)apic; - io_apic->type = APIC_IO; - io_apic->length = sizeof(*io_apic); - io_apic->io_apic_id = smp_cpus; - io_apic->address = cpu_to_le32(0xfec00000); - io_apic->interrupt = cpu_to_le32(0); - - acpi_build_table_header((struct acpi_table_header *)madt, - "APIC", madt_size); - } + s->smbus = i2c_init_bus(); + return s->smbus; }