acpi_machdep.c revision 1.3 1 /* $NetBSD: acpi_machdep.c,v 1.3 2011/01/13 03:40:50 jruoho Exp $ */
2 /*
3 * Copyright (c) 2009 KIYOHARA Takashi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27 /*
28 * Machine-dependent routines for ACPICA.
29 */
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.3 2011/01/13 03:40:50 jruoho Exp $");
32
33 #include <sys/param.h>
34
35 #include <uvm/uvm_extern.h>
36
37 #include <machine/bus.h>
38 #include <machine/efi.h>
39 #include <machine/intrdefs.h>
40
41 #include <dev/acpi/acpica.h>
42 #include <dev/acpi/acpivar.h>
43
44 #include <machine/acpi_machdep.h>
45
46
47 static struct uuid acpi20_table = EFI_TABLE_ACPI20;
48 static u_long acpi_root_phys;
49 int has_i8259 = 0;
50
51
52 ACPI_STATUS
53 acpi_md_OsInitialize(void)
54 {
55
56 if (((ia64_get_cpuid(3) >> 24) & 0xff) == 0x07)
57 has_i8259 = 1; /* Firmware on old Itanium systems is broken */
58
59 return AE_OK;
60 }
61
62 ACPI_STATUS
63 acpi_md_OsTerminate(void)
64 {
65
66 /* nothing to do. */
67 printf("%s\n", __func__);
68 return AE_OK;
69 }
70
71 ACPI_PHYSICAL_ADDRESS
72 acpi_md_OsGetRootPointer(void)
73 {
74 void *acpi_root;
75
76 if (acpi_root_phys == 0) {
77 acpi_root = efi_get_table(&acpi20_table);
78 if (acpi_root == NULL)
79 return 0;
80 acpi_root_phys = IA64_RR_MASK((u_long)acpi_root);
81 }
82
83 return acpi_root_phys;
84 }
85
86 ACPI_STATUS
87 acpi_md_OsInstallInterruptHandler(UINT32 InterruptNumber,
88 ACPI_OSD_HANDLER ServiceRoutine,
89 void *Context, void **cookiep)
90 {
91 static int isa_irq_to_vector_map[16] = {
92 /* i8259 IRQ translation, first 16 entries */
93 0x2f, 0x20, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29,
94 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21,
95 };
96 int irq;
97 void *ih;
98
99 if (has_i8259 && InterruptNumber < 16)
100 irq = isa_irq_to_vector_map[InterruptNumber];
101 else
102 irq = InterruptNumber;
103
104 /*
105 * XXX probably, IPL_BIO is enough.
106 */
107 ih = intr_establish(irq, IST_LEVEL, IPL_TTY,
108 (int (*)(void *)) ServiceRoutine, Context);
109 if (ih == NULL)
110 return AE_NO_MEMORY;
111 *cookiep = ih;
112 return AE_OK;
113 }
114
115 void
116 acpi_md_OsRemoveInterruptHandler(void *cookie)
117 {
118
119 intr_disestablish(cookie);
120 }
121
122 ACPI_STATUS
123 acpi_md_OsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, UINT32 Length,
124 void **LogicalAddress)
125 {
126
127 if (bus_space_map(IA64_BUS_SPACE_MEM, PhysicalAddress, Length,
128 0, (bus_space_handle_t *) LogicalAddress) == 0)
129 return AE_OK;
130
131 return AE_NO_MEMORY;
132 }
133
134 void
135 acpi_md_OsUnmapMemory(void *LogicalAddress, UINT32 Length)
136 {
137
138 bus_space_unmap(IA64_BUS_SPACE_MEM, (bus_space_handle_t) LogicalAddress,
139 Length);
140 }
141
142 ACPI_STATUS
143 acpi_md_OsGetPhysicalAddress(void *LogicalAddress,
144 ACPI_PHYSICAL_ADDRESS *PhysicalAddress)
145 {
146 paddr_t pa;
147
148 printf("%s\n", __func__);
149 if (pmap_extract(pmap_kernel(), (vaddr_t) LogicalAddress, &pa)) {
150 *PhysicalAddress = pa;
151 return AE_OK;
152 }
153
154 return AE_ERROR;
155 }
156
157 BOOLEAN
158 acpi_md_OsReadable(void *Pointer, UINT32 Length)
159 {
160 BOOLEAN rv = TRUE;
161 printf("%s: not yet...\n", __func__);
162
163 return rv;
164 }
165
166 BOOLEAN
167 acpi_md_OsWritable(void *Pointer, UINT32 Length)
168 {
169 BOOLEAN rv = FALSE;
170 printf("%s: not yet...\n", __func__);
171 return rv;
172 }
173
174 void
175 acpi_md_OsEnableInterrupt(void)
176 {
177
178 enable_intr();
179 }
180
181 void
182 acpi_md_OsDisableInterrupt(void)
183 {
184
185 disable_intr();
186 }
187
188 uint32_t
189 acpi_md_ncpus(void)
190 {
191
192 return 0; /* XXX. */
193 }
194
195 void
196 acpi_md_callback(void)
197 {
198
199 /* nothing */
200 }
201
202
203 int
204 acpi_md_sleep(int state)
205 {
206 printf("%s: not yet...\n", __func__);
207 return 0;
208 }
209