Date: Sat, 28 Jul 2007 15:47:53 GMT From: Christopher Davis <loafier@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 124267 for review Message-ID: <200707281547.l6SFlrmm040691@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124267 Change 124267 by loafier@chrisdsoc on 2007/07/28 15:47:18 Edit for bus_alloc_resources(), etc Affected files ... .. //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/via82c686.c#2 edit Differences ... ==== //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/via82c686.c#2 (text+ko) ==== @@ -68,16 +68,25 @@ int base, count, mode, ctrl; }; +enum { + RES_MEM, + RES_IRQ, + RES_SZ +}; + +static struct resource_spec via_res_spec[] = { + {SYS_RES_IOPORT, PCIR_BAR(0), RF_ACTIVE}, + {SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE}, + {-1, 0, 0} +}; + struct via_info { - bus_space_tag_t st; - bus_space_handle_t sh; bus_dma_tag_t parent_dmat; bus_dma_tag_t sgd_dmat; bus_dmamap_t sgd_dmamap; bus_addr_t sgd_addr; - struct resource *reg, *irq; - int regid, irqid; + struct resource *res[RES_SZ]; void *ih; struct ac97_info *codec; @@ -99,40 +108,13 @@ static struct pcmchan_caps via_vracaps = {4000, 48000, via_fmt, 0}; static struct pcmchan_caps via_caps = {48000, 48000, via_fmt, 0}; -static __inline u_int32_t -via_rd(struct via_info *via, int regno, int size) -{ - - switch (size) { - case 1: - return bus_space_read_1(via->st, via->sh, regno); - case 2: - return bus_space_read_2(via->st, via->sh, regno); - case 4: - return bus_space_read_4(via->st, via->sh, regno); - default: - return 0xFFFFFFFF; - } -} +#define via_rd1(_sc, _reg) bus_read_1((_sc)->res[RES_MEM], _reg) +#define via_rd2(_sc, _reg) bus_read_2((_sc)->res[RES_MEM], _reg) +#define via_rd4(_sc, _reg) bus_read_4((_sc)->res[RES_MEM], _reg) +#define via_wr1(_sc, _reg, _val) bus_write_1((_sc)->res[RES_MEM], _reg, _val) +#define via_wr2(_sc, _reg, _val) bus_write_2((_sc)->res[RES_MEM], _reg, _val) +#define via_wr4(_sc, _reg, _val) bus_write_4((_sc)->res[RES_MEM], _reg, _val) - -static __inline void -via_wr(struct via_info *via, int regno, u_int32_t data, int size) -{ - - switch (size) { - case 1: - bus_space_write_1(via->st, via->sh, regno, data); - break; - case 2: - bus_space_write_2(via->st, via->sh, regno, data); - break; - case 4: - bus_space_write_4(via->st, via->sh, regno, data); - break; - } -} - /* -------------------------------------------------------------------- */ /* Codec interface */ @@ -143,7 +125,7 @@ /* poll until codec not busy */ for (i = 0; (i < TIMEOUT) && - (via_rd(via, VIA_CODEC_CTL, 4) & VIA_CODEC_BUSY); i++) + (via_rd4(via, VIA_CODEC_CTL) & VIA_CODEC_BUSY); i++) DELAY(1); if (i >= TIMEOUT) { printf("via: codec busy\n"); @@ -161,7 +143,7 @@ /* poll until codec valid */ for (i = 0; (i < TIMEOUT) && - !(via_rd(via, VIA_CODEC_CTL, 4) & VIA_CODEC_PRIVALID); i++) + !(via_rd4(via, VIA_CODEC_CTL) & VIA_CODEC_PRIVALID); i++) DELAY(1); if (i >= TIMEOUT) { printf("via: codec invalid\n"); @@ -179,7 +161,7 @@ if (via_waitready_codec(via)) return -1; - via_wr(via, VIA_CODEC_CTL, VIA_CODEC_PRIVALID | VIA_CODEC_INDEX(reg) | val, 4); + via_wr4(via, VIA_CODEC_CTL, VIA_CODEC_PRIVALID | VIA_CODEC_INDEX(reg) | val); return 0; } @@ -193,7 +175,8 @@ if (via_waitready_codec(via)) return -1; - via_wr(via, VIA_CODEC_CTL, VIA_CODEC_PRIVALID | VIA_CODEC_READ | VIA_CODEC_INDEX(reg),4); + via_wr4(via, VIA_CODEC_CTL, + VIA_CODEC_PRIVALID | VIA_CODEC_READ | VIA_CODEC_INDEX(reg)); if (via_waitready_codec(via)) return -1; @@ -201,7 +184,7 @@ if (via_waitvalid_codec(via)) return -1; - return via_rd(via, VIA_CODEC_CTL, 2); + return via_rd2(via, VIA_CODEC_CTL); } static kobj_method_t via_ac97_methods[] = { @@ -291,10 +274,10 @@ DEB(printf("set format: dir = %d, format=%x\n", ch->dir, format)); snd_mtxlock(via->lock); - mode = via_rd(via, ch->mode, 1); + mode = via_rd1(via, ch->mode); mode &= ~(VIA_RPMODE_16BIT | VIA_RPMODE_STEREO); mode |= mode_set; - via_wr(via, ch->mode, mode, 1); + via_wr1(via, ch->mode, mode); snd_mtxunlock(via->lock); return 0; @@ -351,10 +334,10 @@ snd_mtxlock(via->lock); if (go == PCMTRIG_START) { via_buildsgdt(ch); - via_wr(via, ch->base, sgd_addr, 4); - via_wr(via, ch->ctrl, VIA_RPCTRL_START, 1); + via_wr4(via, ch->base, sgd_addr); + via_wr1(via, ch->ctrl, VIA_RPCTRL_START); } else - via_wr(via, ch->ctrl, VIA_RPCTRL_TERMINATE, 1); + via_wr1(via, ch->ctrl, VIA_RPCTRL_TERMINATE); snd_mtxunlock(via->lock); DEB(printf("viachan_trigger: go=%d\n", go)); @@ -372,11 +355,11 @@ ado = ch->sgd_table; snd_mtxlock(via->lock); - base1 = via_rd(via, ch->base, 4); - len = via_rd(via, ch->count, 4); - base = via_rd(via, ch->base, 4); + base1 = via_rd4(via, ch->base); + len = via_rd4(via, ch->count); + base = via_rd4(via, ch->base); if (base != base1) /* Avoid race hazard */ - len = via_rd(via, ch->count, 4); + len = via_rd4(via, ch->count); snd_mtxunlock(via->lock); DEB(printf("viachan_getptr: len / base = %x / %x\n", len, base)); @@ -431,16 +414,16 @@ /* DEB(printf("viachan_intr\n")); */ /* Read channel */ snd_mtxlock(via->lock); - if (via_rd(via, VIA_PLAY_STAT, 1) & VIA_RPSTAT_INTR) { - via_wr(via, VIA_PLAY_STAT, VIA_RPSTAT_INTR, 1); + if (via_rd1(via, VIA_PLAY_STAT) & VIA_RPSTAT_INTR) { + via_wr1(via, VIA_PLAY_STAT, VIA_RPSTAT_INTR); snd_mtxunlock(via->lock); chn_intr(via->pch.channel); snd_mtxlock(via->lock); } /* Write channel */ - if (via_rd(via, VIA_RECORD_STAT, 1) & VIA_RPSTAT_INTR) { - via_wr(via, VIA_RECORD_STAT, VIA_RPSTAT_INTR, 1); + if (via_rd1(via, VIA_RECORD_STAT) & VIA_RPSTAT_INTR) { + via_wr1(via, VIA_RECORD_STAT, VIA_RPSTAT_INTR); snd_mtxunlock(via->lock); chn_intr(via->rch.channel); return; @@ -469,6 +452,27 @@ via->sgd_addr = bds->ds_addr; } +static void +via_destroy(device_t dev, struct via_info *via) +{ + if (!via) + return; + + if (via->ih) + bus_teardown_intr(dev, via->res[RES_IRQ], via->ih); + bus_release_resources(dev, via_res_spec, via->res); + if (via->parent_dmat) + bus_dma_tag_destroy(via->parent_dmat); + if (via->sgd_dmamap) + bus_dmamap_unload(via->sgd_dmat, via->sgd_dmamap); + if (via->sgd_table) + bus_dmamem_free(via->sgd_dmat, via->sgd_table, via->sgd_dmamap); + if (via->sgd_dmat) + bus_dma_tag_destroy(via->sgd_dmat); + if (via->lock) + snd_mtxfree(via->lock); + free(via, M_DEVBUF); +} static int via_attach(device_t dev) @@ -518,28 +522,21 @@ DELAY(5000); } - via->regid = PCIR_BAR(0); - via->reg = bus_alloc_resource_any(dev, SYS_RES_IOPORT, - &via->regid, RF_ACTIVE); - if (!via->reg) { - device_printf(dev, "cannot allocate bus resource."); + if (bus_alloc_resources(dev, via_res_spec, via->res) != 0) { + device_printf(dev, "unable to allocate resources\n"); goto bad; } - via->st = rman_get_bustag(via->reg); - via->sh = rman_get_bushandle(via->reg); via->bufsz = pcm_getbuffersize(dev, 4096, VIA_DEFAULT_BUFSZ, 65536); - via->irqid = 0; - via->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &via->irqid, - RF_ACTIVE | RF_SHAREABLE); - if (!via->irq || snd_setup_intr(dev, via->irq, INTR_MPSAFE, via_intr, via, &via->ih)) { + if (snd_setup_intr(dev, via->res[RES_IRQ], INTR_MPSAFE, + via_intr, via, &via->ih)) { device_printf(dev, "unable to map interrupt\n"); goto bad; } - via_wr(via, VIA_PLAY_MODE, VIA_RPMODE_AUTOSTART | VIA_RPMODE_INTR_FLAG | VIA_RPMODE_INTR_EOL, 1); - via_wr(via, VIA_RECORD_MODE, VIA_RPMODE_AUTOSTART | VIA_RPMODE_INTR_FLAG | VIA_RPMODE_INTR_EOL, 1); + via_wr1(via, VIA_PLAY_MODE, VIA_RPMODE_AUTOSTART | VIA_RPMODE_INTR_FLAG | VIA_RPMODE_INTR_EOL); + via_wr1(via, VIA_RECORD_MODE, VIA_RPMODE_AUTOSTART | VIA_RPMODE_INTR_FLAG | VIA_RPMODE_INTR_EOL); via->codec = AC97_CREATE(dev, via, via_ac97); if (!via->codec) @@ -591,7 +588,8 @@ goto bad; snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld %s", - rman_get_start(via->reg), rman_get_start(via->irq), + rman_get_start(via->res[RES_MEM]), + rman_get_start(via->res[RES_IRQ]), PCM_KLDSTRING(snd_via82c686)); /* Register */ @@ -602,15 +600,8 @@ return 0; bad: if (via->codec) ac97_destroy(via->codec); - if (via->reg) bus_release_resource(dev, SYS_RES_IOPORT, via->regid, via->reg); - if (via->ih) bus_teardown_intr(dev, via->irq, via->ih); - if (via->irq) bus_release_resource(dev, SYS_RES_IRQ, via->irqid, via->irq); - if (via->parent_dmat) bus_dma_tag_destroy(via->parent_dmat); - if (via->sgd_dmamap) bus_dmamap_unload(via->sgd_dmat, via->sgd_dmamap); - if (via->sgd_table) bus_dmamem_free(via->sgd_dmat, via->sgd_table, via->sgd_dmamap); - if (via->sgd_dmat) bus_dma_tag_destroy(via->sgd_dmat); - if (via->lock) snd_mtxfree(via->lock); - if (via) free(via, M_DEVBUF); + via_destroy(dev, via); + return ENXIO; } @@ -625,15 +616,8 @@ return r; via = pcm_getdevinfo(dev); - bus_release_resource(dev, SYS_RES_IOPORT, via->regid, via->reg); - bus_teardown_intr(dev, via->irq, via->ih); - bus_release_resource(dev, SYS_RES_IRQ, via->irqid, via->irq); - bus_dma_tag_destroy(via->parent_dmat); - bus_dmamap_unload(via->sgd_dmat, via->sgd_dmamap); - bus_dmamem_free(via->sgd_dmat, via->sgd_table, via->sgd_dmamap); - bus_dma_tag_destroy(via->sgd_dmat); - snd_mtxfree(via->lock); - free(via, M_DEVBUF); + via_destroy(dev, via); + return 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707281547.l6SFlrmm040691>