svn commit: r235200 - projects/altix2/sys/dev/mpt
Marcel Moolenaar
marcel at FreeBSD.org
Wed May 9 16:57:09 UTC 2012
Author: marcel
Date: Wed May 9 16:57:09 2012
New Revision: 235200
URL: http://svn.freebsd.org/changeset/base/235200
Log:
Convert the request buffer to busdma/mi. Since we don't have a dmamap
for allocated memory, compile it out entirely. This also exposes the
places where we call bus_dmamap_sync(), which is a good open item to
have next.
Modified:
projects/altix2/sys/dev/mpt/mpt.c
projects/altix2/sys/dev/mpt/mpt.h
projects/altix2/sys/dev/mpt/mpt_pci.c
Modified: projects/altix2/sys/dev/mpt/mpt.c
==============================================================================
--- projects/altix2/sys/dev/mpt/mpt.c Wed May 9 16:06:20 2012 (r235199)
+++ projects/altix2/sys/dev/mpt/mpt.c Wed May 9 16:57:09 2012 (r235200)
@@ -742,9 +742,12 @@ mpt_intr(void *arg)
*/
reply_baddr = MPT_REPLY_BADDR(reply_desc);
offset = reply_baddr - (mpt->reply_phys & 0xFFFFFFFF);
+#ifdef MPT_USE_BUSDMA
+#else
bus_dmamap_sync_range(mpt->reply_dmat,
mpt->reply_dmap, offset, MPT_REPLY_SIZE,
BUS_DMASYNC_POSTREAD);
+#endif
reply_frame = MPT_REPLY_OTOV(mpt, offset);
ctxt_idx = le32toh(reply_frame->MsgContext);
} else {
@@ -820,15 +823,21 @@ mpt_intr(void *arg)
" 0x%x)\n", req_index, reply_desc);
}
+#ifdef MPT_USE_BUSDMA
+#else
bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
+#endif
free_rf = mpt_reply_handlers[cb_index](mpt, req,
reply_desc, reply_frame);
if (reply_frame != NULL && free_rf) {
+#ifdef MPT_USE_BUSDMA
+#else
bus_dmamap_sync_range(mpt->reply_dmat,
mpt->reply_dmap, offset, MPT_REPLY_SIZE,
BUS_DMASYNC_PREREAD);
+#endif
mpt_free_reply(mpt, reply_baddr);
}
@@ -861,8 +870,11 @@ mpt_complete_request_chain(struct mpt_so
MSG_REQUEST_HEADER *msg_hdr;
u_int cb_index;
+#ifdef MPT_USE_BUSDMA
+#else
bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
+#endif
msg_hdr = (MSG_REQUEST_HEADER *)req->req_vbuf;
ioc_status_frame.Function = msg_hdr->Function;
ioc_status_frame.MsgContext = msg_hdr->MsgContext;
@@ -1250,8 +1262,11 @@ mpt_free_request(struct mpt_softc *mpt,
mpt_send_event_ack(mpt, req, &record->reply, record->context);
offset = (uint32_t)((uint8_t *)record - mpt->reply);
reply_baddr = offset + (mpt->reply_phys & 0xFFFFFFFF);
+#ifdef MPT_USE_BUSDMA
+#else
bus_dmamap_sync_range(mpt->reply_dmat, mpt->reply_dmap, offset,
MPT_REPLY_SIZE, BUS_DMASYNC_PREREAD);
+#endif
mpt_free_reply(mpt, reply_baddr);
}
@@ -1291,8 +1306,11 @@ mpt_send_cmd(struct mpt_softc *mpt, requ
if (mpt->verbose > MPT_PRT_DEBUG2) {
mpt_dump_request(mpt, req);
}
+#ifdef MPT_USE_BUSDMA
+#else
bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
+#endif
req->state |= REQ_STATE_QUEUED;
KASSERT(mpt_req_on_free_list(mpt, req) == 0,
("req %p:%u func %x on freelist list in mpt_send_cmd",
@@ -2528,7 +2546,9 @@ mpt_download_fw(struct mpt_softc *mpt)
static int
mpt_dma_buf_alloc(struct mpt_softc *mpt)
{
+#ifndef MPT_USE_BUSDMA
struct mpt_map_info mi;
+#endif
uint8_t *vptr;
uint32_t pptr, end;
int i, error;
@@ -2552,6 +2572,16 @@ mpt_dma_buf_alloc(struct mpt_softc *mpt)
return (1);
}
+#ifdef MPT_USE_BUSDMA
+ error = busdma_mem_alloc((busdma_tag_t)mpt->request_dmat, 0,
+ &mpt->request_dmam);
+ if (error != 0) {
+ mpt_prt(mpt, "cannot allocate DMA memory for requests\n");
+ return (error);
+ }
+ mpt->request = (void *)busdma_mem_get_seg_addr(mpt->request_dmam, 0);
+ mpt->request_phys = busdma_mem_get_seg_busaddr(mpt->request_dmam, 0);
+#else
/* Allocate some DMA accessible memory for requests */
if (bus_dmamem_alloc(mpt->request_dmat, (void **)&mpt->request,
BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &mpt->request_dmap) != 0) {
@@ -2573,6 +2603,7 @@ mpt_dma_buf_alloc(struct mpt_softc *mpt)
return (1);
}
mpt->request_phys = mi.phys;
+#endif
/*
* Now create per-request dma maps
@@ -2618,11 +2649,14 @@ mpt_dma_buf_free(struct mpt_softc *mpt)
for (i = 0; i < MPT_MAX_REQUESTS(mpt); i++) {
bus_dmamap_destroy(mpt->buffer_dmat, mpt->request_pool[i].dmap);
}
+#ifdef MPT_USE_BUSDMA
+#else
bus_dmamap_unload(mpt->request_dmat, mpt->request_dmap);
bus_dmamem_free(mpt->request_dmat, mpt->request, mpt->request_dmap);
bus_dma_tag_destroy(mpt->request_dmat);
mpt->request_dmat = 0;
bus_dma_tag_destroy(mpt->buffer_dmat);
+#endif
}
/*
Modified: projects/altix2/sys/dev/mpt/mpt.h
==============================================================================
--- projects/altix2/sys/dev/mpt/mpt.h Wed May 9 16:06:20 2012 (r235199)
+++ projects/altix2/sys/dev/mpt/mpt.h Wed May 9 16:57:09 2012 (r235200)
@@ -752,13 +752,21 @@ struct mpt_softc {
bus_dma_tag_t parent_dmat; /* DMA tag for parent PCI bus */
bus_dma_tag_t reply_dmat; /* DMA tag for reply memory */
+#ifdef MPT_USE_BUSDMA
+ busdma_mem_t reply_dmam;
+#else
bus_dmamap_t reply_dmap; /* DMA map for reply memory */
+#endif
uint8_t *reply; /* KVA of reply memory */
bus_addr_t reply_phys; /* BusAddr of reply memory */
bus_dma_tag_t buffer_dmat; /* DMA tag for buffers */
bus_dma_tag_t request_dmat; /* DMA tag for request memroy */
+#ifdef MPT_USE_BUSDMA
+ busdma_mem_t request_dmam;
+#else
bus_dmamap_t request_dmap; /* DMA map for request memroy */
+#endif
uint8_t *request; /* KVA of Request memory */
bus_addr_t request_phys; /* BusAddr of request memory */
Modified: projects/altix2/sys/dev/mpt/mpt_pci.c
==============================================================================
--- projects/altix2/sys/dev/mpt/mpt_pci.c Wed May 9 16:06:20 2012 (r235199)
+++ projects/altix2/sys/dev/mpt/mpt_pci.c Wed May 9 16:57:09 2012 (r235200)
@@ -734,7 +734,10 @@ static int
mpt_dma_mem_alloc(struct mpt_softc *mpt)
{
size_t len;
+#ifndef MPT_USE_BUSDMA
struct mpt_map_info mi;
+#endif
+ int error;
/* Check if we alreay have allocated the reply memory */
if (mpt->reply_phys != 0) {
@@ -746,14 +749,14 @@ mpt_dma_mem_alloc(struct mpt_softc *mpt)
mpt->request_pool = (request_t *)malloc(len, M_DEVBUF, M_WAITOK);
if (mpt->request_pool == NULL) {
mpt_prt(mpt, "cannot allocate request pool\n");
- return (1);
+ return (ENOMEM);
}
memset(mpt->request_pool, 0, len);
#else
mpt->request_pool = (request_t *)malloc(len, M_DEVBUF, M_WAITOK|M_ZERO);
if (mpt->request_pool == NULL) {
mpt_prt(mpt, "cannot allocate request pool\n");
- return (1);
+ return (ENOMEM);
}
#endif
@@ -763,32 +766,45 @@ mpt_dma_mem_alloc(struct mpt_softc *mpt)
* Align at byte boundaries,
* Limit to 32-bit addressing for request/reply queues.
*/
- if (mpt_dma_tag_create(mpt, /*parent*/bus_get_dma_tag(mpt->dev),
+ error = mpt_dma_tag_create(mpt, /*parent*/bus_get_dma_tag(mpt->dev),
/*alignment*/1, /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR,
/*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL,
/*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
/*nsegments*/BUS_SPACE_UNRESTRICTED,
/*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, /*flags*/0,
- &mpt->parent_dmat) != 0) {
+ &mpt->parent_dmat);
+ if (error != 0) {
mpt_prt(mpt, "cannot create parent dma tag\n");
- return (1);
+ return (error);
}
/* Create a child tag for reply buffers */
- if (mpt_dma_tag_derive(mpt, mpt->parent_dmat, PAGE_SIZE, 0,
+ error = mpt_dma_tag_derive(mpt, mpt->parent_dmat, PAGE_SIZE, 0,
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
NULL, NULL, 2 * PAGE_SIZE, 1, BUS_SPACE_MAXSIZE_32BIT, 0,
- &mpt->reply_dmat) != 0) {
+ &mpt->reply_dmat);
+ if (error != 0) {
mpt_prt(mpt, "cannot create a dma tag for replies\n");
- return (1);
+ return (error);
}
+#ifdef MPT_USE_BUSDMA
+ error = busdma_mem_alloc((busdma_tag_t)mpt->reply_dmat, 0,
+ &mpt->reply_dmam);
+ if (error != 0) {
+ mpt_prt(mpt, "cannot allocate DMA memory for replies\n");
+ return (error);
+ }
+ mpt->reply = (void *)busdma_mem_get_seg_addr(mpt->reply_dmam, 0);
+ mpt->reply_phys = busdma_mem_get_seg_busaddr(mpt->reply_dmam, 0);
+#else
/* Allocate some DMA accessible memory for replies */
- if (bus_dmamem_alloc(mpt->reply_dmat, (void **)&mpt->reply,
- BUS_DMA_NOWAIT, &mpt->reply_dmap) != 0) {
+ error = bus_dmamem_alloc(mpt->reply_dmat, (void **)&mpt->reply,
+ BUS_DMA_NOWAIT, &mpt->reply_dmap);
+ if (error != 0) {
mpt_prt(mpt, "cannot allocate %lu bytes of reply memory\n",
(u_long) (2 * PAGE_SIZE));
- return (1);
+ return (error);
}
mi.mpt = mpt;
@@ -801,9 +817,10 @@ mpt_dma_mem_alloc(struct mpt_softc *mpt)
if (mi.error) {
mpt_prt(mpt, "error %d loading dma map for DMA reply queue\n",
mi.error);
- return (1);
+ return (mi.error);
}
mpt->reply_phys = mi.phys;
+#endif /* MPT_USE_BUSDMA */
return (0);
}
@@ -819,11 +836,13 @@ mpt_dma_mem_free(struct mpt_softc *mpt)
mpt_lprt(mpt, MPT_PRT_DEBUG, "already released dma memory\n");
return;
}
-
+#ifdef MPT_USE_BUSDMA
+#else
bus_dmamap_unload(mpt->reply_dmat, mpt->reply_dmap);
bus_dmamem_free(mpt->reply_dmat, mpt->reply, mpt->reply_dmap);
bus_dma_tag_destroy(mpt->reply_dmat);
bus_dma_tag_destroy(mpt->parent_dmat);
+#endif
mpt->reply_dmat = NULL;
free(mpt->request_pool, M_DEVBUF);
mpt->request_pool = NULL;
More information about the svn-src-projects
mailing list