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