Date: Wed, 25 Jul 2007 05:57:03 GMT From: Christopher Davis <loafier@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 124066 for review Message-ID: <200707250557.l6P5v3st062521@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124066 Change 124066 by loafier@chrisdsoc on 2007/07/25 05:56:57 Modified es137x for bus_alloc_resources(), etc. Affected files ... .. //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/es137x.c#2 edit Differences ... ==== //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/es137x.c#2 (text+ko) ==== @@ -177,13 +177,29 @@ */ #define ES_DEFAULT_DAC_CFG 0 +enum { + RES_MEM, + RES_IRQ, + RES_SZ +}; + +static struct resource_spec es_res_spec_io[] = { + {SYS_RES_IOPORT, PCIR_BAR(0), RF_ACTIVE}, + {SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE}, + {-1, 0, 0} +}; + +static struct resource_spec es_res_spec_mem[] = { + {SYS_RES_MEMORY, MEM_MAP_REG, RF_ACTIVE}, + {SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE}, + {-1, 0, 0} +}; + struct es_info { - bus_space_tag_t st; - bus_space_handle_t sh; bus_dma_tag_t parent_dmat; - struct resource *reg, *irq; - int regtype, regid, irqid; + struct resource *res[RES_SZ]; + struct resource_spec *spec; void *ih; device_t dev; @@ -204,6 +220,15 @@ #define ES_UNLOCK(sc) snd_mtxunlock((sc)->lock) #define ES_LOCK_ASSERT(sc) snd_mtxassert((sc)->lock) +#define es_rd1(_sc, _reg) bus_read_1((_sc)->res[RES_MEM], _reg) +#define es_rd2(_sc, _reg) bus_read_2((_sc)->res[RES_MEM], _reg) +#define es_rd4(_sc, _reg) bus_read_4((_sc)->res[RES_MEM], _reg) + +#define es_wr1(_sc, _reg, _val) bus_write_1((_sc)->res[RES_MEM], _reg, _val) +#define es_wr2(_sc, _reg, _val) bus_write_2((_sc)->res[RES_MEM], _reg, _val) +#define es_wr4(_sc, _reg, _val) bus_write_4((_sc)->res[RES_MEM], _reg, _val) + + /* prototypes */ static void es_intr(void *); static uint32_t es1371_wait_src_ready(struct es_info *); @@ -244,37 +269,6 @@ [SOUND_MIXER_OGAIN] = { 9, 0xf, 0x0, 0, 0x0000, 1 } }; -static __inline uint32_t -es_rd(struct es_info *es, int regno, int size) -{ - switch (size) { - case 1: - return (bus_space_read_1(es->st, es->sh, regno)); - case 2: - return (bus_space_read_2(es->st, es->sh, regno)); - case 4: - return (bus_space_read_4(es->st, es->sh, regno)); - default: - return (0xFFFFFFFF); - } -} - -static __inline void -es_wr(struct es_info *es, int regno, uint32_t data, int size) -{ - - switch (size) { - case 1: - bus_space_write_1(es->st, es->sh, regno, data); - break; - case 2: - bus_space_write_2(es->st, es->sh, regno, data); - break; - case 4: - bus_space_write_4(es->st, es->sh, regno, data); - break; - } -} /* -------------------------------------------------------------------- */ /* The es1370 mixer interface */ @@ -394,10 +388,10 @@ ES_LOCK_ASSERT(es); for (t = 0; t < 0x1000; t++) { - if ((es_rd(es, ES1370_REG_STATUS, 4) & + if ((es_rd4(es, ES1370_REG_STATUS) & STAT_CSTAT) == 0) { - es_wr(es, ES1370_REG_CODEC, - ((unsigned short)i << CODEC_INDEX_SHIFT) | data, 2); + es_wr2(es, ES1370_REG_CODEC, + ((unsigned short)i << CODEC_INDEX_SHIFT) | data); return (0); } DELAY(1); @@ -476,26 +470,26 @@ ES_LOCK(es); if (dir == PCMDIR_PLAY) { if (ch->index == ES_DAC1) { - es_wr(es, ES1370_REG_MEMPAGE, - ES1370_REG_DAC1_FRAMEADR >> 8, 1); - es_wr(es, ES1370_REG_DAC1_FRAMEADR & 0xff, - sndbuf_getbufaddr(ch->buffer), 4); - es_wr(es, ES1370_REG_DAC1_FRAMECNT & 0xff, - (ch->bufsz >> 2) - 1, 4); + es_wr1(es, ES1370_REG_MEMPAGE, + ES1370_REG_DAC1_FRAMEADR >> 8); + es_wr4(es, ES1370_REG_DAC1_FRAMEADR & 0xff, + sndbuf_getbufaddr(ch->buffer)); + es_wr4(es, ES1370_REG_DAC1_FRAMECNT & 0xff, + (ch->bufsz >> 2) - 1); } else { - es_wr(es, ES1370_REG_MEMPAGE, - ES1370_REG_DAC2_FRAMEADR >> 8, 1); - es_wr(es, ES1370_REG_DAC2_FRAMEADR & 0xff, - sndbuf_getbufaddr(ch->buffer), 4); - es_wr(es, ES1370_REG_DAC2_FRAMECNT & 0xff, - (ch->bufsz >> 2) - 1, 4); + es_wr1(es, ES1370_REG_MEMPAGE, + ES1370_REG_DAC2_FRAMEADR >> 8); + es_wr4(es, ES1370_REG_DAC2_FRAMEADR & 0xff, + sndbuf_getbufaddr(ch->buffer)); + es_wr4(es, ES1370_REG_DAC2_FRAMECNT & 0xff, + (ch->bufsz >> 2) - 1); } } else { - es_wr(es, ES1370_REG_MEMPAGE, ES1370_REG_ADC_FRAMEADR >> 8, 1); - es_wr(es, ES1370_REG_ADC_FRAMEADR & 0xff, - sndbuf_getbufaddr(ch->buffer), 4); - es_wr(es, ES1370_REG_ADC_FRAMECNT & 0xff, - (ch->bufsz >> 2) - 1, 4); + es_wr1(es, ES1370_REG_MEMPAGE, ES1370_REG_ADC_FRAMEADR >> 8); + es_wr4(es, ES1370_REG_ADC_FRAMEADR & 0xff, + sndbuf_getbufaddr(ch->buffer)); + es_wr4(es, ES1370_REG_ADC_FRAMECNT & 0xff, + (ch->bufsz >> 2) - 1); } ES_UNLOCK(es); return (ch); @@ -529,7 +523,7 @@ if (format & AFMT_STEREO) es->sctrl |= SCTRL_R1SMB; } - es_wr(es, ES1370_REG_SERIAL_CONTROL, es->sctrl, 4); + es_wr4(es, ES1370_REG_SERIAL_CONTROL, es->sctrl); ES_UNLOCK(es); ch->fmt = format; return (0); @@ -575,7 +569,7 @@ es->ctrl &= ~CTRL_PCLKDIV; es->ctrl |= DAC2_SRTODIV(speed) << CTRL_SH_PCLKDIV; } - es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4); + es_wr4(es, ES1370_REG_CONTROL, es->ctrl); ES_UNLOCK(es); return (speed); } @@ -673,8 +667,8 @@ } else reg = ES1370_REG_ADC_FRAMECNT; sz = ch->blksz * ch->blkcnt; - es_wr(es, ES1370_REG_MEMPAGE, reg >> 8, 4); - ptr = es_rd(es, reg & 0x000000ff, 4) >> 16; + es_wr4(es, ES1370_REG_MEMPAGE, reg >> 8); + ptr = es_rd4(es, reg & 0x000000ff) >> 16; ptr <<= 2; ch->ptr = ptr; ptr %= sz; @@ -749,12 +743,12 @@ else es->sctrl &= ~SCTRL_P1INTEN; es->sctrl |= b; - es_wr(es, ES1370_REG_DAC1_SCOUNT, cnt, 4); + es_wr4(es, ES1370_REG_DAC1_SCOUNT, cnt); /* start at beginning of buffer */ - es_wr(es, ES1370_REG_MEMPAGE, - ES1370_REG_DAC1_FRAMECNT >> 8, 4); - es_wr(es, ES1370_REG_DAC1_FRAMECNT & 0xff, - (ch->bufsz >> 2) - 1, 4); + es_wr4(es, ES1370_REG_MEMPAGE, + ES1370_REG_DAC1_FRAMECNT >> 8); + es_wr4(es, ES1370_REG_DAC1_FRAMECNT & 0xff, + (ch->bufsz >> 2) - 1); } else { es->ctrl |= CTRL_DAC2_EN; es->sctrl &= ~(SCTRL_P2ENDINC | SCTRL_P2STINC | @@ -766,12 +760,12 @@ es->sctrl &= ~SCTRL_P2INTEN; es->sctrl |= (b << 2) | ((((b >> 1) & 1) + 1) << SCTRL_SH_P2ENDINC); - es_wr(es, ES1370_REG_DAC2_SCOUNT, cnt, 4); + es_wr4(es, ES1370_REG_DAC2_SCOUNT, cnt); /* start at beginning of buffer */ - es_wr(es, ES1370_REG_MEMPAGE, - ES1370_REG_DAC2_FRAMECNT >> 8, 4); - es_wr(es, ES1370_REG_DAC2_FRAMECNT & 0xff, - (ch->bufsz >> 2) - 1, 4); + es_wr4(es, ES1370_REG_MEMPAGE, + ES1370_REG_DAC2_FRAMECNT >> 8); + es_wr4(es, ES1370_REG_DAC2_FRAMECNT & 0xff, + (ch->bufsz >> 2) - 1); } } else es->ctrl &= ~((ch->index == ES_DAC1) ? @@ -785,17 +779,17 @@ else es->sctrl &= ~SCTRL_R1INTEN; es->sctrl |= b << 4; - es_wr(es, ES1370_REG_ADC_SCOUNT, cnt, 4); + es_wr4(es, ES1370_REG_ADC_SCOUNT, cnt); /* start at beginning of buffer */ - es_wr(es, ES1370_REG_MEMPAGE, - ES1370_REG_ADC_FRAMECNT >> 8, 4); - es_wr(es, ES1370_REG_ADC_FRAMECNT & 0xff, - (ch->bufsz >> 2) - 1, 4); + es_wr4(es, ES1370_REG_MEMPAGE, + ES1370_REG_ADC_FRAMECNT >> 8); + es_wr4(es, ES1370_REG_ADC_FRAMECNT & 0xff, + (ch->bufsz >> 2) - 1); } else es->ctrl &= ~CTRL_ADC_EN; } - es_wr(es, ES1370_REG_SERIAL_CONTROL, es->sctrl, 4); - es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4); + es_wr4(es, ES1370_REG_SERIAL_CONTROL, es->sctrl); + es_wr4(es, ES1370_REG_CONTROL, es->ctrl); if (go == PCMTRIG_START) { if (es->polling != 0) { ch->ptr = 0; @@ -838,8 +832,8 @@ reg = ES1370_REG_DAC2_FRAMECNT; } else reg = ES1370_REG_ADC_FRAMECNT; - es_wr(es, ES1370_REG_MEMPAGE, reg >> 8, 4); - cnt = es_rd(es, reg & 0x000000ff, 4) >> 16; + es_wr4(es, ES1370_REG_MEMPAGE, reg >> 8); + cnt = es_rd4(es, reg & 0x000000ff) >> 16; /* cnt is longwords */ cnt <<= 2; } @@ -897,7 +891,7 @@ ES_UNLOCK(es); return; } - intsrc = es_rd(es, ES1370_REG_STATUS, 4); + intsrc = es_rd4(es, ES1370_REG_STATUS); if ((intsrc & STAT_INTR) == 0) { ES_UNLOCK(es); return; @@ -911,8 +905,8 @@ if (intsrc & STAT_DAC2) sctrl &= ~SCTRL_P2INTEN; - es_wr(es, ES1370_REG_SERIAL_CONTROL, sctrl, 4); - es_wr(es, ES1370_REG_SERIAL_CONTROL, es->sctrl, 4); + es_wr4(es, ES1370_REG_SERIAL_CONTROL, sctrl); + es_wr4(es, ES1370_REG_SERIAL_CONTROL, es->sctrl); ES_UNLOCK(es); if (intsrc & STAT_ADC) @@ -967,10 +961,10 @@ es->ctrl = CTRL_CDC_EN | CTRL_JYSTK_EN | CTRL_SERR_DIS | (DAC2_SRTODIV(fixed_rate) << CTRL_SH_PCLKDIV); es->ctrl |= 3 << CTRL_SH_WTSRSEL; - es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4); + es_wr4(es, ES1370_REG_CONTROL, es->ctrl); es->sctrl = 0; - es_wr(es, ES1370_REG_SERIAL_CONTROL, es->sctrl, 4); + es_wr4(es, ES1370_REG_SERIAL_CONTROL, es->sctrl); /* No RST, PD */ es1370_wrcodec(es, CODEC_RES_PD, 3); @@ -1023,26 +1017,26 @@ es->ctrl |= (1 << 16); } /* initialize the chips */ - es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4); - es_wr(es, ES1370_REG_SERIAL_CONTROL, es->sctrl, 4); - es_wr(es, ES1371_REG_LEGACY, 0, 4); + es_wr4(es, ES1370_REG_CONTROL, es->ctrl); + es_wr4(es, ES1370_REG_SERIAL_CONTROL, es->sctrl); + es_wr4(es, ES1371_REG_LEGACY, 0); if ((devid == ES1371_PCI_ID && revid == ES1371REV_ES1373_8) || (devid == ES1371_PCI_ID && revid == ES1371REV_CT5880_A) || (devid == CT5880_PCI_ID && revid == CT5880REV_CT5880_C) || (devid == CT5880_PCI_ID && revid == CT5880REV_CT5880_D) || (devid == CT5880_PCI_ID && revid == CT5880REV_CT5880_E)) { cssr = 1 << 29; - es_wr(es, ES1370_REG_STATUS, cssr, 4); + es_wr4(es, ES1370_REG_STATUS, cssr); DELAY(20000); } /* AC'97 warm reset to start the bitclk */ - es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4); - es_wr(es, ES1371_REG_LEGACY, ES1371_SYNC_RES, 4); + es_wr4(es, ES1370_REG_CONTROL, es->ctrl); + es_wr4(es, ES1371_REG_LEGACY, ES1371_SYNC_RES); DELAY(2000); - es_wr(es, ES1370_REG_CONTROL, es->sctrl, 4); + es_wr4(es, ES1370_REG_CONTROL, es->sctrl); es1371_wait_src_ready(es); /* Init the sample rate converter */ - es_wr(es, ES1371_REG_SMPRATE, ES1371_DIS_SRC, 4); + es_wr4(es, ES1371_REG_SMPRATE, ES1371_DIS_SRC); for (idx = 0; idx < 0x80; idx++) es1371_src_write(es, idx, 0); es1371_src_write(es, ES_SMPREG_DAC1 + ES_SMPREG_TRUNC_N, 16 << 4); @@ -1066,10 +1060,10 @@ * power cycle) */ es1371_wait_src_ready(es); - es_wr(es, ES1371_REG_SMPRATE, 0, 4); + es_wr4(es, ES1371_REG_SMPRATE, 0); /* try to reset codec directly */ - es_wr(es, ES1371_REG_CODEC, 0, 4); - es_wr(es, ES1370_REG_STATUS, cssr, 4); + es_wr4(es, ES1371_REG_CODEC, 0); + es_wr4(es, ES1370_REG_STATUS, cssr); ES_UNLOCK(es); return (0); @@ -1084,33 +1078,33 @@ struct es_info *es = (struct es_info*)s; for (t = 0; t < 0x1000; t++) { - if (!es_rd(es, ES1371_REG_CODEC & CODEC_WIP, 4)) + if (!es_rd4(es, ES1371_REG_CODEC & CODEC_WIP)) break; } /* save the current state for later */ - x = orig = es_rd(es, ES1371_REG_SMPRATE, 4); + x = orig = es_rd4(es, ES1371_REG_SMPRATE); /* enable SRC state data in SRC mux */ - es_wr(es, ES1371_REG_SMPRATE, (x & (ES1371_DIS_SRC | ES1371_DIS_P1 | - ES1371_DIS_P2 | ES1371_DIS_R1)) | 0x00010000, 4); + es_wr4(es, ES1371_REG_SMPRATE, (x & (ES1371_DIS_SRC | ES1371_DIS_P1 | + ES1371_DIS_P2 | ES1371_DIS_R1)) | 0x00010000); /* busy wait */ for (t = 0; t < 0x1000; t++) { - if ((es_rd(es, ES1371_REG_SMPRATE, 4) & 0x00870000) == + if ((es_rd4(es, ES1371_REG_SMPRATE) & 0x00870000) == 0x00000000) break; } /* wait for a SAFE time to write addr/data and then do it, dammit */ for (t = 0; t < 0x1000; t++) { - if ((es_rd(es, ES1371_REG_SMPRATE, 4) & 0x00870000) == + if ((es_rd4(es, ES1371_REG_SMPRATE) & 0x00870000) == 0x00010000) break; } - es_wr(es, ES1371_REG_CODEC, ((addr << CODEC_POADD_SHIFT) & + es_wr4(es, ES1371_REG_CODEC, ((addr << CODEC_POADD_SHIFT) & CODEC_POADD_MASK) | ((data << CODEC_PODAT_SHIFT) & - CODEC_PODAT_MASK), 4); + CODEC_PODAT_MASK)); /* restore SRC reg */ es1371_wait_src_ready(s); - es_wr(es, ES1371_REG_SMPRATE, orig, 4); + es_wr4(es, ES1371_REG_SMPRATE, orig); return (0); } @@ -1122,38 +1116,38 @@ struct es_info *es = (struct es_info *)s; for (t = 0; t < 0x1000; t++) { - if (!(x = es_rd(es, ES1371_REG_CODEC, 4) & CODEC_WIP)) + if (!(x = es_rd4(es, ES1371_REG_CODEC) & CODEC_WIP)) break; } /* save the current state for later */ - x = orig = es_rd(es, ES1371_REG_SMPRATE, 4); + x = orig = es_rd4(es, ES1371_REG_SMPRATE); /* enable SRC state data in SRC mux */ - es_wr(es, ES1371_REG_SMPRATE, (x & (ES1371_DIS_SRC | ES1371_DIS_P1 | - ES1371_DIS_P2 | ES1371_DIS_R1)) | 0x00010000, 4); + es_wr4(es, ES1371_REG_SMPRATE, (x & (ES1371_DIS_SRC | ES1371_DIS_P1 | + ES1371_DIS_P2 | ES1371_DIS_R1)) | 0x00010000); /* busy wait */ for (t = 0; t < 0x1000; t++) { - if ((x = es_rd(es, ES1371_REG_SMPRATE, 4) & 0x00870000) == + if ((x = es_rd4(es, ES1371_REG_SMPRATE) & 0x00870000) == 0x00000000) break; } /* wait for a SAFE time to write addr/data and then do it, dammit */ for (t = 0; t < 0x1000; t++) { - if ((x = es_rd(es, ES1371_REG_SMPRATE, 4) & 0x00870000) == + if ((x = es_rd4(es, ES1371_REG_SMPRATE) & 0x00870000) == 0x00010000) break; } - es_wr(es, ES1371_REG_CODEC, ((addr << CODEC_POADD_SHIFT) & - CODEC_POADD_MASK) | CODEC_PORD, 4); + es_wr4(es, ES1371_REG_CODEC, ((addr << CODEC_POADD_SHIFT) & + CODEC_POADD_MASK) | CODEC_PORD); /* restore SRC reg */ es1371_wait_src_ready(s); - es_wr(es, ES1371_REG_SMPRATE, orig, 4); + es_wr4(es, ES1371_REG_SMPRATE, orig); /* now wait for the stinkin' data (RDY) */ for (t = 0; t < 0x1000; t++) { - if ((x = es_rd(es, ES1371_REG_CODEC, 4)) & CODEC_RDY) + if ((x = es_rd4(es, ES1371_REG_CODEC)) & CODEC_RDY) break; } @@ -1177,7 +1171,7 @@ r = es1371_wait_src_ready(es) & (ES1371_DIS_SRC | ES1371_DIS_P1 | ES1371_DIS_P2 | ES1371_DIS_R1); r |= ES1371_SRC_RAM_ADDRO(reg); - es_wr(es, ES1371_REG_SMPRATE, r, 4); + es_wr4(es, ES1371_REG_SMPRATE, r); return (ES1371_SRC_RAM_DATAI(es1371_wait_src_ready(es))); } @@ -1189,7 +1183,7 @@ r = es1371_wait_src_ready(es) & (ES1371_DIS_SRC | ES1371_DIS_P1 | ES1371_DIS_P2 | ES1371_DIS_R1); r |= ES1371_SRC_RAM_ADDRO(reg) | ES1371_SRC_RAM_DATAO(data); - es_wr(es, ES1371_REG_SMPRATE, r | ES1371_SRC_RAM_WE, 4); + es_wr4(es, ES1371_REG_SMPRATE, r | ES1371_SRC_RAM_WE); } static unsigned int @@ -1250,14 +1244,14 @@ dis = (set == ES_DAC1) ? ES1371_DIS_P2 : ES1371_DIS_P1; r = (es1371_wait_src_ready(es) & (ES1371_DIS_SRC | ES1371_DIS_P1 | ES1371_DIS_P2 | ES1371_DIS_R1)); - es_wr(es, ES1371_REG_SMPRATE, r, 4); + es_wr4(es, ES1371_REG_SMPRATE, r); es1371_src_write(es, dac + ES_SMPREG_INT_REGS, (es1371_src_read(es, dac + ES_SMPREG_INT_REGS) & 0x00ff) | ((freq >> 5) & 0xfc00)); es1371_src_write(es, dac + ES_SMPREG_VFREQ_FRAC, freq & 0x7fff); r = (es1371_wait_src_ready(es) & (ES1371_DIS_SRC | dis | ES1371_DIS_R1)); - es_wr(es, ES1371_REG_SMPRATE, r, 4); + es_wr4(es, ES1371_REG_SMPRATE, r); return (result); } @@ -1267,7 +1261,7 @@ uint32_t t, r; for (t = 0; t < 0x1000; t++) { - if (!((r = es_rd(es, ES1371_REG_SMPRATE, 4)) & + if (!((r = es_rd4(es, ES1371_REG_SMPRATE)) & ES1371_SRC_RAM_BUSY)) return (r); DELAY(1); @@ -1374,7 +1368,7 @@ dev = oidp->oid_arg1; es = pcm_getdevinfo(dev); ES_LOCK(es); - r = es_rd(es, ES1370_REG_STATUS, 4); + r = es_rd4(es, ES1370_REG_STATUS); ES_UNLOCK(es); new_en = (r & ENABLE_SPDIF) ? 1 : 0; err = sysctl_handle_int(oidp, &new_en, 0, req); @@ -1394,8 +1388,8 @@ es->ctrl &= ~SPDIFEN_B; es->ctrl &= ~RECEN_B; } - es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4); - es_wr(es, ES1370_REG_STATUS, r, 4); + es_wr4(es, ES1370_REG_CONTROL, es->ctrl); + es_wr4(es, ES1370_REG_STATUS, r); ES_UNLOCK(es); return (0); @@ -1464,7 +1458,7 @@ es->ch[ES_ADC].caps.minspeed = val; es->ctrl &= ~CTRL_PCLKDIV; es->ctrl |= DAC2_SRTODIV(val) << CTRL_SH_PCLKDIV; - es_wr(es, ES1370_REG_CONTROL, es->ctrl, 4); + es_wr4(es, ES1370_REG_CONTROL, es->ctrl); } } else { es->escfg = ES_SET_FIXED_RATE(es->escfg, 0); @@ -1676,6 +1670,22 @@ #endif /* SND_DYNSYSCTL */ } +static void +es_destroy(device_t dev, struct es_info *es) +{ + if (!es) + return; + + if (es->parent_dmat) + bus_dma_tag_destroy(es->parent_dmat); + if (es->ih) + bus_teardown_intr(dev, es->res[RES_IRQ], es->ih); + bus_release_resources(dev, es->spec, es->res); + if (es->lock) + snd_mtxfree(es->lock); + free(es, M_DEVBUF); +} + static int es_pci_attach(device_t dev) { @@ -1698,29 +1708,22 @@ data |= (PCIM_CMD_PORTEN|PCIM_CMD_MEMEN); pci_write_config(dev, PCIR_COMMAND, data, 2); data = pci_read_config(dev, PCIR_COMMAND, 2); + if (mapped == 0 && (data & PCIM_CMD_MEMEN)) { - es->regid = MEM_MAP_REG; - es->regtype = SYS_RES_MEMORY; - es->reg = bus_alloc_resource_any(dev, es->regtype, &es->regid, - RF_ACTIVE); - if (es->reg) + es->spec = es_res_spec_mem; + if (bus_alloc_resources(dev, es->spec, es->res) == 0) mapped++; } if (mapped == 0 && (data & PCIM_CMD_PORTEN)) { - es->regid = PCIR_BAR(0); - es->regtype = SYS_RES_IOPORT; - es->reg = bus_alloc_resource_any(dev, es->regtype, &es->regid, - RF_ACTIVE); - if (es->reg) + es->spec = es_res_spec_io; + if (bus_alloc_resources(dev, es->spec, es->res) == 0) mapped++; - } + } if (mapped == 0) { device_printf(dev, "unable to map register space\n"); goto bad; } - es->st = rman_get_bustag(es->reg); - es->sh = rman_get_bushandle(es->reg); callout_init(&es->poll_timer, CALLOUT_MPSAFE); es->poll_ticks = 1; @@ -1815,10 +1818,7 @@ /* NOTREACHED */ } - es->irqid = 0; - es->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &es->irqid, - RF_ACTIVE | RF_SHAREABLE); - if (!es->irq || snd_setup_intr(dev, es->irq, INTR_MPSAFE, es_intr, + if (snd_setup_intr(dev, es->res[RES_IRQ], INTR_MPSAFE, es_intr, es, &es->ih)) { device_printf(dev, "unable to map interrupt\n"); goto bad; @@ -1837,8 +1837,9 @@ } snprintf(status, SND_STATUSLEN, "at %s 0x%lx irq %ld %s", - (es->regtype == SYS_RES_IOPORT)? "io" : "memory", - rman_get_start(es->reg), rman_get_start(es->irq), + (es->spec == es_res_spec_io)? "io" : "memory", + rman_get_start(es->res[RES_MEM]), + rman_get_start(es->res[RES_IRQ]), PCM_KLDSTRING(snd_es137x)); if (pcm_register(dev, es, numplay, 1)) @@ -1858,20 +1859,10 @@ return (0); bad: - if (es->parent_dmat) - bus_dma_tag_destroy(es->parent_dmat); - if (es->ih) - bus_teardown_intr(dev, es->irq, es->ih); - if (es->irq) - bus_release_resource(dev, SYS_RES_IRQ, es->irqid, es->irq); if (codec) ac97_destroy(codec); - if (es->reg) - bus_release_resource(dev, es->regtype, es->regid, es->reg); - if (es->lock) - snd_mtxfree(es->lock); - if (es) - free(es, M_DEVBUF); + es_destroy(dev, es); + return (ENXIO); } @@ -1895,12 +1886,7 @@ callout_drain(&es->poll_timer); } - bus_teardown_intr(dev, es->irq, es->ih); - bus_release_resource(dev, SYS_RES_IRQ, es->irqid, es->irq); - bus_release_resource(dev, es->regtype, es->regid, es->reg); - bus_dma_tag_destroy(es->parent_dmat); - snd_mtxfree(es->lock); - free(es, M_DEVBUF); + es_destroy(dev, es); return (0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707250557.l6P5v3st062521>