1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-18 10:35:55 +00:00

Cleanup the dma int/alloc/free code.

This commit is contained in:
Søren Schmidt 2003-08-25 11:13:04 +00:00
parent a7b60ab26e
commit 6419d0b0e4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=119453
5 changed files with 71 additions and 97 deletions

View File

@ -251,7 +251,7 @@ struct ata_dma {
#define ATA_DMA_ACTIVE 0x01 /* DMA transfer in progress */ #define ATA_DMA_ACTIVE 0x01 /* DMA transfer in progress */
#define ATA_DMA_READ 0x02 /* transaction is a read */ #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); void (*free)(struct ata_channel *ch);
int (*setup)(struct ata_device *atadev, caddr_t data, int32_t count); 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); int (*start)(struct ata_channel *ch, caddr_t data, int32_t count, int dir);

View File

@ -89,10 +89,10 @@ static void ata_promise_old_intr(void *);
static void ata_promise_tx2_intr(void *); static void ata_promise_tx2_intr(void *);
static void ata_promise_mio_intr(void *); static void ata_promise_mio_intr(void *);
static void ata_promise_setmode(struct ata_device *, int); 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_dmastart(struct ata_channel *, caddr_t, int32_t,int);
static int ata_promise_new_dmastop(struct ata_channel *); 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_dmastart(struct ata_channel *, caddr_t, int32_t,int);
static int ata_promise_mio_dmastop(struct ata_channel *); static int ata_promise_mio_dmastop(struct ata_channel *);
static int ata_serverworks_chipinit(device_t); static int ata_serverworks_chipinit(device_t);
@ -1346,18 +1346,14 @@ ata_promise_setmode(struct ata_device *atadev, int mode)
return; return;
} }
static int static void
ata_promise_new_dmainit(struct ata_channel *ch) ata_promise_new_dmainit(struct ata_channel *ch)
{ {
int error; ata_dmainit(ch);
if (ch->dma) {
if ((error = ata_dmainit(ch)))
return error;
ch->dma->start = ata_promise_new_dmastart; ch->dma->start = ata_promise_new_dmastart;
ch->dma->stop = ata_promise_new_dmastop; ch->dma->stop = ata_promise_new_dmastop;
}
return 0;
} }
static int static int
@ -1404,17 +1400,14 @@ ata_promise_new_dmastop(struct ata_channel *ch)
return error; return error;
} }
static int static void
ata_promise_mio_dmainit(struct ata_channel *ch) ata_promise_mio_dmainit(struct ata_channel *ch)
{ {
int error; ata_dmainit(ch);
if (ch->dma) {
if ((error = ata_dmainit(ch)))
return error;
ch->dma->start = ata_promise_mio_dmastart; ch->dma->start = ata_promise_mio_dmastart;
ch->dma->stop = ata_promise_mio_dmastop; ch->dma->stop = ata_promise_mio_dmastop;
return 0; }
} }
static int static int

View File

@ -46,8 +46,7 @@ __FBSDID("$FreeBSD$");
#include <dev/ata/ata-pci.h> #include <dev/ata/ata-pci.h>
/* prototypes */ /* prototypes */
static void ata_dmasetupc_cb(void *, bus_dma_segment_t *, int, int); static void ata_dmaalloc(struct ata_channel *);
static int ata_dmaalloc(struct ata_channel *);
static void ata_dmafree(struct ata_channel *); static void ata_dmafree(struct ata_channel *);
static void ata_dmasetupd_cb(void *, bus_dma_segment_t *, int, int); static void ata_dmasetupd_cb(void *, bus_dma_segment_t *, int, int);
static int ata_dmasetup(struct ata_device *, caddr_t, int32_t); static int ata_dmasetup(struct ata_device *, caddr_t, int32_t);
@ -65,12 +64,10 @@ struct ata_dc_cb_args {
int error; int error;
}; };
int void
ata_dmainit(struct ata_channel *ch) ata_dmainit(struct ata_channel *ch)
{ {
if (!(ch->dma = if ((ch->dma = malloc(sizeof(struct ata_dma), M_ATADMA, M_NOWAIT|M_ZERO))) {
malloc(sizeof(struct ata_dma), M_ATADMA, M_NOWAIT | M_ZERO)))
return ENOMEM;
ch->dma->alloc = ata_dmaalloc; ch->dma->alloc = ata_dmaalloc;
ch->dma->free = ata_dmafree; ch->dma->free = ata_dmafree;
ch->dma->setup = ata_dmasetup; ch->dma->setup = ata_dmasetup;
@ -78,7 +75,7 @@ ata_dmainit(struct ata_channel *ch)
ch->dma->stop = ata_dmastop; ch->dma->stop = ata_dmastop;
ch->dma->alignment = 2; ch->dma->alignment = 2;
ch->dma->max_iosize = 64*1024; ch->dma->max_iosize = 64*1024;
return 0; }
} }
@ -91,61 +88,48 @@ ata_dmasetupc_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
cba->maddr = segs[0].ds_addr; cba->maddr = segs[0].ds_addr;
} }
static int static void
ata_dmaalloc(struct ata_channel *ch) ata_dmaalloc(struct ata_channel *ch)
{ {
struct ata_dc_cb_args ccba; struct ata_dc_cb_args ccba;
int error;
if (!ch->dma->dmatag) { if (bus_dma_tag_create(NULL, 1, 0, BUS_SPACE_MAXADDR_32BIT,
if (bus_dma_tag_create(NULL, 1, 0, BUS_SPACE_MAXADDR, NULL, NULL, MAXCTLDMASZ,
ATA_DMA_ENTRIES, BUS_SPACE_MAXSIZE_32BIT, 0,
NULL, NULL, &ch->dma->dmatag))
goto error;
if (bus_dma_tag_create(ch->dma->dmatag, 1, PAGE_SIZE,
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
NULL, NULL, MAXCTLDMASZ, ATA_DMA_ENTRIES, NULL, NULL, MAXTABSZ, 1, MAXTABSZ, BUS_DMA_ALLOCNOW,
BUS_SPACE_MAXSIZE_32BIT, 0, NULL, NULL, NULL, NULL, &ch->dma->cdmatag))
&ch->dma->dmatag)) { goto error;
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 ((error = bus_dmamap_load(ch->dma->cdmatag, ch->dma->cdmamap, if (bus_dma_tag_create(ch->dma->dmatag, ch->dma->alignment, 0,
ch->dma->dmatab, MAXTABSZ, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
ata_dmasetupc_cb, &ccba, 0)) != 0 || NULL, NULL, MAXPHYS, ATA_DMA_ENTRIES, MAXSEGSZ,
ccba.error != 0) { 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); bus_dmamem_free(ch->dma->cdmatag, ch->dma->dmatab,ch->dma->cdmamap);
return error; goto error;
} }
ch->dma->mdmatab = ccba.maddr; ch->dma->mdmatab = ccba.maddr;
} if (bus_dmamap_create(ch->dma->ddmatag, 0, &ch->dma->ddmamap))
if (!ch->dma->ddmamap) { goto error;
if ((error = bus_dmamap_create(ch->dma->ddmatag, 0, return;
&ch->dma->ddmamap)) != 0)
return error; error:
} ata_printf(ch, -1, "WARNING - DMA tag allocation failed, disabling DMA\n");
return 0; ata_dmafree(ch);
free(ch->dma, M_ATADMA);
ch->dma = NULL;
} }
static void static void

View File

@ -57,7 +57,7 @@ static MALLOC_DEFINE(M_ATAPCI, "ATA PCI", "ATA driver PCI");
/* prototypes */ /* prototypes */
static int ata_pci_allocate(device_t, struct ata_channel *); 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 void ata_pci_locknoop(struct ata_channel *, int);
static int static int
@ -438,17 +438,14 @@ ata_pci_dmastop(struct ata_channel *ch)
return error; return error;
} }
static int static void
ata_pci_dmainit(struct ata_channel *ch) ata_pci_dmainit(struct ata_channel *ch)
{ {
int error; ata_dmainit(ch);
if (ch->dma) {
if ((error = ata_dmainit(ch)))
return error;
ch->dma->start = ata_pci_dmastart; ch->dma->start = ata_pci_dmastart;
ch->dma->stop = ata_pci_dmastop; ch->dma->stop = ata_pci_dmastop;
return 0; }
} }
static void static void

View File

@ -47,7 +47,7 @@ struct ata_pci_controller {
struct ata_chip_id *chip; struct ata_chip_id *chip;
int (*chipinit)(device_t); int (*chipinit)(device_t);
int (*allocate)(device_t, struct ata_channel *); int (*allocate)(device_t, struct ata_channel *);
int (*dmainit)(struct ata_channel *); void (*dmainit)(struct ata_channel *);
void (*setmode)(struct ata_device *, int); void (*setmode)(struct ata_device *, int);
void (*locking)(struct ata_channel *, int); void (*locking)(struct ata_channel *, int);
int locked_ch; int locked_ch;
@ -271,7 +271,7 @@ struct ata_pci_controller {
#define VIABUG 0x10 #define VIABUG 0x10
/* global prototypes */ /* 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_dmastart(struct ata_channel *, caddr_t, int32_t, int);
int ata_dmastop(struct ata_channel *); int ata_dmastop(struct ata_channel *);