vchiq_netbsd_acpi.c revision 1.2
1/* $NetBSD: vchiq_netbsd_acpi.c,v 1.2 2020/02/22 19:37:31 jmcneill Exp $ */ 2 3/*- 4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jared D. McNeill 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: vchiq_netbsd_acpi.c,v 1.2 2020/02/22 19:37:31 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/bus.h> 40#include <sys/sysctl.h> 41 42#include <arm/broadcom/bcm2835reg.h> 43#include <arm/broadcom/bcm2835_intr.h> 44 45#include <dev/acpi/acpivar.h> 46#include <dev/acpi/acpi_intr.h> 47 48#include "vchiq_arm.h" 49#include "vchiq_2835.h" 50#include "vchiq_netbsd.h" 51 52struct vchiq_acpi_softc { 53 struct vchiq_softc sc_vchiq; 54 ACPI_HANDLE sc_handle; 55}; 56 57static int vchiq_acpi_match(device_t, cfdata_t, void *); 58static void vchiq_acpi_attach(device_t, device_t, void *); 59 60static void vchiq_acpi_defer(device_t); 61 62/* External functions */ 63int vchiq_init(void); 64 65 66CFATTACH_DECL_NEW(vchiq_acpi, sizeof(struct vchiq_acpi_softc), 67 vchiq_acpi_match, vchiq_acpi_attach, NULL, NULL); 68 69static int 70vchiq_acpi_match(device_t parent, cfdata_t match, void *aux) 71{ 72 const char * const compatible[] = { "BCM2835", NULL }; 73 struct acpi_attach_args * const aa = aux; 74 75 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 76 return 0; 77 78 return acpi_match_hid(aa->aa_node->ad_devinfo, compatible); 79} 80 81static void 82vchiq_acpi_attach(device_t parent, device_t self, void *aux) 83{ 84 struct vchiq_acpi_softc *asc = device_private(self); 85 struct vchiq_softc *sc = &asc->sc_vchiq; 86 struct acpi_attach_args * const aa = aux; 87 struct acpi_resources res; 88 struct acpi_mem *mem; 89 struct acpi_irq *irq; 90 ACPI_STATUS rv; 91 92 sc->sc_dev = self; 93 sc->sc_iot = aa->aa_memt; 94 asc->sc_handle = aa->aa_node->ad_handle; 95 96 rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", 97 &res, &acpi_resource_parse_ops_default); 98 if (ACPI_FAILURE(rv)) 99 return; 100 101 mem = acpi_res_mem(&res, 0); 102 irq = acpi_res_irq(&res, 0); 103 if (mem == NULL || irq == NULL) { 104 aprint_error_dev(self, "couldn't find resources\n"); 105 return; 106 } 107 108 if (bus_space_map(sc->sc_iot, mem->ar_base, mem->ar_length, 0, 109 &sc->sc_ioh) != 0) { 110 aprint_error_dev(sc->sc_dev, "unable to map device\n"); 111 return; 112 } 113 114 vchiq_platform_attach(aa->aa_dmat); 115 116 vchiq_set_softc(sc); 117 118 config_mountroot(self, vchiq_acpi_defer); 119} 120 121static void 122vchiq_acpi_defer(device_t self) 123{ 124 struct vchiq_attach_args vaa; 125 struct vchiq_acpi_softc *asc = device_private(self); 126 struct vchiq_softc *sc = &asc->sc_vchiq; 127 ACPI_HANDLE handle = asc->sc_handle; 128 129 vchiq_core_initialize(); 130 131 sc->sc_ih = acpi_intr_establish(sc->sc_dev, (uint64_t)handle, 132 IPL_VM, true, vchiq_intr, sc, device_xname(self)); 133 if (sc->sc_ih == NULL) { 134 aprint_error_dev(sc->sc_dev, "failed to establish interrupt\n"); 135 return; 136 } 137 138 vchiq_init(); 139 140 vaa.vaa_name = "AUDS"; 141 config_found_ia(self, "vchiqbus", &vaa, vchiq_print); 142} 143