hammer - Add memory use limit option for dedup runs
[dragonfly.git] / sys / boot / ia64 / libski / acpi_stub.c
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  * $FreeBSD: src/sys/boot/ia64/libski/acpi_stub.c,v 1.2 2003/09/08 09:11:32 obrien Exp $
27  * $DragonFly: src/sys/boot/ia64/libski/acpi_stub.c,v 1.2 2007/01/19 07:23:42 dillon Exp $
28  */
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
37 typedef 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
48 typedef 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
60 struct {
61         APIC_TABLE              Header;
62         LOCAL_SAPIC             cpu0;
63         LOCAL_SAPIC             cpu1;
64         LOCAL_SAPIC             cpu2;
65         LOCAL_SAPIC             cpu3;
66         IO_SAPIC                sapic;
67 } apic = {
68         /* Header. */
69         {
70                 {
71                         APIC_SIG,               /* Signature. */
72                         sizeof(apic),           /* Length of table. */
73                         0,                      /* ACPI minor revision. */
74                         0,                      /* XXX checksum. */
75                         "FBSD",                 /* OEM Id. */
76                         "SKI",                  /* OEM table Id. */
77                         0,                      /* OEM revision. */
78                         "FBSD",                 /* ASL compiler Id. */
79                         0                       /* ASL revision. */
80                 },
81                 0xfee00000,
82         },
83         /* cpu0. */
84         {
85                 {
86                         APIC_LOCAL_SAPIC,       /* Type. */
87                         sizeof(apic.cpu0)       /* Length. */
88                 },
89                 0,                              /* ACPI processor id */
90                 0,                              /* Processor local SAPIC id */
91                 0,                              /* Processor local SAPIC eid */
92                 { 0, 0, 0 },
93                 1,                              /* FL: Enabled. */
94         },
95         /* cpu1. */
96         {
97                 {
98                         APIC_LOCAL_SAPIC,       /* Type. */
99                         sizeof(apic.cpu1)       /* Length. */
100                 },
101                 1,                              /* ACPI processor id */
102                 0,                              /* Processor local SAPIC id */
103                 1,                              /* Processor local SAPIC eid */
104                 { 0, 0, 0 },
105                 1,                              /* FL: Enabled. */
106         },
107         /* cpu2. */
108         {
109                 {
110                         APIC_LOCAL_SAPIC,       /* Type. */
111                         sizeof(apic.cpu2)       /* Length. */
112                 },
113                 2,                              /* ACPI processor id */
114                 1,                              /* Processor local SAPIC id */
115                 0,                              /* Processor local SAPIC eid */
116                 { 0, 0, 0 },
117                 0,                              /* FL: Enabled. */
118         },
119         /* cpu3. */
120         {
121                 {
122                         APIC_LOCAL_SAPIC,       /* Type. */
123                         sizeof(apic.cpu3)       /* Length. */
124                 },
125                 3,                              /* ACPI processor id */
126                 1,                              /* Processor local SAPIC id */
127                 1,                              /* Processor local SAPIC eid */
128                 { 0, 0, 0 },
129                 0,                              /* FL: Enabled. */
130         },
131         /* sapic. */
132         {
133                 {
134                         APIC_IO_SAPIC,          /* Type. */
135                         sizeof(apic.sapic)      /* Length. */
136                 },
137                 4,                              /* IO SAPIC id. */
138                 0,
139                 16,                             /* Interrupt base. */
140                 0xfec00000                      /* IO SAPIC address. */
141         }
142 };
143
144 struct {
145         ACPI_TABLE_HEADER       Header;
146         UINT64                  apic_tbl;
147 } xsdt = {
148         {
149                 XSDT_SIG,               /* Signature. */
150                 sizeof(xsdt),           /* Length of table. */
151                 0,                      /* ACPI minor revision. */
152                 0,                      /* XXX checksum. */
153                 "FBSD",                 /* OEM Id. */
154                 "SKI",                  /* OEM table Id. */
155                 0,                      /* OEM revision. */
156                 "FBSD",                 /* ASL compiler Id. */
157                 0                       /* ASL revision. */
158         },
159         NULL                            /* XXX APIC table address. */
160 };
161
162 ACPI_TABLE_RSDP acpi_root = {
163         RSDP_SIG,
164         0,                              /* XXX checksum. */
165         "FBSD",
166         2,                              /* ACPI Rev 2.0. */
167         NULL,
168         sizeof(xsdt),                   /* XSDT length. */
169         NULL,                           /* XXX PA of XSDT. */
170         0,                              /* XXX Extended checksum. */
171 };
172
173 static void
174 cksum(void *addr, int sz, UINT8 *sum)
175 {
176         UINT8 *p, s;
177
178         p = addr;
179         s = 0;
180         while (sz--)
181                 s += *p++;
182         *sum = -s;
183 }
184
185 void
186 acpi_stub_init(void)
187 {
188         acpi_root.XsdtPhysicalAddress = (UINT64)&xsdt;
189         cksum(&acpi_root, 20, &acpi_root.Checksum);
190         cksum(&acpi_root, sizeof(acpi_root), &acpi_root.ExtendedChecksum);
191
192         xsdt.apic_tbl = (UINT32)&apic;
193         cksum(&xsdt, sizeof(xsdt), &xsdt.Header.Checksum);
194 }