xref: /netbsd-src/sys/arch/arm/broadcom/bcm2835_mbox_acpi.c (revision e92ada05cce51645294ff6284dd4475419f5dc33)
1*e92ada05Sjmcneill /*	$NetBSD: bcm2835_mbox_acpi.c,v 1.2 2020/02/22 22:09:07 jmcneill Exp $	*/
28f3c29f9Sjmcneill 
38f3c29f9Sjmcneill /*-
48f3c29f9Sjmcneill  * Copyright (c) 2012 The NetBSD Foundation, Inc.
58f3c29f9Sjmcneill  * All rights reserved.
68f3c29f9Sjmcneill  *
78f3c29f9Sjmcneill  * This code is derived from software contributed to The NetBSD Foundation
88f3c29f9Sjmcneill  * by Nick Hudson
98f3c29f9Sjmcneill  *
108f3c29f9Sjmcneill  * Redistribution and use in source and binary forms, with or without
118f3c29f9Sjmcneill  * modification, are permitted provided that the following conditions
128f3c29f9Sjmcneill  * are met:
138f3c29f9Sjmcneill  * 1. Redistributions of source code must retain the above copyright
148f3c29f9Sjmcneill  *    notice, this list of conditions and the following disclaimer.
158f3c29f9Sjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
168f3c29f9Sjmcneill  *    notice, this list of conditions and the following disclaimer in the
178f3c29f9Sjmcneill  *    documentation and/or other materials provided with the distribution.
188f3c29f9Sjmcneill  *
198f3c29f9Sjmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
208f3c29f9Sjmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
218f3c29f9Sjmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
228f3c29f9Sjmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
238f3c29f9Sjmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
248f3c29f9Sjmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
258f3c29f9Sjmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
268f3c29f9Sjmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
278f3c29f9Sjmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
288f3c29f9Sjmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
298f3c29f9Sjmcneill  * POSSIBILITY OF SUCH DAMAGE.
308f3c29f9Sjmcneill  */
318f3c29f9Sjmcneill 
328f3c29f9Sjmcneill #include <sys/cdefs.h>
33*e92ada05Sjmcneill __KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox_acpi.c,v 1.2 2020/02/22 22:09:07 jmcneill Exp $");
348f3c29f9Sjmcneill 
358f3c29f9Sjmcneill #include <sys/param.h>
368f3c29f9Sjmcneill #include <sys/systm.h>
378f3c29f9Sjmcneill #include <sys/device.h>
388f3c29f9Sjmcneill #include <sys/kernel.h>
398f3c29f9Sjmcneill #include <sys/timetc.h>
408f3c29f9Sjmcneill #include <sys/bus.h>
418f3c29f9Sjmcneill #include <sys/mutex.h>
428f3c29f9Sjmcneill 
438f3c29f9Sjmcneill #include <arm/broadcom/bcm2835_mbox.h>
448f3c29f9Sjmcneill #include <arm/broadcom/bcm2835_mboxreg.h>
458f3c29f9Sjmcneill #include <arm/broadcom/bcm2835reg.h>
468f3c29f9Sjmcneill #include <arm/broadcom/bcm2835var.h>
478f3c29f9Sjmcneill 
488f3c29f9Sjmcneill #include <dev/acpi/acpivar.h>
498f3c29f9Sjmcneill #include <dev/acpi/acpi_intr.h>
508f3c29f9Sjmcneill #include <arch/evbarm/rpi/vcprop.h>
518f3c29f9Sjmcneill #include <arch/evbarm/rpi/vcio.h>
528f3c29f9Sjmcneill #include <arch/evbarm/rpi/vcpm.h>
538f3c29f9Sjmcneill 
548f3c29f9Sjmcneill static int bcmmbox_acpi_match(device_t, cfdata_t, void *);
558f3c29f9Sjmcneill static void bcmmbox_acpi_attach(device_t, device_t, void *);
568f3c29f9Sjmcneill 
578f3c29f9Sjmcneill CFATTACH_DECL_NEW(bcmmbox_acpi, sizeof(struct bcm2835mbox_softc),
588f3c29f9Sjmcneill     bcmmbox_acpi_match, bcmmbox_acpi_attach, NULL, NULL);
598f3c29f9Sjmcneill 
608f3c29f9Sjmcneill static int
bcmmbox_acpi_match(device_t parent,cfdata_t match,void * aux)618f3c29f9Sjmcneill bcmmbox_acpi_match(device_t parent, cfdata_t match, void *aux)
628f3c29f9Sjmcneill {
638f3c29f9Sjmcneill 	const char * const acpi_compatible[] = {
648f3c29f9Sjmcneill 		"BCM2849",
658f3c29f9Sjmcneill 		NULL
668f3c29f9Sjmcneill 	};
678f3c29f9Sjmcneill 	struct acpi_attach_args * const aa = aux;
688f3c29f9Sjmcneill 
698f3c29f9Sjmcneill 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
708f3c29f9Sjmcneill 		return 0;
718f3c29f9Sjmcneill 
728f3c29f9Sjmcneill 	return acpi_match_hid(aa->aa_node->ad_devinfo, acpi_compatible);
738f3c29f9Sjmcneill }
748f3c29f9Sjmcneill 
758f3c29f9Sjmcneill static void
bcmmbox_acpi_attach(device_t parent,device_t self,void * aux)768f3c29f9Sjmcneill bcmmbox_acpi_attach(device_t parent, device_t self, void *aux)
778f3c29f9Sjmcneill {
788f3c29f9Sjmcneill 	struct bcm2835mbox_softc *sc = device_private(self);
798f3c29f9Sjmcneill 	struct acpi_attach_args * const aa = aux;
808f3c29f9Sjmcneill 	struct acpi_resources res;
818f3c29f9Sjmcneill 	struct acpi_mem *mem;
828f3c29f9Sjmcneill 	struct acpi_irq *irq;
838f3c29f9Sjmcneill 	ACPI_STATUS rv;
848f3c29f9Sjmcneill 
858f3c29f9Sjmcneill 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
868f3c29f9Sjmcneill 	    &res, &acpi_resource_parse_ops_default);
878f3c29f9Sjmcneill 	if (ACPI_FAILURE(rv))
888f3c29f9Sjmcneill 		return;
898f3c29f9Sjmcneill 
908f3c29f9Sjmcneill 	mem = acpi_res_mem(&res, 0);
918f3c29f9Sjmcneill 	irq = acpi_res_irq(&res, 0);
928f3c29f9Sjmcneill 	if (mem == NULL || irq == NULL) {
938f3c29f9Sjmcneill 		aprint_error_dev(self, "couldn't find resources\n");
948f3c29f9Sjmcneill 		return;
958f3c29f9Sjmcneill 	}
968f3c29f9Sjmcneill 
978f3c29f9Sjmcneill 	sc->sc_dev = self;
988f3c29f9Sjmcneill 	sc->sc_iot = aa->aa_memt;
998f3c29f9Sjmcneill 	sc->sc_dmat = aa->aa_dmat;
1008f3c29f9Sjmcneill 
1018f3c29f9Sjmcneill 	if (bus_space_map(sc->sc_iot, mem->ar_base, mem->ar_length, 0, &sc->sc_ioh) != 0) {
1028f3c29f9Sjmcneill 		aprint_error_dev(sc->sc_dev, "unable to map device\n");
1038f3c29f9Sjmcneill 		return;
1048f3c29f9Sjmcneill 	}
1058f3c29f9Sjmcneill 
106*e92ada05Sjmcneill #if notyet
1078f3c29f9Sjmcneill 	sc->sc_intrh = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
1088f3c29f9Sjmcneill 	    IPL_VM, false, bcmmbox_intr, sc, device_xname(self));
1098f3c29f9Sjmcneill 	if (sc->sc_intrh == NULL) {
1108f3c29f9Sjmcneill 		aprint_error_dev(self, "failed to establish interrupt\n");
1118f3c29f9Sjmcneill 		return;
1128f3c29f9Sjmcneill 	}
113*e92ada05Sjmcneill #endif
1148f3c29f9Sjmcneill 
1158f3c29f9Sjmcneill 	bcmmbox_attach(sc);
1168f3c29f9Sjmcneill }
117