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