Home | History | Annotate | Line # | Download | only in fdt
acpi_fdt.c revision 1.3
      1 /* $NetBSD: acpi_fdt.c,v 1.3 2018/10/15 11:35:03 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2015-2017 Jared McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.3 2018/10/15 11:35:03 jmcneill Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/bus.h>
     34 #include <sys/device.h>
     35 #include <sys/intr.h>
     36 #include <sys/systm.h>
     37 #include <sys/kernel.h>
     38 #include <sys/lwp.h>
     39 #include <sys/kmem.h>
     40 #include <sys/queue.h>
     41 
     42 #include <dev/fdt/fdtvar.h>
     43 
     44 #include <dev/acpi/acpivar.h>
     45 #include <dev/pci/pcivar.h>
     46 
     47 #include <arm/arm/psci.h>
     48 
     49 #include <arm/acpi/acpi_pci_machdep.h>
     50 
     51 static int	acpi_fdt_match(device_t, cfdata_t, void *);
     52 static void	acpi_fdt_attach(device_t, device_t, void *);
     53 
     54 static void	acpi_fdt_poweroff(device_t);
     55 
     56 static const char * const compatible[] = {
     57 	"netbsd,acpi",
     58 	NULL
     59 };
     60 
     61 static const struct fdtbus_power_controller_func acpi_fdt_power_funcs = {
     62 	.poweroff = acpi_fdt_poweroff,
     63 };
     64 
     65 CFATTACH_DECL_NEW(acpi_fdt, 0, acpi_fdt_match, acpi_fdt_attach, NULL, NULL);
     66 
     67 static int
     68 acpi_fdt_match(device_t parent, cfdata_t cf, void *aux)
     69 {
     70 	struct fdt_attach_args * const faa = aux;
     71 
     72 	return of_compatible(faa->faa_phandle, compatible) >= 0;
     73 }
     74 
     75 static void
     76 acpi_fdt_attach(device_t parent, device_t self, void *aux)
     77 {
     78 	struct fdt_attach_args * const faa = aux;
     79 	struct acpibus_attach_args aa;
     80 
     81 	aprint_naive("\n");
     82 	aprint_normal(": ACPI Platform support\n");
     83 
     84 	fdtbus_register_power_controller(self, faa->faa_phandle,
     85 	    &acpi_fdt_power_funcs);
     86 
     87 	if (!acpi_probe())
     88 		aprint_error_dev(self, "failed to probe ACPI\n");
     89 
     90 	aa.aa_iot = 0;
     91 	aa.aa_memt = faa->faa_bst;
     92 	aa.aa_pc = &arm_acpi_pci_chipset;
     93 	aa.aa_pciflags =
     94 	    /*PCI_FLAGS_IO_OKAY |*/ PCI_FLAGS_MEM_OKAY |
     95 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
     96 	    PCI_FLAGS_MWI_OKAY;
     97 	aa.aa_ic = 0;
     98 	aa.aa_dmat = faa->faa_dmat;
     99 #ifdef _PCI_HAVE_DMA64
    100 	aa.aa_dmat64 = faa->faa_dmat;
    101 #endif
    102 	config_found_ia(self, "acpibus", &aa, 0);
    103 }
    104 
    105 static void
    106 acpi_fdt_poweroff(device_t dev)
    107 {
    108 	delay(500000);
    109 	if (psci_available())
    110 		psci_system_off();
    111 }
    112