xref: /netbsd-src/sys/arch/ia64/acpi/acpi_machdep.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: acpi_machdep.c,v 1.7 2018/03/20 12:14:52 bouyer 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.7 2018/03/20 12:14:52 bouyer 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_PHYSICAL_ADDRESS
63 acpi_md_OsGetRootPointer(void)
64 {
65 	void *acpi_root;
66 
67 	if (acpi_root_phys == 0) {
68 		acpi_root = efi_get_table(&acpi20_table);
69 		if (acpi_root == NULL)
70 			return 0;
71 		acpi_root_phys = IA64_RR_MASK((u_long)acpi_root);
72 	}
73 
74 	return acpi_root_phys;
75 }
76 
77 ACPI_STATUS
78 acpi_md_OsInstallInterruptHandler(UINT32 InterruptNumber,
79 				  ACPI_OSD_HANDLER ServiceRoutine,
80 				  void *Context, void **cookiep,
81 				  const char *xname)
82 {
83 	static int isa_irq_to_vector_map[16] = {
84 	        /* i8259 IRQ translation, first 16 entries */
85 		0x2f, 0x20, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29,
86 		0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21,
87 	};
88 	int irq;
89 	void *ih;
90 
91 	if (has_i8259 && InterruptNumber < 16)
92 		irq = isa_irq_to_vector_map[InterruptNumber];
93 	else
94 		irq = InterruptNumber;
95 
96 	/*
97 	 * XXX probably, IPL_BIO is enough.
98 	 */
99 	ih = intr_establish(irq, IST_LEVEL, IPL_TTY,
100 	    (int (*)(void *)) ServiceRoutine, Context);
101 	if (ih == NULL)
102 		return AE_NO_MEMORY;
103 	*cookiep = ih;
104 	return AE_OK;
105 }
106 
107 void
108 acpi_md_OsRemoveInterruptHandler(void *cookie)
109 {
110 
111 	intr_disestablish(cookie);
112 }
113 
114 ACPI_STATUS
115 acpi_md_OsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, UINT32 Length,
116 		    void **LogicalAddress)
117 {
118 
119 	if (bus_space_map(IA64_BUS_SPACE_MEM, PhysicalAddress, Length,
120 	    0, (bus_space_handle_t *) LogicalAddress) == 0)
121 		return AE_OK;
122 
123 	return AE_NO_MEMORY;
124 }
125 
126 void
127 acpi_md_OsUnmapMemory(void *LogicalAddress, UINT32 Length)
128 {
129 
130 	bus_space_unmap(IA64_BUS_SPACE_MEM, (bus_space_handle_t) LogicalAddress,
131 	    Length);
132 }
133 
134 ACPI_STATUS
135 acpi_md_OsGetPhysicalAddress(void *LogicalAddress,
136 			     ACPI_PHYSICAL_ADDRESS *PhysicalAddress)
137 {
138 	paddr_t pa;
139 
140 printf("%s\n", __func__);
141 	if (pmap_extract(pmap_kernel(), (vaddr_t) LogicalAddress, &pa)) {
142 		*PhysicalAddress = pa;
143 		return AE_OK;
144 	}
145 
146 	return AE_ERROR;
147 }
148 
149 BOOLEAN
150 acpi_md_OsReadable(void *Pointer, UINT32 Length)
151 {
152 	BOOLEAN rv = TRUE;
153 printf("%s: not yet...\n", __func__);
154 
155 	return rv;
156 }
157 
158 BOOLEAN
159 acpi_md_OsWritable(void *Pointer, UINT32 Length)
160 {
161 	BOOLEAN rv = FALSE;
162 printf("%s: not yet...\n", __func__);
163 	return rv;
164 }
165 
166 void
167 acpi_md_OsEnableInterrupt(void)
168 {
169 
170 	enable_intr();
171 }
172 
173 void
174 acpi_md_OsDisableInterrupt(void)
175 {
176 
177 	disable_intr();
178 }
179 
180 uint32_t
181 acpi_md_pdc(void)
182 {
183 	return 0;
184 }
185 
186 uint32_t
187 acpi_md_ncpus(void)
188 {
189 	return 0;		/* XXX. */
190 }
191 
192 void
193 acpi_md_callback(struct acpi_softc *sc)
194 {
195 	/* Nothing. */
196 }
197 
198 int
199 acpi_md_sleep(int state)
200 {
201 printf("%s: not yet...\n", __func__);
202 	return 0;
203 }
204