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