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