Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Jul 2007 13:56:30 GMT
From:      Christopher Davis <loafier@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 124261 for review
Message-ID:  <200707281356.l6SDuUMX003086@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124261

Change 124261 by loafier@chrisdsoc on 2007/07/28 13:56:16

	Edit neomagic for bus_alloc_resources(), etc.

Affected files ...

.. //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/neomagic.c#2 edit

Differences ...

==== //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/neomagic.c#2 (text+ko) ====

@@ -54,13 +54,26 @@
 	struct sc_info *parent;
 };
 
+enum {
+	RES_BUF,
+	RES_REG,
+	RES_IRQ,
+	RES_SZ
+};
+
+static struct resource_spec nm_res_spec[] = {
+	{SYS_RES_MEMORY, PCIR_BAR(0), RF_ACTIVE},
+	{SYS_RES_MEMORY, PCIR_BAR(1), RF_ACTIVE},
+	{SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE},
+	{-1, 0, 0}
+};
+
 /* device private data */
 struct sc_info {
 	device_t	dev;
 	u_int32_t 	type;
 
-	struct resource *reg, *irq, *buf;
-	int		regid, irqid, bufid;
+	struct resource *res[RES_SZ];
 	void		*ih;
 
 	u_int32_t 	ac97_base, ac97_status, ac97_busy;
@@ -84,10 +97,19 @@
 static void      nm_intr(void *);
 
 /* talk to the card */
-static u_int32_t nm_rd(struct sc_info *, int, int);
-static void 	 nm_wr(struct sc_info *, int, u_int32_t, int);
-static u_int32_t nm_rdbuf(struct sc_info *, int, int);
-static void 	 nm_wrbuf(struct sc_info *, int, u_int32_t, int);
+#define nm_rd1(_sc, _reg) bus_read_1((_sc)->res[RES_REG], _reg)
+#define nm_rd2(_sc, _reg) bus_read_2((_sc)->res[RES_REG], _reg)
+#define nm_rd4(_sc, _reg) bus_read_4((_sc)->res[RES_REG], _reg)
+#define nm_wr1(_sc, _reg, _val) bus_write_1((_sc)->res[RES_REG], _reg, _val)
+#define nm_wr2(_sc, _reg, _val) bus_write_2((_sc)->res[RES_REG], _reg, _val)
+#define nm_wr4(_sc, _reg, _val) bus_write_4((_sc)->res[RES_REG], _reg, _val)
+
+#define nm_rdbuf1(_sc, _reg) bus_read_1((_sc)->res[RES_BUF], _reg)
+#define nm_rdbuf2(_sc, _reg) bus_read_2((_sc)->res[RES_BUF], _reg)
+#define nm_rdbuf4(_sc, _reg) bus_read_4((_sc)->res[RES_BUF], _reg)
+#define nm_wrbuf1(_sc, _reg, _val) bus_write_1((_sc)->res[RES_BUF], _reg, _val)
+#define nm_wrbuf2(_sc, _reg, _val) bus_write_2((_sc)->res[RES_BUF], _reg, _val)
+#define nm_wrbuf4(_sc, _reg, _val) bus_write_4((_sc)->res[RES_BUF], _reg, _val)
 
 static u_int32_t badcards[] = {
 	0x0007103c,
@@ -122,83 +144,6 @@
 static struct pcmchan_caps nm_caps = {4000, 48000, nm_fmt, 0};
 
 /* -------------------------------------------------------------------- */
-
-/* Hardware */
-static u_int32_t
-nm_rd(struct sc_info *sc, int regno, int size)
-{
-	bus_space_tag_t st = rman_get_bustag(sc->reg);
-	bus_space_handle_t sh = rman_get_bushandle(sc->reg);
-
-	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
-nm_wr(struct sc_info *sc, int regno, u_int32_t data, int size)
-{
-	bus_space_tag_t st = rman_get_bustag(sc->reg);
-	bus_space_handle_t sh = rman_get_bushandle(sc->reg);
-
-	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 u_int32_t
-nm_rdbuf(struct sc_info *sc, int regno, int size)
-{
-	bus_space_tag_t st = rman_get_bustag(sc->buf);
-	bus_space_handle_t sh = rman_get_bushandle(sc->buf);
-
-	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
-nm_wrbuf(struct sc_info *sc, int regno, u_int32_t data, int size)
-{
-	bus_space_tag_t st = rman_get_bustag(sc->buf);
-	bus_space_handle_t sh = rman_get_bushandle(sc->buf);
-
-	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;
-	}
-}
-
-/* -------------------------------------------------------------------- */
 /* ac97 codec */
 static int
 nm_waitcd(struct sc_info *sc)
@@ -207,7 +152,7 @@
 	int fail = 1;
 
 	while (cnt-- > 0) {
-		if (nm_rd(sc, sc->ac97_status, 2) & sc->ac97_busy) {
+		if (nm_rd2(sc, sc->ac97_status) & sc->ac97_busy) {
 			DELAY(100);
 		} else {
 			fail = 0;
@@ -222,7 +167,7 @@
 {
 	struct sc_info *sc = (struct sc_info *)devinfo;
 
-	nm_wr(sc, 0x6c0, 0x01, 1);
+	nm_wr1(sc, 0x6c0, 0x01);
 #if 0
 	/*
 	 * The following code-line may cause a hang for some chipsets, see
@@ -231,10 +176,10 @@
 	 * conditionize the code-line based upon the specific version of
 	 * the chip.
 	 */
-	nm_wr(sc, 0x6cc, 0x87, 1);
+	nm_wr1(sc, 0x6cc, 0x87);
 #endif
-	nm_wr(sc, 0x6cc, 0x80, 1);
-	nm_wr(sc, 0x6cc, 0x00, 1);
+	nm_wr1(sc, 0x6cc, 0x80);
+	nm_wr1(sc, 0x6cc, 0x00);
 	return 1;
 }
 
@@ -245,7 +190,7 @@
 	u_int32_t x;
 
 	if (!nm_waitcd(sc)) {
-		x = nm_rd(sc, sc->ac97_base + regno, 2);
+		x = nm_rd2(sc, sc->ac97_base + regno);
 		DELAY(1000);
 		return x;
 	} else {
@@ -262,7 +207,7 @@
 
 	if (!nm_waitcd(sc)) {
 		while (cnt-- > 0) {
-			nm_wr(sc, sc->ac97_base + regno, data, 2);
+			nm_wr2(sc, sc->ac97_base + regno, data);
 			if (!nm_waitcd(sc)) {
 				DELAY(1000);
 				return 0;
@@ -287,9 +232,9 @@
 nm_ackint(struct sc_info *sc, u_int32_t num)
 {
 	if (sc->type == NM256AV_PCI_ID) {
-		nm_wr(sc, NM_INT_REG, num << 1, 2);
+		nm_wr2(sc, NM_INT_REG, num << 1);
 	} else if (sc->type == NM256ZX_PCI_ID) {
-		nm_wr(sc, NM_INT_REG, num, 4);
+		nm_wr4(sc, NM_INT_REG, num);
 	}
 }
 
@@ -307,11 +252,11 @@
 	while (num-- > 0)
 		ofs+= coefficientSizes[num];
 	for (i = 0; i < sz; i++)
-		nm_wrbuf(sc, sc->cbuf + i, coefficients[ofs + i], 1);
-	nm_wr(sc, addr, sc->cbuf, 4);
+		nm_wrbuf1(sc, sc->cbuf + i, coefficients[ofs + i]);
+	nm_wr4(sc, addr, sc->cbuf);
 	if (dir == PCMDIR_PLAY)
 		sz--;
-	nm_wr(sc, addr + 4, sc->cbuf + sz, 4);
+	nm_wr4(sc, addr + 4, sc->cbuf + sz);
 	return 0;
 }
 
@@ -337,7 +282,7 @@
 	if (ch->fmt & AFMT_STEREO) x |= NM_RATE_STEREO;
 
 	base = (ch->dir == PCMDIR_PLAY)? NM_PLAYBACK_REG_OFFSET : NM_RECORD_REG_OFFSET;
-	nm_wr(sc, base + NM_RATE_REG_OFFSET, x, 1);
+	nm_wr1(sc, base + NM_RATE_REG_OFFSET, x);
 	return 0;
 }
 
@@ -355,7 +300,9 @@
 	ch->blksize = 0;
 	ch->wmark = 0;
 	ch->buffer = b;
-	sndbuf_setup(ch->buffer, (u_int8_t *)rman_get_virtual(sc->buf) + chnbuf, NM_BUFFSIZE);
+	sndbuf_setup(ch->buffer, 
+		    (u_int8_t *)rman_get_virtual(sc->res[RES_BUF]) + chnbuf, 
+		    NM_BUFFSIZE);
 	if (bootverbose)
 		device_printf(sc->dev, "%s buf %p\n", (dir == PCMDIR_PLAY)?
 			      "play" : "rec", sndbuf_getbuf(ch->buffer));
@@ -417,31 +364,31 @@
 		if (go == PCMTRIG_START) {
 			ch->active = 1;
 			ch->wmark = ch->blksize;
-			nm_wr(sc, NM_PBUFFER_START, sc->pbuf, 4);
-			nm_wr(sc, NM_PBUFFER_END, sc->pbuf + NM_BUFFSIZE - ssz, 4);
-			nm_wr(sc, NM_PBUFFER_CURRP, sc->pbuf, 4);
-			nm_wr(sc, NM_PBUFFER_WMARK, sc->pbuf + ch->wmark, 4);
-			nm_wr(sc, NM_PLAYBACK_ENABLE_REG, NM_PLAYBACK_FREERUN |
-				NM_PLAYBACK_ENABLE_FLAG, 1);
-			nm_wr(sc, NM_AUDIO_MUTE_REG, 0, 2);
+			nm_wr4(sc, NM_PBUFFER_START, sc->pbuf);
+			nm_wr4(sc, NM_PBUFFER_END, sc->pbuf + NM_BUFFSIZE - ssz);
+			nm_wr4(sc, NM_PBUFFER_CURRP, sc->pbuf);
+			nm_wr4(sc, NM_PBUFFER_WMARK, sc->pbuf + ch->wmark);
+			nm_wr1(sc, NM_PLAYBACK_ENABLE_REG, NM_PLAYBACK_FREERUN |
+				NM_PLAYBACK_ENABLE_FLAG);
+			nm_wr2(sc, NM_AUDIO_MUTE_REG, 0);
 		} else {
 			ch->active = 0;
-			nm_wr(sc, NM_PLAYBACK_ENABLE_REG, 0, 1);
-			nm_wr(sc, NM_AUDIO_MUTE_REG, NM_AUDIO_MUTE_BOTH, 2);
+			nm_wr1(sc, NM_PLAYBACK_ENABLE_REG, 0);
+			nm_wr2(sc, NM_AUDIO_MUTE_REG, NM_AUDIO_MUTE_BOTH);
 		}
 	} else {
 		if (go == PCMTRIG_START) {
 			ch->active = 1;
 			ch->wmark = ch->blksize;
-			nm_wr(sc, NM_RECORD_ENABLE_REG, NM_RECORD_FREERUN |
-				NM_RECORD_ENABLE_FLAG, 1);
-			nm_wr(sc, NM_RBUFFER_START, sc->rbuf, 4);
-			nm_wr(sc, NM_RBUFFER_END, sc->rbuf + NM_BUFFSIZE, 4);
-			nm_wr(sc, NM_RBUFFER_CURRP, sc->rbuf, 4);
-			nm_wr(sc, NM_RBUFFER_WMARK, sc->rbuf + ch->wmark, 4);
+			nm_wr1(sc, NM_RECORD_ENABLE_REG, NM_RECORD_FREERUN |
+				NM_RECORD_ENABLE_FLAG);
+			nm_wr4(sc, NM_RBUFFER_START, sc->rbuf);
+			nm_wr4(sc, NM_RBUFFER_END, sc->rbuf + NM_BUFFSIZE);
+			nm_wr4(sc, NM_RBUFFER_CURRP, sc->rbuf);
+			nm_wr4(sc, NM_RBUFFER_WMARK, sc->rbuf + ch->wmark);
 		} else {
 			ch->active = 0;
-			nm_wr(sc, NM_RECORD_ENABLE_REG, 0, 1);
+			nm_wr1(sc, NM_RECORD_ENABLE_REG, 0);
 		}
 	}
 	return 0;
@@ -454,9 +401,9 @@
 	struct sc_info *sc = ch->parent;
 
 	if (ch->dir == PCMDIR_PLAY)
-		return nm_rd(sc, NM_PBUFFER_CURRP, 4) - sc->pbuf;
+		return nm_rd4(sc, NM_PBUFFER_CURRP) - sc->pbuf;
 	else
-		return nm_rd(sc, NM_RBUFFER_CURRP, 4) - sc->rbuf;
+		return nm_rd4(sc, NM_RBUFFER_CURRP) - sc->rbuf;
 }
 
 static struct pcmchan_caps *
@@ -482,10 +429,23 @@
 static void
 nm_intr(void *p)
 {
-	struct sc_info *sc = (struct sc_info *)p;
-	int status, x;
+	struct sc_info *sc = p;
+	int status = 0, x;
+
+	switch (sc->irsz) {
+		case 1:
+		status = nm_rd1(sc, NM_INT_REG);
+		break;
+
+		case 2:
+		status = nm_rd2(sc, NM_INT_REG);
+		break;
+
+		case 4:
+		status = nm_rd4(sc, NM_INT_REG);
+		break;
+	}
 
-	status = nm_rd(sc, NM_INT_REG, sc->irsz);
 	if (status == 0)
 		return;
 
@@ -493,7 +453,7 @@
 		status &= ~sc->playint;
 		sc->pch.wmark += sc->pch.blksize;
 		sc->pch.wmark %= NM_BUFFSIZE;
-		nm_wr(sc, NM_PBUFFER_WMARK, sc->pbuf + sc->pch.wmark, 4);
+		nm_wr4(sc, NM_PBUFFER_WMARK, sc->pbuf + sc->pch.wmark);
 
 		nm_ackint(sc, sc->playint);
 		chn_intr(sc->pch.channel);
@@ -502,7 +462,7 @@
 		status &= ~sc->recint;
 		sc->rch.wmark += sc->rch.blksize;
 		sc->rch.wmark %= NM_BUFFSIZE;
-		nm_wr(sc, NM_RBUFFER_WMARK, sc->rbuf + sc->rch.wmark, 4);
+		nm_wr4(sc, NM_RBUFFER_WMARK, sc->rbuf + sc->rch.wmark);
 
 		nm_ackint(sc, sc->recint);
 		chn_intr(sc->rch.channel);
@@ -510,15 +470,15 @@
 	if (status & sc->misc1int) {
 		status &= ~sc->misc1int;
 		nm_ackint(sc, sc->misc1int);
-		x = nm_rd(sc, 0x400, 1);
-		nm_wr(sc, 0x400, x | 2, 1);
+		x = nm_rd1(sc, 0x400);
+		nm_wr1(sc, 0x400, x | 2);
 	 	device_printf(sc->dev, "misc int 1\n");
 	}
 	if (status & sc->misc2int) {
 		status &= ~sc->misc2int;
 		nm_ackint(sc, sc->misc2int);
-		x = nm_rd(sc, 0x400, 1);
-		nm_wr(sc, 0x400, x & ~2, 1);
+		x = nm_rd1(sc, 0x400);
+		nm_wr1(sc, 0x400, x & ~2);
 	 	device_printf(sc->dev, "misc int 2\n");
 	}
 	if (status) {
@@ -555,7 +515,7 @@
 		sc->ac97_status = NM2_MIXER_STATUS_OFFSET;
 		sc->ac97_busy = NM2_MIXER_READY_MASK;
 
-		sc->buftop = (nm_rd(sc, 0xa0b, 2)? 6144 : 4096) * 1024;
+		sc->buftop = (nm_rd2(sc, 0xa0b)? 6144 : 4096) * 1024;
 
 		sc->irsz = 4;
 		sc->playint = NM2_PLAYBACK_INT;
@@ -569,8 +529,8 @@
 
 	if (bootverbose)
 		device_printf(sc->dev, "buftop is 0x%08x\n", sc->buftop);
- 	if ((nm_rdbuf(sc, ofs, 4) & NM_SIG_MASK) == NM_SIGNATURE) {
-		i = nm_rdbuf(sc, ofs + 4, 4);
+ 	if ((nm_rdbuf4(sc, ofs) & NM_SIG_MASK) == NM_SIGNATURE) {
+		i = nm_rdbuf4(sc, ofs + 4);
 		if (i != 0 && i != 0xffffffff) {
 			if (bootverbose)
 				device_printf(sc->dev, "buftop is changed to 0x%08x\n", i);
@@ -583,20 +543,33 @@
 	sc->pbuf = sc->rbuf - NM_BUFFSIZE;
 	sc->acbuf = sc->pbuf - (NM_TOTAL_COEFF_COUNT * 4);
 
-	nm_wr(sc, 0, 0x11, 1);
-	nm_wr(sc, NM_RECORD_ENABLE_REG, 0, 1);
-	nm_wr(sc, 0x214, 0, 2);
+	nm_wr1(sc, 0, 0x11);
+	nm_wr1(sc, NM_RECORD_ENABLE_REG, 0);
+	nm_wr2(sc, 0x214, 0);
 
 	return 0;
 }
 
+static void
+nm_destroy(device_t dev, struct sc_info *sc)
+{
+	if (!sc)
+		return;
+
+	if (sc->ih) 
+		bus_teardown_intr(dev, sc->res[RES_IRQ], sc->ih);
+	bus_release_resources(dev, nm_res_spec, sc->res);
+	free(sc, M_DEVBUF);
+}
+
 static int
 nm_pci_probe(device_t dev)
 {
-	struct sc_info *sc = NULL;
 	char *s = NULL;
 	u_int32_t subdev, i, data;
-
+	int rid;
+	struct resource *reg;
+	
 	subdev = (pci_get_subdevice(dev) << 16) | pci_get_subvendor(dev);
 	switch (pci_get_devid(dev)) {
 	case NM256AV_PCI_ID:
@@ -607,25 +580,19 @@
 		/* Try to catch other non-ac97 cards */
 
 		if (i == NUM_BADCARDS) {
-			if (!(sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT | M_ZERO))) {
-				device_printf(dev, "cannot allocate softc\n");
-				return ENXIO;
-			}
-
 			data = pci_read_config(dev, PCIR_COMMAND, 2);
 			pci_write_config(dev, PCIR_COMMAND, data |
 					 PCIM_CMD_PORTEN | PCIM_CMD_MEMEN |
 					 PCIM_CMD_BUSMASTEREN, 2);
 
-			sc->regid = PCIR_BAR(1);
-			sc->reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
-							 &sc->regid,
+			rid = PCIR_BAR(1);
+			reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
+							 &rid,
 							 RF_ACTIVE);
 
-			if (!sc->reg) {
+			if (!reg) {
 				device_printf(dev, "unable to map register space\n");
 				pci_write_config(dev, PCIR_COMMAND, data, 2);
-				free(sc, M_DEVBUF);
 				return ENXIO;
 			}
 
@@ -634,17 +601,16 @@
 			 * before checking mixer is present or not.
 			 * t.ichinoseki@nifty.com.
 			 */
-			nm_wr(sc, 0, 0x11, 1); /* reset device */
-			if ((nm_rd(sc, NM_MIXER_PRESENCE, 2) &
+			bus_write_1(reg, 0, 0x11); /* reset device */
+			if ((bus_read_2(reg, NM_MIXER_PRESENCE) &
 				NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
 				i = 0;	/* non-ac97 card, but not listed */
 				DEB(device_printf(dev, "subdev = 0x%x - badcard?\n",
 				    subdev));
 			}
 			pci_write_config(dev, PCIR_COMMAND, data, 2);
-			bus_release_resource(dev, SYS_RES_MEMORY, sc->regid,
-					     sc->reg);
-			free(sc, M_DEVBUF);
+			bus_release_resource(dev, SYS_RES_MEMORY, rid,
+					     reg);
 		}
 
 		if (i == NUM_BADCARDS)
@@ -666,7 +632,6 @@
 static int
 nm_pci_attach(device_t dev)
 {
-	u_int32_t	data;
 	struct sc_info *sc;
 	struct ac97_info *codec = 0;
 	char 		status[SND_STATUSLEN];
@@ -675,20 +640,11 @@
 	sc->dev = dev;
 	sc->type = pci_get_devid(dev);
 
-	data = pci_read_config(dev, PCIR_COMMAND, 2);
-	data |= (PCIM_CMD_PORTEN|PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
-	pci_write_config(dev, PCIR_COMMAND, data, 2);
-	data = pci_read_config(dev, PCIR_COMMAND, 2);
+	pci_enable_busmaster(dev);
+	pci_enable_io(dev, SYS_RES_MEMORY);
 
-	sc->bufid = PCIR_BAR(0);
-	sc->buf = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->bufid,
-					 RF_ACTIVE);
-	sc->regid = PCIR_BAR(1);
-	sc->reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->regid,
-					 RF_ACTIVE);
-
-	if (!sc->buf || !sc->reg) {
-		device_printf(dev, "unable to map register space\n");
+	if (bus_alloc_resources(dev, nm_res_spec, sc->res) != 0) {
+		device_printf(dev, "unable to allocate resources\n");
 		goto bad;
 	}
 
@@ -701,17 +657,16 @@
 	if (codec == NULL) goto bad;
 	if (mixer_init(dev, ac97_getmixerclass(), codec) == -1) goto bad;
 
-	sc->irqid = 0;
-	sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqid,
-					 RF_ACTIVE | RF_SHAREABLE);
-	if (!sc->irq || snd_setup_intr(dev, sc->irq, 0, nm_intr, sc, &sc->ih)) {
+	if (snd_setup_intr(dev, sc->res[RES_IRQ], 0, nm_intr, sc, &sc->ih)) {
 		device_printf(dev, "unable to map interrupt\n");
 		goto bad;
 	}
 
 	snprintf(status, SND_STATUSLEN, "at memory 0x%lx, 0x%lx irq %ld %s",
-		 rman_get_start(sc->buf), rman_get_start(sc->reg),
-		 rman_get_start(sc->irq),PCM_KLDSTRING(snd_neomagic));
+		 rman_get_start(sc->res[RES_BUF]), 
+		 rman_get_start(sc->res[RES_REG]),
+		 rman_get_start(sc->res[RES_IRQ]),
+		 PCM_KLDSTRING(snd_neomagic));
 
 	if (pcm_register(dev, sc, 1, 1)) goto bad;
 	pcm_addchan(dev, PCMDIR_REC, &nmchan_class, sc);
@@ -722,11 +677,8 @@
 
 bad:
 	if (codec) ac97_destroy(codec);
-	if (sc->buf) bus_release_resource(dev, SYS_RES_MEMORY, sc->bufid, sc->buf);
-	if (sc->reg) bus_release_resource(dev, SYS_RES_MEMORY, sc->regid, sc->reg);
-	if (sc->ih) bus_teardown_intr(dev, sc->irq, sc->ih);
-	if (sc->irq) bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq);
-	free(sc, M_DEVBUF);
+	nm_destroy(dev, sc);
+
 	return ENXIO;
 }
 
@@ -741,11 +693,7 @@
 		return r;
 
 	sc = pcm_getdevinfo(dev);
-	bus_release_resource(dev, SYS_RES_MEMORY, sc->bufid, sc->buf);
-	bus_release_resource(dev, SYS_RES_MEMORY, sc->regid, sc->reg);
-	bus_teardown_intr(dev, sc->irq, sc->ih);
-	bus_release_resource(dev, SYS_RES_IRQ, sc->irqid, sc->irq);
-	free(sc, M_DEVBUF);
+	nm_destroy(dev, sc);
 
 	return 0;
 }
@@ -759,12 +707,12 @@
 
 	/* stop playing */
 	if (sc->pch.active) {
-		nm_wr(sc, NM_PLAYBACK_ENABLE_REG, 0, 1);
-		nm_wr(sc, NM_AUDIO_MUTE_REG, NM_AUDIO_MUTE_BOTH, 2);
+		nm_wr1(sc, NM_PLAYBACK_ENABLE_REG, 0);
+		nm_wr2(sc, NM_AUDIO_MUTE_REG, NM_AUDIO_MUTE_BOTH);
 	}
 	/* stop recording */
 	if (sc->rch.active) {
-		nm_wr(sc, NM_RECORD_ENABLE_REG, 0, 1);
+		nm_wr1(sc, NM_RECORD_ENABLE_REG, 0);
 	}
 	return 0;
 }
@@ -784,8 +732,8 @@
 	 * As a result of this inconsistency, periodic noise will be
 	 * generated while playing.
 	 */
-	nm_wr(sc, 0, 0x11, 1);
-	nm_wr(sc, 0x214, 0, 2);
+	nm_wr1(sc, 0, 0x11);
+	nm_wr2(sc, 0x214, 0);
 
 	/* Reinit mixer */
     	if (mixer_reinit(dev) == -1) {
@@ -794,14 +742,14 @@
 	}
 	/* restart playing */
 	if (sc->pch.active) {
-		nm_wr(sc, NM_PLAYBACK_ENABLE_REG, NM_PLAYBACK_FREERUN |
-			  NM_PLAYBACK_ENABLE_FLAG, 1);
-		nm_wr(sc, NM_AUDIO_MUTE_REG, 0, 2);
+		nm_wr1(sc, NM_PLAYBACK_ENABLE_REG, NM_PLAYBACK_FREERUN |
+			  NM_PLAYBACK_ENABLE_FLAG);
+		nm_wr2(sc, NM_AUDIO_MUTE_REG, 0);
 	}
 	/* restart recording */
 	if (sc->rch.active) {
-		nm_wr(sc, NM_RECORD_ENABLE_REG, NM_RECORD_FREERUN |
-			  NM_RECORD_ENABLE_FLAG, 1);
+		nm_wr1(sc, NM_RECORD_ENABLE_REG, NM_RECORD_FREERUN |
+			  NM_RECORD_ENABLE_FLAG);
 	}
 	return 0;
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707281356.l6SDuUMX003086>