1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +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_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);

View File

@ -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;
ata_dmainit(ch);
if (ch->dma) {
ch->dma->start = ata_promise_new_dmastart;
ch->dma->stop = ata_promise_new_dmastop;
return 0;
}
}
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;
ata_dmainit(ch);
if (ch->dma) {
ch->dma->start = ata_promise_mio_dmastart;
ch->dma->stop = ata_promise_mio_dmastop;
return 0;
}
}
static int

View File

@ -46,8 +46,7 @@ __FBSDID("$FreeBSD$");
#include <dev/ata/ata-pci.h>
/* 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,12 +64,10 @@ 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;
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;
@ -78,7 +75,7 @@ ata_dmainit(struct ata_channel *ch)
ch->dma->stop = ata_dmastop;
ch->dma->alignment = 2;
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;
}
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,
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 (bus_dma_tag_create(ch->dma->dmatag, 1, PAGE_SIZE,
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;
NULL, NULL, MAXTABSZ, 1, MAXTABSZ, BUS_DMA_ALLOCNOW,
NULL, NULL, &ch->dma->cdmatag))
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) {
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);
return error;
goto error;
}
ch->dma->mdmatab = ccba.maddr;
}
if (!ch->dma->ddmamap) {
if ((error = bus_dmamap_create(ch->dma->ddmatag, 0,
&ch->dma->ddmamap)) != 0)
return error;
}
return 0;
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

View File

@ -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;
ata_dmainit(ch);
if (ch->dma) {
ch->dma->start = ata_pci_dmastart;
ch->dma->stop = ata_pci_dmastop;
return 0;
}
}
static void

View File

@ -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 *);