Home | History | Annotate | Line # | Download | only in acpi
acpi_machdep.c revision 1.18.6.2
      1  1.18.6.2    martin /* $NetBSD: acpi_machdep.c,v 1.18.6.2 2019/09/23 14:36:17 martin Exp $ */
      2       1.1    jruoho 
      3       1.1    jruoho /*
      4       1.1    jruoho  * Copyright 2001 Wasabi Systems, Inc.
      5       1.1    jruoho  * All rights reserved.
      6       1.1    jruoho  *
      7       1.1    jruoho  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8       1.1    jruoho  *
      9       1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     10       1.1    jruoho  * modification, are permitted provided that the following conditions
     11       1.1    jruoho  * are met:
     12       1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     13       1.1    jruoho  *    notice, this list of conditions and the following disclaimer.
     14       1.1    jruoho  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1    jruoho  *    notice, this list of conditions and the following disclaimer in the
     16       1.1    jruoho  *    documentation and/or other materials provided with the distribution.
     17       1.1    jruoho  * 3. All advertising materials mentioning features or use of this software
     18       1.1    jruoho  *    must display the following acknowledgement:
     19       1.1    jruoho  *	This product includes software developed for the NetBSD Project by
     20       1.1    jruoho  *	Wasabi Systems, Inc.
     21       1.1    jruoho  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22       1.1    jruoho  *    or promote products derived from this software without specific prior
     23       1.1    jruoho  *    written permission.
     24       1.1    jruoho  *
     25       1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26       1.1    jruoho  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27       1.1    jruoho  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28       1.1    jruoho  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29       1.1    jruoho  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30       1.1    jruoho  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31       1.1    jruoho  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32       1.1    jruoho  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33       1.1    jruoho  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34       1.1    jruoho  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35       1.1    jruoho  * POSSIBILITY OF SUCH DAMAGE.
     36       1.1    jruoho  */
     37       1.1    jruoho 
     38       1.1    jruoho /*
     39       1.1    jruoho  * Machine-dependent routines for ACPICA.
     40       1.1    jruoho  */
     41       1.1    jruoho 
     42       1.1    jruoho #include <sys/cdefs.h>
     43  1.18.6.2    martin __KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.18.6.2 2019/09/23 14:36:17 martin Exp $");
     44       1.1    jruoho 
     45       1.1    jruoho #include <sys/param.h>
     46       1.1    jruoho #include <sys/systm.h>
     47       1.2    dyoung #include <sys/bus.h>
     48       1.3     rmind #include <sys/cpu.h>
     49       1.1    jruoho #include <sys/device.h>
     50       1.1    jruoho 
     51       1.1    jruoho #include <uvm/uvm_extern.h>
     52       1.1    jruoho 
     53       1.1    jruoho #include <machine/cpufunc.h>
     54       1.9   msaitoh #include <machine/bootinfo.h>
     55      1.13  jmcneill #include <machine/autoconf.h>
     56       1.1    jruoho 
     57       1.1    jruoho #include <dev/acpi/acpica.h>
     58       1.1    jruoho #include <dev/acpi/acpivar.h>
     59       1.9   msaitoh #include <dev/acpi/acpi_mcfg.h>
     60       1.1    jruoho 
     61       1.1    jruoho #include <machine/acpi_machdep.h>
     62       1.1    jruoho #include <machine/mpbiosvar.h>
     63       1.1    jruoho #include <machine/mpacpi.h>
     64       1.1    jruoho #include <machine/i82093reg.h>
     65       1.1    jruoho #include <machine/i82093var.h>
     66       1.1    jruoho #include <machine/pic.h>
     67       1.1    jruoho 
     68      1.11  christos #include <x86/efi.h>
     69      1.11  christos 
     70       1.1    jruoho #include <dev/pci/pcivar.h>
     71       1.1    jruoho 
     72       1.1    jruoho #include <dev/isa/isareg.h>
     73       1.1    jruoho #include <dev/isa/isavar.h>
     74       1.1    jruoho 
     75       1.1    jruoho #include "ioapic.h"
     76       1.1    jruoho 
     77       1.1    jruoho #include "acpica.h"
     78       1.1    jruoho #include "opt_mpbios.h"
     79       1.1    jruoho #include "opt_acpi.h"
     80      1.13  jmcneill #include "opt_vga.h"
     81      1.13  jmcneill 
     82      1.13  jmcneill /*
     83      1.13  jmcneill  * Default VBIOS reset method for non-HW accelerated VGA drivers.
     84      1.13  jmcneill  */
     85      1.13  jmcneill #ifdef VGA_POST
     86      1.13  jmcneill # define VBIOS_RESET_DEFAULT	2
     87      1.13  jmcneill #else
     88      1.13  jmcneill # define VBIOS_RESET_DEFAULT	1
     89      1.13  jmcneill #endif
     90       1.1    jruoho 
     91       1.1    jruoho ACPI_STATUS
     92       1.1    jruoho acpi_md_OsInitialize(void)
     93       1.1    jruoho {
     94       1.1    jruoho 	return AE_OK;
     95       1.1    jruoho }
     96       1.1    jruoho 
     97       1.1    jruoho ACPI_PHYSICAL_ADDRESS
     98       1.1    jruoho acpi_md_OsGetRootPointer(void)
     99       1.1    jruoho {
    100       1.1    jruoho 	ACPI_PHYSICAL_ADDRESS PhysicalAddress;
    101       1.1    jruoho 	ACPI_STATUS Status;
    102       1.1    jruoho 
    103  1.18.6.1    martin #ifdef XEN
    104  1.18.6.1    martin 	/*
    105  1.18.6.2    martin 	 * This should use EFI_UUID_ACPI20 and EFI_UUID_ACPI10
    106  1.18.6.2    martin 	 * from src/sys/arch/x86/x86/efi.c but we want the
    107  1.18.6.2    martin 	 * ablility to build without this file included.
    108  1.18.6.2    martin 	 */
    109  1.18.6.2    martin 	const struct uuid UUID_ACPI20 = EFI_TABLE_ACPI20;
    110  1.18.6.2    martin 	const struct uuid UUID_ACPI10 = EFI_TABLE_ACPI10;
    111  1.18.6.2    martin 
    112  1.18.6.2    martin 	/*
    113  1.18.6.1    martin 	 * Obtain the ACPI RSDP from the hypervisor.
    114  1.18.6.1    martin 	 * This is the only way to go if Xen booted from EFI: the
    115  1.18.6.1    martin 	 * Extended BIOS Data Area (EBDA) is not mapped, and Xen
    116  1.18.6.1    martin 	 * does not pass an EFI SystemTable to the kernel.
    117  1.18.6.1    martin 	 */
    118  1.18.6.1    martin         struct xen_platform_op op = {
    119  1.18.6.1    martin                 .cmd = XENPF_firmware_info,
    120  1.18.6.1    martin                 .u.firmware_info = {
    121  1.18.6.1    martin                         .type = XEN_FW_EFI_INFO,
    122  1.18.6.1    martin                         .index = XEN_FW_EFI_CONFIG_TABLE
    123  1.18.6.1    martin                 }
    124  1.18.6.1    martin         };
    125  1.18.6.1    martin         union xenpf_efi_info *info = &op.u.firmware_info.u.efi_info;
    126  1.18.6.1    martin 
    127  1.18.6.1    martin         if (HYPERVISOR_platform_op(&op) == 0) {
    128  1.18.6.1    martin 		struct efi_cfgtbl *ct;
    129  1.18.6.1    martin 		int i;
    130  1.18.6.1    martin 
    131  1.18.6.1    martin 		ct = AcpiOsMapMemory(info->cfg.addr,
    132  1.18.6.1    martin 		    sizeof(*ct) * info->cfg.nent);
    133  1.18.6.1    martin 
    134  1.18.6.1    martin 		for (i = 0; i < info->cfg.nent; i++) {
    135  1.18.6.1    martin                 	if (memcmp(&ct[i].ct_uuid,
    136  1.18.6.2    martin 			    &UUID_ACPI20, sizeof(UUID_ACPI20)) == 0) {
    137  1.18.6.1    martin 				PhysicalAddress = (ACPI_PHYSICAL_ADDRESS)
    138  1.18.6.1    martin 				    (uintptr_t)ct[i].ct_data;
    139  1.18.6.1    martin 				if (PhysicalAddress)
    140  1.18.6.1    martin 					goto out;
    141  1.18.6.1    martin 
    142  1.18.6.1    martin 			}
    143  1.18.6.1    martin 		}
    144  1.18.6.1    martin 
    145  1.18.6.1    martin 		for (i = 0; i < info->cfg.nent; i++) {
    146  1.18.6.1    martin                 	if (memcmp(&ct[i].ct_uuid,
    147  1.18.6.2    martin 			    &UUID_ACPI10, sizeof(UUID_ACPI10)) == 0) {
    148  1.18.6.1    martin 				PhysicalAddress = (ACPI_PHYSICAL_ADDRESS)
    149  1.18.6.1    martin 				    (uintptr_t)ct[i].ct_data;
    150  1.18.6.1    martin 				if (PhysicalAddress)
    151  1.18.6.1    martin 					goto out;
    152  1.18.6.1    martin 
    153  1.18.6.1    martin 			}
    154  1.18.6.1    martin 		}
    155  1.18.6.1    martin out:
    156  1.18.6.1    martin 		AcpiOsUnmapMemory(ct, sizeof(*ct) * info->cfg.nent);
    157  1.18.6.1    martin 
    158  1.18.6.1    martin 		if (PhysicalAddress)
    159  1.18.6.1    martin 			return PhysicalAddress;
    160  1.18.6.1    martin 	}
    161  1.18.6.1    martin #else
    162  1.18.6.1    martin 	/*
    163  1.18.6.1    martin 	 * Get the ACPI RSDP from EFI SystemTable. This works when the
    164  1.18.6.1    martin 	 * kernel was loaded from EFI bootloader.
    165  1.18.6.1    martin 	 */
    166      1.11  christos 	if (efi_probe()) {
    167      1.11  christos 		PhysicalAddress = efi_getcfgtblpa(&EFI_UUID_ACPI20);
    168      1.11  christos 		if (!PhysicalAddress)
    169      1.11  christos 			PhysicalAddress = efi_getcfgtblpa(&EFI_UUID_ACPI10);
    170      1.11  christos 		if (PhysicalAddress)
    171      1.11  christos 			return PhysicalAddress;
    172      1.11  christos 	}
    173      1.11  christos 
    174      1.12     htodd #endif
    175  1.18.6.1    martin 	/*
    176  1.18.6.1    martin 	 * Find ACPI RSDP from Extended BIOS Data Area (EBDA). This
    177  1.18.6.1    martin 	 * works when the kernel was started from BIOS bootloader,
    178  1.18.6.1    martin 	 * or for Xen PV when Xen was started from BIOS bootloader.
    179  1.18.6.1    martin 	 */
    180       1.1    jruoho 	Status = AcpiFindRootPointer(&PhysicalAddress);
    181       1.1    jruoho 	if (ACPI_FAILURE(Status))
    182       1.1    jruoho 		PhysicalAddress = 0;
    183       1.1    jruoho 
    184       1.1    jruoho 	return PhysicalAddress;
    185       1.1    jruoho }
    186       1.1    jruoho 
    187       1.5       chs struct acpi_md_override {
    188       1.5       chs 	int irq;
    189       1.5       chs 	int pin;
    190       1.5       chs 	int flags;
    191       1.5       chs };
    192       1.5       chs 
    193       1.8     joerg #if NIOAPIC > 0
    194       1.5       chs static ACPI_STATUS
    195       1.5       chs acpi_md_findoverride(ACPI_SUBTABLE_HEADER *hdrp, void *aux)
    196       1.5       chs {
    197       1.5       chs 	ACPI_MADT_INTERRUPT_OVERRIDE *iop;
    198       1.5       chs 	struct acpi_md_override *ovrp;
    199       1.5       chs 
    200       1.5       chs 	if (hdrp->Type != ACPI_MADT_TYPE_INTERRUPT_OVERRIDE) {
    201       1.5       chs 		return AE_OK;
    202       1.5       chs 	}
    203       1.5       chs 
    204       1.5       chs 	iop = (void *)hdrp;
    205       1.5       chs 	ovrp = aux;
    206       1.5       chs 	if (iop->SourceIrq == ovrp->irq) {
    207       1.5       chs 		ovrp->pin = iop->GlobalIrq;
    208       1.5       chs 		ovrp->flags = iop->IntiFlags;
    209       1.5       chs 	}
    210       1.5       chs 	return AE_OK;
    211       1.5       chs }
    212       1.8     joerg #endif
    213       1.5       chs 
    214       1.1    jruoho ACPI_STATUS
    215       1.1    jruoho acpi_md_OsInstallInterruptHandler(uint32_t InterruptNumber,
    216       1.1    jruoho     ACPI_OSD_HANDLER ServiceRoutine, void *Context, void **cookiep)
    217       1.1    jruoho {
    218       1.1    jruoho 	void *ih;
    219       1.1    jruoho 	struct pic *pic;
    220       1.1    jruoho #if NIOAPIC > 0
    221       1.1    jruoho 	struct ioapic_softc *sc;
    222       1.5       chs 	struct acpi_md_override ovr;
    223       1.5       chs 	struct mp_intr_map tmpmap, *mip, **mipp = NULL;
    224       1.1    jruoho #endif
    225       1.5       chs 	int irq, pin, type, redir, mpflags;
    226       1.5       chs 
    227       1.5       chs 	/*
    228       1.5       chs 	 * ACPI interrupts default to level-triggered active-low.
    229       1.5       chs 	 */
    230       1.5       chs 
    231       1.5       chs 	type = IST_LEVEL;
    232       1.5       chs 	mpflags = (MPS_INTTR_LEVEL << 2) | MPS_INTPO_ACTLO;
    233       1.5       chs 	redir = IOAPIC_REDLO_LEVEL | IOAPIC_REDLO_ACTLO;
    234       1.1    jruoho 
    235       1.1    jruoho #if NIOAPIC > 0
    236       1.5       chs 
    237       1.1    jruoho 	/*
    238       1.5       chs 	 * Apply any MADT override setting.
    239       1.1    jruoho 	 */
    240       1.5       chs 
    241       1.5       chs 	ovr.irq = InterruptNumber;
    242       1.5       chs 	ovr.pin = -1;
    243       1.5       chs 	if (acpi_madt_map() == AE_OK) {
    244       1.5       chs 		acpi_madt_walk(acpi_md_findoverride, &ovr);
    245       1.5       chs 		acpi_madt_unmap();
    246       1.5       chs 	} else {
    247       1.5       chs 		aprint_debug("acpi_madt_map() failed, can't check for MADT override\n");
    248       1.5       chs 	}
    249       1.5       chs 
    250       1.5       chs 	if (ovr.pin != -1) {
    251       1.5       chs 		bool sci = InterruptNumber == AcpiGbl_FADT.SciInterrupt;
    252       1.5       chs 		int polarity = ovr.flags & ACPI_MADT_POLARITY_MASK;
    253       1.5       chs 		int trigger = ovr.flags & ACPI_MADT_TRIGGER_MASK;
    254       1.5       chs 
    255       1.5       chs 		InterruptNumber = ovr.pin;
    256       1.5       chs 		if (polarity == ACPI_MADT_POLARITY_ACTIVE_HIGH ||
    257       1.5       chs 		    (!sci && polarity == ACPI_MADT_POLARITY_CONFORMS)) {
    258       1.5       chs 			mpflags &= ~MPS_INTPO_ACTLO;
    259       1.6       chs 			mpflags |= MPS_INTPO_ACTHI;
    260       1.5       chs 			redir &= ~IOAPIC_REDLO_ACTLO;
    261       1.5       chs 		}
    262       1.5       chs 		if (trigger == ACPI_MADT_TRIGGER_EDGE ||
    263       1.5       chs 		    (!sci && trigger == ACPI_MADT_TRIGGER_CONFORMS)) {
    264       1.5       chs 			type = IST_EDGE;
    265       1.5       chs 			mpflags &= ~(MPS_INTTR_LEVEL << 2);
    266       1.6       chs 			mpflags |= (MPS_INTTR_EDGE << 2);
    267       1.5       chs 			redir &= ~IOAPIC_REDLO_LEVEL;
    268       1.5       chs 		}
    269       1.1    jruoho 	}
    270       1.1    jruoho 
    271       1.1    jruoho 	/*
    272       1.5       chs 	 * If the interrupt is handled via IOAPIC, update the map.
    273       1.5       chs 	 * If the map isn't set up yet, install a temporary one.
    274       1.1    jruoho 	 */
    275       1.1    jruoho 
    276       1.1    jruoho 	sc = ioapic_find_bybase(InterruptNumber);
    277       1.1    jruoho 	if (sc != NULL) {
    278       1.1    jruoho 		pic = &sc->sc_pic;
    279       1.1    jruoho 
    280       1.1    jruoho 		if (pic->pic_type == PIC_IOAPIC) {
    281       1.1    jruoho 			pin = (int)InterruptNumber - pic->pic_vecbase;
    282       1.1    jruoho 			irq = -1;
    283       1.1    jruoho 		} else {
    284       1.1    jruoho 			irq = pin = (int)InterruptNumber;
    285       1.1    jruoho 		}
    286       1.1    jruoho 
    287       1.1    jruoho 		mip = sc->sc_pins[pin].ip_map;
    288       1.1    jruoho 		if (mip) {
    289       1.5       chs 			mip->flags &= ~0xf;
    290       1.5       chs 			mip->flags |= mpflags;
    291       1.5       chs 			mip->redir &= ~(IOAPIC_REDLO_LEVEL |
    292       1.5       chs 					IOAPIC_REDLO_ACTLO);
    293       1.5       chs 			mip->redir |= redir;
    294       1.5       chs 		} else {
    295       1.5       chs 			mipp = &sc->sc_pins[pin].ip_map;
    296       1.5       chs 			*mipp = &tmpmap;
    297       1.5       chs 			tmpmap.redir = redir;
    298       1.6       chs 			tmpmap.flags = mpflags;
    299       1.1    jruoho 		}
    300       1.1    jruoho 	} else
    301       1.1    jruoho #endif
    302       1.1    jruoho 	{
    303       1.1    jruoho 		pic = &i8259_pic;
    304       1.1    jruoho 		irq = pin = (int)InterruptNumber;
    305       1.1    jruoho 	}
    306       1.1    jruoho 
    307       1.1    jruoho 	/*
    308       1.1    jruoho 	 * XXX probably, IPL_BIO is enough.
    309       1.1    jruoho 	 */
    310      1.14  jdolecek 	ih = intr_establish_xname(irq, pic, pin, type, IPL_TTY,
    311      1.14  jdolecek 	    (int (*)(void *)) ServiceRoutine, Context, false, "acpi SCI");
    312       1.1    jruoho 
    313       1.5       chs #if NIOAPIC > 0
    314       1.5       chs 	if (mipp) {
    315       1.5       chs 		*mipp = NULL;
    316       1.5       chs 	}
    317       1.5       chs #endif
    318       1.5       chs 
    319       1.1    jruoho 	if (ih == NULL)
    320       1.1    jruoho 		return AE_NO_MEMORY;
    321       1.1    jruoho 
    322       1.1    jruoho 	*cookiep = ih;
    323       1.1    jruoho 
    324       1.1    jruoho 	return AE_OK;
    325       1.1    jruoho }
    326       1.1    jruoho 
    327       1.1    jruoho void
    328       1.1    jruoho acpi_md_OsRemoveInterruptHandler(void *cookie)
    329       1.1    jruoho {
    330       1.1    jruoho 	intr_disestablish(cookie);
    331       1.1    jruoho }
    332       1.1    jruoho 
    333       1.1    jruoho ACPI_STATUS
    334       1.1    jruoho acpi_md_OsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress,
    335       1.1    jruoho     uint32_t Length, void **LogicalAddress)
    336       1.1    jruoho {
    337       1.1    jruoho 	int rv;
    338       1.1    jruoho 
    339       1.1    jruoho 	rv = _x86_memio_map(x86_bus_space_mem, PhysicalAddress,
    340       1.1    jruoho 	    Length, 0, (bus_space_handle_t *)LogicalAddress);
    341       1.1    jruoho 
    342       1.1    jruoho 	return (rv != 0) ? AE_NO_MEMORY : AE_OK;
    343       1.1    jruoho }
    344       1.1    jruoho 
    345       1.1    jruoho void
    346       1.1    jruoho acpi_md_OsUnmapMemory(void *LogicalAddress, uint32_t Length)
    347       1.1    jruoho {
    348       1.1    jruoho 	(void) _x86_memio_unmap(x86_bus_space_mem,
    349       1.1    jruoho 	    (bus_space_handle_t)LogicalAddress, Length, NULL);
    350       1.1    jruoho }
    351       1.1    jruoho 
    352       1.1    jruoho ACPI_STATUS
    353       1.1    jruoho acpi_md_OsGetPhysicalAddress(void *LogicalAddress,
    354       1.1    jruoho     ACPI_PHYSICAL_ADDRESS *PhysicalAddress)
    355       1.1    jruoho {
    356       1.1    jruoho 	paddr_t pa;
    357       1.1    jruoho 
    358       1.1    jruoho 	if (pmap_extract(pmap_kernel(), (vaddr_t) LogicalAddress, &pa)) {
    359       1.1    jruoho 		*PhysicalAddress = pa;
    360       1.1    jruoho 		return AE_OK;
    361       1.1    jruoho 	}
    362       1.1    jruoho 
    363       1.1    jruoho 	return AE_ERROR;
    364       1.1    jruoho }
    365       1.1    jruoho 
    366       1.1    jruoho BOOLEAN
    367       1.1    jruoho acpi_md_OsReadable(void *Pointer, uint32_t Length)
    368       1.1    jruoho {
    369       1.1    jruoho 	BOOLEAN rv = TRUE;
    370       1.1    jruoho 	vaddr_t sva, eva;
    371       1.1    jruoho 	pt_entry_t *pte;
    372       1.1    jruoho 
    373       1.1    jruoho 	sva = trunc_page((vaddr_t) Pointer);
    374       1.1    jruoho 	eva = round_page((vaddr_t) Pointer + Length);
    375       1.1    jruoho 
    376       1.1    jruoho 	if (sva < VM_MIN_KERNEL_ADDRESS)
    377       1.1    jruoho 		return FALSE;
    378       1.1    jruoho 
    379       1.1    jruoho 	for (; sva < eva; sva += PAGE_SIZE) {
    380       1.1    jruoho 		pte = kvtopte(sva);
    381       1.1    jruoho 		if ((*pte & PG_V) == 0) {
    382       1.1    jruoho 			rv = FALSE;
    383       1.1    jruoho 			break;
    384       1.1    jruoho 		}
    385       1.1    jruoho 	}
    386       1.1    jruoho 
    387       1.1    jruoho 	return rv;
    388       1.1    jruoho }
    389       1.1    jruoho 
    390       1.1    jruoho BOOLEAN
    391       1.1    jruoho acpi_md_OsWritable(void *Pointer, uint32_t Length)
    392       1.1    jruoho {
    393       1.7  jakllsch 	BOOLEAN rv = TRUE;
    394       1.1    jruoho 	vaddr_t sva, eva;
    395       1.1    jruoho 	pt_entry_t *pte;
    396       1.1    jruoho 
    397       1.1    jruoho 	sva = trunc_page((vaddr_t) Pointer);
    398       1.1    jruoho 	eva = round_page((vaddr_t) Pointer + Length);
    399       1.1    jruoho 
    400       1.1    jruoho 	if (sva < VM_MIN_KERNEL_ADDRESS)
    401       1.1    jruoho 		return FALSE;
    402       1.1    jruoho 
    403       1.1    jruoho 	for (; sva < eva; sva += PAGE_SIZE) {
    404       1.1    jruoho 		pte = kvtopte(sva);
    405       1.1    jruoho 		if ((*pte & (PG_V|PG_W)) != (PG_V|PG_W)) {
    406       1.1    jruoho 			rv = FALSE;
    407       1.1    jruoho 			break;
    408       1.1    jruoho 		}
    409       1.1    jruoho 	}
    410       1.1    jruoho 
    411       1.1    jruoho 	return rv;
    412       1.1    jruoho }
    413       1.1    jruoho 
    414       1.1    jruoho void
    415       1.1    jruoho acpi_md_OsDisableInterrupt(void)
    416       1.1    jruoho {
    417       1.1    jruoho 	x86_disable_intr();
    418       1.1    jruoho }
    419       1.1    jruoho 
    420       1.1    jruoho void
    421       1.1    jruoho acpi_md_OsEnableInterrupt(void)
    422       1.1    jruoho {
    423       1.1    jruoho 	x86_enable_intr();
    424       1.1    jruoho }
    425       1.1    jruoho 
    426       1.1    jruoho uint32_t
    427       1.1    jruoho acpi_md_ncpus(void)
    428       1.1    jruoho {
    429       1.3     rmind 	return kcpuset_countset(kcpuset_attached);
    430       1.1    jruoho }
    431       1.1    jruoho 
    432       1.9   msaitoh static bool
    433       1.9   msaitoh acpi_md_mcfg_validate(uint64_t addr, int bus_start, int *bus_end)
    434       1.9   msaitoh {
    435      1.17    nonaka 	struct btinfo_memmap *bim;
    436       1.9   msaitoh 	uint64_t size, mapaddr, mapsize;
    437       1.9   msaitoh 	uint32_t type;
    438      1.17    nonaka 	int i, n;
    439       1.9   msaitoh 
    440      1.17    nonaka #ifndef XEN
    441      1.17    nonaka 	if (lookup_bootinfo(BTINFO_EFIMEMMAP) != NULL)
    442      1.17    nonaka 		bim = efi_get_e820memmap();
    443      1.17    nonaka 	else
    444      1.17    nonaka #endif
    445      1.17    nonaka 		bim = lookup_bootinfo(BTINFO_MEMMAP);
    446      1.17    nonaka 	if (bim == NULL)
    447      1.17    nonaka 		return false;
    448       1.9   msaitoh 
    449      1.10  christos 	size = *bus_end - bus_start + 1;
    450      1.10  christos 	size *= ACPIMCFG_SIZE_PER_BUS;
    451      1.17    nonaka 	for (i = 0; i < bim->num; i++) {
    452      1.17    nonaka 		mapaddr = bim->entry[i].addr;
    453      1.17    nonaka 		mapsize = bim->entry[i].size;
    454      1.17    nonaka 		type = bim->entry[i].type;
    455      1.17    nonaka 
    456      1.17    nonaka 		aprint_debug("MCFG: MEMMAP: 0x%016" PRIx64
    457      1.17    nonaka 		    "-0x%016" PRIx64 ", size=0x%016" PRIx64
    458      1.17    nonaka 		    ", type=%d(%s)\n",
    459      1.17    nonaka 		    mapaddr, mapaddr + mapsize - 1, mapsize, type,
    460      1.17    nonaka 		    (type == BIM_Memory) ?  "Memory" :
    461      1.17    nonaka 		    (type == BIM_Reserved) ?  "Reserved" :
    462      1.17    nonaka 		    (type == BIM_ACPI) ? "ACPI" :
    463      1.17    nonaka 		    (type == BIM_NVS) ? "NVS" :
    464      1.18    nonaka 		    (type == BIM_PMEM) ? "Persistent" :
    465      1.18    nonaka 		    (type == BIM_PRAM) ? "Persistent (Legacy)" :
    466      1.17    nonaka 		    "unknown");
    467       1.9   msaitoh 
    468       1.9   msaitoh 		switch (type) {
    469       1.9   msaitoh 		case BIM_ACPI:
    470       1.9   msaitoh 		case BIM_Reserved:
    471       1.9   msaitoh 			if (addr < mapaddr || addr >= mapaddr + mapsize)
    472       1.9   msaitoh 				break;
    473       1.9   msaitoh 
    474       1.9   msaitoh 			/* full map */
    475       1.9   msaitoh 			if (addr + size <= mapaddr + mapsize)
    476       1.9   msaitoh 				return true;
    477       1.9   msaitoh 
    478       1.9   msaitoh 			/* partial map */
    479       1.9   msaitoh 			n = (mapsize - (addr - mapaddr)) /
    480       1.9   msaitoh 			    ACPIMCFG_SIZE_PER_BUS;
    481       1.9   msaitoh 			/* bus_start == bus_end is not allowed. */
    482       1.9   msaitoh 			if (n > 1) {
    483       1.9   msaitoh 				*bus_end = bus_start + n - 1;
    484       1.9   msaitoh 				return true;
    485       1.9   msaitoh 			}
    486       1.9   msaitoh 			aprint_debug("MCFG: bus %d-%d, address 0x%016" PRIx64
    487       1.9   msaitoh 			    ": invalid size: request 0x%016" PRIx64 ", "
    488       1.9   msaitoh 			    "actual 0x%016" PRIx64 "\n",
    489       1.9   msaitoh 			    bus_start, *bus_end, addr, size, mapsize);
    490       1.9   msaitoh 			break;
    491       1.9   msaitoh 		}
    492       1.9   msaitoh 	}
    493       1.9   msaitoh 	aprint_debug("MCFG: bus %d-%d, address 0x%016" PRIx64 ": "
    494       1.9   msaitoh 	    "no valid region\n", bus_start, *bus_end, addr);
    495       1.9   msaitoh 	return false;
    496       1.9   msaitoh }
    497       1.9   msaitoh 
    498       1.9   msaitoh static uint32_t
    499       1.9   msaitoh acpi_md_mcfg_read(bus_space_tag_t bst, bus_space_handle_t bsh, bus_addr_t addr)
    500       1.9   msaitoh {
    501       1.9   msaitoh 	vaddr_t va = bsh + addr;
    502       1.9   msaitoh 	uint32_t data = (uint32_t) -1;
    503       1.9   msaitoh 
    504       1.9   msaitoh 	KASSERT(bst == x86_bus_space_mem);
    505       1.9   msaitoh 
    506       1.9   msaitoh 	__asm("movl %1, %0" : "=a" (data) : "m" (*(volatile uint32_t *)va));
    507       1.9   msaitoh 
    508       1.9   msaitoh 	return data;
    509       1.9   msaitoh }
    510       1.9   msaitoh 
    511       1.9   msaitoh static void
    512       1.9   msaitoh acpi_md_mcfg_write(bus_space_tag_t bst, bus_space_handle_t bsh, bus_addr_t addr,
    513       1.9   msaitoh     uint32_t data)
    514       1.9   msaitoh {
    515       1.9   msaitoh 	vaddr_t va = bsh + addr;
    516       1.9   msaitoh 
    517       1.9   msaitoh 	KASSERT(bst == x86_bus_space_mem);
    518       1.9   msaitoh 
    519       1.9   msaitoh 	__asm("movl %1, %0" : "=m" (*(volatile uint32_t *)va) : "a" (data));
    520       1.9   msaitoh }
    521       1.9   msaitoh 
    522       1.9   msaitoh static const struct acpimcfg_ops acpi_md_mcfg_ops = {
    523       1.9   msaitoh 	.ao_validate = acpi_md_mcfg_validate,
    524       1.9   msaitoh 
    525       1.9   msaitoh 	.ao_read = acpi_md_mcfg_read,
    526       1.9   msaitoh 	.ao_write = acpi_md_mcfg_write,
    527       1.9   msaitoh };
    528       1.9   msaitoh 
    529       1.1    jruoho void
    530       1.4       chs acpi_md_callback(struct acpi_softc *sc)
    531       1.1    jruoho {
    532       1.1    jruoho #ifdef MPBIOS
    533       1.1    jruoho 	if (!mpbios_scanned)
    534       1.1    jruoho #endif
    535       1.4       chs 	mpacpi_find_interrupts(sc);
    536       1.1    jruoho 
    537       1.1    jruoho #ifndef XEN
    538       1.1    jruoho 	acpi_md_sleep_init();
    539       1.1    jruoho #endif
    540       1.9   msaitoh 
    541       1.9   msaitoh 	acpimcfg_init(x86_bus_space_mem, &acpi_md_mcfg_ops);
    542       1.1    jruoho }
    543      1.13  jmcneill 
    544      1.13  jmcneill #ifndef XEN
    545      1.13  jmcneill void
    546      1.13  jmcneill device_acpi_register(device_t dev, void *aux)
    547      1.13  jmcneill {
    548      1.13  jmcneill 	device_t parent;
    549      1.13  jmcneill 	bool device_is_vga, device_is_pci, device_is_isa;
    550      1.13  jmcneill 
    551      1.13  jmcneill 	parent = device_parent(dev);
    552      1.13  jmcneill 	if (parent == NULL)
    553      1.13  jmcneill 		return;
    554      1.13  jmcneill 
    555      1.13  jmcneill 	device_is_vga = device_is_a(dev, "vga") || device_is_a(dev, "genfb");
    556      1.13  jmcneill 	device_is_pci = device_is_a(parent, "pci");
    557      1.13  jmcneill 	device_is_isa = device_is_a(parent, "isa");
    558      1.13  jmcneill 
    559      1.13  jmcneill 	if (device_is_vga && (device_is_pci || device_is_isa)) {
    560      1.13  jmcneill 		extern int acpi_md_vbios_reset;
    561      1.13  jmcneill 
    562      1.13  jmcneill 		acpi_md_vbios_reset = VBIOS_RESET_DEFAULT;
    563      1.13  jmcneill 	}
    564      1.13  jmcneill }
    565      1.13  jmcneill #endif
    566