Home | History | Annotate | Line # | Download | only in ski
acpi_stub.c revision 1.2
      1 /*	$NetBSD: acpi_stub.c,v 1.2 2006/04/22 07:58:53 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 /* __FBSDID("$FreeBSD: src/sys/boot/ia64/libski/acpi_stub.c,v 1.3 2003/12/09 08:35:17 marcel Exp $"); */
     34 
     35 #define _KERNEL /* XXX: Fix dist/acpica/acnetbsd.h for _STANDALONE */
     36 #include <sys/types.h>
     37 #include <dist/acpica/acpi.h>
     38 #undef _KERNEL
     39 
     40 #define APIC_IO_SAPIC                   6
     41 #define APIC_LOCAL_SAPIC                7
     42 
     43 #pragma pack(1)
     44 
     45 typedef struct  /* LOCAL SAPIC */
     46 {
     47         APIC_HEADER     Header;
     48         UINT8           ProcessorId;            /* ACPI processor id */
     49         UINT8           LocalSapicId;           /* Processor local SAPIC id */
     50         UINT8           LocalSapicEid;          /* Processor local SAPIC eid */
     51         UINT8           Reserved[3];
     52         UINT32          ProcessorEnabled: 1;
     53         UINT32          FlagsReserved: 31;
     54 } LOCAL_SAPIC;
     55 
     56 typedef struct  /* IO SAPIC */
     57 {
     58         APIC_HEADER     Header;
     59         UINT8           IoSapicId;              /* I/O SAPIC ID */
     60         UINT8           Reserved;               /* reserved - must be zero */
     61         UINT32          Vector;                 /* interrupt base */
     62         UINT64          IoSapicAddress;         /* SAPIC's physical address */
     63 } IO_SAPIC;
     64 
     65 /*
     66  */
     67 
     68 struct {
     69 	MULTIPLE_APIC_TABLE	Header;
     70 	MADT_LOCAL_SAPIC	cpu0;
     71 	MADT_LOCAL_SAPIC	cpu1;
     72 	MADT_LOCAL_SAPIC	cpu2;
     73 	MADT_LOCAL_SAPIC	cpu3;
     74 	MADT_IO_SAPIC		sapic;
     75 } apic = {
     76 	/* Header. */
     77 	{
     78 		APIC_SIG,			/* Signature. */
     79 		sizeof(apic),			/* Length of table. */
     80 		0,				/* ACPI minor revision. */
     81 		0,				/* XXX checksum. */
     82 		"FBSD",				/* OEM Id. */
     83 		"SKI",				/* OEM table Id. */
     84 		0,				/* OEM revision. */
     85 		"FBSD",				/* ASL compiler Id. */
     86 		0,				/* ASL revision. */
     87 		0xfee00000,
     88 	},
     89 	/* cpu0. */
     90 	{
     91 		APIC_LOCAL_SAPIC,		/* Type. */
     92 		sizeof(apic.cpu0),		/* Length. */
     93 		0,				/* ACPI processor id */
     94 		0,				/* Processor local SAPIC id */
     95 		0,				/* Processor local SAPIC eid */
     96 		{ 0, 0, 0 },
     97 		1,				/* FL: Enabled. */
     98 	},
     99 	/* cpu1. */
    100 	{
    101 		APIC_LOCAL_SAPIC,		/* Type. */
    102 		sizeof(apic.cpu1),		/* Length. */
    103 		1,				/* ACPI processor id */
    104 		0,				/* Processor local SAPIC id */
    105 		1,				/* Processor local SAPIC eid */
    106 		{ 0, 0, 0 },
    107 		1,				/* FL: Enabled. */
    108 	},
    109 	/* cpu2. */
    110 	{
    111 		APIC_LOCAL_SAPIC,		/* Type. */
    112 		sizeof(apic.cpu2),		/* Length. */
    113 		2,				/* ACPI processor id */
    114 		1,				/* Processor local SAPIC id */
    115 		0,				/* Processor local SAPIC eid */
    116 		{ 0, 0, 0 },
    117 		0,				/* FL: Enabled. */
    118 	},
    119 	/* cpu3. */
    120 	{
    121 		APIC_LOCAL_SAPIC,		/* Type. */
    122 		sizeof(apic.cpu3),		/* Length. */
    123 		3,				/* ACPI processor id */
    124 		1,				/* Processor local SAPIC id */
    125 		1,				/* Processor local SAPIC eid */
    126 		{ 0, 0, 0 },
    127 		0,				/* FL: Enabled. */
    128 	},
    129 	/* sapic. */
    130 	{
    131 		APIC_IO_SAPIC,			/* Type. */
    132 		sizeof(apic.sapic),		/* Length. */
    133 		4,				/* IO SAPIC id. */
    134 		0,
    135 		16,				/* Interrupt base. */
    136 		0xfec00000			/* IO SAPIC address. */
    137 	}
    138 };
    139 
    140 struct {
    141 	ACPI_TABLE_HEADER	Header;
    142 	UINT64			apic_tbl;
    143 } xsdt = {
    144 	{
    145 		XSDT_SIG,		/* Signature. */
    146 		sizeof(xsdt),		/* Length of table. */
    147 		0,			/* ACPI minor revision. */
    148 		0,			/* XXX checksum. */
    149 		"FBSD",			/* OEM Id. */
    150 		"SKI",			/* OEM table Id. */
    151 		0,			/* OEM revision. */
    152 		"FBSD",			/* ASL compiler Id. */
    153 		0			/* ASL revision. */
    154 	},
    155 	0UL				/* XXX APIC table address. */
    156 };
    157 
    158 RSDP_DESCRIPTOR acpi_root = {
    159 	RSDP_SIG,
    160 	0,				/* XXX checksum. */
    161 	"FBSD",
    162 	2,				/* ACPI Rev 2.0. */
    163 	0UL,
    164 	sizeof(xsdt),			/* XSDT length. */
    165 	0UL,				/* XXX PA of XSDT. */
    166 	0,				/* XXX Extended checksum. */
    167 };
    168 
    169 static void
    170 cksum(void *addr, int sz, UINT8 *sum)
    171 {
    172 	UINT8 *p, s;
    173 
    174 	p = addr;
    175 	s = 0;
    176 	while (sz--)
    177 		s += *p++;
    178 	*sum = -s;
    179 }
    180 
    181 void
    182 acpi_stub_init(void)
    183 {
    184 	acpi_root.XsdtPhysicalAddress = (UINT64)&xsdt;
    185 	cksum(&acpi_root, 20, &acpi_root.Checksum);
    186 	cksum(&acpi_root, sizeof(acpi_root), &acpi_root.ExtendedChecksum);
    187 
    188 	xsdt.apic_tbl = (UINT32)&apic;
    189 	cksum(&xsdt, sizeof(xsdt), &xsdt.Header.Checksum);
    190 }
    191