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