1 /* $OpenBSD: acpisectwo.c,v 1.1 2024/07/30 19:47:06 mglocker Exp $ */
2 /*
3 * Copyright (c) 2024 Marcus Glocker <mglocker@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <sys/param.h>
19 #include <sys/systm.h>
20
21 #include <dev/acpi/acpivar.h>
22 #include <dev/acpi/dsdt.h>
23
24 //#define ACPISECTWO_DEBUG
25 #ifdef ACPISECTWO_DEBUG
26 #define DPRINTF(x) printf x
27 #else
28 #define DPRINTF(x)
29 #endif
30
31 #define ACPISECTWO_REGIONSPACE_BAT 0xa1
32
33 struct acpisectwo_softc {
34 struct device sc_dev;
35 struct acpi_softc *sc_acpi;
36 struct aml_node *sc_node;
37 };
38
39 int acpisectwo_match(struct device *, void *, void *);
40 void acpisectwo_attach(struct device *, struct device *, void *);
41
42 const struct cfattach acpisectwo_ca = {
43 sizeof(struct acpisectwo_softc), acpisectwo_match, acpisectwo_attach
44 };
45
46 struct cfdriver acpisectwo_cd = {
47 NULL, "acpisectwo", DV_DULL
48 };
49
50 int acpisectwo_bat_opreg_handler(void *, int, uint64_t, int, uint64_t *);
51
52 int
acpisectwo_match(struct device * parent,void * match,void * aux)53 acpisectwo_match(struct device *parent, void *match, void *aux)
54 {
55 struct acpi_attach_args *aa = aux;
56 struct cfdata *cf = match;
57
58 if (aa->aaa_name == NULL ||
59 strcmp(aa->aaa_name, cf->cf_driver->cd_name) != 0 ||
60 aa->aaa_table != NULL)
61 return 0;
62
63 return 1;
64 }
65
66 void
acpisectwo_attach(struct device * parent,struct device * self,void * aux)67 acpisectwo_attach(struct device *parent, struct device *self, void *aux)
68 {
69 struct acpisectwo_softc *sc = (struct acpisectwo_softc *)self;
70 struct acpi_attach_args *aa = aux;
71
72 printf("\n");
73
74 sc->sc_node = aa->aaa_node;
75
76 aml_register_regionspace(sc->sc_node, ACPISECTWO_REGIONSPACE_BAT, sc,
77 acpisectwo_bat_opreg_handler);
78 }
79
80 int
acpisectwo_bat_opreg_handler(void * cookie,int iodir,uint64_t address,int size,uint64_t * value)81 acpisectwo_bat_opreg_handler(void *cookie, int iodir, uint64_t address,
82 int size, uint64_t *value)
83 {
84 DPRINTF(("%s: iodir=%d, address=0x%llx, size=%d\n",
85 __func__, iodir, address, size));
86
87 *value = 0;
88
89 return 0;
90 }
91