Date: Fri, 20 Jul 2007 17:22:10 GMT From: Christopher Davis <loafier@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 123811 for review Message-ID: <200707201722.l6KHMA9O001601@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123811 Change 123811 by loafier@chrisdsoc on 2007/07/20 17:21:29 Used bus_alloc_resources, changed write functions. Sound still plays Affected files ... .. //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/solo.c#2 edit Differences ... ==== //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/solo.c#2 (text+ko) ==== @@ -86,9 +86,28 @@ u_int32_t fmt, spd, blksz; }; +enum { + RES_IO, + RES_SB, + RES_VC, + RES_MPU, + RES_GP, + RES_IRQ, + RES_SZ +}; + +static struct resource_spec ess_res_spec[] = { + {SYS_RES_IOPORT, PCIR_BAR(0), RF_ACTIVE}, + {SYS_RES_IOPORT, PCIR_BAR(1), RF_ACTIVE}, + {SYS_RES_IOPORT, PCIR_BAR(2), RF_ACTIVE}, + {SYS_RES_IOPORT, PCIR_BAR(3), RF_ACTIVE}, + {SYS_RES_IOPORT, PCIR_BAR(4), RF_ACTIVE}, + {SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE}, + {-1, 0, 0} +}; + struct ess_info { - struct resource *io, *sb, *vc, *mpu, *gp; /* I/O address for the board */ - struct resource *irq; + struct resource *res[RES_SZ]; void *ih; bus_dma_tag_t parent_dmat; @@ -112,8 +131,9 @@ #define ess_lock_assert(_ess) #endif -static int ess_rd(struct ess_info *sc, int reg); -static void ess_wr(struct ess_info *sc, int reg, u_int8_t val); +#define ess_rd(_sc, _reg) bus_read_1((_sc)->res[RES_SB], _reg) +#define ess_wr(_sc, _reg, _val) bus_write_1((_sc)->res[RES_SB], _reg, _val) + static int ess_dspready(struct ess_info *sc); static int ess_cmd(struct ess_info *sc, u_char val); static int ess_cmd1(struct ess_info *sc, u_char cmd, int val); @@ -147,55 +167,6 @@ */ static int -port_rd(struct resource *port, int regno, int size) -{ - bus_space_tag_t st = rman_get_bustag(port); - bus_space_handle_t sh = rman_get_bushandle(port); - - switch (size) { - case 1: - return bus_space_read_1(st, sh, regno); - case 2: - return bus_space_read_2(st, sh, regno); - case 4: - return bus_space_read_4(st, sh, regno); - default: - return 0xffffffff; - } -} - -static void -port_wr(struct resource *port, int regno, u_int32_t data, int size) -{ - bus_space_tag_t st = rman_get_bustag(port); - bus_space_handle_t sh = rman_get_bushandle(port); - - switch (size) { - case 1: - bus_space_write_1(st, sh, regno, data); - break; - case 2: - bus_space_write_2(st, sh, regno, data); - break; - case 4: - bus_space_write_4(st, sh, regno, data); - break; - } -} - -static int -ess_rd(struct ess_info *sc, int reg) -{ - return port_rd(sc->sb, reg, 1); -} - -static void -ess_wr(struct ess_info *sc, int reg, u_int8_t val) -{ - port_wr(sc->sb, reg, val, 1); -} - -static int ess_dspready(struct ess_info *sc) { return ((ess_rd(sc, SBDSP_STATUS) & 0x80) == 0); @@ -767,17 +738,18 @@ KASSERT(ch == 1 || ch == 2, ("bad ch")); sc->dmasz[ch - 1] = cnt; if (ch == 1) { - port_wr(sc->vc, 0x8, 0xc4, 1); /* command */ - port_wr(sc->vc, 0xd, 0xff, 1); /* reset */ - port_wr(sc->vc, 0xf, 0x01, 1); /* mask */ - port_wr(sc->vc, 0xb, dir == PCMDIR_PLAY? 0x58 : 0x54, 1); /* mode */ - port_wr(sc->vc, 0x0, base, 4); - port_wr(sc->vc, 0x4, cnt - 1, 2); + bus_write_1(sc->res[RES_VC], 0x8, 0xc4); /* command */ + bus_write_1(sc->res[RES_VC], 0xd, 0xff); /* reset */ + bus_write_1(sc->res[RES_VC], 0xf, 0x01); /* mask */ + bus_write_1(sc->res[RES_VC], 0xb, + dir == PCMDIR_PLAY? 0x58 : 0x54); /* mode */ + bus_write_4(sc->res[RES_VC], 0x0, base); + bus_write_2(sc->res[RES_VC], 0x4, cnt - 1); } else if (ch == 2) { - port_wr(sc->io, 0x6, 0x08, 1); /* autoinit */ - port_wr(sc->io, 0x0, base, 4); - port_wr(sc->io, 0x4, cnt, 2); + bus_write_1(sc->res[RES_IO], 0x6, 0x08); /* autoinit */ + bus_write_4(sc->res[RES_IO], 0x0, base); + bus_write_2(sc->res[RES_IO], 0x4, cnt); } return 0; } @@ -804,13 +776,13 @@ if (j > 1) printf("DMA count reg bogus: %04x & %04x\n", i, p); - i = port_rd(sc->vc, 0x4, 2) + 1; - p = port_rd(sc->vc, 0x4, 2) + 1; + i = bus_read_2(sc->res[RES_VC], 0x4) + 1; + p = bus_read_2(sc->res[RES_VC], 0x4) + 1; } while ((p > sc->dmasz[ch - 1] || i < p || (p - i) > 0x8) && j++ < 1000); ess_dmatrigger(sc, ch, 1); } else if (ch == 2) - p = port_rd(sc->io, 0x4, 2); + p = bus_read_2(sc->res[RES_IO], 0x4); return sc->dmasz[ch - 1] - p; } @@ -819,46 +791,24 @@ { KASSERT(ch == 1 || ch == 2, ("bad ch")); if (ch == 1) - port_wr(sc->vc, 0xf, go? 0x00 : 0x01, 1); /* mask */ + bus_write_1(sc->res[RES_VC], 0xf, go? 0x00 : 0x01); /* mask */ else if (ch == 2) - port_wr(sc->io, 0x6, 0x08 | (go? 0x02 : 0x00), 1); /* autoinit */ + bus_write_1(sc->res[RES_IO], 0x6, + 0x08 | (go? 0x02 : 0x00)); /* autoinit */ return 0; } static void ess_release_resources(struct ess_info *sc, device_t dev) { - if (sc->irq) { + if (sc->res[RES_IRQ]) { if (sc->ih) - bus_teardown_intr(dev, sc->irq, sc->ih); - bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq); - sc->irq = 0; + bus_teardown_intr(dev, sc->res[RES_IRQ], sc->ih); + sc->ih = NULL; } - if (sc->io) { - bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(0), sc->io); - sc->io = 0; - } - - if (sc->sb) { - bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(1), sc->sb); - sc->sb = 0; - } - - if (sc->vc) { - bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(2), sc->vc); - sc->vc = 0; - } + + bus_release_resources(dev, ess_res_spec, sc->res); - if (sc->mpu) { - bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(3), sc->mpu); - sc->mpu = 0; - } - - if (sc->gp) { - bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(4), sc->gp); - sc->gp = 0; - } - if (sc->parent_dmat) { bus_dma_tag_destroy(sc->parent_dmat); sc->parent_dmat = 0; @@ -875,40 +825,6 @@ } static int -ess_alloc_resources(struct ess_info *sc, device_t dev) -{ - int rid; - - rid = PCIR_BAR(0); - sc->io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); - - rid = PCIR_BAR(1); - sc->sb = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); - - rid = PCIR_BAR(2); - sc->vc = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); - - rid = PCIR_BAR(3); - sc->mpu = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); - - rid = PCIR_BAR(4); - sc->gp = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); - - rid = 0; - sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, - RF_ACTIVE | RF_SHAREABLE); - -#if ESS18XX_MPSAFE == 1 - sc->lock = snd_mtxcreate(device_get_nameunit(dev), "snd_solo softc"); - - return (sc->irq && sc->io && sc->sb && sc->vc && - sc->mpu && sc->gp && sc->lock)? 0 : ENXIO; -#else - return (sc->irq && sc->io && sc->sb && sc->vc && sc->mpu && sc->gp)? 0 : ENXIO; -#endif -} - -static int ess_probe(device_t dev) { char *s = NULL; @@ -954,7 +870,7 @@ pci_write_config(dev, PCIR_COMMAND, data, 2); data = pci_read_config(dev, PCIR_COMMAND, 2); - ddma = rman_get_start(sc->vc) | 1; + ddma = rman_get_start(sc->res[RES_VC]) | 1; pci_write_config(dev, ESS_PCI_LEGACYCONTROL, 0x805f, 2); pci_write_config(dev, ESS_PCI_DDMACONTROL, ddma, 2); pci_write_config(dev, ESS_PCI_CONFIG, 0, 2); @@ -970,7 +886,7 @@ if (sc->newspeed) ess_setmixer(sc, 0x71, 0x2a); - port_wr(sc->io, 0x7, 0xb0, 1); /* enable irqs */ + bus_write_1(sc->res[RES_IO], 0x7, 0xb0); /* enable irqs */ ess_unlock(sc); return 0; @@ -992,17 +908,23 @@ pci_write_config(dev, PCIR_COMMAND, data, 2); data = pci_read_config(dev, PCIR_COMMAND, 2); - if (ess_alloc_resources(sc, dev)) + if (bus_alloc_resources(dev, ess_res_spec, sc->res) != 0) goto no; +#if ESS18XX_MPSAFE == 1 + sc->lock = snd_mtxcreate(device_get_nameunit(dev), "snd_solo softc"); + if (sc->lock == NULL) + goto no; +#endif + sc->bufsz = pcm_getbuffersize(dev, 4096, SOLO_DEFAULT_BUFSZ, 65536); - ddma = rman_get_start(sc->vc) | 1; + ddma = rman_get_start(sc->res[RES_VC]) | 1; pci_write_config(dev, ESS_PCI_LEGACYCONTROL, 0x805f, 2); pci_write_config(dev, ESS_PCI_DDMACONTROL, ddma, 2); pci_write_config(dev, ESS_PCI_CONFIG, 0, 2); - port_wr(sc->io, 0x7, 0xb0, 1); /* enable irqs */ + bus_write_1(sc->res[RES_IO], 0x7, 0xb0); /* enable irqs */ #ifdef ESS18XX_DUPLEX sc->duplex = 1; #else @@ -1014,7 +936,7 @@ #else sc->newspeed = 0; #endif - if (snd_setup_intr(dev, sc->irq, + if (snd_setup_intr(dev, sc->res[RES_IRQ], #if ESS18XX_MPSAFE == 1 INTR_MPSAFE #else @@ -1058,15 +980,18 @@ goto no; snprintf(status, SND_STATUSLEN, "at io 0x%lx,0x%lx,0x%lx irq %ld %s", - rman_get_start(sc->io), rman_get_start(sc->sb), rman_get_start(sc->vc), - rman_get_start(sc->irq),PCM_KLDSTRING(snd_solo)); + rman_get_start(sc->res[RES_IO]), + rman_get_start(sc->res[RES_SB]), + rman_get_start(sc->res[RES_VC]), + rman_get_start(sc->res[RES_IRQ]), + PCM_KLDSTRING(snd_solo)); if (pcm_register(dev, sc, 1, 1)) goto no; pcm_addchan(dev, PCMDIR_REC, &esschan_class, sc); pcm_addchan(dev, PCMDIR_PLAY, &esschan_class, sc); pcm_setstatus(dev, status); - + return 0; no:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707201722.l6KHMA9O001601>