Home | History | Annotate | Line # | Download | only in ski
acpi_stub.c revision 1.6
      1 /*	$NetBSD: acpi_stub.c,v 1.6 2009/11/11 05:19:34 kiyohara 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 #include <sys/types.h>
     36 #include <sys/lock.h>
     37 #include <dev/acpi/acpica.h>
     38 
     39 #define APIC_IO_SAPIC                   6
     40 #define APIC_LOCAL_SAPIC                7
     41 
     42 #pragma pack(1) /* XXX: Standardify me */
     43 
     44 typedef struct  /* LOCAL SAPIC */
     45 {
     46         ACPI_SUBTABLE_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         ACPI_SUBTABLE_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 	ACPI_TABLE_MADT		Header;
     69 	ACPI_MADT_LOCAL_SAPIC	cpu0;
     70 	ACPI_MADT_LOCAL_SAPIC	cpu1;
     71 	ACPI_MADT_LOCAL_SAPIC	cpu2;
     72 	ACPI_MADT_LOCAL_SAPIC	cpu3;
     73 	ACPI_MADT_IO_SAPIC	sapic;
     74 } apic = {
     75 	/* Header. */
     76 	{
     77 		ACPI_SIG_MADT,			/* 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 		ACPI_SIG_XSDT,		/* 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 ACPI_TABLE_RSDP acpi_root = {
    158 	ACPI_SIG_RSDP,
    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 #pragma pack() /* Reset Packing */
    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