138061Smsmith/*- 238061Smsmith * Copyright (c) 2003 Marcel Moolenaar 338061Smsmith * All rights reserved. 438061Smsmith * 538061Smsmith * Redistribution and use in source and binary forms, with or without 638061Smsmith * modification, are permitted provided that the following conditions 738061Smsmith * are met: 838061Smsmith * 938061Smsmith * 1. Redistributions of source code must retain the above copyright 1038061Smsmith * notice, this list of conditions and the following disclaimer. 1138061Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1238061Smsmith * notice, this list of conditions and the following disclaimer in the 1338061Smsmith * documentation and/or other materials provided with the distribution. 1438061Smsmith * 1538061Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1638061Smsmith * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1738061Smsmith * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1838061Smsmith * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1938061Smsmith * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2038061Smsmith * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2138061Smsmith * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2238061Smsmith * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2338061Smsmith * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2438061Smsmith * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2538061Smsmith */ 2650477Speter 2738061Smsmith#include <sys/cdefs.h> 2838061Smsmith__FBSDID("$FreeBSD$"); 2938061Smsmith 3038061Smsmith#include <contrib/dev/acpica/include/acpi.h> 3138061Smsmith 3238061Smsmith#define APIC_IO_SAPIC 6 3338061Smsmith#define APIC_LOCAL_SAPIC 7 3438061Smsmith 3538061Smsmith#pragma pack(1) 3638061Smsmith 3742475Snsouchtypedef struct /* LOCAL SAPIC */ 3838061Smsmith{ 3938061Smsmith ACPI_SUBTABLE_HEADER Header; 4038061Smsmith UINT8 ProcessorId; /* ACPI processor id */ 4138061Smsmith UINT8 LocalSapicId; /* Processor local SAPIC id */ 4238061Smsmith UINT8 LocalSapicEid; /* Processor local SAPIC eid */ 4338061Smsmith UINT8 Reserved[3]; 4438061Smsmith UINT32 ProcessorEnabled: 1; 4538061Smsmith UINT32 FlagsReserved: 31; 4638061Smsmith} LOCAL_SAPIC; 4738061Smsmith 4838061Smsmithtypedef struct /* IO SAPIC */ 4938061Smsmith{ 5038061Smsmith ACPI_SUBTABLE_HEADER Header; 5138061Smsmith UINT8 IoSapicId; /* I/O SAPIC ID */ 5238061Smsmith UINT8 Reserved; /* reserved - must be zero */ 5338061Smsmith UINT32 Vector; /* interrupt base */ 5438061Smsmith UINT64 IoSapicAddress; /* SAPIC's physical address */ 5538061Smsmith} IO_SAPIC; 5638061Smsmith 5738061Smsmith/* 5838061Smsmith */ 5938061Smsmith 6038061Smsmithstruct { 6138061Smsmith ACPI_TABLE_MADT MADT; 6238061Smsmith ACPI_MADT_LOCAL_SAPIC cpu0; 6338061Smsmith ACPI_MADT_LOCAL_SAPIC cpu1; 6438061Smsmith ACPI_MADT_LOCAL_SAPIC cpu2; 6538061Smsmith ACPI_MADT_LOCAL_SAPIC cpu3; 6638061Smsmith ACPI_MADT_IO_SAPIC sapic; 6738061Smsmith} apic = { 6838061Smsmith /* Header. */ 6938061Smsmith { 7038061Smsmith ACPI_SIG_MADT, /* Signature. */ 7138061Smsmith sizeof(apic), /* Length of table. */ 7238061Smsmith 0, /* ACPI minor revision. */ 7338061Smsmith 0, /* Checksum. */ 7438061Smsmith "FBSD", /* OEM Id. */ 7538061Smsmith "SKI", /* OEM table Id. */ 7639134Snsouch 0, /* OEM revision. */ 7739134Snsouch "FBSD", /* ASL compiler Id. */ 7838061Smsmith 0, /* ASL revision. */ 7938061Smsmith 0xfee00000, 8038061Smsmith }, 8138061Smsmith /* cpu0. */ 8238061Smsmith { 8338061Smsmith APIC_LOCAL_SAPIC, /* Type. */ 8438061Smsmith sizeof(apic.cpu0), /* Length. */ 8538061Smsmith 0, /* ACPI processor id */ 8638061Smsmith 0, /* Processor local SAPIC id */ 8738061Smsmith 0, /* Processor local SAPIC eid */ 8838061Smsmith { 0, 0, 0 }, 8938061Smsmith 1, /* FL: Enabled. */ 9038061Smsmith }, 9139134Snsouch /* cpu1. */ 9239134Snsouch { 9338061Smsmith APIC_LOCAL_SAPIC, /* Type. */ 9439134Snsouch sizeof(apic.cpu1), /* Length. */ 9539134Snsouch 1, /* ACPI processor id */ 9639134Snsouch 0, /* Processor local SAPIC id */ 9738061Smsmith 1, /* Processor local SAPIC eid */ 9838061Smsmith { 0, 0, 0 }, 9938061Smsmith 1, /* FL: Enabled. */ 10038061Smsmith }, 10143433Snsouch /* cpu2. */ 10243433Snsouch { 10338061Smsmith APIC_LOCAL_SAPIC, /* Type. */ 10438061Smsmith sizeof(apic.cpu2), /* Length. */ 10538061Smsmith 2, /* ACPI processor id */ 10638061Smsmith 1, /* Processor local SAPIC id */ 10738061Smsmith 0, /* Processor local SAPIC eid */ 10838061Smsmith { 0, 0, 0 }, 109106696Salfred 0, /* FL: Enabled. */ 110106696Salfred }, 111106696Salfred /* cpu3. */ 11238061Smsmith { 113106696Salfred APIC_LOCAL_SAPIC, /* Type. */ 11438061Smsmith sizeof(apic.cpu3), /* Length. */ 11538061Smsmith 3, /* ACPI processor id */ 116106696Salfred 1, /* Processor local SAPIC id */ 11738061Smsmith 1, /* Processor local SAPIC eid */ 11838061Smsmith { 0, 0, 0 }, 119106696Salfred 0, /* FL: Enabled. */ 120106696Salfred }, 12138061Smsmith /* sapic. */ 12238061Smsmith { 123106696Salfred APIC_IO_SAPIC, /* Type. */ 12438061Smsmith sizeof(apic.sapic), /* Length. */ 12538061Smsmith 4, /* IO SAPIC id. */ 12638061Smsmith 0, 12738061Smsmith 16, /* Interrupt base. */ 12838061Smsmith 0xfec00000 /* IO SAPIC address. */ 129106696Salfred } 130106696Salfred}; 131106696Salfred 132106696Salfredstruct { 13339134Snsouch ACPI_TABLE_HEADER Header; 134106696Salfred UINT64 apic_tbl; 13538061Smsmith} xsdt = { 13638061Smsmith { 13738061Smsmith ACPI_SIG_XSDT, /* Signature. */ 138106696Salfred sizeof(xsdt), /* Length of table. */ 139106696Salfred 0, /* ACPI minor revision. */ 14038061Smsmith 0, /* XXX checksum. */ 14138061Smsmith "FBSD", /* OEM Id. */ 14238061Smsmith "SKI", /* OEM table Id. */ 14338061Smsmith 0, /* OEM revision. */ 144106696Salfred "FBSD", /* ASL compiler Id. */ 145106696Salfred 0 /* ASL revision. */ 14638061Smsmith }, 14738061Smsmith 0UL /* XXX APIC table address. */ 148106696Salfred}; 14938061Smsmith 15039134SnsouchACPI_TABLE_RSDP acpi_root = { 151106696Salfred ACPI_SIG_RSDP, 15239134Snsouch 0, /* XXX checksum. */ 15338061Smsmith "FBSD", 154106696Salfred 2, /* ACPI Rev 2.0. */ 155106696Salfred 0UL, 15638061Smsmith sizeof(xsdt), /* XSDT length. */ 15738061Smsmith 0UL, /* XXX PA of XSDT. */ 15838061Smsmith 0, /* XXX Extended checksum. */ 15938061Smsmith}; 16038061Smsmith 16155939Snsouchstatic void 16238061Smsmithcksum(void *addr, int sz, UINT8 *sum) 16355939Snsouch{ 16438061Smsmith UINT8 *p, s; 16538061Smsmith 16655939Snsouch p = addr; 16755939Snsouch s = 0; 16838061Smsmith while (sz--) 16938061Smsmith s += *p++; 17038061Smsmith *sum = -s; 17138061Smsmith} 17238061Smsmith 17338061Smsmithvoid 17438061Smsmithacpi_stub_init(void) 17538061Smsmith{ 17638061Smsmith acpi_root.XsdtPhysicalAddress = (UINT64)&xsdt; 17738061Smsmith cksum(&acpi_root, 20, &acpi_root.Checksum); 17838061Smsmith cksum(&acpi_root, sizeof(acpi_root), &acpi_root.ExtendedChecksum); 17955939Snsouch 18055939Snsouch cksum(&apic, sizeof(apic), &apic.MADT.Header.Checksum); 18138061Smsmith xsdt.apic_tbl = (UINT32)&apic; 18238061Smsmith cksum(&xsdt, sizeof(xsdt), &xsdt.Header.Checksum); 18338061Smsmith} 18438061Smsmith