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