Home | History | Annotate | Line # | Download | only in broadcom
      1 /*	$NetBSD: bcm2835_mbox_acpi.c,v 1.2 2020/02/22 22:09:07 jmcneill Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Nick Hudson
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox_acpi.c,v 1.2 2020/02/22 22:09:07 jmcneill Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 #include <sys/kernel.h>
     39 #include <sys/timetc.h>
     40 #include <sys/bus.h>
     41 #include <sys/mutex.h>
     42 
     43 #include <arm/broadcom/bcm2835_mbox.h>
     44 #include <arm/broadcom/bcm2835_mboxreg.h>
     45 #include <arm/broadcom/bcm2835reg.h>
     46 #include <arm/broadcom/bcm2835var.h>
     47 
     48 #include <dev/acpi/acpivar.h>
     49 #include <dev/acpi/acpi_intr.h>
     50 #include <arch/evbarm/rpi/vcprop.h>
     51 #include <arch/evbarm/rpi/vcio.h>
     52 #include <arch/evbarm/rpi/vcpm.h>
     53 
     54 static int bcmmbox_acpi_match(device_t, cfdata_t, void *);
     55 static void bcmmbox_acpi_attach(device_t, device_t, void *);
     56 
     57 CFATTACH_DECL_NEW(bcmmbox_acpi, sizeof(struct bcm2835mbox_softc),
     58     bcmmbox_acpi_match, bcmmbox_acpi_attach, NULL, NULL);
     59 
     60 static int
     61 bcmmbox_acpi_match(device_t parent, cfdata_t match, void *aux)
     62 {
     63 	const char * const acpi_compatible[] = {
     64 		"BCM2849",
     65 		NULL
     66 	};
     67 	struct acpi_attach_args * const aa = aux;
     68 
     69 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
     70 		return 0;
     71 
     72 	return acpi_match_hid(aa->aa_node->ad_devinfo, acpi_compatible);
     73 }
     74 
     75 static void
     76 bcmmbox_acpi_attach(device_t parent, device_t self, void *aux)
     77 {
     78 	struct bcm2835mbox_softc *sc = device_private(self);
     79 	struct acpi_attach_args * const aa = aux;
     80 	struct acpi_resources res;
     81 	struct acpi_mem *mem;
     82 	struct acpi_irq *irq;
     83 	ACPI_STATUS rv;
     84 
     85 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
     86 	    &res, &acpi_resource_parse_ops_default);
     87 	if (ACPI_FAILURE(rv))
     88 		return;
     89 
     90 	mem = acpi_res_mem(&res, 0);
     91 	irq = acpi_res_irq(&res, 0);
     92 	if (mem == NULL || irq == NULL) {
     93 		aprint_error_dev(self, "couldn't find resources\n");
     94 		return;
     95 	}
     96 
     97 	sc->sc_dev = self;
     98 	sc->sc_iot = aa->aa_memt;
     99 	sc->sc_dmat = aa->aa_dmat;
    100 
    101 	if (bus_space_map(sc->sc_iot, mem->ar_base, mem->ar_length, 0, &sc->sc_ioh) != 0) {
    102 		aprint_error_dev(sc->sc_dev, "unable to map device\n");
    103 		return;
    104 	}
    105 
    106 #if notyet
    107 	sc->sc_intrh = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
    108 	    IPL_VM, false, bcmmbox_intr, sc, device_xname(self));
    109 	if (sc->sc_intrh == NULL) {
    110 		aprint_error_dev(self, "failed to establish interrupt\n");
    111 		return;
    112 	}
    113 #endif
    114 
    115 	bcmmbox_attach(sc);
    116 }
    117