FreeBSD/sys/dev/bxe/bxe.c
/*
 * Allocate a block of memory and map it for DMA. No partial completions
 * allowed and release any resources acquired if we can't acquire all
 * resources.
 *
 * Returns:
 *   0 = Success, !0 = Failure
 */
Allocate a block of memory and map it for DMA. No partial completions
allowed and release any resources acquired if we can't acquire all
resources.

0 = Success, !0 = Failure
Allocate a block of memory and map it for DMA . No partial completions allowed and release any resources acquired if we can ' t acquire all resources . 0 = Success !0 = Failure
int
bxe_dma_alloc(struct bxe_softc *sc,
              bus_size_t       size,
              struct bxe_dma   *dma,
              const char       *msg)
{
    int rc;
    if (dma->size > 0) {
        BLOGE(sc, "dma block '%s' already has size %lu\n", msg,
              (unsigned long)dma->size);
        return (1);
    }
    memset(dma, 0, sizeof(*dma)); 
    dma->sc   = sc;
    dma->size = size;
    snprintf(dma->msg, sizeof(dma->msg), "%s", msg);
    rc = bus_dma_tag_create(sc->parent_dma_tag, 
                            BCM_PAGE_SIZE,      
                            0,                  
                            BUS_SPACE_MAXADDR,  
                            BUS_SPACE_MAXADDR,  
                            NULL,               
                            NULL,               
                            size,               
                            1,                  
                            size,               
                            BUS_DMA_ALLOCNOW,   
                            NULL,               
                            NULL,               
                            &dma->tag);         
    if (rc != 0) {
        BLOGE(sc, "Failed to create dma tag for '%s' (%d)\n", msg, rc);
        memset(dma, 0, sizeof(*dma));
        return (1);
    }
    rc = bus_dmamem_alloc(dma->tag,
                          (void **)&dma->vaddr,
                          (BUS_DMA_NOWAIT | BUS_DMA_ZERO),
                          &dma->map);
    if (rc != 0) {
        BLOGE(sc, "Failed to alloc dma mem for '%s' (%d)\n", msg, rc);
        bus_dma_tag_destroy(dma->tag);
        memset(dma, 0, sizeof(*dma));
        return (1);
    }
    rc = bus_dmamap_load(dma->tag,
                         dma->map,
                         dma->vaddr,
                         size,
                         bxe_dma_map_addr, 
                         dma,
                         BUS_DMA_NOWAIT);
    if (rc != 0) {
        BLOGE(sc, "Failed to load dma map for '%s' (%d)\n", msg, rc);
        bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
        bus_dma_tag_destroy(dma->tag);
        memset(dma, 0, sizeof(*dma));
        return (1);
    }
    return (0);
}
int bxe_dma_alloc ( struct bxe_softc * sc , bus_size_t size , struct bxe_dma * dma , const char * msg ) { int rc ; if ( dma -> size > 0 ) { BLOGE ( sc , " \n " , msg , ( unsigned long ) dma -> size ) ; return ( 1 ) ; } memset ( dma , 0 , sizeof ( * dma ) ) ; dma -> sc = sc ; dma -> size = size ; snprintf ( dma -> msg , sizeof ( dma -> msg ) , " " , msg ) ; rc = bus_dma_tag_create ( sc -> parent_dma_tag , BCM_PAGE_SIZE , 0 , BUS_SPACE_MAXADDR , BUS_SPACE_MAXADDR , NULL , NULL , size , 1 , size , BUS_DMA_ALLOCNOW , NULL , NULL , & dma -> tag ) ; if ( rc != 0 ) { BLOGE ( sc , " \n " , msg , rc ) ; memset ( dma , 0 , sizeof ( * dma ) ) ; return ( 1 ) ; } rc = bus_dmamem_alloc ( dma -> tag , ( void * * ) & dma -> vaddr , ( BUS_DMA_NOWAIT | BUS_DMA_ZERO ) , & dma -> map ) ; if ( rc != 0 ) { BLOGE ( sc , " \n " , msg , rc ) ; bus_dma_tag_destroy ( dma -> tag ) ; memset ( dma , 0 , sizeof ( * dma ) ) ; return ( 1 ) ; } rc = bus_dmamap_load ( dma -> tag , dma -> map , dma -> vaddr , size , bxe_dma_map_addr , dma , BUS_DMA_NOWAIT ) ; if ( rc != 0 ) { BLOGE ( sc , " \n " , msg , rc ) ; bus_dmamem_free ( dma -> tag , dma -> vaddr , dma -> map ) ; bus_dma_tag_destroy ( dma -> tag ) ; memset ( dma , 0 , sizeof ( * dma ) ) ; return ( 1 ) ; } return ( 0 ) ; }
Allocate a block of memory and map it for DMA.
Allocate a block of memory and map it for DMA .
/* sanity */ /* parent tag */ /* alignment */ /* boundary limit */ /* restricted low */ /* restricted hi */ /* addr filter() */ /* addr filter() arg */ /* max map size */ /* num discontinuous */ /* max seg size */ /* flags */ /* lock() */ /* lock() arg */ /* returned dma tag */ /* BLOGD in here */