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