summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMarco Peereboom <marco@cvs.openbsd.org>2005-12-13 07:23:35 +0000
committerMarco Peereboom <marco@cvs.openbsd.org>2005-12-13 07:23:35 +0000
commite0e23b5e5a2b68d53cf4ecb4099b19a486c15304 (patch)
tree6d4dfc65d0769fd63ab0d923b079eed20c5a8d9e /sys
parentbac153c498d4994172804db4df813e354b69ba1e (diff)
Add glue to attach devices to apci.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/acpi/acpi.c132
-rw-r--r--sys/dev/acpi/acpivar.h11
-rw-r--r--sys/dev/acpi/amltypes.h8
-rw-r--r--sys/dev/acpi/dsdt.c40
-rw-r--r--sys/dev/acpi/files.acpi7
5 files changed, 144 insertions, 54 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c
index bd97a0a6d18..a61ec24789d 100644
--- a/sys/dev/acpi/acpi.c
+++ b/sys/dev/acpi/acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpi.c,v 1.3 2005/12/07 03:44:36 marco Exp $ */
+/* $OpenBSD: acpi.c,v 1.4 2005/12/13 07:23:33 marco Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
*
@@ -28,6 +28,12 @@
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
+#include <dev/acpi/amltypes.h>
+#include <dev/acpi/dsdt.h>
+
+#ifdef ACPI_DEBUG
+int acpi_debug = 3;
+#endif
int acpimatch(struct device *, void *, void *);
void acpiattach(struct device *, struct device *, void *);
@@ -39,10 +45,14 @@ void acpi_load_dsdt(paddr_t, struct acpi_q **);
void acpi_softintr(void *);
void acpi_filtdetach(struct knote *);
int acpi_filtread(struct knote *, long);
+void acpi_foundhid(struct aml_node *, void *);
#define ACPI_LOCK(sc)
#define ACPI_UNLOCK(sc)
+/* XXX move this into dsdt softc at some point */
+extern struct aml_node aml_root;
+
struct filterops acpiread_filtops = {
1, NULL, acpi_filtdetach, acpi_filtread
};
@@ -58,6 +68,82 @@ struct cfdriver acpi_cd = {
int acpi_evindex;
struct acpi_softc *acpi_softc;
+#if 0
+void
+acpi_read_pm1_status(struct acpi_softc *sc, uint32_t *status_a, uint32_t *status_b)
+{
+ *status_a = bus_space_read_2(sc->sc_iot, sc->sc_ioh_pm1a_evt, ACPI_PM1_STATUS);
+ *status_b = 0;
+}
+void
+acpi_write_pm1_status(struct acpi_softc *sc, uint32_t status_a, uint32_t status_b)
+{
+ bus_space_write_2(sc->sc_iot, sc->sc_ioh_pm1a_evt, ACPI_PM1_STATUS, status_a);
+}
+void
+acpi_read_pm1_enable(struct acpi_softc *sc, uint32_t *enable_a, uint32_t *enable_b)
+{
+ *status_a = bus_space_read_2(sc->sc_iot, sc->sc_ioh_pm1a_evt, ACPI_PM1_STATUS);
+ *status_b = 0;
+}
+void
+acpi_write_pm1_enable(struct acpi_softc *sc, uint32_t enable_a, uint32_t enable_b)
+{
+ bus_space_write_2(sc->sc_iot, sc->sc_ioh_pm1a_evt, ACPI_PM1_STATUS, status_a);
+}
+
+void
+acpi_read_gpe_status(struct acpi_softc *sc, uint32_t *status_0, uint32_t *status_1)
+{
+}
+void
+acpi_write_gpe_status(struct acpi_softc *sc, uint32_t status_0, uint32_t status_1)
+{
+}
+void
+acpi_read_gpe_enable(struct acpi_softc *sc, uint32_t *enable_0, uint32_t *enable_1)
+{
+}
+void
+acpi_write_gpe_enable(struct acpi_softc *sc, uint32_t enable_0, uint32_t enable_1)
+{
+}
+#endif
+
+void
+acpi_foundhid(struct aml_node *node, void *arg)
+{
+ struct acpi_softc *sc = (struct acpi_softc *)arg;
+ struct device *self = (struct device *)arg;
+ const char *dev;
+
+ dnprintf(1, "found hid device: %s ", node->parent->name);
+ switch(node->child->value.type) {
+ case AML_OBJTYPE_STRING:
+ dev = node->child->value.v_string;
+ break;
+ case AML_OBJTYPE_INTEGER:
+ dev = aml_eisaid(node->child->value.v_integer);
+ break;
+ default:
+ dev = "unknown";
+ break;
+ }
+ dnprintf(1, " device: %s\n", dev);
+
+ if (!strcmp(dev, ACPI_DEV_CMB))
+ {
+ struct acpi_attach_args aaa;
+
+ memset(&aaa, 0, sizeof(aaa));
+ aaa.aaa_name = "acpibat";
+ aaa.aaa_iot = sc->sc_iot;
+ aaa.aaa_memt = sc->sc_memt;
+ config_found(self, &aaa, acpi_print);
+ }
+
+}
+
int
acpimatch(struct device *parent, void *match, void *aux)
{
@@ -193,11 +279,18 @@ acpiattach(struct device *parent, struct device *self, void *aux)
if (sc->sc_interrupt) {
int16_t flags;
+#if 0
+ acpi_read_pm1_enable(sc, &ena, &enb);
+ ena |= (ACPI_PM1_PWRBTN_EN|ACPI_PM1_SLPBTN_EN);
+ enb |= (ACPI_PM1_PWRBTN_EN|ACPI_PM1_SLPBTN_EN);
+ acpi_write_pm1_enable(sc, ena, enb);
+#else
flags = bus_space_read_2(sc->sc_iot, sc->sc_ioh_pm1a_evt,
sc->sc_fadt->pm1_evt_len / 2);
flags |= ACPI_PM1_PWRBTN_EN | ACPI_PM1_SLPBTN_EN;
bus_space_write_2(sc->sc_iot, sc->sc_ioh_pm1a_evt,
sc->sc_fadt->pm1_evt_len / 2, flags);
+#endif
}
printf("attached\n");
@@ -239,6 +332,9 @@ acpiattach(struct device *parent, struct device *self, void *aux)
acpi_softc = sc;
+ /* attach devices found in dsdt */
+ aml_find_node(aml_root.child, "_HID", acpi_foundhid, sc);
+
return;
fail:
@@ -259,9 +355,11 @@ acpi_submatch(struct device *parent, void *match, void *aux)
int
acpi_print(void *aux, const char *pnp)
{
+ /* XXX ACPIVERBOSE should be replaced with dnprintf */
struct acpi_attach_args *aa = aux;
#ifdef ACPIVERBOSE
- struct acpi_table_header *hdr = (struct acpi_table_header *)aa->aaa_table;
+ struct acpi_table_header *hdr =
+ (struct acpi_table_header *)aa->aaa_table;
#endif
if (pnp) {
@@ -312,7 +410,8 @@ acpi_loadtables(struct acpi_softc *sc, struct acpi_rsdp *rsdp)
for (i = 0; i < ntables; i++) {
acpi_map(xsdt->table_offsets[i], sizeof(*hdr), &handle);
hdr = (struct acpi_table_header *)handle.va;
- acpi_load_table(xsdt->table_offsets[i], hdr->length, &sc->sc_tables);
+ acpi_load_table(xsdt->table_offsets[i], hdr->length,
+ &sc->sc_tables);
acpi_unmap(&handle);
}
acpi_unmap(&hrsdt);
@@ -333,12 +432,13 @@ acpi_loadtables(struct acpi_softc *sc, struct acpi_rsdp *rsdp)
rsdt = (struct acpi_rsdt *)hrsdt.va;
ntables = (len - sizeof(struct acpi_table_header)) /
- sizeof(rsdt->table_offsets[0]);
+ sizeof(rsdt->table_offsets[0]);
for (i = 0; i < ntables; i++) {
acpi_map(rsdt->table_offsets[i], sizeof(*hdr), &handle);
hdr = (struct acpi_table_header *)handle.va;
- acpi_load_table(rsdt->table_offsets[i], hdr->length, &sc->sc_tables);
+ acpi_load_table(rsdt->table_offsets[i], hdr->length,
+ &sc->sc_tables);
acpi_unmap(&handle);
}
acpi_unmap(&hrsdt);
@@ -400,11 +500,17 @@ acpi_interrupt(void *arg)
struct acpi_softc *sc = (struct acpi_softc *)arg;
u_int16_t flags;
- flags = bus_space_read_2(sc->sc_iot, sc->sc_ioh_pm1a_evt, ACPI_PM1_STATUS);
+#if 0
+ acpi_read_pm1_status(sc, &sts_a, &sts_b);
+ if ((sts_a & ACPI_PM1_PWRBTN_STS) && (sts_b & ACPI_PM1_PWRBTN_STS) {
+ acpi_write_pm1_status(sc,
+#else
+ flags = bus_space_read_2(sc->sc_iot, sc->sc_ioh_pm1a_evt,
+ ACPI_PM1_STATUS);
if (flags & (ACPI_PM1_PWRBTN_STS | ACPI_PM1_SLPBTN_STS)) {
if (flags & ACPI_PM1_PWRBTN_STS) {
bus_space_write_2(sc->sc_iot, sc->sc_ioh_pm1a_evt,
- ACPI_PM1_STATUS, ACPI_PM1_PWRBTN_STS);
+ ACPI_PM1_STATUS, ACPI_PM1_PWRBTN_STS);
/*
* Power-button has been pressed, do something!
*/
@@ -412,7 +518,7 @@ acpi_interrupt(void *arg)
}
if (flags & ACPI_PM1_SLPBTN_STS) {
bus_space_write_2(sc->sc_iot, sc->sc_ioh_pm1a_evt,
- ACPI_PM1_STATUS, ACPI_PM1_SLPBTN_STS);
+ ACPI_PM1_STATUS, ACPI_PM1_SLPBTN_STS);
/*
* Sleep-button has been pressed, do something!
*/
@@ -426,6 +532,7 @@ acpi_interrupt(void *arg)
#endif
return (1);
}
+#endif
return (0);
}
@@ -437,12 +544,14 @@ acpi_softintr(void *arg)
if (sc->sc_powerbtn) {
sc->sc_powerbtn = 0;
acpi_evindex++;
- KNOTE(sc->sc_note, ACPI_EVENT_COMPOSE(ACPI_EV_PWRBTN, acpi_evindex));
+ KNOTE(sc->sc_note, ACPI_EVENT_COMPOSE(ACPI_EV_PWRBTN,
+ acpi_evindex));
}
if (sc->sc_sleepbtn) {
sc->sc_sleepbtn = 0;
acpi_evindex++;
- KNOTE(sc->sc_note, ACPI_EVENT_COMPOSE(ACPI_EV_SLPBTN, acpi_evindex));
+ KNOTE(sc->sc_note, ACPI_EVENT_COMPOSE(ACPI_EV_SLPBTN,
+ acpi_evindex));
}
}
@@ -533,7 +642,8 @@ acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
} else if (hdr->length > table->size)
error = ENOSPC;
else
- error = copyout(hdr, table->table, hdr->length);
+ error = copyout(hdr,
+ table->table, hdr->length);
break;
}
}
diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h
index c60bd52c6dc..284f371b8df 100644
--- a/sys/dev/acpi/acpivar.h
+++ b/sys/dev/acpi/acpivar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpivar.h,v 1.3 2005/07/10 19:39:01 grange Exp $ */
+/* $OpenBSD: acpivar.h,v 1.4 2005/12/13 07:23:34 marco Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
*
@@ -20,6 +20,15 @@
#include <sys/timeout.h>
+/* #define ACPI_DEBUG */
+#ifdef ACPI_DEBUG
+#define dprintf(x...) do { if (acpi_debug) printf(x); } while(0)
+#define dnprintf(n,x...) do { if (acpi_debug > (n)) printf(x); } while(0)
+#else
+#define dprintf(x...)
+#define dnprintf(n,x...)
+#endif
+
struct klist;
struct acpi_attach_args {
diff --git a/sys/dev/acpi/amltypes.h b/sys/dev/acpi/amltypes.h
index 22e6b6c387b..098a649f9d8 100644
--- a/sys/dev/acpi/amltypes.h
+++ b/sys/dev/acpi/amltypes.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: amltypes.h,v 1.6 2005/12/13 04:16:56 jordan Exp $ */
+/* $OpenBSD: amltypes.h,v 1.7 2005/12/13 07:23:34 marco Exp $ */
/*
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
*
@@ -15,8 +15,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __AMLPARSE_H__
-#define __AMLPARSE_H__
+#ifndef __DEV_ACPI_AMLTYPES_H__
+#define __DEV_ACPI_AMLTYPES_H__
/* AML Opcodes */
#define AMLOP_ZERO 0x00
@@ -280,4 +280,4 @@ struct aml_node
struct aml_value value;
};
-#endif /* __AMLPARSE_H__ */
+#endif /* __DEV_ACPI_AMLTYPES_H__ */
diff --git a/sys/dev/acpi/dsdt.c b/sys/dev/acpi/dsdt.c
index d2b8d9f18c8..a60621e2b46 100644
--- a/sys/dev/acpi/dsdt.c
+++ b/sys/dev/acpi/dsdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dsdt.c,v 1.8 2005/12/13 04:16:56 jordan Exp $ */
+/* $OpenBSD: dsdt.c,v 1.9 2005/12/13 07:23:34 marco Exp $ */
/*
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
*
@@ -25,6 +25,7 @@
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
#include <dev/acpi/amltypes.h>
+#include <dev/acpi/dsdt.h>
struct dsdt_softc {
struct device sc_dev;
@@ -45,14 +46,7 @@ struct cfdriver dsdt_cd = {
NULL, "dsdt", DV_DULL
};
-#ifdef AML_DEBUG
-int amldebug=3;
-#define dprintf(x...) do { if (amldebug) printf(x); } while(0)
-#define dnprintf(n,x...) do { if (amldebug > (n)) printf(x); } while(0)
-#else
-#define dprintf(x...)
-#define dnprintf(n,x...)
-#endif
+extern int acpi_debug;
int
dsdtmatch(struct device *parent, void *match, void *aux)
@@ -115,9 +109,6 @@ int aml_msb(u_int32_t val);
void aml_addchildnode(struct aml_node *, struct aml_node *);
void aml_walktree(struct aml_node *, int);
void aml_walkroot(void);
-int aml_find_node(struct aml_node *, const char *,
- void (*)(struct aml_node *, void *),
- void *);
int64_t aml_evalmath(u_int16_t, int64_t, int64_t);
int aml_testlogical(u_int16_t, long, long);
@@ -1369,9 +1360,6 @@ aml_find_node(struct aml_node *node, const char *name,
return (0);
}
-void foundhid(struct aml_node *, void *);
-const char *aml_eisaid(u_int32_t pid);
-
const char hext[] = "0123456789ABCDEF";
const char *
@@ -1391,26 +1379,6 @@ aml_eisaid(u_int32_t pid)
return id;
}
-void
-foundhid(struct aml_node *node, void *arg)
-{
- const char *dev;
-
- printf("found hid device: %s ", node->parent->name);
- switch(node->child->value.type) {
- case AML_OBJTYPE_STRING:
- dev = node->child->value.v_string;
- break;
- case AML_OBJTYPE_INTEGER:
- dev = aml_eisaid(node->child->value.v_integer);
- break;
- default:
- dev = "unknown";
- break;
- }
- printf(" device: %s\n", dev);
-}
-
int
dsdt_parse_aml(struct dsdt_softc *sc, u_int8_t *start, u_int32_t length)
{
@@ -1421,7 +1389,5 @@ dsdt_parse_aml(struct dsdt_softc *sc, u_int8_t *start, u_int32_t length)
}
printf(" : parsed %d AML bytes\n", length);
- /* aml_find_node(aml_root.child, "_HID", foundhid, NULL); */
-
return (0);
}
diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi
index 91a4eff4b95..83c953b7b06 100644
--- a/sys/dev/acpi/files.acpi
+++ b/sys/dev/acpi/files.acpi
@@ -1,4 +1,4 @@
-# $OpenBSD: files.acpi,v 1.3 2005/12/07 04:25:38 jordan Exp $
+# $OpenBSD: files.acpi,v 1.4 2005/12/13 07:23:34 marco Exp $
#
# Config file and device description for machine-independent ACPI code.
# Included by ports that need it.
@@ -14,6 +14,11 @@ device acpitimer
attach acpitimer at acpi
file dev/acpi/acpitimer.c acpitimer
+# generic device
+device acpibat
+attach acpibat at acpi
+file dev/acpi/acpibat.c acpibat
+
# High Precision Event Timer
device hpet
attach hpet at acpi