1 From 8da5f5ca322c3b6c5c9055381af9db67f724bdc3 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Tue, 29 Jan 2019 16:32:57 +0000
4 Subject: [PATCH 344/725] staging: vc-sm-cma: Fix up for 64bit builds
6 There were a number of logging lines that were using
7 inappropriate formatting under 64bit kernels.
9 The kernel_id field passed to/from the VPU was being
10 abused for storing the struct vc_sm_buffer *.
11 This breaks with 64bit kernels, so change to using an IDR.
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
15 .../staging/vc04_services/vc-sm-cma/vc_sm.c | 60 +++++++++++++++----
16 .../vc04_services/vc-sm-cma/vc_sm_cma_vchi.c | 3 +-
17 2 files changed, 48 insertions(+), 15 deletions(-)
19 --- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
20 +++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
21 @@ -75,6 +75,9 @@ struct sm_state_t {
22 struct miscdevice dev;
23 struct sm_instance *sm_handle; /* Handle for videocore service. */
25 + spinlock_t kernelid_map_lock; /* Spinlock protecting kernelid_map */
26 + struct idr kernelid_map;
28 struct mutex map_lock; /* Global map lock. */
29 struct list_head buffer_list; /* List of buffer. */
31 @@ -97,6 +100,29 @@ static int sm_inited;
33 /* ---- Private Functions ------------------------------------------------ */
35 +static int get_kernel_id(struct vc_sm_buffer *buffer)
39 + spin_lock(&sm_state->kernelid_map_lock);
40 + handle = idr_alloc(&sm_state->kernelid_map, buffer, 0, 0, GFP_KERNEL);
41 + spin_unlock(&sm_state->kernelid_map_lock);
46 +static struct vc_sm_buffer *lookup_kernel_id(int handle)
48 + return idr_find(&sm_state->kernelid_map, handle);
51 +static void free_kernel_id(int handle)
53 + spin_lock(&sm_state->kernelid_map_lock);
54 + idr_remove(&sm_state->kernelid_map, handle);
55 + spin_unlock(&sm_state->kernelid_map_lock);
58 static int vc_sm_cma_seq_file_show(struct seq_file *s, void *v)
60 struct sm_pde_t *sm_pde;
61 @@ -129,8 +155,7 @@ static int vc_sm_cma_global_state_show(s
65 - seq_printf(s, "\nVC-ServiceHandle 0x%x\n",
66 - (unsigned int)sm_state->sm_handle);
67 + seq_printf(s, "\nVC-ServiceHandle %p\n", sm_state->sm_handle);
69 /* Log all applicable mapping(s). */
71 @@ -145,7 +170,7 @@ static int vc_sm_cma_global_state_show(s
73 seq_printf(s, " NAME %s\n",
75 - seq_printf(s, " SIZE %d\n",
76 + seq_printf(s, " SIZE %zu\n",
78 seq_printf(s, " DMABUF %p\n",
80 @@ -181,7 +206,7 @@ static void vc_sm_add_resource(struct vc
81 list_add(&buffer->global_buffer_list, &sm_state->buffer_list);
82 mutex_unlock(&sm_state->map_lock);
84 - pr_debug("[%s]: added buffer %p (name %s, size %d)\n",
85 + pr_debug("[%s]: added buffer %p (name %s, size %zu)\n",
86 __func__, buffer, buffer->name, buffer->size);
89 @@ -194,7 +219,7 @@ static void vc_sm_release_resource(struc
90 mutex_lock(&sm_state->map_lock);
91 mutex_lock(&buffer->lock);
93 - pr_debug("[%s]: buffer %p (name %s, size %d)\n",
94 + pr_debug("[%s]: buffer %p (name %s, size %zu)\n",
95 __func__, buffer, buffer->name, buffer->size);
97 if (buffer->vc_handle && buffer->vpu_state == VPU_MAPPED) {
98 @@ -443,6 +468,7 @@ vc_sm_cma_import_dmabuf_internal(struct
99 struct vc_sm_import_result result = { };
100 struct dma_buf_attachment *attach = NULL;
101 struct sg_table *sgt = NULL;
102 + dma_addr_t dma_addr;
106 @@ -478,21 +504,22 @@ vc_sm_cma_import_dmabuf_internal(struct
109 import.type = VC_SM_ALLOC_NON_CACHED;
110 - import.addr = (uint32_t)sg_dma_address(sgt->sgl);
111 + dma_addr = sg_dma_address(sgt->sgl);
112 + import.addr = (uint32_t)dma_addr;
113 if ((import.addr & 0xC0000000) != 0xC0000000) {
114 - pr_err("%s: Expecting an uncached alias for dma_addr %08x\n",
115 - __func__, import.addr);
116 + pr_err("%s: Expecting an uncached alias for dma_addr %pad\n",
117 + __func__, &dma_addr);
118 import.addr |= 0xC0000000;
120 import.size = sg_dma_len(sgt->sgl);
121 import.allocator = current->tgid;
122 - import.kernel_id = (uint32_t)buffer; //FIXME: 64 bit support needed.
123 + import.kernel_id = get_kernel_id(buffer);
125 memcpy(import.name, VC_SM_RESOURCE_NAME_DEFAULT,
126 sizeof(VC_SM_RESOURCE_NAME_DEFAULT));
128 - pr_debug("[%s]: attempt to import \"%s\" data - type %u, addr %p, size %u\n",
129 - __func__, import.name, import.type, (void *)import.addr,
130 + pr_debug("[%s]: attempt to import \"%s\" data - type %u, addr %pad, size %u\n",
131 + __func__, import.name, import.type, &dma_addr,
134 /* Allocate the videocore buffer. */
135 @@ -527,7 +554,7 @@ vc_sm_cma_import_dmabuf_internal(struct
137 buffer->attach = attach;
139 - buffer->dma_addr = sg_dma_address(sgt->sgl);
140 + buffer->dma_addr = dma_addr;
144 @@ -559,6 +586,7 @@ error:
145 vc_sm_cma_vchi_free(sm_state->sm_handle, &free,
146 &sm_state->int_trans_id);
148 + free_kernel_id(import.kernel_id);
151 dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL);
152 @@ -586,7 +614,7 @@ vc_sm_vpu_event(struct sm_instance *inst
154 struct vc_sm_released *release = (struct vc_sm_released *)reply;
155 struct vc_sm_buffer *buffer =
156 - (struct vc_sm_buffer *)release->kernel_id;
157 + lookup_kernel_id(release->kernel_id);
160 * FIXME: Need to check buffer is still valid and allocated
161 @@ -599,6 +627,7 @@ vc_sm_vpu_event(struct sm_instance *inst
162 buffer->vc_handle = 0;
163 buffer->vpu_state = VPU_NOT_MAPPED;
164 mutex_unlock(&buffer->lock);
165 + free_kernel_id(release->kernel_id);
167 vc_sm_release_resource(buffer, 0);
169 @@ -711,6 +740,9 @@ static int bcm2835_vc_sm_cma_probe(struc
170 sm_state->pdev = pdev;
171 mutex_init(&sm_state->map_lock);
173 + spin_lock_init(&sm_state->kernelid_map_lock);
174 + idr_init_base(&sm_state->kernelid_map, 1);
176 pdev->dev.dma_parms = devm_kzalloc(&pdev->dev,
177 sizeof(*pdev->dev.dma_parms),
179 @@ -735,6 +767,8 @@ static int bcm2835_vc_sm_cma_remove(stru
180 /* Stop the videocore shared memory service. */
181 vc_sm_cma_vchi_stop(&sm_state->sm_handle);
183 + idr_destroy(&sm_state->kernelid_map);
185 /* Free the memory for the state structure. */
186 mutex_destroy(&sm_state->map_lock);
188 --- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.c
189 +++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.c
190 @@ -356,8 +356,7 @@ struct sm_instance *vc_sm_cma_vchi_init(
191 set_user_nice(instance->io_thread, -10);
192 wake_up_process(instance->io_thread);
194 - pr_debug("%s: success - instance 0x%x", __func__,
195 - (unsigned int)instance);
196 + pr_debug("%s: success - instance %p", __func__, instance);