From 6419d0b0e4d646339818b92e9585491d3375fecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Schmidt?= Date: Mon, 25 Aug 2003 11:13:04 +0000 Subject: [PATCH] Cleanup the dma int/alloc/free code. --- sys/dev/ata/ata-all.h | 2 +- sys/dev/ata/ata-chipset.c | 35 +++++------- sys/dev/ata/ata-dma.c | 110 ++++++++++++++++---------------------- sys/dev/ata/ata-pci.c | 17 +++--- sys/dev/ata/ata-pci.h | 4 +- 5 files changed, 71 insertions(+), 97 deletions(-) diff --git a/sys/dev/ata/ata-all.h b/sys/dev/ata/ata-all.h index a012e3ec498d..da5a14202631 100644 --- a/sys/dev/ata/ata-all.h +++ b/sys/dev/ata/ata-all.h @@ -251,7 +251,7 @@ struct ata_dma { #define ATA_DMA_ACTIVE 0x01 /* DMA transfer in progress */ #define ATA_DMA_READ 0x02 /* transaction is a read */ - int (*alloc)(struct ata_channel *ch); + void (*alloc)(struct ata_channel *ch); void (*free)(struct ata_channel *ch); int (*setup)(struct ata_device *atadev, caddr_t data, int32_t count); int (*start)(struct ata_channel *ch, caddr_t data, int32_t count, int dir); diff --git a/sys/dev/ata/ata-chipset.c b/sys/dev/ata/ata-chipset.c index 85a1634a08bc..b2266d50bf56 100644 --- a/sys/dev/ata/ata-chipset.c +++ b/sys/dev/ata/ata-chipset.c @@ -89,10 +89,10 @@ static void ata_promise_old_intr(void *); static void ata_promise_tx2_intr(void *); static void ata_promise_mio_intr(void *); static void ata_promise_setmode(struct ata_device *, int); -static int ata_promise_new_dmainit(struct ata_channel *); +static void ata_promise_new_dmainit(struct ata_channel *); static int ata_promise_new_dmastart(struct ata_channel *, caddr_t, int32_t,int); static int ata_promise_new_dmastop(struct ata_channel *); -static int ata_promise_mio_dmainit(struct ata_channel *); +static void ata_promise_mio_dmainit(struct ata_channel *); static int ata_promise_mio_dmastart(struct ata_channel *, caddr_t, int32_t,int); static int ata_promise_mio_dmastop(struct ata_channel *); static int ata_serverworks_chipinit(device_t); @@ -1346,18 +1346,14 @@ ata_promise_setmode(struct ata_device *atadev, int mode) return; } -static int +static void ata_promise_new_dmainit(struct ata_channel *ch) { - int error; - - if ((error = ata_dmainit(ch))) - return error; - - ch->dma->start = ata_promise_new_dmastart; - ch->dma->stop = ata_promise_new_dmastop; - - return 0; + ata_dmainit(ch); + if (ch->dma) { + ch->dma->start = ata_promise_new_dmastart; + ch->dma->stop = ata_promise_new_dmastop; + } } static int @@ -1404,17 +1400,14 @@ ata_promise_new_dmastop(struct ata_channel *ch) return error; } -static int +static void ata_promise_mio_dmainit(struct ata_channel *ch) { - int error; - - if ((error = ata_dmainit(ch))) - return error; - - ch->dma->start = ata_promise_mio_dmastart; - ch->dma->stop = ata_promise_mio_dmastop; - return 0; + ata_dmainit(ch); + if (ch->dma) { + ch->dma->start = ata_promise_mio_dmastart; + ch->dma->stop = ata_promise_mio_dmastop; + } } static int diff --git a/sys/dev/ata/ata-dma.c b/sys/dev/ata/ata-dma.c index 97a136c7ad52..a6a3be49bce6 100644 --- a/sys/dev/ata/ata-dma.c +++ b/sys/dev/ata/ata-dma.c @@ -46,8 +46,7 @@ __FBSDID("$FreeBSD$"); #include /* prototypes */ -static void ata_dmasetupc_cb(void *, bus_dma_segment_t *, int, int); -static int ata_dmaalloc(struct ata_channel *); +static void ata_dmaalloc(struct ata_channel *); static void ata_dmafree(struct ata_channel *); static void ata_dmasetupd_cb(void *, bus_dma_segment_t *, int, int); static int ata_dmasetup(struct ata_device *, caddr_t, int32_t); @@ -65,20 +64,18 @@ struct ata_dc_cb_args { int error; }; -int +void ata_dmainit(struct ata_channel *ch) { - if (!(ch->dma = - malloc(sizeof(struct ata_dma), M_ATADMA, M_NOWAIT | M_ZERO))) - return ENOMEM; - ch->dma->alloc = ata_dmaalloc; - ch->dma->free = ata_dmafree; - ch->dma->setup = ata_dmasetup; - ch->dma->start = ata_dmastart; - ch->dma->stop = ata_dmastop; - ch->dma->alignment = 2; - ch->dma->max_iosize = 64*1024; - return 0; + if ((ch->dma = malloc(sizeof(struct ata_dma), M_ATADMA, M_NOWAIT|M_ZERO))) { + ch->dma->alloc = ata_dmaalloc; + ch->dma->free = ata_dmafree; + ch->dma->setup = ata_dmasetup; + ch->dma->start = ata_dmastart; + ch->dma->stop = ata_dmastop; + ch->dma->alignment = 2; + ch->dma->max_iosize = 64*1024; + } } @@ -91,61 +88,48 @@ ata_dmasetupc_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error) cba->maddr = segs[0].ds_addr; } -static int +static void ata_dmaalloc(struct ata_channel *ch) { struct ata_dc_cb_args ccba; - int error; - if (!ch->dma->dmatag) { - if (bus_dma_tag_create(NULL, 1, 0, - BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, - NULL, NULL, MAXCTLDMASZ, ATA_DMA_ENTRIES, - BUS_SPACE_MAXSIZE_32BIT, 0, NULL, NULL, - &ch->dma->dmatag)) { - ata_printf(ch, -1, - "WARNING - DMA tag allocation failed, disabling DMA\n"); - } - } - if (!ch->dma->cdmatag) { - if ((error = bus_dma_tag_create(ch->dma->dmatag, 1, PAGE_SIZE, - BUS_SPACE_MAXADDR_32BIT, - BUS_SPACE_MAXADDR, NULL, NULL, - MAXTABSZ, 1, MAXTABSZ, - BUS_DMA_ALLOCNOW, NULL, NULL, - &ch->dma->cdmatag))) - return error; - } - if (!ch->dma->ddmatag) { - if ((error = bus_dma_tag_create(ch->dma->dmatag, ch->dma->alignment, 0, - BUS_SPACE_MAXADDR_32BIT, - BUS_SPACE_MAXADDR, NULL, NULL, - MAXPHYS, ATA_DMA_ENTRIES, MAXSEGSZ, - BUS_DMA_ALLOCNOW, NULL, NULL, - &ch->dma->ddmatag))) - return error; - } - if (!ch->dma->mdmatab) { - if ((error = bus_dmamem_alloc(ch->dma->cdmatag, - (void **)&ch->dma->dmatab, 0, - &ch->dma->cdmamap))) - return error; + if (bus_dma_tag_create(NULL, 1, 0, BUS_SPACE_MAXADDR_32BIT, + BUS_SPACE_MAXADDR, NULL, NULL, MAXCTLDMASZ, + ATA_DMA_ENTRIES, BUS_SPACE_MAXSIZE_32BIT, 0, + NULL, NULL, &ch->dma->dmatag)) + goto error; - if ((error = bus_dmamap_load(ch->dma->cdmatag, ch->dma->cdmamap, - ch->dma->dmatab, MAXTABSZ, - ata_dmasetupc_cb, &ccba, 0)) != 0 || - ccba.error != 0) { - bus_dmamem_free(ch->dma->cdmatag, ch->dma->dmatab,ch->dma->cdmamap); - return error; - } - ch->dma->mdmatab = ccba.maddr; + if (bus_dma_tag_create(ch->dma->dmatag, 1, PAGE_SIZE, + BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, + NULL, NULL, MAXTABSZ, 1, MAXTABSZ, BUS_DMA_ALLOCNOW, + NULL, NULL, &ch->dma->cdmatag)) + goto error; + + if (bus_dma_tag_create(ch->dma->dmatag, ch->dma->alignment, 0, + BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, + NULL, NULL, MAXPHYS, ATA_DMA_ENTRIES, MAXSEGSZ, + BUS_DMA_ALLOCNOW, NULL, NULL, &ch->dma->ddmatag)) + goto error; + + if (bus_dmamem_alloc(ch->dma->cdmatag, (void **)&ch->dma->dmatab, 0, + &ch->dma->cdmamap)) + goto error; + + if (bus_dmamap_load(ch->dma->cdmatag, ch->dma->cdmamap, ch->dma->dmatab, + MAXTABSZ, ata_dmasetupc_cb, &ccba, 0) || ccba.error) { + bus_dmamem_free(ch->dma->cdmatag, ch->dma->dmatab,ch->dma->cdmamap); + goto error; } - if (!ch->dma->ddmamap) { - if ((error = bus_dmamap_create(ch->dma->ddmatag, 0, - &ch->dma->ddmamap)) != 0) - return error; - } - return 0; + ch->dma->mdmatab = ccba.maddr; + if (bus_dmamap_create(ch->dma->ddmatag, 0, &ch->dma->ddmamap)) + goto error; + return; + +error: + ata_printf(ch, -1, "WARNING - DMA tag allocation failed, disabling DMA\n"); + ata_dmafree(ch); + free(ch->dma, M_ATADMA); + ch->dma = NULL; } static void diff --git a/sys/dev/ata/ata-pci.c b/sys/dev/ata/ata-pci.c index 6a4352b12b61..18fdfb1c2a87 100644 --- a/sys/dev/ata/ata-pci.c +++ b/sys/dev/ata/ata-pci.c @@ -57,7 +57,7 @@ static MALLOC_DEFINE(M_ATAPCI, "ATA PCI", "ATA driver PCI"); /* prototypes */ static int ata_pci_allocate(device_t, struct ata_channel *); -static int ata_pci_dmainit(struct ata_channel *); +static void ata_pci_dmainit(struct ata_channel *); static void ata_pci_locknoop(struct ata_channel *, int); static int @@ -438,17 +438,14 @@ ata_pci_dmastop(struct ata_channel *ch) return error; } -static int +static void ata_pci_dmainit(struct ata_channel *ch) { - int error; - - if ((error = ata_dmainit(ch))) - return error; - - ch->dma->start = ata_pci_dmastart; - ch->dma->stop = ata_pci_dmastop; - return 0; + ata_dmainit(ch); + if (ch->dma) { + ch->dma->start = ata_pci_dmastart; + ch->dma->stop = ata_pci_dmastop; + } } static void diff --git a/sys/dev/ata/ata-pci.h b/sys/dev/ata/ata-pci.h index aaab23c419a5..8c584a9788d0 100644 --- a/sys/dev/ata/ata-pci.h +++ b/sys/dev/ata/ata-pci.h @@ -47,7 +47,7 @@ struct ata_pci_controller { struct ata_chip_id *chip; int (*chipinit)(device_t); int (*allocate)(device_t, struct ata_channel *); - int (*dmainit)(struct ata_channel *); + void (*dmainit)(struct ata_channel *); void (*setmode)(struct ata_device *, int); void (*locking)(struct ata_channel *, int); int locked_ch; @@ -271,7 +271,7 @@ struct ata_pci_controller { #define VIABUG 0x10 /* global prototypes */ -int ata_dmainit(struct ata_channel *); +void ata_dmainit(struct ata_channel *); int ata_dmastart(struct ata_channel *, caddr_t, int32_t, int); int ata_dmastop(struct ata_channel *);