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