1139738Simp/*- 2110211Smarcel * Copyright (c) 2003 Marcel Moolenaar 3110211Smarcel * All rights reserved. 4110211Smarcel * 5110211Smarcel * Redistribution and use in source and binary forms, with or without 6110211Smarcel * modification, are permitted provided that the following conditions 7110211Smarcel * are met: 8110211Smarcel * 9110211Smarcel * 1. Redistributions of source code must retain the above copyright 10110211Smarcel * notice, this list of conditions and the following disclaimer. 11110211Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12110211Smarcel * notice, this list of conditions and the following disclaimer in the 13110211Smarcel * documentation and/or other materials provided with the distribution. 14110211Smarcel * 15110211Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16110211Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17110211Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18110211Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19110211Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20110211Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21110211Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22110211Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23110211Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24110211Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25110211Smarcel */ 26110211Smarcel 27119880Sobrien#include <sys/cdefs.h> 28119880Sobrien__FBSDID("$FreeBSD$"); 29119880Sobrien 30193530Sjkim#include <contrib/dev/acpica/include/acpi.h> 31110211Smarcel 32110211Smarcel#define APIC_IO_SAPIC 6 33110211Smarcel#define APIC_LOCAL_SAPIC 7 34110211Smarcel 35110211Smarcel#pragma pack(1) 36110211Smarcel 37110211Smarceltypedef struct /* LOCAL SAPIC */ 38110211Smarcel{ 39167814Sjkim ACPI_SUBTABLE_HEADER Header; 40167814Sjkim UINT8 ProcessorId; /* ACPI processor id */ 41167814Sjkim UINT8 LocalSapicId; /* Processor local SAPIC id */ 42167814Sjkim UINT8 LocalSapicEid; /* Processor local SAPIC eid */ 43167814Sjkim UINT8 Reserved[3]; 44167814Sjkim UINT32 ProcessorEnabled: 1; 45167814Sjkim UINT32 FlagsReserved: 31; 46110211Smarcel} LOCAL_SAPIC; 47110211Smarcel 48110211Smarceltypedef struct /* IO SAPIC */ 49110211Smarcel{ 50167814Sjkim ACPI_SUBTABLE_HEADER Header; 51167814Sjkim UINT8 IoSapicId; /* I/O SAPIC ID */ 52167814Sjkim UINT8 Reserved; /* reserved - must be zero */ 53167814Sjkim UINT32 Vector; /* interrupt base */ 54167814Sjkim UINT64 IoSapicAddress; /* SAPIC's physical address */ 55110211Smarcel} IO_SAPIC; 56110211Smarcel 57110211Smarcel/* 58110211Smarcel */ 59110211Smarcel 60110211Smarcelstruct { 61167814Sjkim ACPI_TABLE_MADT MADT; 62167814Sjkim ACPI_MADT_LOCAL_SAPIC cpu0; 63167814Sjkim ACPI_MADT_LOCAL_SAPIC cpu1; 64167814Sjkim ACPI_MADT_LOCAL_SAPIC cpu2; 65167814Sjkim ACPI_MADT_LOCAL_SAPIC cpu3; 66167814Sjkim ACPI_MADT_IO_SAPIC sapic; 67110211Smarcel} apic = { 68110211Smarcel /* Header. */ 69110211Smarcel { 70167814Sjkim ACPI_SIG_MADT, /* Signature. */ 71123343Smarcel sizeof(apic), /* Length of table. */ 72123343Smarcel 0, /* ACPI minor revision. */ 73163927Smarcel 0, /* Checksum. */ 74123343Smarcel "FBSD", /* OEM Id. */ 75123343Smarcel "SKI", /* OEM table Id. */ 76123343Smarcel 0, /* OEM revision. */ 77123343Smarcel "FBSD", /* ASL compiler Id. */ 78123343Smarcel 0, /* ASL revision. */ 79110211Smarcel 0xfee00000, 80110211Smarcel }, 81110211Smarcel /* cpu0. */ 82110211Smarcel { 83123343Smarcel APIC_LOCAL_SAPIC, /* Type. */ 84123343Smarcel sizeof(apic.cpu0), /* Length. */ 85110211Smarcel 0, /* ACPI processor id */ 86110211Smarcel 0, /* Processor local SAPIC id */ 87110211Smarcel 0, /* Processor local SAPIC eid */ 88110211Smarcel { 0, 0, 0 }, 89110211Smarcel 1, /* FL: Enabled. */ 90110211Smarcel }, 91110211Smarcel /* cpu1. */ 92110211Smarcel { 93123343Smarcel APIC_LOCAL_SAPIC, /* Type. */ 94123343Smarcel sizeof(apic.cpu1), /* Length. */ 95110211Smarcel 1, /* ACPI processor id */ 96110211Smarcel 0, /* Processor local SAPIC id */ 97110211Smarcel 1, /* Processor local SAPIC eid */ 98110211Smarcel { 0, 0, 0 }, 99110211Smarcel 1, /* FL: Enabled. */ 100110211Smarcel }, 101110211Smarcel /* cpu2. */ 102110211Smarcel { 103123343Smarcel APIC_LOCAL_SAPIC, /* Type. */ 104123343Smarcel sizeof(apic.cpu2), /* Length. */ 105110211Smarcel 2, /* ACPI processor id */ 106110211Smarcel 1, /* Processor local SAPIC id */ 107110211Smarcel 0, /* Processor local SAPIC eid */ 108110211Smarcel { 0, 0, 0 }, 109110211Smarcel 0, /* FL: Enabled. */ 110110211Smarcel }, 111110211Smarcel /* cpu3. */ 112110211Smarcel { 113123343Smarcel APIC_LOCAL_SAPIC, /* Type. */ 114123343Smarcel sizeof(apic.cpu3), /* Length. */ 115110211Smarcel 3, /* ACPI processor id */ 116110211Smarcel 1, /* Processor local SAPIC id */ 117110211Smarcel 1, /* Processor local SAPIC eid */ 118110211Smarcel { 0, 0, 0 }, 119110211Smarcel 0, /* FL: Enabled. */ 120110211Smarcel }, 121110211Smarcel /* sapic. */ 122110211Smarcel { 123123343Smarcel APIC_IO_SAPIC, /* Type. */ 124123343Smarcel sizeof(apic.sapic), /* Length. */ 125110211Smarcel 4, /* IO SAPIC id. */ 126110211Smarcel 0, 127110211Smarcel 16, /* Interrupt base. */ 128110211Smarcel 0xfec00000 /* IO SAPIC address. */ 129110211Smarcel } 130110211Smarcel}; 131110211Smarcel 132110211Smarcelstruct { 133110211Smarcel ACPI_TABLE_HEADER Header; 134110211Smarcel UINT64 apic_tbl; 135110211Smarcel} xsdt = { 136110211Smarcel { 137167814Sjkim ACPI_SIG_XSDT, /* Signature. */ 138110211Smarcel sizeof(xsdt), /* Length of table. */ 139110211Smarcel 0, /* ACPI minor revision. */ 140110211Smarcel 0, /* XXX checksum. */ 141110211Smarcel "FBSD", /* OEM Id. */ 142110211Smarcel "SKI", /* OEM table Id. */ 143110211Smarcel 0, /* OEM revision. */ 144110211Smarcel "FBSD", /* ASL compiler Id. */ 145110211Smarcel 0 /* ASL revision. */ 146110211Smarcel }, 147135700Smarcel 0UL /* XXX APIC table address. */ 148110211Smarcel}; 149110211Smarcel 150167814SjkimACPI_TABLE_RSDP acpi_root = { 151167814Sjkim ACPI_SIG_RSDP, 152110211Smarcel 0, /* XXX checksum. */ 153110211Smarcel "FBSD", 154110211Smarcel 2, /* ACPI Rev 2.0. */ 155135700Smarcel 0UL, 156110211Smarcel sizeof(xsdt), /* XSDT length. */ 157135700Smarcel 0UL, /* XXX PA of XSDT. */ 158110211Smarcel 0, /* XXX Extended checksum. */ 159110211Smarcel}; 160110211Smarcel 161110211Smarcelstatic void 162110211Smarcelcksum(void *addr, int sz, UINT8 *sum) 163110211Smarcel{ 164110211Smarcel UINT8 *p, s; 165110211Smarcel 166110211Smarcel p = addr; 167110211Smarcel s = 0; 168110211Smarcel while (sz--) 169110211Smarcel s += *p++; 170110211Smarcel *sum = -s; 171110211Smarcel} 172110211Smarcel 173110211Smarcelvoid 174110211Smarcelacpi_stub_init(void) 175110211Smarcel{ 176110211Smarcel acpi_root.XsdtPhysicalAddress = (UINT64)&xsdt; 177110211Smarcel cksum(&acpi_root, 20, &acpi_root.Checksum); 178110211Smarcel cksum(&acpi_root, sizeof(acpi_root), &acpi_root.ExtendedChecksum); 179110211Smarcel 180167814Sjkim cksum(&apic, sizeof(apic), &apic.MADT.Header.Checksum); 181110211Smarcel xsdt.apic_tbl = (UINT32)&apic; 182110211Smarcel cksum(&xsdt, sizeof(xsdt), &xsdt.Header.Checksum); 183110211Smarcel} 184