Home | History | Annotate | Line # | Download | only in ski
acpi_stub.c revision 1.1
      1 /*	$NetBSD: acpi_stub.c,v 1.1 2006/04/07 14:21:32 cherry Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2003 Marcel Moolenaar
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  *
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 
     30 
     31 
     32 #include <sys/cdefs.h>
     33 
     34 #define _KERNEL /* XXX: Fix dist/acpica/acnetbsd.h for _STANDALONE */
     35 #include <sys/types.h>
     36 #include <dist/acpica/acpi.h>
     37 #undef _KERNEL
     38 
     39 #define APIC_IO_SAPIC                   6
     40 #define APIC_LOCAL_SAPIC                7
     41 
     42 #pragma pack(1)
     43 
     44 typedef struct  /* LOCAL SAPIC */
     45 {
     46         APIC_HEADER     Header;
     47         UINT8           ProcessorId;            /* ACPI processor id */
     48         UINT8           LocalSapicId;           /* Processor local SAPIC id */
     49         UINT8           LocalSapicEid;          /* Processor local SAPIC eid */
     50         UINT8           Reserved[3];
     51         UINT32          ProcessorEnabled: 1;
     52         UINT32          FlagsReserved: 31;
     53 } LOCAL_SAPIC;
     54 
     55 typedef struct  /* IO SAPIC */
     56 {
     57         APIC_HEADER     Header;
     58         UINT8           IoSapicId;              /* I/O SAPIC ID */
     59         UINT8           Reserved;               /* reserved - must be zero */
     60         UINT32          Vector;                 /* interrupt base */
     61         UINT64          IoSapicAddress;         /* SAPIC's physical address */
     62 } IO_SAPIC;
     63 
     64 /*
     65  */
     66 
     67 struct {
     68 	MULTIPLE_APIC_TABLE	Header;
     69 	MADT_LOCAL_SAPIC	cpu0;
     70 	MADT_LOCAL_SAPIC	cpu1;
     71 	MADT_LOCAL_SAPIC	cpu2;
     72 	MADT_LOCAL_SAPIC	cpu3;
     73 	MADT_IO_SAPIC		sapic;
     74 } apic = {
     75 	/* Header. */
     76 	{
     77 		APIC_SIG,			/* Signature. */
     78 		sizeof(apic),			/* Length of table. */
     79 		0,				/* ACPI minor revision. */
     80 		0,				/* XXX checksum. */
     81 		"FBSD",				/* OEM Id. */
     82 		"SKI",				/* OEM table Id. */
     83 		0,				/* OEM revision. */
     84 		"FBSD",				/* ASL compiler Id. */
     85 		0,				/* ASL revision. */
     86 		0xfee00000,
     87 	},
     88 	/* cpu0. */
     89 	{
     90 		APIC_LOCAL_SAPIC,		/* Type. */
     91 		sizeof(apic.cpu0),		/* Length. */
     92 		0,				/* ACPI processor id */
     93 		0,				/* Processor local SAPIC id */
     94 		0,				/* Processor local SAPIC eid */
     95 		{ 0, 0, 0 },
     96 		1,				/* FL: Enabled. */
     97 	},
     98 	/* cpu1. */
     99 	{
    100 		APIC_LOCAL_SAPIC,		/* Type. */
    101 		sizeof(apic.cpu1),		/* Length. */
    102 		1,				/* ACPI processor id */
    103 		0,				/* Processor local SAPIC id */
    104 		1,				/* Processor local SAPIC eid */
    105 		{ 0, 0, 0 },
    106 		1,				/* FL: Enabled. */
    107 	},
    108 	/* cpu2. */
    109 	{
    110 		APIC_LOCAL_SAPIC,		/* Type. */
    111 		sizeof(apic.cpu2),		/* Length. */
    112 		2,				/* ACPI processor id */
    113 		1,				/* Processor local SAPIC id */
    114 		0,				/* Processor local SAPIC eid */
    115 		{ 0, 0, 0 },
    116 		0,				/* FL: Enabled. */
    117 	},
    118 	/* cpu3. */
    119 	{
    120 		APIC_LOCAL_SAPIC,		/* Type. */
    121 		sizeof(apic.cpu3),		/* Length. */
    122 		3,				/* ACPI processor id */
    123 		1,				/* Processor local SAPIC id */
    124 		1,				/* Processor local SAPIC eid */
    125 		{ 0, 0, 0 },
    126 		0,				/* FL: Enabled. */
    127 	},
    128 	/* sapic. */
    129 	{
    130 		APIC_IO_SAPIC,			/* Type. */
    131 		sizeof(apic.sapic),		/* Length. */
    132 		4,				/* IO SAPIC id. */
    133 		0,
    134 		16,				/* Interrupt base. */
    135 		0xfec00000			/* IO SAPIC address. */
    136 	}
    137 };
    138 
    139 struct {
    140 	ACPI_TABLE_HEADER	Header;
    141 	UINT64			apic_tbl;
    142 } xsdt = {
    143 	{
    144 		XSDT_SIG,		/* Signature. */
    145 		sizeof(xsdt),		/* Length of table. */
    146 		0,			/* ACPI minor revision. */
    147 		0,			/* XXX checksum. */
    148 		"FBSD",			/* OEM Id. */
    149 		"SKI",			/* OEM table Id. */
    150 		0,			/* OEM revision. */
    151 		"FBSD",			/* ASL compiler Id. */
    152 		0			/* ASL revision. */
    153 	},
    154 	0UL				/* XXX APIC table address. */
    155 };
    156 
    157 RSDP_DESCRIPTOR acpi_root = {
    158 	RSDP_SIG,
    159 	0,				/* XXX checksum. */
    160 	"FBSD",
    161 	2,				/* ACPI Rev 2.0. */
    162 	0UL,
    163 	sizeof(xsdt),			/* XSDT length. */
    164 	0UL,				/* XXX PA of XSDT. */
    165 	0,				/* XXX Extended checksum. */
    166 };
    167 
    168 static void
    169 cksum(void *addr, int sz, UINT8 *sum)
    170 {
    171 	UINT8 *p, s;
    172 
    173 	p = addr;
    174 	s = 0;
    175 	while (sz--)
    176 		s += *p++;
    177 	*sum = -s;
    178 }
    179 
    180 void
    181 acpi_stub_init(void)
    182 {
    183 	acpi_root.XsdtPhysicalAddress = (UINT64)&xsdt;
    184 	cksum(&acpi_root, 20, &acpi_root.Checksum);
    185 	cksum(&acpi_root, sizeof(acpi_root), &acpi_root.ExtendedChecksum);
    186 
    187 	xsdt.apic_tbl = (UINT32)&apic;
    188 	cksum(&xsdt, sizeof(xsdt), &xsdt.Header.Checksum);
    189 }
    190