Home | History | Annotate | Line # | Download | only in acpi
      1 /* $NetBSD: amdccp_acpi.c,v 1.6 2022/12/18 15:50:32 reinoud 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.6 2022/12/18 15:50:32 reinoud 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 #include <dev/acpi/acpi_intr.h>
     40 
     41 #include <dev/ic/amdccpvar.h>
     42 
     43 static int	amdccp_acpi_match(device_t, cfdata_t, void *);
     44 static void	amdccp_acpi_attach(device_t, device_t, void *);
     45 
     46 CFATTACH_DECL_NEW(amdccp_acpi, sizeof(struct amdccp_softc),
     47     amdccp_acpi_match, amdccp_acpi_attach, NULL, NULL);
     48 
     49 static const struct device_compatible_entry compat_data[] = {
     50 	{ .compat = "AMDI0C00" },
     51 	DEVICE_COMPAT_EOL
     52 };
     53 
     54 static int
     55 amdccp_acpi_match(device_t parent, cfdata_t cf, void *aux)
     56 {
     57 	struct acpi_attach_args *aa = aux;
     58 
     59 	return acpi_compatible_match(aa, compat_data);
     60 }
     61 
     62 static void
     63 amdccp_acpi_attach(device_t parent, device_t self, void *aux)
     64 {
     65 	struct amdccp_softc * const sc = device_private(self);
     66 	struct acpi_attach_args *aa = aux;
     67 	struct acpi_resources res;
     68 	struct acpi_mem *mem;
     69 	ACPI_STATUS rv;
     70 #if notyet
     71 	void *ih;
     72 #endif
     73 
     74 	sc->sc_dev = self;
     75 
     76 	rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
     77 	    &res, &acpi_resource_parse_ops_default);
     78 	if (ACPI_FAILURE(rv))
     79 		return;
     80 
     81 	mem = acpi_res_mem(&res, 0);
     82 	if (mem == NULL) {
     83 		aprint_error_dev(self, "couldn't find mem resource\n");
     84 		goto done;
     85 	}
     86 
     87 	sc->sc_bst = aa->aa_memt;
     88 	if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0,
     89 	    &sc->sc_bsh) != 0) {
     90 		aprint_error_dev(self, "couldn't map registers\n");
     91 		goto done;
     92 	}
     93 
     94 #if notyet
     95 	ih = acpi_intr_establish(self,
     96 	    (uint64_t)(uintptr_t)aa->aa_node->ad_handle,
     97 	    IPL_VM, true, amdccp_intr, sc, device_xname(self));
     98 	if (ih == NULL) {
     99 		aprint_error_dev(self, "couldn't install interrupt handler\n");
    100 		return;
    101 	}
    102 
    103 #endif
    104 
    105 	amdccp_common_attach(sc);
    106 	pmf_device_register(self, NULL, NULL);
    107 
    108 done:
    109 	acpi_resource_cleanup(&res);
    110 }
    111