PERFORCE change 124420 for review
Christopher Davis
loafier at FreeBSD.org
Tue Jul 31 13:42:43 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=124420
Change 124420 by loafier at chrisdsoc on 2007/07/31 13:41:49
Use bus_alloc_resources(), update read/write functions.
Affected files ...
.. //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/emu10kx.c#2 edit
Differences ...
==== //depot/projects/soc2007/loafier_busalloc/src/sys/dev/sound/pci/emu10kx.c#2 (text+ko) ====
@@ -280,6 +280,18 @@
uint32_t(*irq_func) (void *softc, uint32_t irq);
};
+enum {
+ RES_MEM,
+ RES_IRQ,
+ RES_SZ
+};
+
+static struct resource_spec emu_res_spec[] = {
+ {SYS_RES_IOPORT, PCIR_BAR(0), RF_ACTIVE},
+ {SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE},
+ {-1, 0, 0}
+};
+
struct emu_sc_info {
struct mtx lock;
struct mtx rw; /* Hardware exclusive access lock */
@@ -291,9 +303,6 @@
uint32_t type;
uint32_t rev;
- bus_space_tag_t st;
- bus_space_handle_t sh;
-
struct cdev *cdev; /* /dev/emu10k character device */
struct mtx emu10kx_lock;
int emu10kx_isopen;
@@ -302,8 +311,7 @@
/* Resources */
- struct resource *reg;
- struct resource *irq;
+ struct resource *res[RES_SZ];
void *ih;
/* IRQ handlers */
@@ -556,11 +564,11 @@
KASSERT(sc != NULL, ("emu_rd: NULL sc"));
switch (size) {
case 1:
- return (bus_space_read_1(sc->st, sc->sh, regno));
+ return (bus_read_1(sc->res[RES_MEM], regno));
case 2:
- return (bus_space_read_2(sc->st, sc->sh, regno));
+ return (bus_read_2(sc->res[RES_MEM], regno));
case 4:
- return (bus_space_read_4(sc->st, sc->sh, regno));
+ return (bus_read_4(sc->res[RES_MEM], regno));
}
return (0xffffffff);
}
@@ -572,13 +580,13 @@
KASSERT(sc != NULL, ("emu_rd: NULL sc"));
switch (size) {
case 1:
- bus_space_write_1(sc->st, sc->sh, regno, data);
+ bus_write_1(sc->res[RES_MEM], regno, data);
break;
case 2:
- bus_space_write_2(sc->st, sc->sh, regno, data);
+ bus_write_2(sc->res[RES_MEM], regno, data);
break;
case 4:
- bus_space_write_4(sc->st, sc->sh, regno, data);
+ bus_write_4(sc->res[RES_MEM], regno, data);
break;
}
}
@@ -2697,7 +2705,6 @@
struct emu_sc_info *sc;
struct emu_pcminfo *pcminfo;
struct emu_midiinfo *midiinfo[3];
- uint32_t data;
int i;
int device_flags;
char status[255];
@@ -2811,28 +2818,19 @@
if (sc->opcode_shift == 0)
goto bad;
- data = pci_read_config(dev, PCIR_COMMAND, 2);
- data |= (PCIM_CMD_PORTEN | 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_IOPORT);
- i = PCIR_BAR(0);
- sc->reg = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &i, RF_ACTIVE);
- if (sc->reg == NULL) {
- device_printf(dev, "unable to map register space\n");
+ if (bus_alloc_resources(dev, emu_res_spec, sc->res) != 0) {
+ device_printf(dev, "unable to allocate resources\n");
goto bad;
}
- sc->st = rman_get_bustag(sc->reg);
- sc->sh = rman_get_bushandle(sc->reg);
for (i = 0; i < EMU_MAX_IRQ_CONSUMERS; i++)
sc->timer[i] = 0; /* disable it */
- i = 0;
- sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &i, RF_ACTIVE | RF_SHAREABLE);
- if ((sc->irq == NULL) || snd_setup_intr(dev, sc->irq, INTR_MPSAFE, emu_intr, sc, &sc->ih)) {
+ if (snd_setup_intr(dev, sc->res[RES_IRQ], INTR_MPSAFE,
+ emu_intr, sc, &sc->ih)) {
device_printf(dev, "unable to map interrupt\n");
goto bad;
}
@@ -2859,7 +2857,10 @@
device_printf(dev, "unable to create control device\n");
goto bad;
}
- snprintf(status, 255, "rev %d at io 0x%lx irq %ld", sc->rev, rman_get_start(sc->reg), rman_get_start(sc->irq));
+ snprintf(status, 255, "rev %d at io 0x%lx irq %ld",
+ sc->rev,
+ rman_get_start(sc->res[RES_MEM]),
+ rman_get_start(sc->res[RES_IRQ]));
/* Voices */
for (i = 0; i < NUM_G; i++) {
@@ -3052,12 +3053,9 @@
emu10kx_dev_uninit(sc);
if (sc->rm != NULL)
emu_rm_uninit(sc);
- if (sc->reg)
- bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(0), sc->reg);
if (sc->ih)
- bus_teardown_intr(dev, sc->irq, sc->ih);
- if (sc->irq)
- bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
+ bus_teardown_intr(dev, sc->res[RES_IRQ], sc->ih);
+ bus_release_resources(dev, emu_res_spec, sc->res);
mtx_destroy(&sc->lock);
mtx_destroy(&sc->rw);
return (error);
@@ -3104,10 +3102,8 @@
if (sc->mem.dmat)
bus_dma_tag_destroy(sc->mem.dmat);
- if (sc->reg)
- bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(0), sc->reg);
- bus_teardown_intr(dev, sc->irq, sc->ih);
- bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
+ bus_teardown_intr(dev, sc->res[RES_IRQ], sc->ih);
+ bus_release_resources(dev, emu_res_spec, sc->res);
mtx_destroy(&sc->lock);
mtx_destroy(&sc->rw);
return (bus_generic_detach(dev));
More information about the p4-projects
mailing list