busdma_machdep-v4.c (143284) | busdma_machdep-v4.c (143294) |
---|---|
1/*- 2 * Copyright (c) 2004 Olivier Houchard 3 * Copyright (c) 2002 Peter Grehan 4 * Copyright (c) 1997, 1998 Justin T. Gibbs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 15 unchanged lines hidden (view full) --- 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * From i386/busdma_machdep.c,v 1.26 2002/04/19 22:58:09 alfred 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2004 Olivier Houchard 3 * Copyright (c) 2002 Peter Grehan 4 * Copyright (c) 1997, 1998 Justin T. Gibbs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 15 unchanged lines hidden (view full) --- 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * From i386/busdma_machdep.c,v 1.26 2002/04/19 22:58:09 alfred 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sys/arm/arm/busdma_machdep.c 143284 2005-03-08 11:18:14Z mux $"); | 32__FBSDID("$FreeBSD: head/sys/arm/arm/busdma_machdep.c 143294 2005-03-08 14:49:05Z mux $"); |
33 34/* 35 * MacPPC bus dma support routines 36 */ 37 38#define _ARM32_BUS_DMA_PRIVATE 39#include <sys/param.h> 40#include <sys/systm.h> --- 132 unchanged lines hidden (view full) --- 173{ 174 bus_dma_tag_t newtag; 175 int error = 0; 176 /* Return a NULL tag on failure */ 177 *dmat = NULL; 178 179 newtag = (bus_dma_tag_t)malloc(sizeof(*newtag), M_DEVBUF, M_NOWAIT); 180 if (newtag == NULL) { | 33 34/* 35 * MacPPC bus dma support routines 36 */ 37 38#define _ARM32_BUS_DMA_PRIVATE 39#include <sys/param.h> 40#include <sys/systm.h> --- 132 unchanged lines hidden (view full) --- 173{ 174 bus_dma_tag_t newtag; 175 int error = 0; 176 /* Return a NULL tag on failure */ 177 *dmat = NULL; 178 179 newtag = (bus_dma_tag_t)malloc(sizeof(*newtag), M_DEVBUF, M_NOWAIT); 180 if (newtag == NULL) { |
181 CTR3(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d", | 181 CTR4(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d", |
182 __func__, newtag, 0, error); 183 return (ENOMEM); 184 } 185 186 newtag->parent = parent; 187 newtag->alignment = alignment; 188 newtag->boundary = boundary; 189 newtag->lowaddr = trunc_page((vm_offset_t)lowaddr) + (PAGE_SIZE - 1); --- 35 unchanged lines hidden (view full) --- 225 newtag->filterarg = parent->filterarg; 226 newtag->parent = parent->parent; 227 } 228 if (newtag->parent != NULL) 229 atomic_add_int(&parent->ref_count, 1); 230 } 231 232 *dmat = newtag; | 182 __func__, newtag, 0, error); 183 return (ENOMEM); 184 } 185 186 newtag->parent = parent; 187 newtag->alignment = alignment; 188 newtag->boundary = boundary; 189 newtag->lowaddr = trunc_page((vm_offset_t)lowaddr) + (PAGE_SIZE - 1); --- 35 unchanged lines hidden (view full) --- 225 newtag->filterarg = parent->filterarg; 226 newtag->parent = parent->parent; 227 } 228 if (newtag->parent != NULL) 229 atomic_add_int(&parent->ref_count, 1); 230 } 231 232 *dmat = newtag; |
233 CTR3(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d", | 233 CTR4(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d", |
234 __func__, newtag, (newtag != NULL ? newtag->flags : 0), error); 235 236 return (error); 237} 238 239int 240bus_dma_tag_destroy(bus_dma_tag_t dmat) 241{ --- 18 unchanged lines hidden (view full) --- 260 * release our reference 261 * count on our parent. 262 */ 263 dmat = parent; 264 } else 265 dmat = NULL; 266 } 267 } | 234 __func__, newtag, (newtag != NULL ? newtag->flags : 0), error); 235 236 return (error); 237} 238 239int 240bus_dma_tag_destroy(bus_dma_tag_t dmat) 241{ --- 18 unchanged lines hidden (view full) --- 260 * release our reference 261 * count on our parent. 262 */ 263 dmat = parent; 264 } else 265 dmat = NULL; 266 } 267 } |
268 CTR1(KTR_BUSDMA, "%s tag %p", __func__, dmat_copy); | 268 CTR2(KTR_BUSDMA, "%s tag %p", __func__, dmat_copy); |
269 270 return (0); 271} 272 273/* 274 * Allocate a handle for mapping from kva/uva/physical 275 * address space into bus device space. 276 */ 277int 278bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) 279{ 280 bus_dmamap_t newmap; 281#ifdef KTR 282 int error = 0; 283#endif 284 285 newmap = malloc(sizeof(*newmap), M_DEVBUF, M_NOWAIT | M_ZERO); 286 if (newmap == NULL) { | 269 270 return (0); 271} 272 273/* 274 * Allocate a handle for mapping from kva/uva/physical 275 * address space into bus device space. 276 */ 277int 278bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) 279{ 280 bus_dmamap_t newmap; 281#ifdef KTR 282 int error = 0; 283#endif 284 285 newmap = malloc(sizeof(*newmap), M_DEVBUF, M_NOWAIT | M_ZERO); 286 if (newmap == NULL) { |
287 CTR2(KTR_BUSDMA, "%s: tag %p error %d", __func__, dmat, ENOMEM); | 287 CTR3(KTR_BUSDMA, "%s: tag %p error %d", __func__, dmat, ENOMEM); |
288 return (ENOMEM); 289 } 290 *mapp = newmap; 291 newmap->dmat = dmat; 292 newmap->flags = 0; 293 dmat->map_count++; 294 | 288 return (ENOMEM); 289 } 290 *mapp = newmap; 291 newmap->dmat = dmat; 292 newmap->flags = 0; 293 dmat->map_count++; 294 |
295 CTR3(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", | 295 CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", |
296 __func__, dmat, dmat->flags, error); 297 298 return (0); 299} 300 301/* 302 * Destroy a handle for mapping from kva/uva/physical 303 * address space into bus device space. 304 */ 305int 306bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map) 307{ 308 309 free(map, M_DEVBUF); 310 dmat->map_count--; | 296 __func__, dmat, dmat->flags, error); 297 298 return (0); 299} 300 301/* 302 * Destroy a handle for mapping from kva/uva/physical 303 * address space into bus device space. 304 */ 305int 306bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map) 307{ 308 309 free(map, M_DEVBUF); 310 dmat->map_count--; |
311 CTR1(KTR_BUSDMA, "%s: tag %p error 0", __func__, dmat); | 311 CTR2(KTR_BUSDMA, "%s: tag %p error 0", __func__, dmat); |
312 return (0); 313} 314 315/* 316 * Allocate a piece of memory that can be efficiently mapped into 317 * bus device space based on the constraints lited in the dma tag. 318 * A dmamap to for use with dmamap_load is also allocated. 319 */ --- 10 unchanged lines hidden (view full) --- 330 else 331 mflags = M_WAITOK; 332 if (flags & BUS_DMA_ZERO) 333 mflags |= M_ZERO; 334 335 if (!*mapp) { 336 newmap = malloc(sizeof(*newmap), M_DEVBUF, M_NOWAIT | M_ZERO); 337 if (newmap == NULL) { | 312 return (0); 313} 314 315/* 316 * Allocate a piece of memory that can be efficiently mapped into 317 * bus device space based on the constraints lited in the dma tag. 318 * A dmamap to for use with dmamap_load is also allocated. 319 */ --- 10 unchanged lines hidden (view full) --- 330 else 331 mflags = M_WAITOK; 332 if (flags & BUS_DMA_ZERO) 333 mflags |= M_ZERO; 334 335 if (!*mapp) { 336 newmap = malloc(sizeof(*newmap), M_DEVBUF, M_NOWAIT | M_ZERO); 337 if (newmap == NULL) { |
338 CTR3(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", 339 dmat, dmat->flags, ENOMEM); | 338 CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", 339 __func__, dmat, dmat->flags, ENOMEM); |
340 return (ENOMEM); 341 } 342 dmat->map_count++; 343 newmap->flags = 0; 344 *mapp = newmap; 345 newmap->dmat = dmat; 346 } 347 --- 29 unchanged lines hidden (view full) --- 377{ 378 if (dmat->maxsize <= PAGE_SIZE) 379 free(vaddr, M_DEVBUF); 380 else { 381 contigfree(vaddr, dmat->maxsize, M_DEVBUF); 382 } 383 dmat->map_count--; 384 free(map, M_DEVBUF); | 340 return (ENOMEM); 341 } 342 dmat->map_count++; 343 newmap->flags = 0; 344 *mapp = newmap; 345 newmap->dmat = dmat; 346 } 347 --- 29 unchanged lines hidden (view full) --- 377{ 378 if (dmat->maxsize <= PAGE_SIZE) 379 free(vaddr, M_DEVBUF); 380 else { 381 contigfree(vaddr, dmat->maxsize, M_DEVBUF); 382 } 383 dmat->map_count--; 384 free(map, M_DEVBUF); |
385 CTR2(KTR_BUSDMA, "%s: tag %p flags 0x%x", __func__, dmat, dmat->flags); | 385 CTR3(KTR_BUSDMA, "%s: tag %p flags 0x%x", __func__, dmat, dmat->flags); |
386} 387 388/* 389 * Utility function to load a linear buffer. lastaddrp holds state 390 * between invocations (for multiple-buffer loads). segp contains 391 * the starting segment on entrance, and the ending segment on exit. 392 * first indicates if this is the first invocation of this function. 393 */ --- 149 unchanged lines hidden (view full) --- 543 error = bus_dmamap_load_buffer(dmat, 544 dm_segments, map, buf, buflen, kernel_pmap, 545 flags, &lastaddr, &nsegs); 546 if (error) 547 (*callback)(callback_arg, NULL, 0, error); 548 else 549 (*callback)(callback_arg, dm_segments, nsegs + 1, error); 550 | 386} 387 388/* 389 * Utility function to load a linear buffer. lastaddrp holds state 390 * between invocations (for multiple-buffer loads). segp contains 391 * the starting segment on entrance, and the ending segment on exit. 392 * first indicates if this is the first invocation of this function. 393 */ --- 149 unchanged lines hidden (view full) --- 543 error = bus_dmamap_load_buffer(dmat, 544 dm_segments, map, buf, buflen, kernel_pmap, 545 flags, &lastaddr, &nsegs); 546 if (error) 547 (*callback)(callback_arg, NULL, 0, error); 548 else 549 (*callback)(callback_arg, dm_segments, nsegs + 1, error); 550 |
551 CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", | 551 CTR5(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", |
552 __func__, dmat, dmat->flags, nsegs + 1, error); 553 554 return (0); 555} 556 557/* 558 * Like bus_dmamap_load(), but for mbufs. 559 */ --- 32 unchanged lines hidden (view full) --- 592 /* 593 * force "no valid mappings" on error in callback. 594 */ 595 (*callback)(callback_arg, dm_segments, 0, 0, error); 596 } else { 597 (*callback)(callback_arg, dm_segments, nsegs + 1, 598 m0->m_pkthdr.len, error); 599 } | 552 __func__, dmat, dmat->flags, nsegs + 1, error); 553 554 return (0); 555} 556 557/* 558 * Like bus_dmamap_load(), but for mbufs. 559 */ --- 32 unchanged lines hidden (view full) --- 592 /* 593 * force "no valid mappings" on error in callback. 594 */ 595 (*callback)(callback_arg, dm_segments, 0, 0, error); 596 } else { 597 (*callback)(callback_arg, dm_segments, nsegs + 1, 598 m0->m_pkthdr.len, error); 599 } |
600 CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", | 600 CTR5(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", |
601 __func__, dmat, dmat->flags, error, nsegs + 1); 602 603 return (error); 604} 605 606int 607bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, 608 struct mbuf *m0, bus_dma_segment_t *segs, int *nsegs, --- 20 unchanged lines hidden (view full) --- 629 } 630 } 631 } else { 632 error = EINVAL; 633 } 634 635 /* XXX FIXME: Having to increment nsegs is really annoying */ 636 ++*nsegs; | 601 __func__, dmat, dmat->flags, error, nsegs + 1); 602 603 return (error); 604} 605 606int 607bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, 608 struct mbuf *m0, bus_dma_segment_t *segs, int *nsegs, --- 20 unchanged lines hidden (view full) --- 629 } 630 } 631 } else { 632 error = EINVAL; 633 } 634 635 /* XXX FIXME: Having to increment nsegs is really annoying */ 636 ++*nsegs; |
637 CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", | 637 CTR5(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", |
638 __func__, dmat, dmat->flags, error, *nsegs); 639 return (error); 640} 641 642/* 643 * Like bus_dmamap_load(), but for uios. 644 */ 645int --- 49 unchanged lines hidden (view full) --- 695 * force "no valid mappings" on error in callback. 696 */ 697 (*callback)(callback_arg, dm_segments, 0, 0, error); 698 } else { 699 (*callback)(callback_arg, dm_segments, nsegs+1, 700 uio->uio_resid, error); 701 } 702 | 638 __func__, dmat, dmat->flags, error, *nsegs); 639 return (error); 640} 641 642/* 643 * Like bus_dmamap_load(), but for uios. 644 */ 645int --- 49 unchanged lines hidden (view full) --- 695 * force "no valid mappings" on error in callback. 696 */ 697 (*callback)(callback_arg, dm_segments, 0, 0, error); 698 } else { 699 (*callback)(callback_arg, dm_segments, nsegs+1, 700 uio->uio_resid, error); 701 } 702 |
703 CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", | 703 CTR5(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d nsegs %d", |
704 __func__, dmat, dmat->flags, error, nsegs + 1); 705 return (error); 706} 707 708/* 709 * Release the mapping held by map. 710 */ 711void --- 29 unchanged lines hidden (view full) --- 741 struct uio *uio; 742 int resid; 743 struct iovec *iov; 744 745 if (op == BUS_DMASYNC_POSTWRITE) 746 return; 747 if (map->flags & DMAMAP_COHERENT) 748 return; | 704 __func__, dmat, dmat->flags, error, nsegs + 1); 705 return (error); 706} 707 708/* 709 * Release the mapping held by map. 710 */ 711void --- 29 unchanged lines hidden (view full) --- 741 struct uio *uio; 742 int resid; 743 struct iovec *iov; 744 745 if (op == BUS_DMASYNC_POSTWRITE) 746 return; 747 if (map->flags & DMAMAP_COHERENT) 748 return; |
749 CTR2(KTR_BUSDMA, "%s: op %x flags %x", __func__, op, map->flags); | 749 CTR3(KTR_BUSDMA, "%s: op %x flags %x", __func__, op, map->flags); |
750 switch(map->flags & DMAMAP_TYPE_MASK) { 751 case DMAMAP_LINEAR: 752 bus_dmamap_sync_buf(map->buffer, map->len, op); 753 break; 754 case DMAMAP_MBUF: 755 m = map->buffer; 756 while (m) { 757 bus_dmamap_sync_buf(m->m_data, m->m_len, op); --- 22 unchanged lines hidden --- | 750 switch(map->flags & DMAMAP_TYPE_MASK) { 751 case DMAMAP_LINEAR: 752 bus_dmamap_sync_buf(map->buffer, map->len, op); 753 break; 754 case DMAMAP_MBUF: 755 m = map->buffer; 756 while (m) { 757 bus_dmamap_sync_buf(m->m_data, m->m_len, op); --- 22 unchanged lines hidden --- |