summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-05-08 11:18:02 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-05-08 11:18:02 +0000
commit4fccbdcf9c04db88316f1bf61df4c648355a9285 (patch)
tree43be52a91b508a7b9772aba3bcd2565b513263ba
parente21ab7cec767ec1d96181b3a7ed63e65c7dbe058 (diff)
Move parsing of _CRS into acpi(4) and pass the parsed address and interrupt
information in struct acpi_attach_args. ok mpi@
-rw-r--r--sys/dev/acpi/acpi.c132
-rw-r--r--sys/dev/acpi/acpivar.h9
-rw-r--r--sys/dev/acpi/ahci_acpi.c63
-rw-r--r--sys/dev/acpi/ccp_acpi.c43
-rw-r--r--sys/dev/acpi/com_acpi.c61
-rw-r--r--sys/dev/acpi/dwiic_acpi.c71
-rw-r--r--sys/dev/acpi/if_bse_acpi.c57
-rw-r--r--sys/dev/acpi/pluart_acpi.c59
-rw-r--r--sys/dev/acpi/sdhc_acpi.c54
-rw-r--r--sys/dev/acpi/xhci_acpi.c66
10 files changed, 281 insertions, 334 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c
index c3871e007a3..e24222b3170 100644
--- a/sys/dev/acpi/acpi.c
+++ b/sys/dev/acpi/acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpi.c,v 1.382 2020/04/14 20:42:26 kettenis Exp $ */
+/* $OpenBSD: acpi.c,v 1.383 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
@@ -3165,6 +3165,135 @@ acpi_attach_deps(struct acpi_softc *sc, struct aml_node *node)
}
int
+acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
+{
+ struct acpi_attach_args *aaa = arg;
+ int type = AML_CRSTYPE(crs);
+ uint8_t flags;
+
+ switch (type) {
+ case SR_IOPORT:
+ case SR_FIXEDPORT:
+ case LR_MEM24:
+ case LR_MEM32:
+ case LR_MEM32FIXED:
+ case LR_WORD:
+ case LR_DWORD:
+ case LR_QWORD:
+ if (aaa->aaa_naddr >= nitems(aaa->aaa_addr))
+ return 0;
+ break;
+ case SR_IRQ:
+ case LR_EXTIRQ:
+ if (aaa->aaa_nirq >= nitems(aaa->aaa_irq))
+ return 0;
+ }
+
+ switch (type) {
+ case SR_IOPORT:
+ case SR_FIXEDPORT:
+ aaa->aaa_bst[aaa->aaa_naddr] = aaa->aaa_iot;
+ break;
+ case LR_MEM24:
+ case LR_MEM32:
+ case LR_MEM32FIXED:
+ aaa->aaa_bst[aaa->aaa_naddr] = aaa->aaa_memt;
+ break;
+ case LR_WORD:
+ case LR_DWORD:
+ case LR_QWORD:
+ switch (crs->lr_word.type) {
+ case LR_TYPE_MEMORY:
+ aaa->aaa_bst[aaa->aaa_naddr] = aaa->aaa_memt;
+ break;
+ case LR_TYPE_IO:
+ aaa->aaa_bst[aaa->aaa_naddr] = aaa->aaa_iot;
+ break;
+ default:
+ /* Bus number range or something else; skip. */
+ return 0;
+ }
+ }
+
+ switch (type) {
+ case SR_IOPORT:
+ aaa->aaa_addr[aaa->aaa_naddr] = crs->sr_ioport._min;
+ aaa->aaa_size[aaa->aaa_naddr] = crs->sr_ioport._len;
+ aaa->aaa_naddr++;
+ break;
+ case SR_FIXEDPORT:
+ aaa->aaa_addr[aaa->aaa_naddr] = crs->sr_fioport._bas;
+ aaa->aaa_size[aaa->aaa_naddr] = crs->sr_fioport._len;
+ aaa->aaa_naddr++;
+ break;
+ case LR_MEM24:
+ aaa->aaa_addr[aaa->aaa_naddr] = crs->lr_m24._min;
+ aaa->aaa_size[aaa->aaa_naddr] = crs->lr_m24._len;
+ aaa->aaa_naddr++;
+ break;
+ case LR_MEM32:
+ aaa->aaa_addr[aaa->aaa_naddr] = crs->lr_m32._min;
+ aaa->aaa_size[aaa->aaa_naddr] = crs->lr_m32._len;
+ aaa->aaa_naddr++;
+ break;
+ case LR_MEM32FIXED:
+ aaa->aaa_addr[aaa->aaa_naddr] = crs->lr_m32fixed._bas;
+ aaa->aaa_size[aaa->aaa_naddr] = crs->lr_m32fixed._len;
+ aaa->aaa_naddr++;
+ break;
+ case LR_WORD:
+ aaa->aaa_addr[aaa->aaa_naddr] = crs->lr_word._min;
+ aaa->aaa_size[aaa->aaa_naddr] = crs->lr_word._len;
+ aaa->aaa_naddr++;
+ break;
+ case LR_DWORD:
+ aaa->aaa_addr[aaa->aaa_naddr] = crs->lr_dword._min;
+ aaa->aaa_size[aaa->aaa_naddr] = crs->lr_dword._len;
+ aaa->aaa_naddr++;
+ break;
+ case LR_QWORD:
+ aaa->aaa_addr[aaa->aaa_naddr] = crs->lr_qword._min;
+ aaa->aaa_size[aaa->aaa_naddr] = crs->lr_qword._len;
+ aaa->aaa_naddr++;
+ break;
+ case SR_IRQ:
+ aaa->aaa_irq[aaa->aaa_nirq] = ffs(crs->sr_irq.irq_mask) - 1;
+ /* Default is exclusive, active-high, edge triggered. */
+ if (AML_CRSLEN(crs) < 3)
+ flags = SR_IRQ_MODE;
+ else
+ flags = crs->sr_irq.irq_flags;
+ /* Map flags to those of the extended interrupt descriptor. */
+ if (flags & SR_IRQ_SHR)
+ aaa->aaa_irq_flags[aaa->aaa_nirq] |= LR_EXTIRQ_SHR;
+ if (flags & SR_IRQ_POLARITY)
+ aaa->aaa_irq_flags[aaa->aaa_nirq] |= LR_EXTIRQ_POLARITY;
+ if (flags & SR_IRQ_MODE)
+ aaa->aaa_irq_flags[aaa->aaa_nirq] |= LR_EXTIRQ_MODE;
+ aaa->aaa_nirq++;
+ break;
+ case LR_EXTIRQ:
+ aaa->aaa_irq[aaa->aaa_nirq] = crs->lr_extirq.irq[0];
+ aaa->aaa_irq_flags[aaa->aaa_nirq] = crs->lr_extirq.flags;
+ aaa->aaa_nirq++;
+ break;
+ }
+
+ return 0;
+}
+
+void
+acpi_parse_crs(struct acpi_softc *sc, struct acpi_attach_args *aaa)
+{
+ struct aml_value res;
+
+ if (aml_evalname(sc, aaa->aaa_node, "_CRS", 0, NULL, &res))
+ return;
+
+ aml_parse_resource(&res, acpi_parse_resources, aaa);
+}
+
+int
acpi_foundhid(struct aml_node *node, void *arg)
{
struct acpi_softc *sc = (struct acpi_softc *)arg;
@@ -3197,6 +3326,7 @@ acpi_foundhid(struct aml_node *node, void *arg)
aaa.aaa_node = node->parent;
aaa.aaa_dev = dev;
aaa.aaa_cdev = cdev;
+ acpi_parse_crs(sc, &aaa);
#ifndef SMALL_KERNEL
if (!strcmp(cdev, ACPI_DEV_MOUSE)) {
diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h
index b80105a50f5..6fac33f00ed 100644
--- a/sys/dev/acpi/acpivar.h
+++ b/sys/dev/acpi/acpivar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpivar.h,v 1.107 2020/04/14 20:42:26 kettenis Exp $ */
+/* $OpenBSD: acpivar.h,v 1.108 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
*
@@ -64,6 +64,13 @@ struct acpi_attach_args {
struct aml_node *aaa_node;
const char *aaa_dev;
const char *aaa_cdev;
+ uint64_t aaa_addr[4];
+ uint64_t aaa_size[4];
+ bus_space_tag_t aaa_bst[4];
+ int aaa_naddr;
+ uint32_t aaa_irq[4];
+ uint32_t aaa_irq_flags[4];
+ int aaa_nirq;
};
struct acpi_mem_map {
diff --git a/sys/dev/acpi/ahci_acpi.c b/sys/dev/acpi/ahci_acpi.c
index 07438337e10..294214207b9 100644
--- a/sys/dev/acpi/ahci_acpi.c
+++ b/sys/dev/acpi/ahci_acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ahci_acpi.c,v 1.2 2018/08/03 22:18:13 kettenis Exp $ */
+/* $OpenBSD: ahci_acpi.c,v 1.3 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2018 Mark Kettenis
*
@@ -33,13 +33,7 @@ struct ahci_acpi_softc {
struct ahci_softc sc;
struct acpi_softc *sc_acpi;
struct aml_node *sc_node;
-
- bus_addr_t sc_addr;
- bus_size_t sc_size;
-
- int sc_irq;
- int sc_irq_flags;
- void *sc_ih;
+ void *sc_ih;
};
int ahci_acpi_match(struct device *, void *, void *);
@@ -49,8 +43,6 @@ struct cfattach ahci_acpi_ca = {
sizeof(struct ahci_acpi_softc), ahci_acpi_match, ahci_acpi_attach
};
-int ahci_acpi_parse_resources(int, union acpi_resource *, void *);
-
int
ahci_acpi_match(struct device *parent, void *match, void *aux)
{
@@ -63,40 +55,38 @@ ahci_acpi_match(struct device *parent, void *match, void *aux)
void
ahci_acpi_attach(struct device *parent, struct device *self, void *aux)
{
- struct acpi_attach_args *aaa = aux;
struct ahci_acpi_softc *sc = (struct ahci_acpi_softc *)self;
- struct aml_value res;
+ struct acpi_attach_args *aaa = aux;
sc->sc_acpi = (struct acpi_softc *)parent;
sc->sc_node = aaa->aaa_node;
printf(" %s", sc->sc_node->name);
- if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
- printf(": can't find registers\n");
+ if (aaa->aaa_naddr < 1) {
+ printf(": no registers\n");
return;
}
- aml_parse_resource(&res, ahci_acpi_parse_resources, sc);
- printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
- if (sc->sc_addr == 0 || sc->sc_size == 0) {
- printf("\n");
+ if (aaa->aaa_nirq < 1) {
+ printf(": no interrupt\n");
return;
}
- printf(" irq %d", sc->sc_irq);
+ printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
+ printf(" irq %d", aaa->aaa_irq[0]);
- sc->sc.sc_iot = aaa->aaa_memt;
- sc->sc.sc_ios = sc->sc_size;
+ sc->sc.sc_iot = aaa->aaa_bst[0];
+ sc->sc.sc_ios = aaa->aaa_size[0];
sc->sc.sc_dmat = aaa->aaa_dmat;
- if (bus_space_map(sc->sc.sc_iot, sc->sc_addr, sc->sc_size, 0,
- &sc->sc.sc_ioh)) {
+ if (bus_space_map(sc->sc.sc_iot, aaa->aaa_addr[0], aaa->aaa_size[0],
+ 0, &sc->sc.sc_ioh)) {
printf(": can't map registers\n");
return;
}
- sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_BIO,
- ahci_intr, sc, sc->sc.sc_dev.dv_xname);
+ sc->sc_ih = acpi_intr_establish(aaa->aaa_irq[0], aaa->aaa_irq_flags[0],
+ IPL_BIO, ahci_intr, sc, sc->sc.sc_dev.dv_xname);
if (sc->sc_ih == NULL) {
printf(": can't establish interrupt\n");
return;
@@ -114,26 +104,3 @@ ahci_acpi_attach(struct device *parent, struct device *self, void *aux)
irq:
return;
}
-
-int
-ahci_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
-{
- struct ahci_acpi_softc *sc = arg;
- int type = AML_CRSTYPE(crs);
-
- switch (type) {
- case LR_MEM32FIXED:
- /* AHCI registers are specified by the first resource. */
- if (sc->sc_size == 0) {
- sc->sc_addr = crs->lr_m32fixed._bas;
- sc->sc_size = crs->lr_m32fixed._len;
- }
- break;
- case LR_EXTIRQ:
- sc->sc_irq = crs->lr_extirq.irq[0];
- sc->sc_irq_flags = crs->lr_extirq.flags;
- break;
- }
-
- return 0;
-}
diff --git a/sys/dev/acpi/ccp_acpi.c b/sys/dev/acpi/ccp_acpi.c
index 0b550173d89..e720cd87697 100644
--- a/sys/dev/acpi/ccp_acpi.c
+++ b/sys/dev/acpi/ccp_acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ccp_acpi.c,v 1.1 2019/04/23 18:34:06 kettenis Exp $ */
+/* $OpenBSD: ccp_acpi.c,v 1.2 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2019 Mark Kettenis
*
@@ -30,9 +30,6 @@ struct ccp_acpi_softc {
struct ccp_softc sc;
struct acpi_softc *sc_acpi;
struct aml_node *sc_node;
-
- bus_addr_t sc_addr;
- bus_size_t sc_size;
};
int ccp_acpi_match(struct device *, void *, void *);
@@ -47,8 +44,6 @@ const char *ccp_hids[] = {
NULL
};
-int ccp_acpi_parse_resources(int, union acpi_resource *, void *);
-
int
ccp_acpi_match(struct device *parent, void *match, void *aux)
{
@@ -61,48 +56,26 @@ ccp_acpi_match(struct device *parent, void *match, void *aux)
void
ccp_acpi_attach(struct device *parent, struct device *self, void *aux)
{
- struct acpi_attach_args *aaa = aux;
struct ccp_acpi_softc *sc = (struct ccp_acpi_softc *)self;
- struct aml_value res;
+ struct acpi_attach_args *aaa = aux;
sc->sc_acpi = (struct acpi_softc *)parent;
sc->sc_node = aaa->aaa_node;
printf(" %s", sc->sc_node->name);
- if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
- printf(": can't find registers\n");
+ if (aaa->aaa_naddr < 1) {
+ printf(": no registers\n");
return;
}
- aml_parse_resource(&res, ccp_acpi_parse_resources, sc);
- printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
- if (sc->sc_addr == 0 || sc->sc_size == 0) {
- printf("\n");
- return;
- }
+ printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
- sc->sc.sc_iot = aaa->aaa_memt;
- if (bus_space_map(sc->sc.sc_iot, sc->sc_addr, sc->sc_size, 0,
- &sc->sc.sc_ioh)) {
+ sc->sc.sc_iot = aaa->aaa_bst[0];
+ if (bus_space_map(sc->sc.sc_iot, aaa->aaa_addr[0], aaa->aaa_size[0],
+ 0, &sc->sc.sc_ioh)) {
printf(": can't map registers\n");
return;
}
ccp_attach(&sc->sc);
}
-
-int
-ccp_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
-{
- struct ccp_acpi_softc *sc = arg;
- int type = AML_CRSTYPE(crs);
-
- switch (type) {
- case LR_MEM32FIXED:
- sc->sc_addr = crs->lr_m32fixed._bas;
- sc->sc_size = crs->lr_m32fixed._len;
- break;
- }
-
- return 0;
-}
diff --git a/sys/dev/acpi/com_acpi.c b/sys/dev/acpi/com_acpi.c
index 4e0f1df6686..852be6c71b3 100644
--- a/sys/dev/acpi/com_acpi.c
+++ b/sys/dev/acpi/com_acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: com_acpi.c,v 1.1 2018/07/01 10:29:30 kettenis Exp $ */
+/* $OpenBSD: com_acpi.c,v 1.2 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2018 Mark Kettenis
*
@@ -37,13 +37,7 @@ struct com_acpi_softc {
struct com_softc sc;
struct acpi_softc *sc_acpi;
struct aml_node *sc_node;
-
- bus_addr_t sc_addr;
- bus_size_t sc_size;
-
- int sc_irq;
- int sc_irq_flags;
- void *sc_ih;
+ void *sc_ih;
};
int com_acpi_match(struct device *, void *, void *);
@@ -58,7 +52,6 @@ const char *com_hids[] = {
NULL
};
-int com_acpi_parse_resources(int, union acpi_resource *, void *);
int com_acpi_is_console(struct com_acpi_softc *);
int com_acpi_intr_designware(void *);
@@ -74,33 +67,31 @@ com_acpi_match(struct device *parent, void *match, void *aux)
void
com_acpi_attach(struct device *parent, struct device *self, void *aux)
{
- struct acpi_attach_args *aaa = aux;
struct com_acpi_softc *sc = (struct com_acpi_softc *)self;
- struct aml_value res;
+ struct acpi_attach_args *aaa = aux;
uint32_t freq;
sc->sc_acpi = (struct acpi_softc *)parent;
sc->sc_node = aaa->aaa_node;
printf(" %s", sc->sc_node->name);
- if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
- printf(": can't find registers\n");
+ if (aaa->aaa_naddr < 1) {
+ printf(": no registers\n");
return;
}
- aml_parse_resource(&res, com_acpi_parse_resources, sc);
- printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
- if (sc->sc_addr == 0 || sc->sc_size == 0) {
- printf("\n");
+ if (aaa->aaa_nirq < 1) {
+ printf(": no interrupt\n");
return;
}
- printf(" irq %d", sc->sc_irq);
+ printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
+ printf(" irq %d", aaa->aaa_irq[0]);
freq = acpi_getpropint(sc->sc_node, "clock-frequency", 0);
- sc->sc.sc_iot = aaa->aaa_memt;
- sc->sc.sc_iobase = sc->sc_addr;
+ sc->sc.sc_iot = aaa->aaa_bst[0];
+ sc->sc.sc_iobase = aaa->aaa_addr[0];
sc->sc.sc_uarttype = COM_UART_16550;
sc->sc.sc_frequency = freq ? freq : COM_FREQ;
@@ -114,14 +105,14 @@ com_acpi_attach(struct device *parent, struct device *self, void *aux)
comconsrate = B115200;
}
- if (bus_space_map(sc->sc.sc_iot, sc->sc_addr, sc->sc_size, 0,
- &sc->sc.sc_ioh)) {
+ if (bus_space_map(sc->sc.sc_iot, aaa->aaa_addr[0], aaa->aaa_size[0],
+ 0, &sc->sc.sc_ioh)) {
printf(": can't map registers\n");
return;
}
- sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_TTY,
- com_acpi_intr_designware, sc, sc->sc.sc_dev.dv_xname);
+ sc->sc_ih = acpi_intr_establish(aaa->aaa_irq[0], aaa->aaa_irq_flags[0],
+ IPL_TTY, com_acpi_intr_designware, sc, sc->sc.sc_dev.dv_xname);
if (sc->sc_ih == NULL) {
printf(": can't establish interrupt\n");
return;
@@ -131,26 +122,6 @@ com_acpi_attach(struct device *parent, struct device *self, void *aux)
}
int
-com_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
-{
- struct com_acpi_softc *sc = arg;
- int type = AML_CRSTYPE(crs);
-
- switch (type) {
- case LR_MEM32FIXED:
- sc->sc_addr = crs->lr_m32fixed._bas;
- sc->sc_size = crs->lr_m32fixed._len;
- break;
- case LR_EXTIRQ:
- sc->sc_irq = crs->lr_extirq.irq[0];
- sc->sc_irq_flags = crs->lr_extirq.flags;
- break;
- }
-
- return 0;
-}
-
-int
com_acpi_is_console(struct com_acpi_softc *sc)
{
struct acpi_table_header *hdr;
@@ -165,7 +136,7 @@ com_acpi_is_console(struct com_acpi_softc *sc)
spcr = entry->q_table;
base = &spcr->base_address;
if (base->address_space_id == GAS_SYSTEM_MEMORY &&
- base->address == sc->sc_addr)
+ base->address == sc->sc.sc_iobase)
return 1;
}
}
diff --git a/sys/dev/acpi/dwiic_acpi.c b/sys/dev/acpi/dwiic_acpi.c
index 928cc588e7c..2211a16abc9 100644
--- a/sys/dev/acpi/dwiic_acpi.c
+++ b/sys/dev/acpi/dwiic_acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dwiic_acpi.c,v 1.13 2020/02/18 12:13:39 mpi Exp $ */
+/* $OpenBSD: dwiic_acpi.c,v 1.14 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Synopsys DesignWare I2C controller
*
@@ -32,9 +32,6 @@
struct dwiic_crs {
int irq_int;
uint8_t irq_flags;
- uint32_t addr_min;
- uint32_t addr_bas;
- uint32_t addr_len;
uint16_t i2c_addr;
struct aml_node *devnode;
struct aml_node *gpio_int_node;
@@ -100,16 +97,21 @@ void
dwiic_acpi_attach(struct device *parent, struct device *self, void *aux)
{
struct dwiic_softc *sc = (struct dwiic_softc *)self;
- struct acpi_attach_args *aa = aux;
+ struct acpi_attach_args *aaa = aux;
struct aml_value res;
struct dwiic_crs crs;
sc->sc_acpi = (struct acpi_softc *)parent;
- sc->sc_devnode = aa->aaa_node;
- memcpy(&sc->sc_hid, aa->aaa_dev, sizeof(sc->sc_hid));
+ sc->sc_devnode = aaa->aaa_node;
+ memcpy(&sc->sc_hid, aaa->aaa_dev, sizeof(sc->sc_hid));
printf(" %s", sc->sc_devnode->name);
+ if (aaa->aaa_naddr < 1) {
+ printf(": no registers\n");
+ return;
+ }
+
if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_CRS", 0, NULL, &res)) {
printf(", no _CRS method\n");
return;
@@ -125,17 +127,12 @@ dwiic_acpi_attach(struct device *parent, struct device *self, void *aux)
aml_parse_resource(&res, dwiic_acpi_parse_crs, &crs);
aml_freevalue(&res);
- if (crs.addr_bas == 0) {
- printf(", can't find address\n");
- return;
- }
-
- printf(" addr 0x%x/0x%x", crs.addr_bas, crs.addr_len);
+ printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
- sc->sc_iot = aa->aaa_memt;
- if (bus_space_map(sc->sc_iot, crs.addr_bas, crs.addr_len, 0,
- &sc->sc_ioh)) {
- printf(", failed mapping at 0x%x\n", crs.addr_bas);
+ sc->sc_iot = aaa->aaa_bst[0];
+ if (bus_space_map(sc->sc_iot, aaa->aaa_addr[0], aaa->aaa_size[0],
+ 0, &sc->sc_ioh)) {
+ printf(": can't map registers\n");
return;
}
@@ -149,7 +146,7 @@ dwiic_acpi_attach(struct device *parent, struct device *self, void *aux)
if (dwiic_init(sc)) {
printf(", failed initializing\n");
- bus_space_unmap(sc->sc_iot, sc->sc_ioh, crs.addr_len);
+ bus_space_unmap(sc->sc_iot, sc->sc_ioh, aaa->aaa_size[0]);
return;
}
@@ -159,13 +156,13 @@ dwiic_acpi_attach(struct device *parent, struct device *self, void *aux)
dwiic_read(sc, DW_IC_CLR_INTR);
/* try to register interrupt with apic, but not fatal without it */
- if (crs.irq_int > 0) {
- printf(" irq %d", crs.irq_int);
+ if (aaa->aaa_nirq > 0) {
+ printf(" irq %d", aaa->aaa_irq[0]);
- sc->sc_ih = acpi_intr_establish(crs.irq_int, crs.irq_flags,
+ sc->sc_ih = acpi_intr_establish(aaa->aaa_irq[0], aaa->aaa_irq_flags[0],
IPL_BIO, dwiic_intr, sc, sc->sc_dev.dv_xname);
if (sc->sc_ih == NULL)
- printf(", can't establish interrupt");
+ printf(": can't establish interrupt");
}
printf("\n");
@@ -192,8 +189,6 @@ dwiic_acpi_attach(struct device *parent, struct device *self, void *aux)
sc->sc_devnode->i2c = &sc->sc_i2c_tag;
acpi_register_gsb(sc->sc_acpi, sc->sc_devnode);
#endif
-
- return;
}
int
@@ -202,11 +197,23 @@ dwiic_acpi_parse_crs(int crsidx, union acpi_resource *crs, void *arg)
struct dwiic_crs *sc_crs = arg;
struct aml_node *node;
uint16_t pin;
+ uint8_t flags;
switch (AML_CRSTYPE(crs)) {
case SR_IRQ:
sc_crs->irq_int = ffs(letoh16(crs->sr_irq.irq_mask)) - 1;
- sc_crs->irq_flags = crs->sr_irq.irq_flags;
+ /* Default is exclusive, active-high, edge triggered. */
+ if (AML_CRSLEN(crs) < 3)
+ flags = SR_IRQ_MODE;
+ else
+ flags = crs->sr_irq.irq_flags;
+ /* Map flags to those of the extended interrupt descriptor. */
+ if (flags & SR_IRQ_SHR)
+ sc_crs->irq_flags |= LR_EXTIRQ_SHR;
+ if (flags & SR_IRQ_POLARITY)
+ sc_crs->irq_flags |= LR_EXTIRQ_POLARITY;
+ if (flags & SR_IRQ_MODE)
+ sc_crs->irq_flags |= LR_EXTIRQ_MODE;
break;
case LR_EXTIRQ:
@@ -225,21 +232,15 @@ dwiic_acpi_parse_crs(int crsidx, union acpi_resource *crs, void *arg)
}
break;
- case LR_MEM32:
- sc_crs->addr_min = letoh32(crs->lr_m32._min);
- sc_crs->addr_len = letoh32(crs->lr_m32._len);
- break;
-
- case LR_MEM32FIXED:
- sc_crs->addr_bas = letoh32(crs->lr_m32fixed._bas);
- sc_crs->addr_len = letoh32(crs->lr_m32fixed._len);
- break;
-
case LR_SERBUS:
if (crs->lr_serbus.type == LR_SERBUS_I2C)
sc_crs->i2c_addr = letoh16(crs->lr_i2cbus._adr);
break;
+ case LR_MEM32:
+ case LR_MEM32FIXED:
+ break;
+
default:
DPRINTF(("%s: unknown resource type %d\n", __func__,
AML_CRSTYPE(crs)));
diff --git a/sys/dev/acpi/if_bse_acpi.c b/sys/dev/acpi/if_bse_acpi.c
index 1920bc9c7dd..b5b95370b64 100644
--- a/sys/dev/acpi/if_bse_acpi.c
+++ b/sys/dev/acpi/if_bse_acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bse_acpi.c,v 1.2 2020/04/18 10:03:32 kettenis Exp $ */
+/* $OpenBSD: if_bse_acpi.c,v 1.3 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2020 Mark Kettenis
*
@@ -40,12 +40,6 @@ struct bse_acpi_softc {
struct genet_softc sc;
struct acpi_softc *sc_acpi;
struct aml_node *sc_node;
-
- bus_addr_t sc_addr;
- bus_size_t sc_size;
-
- int sc_irq;
- int sc_irq_flags;
};
int bse_acpi_match(struct device *, void *, void *);
@@ -60,8 +54,6 @@ const char *bse_hids[] = {
NULL
};
-int bse_acpi_parse_resources(int, union acpi_resource *, void *);
-
int
bse_acpi_match(struct device *parent, void *match, void *aux)
{
@@ -76,7 +68,6 @@ bse_acpi_attach(struct device *parent, struct device *self, void *aux)
{
struct bse_acpi_softc *sc = (struct bse_acpi_softc *)self;
struct acpi_attach_args *aaa = aux;
- struct aml_value res;
char phy_mode[16] = { 0 };
int error;
@@ -84,31 +75,31 @@ bse_acpi_attach(struct device *parent, struct device *self, void *aux)
sc->sc_node = aaa->aaa_node;
printf(" %s", sc->sc_node->name);
- if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
- printf(": can't find registers\n");
+ if (aaa->aaa_naddr < 1) {
+ printf(": no registers\n");
return;
}
- aml_parse_resource(&res, bse_acpi_parse_resources, sc);
- printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
- if (sc->sc_addr == 0 || sc->sc_size == 0) {
- printf("\n");
+ if (aaa->aaa_nirq < 1) {
+ printf(": no interrupt\n");
return;
}
- printf(" irq %d", sc->sc_irq);
+ printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
+ printf(" irq %d", aaa->aaa_irq[0]);
- sc->sc.sc_bst = aaa->aaa_memt;
+ sc->sc.sc_bst = aaa->aaa_bst[0];
sc->sc.sc_dmat = aaa->aaa_dmat;
- if (bus_space_map(sc->sc.sc_bst, sc->sc_addr, sc->sc_size, 0,
- &sc->sc.sc_bsh)) {
+ if (bus_space_map(sc->sc.sc_bst, aaa->aaa_addr[0], aaa->aaa_size[0],
+ 0, &sc->sc.sc_bsh)) {
printf(": can't map registers\n");
return;
}
- sc->sc.sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags,
- IPL_NET, genet_intr, sc, sc->sc.sc_dev.dv_xname);
+ sc->sc.sc_ih = acpi_intr_establish(aaa->aaa_irq[0],
+ aaa->aaa_irq_flags[0], IPL_NET, genet_intr,
+ sc, sc->sc.sc_dev.dv_xname);
if (sc->sc.sc_ih == NULL) {
printf(": can't establish interrupt\n");
goto unmap;
@@ -142,25 +133,5 @@ disestablish:
acpi_intr_disestablish(sc->sc.sc_ih);
#endif
unmap:
- bus_space_unmap(sc->sc.sc_bst, sc->sc.sc_bsh, sc->sc_size);
-}
-
-int
-bse_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
-{
- struct bse_acpi_softc *sc = arg;
- int type = AML_CRSTYPE(crs);
-
- switch (type) {
- case LR_MEM32FIXED:
- sc->sc_addr = crs->lr_m32fixed._bas;
- sc->sc_size = crs->lr_m32fixed._len;
- break;
- case LR_EXTIRQ:
- sc->sc_irq = crs->lr_extirq.irq[0];
- sc->sc_irq_flags = crs->lr_extirq.flags;
- break;
- }
-
- return 0;
+ bus_space_unmap(sc->sc.sc_bst, sc->sc.sc_bsh, aaa->aaa_size[0]);
}
diff --git a/sys/dev/acpi/pluart_acpi.c b/sys/dev/acpi/pluart_acpi.c
index 7b622668284..4c531187407 100644
--- a/sys/dev/acpi/pluart_acpi.c
+++ b/sys/dev/acpi/pluart_acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pluart_acpi.c,v 1.3 2018/08/25 09:39:20 kettenis Exp $ */
+/* $OpenBSD: pluart_acpi.c,v 1.4 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2018 Mark Kettenis
*
@@ -34,13 +34,8 @@ struct pluart_acpi_softc {
struct pluart_softc sc;
struct acpi_softc *sc_acpi;
struct aml_node *sc_node;
-
- bus_addr_t sc_addr;
- bus_size_t sc_size;
-
- int sc_irq;
- int sc_irq_flags;
- void *sc_ih;
+ bus_addr_t sc_addr;
+ void *sc_ih;
};
int pluart_acpi_match(struct device *, void *, void *);
@@ -55,7 +50,6 @@ const char *pluart_hids[] = {
NULL
};
-int pluart_acpi_parse_resources(int, union acpi_resource *, void *);
int pluart_acpi_is_console(struct pluart_acpi_softc *);
int
@@ -70,37 +64,36 @@ pluart_acpi_match(struct device *parent, void *match, void *aux)
void
pluart_acpi_attach(struct device *parent, struct device *self, void *aux)
{
- struct acpi_attach_args *aaa = aux;
struct pluart_acpi_softc *sc = (struct pluart_acpi_softc *)self;
- struct aml_value res;
+ struct acpi_attach_args *aaa = aux;
sc->sc_acpi = (struct acpi_softc *)parent;
sc->sc_node = aaa->aaa_node;
printf(" %s", sc->sc_node->name);
- if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
- printf(": can't find registers\n");
+ if (aaa->aaa_naddr < 1) {
+ printf(": no registers\n");
return;
}
- aml_parse_resource(&res, pluart_acpi_parse_resources, sc);
- printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
- if (sc->sc_addr == 0 || sc->sc_size == 0) {
- printf("\n");
+ if (aaa->aaa_nirq < 1) {
+ printf(": no interrupt\n");
return;
}
- printf(" irq %d", sc->sc_irq);
+ printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
+ printf(" irq %d", aaa->aaa_irq[0]);
- sc->sc.sc_iot = aaa->aaa_memt;
- if (bus_space_map(sc->sc.sc_iot, sc->sc_addr, sc->sc_size, 0,
- &sc->sc.sc_ioh)) {
+ sc->sc.sc_iot = aaa->aaa_bst[0];
+ sc->sc_addr = aaa->aaa_addr[0];
+ if (bus_space_map(sc->sc.sc_iot, aaa->aaa_addr[0], aaa->aaa_size[0],
+ 0, &sc->sc.sc_ioh)) {
printf(": can't map registers\n");
return;
}
- sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_TTY,
- pluart_intr, sc, sc->sc.sc_dev.dv_xname);
+ sc->sc_ih = acpi_intr_establish(aaa->aaa_irq[0], aaa->aaa_irq_flags[0],
+ IPL_TTY, pluart_intr, sc, sc->sc.sc_dev.dv_xname);
if (sc->sc_ih == NULL) {
printf(": can't establish interrupt\n");
return;
@@ -110,26 +103,6 @@ pluart_acpi_attach(struct device *parent, struct device *self, void *aux)
}
int
-pluart_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
-{
- struct pluart_acpi_softc *sc = arg;
- int type = AML_CRSTYPE(crs);
-
- switch (type) {
- case LR_MEM32FIXED:
- sc->sc_addr = crs->lr_m32fixed._bas;
- sc->sc_size = crs->lr_m32fixed._len;
- break;
- case LR_EXTIRQ:
- sc->sc_irq = crs->lr_extirq.irq[0];
- sc->sc_irq_flags = crs->lr_extirq.flags;
- break;
- }
-
- return 0;
-}
-
-int
pluart_acpi_is_console(struct pluart_acpi_softc *sc)
{
struct acpi_table_header *hdr;
diff --git a/sys/dev/acpi/sdhc_acpi.c b/sys/dev/acpi/sdhc_acpi.c
index 8e21b1d7538..3b4c827b9bd 100644
--- a/sys/dev/acpi/sdhc_acpi.c
+++ b/sys/dev/acpi/sdhc_acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdhc_acpi.c,v 1.14 2019/04/02 07:08:39 stsp Exp $ */
+/* $OpenBSD: sdhc_acpi.c,v 1.15 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2016 Mark Kettenis
*
@@ -36,11 +36,6 @@ struct sdhc_acpi_softc {
bus_space_tag_t sc_memt;
bus_space_handle_t sc_memh;
- bus_addr_t sc_addr;
- bus_size_t sc_size;
-
- int sc_irq;
- int sc_irq_flags;
void *sc_ih;
struct aml_node *sc_gpio_int_node;
@@ -86,39 +81,45 @@ sdhc_acpi_match(struct device *parent, void *match, void *aux)
void
sdhc_acpi_attach(struct device *parent, struct device *self, void *aux)
{
- struct acpi_attach_args *aaa = aux;
struct sdhc_acpi_softc *sc = (struct sdhc_acpi_softc *)self;
+ struct acpi_attach_args *aaa = aux;
struct aml_value res;
sc->sc_acpi = (struct acpi_softc *)parent;
sc->sc_node = aaa->aaa_node;
printf(" %s", sc->sc_node->name);
- if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
- printf(", can't find registers\n");
+ if (aaa->aaa_naddr < 1) {
+ printf(": no registers\n");
return;
}
- aml_parse_resource(&res, sdhc_acpi_parse_resources, sc);
- printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
- if (sc->sc_addr == 0 || sc->sc_size == 0) {
- printf("\n");
+ if (aaa->aaa_nirq < 1) {
+ printf(": no interrupt\n");
return;
}
- printf(" irq %d", sc->sc_irq);
+ if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
+ printf(": can't find registers\n");
+ return;
+ }
+
+ aml_parse_resource(&res, sdhc_acpi_parse_resources, sc);
- sc->sc_memt = aaa->aaa_memt;
- if (bus_space_map(sc->sc_memt, sc->sc_addr, sc->sc_size, 0,
- &sc->sc_memh)) {
- printf(", can't map registers\n");
+ printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
+ printf(" irq %d", aaa->aaa_irq[0]);
+
+ sc->sc_memt = aaa->aaa_bst[0];
+ if (bus_space_map(sc->sc_memt, aaa->aaa_addr[0], aaa->aaa_size[0],
+ 0, &sc->sc_memh)) {
+ printf(": can't map registers\n");
return;
}
- sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_BIO,
- sdhc_intr, sc, sc->sc.sc_dev.dv_xname);
+ sc->sc_ih = acpi_intr_establish(aaa->aaa_irq[0], aaa->aaa_irq_flags[0],
+ IPL_BIO, sdhc_intr, sc, sc->sc.sc_dev.dv_xname);
if (sc->sc_ih == NULL) {
- printf(", can't establish interrupt\n");
+ printf(": can't establish interrupt\n");
return;
}
@@ -141,7 +142,8 @@ sdhc_acpi_attach(struct device *parent, struct device *self, void *aux)
sc->sc.sc_host = &sc->sc_host;
sc->sc.sc_dmat = aaa->aaa_dmat;
- sdhc_host_found(&sc->sc, sc->sc_memt, sc->sc_memh, sc->sc_size, 1, 0);
+ sdhc_host_found(&sc->sc, sc->sc_memt, sc->sc_memh,
+ aaa->aaa_size[0], 1, 0);
}
int
@@ -153,14 +155,6 @@ sdhc_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
uint16_t pin;
switch (type) {
- case LR_MEM32FIXED:
- sc->sc_addr = crs->lr_m32fixed._bas;
- sc->sc_size = crs->lr_m32fixed._len;
- break;
- case LR_EXTIRQ:
- sc->sc_irq = crs->lr_extirq.irq[0];
- sc->sc_irq_flags = crs->lr_extirq.flags;
- break;
case LR_GPIO:
node = aml_searchname(sc->sc_node, (char *)&crs->pad[crs->lr_gpio.res_off]);
pin = *(uint16_t *)&crs->pad[crs->lr_gpio.pin_off];
diff --git a/sys/dev/acpi/xhci_acpi.c b/sys/dev/acpi/xhci_acpi.c
index b2a32eb0f77..95e69cee896 100644
--- a/sys/dev/acpi/xhci_acpi.c
+++ b/sys/dev/acpi/xhci_acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xhci_acpi.c,v 1.2 2020/04/10 21:25:00 kettenis Exp $ */
+/* $OpenBSD: xhci_acpi.c,v 1.3 2020/05/08 11:18:01 kettenis Exp $ */
/*
* Copyright (c) 2018 Mark Kettenis
*
@@ -40,12 +40,6 @@ struct xhci_acpi_softc {
struct xhci_softc sc;
struct acpi_softc *sc_acpi;
struct aml_node *sc_node;
-
- bus_addr_t sc_addr;
- bus_size_t sc_size;
-
- int sc_irq;
- int sc_irq_flags;
void *sc_ih;
};
@@ -61,8 +55,6 @@ const char *xhci_hids[] = {
NULL
};
-int xhci_acpi_parse_resources(int, union acpi_resource *, void *);
-
int
xhci_acpi_match(struct device *parent, void *match, void *aux)
{
@@ -77,39 +69,37 @@ xhci_acpi_attach(struct device *parent, struct device *self, void *aux)
{
struct xhci_acpi_softc *sc = (struct xhci_acpi_softc *)self;
struct acpi_attach_args *aaa = aux;
- struct aml_value res;
int error;
sc->sc_acpi = (struct acpi_softc *)parent;
sc->sc_node = aaa->aaa_node;
printf(" %s", sc->sc_node->name);
- if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
- printf(": can't find registers\n");
+ if (aaa->aaa_naddr < 1) {
+ printf(": no registers\n");
return;
}
- aml_parse_resource(&res, xhci_acpi_parse_resources, sc);
- printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
- if (sc->sc_addr == 0 || sc->sc_size == 0) {
- printf("\n");
+ if (aaa->aaa_nirq < 1) {
+ printf(": no interrupt\n");
return;
}
- printf(" irq %d", sc->sc_irq);
+ printf(" addr 0x%llx/0x%llx", aaa->aaa_addr[0], aaa->aaa_size[0]);
+ printf(" irq %d", aaa->aaa_irq[0]);
- sc->sc.iot = aaa->aaa_memt;
- sc->sc.sc_size = sc->sc_size;
+ sc->sc.iot = aaa->aaa_bst[0];
+ sc->sc.sc_size = aaa->aaa_size[0];
sc->sc.sc_bus.dmatag = aaa->aaa_dmat;
- if (bus_space_map(sc->sc.iot, sc->sc_addr, sc->sc_size, 0,
- &sc->sc.ioh)) {
+ if (bus_space_map(sc->sc.iot, aaa->aaa_addr[0], aaa->aaa_size[0],
+ 0, &sc->sc.ioh)) {
printf(": can't map registers\n");
return;
}
- sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_USB,
- xhci_intr, sc, sc->sc.sc_bus.bdev.dv_xname);
+ sc->sc_ih = acpi_intr_establish(aaa->aaa_irq[0], aaa->aaa_irq_flags[0],
+ IPL_USB, xhci_intr, sc, sc->sc.sc_bus.bdev.dv_xname);
if (sc->sc_ih == NULL) {
printf(": can't establish interrupt\n");
goto unmap;
@@ -138,33 +128,3 @@ unmap:
bus_space_unmap(sc->sc.iot, sc->sc.ioh, sc->sc.sc_size);
return;
}
-
-int
-xhci_acpi_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
-{
- struct xhci_acpi_softc *sc = arg;
- int type = AML_CRSTYPE(crs);
-
- switch (type) {
- case LR_MEM32FIXED:
- /* XHCI registers are specified by the first resource. */
- if (sc->sc_size == 0) {
- sc->sc_addr = crs->lr_m32fixed._bas;
- sc->sc_size = crs->lr_m32fixed._len;
- }
- break;
- case LR_QWORD:
- /* XHCI registers are specified by the first resource. */
- if (sc->sc_size == 0) {
- sc->sc_addr = crs->lr_qword._min;
- sc->sc_size = crs->lr_qword._len;
- }
- break;
- case LR_EXTIRQ:
- sc->sc_irq = crs->lr_extirq.irq[0];
- sc->sc_irq_flags = crs->lr_extirq.flags;
- break;
- }
-
- return 0;
-}