Lines Matching refs:dma
27 struct bcm_vk_dma *dma,
30 static int bcm_vk_dma_free(struct device *dev, struct bcm_vk_dma *dma);
36 struct bcm_vk_dma *dma, in bcm_vk_dma_alloc() argument
60 dma->nr_pages = last - first + 1; in bcm_vk_dma_alloc()
63 dma->pages = kmalloc_array(dma->nr_pages, in bcm_vk_dma_alloc()
66 if (!dma->pages) in bcm_vk_dma_alloc()
70 data, vkdata->size, dma->nr_pages); in bcm_vk_dma_alloc()
72 dma->direction = direction; in bcm_vk_dma_alloc()
76 dma->nr_pages, in bcm_vk_dma_alloc()
78 dma->pages); in bcm_vk_dma_alloc()
79 if (err != dma->nr_pages) { in bcm_vk_dma_alloc()
80 dma->nr_pages = (err >= 0) ? err : 0; in bcm_vk_dma_alloc()
82 err, dma->nr_pages); in bcm_vk_dma_alloc()
87 dma->sglen = (dma->nr_pages * sizeof(*sgdata)) + in bcm_vk_dma_alloc()
91 dma->sglist = dma_alloc_coherent(dev, in bcm_vk_dma_alloc()
92 dma->sglen, in bcm_vk_dma_alloc()
93 &dma->handle, in bcm_vk_dma_alloc()
95 if (!dma->sglist) in bcm_vk_dma_alloc()
98 dma->sglist[SGLIST_NUM_SG] = 0; in bcm_vk_dma_alloc()
99 dma->sglist[SGLIST_TOTALSIZE] = vkdata->size; in bcm_vk_dma_alloc()
101 sgdata = (struct _vk_data *)&dma->sglist[SGLIST_VKDATA_START]; in bcm_vk_dma_alloc()
107 dma->pages[0], in bcm_vk_dma_alloc()
110 dma->direction); in bcm_vk_dma_alloc()
113 __free_page(dma->pages[0]); in bcm_vk_dma_alloc()
117 for (i = 1; i < dma->nr_pages; i++) { in bcm_vk_dma_alloc()
121 dma->pages[i], in bcm_vk_dma_alloc()
124 dma->direction); in bcm_vk_dma_alloc()
126 __free_page(dma->pages[i]); in bcm_vk_dma_alloc()
142 dma->sglist[SGLIST_NUM_SG]++; in bcm_vk_dma_alloc()
153 dma->sglist[SGLIST_NUM_SG]++; in bcm_vk_dma_alloc()
156 put_unaligned((u64)dma->handle, &vkdata->address); in bcm_vk_dma_alloc()
157 vkdata->size = (dma->sglist[SGLIST_NUM_SG] * sizeof(*sgdata)) + in bcm_vk_dma_alloc()
163 (u64)dma->sglist, in bcm_vk_dma_alloc()
164 dma->handle, in bcm_vk_dma_alloc()
165 dma->sglen, in bcm_vk_dma_alloc()
168 dev_dbg(dev, "i:0x%x 0x%x\n", i, dma->sglist[i]); in bcm_vk_dma_alloc()
175 struct bcm_vk_dma *dma, in bcm_vk_sg_alloc() argument
191 &dma[i], in bcm_vk_sg_alloc()
220 if (dma[i].sglist) in bcm_vk_sg_alloc()
221 bcm_vk_dma_free(dev, &dma[i]); in bcm_vk_sg_alloc()
226 static int bcm_vk_dma_free(struct device *dev, struct bcm_vk_dma *dma) in bcm_vk_dma_free() argument
234 dev_dbg(dev, "free sglist=%p sglen=0x%x\n", dma->sglist, dma->sglen); in bcm_vk_dma_free()
237 num_sg = dma->sglist[SGLIST_NUM_SG]; in bcm_vk_dma_free()
238 vkdata = (struct _vk_data *)&dma->sglist[SGLIST_VKDATA_START]; in bcm_vk_dma_free()
243 dma_unmap_page(dev, addr, size, dma->direction); in bcm_vk_dma_free()
247 dma_free_coherent(dev, dma->sglen, dma->sglist, dma->handle); in bcm_vk_dma_free()
250 for (i = 0; i < dma->nr_pages; i++) in bcm_vk_dma_free()
251 put_page(dma->pages[i]); in bcm_vk_dma_free()
254 kfree(dma->pages); in bcm_vk_dma_free()
255 dma->sglist = NULL; in bcm_vk_dma_free()
260 int bcm_vk_sg_free(struct device *dev, struct bcm_vk_dma *dma, int num, in bcm_vk_sg_free() argument
268 if (dma[i].sglist) { in bcm_vk_sg_free()
269 bcm_vk_dma_free(dev, &dma[i]); in bcm_vk_sg_free()