1*111d746bSScott Branden /* SPDX-License-Identifier: GPL-2.0 */ 2*111d746bSScott Branden /* 3*111d746bSScott Branden * Copyright 2018-2020 Broadcom. 4*111d746bSScott Branden */ 5*111d746bSScott Branden 6*111d746bSScott Branden #ifndef BCM_VK_SG_H 7*111d746bSScott Branden #define BCM_VK_SG_H 8*111d746bSScott Branden 9*111d746bSScott Branden #include <linux/dma-mapping.h> 10*111d746bSScott Branden 11*111d746bSScott Branden struct bcm_vk_dma { 12*111d746bSScott Branden /* for userland buffer */ 13*111d746bSScott Branden struct page **pages; 14*111d746bSScott Branden int nr_pages; 15*111d746bSScott Branden 16*111d746bSScott Branden /* common */ 17*111d746bSScott Branden dma_addr_t handle; 18*111d746bSScott Branden /* 19*111d746bSScott Branden * sglist is of the following LE format 20*111d746bSScott Branden * [U32] num_sg = number of sg addresses (N) 21*111d746bSScott Branden * [U32] totalsize = totalsize of data being transferred in sglist 22*111d746bSScott Branden * [U32] size[0] = size of data in address0 23*111d746bSScott Branden * [U32] addr_l[0] = lower 32-bits of address0 24*111d746bSScott Branden * [U32] addr_h[0] = higher 32-bits of address0 25*111d746bSScott Branden * .. 26*111d746bSScott Branden * [U32] size[N-1] = size of data in addressN-1 27*111d746bSScott Branden * [U32] addr_l[N-1] = lower 32-bits of addressN-1 28*111d746bSScott Branden * [U32] addr_h[N-1] = higher 32-bits of addressN-1 29*111d746bSScott Branden */ 30*111d746bSScott Branden u32 *sglist; 31*111d746bSScott Branden #define SGLIST_NUM_SG 0 32*111d746bSScott Branden #define SGLIST_TOTALSIZE 1 33*111d746bSScott Branden #define SGLIST_VKDATA_START 2 34*111d746bSScott Branden 35*111d746bSScott Branden int sglen; /* Length (bytes) of sglist */ 36*111d746bSScott Branden int direction; 37*111d746bSScott Branden }; 38*111d746bSScott Branden 39*111d746bSScott Branden struct _vk_data { 40*111d746bSScott Branden u32 size; /* data size in bytes */ 41*111d746bSScott Branden u64 address; /* Pointer to data */ 42*111d746bSScott Branden } __packed; 43*111d746bSScott Branden 44*111d746bSScott Branden /* 45*111d746bSScott Branden * Scatter-gather DMA buffer API. 46*111d746bSScott Branden * 47*111d746bSScott Branden * These functions provide a simple way to create a page list and a 48*111d746bSScott Branden * scatter-gather list from userspace address and map the memory 49*111d746bSScott Branden * for DMA operation. 50*111d746bSScott Branden */ 51*111d746bSScott Branden int bcm_vk_sg_alloc(struct device *dev, 52*111d746bSScott Branden struct bcm_vk_dma *dma, 53*111d746bSScott Branden int dir, 54*111d746bSScott Branden struct _vk_data *vkdata, 55*111d746bSScott Branden int num); 56*111d746bSScott Branden 57*111d746bSScott Branden int bcm_vk_sg_free(struct device *dev, struct bcm_vk_dma *dma, int num, 58*111d746bSScott Branden int *proc_cnt); 59*111d746bSScott Branden 60*111d746bSScott Branden #endif 61*111d746bSScott Branden 62