amdgpio(4): acpi_attach_args resources

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

amdgpio(4): acpi_attach_args resources

James Hastings
correction, s/aaa_memt/aaa_bst[0]/

> stop parsing _CRS and use resources from struct acpi_attach_args.

Index: dev/acpi/amdgpio.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/amdgpio.c,v
retrieving revision 1.2
diff -u -p -r1.2 amdgpio.c
--- dev/acpi/amdgpio.c 26 Jan 2020 00:11:42 -0000 1.2
+++ dev/acpi/amdgpio.c 22 May 2020 05:22:11 -0000
@@ -55,11 +55,7 @@ struct amdgpio_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;
 
  int sc_npins;
@@ -85,7 +81,6 @@ const char *amdgpio_hids[] = {
  NULL
 };
 
-int amdgpio_parse_resources(int, union acpi_resource *, void *);
 int amdgpio_read_pin(void *, int);
 void amdgpio_write_pin(void *, int, int);
 void amdgpio_intr_establish(void *, int, int, int (*)(), void *);
@@ -106,13 +101,22 @@ amdgpio_attach(struct device *parent, st
 {
  struct acpi_attach_args *aaa = aux;
  struct amdgpio_softc *sc = (struct amdgpio_softc *)self;
- struct aml_value res;
  int64_t uid;
 
  sc->sc_acpi = (struct acpi_softc *)parent;
  sc->sc_node = aaa->aaa_node;
  printf(": %s", sc->sc_node->name);
 
+ if (aaa->aaa_naddr < 1) {
+ printf(", no registers\n");
+ return;
+ }
+
+ if (aaa->aaa_nirq < 1) {
+ printf(", no interrupt\n");
+ return;
+ }
+
  if (aml_evalinteger(sc->sc_acpi, sc->sc_node, "_UID", 0, NULL, &uid)) {
  printf(", can't find uid\n");
  return;
@@ -129,19 +133,6 @@ amdgpio_attach(struct device *parent, st
  return;
  }
 
- if (aml_evalname(sc->sc_acpi, sc->sc_node, "_CRS", 0, NULL, &res)) {
- printf(", can't find registers\n");
- return;
- }
-
- aml_parse_resource(&res, amdgpio_parse_resources, sc);
- aml_freevalue(&res);
- printf(" addr 0x%lx/0x%lx", sc->sc_addr, sc->sc_size);
- if (sc->sc_addr == 0 || sc->sc_size == 0) {
- printf("\n");
- return;
- }
-
  sc->sc_pin_ih = mallocarray(sc->sc_npins, sizeof(*sc->sc_pin_ih),
     M_DEVBUF, M_NOWAIT | M_ZERO);
  if (sc->sc_pin_ih == NULL) {
@@ -149,17 +140,18 @@ amdgpio_attach(struct device *parent, st
  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_memt = aaa->aaa_memt;
- if (bus_space_map(sc->sc_memt, sc->sc_addr, sc->sc_size, 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");
  goto free;
  }
 
- sc->sc_ih = acpi_intr_establish(sc->sc_irq, sc->sc_irq_flags, IPL_BIO,
-    amdgpio_intr, sc, sc->sc_dev.dv_xname);
+ sc->sc_ih = acpi_intr_establish(aaa->aaa_irq[0], aaa->aaa_irq_flags[0],
+    IPL_BIO, amdgpio_intr, sc, sc->sc_dev.dv_xname);
  if (sc->sc_ih == NULL) {
  printf(", can't establish interrupt\n");
  goto unmap;
@@ -177,32 +169,9 @@ amdgpio_attach(struct device *parent, st
  return;
 
 unmap:
- bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_size);
+ bus_space_unmap(sc->sc_memt, sc->sc_memh, aaa->aaa_size[0]);
 free:
  free(sc->sc_pin_ih, M_DEVBUF, sc->sc_npins * sizeof(*sc->sc_pin_ih));
-}
-
-int
-amdgpio_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
-{
- struct amdgpio_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;
- default:
- printf(" type 0x%x\n", type);
- break;
- }
-
- return 0;
 }
 
 int