Home | History | Annotate | Line # | Download | only in fdt
acpi_fdt.c revision 1.5
      1 /* $NetBSD: acpi_fdt.c,v 1.5 2018/10/21 12:06:22 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.5 2018/10/21 12:06:22 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 struct acpi_pci_context acpi_fdt_pci_context;
     57 
     58 static const char * const compatible[] = {
     59 	"netbsd,acpi",
     60 	NULL
     61 };
     62 
     63 static const struct fdtbus_power_controller_func acpi_fdt_power_funcs = {
     64 	.poweroff = acpi_fdt_poweroff,
     65 };
     66 
     67 CFATTACH_DECL_NEW(acpi_fdt, 0, acpi_fdt_match, acpi_fdt_attach, NULL, NULL);
     68 
     69 static int
     70 acpi_fdt_match(device_t parent, cfdata_t cf, void *aux)
     71 {
     72 	struct fdt_attach_args * const faa = aux;
     73 
     74 	return of_compatible(faa->faa_phandle, compatible) >= 0;
     75 }
     76 
     77 static void
     78 acpi_fdt_attach(device_t parent, device_t self, void *aux)
     79 {
     80 	struct fdt_attach_args * const faa = aux;
     81 	struct acpibus_attach_args aa;
     82 
     83 	aprint_naive("\n");
     84 	aprint_normal(": ACPI Platform support\n");
     85 
     86 	fdtbus_register_power_controller(self, faa->faa_phandle,
     87 	    &acpi_fdt_power_funcs);
     88 
     89 	if (!acpi_probe())
     90 		aprint_error_dev(self, "failed to probe ACPI\n");
     91 
     92 	acpi_fdt_pci_context.ap_pc = arm_acpi_pci_chipset;
     93 	acpi_fdt_pci_context.ap_pc.pc_conf_v = &acpi_fdt_pci_context;
     94 	acpi_fdt_pci_context.ap_seg = 0;
     95 
     96 	aa.aa_iot = 0;
     97 	aa.aa_memt = faa->faa_bst;
     98 	aa.aa_pc = &acpi_fdt_pci_context.ap_pc;
     99 	aa.aa_pciflags =
    100 	    /*PCI_FLAGS_IO_OKAY |*/ PCI_FLAGS_MEM_OKAY |
    101 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
    102 	    PCI_FLAGS_MWI_OKAY;
    103 #ifdef __HAVE_PCI_MSI_MSIX
    104 	aa.aa_pciflags |= PCI_FLAGS_MSI_OKAY;
    105 #endif
    106 	aa.aa_ic = 0;
    107 	aa.aa_dmat = faa->faa_dmat;
    108 #ifdef _PCI_HAVE_DMA64
    109 	aa.aa_dmat64 = faa->faa_dmat;
    110 #endif
    111 	config_found_ia(self, "acpibus", &aa, 0);
    112 }
    113 
    114 static void
    115 acpi_fdt_poweroff(device_t dev)
    116 {
    117 	delay(500000);
    118 	if (psci_available())
    119 		psci_system_off();
    120 }
    121