tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

device_t/softc split: esm and auvia



Hi,

Attached two patches do a device_t/softc split
on esm and auvia drivers.

These are the last two drivers using
CFATTACH_DECL2 and IMO this can go then.
Don't mix it up with CFATTACH_DECL2_NEW.

Christoph
Index: auvia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auvia.c,v
retrieving revision 1.68
diff -u -p -r1.68 auvia.c
--- auvia.c     5 May 2009 21:50:15 -0000       1.68
+++ auvia.c     5 May 2009 22:10:27 -0000
@@ -124,7 +124,7 @@ static int  auvia_waitready_codec(struct 
 static int     auvia_waitvalid_codec(struct auvia_softc *);
 static void    auvia_spdif_event(void *, bool);
 
-CFATTACH_DECL2(auvia, sizeof (struct auvia_softc),
+CFATTACH_DECL2_NEW(auvia, sizeof (struct auvia_softc),
     auvia_match, auvia_attach, auvia_detach, NULL, NULL, auvia_childdet);
 
 /* VIA VT823xx revision number */
@@ -333,6 +333,7 @@ auvia_attach(device_t parent, device_t s
 
        pa = aux;
        sc = device_private(self);
+       sc->sc_dev = self;
        intrstr = NULL;
        pc = pa->pa_pc;
        pt = pa->pa_tag;
@@ -411,7 +412,7 @@ auvia_attach(device_t parent, device_t s
 
        sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, auvia_intr, sc);
        if (sc->sc_ih == NULL) {
-               aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt");
+               aprint_error_dev(sc->sc_dev, "couldn't establish interrupt");
                if (intrstr != NULL)
                        aprint_normal(" at %s", intrstr);
                aprint_normal("\n");
@@ -419,7 +420,7 @@ auvia_attach(device_t parent, device_t s
                return;
        }
 
-       aprint_normal_dev(&sc->sc_dev, "interrupting at %s\n", intrstr);
+       aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
 
        /* disable SBPro compat & others */
        pr = pci_conf_read(pc, pt, AUVIA_PCICONF_JUNK);
@@ -442,7 +443,7 @@ auvia_attach(device_t parent, device_t s
        sc->host_if.spdif_event = auvia_spdif_event;
 
        if ((r = ac97_attach(&sc->host_if, self)) != 0) {
-               aprint_error_dev(&sc->sc_dev, "can't attach codec (error 
0x%X)\n", r);
+               aprint_error_dev(sc->sc_dev, "can't attach codec (error 
0x%X)\n", r);
                pci_intr_disestablish(pc, sc->sc_ih);
                bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
                return;
@@ -470,7 +471,7 @@ auvia_attach(device_t parent, device_t s
                sc->codec_if->vtbl->detach(sc->codec_if);
                pci_intr_disestablish(pc, sc->sc_ih);
                bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
-               aprint_error_dev(&sc->sc_dev, "can't create encodings\n");
+               aprint_error_dev(sc->sc_dev, "can't create encodings\n");
                return;
        }
        if (0 != auconv_create_encodings(auvia_spdif_formats,
@@ -478,14 +479,14 @@ auvia_attach(device_t parent, device_t s
                sc->codec_if->vtbl->detach(sc->codec_if);
                pci_intr_disestablish(pc, sc->sc_ih);
                bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_iosize);
-               aprint_error_dev(&sc->sc_dev, "can't create spdif encodings\n");
+               aprint_error_dev(sc->sc_dev, "can't create spdif encodings\n");
                return;
        }
 
        if (!pmf_device_register(self, NULL, auvia_resume))
                aprint_error_dev(self, "couldn't establish power handler\n");
 
-       audio_attach_mi(&auvia_hw_if, sc, &sc->sc_dev);
+       audio_attach_mi(&auvia_hw_if, sc, sc->sc_dev);
        sc->codec_if->vtbl->unlock(sc->codec_if);
        return;
 }
@@ -523,7 +524,7 @@ auvia_reset_codec(void *addr)
                AUVIA_PCICONF_JUNK) & AUVIA_PCICONF_PRIVALID); i--)
                DELAY(1);
        if (i == 0) {
-               printf("%s: codec reset timed out\n", 
device_xname(&sc->sc_dev));
+               printf("%s: codec reset timed out\n", device_xname(sc->sc_dev));
                return ETIMEDOUT;
        }
        return 0;
@@ -539,7 +540,7 @@ auvia_waitready_codec(struct auvia_softc
                AUVIA_CODEC_CTL) & AUVIA_CODEC_BUSY); i++)
                delay(1);
        if (i >= TIMEOUT) {
-               printf("%s: codec busy\n", device_xname(&sc->sc_dev));
+               printf("%s: codec busy\n", device_xname(sc->sc_dev));
                return 1;
        }
 
@@ -556,7 +557,7 @@ auvia_waitvalid_codec(struct auvia_softc
                AUVIA_CODEC_CTL) & AUVIA_CODEC_PRIVALID); i++)
                        delay(1);
        if (i >= TIMEOUT) {
-               printf("%s: codec invalid\n", device_xname(&sc->sc_dev));
+               printf("%s: codec invalid\n", device_xname(sc->sc_dev));
                return 1;
        }
 
@@ -849,27 +850,27 @@ auvia_malloc(void *addr, int direction, 
        p->size = size;
        if ((error = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0, &p->seg,
                                      1, &rseg, BUS_DMA_NOWAIT)) != 0) {
-               aprint_error_dev(&sc->sc_dev, "unable to allocate DMA, error = 
%d\n", error);
+               aprint_error_dev(sc->sc_dev, "unable to allocate DMA, error = 
%d\n", error);
                goto fail_alloc;
        }
 
        if ((error = bus_dmamem_map(sc->sc_dmat, &p->seg, rseg, size, &p->addr,
                                    BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
-               aprint_error_dev(&sc->sc_dev, "unable to map DMA, error = %d\n",
+               aprint_error_dev(sc->sc_dev, "unable to map DMA, error = %d\n",
                       error);
                goto fail_map;
        }
 
        if ((error = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
                                       BUS_DMA_NOWAIT, &p->map)) != 0) {
-               aprint_error_dev(&sc->sc_dev, "unable to create DMA map, error 
= %d\n",
+               aprint_error_dev(sc->sc_dev, "unable to create DMA map, error = 
%d\n",
                       error);
                goto fail_create;
        }
 
        if ((error = bus_dmamap_load(sc->sc_dmat, p->map, p->addr, size, NULL,
                                     BUS_DMA_NOWAIT)) != 0) {
-               aprint_error_dev(&sc->sc_dev, "unable to load DMA map, error = 
%d\n",
+               aprint_error_dev(sc->sc_dev, "unable to load DMA map, error = 
%d\n",
                       error);
                goto fail_load;
        }
@@ -981,7 +982,7 @@ auvia_build_dma_ops(struct auvia_softc *
                        sizeof(struct auvia_dma_op) * segs, M_DEVBUF, M_WAITOK);
 
                if (ch->sc_dma_ops == NULL) {
-                       aprint_error_dev(&sc->sc_dev, "couldn't build 
dmaops\n");
+                       aprint_error_dev(sc->sc_dev, "couldn't build dmaops\n");
                        return 1;
                }
 
@@ -992,7 +993,7 @@ auvia_build_dma_ops(struct auvia_softc *
 
                if (!dp)
                        panic("%s: build_dma_ops: where'd my memory go??? "
-                               "address (%p)\n", device_xname(&sc->sc_dev),
+                               "address (%p)\n", device_xname(sc->sc_dev),
                                ch->sc_dma_ops);
 
                ch->sc_dma_op_count = segs;
Index: auviavar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/auviavar.h,v
retrieving revision 1.14
diff -u -p -r1.14 auviavar.h
--- auviavar.h  28 Apr 2008 20:23:54 -0000      1.14
+++ auviavar.h  5 May 2009 22:10:27 -0000
@@ -45,7 +45,7 @@ struct auvia_softc_chan {
 };
 
 struct auvia_softc {
-       struct device sc_dev;
+       device_t sc_dev;
 
        char sc_revision[8];
        u_int   sc_flags;
Index: esm.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/esm.c,v
retrieving revision 1.48
diff -u -p -r1.48 esm.c
--- esm.c       5 May 2009 21:47:49 -0000       1.48
+++ esm.c       5 May 2009 21:58:08 -0000
@@ -159,7 +159,7 @@ static int          esm_allocmem(struct esm_soft
                                     struct esm_dma *);
 
 
-CFATTACH_DECL2(esm, sizeof(struct esm_softc),
+CFATTACH_DECL2_NEW(esm, sizeof(struct esm_softc),
     esm_match, esm_attach, esm_detach, NULL, NULL, esm_childdet);
 
 const struct audio_hw_if esm_hw_if = {
@@ -287,7 +287,7 @@ esm_dump_regs(struct esm_softc *ess)
 {
        int i;
 
-       printf("%s registers:", device_xname(&ess->sc_dev));
+       printf("%s registers:", device_xname(ess->sc_dev));
        for (i = 0; i < (sizeof dump_regs / sizeof dump_regs[0]); i++) {
                if (i % 5 == 0)
                        printf("\n");
@@ -336,7 +336,7 @@ esm_read_codec(void *sc, uint8_t regno, 
        }
        if (t == 20)
                printf("%s: esm_read_codec() PROGLESS timed out.\n",
-                   device_xname(&ess->sc_dev));
+                   device_xname(ess->sc_dev));
 
        bus_space_write_1(ess->st, ess->sh, PORT_CODEC_CMD,
            CODEC_CMD_READ | regno);
@@ -352,7 +352,7 @@ esm_read_codec(void *sc, uint8_t regno, 
        if (t == 20)
                /* Timed out, but perform dummy read. */
                printf("%s: esm_read_codec() RW_DONE timed out.\n",
-                   device_xname(&ess->sc_dev));
+                   device_xname(ess->sc_dev));
 
        *result = bus_space_read_2(ess->st, ess->sh, PORT_CODEC_REG);
 
@@ -376,7 +376,7 @@ esm_write_codec(void *sc, uint8_t regno,
        if (t == 20) {
                /* Timed out. Abort writing. */
                printf("%s: esm_write_codec() PROGLESS timed out.\n",
-                   device_xname(&ess->sc_dev));
+                   device_xname(ess->sc_dev));
                return -1;
        }
 
@@ -431,7 +431,7 @@ apu_setindex(struct esm_softc *ess, uint
                bus_space_write_2(ess->st, ess->sh, PORT_DSP_DATA, reg);
        }
        if (t == 1000)
-               printf("%s: apu_setindex() timed out.\n", 
device_xname(&ess->sc_dev));
+               printf("%s: apu_setindex() timed out.\n", 
device_xname(ess->sc_dev));
 }
 
 static inline uint16_t
@@ -461,7 +461,7 @@ wp_wrapu(struct esm_softc *ess, int ch, 
                bus_space_write_2(ess->st, ess->sh, PORT_DSP_DATA, data);
        }
        if (t == 1000)
-               printf("%s: wp_wrapu() timed out.\n", 
device_xname(&ess->sc_dev));
+               printf("%s: wp_wrapu() timed out.\n", 
device_xname(ess->sc_dev));
 }
 
 static inline void
@@ -599,7 +599,7 @@ esm_initcodec(struct esm_softc *ess)
                delay(21);
 
                /* Try cold reset. */
-               printf("%s: will perform cold reset.\n", 
device_xname(&ess->sc_dev));
+               printf("%s: will perform cold reset.\n", 
device_xname(ess->sc_dev));
                data = bus_space_read_2(ess->st, ess->sh, PORT_GPIO_DIR);
                if (pci_conf_read(ess->pc, ess->tag, 0x58) & 1)
                        data |= 0x10;
@@ -697,14 +697,14 @@ esm_init_output (void *sc, void *start, 
        p = &ess->sc_dma;
        if ((char *)start != (char *)p->addr + MAESTRO_PLAYBUF_OFF) {
                printf("%s: esm_init_output: bad addr %p\n",
-                   device_xname(&ess->sc_dev), start);
+                   device_xname(ess->sc_dev), start);
                return EINVAL;
        }
 
        ess->pch.base = DMAADDR(p) + MAESTRO_PLAYBUF_OFF;
 
        DPRINTF(ESM_DEBUG_DMA, ("%s: pch.base = 0x%x\n",
-               device_xname(&ess->sc_dev), ess->pch.base));
+               device_xname(ess->sc_dev), ess->pch.base));
 
        return 0;
 }
@@ -719,7 +719,7 @@ esm_init_input (void *sc, void *start, i
        p = &ess->sc_dma;
        if ((char *)start != (char *)p->addr + MAESTRO_RECBUF_OFF) {
                printf("%s: esm_init_input: bad addr %p\n",
-                   device_xname(&ess->sc_dev), start);
+                   device_xname(ess->sc_dev), start);
                return EINVAL;
        }
 
@@ -733,7 +733,7 @@ esm_init_input (void *sc, void *start, i
        }
 
        DPRINTF(ESM_DEBUG_DMA, ("%s: rch.base = 0x%x\n",
-               device_xname(&ess->sc_dev), ess->rch.base));
+               device_xname(ess->sc_dev), ess->rch.base));
 
        return 0;
 }
@@ -764,7 +764,7 @@ esm_trigger_output(void *sc, void *start
 #ifdef DIAGNOSTIC
        if (ess->pactive) {
                printf("%s: esm_trigger_output: already running",
-                   device_xname(&ess->sc_dev));
+                   device_xname(ess->sc_dev));
                return EINVAL;
        }
 #endif
@@ -774,7 +774,7 @@ esm_trigger_output(void *sc, void *start
        p = &ess->sc_dma;
        if ((char *)start != (char *)p->addr + MAESTRO_PLAYBUF_OFF) {
                printf("%s: esm_trigger_output: bad addr %p\n",
-                   device_xname(&ess->sc_dev), start);
+                   device_xname(ess->sc_dev), start);
                return EINVAL;
        }
 
@@ -880,7 +880,7 @@ esm_trigger_input(void *sc, void *start,
 #ifdef DIAGNOSTIC
        if (ess->ractive) {
                printf("%s: esm_trigger_input: already running",
-                   device_xname(&ess->sc_dev));
+                   device_xname(ess->sc_dev));
                return EINVAL;
        }
 #endif
@@ -890,7 +890,7 @@ esm_trigger_input(void *sc, void *start,
        p = &ess->sc_dma;
        if ((char *)start != (char *)p->addr + MAESTRO_RECBUF_OFF) {
                printf("%s: esm_trigger_input: bad addr %p\n",
-                   device_xname(&ess->sc_dev), start);
+                   device_xname(ess->sc_dev), start);
                return EINVAL;
        }
 
@@ -1602,6 +1602,7 @@ esm_attach(device_t parent, device_t sel
        int error;
 
        ess = device_private(self);
+       ess->sc_dev = self;
        pa = (struct pci_attach_args *)aux;
        pc = pa->pa_pc;
        tag = pa->pa_tag;
@@ -1619,7 +1620,7 @@ esm_attach(device_t parent, device_t sel
        /* Map I/O register */
        if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
            &ess->st, &ess->sh, NULL, &ess->sz)) {
-               aprint_error_dev(&ess->sc_dev, "can't map i/o space\n");
+               aprint_error_dev(ess->sc_dev, "can't map i/o space\n");
                return;
        }
 
@@ -1633,24 +1634,24 @@ esm_attach(device_t parent, device_t sel
 
        DPRINTF(ESM_DEBUG_PCI,
            ("%s: sub-system vendor 0x%4.4x, product 0x%4.4x\n",
-           device_xname(&ess->sc_dev),
+           device_xname(ess->sc_dev),
            PCI_VENDOR(ess->subid), PCI_PRODUCT(ess->subid)));
 
        /* Map and establish the interrupt. */
        if (pci_intr_map(pa, &ih)) {
-               aprint_error_dev(&ess->sc_dev, "can't map interrupt\n");
+               aprint_error_dev(ess->sc_dev, "can't map interrupt\n");
                return;
        }
        intrstr = pci_intr_string(pc, ih);
        ess->ih = pci_intr_establish(pc, ih, IPL_AUDIO, esm_intr, self);
        if (ess->ih == NULL) {
-               aprint_error_dev(&ess->sc_dev, "can't establish interrupt");
+               aprint_error_dev(ess->sc_dev, "can't establish interrupt");
                if (intrstr != NULL)
                        aprint_normal(" at %s", intrstr);
                aprint_normal("\n");
                return;
        }
-       aprint_normal_dev(&ess->sc_dev, "interrupting at %s\n",
+       aprint_normal_dev(ess->sc_dev, "interrupting at %s\n",
            intrstr);
 
        /*
@@ -1660,7 +1661,7 @@ esm_attach(device_t parent, device_t sel
        /* power up chip */
        if ((error = pci_activate(pa->pa_pc, pa->pa_tag, self,
            pci_activate_null)) && error != EOPNOTSUPP) {
-               aprint_error_dev(&ess->sc_dev, "cannot activate %d\n",
+               aprint_error_dev(ess->sc_dev, "cannot activate %d\n",
                    error);
                return;
        }
@@ -1684,7 +1685,7 @@ esm_attach(device_t parent, device_t sel
 
        esm_read_codec(ess, 0, &codec_data);
        if (codec_data == 0x80) {
-               aprint_error_dev(&ess->sc_dev, "PT101 codec detected!\n");
+               aprint_error_dev(ess->sc_dev, "PT101 codec detected!\n");
                return;
        }
 
@@ -1713,7 +1714,7 @@ esm_attach(device_t parent, device_t sel
        /* allocate our DMA region */
        if (esm_allocmem(ess, MAESTRO_DMA_SZ, MAESTRO_DMA_ALIGN,
                &ess->sc_dma)) {
-               aprint_error_dev(&ess->sc_dev, "couldn't allocate memory!\n");
+               aprint_error_dev(ess->sc_dev, "couldn't allocate memory!\n");
                return;
        }
        ess->rings_alloced = 0;
@@ -1723,7 +1724,7 @@ esm_attach(device_t parent, device_t sel
                wc_wrreg(ess, pcmbar,
                    DMAADDR(&ess->sc_dma) >> WAVCACHE_BASEADDR_SHIFT);
 
-       audio_attach_mi(&esm_hw_if, self, &ess->sc_dev);
+       audio_attach_mi(&esm_hw_if, self, ess->sc_dev);
 
        if (!pmf_device_register(self, esm_suspend, esm_resume))
                aprint_error_dev(self, "couldn't establish power handler\n");
@@ -1806,7 +1807,7 @@ esm_resume(device_t dv PMF_FN_ARGS)
 #if 0
        if (mixer_reinit(dev)) {
                printf("%s: unable to reinitialize the mixer\n",
-                   device_xname(&ess->sc_dev));
+                   device_xname(ess->sc_dev));
                return ENXIO;
        }
 #endif
Index: esmvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/esmvar.h,v
retrieving revision 1.16
diff -u -p -r1.16 esmvar.h
--- esmvar.h    23 Feb 2008 02:17:16 -0000      1.16
+++ esmvar.h    5 May 2009 21:58:08 -0000
@@ -150,7 +150,7 @@ struct esm_chinfo {
 };
 
 struct esm_softc {
-       struct device           sc_dev;
+       device_t                sc_dev;
 
        bus_space_tag_t         st;
        bus_space_handle_t      sh;


Home | Main Index | Thread Index | Old Index