1 /* $NetBSD: amdccp_acpi.c,v 1.2 2018/10/21 11:09:20 jmcneill Exp $ */ 2 3 /* 4 * Copyright (c) 2018 Jonathan A. Kollasch 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 COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: amdccp_acpi.c,v 1.2 2018/10/21 11:09:20 jmcneill Exp $"); 31 32 #include <sys/param.h> 33 #include <sys/bus.h> 34 #include <sys/cpu.h> 35 #include <sys/device.h> 36 37 #include <dev/acpi/acpireg.h> 38 #include <dev/acpi/acpivar.h> 39 40 #include <dev/ic/amdccpvar.h> 41 42 static int amdccp_acpi_match(device_t, cfdata_t, void *); 43 static void amdccp_acpi_attach(device_t, device_t, void *); 44 45 CFATTACH_DECL_NEW(amdccp_acpi, sizeof(struct amdccp_softc), 46 amdccp_acpi_match, amdccp_acpi_attach, NULL, NULL); 47 48 static const char * const compatible[] = { 49 "AMDI0C00", 50 NULL 51 }; 52 53 static int 54 amdccp_acpi_match(device_t parent, cfdata_t cf, void *aux) 55 { 56 struct acpi_attach_args *aa = aux; 57 58 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 59 return 0; 60 61 return acpi_match_hid(aa->aa_node->ad_devinfo, compatible); 62 } 63 64 static void 65 amdccp_acpi_attach(device_t parent, device_t self, void *aux) 66 { 67 struct amdccp_softc * const sc = device_private(self); 68 struct acpi_attach_args *aa = aux; 69 struct acpi_resources res; 70 struct acpi_mem *mem; 71 #if notyet 72 struct acpi_irq *irq; 73 #endif 74 ACPI_STATUS rv; 75 #if notyet 76 void *ih; 77 #endif 78 79 sc->sc_dev = self; 80 81 rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS", 82 &res, &acpi_resource_parse_ops_default); 83 if (ACPI_FAILURE(rv)) 84 return; 85 86 mem = acpi_res_mem(&res, 0); 87 if (mem == NULL) { 88 aprint_error_dev(self, "couldn't find mem resource\n"); 89 goto done; 90 } 91 92 #if notyet 93 irq = acpi_res_irq(&res, 0); 94 if (irq == NULL) { 95 aprint_error_dev(self, "couldn't find irq resource\n"); 96 goto done; 97 } 98 99 #endif 100 sc->sc_bst = aa->aa_memt; 101 if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0, &sc->sc_bsh) != 0) { 102 aprint_error_dev(self, "couldn't map registers\n"); 103 goto done; 104 } 105 106 #if notyet 107 const int type = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL; 108 ih = intr_establish(irq->ar_irq, IPL_VM, type | IST_MPSAFE, amdccp_intr, sc); 109 if (ih == NULL) { 110 aprint_error_dev(self, "couldn't install interrupt handler\n"); 111 return; 112 } 113 114 #endif 115 116 amdccp_common_attach(sc); 117 118 done: 119 acpi_resource_cleanup(&res); 120 } 121