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