当前位置:网站首页>ion_dma_buf_begin_cpu_access

ion_dma_buf_begin_cpu_access

2022-06-10 23:57:00 wmzjzwlzs

static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
                    enum dma_data_direction direction)
{
    struct ion_buffer *buffer = dmabuf->priv;
    void *vaddr;
    struct ion_dma_buf_attachment *a;
    int ret = 0;

    /*
     * TODO: Move this elsewhere because we don't always need a vaddr
     */
    if (buffer->heap->ops->map_kernel) {
        mutex_lock(&buffer->lock);
        vaddr = ion_buffer_kmap_get(buffer);
        if (IS_ERR(vaddr)) {
            ret = PTR_ERR(vaddr);
            goto unlock;
        }
        mutex_unlock(&buffer->lock);
    }

    mutex_lock(&buffer->lock);
    list_for_each_entry(a, &buffer->attachments, list) {
        dma_sync_sg_for_cpu(a->dev, a->table->sgl, a->table->nents,
                    direction);
    }

unlock:
    mutex_unlock(&buffer->lock);
    return ret;
}

static inline void
dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
            int nelems, enum dma_data_direction dir)
{
    const struct dma_map_ops *ops = get_dma_ops(dev);

    BUG_ON(!valid_dma_direction(dir));
    if (dma_is_direct(ops))
        dma_direct_sync_sg_for_cpu(dev, sg, nelems, dir);
    else if (ops->sync_sg_for_cpu)
        ops->sync_sg_for_cpu(dev, sg, nelems, dir);
    debug_dma_sync_sg_for_cpu(dev, sg, nelems, dir);
}

sync_sg_for_cpu __dma_unmap_area

sync_sg_for_device __dma_map_area

ENTRY(__dma_map_area)

cmp w2, #DMA_FROM_DEVICE

b.eq __dma_inv_area

b __dma_clean_area

ENDPIPROC(__dma_map_area)

/* * __dma_unmap_area(start, size, dir) * - start - kernel virtual start address * - size - size of region * - dir - DMA direction */

ENTRY(__dma_unmap_area)

cmp w2, #DMA_TO_DEVICE

b.ne __dma_inv_area ret

ENDPIPROC(__dma_unmap_area)

原网站

版权声明
本文为[wmzjzwlzs]所创,转载请带上原文链接,感谢
https://blog.csdn.net/wmzjzwlzs/article/details/125229340