d512ffaa6488d8fd6b0b58c7ecfacdc556281745
[openwrt/staging/pepe2k.git] /
1 From ac1d09b5d0dd7e9877ace3954d6042723fa75169 Mon Sep 17 00:00:00 2001
2 From: Dom Cobley <popcornmix@gmail.com>
3 Date: Mon, 15 Aug 2022 19:44:20 +0100
4 Subject: [PATCH] vc04_services/vc-sm-cma: Handle upstream require
5 vchiq_instance to be passed around
6
7 ---
8 .../staging/vc04_services/vc-sm-cma/vc_sm.c | 12 +++----
9 .../vc04_services/vc-sm-cma/vc_sm_cma_vchi.c | 36 +++++++++++--------
10 .../vc04_services/vc-sm-cma/vc_sm_cma_vchi.h | 2 +-
11 3 files changed, 28 insertions(+), 22 deletions(-)
12
13 --- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
14 +++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
15 @@ -106,6 +106,7 @@ struct sm_state_t {
16 * has finished with a resource.
17 */
18 u32 int_trans_id; /* Interrupted transaction. */
19 + struct vchiq_instance *vchiq_instance;
20 };
21
22 struct vc_sm_dma_buf_attachment {
23 @@ -1491,7 +1492,6 @@ static const struct file_operations vc_s
24 static void vc_sm_connected_init(void)
25 {
26 int ret;
27 - struct vchiq_instance *vchiq_instance;
28 struct vc_sm_version version;
29 struct vc_sm_result_t version_result;
30
31 @@ -1501,7 +1501,7 @@ static void vc_sm_connected_init(void)
32 * Initialize and create a VCHI connection for the shared memory service
33 * running on videocore.
34 */
35 - ret = vchiq_initialise(&vchiq_instance);
36 + ret = vchiq_initialise(&sm_state->vchiq_instance);
37 if (ret) {
38 pr_err("[%s]: failed to initialise VCHI instance (ret=%d)\n",
39 __func__, ret);
40 @@ -1509,7 +1509,7 @@ static void vc_sm_connected_init(void)
41 return;
42 }
43
44 - ret = vchiq_connect(vchiq_instance);
45 + ret = vchiq_connect(sm_state->vchiq_instance);
46 if (ret) {
47 pr_err("[%s]: failed to connect VCHI instance (ret=%d)\n",
48 __func__, ret);
49 @@ -1518,7 +1518,7 @@ static void vc_sm_connected_init(void)
50 }
51
52 /* Initialize an instance of the shared memory service. */
53 - sm_state->sm_handle = vc_sm_cma_vchi_init(vchiq_instance, 1,
54 + sm_state->sm_handle = vc_sm_cma_vchi_init(sm_state->vchiq_instance, 1,
55 vc_sm_vpu_event);
56 if (!sm_state->sm_handle) {
57 pr_err("[%s]: failed to initialize shared memory service\n",
58 @@ -1576,7 +1576,7 @@ err_remove_misc_dev:
59 misc_deregister(&sm_state->misc_dev);
60 err_remove_debugfs:
61 debugfs_remove_recursive(sm_state->dir_root);
62 - vc_sm_cma_vchi_stop(&sm_state->sm_handle);
63 + vc_sm_cma_vchi_stop(sm_state->vchiq_instance, &sm_state->sm_handle);
64 }
65
66 /* Driver loading. */
67 @@ -1614,7 +1614,7 @@ static int bcm2835_vc_sm_cma_remove(stru
68 debugfs_remove_recursive(sm_state->dir_root);
69
70 /* Stop the videocore shared memory service. */
71 - vc_sm_cma_vchi_stop(&sm_state->sm_handle);
72 + vc_sm_cma_vchi_stop(sm_state->vchiq_instance, &sm_state->sm_handle);
73 }
74
75 if (sm_state) {
76 --- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.c
77 +++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.c
78 @@ -70,7 +70,7 @@ struct sm_instance {
79 struct list_head free_list;
80
81 struct semaphore free_sema;
82 -
83 + struct vchiq_instance *vchiq_instance;
84 };
85
86 /* ---- Private Variables ------------------------------------------------ */
87 @@ -79,11 +79,11 @@ struct sm_instance {
88
89 /* ---- Private Functions ------------------------------------------------ */
90 static int
91 -bcm2835_vchi_msg_queue(unsigned int handle,
92 +bcm2835_vchi_msg_queue(struct vchiq_instance *vchiq_instance, unsigned int handle,
93 void *data,
94 unsigned int size)
95 {
96 - return vchiq_queue_kernel_message(handle, data, size);
97 + return vchiq_queue_kernel_message(vchiq_instance, handle, data, size);
98 }
99
100 static struct
101 @@ -187,12 +187,12 @@ static int vc_sm_cma_vchi_videocore_io(v
102
103 while (1) {
104 if (svc_use)
105 - vchiq_release_service(instance->service_handle[0]);
106 + vchiq_release_service(instance->vchiq_instance, instance->service_handle[0]);
107 svc_use = 0;
108
109 if (wait_for_completion_interruptible(&instance->io_cmplt))
110 continue;
111 - vchiq_use_service(instance->service_handle[0]);
112 + vchiq_use_service(instance->vchiq_instance, instance->service_handle[0]);
113 svc_use = 1;
114
115 do {
116 @@ -212,7 +212,8 @@ static int vc_sm_cma_vchi_videocore_io(v
117 mutex_unlock(&instance->lock);
118 /* Send the command */
119 status =
120 - bcm2835_vchi_msg_queue(instance->service_handle[0],
121 + bcm2835_vchi_msg_queue(instance->vchiq_instance,
122 + instance->service_handle[0],
123 cmd->msg, cmd->length);
124 if (status) {
125 pr_err("%s: failed to queue message (%d)",
126 @@ -235,7 +236,8 @@ static int vc_sm_cma_vchi_videocore_io(v
127
128 } while (1);
129
130 - while ((header = vchiq_msg_hold(instance->service_handle[0]))) {
131 + while ((header = vchiq_msg_hold(instance->vchiq_instance,
132 + instance->service_handle[0]))) {
133 reply = (struct vc_sm_result_t *)header->data;
134 if (reply->trans_id & 0x80000000) {
135 /* Async event or cmd from the VPU */
136 @@ -247,7 +249,8 @@ static int vc_sm_cma_vchi_videocore_io(v
137 header->size);
138 }
139
140 - vchiq_release_message(instance->service_handle[0],
141 + vchiq_release_message(instance->vchiq_instance,
142 + instance->service_handle[0],
143 header);
144 }
145
146 @@ -264,15 +267,16 @@ static int vc_sm_cma_vchi_videocore_io(v
147 return 0;
148 }
149
150 -static enum vchiq_status vc_sm_cma_vchi_callback(enum vchiq_reason reason,
151 +static enum vchiq_status vc_sm_cma_vchi_callback(struct vchiq_instance *vchiq_instance,
152 + enum vchiq_reason reason,
153 struct vchiq_header *header,
154 unsigned int handle, void *userdata)
155 {
156 - struct sm_instance *instance = vchiq_get_service_userdata(handle);
157 + struct sm_instance *instance = vchiq_get_service_userdata(vchiq_instance, handle);
158
159 switch (reason) {
160 case VCHIQ_MESSAGE_AVAILABLE:
161 - vchiq_msg_queue_push(handle, header);
162 + vchiq_msg_queue_push(vchiq_instance, handle, header);
163 complete(&instance->io_cmplt);
164 break;
165
166 @@ -320,6 +324,8 @@ struct sm_instance *vc_sm_cma_vchi_init(
167 list_add(&instance->free_blk[i].head, &instance->free_list);
168 }
169
170 + instance->vchiq_instance = vchiq_instance;
171 +
172 /* Open the VCHI service connections */
173 instance->num_connections = num_connections;
174 for (i = 0; i < num_connections; i++) {
175 @@ -358,7 +364,7 @@ struct sm_instance *vc_sm_cma_vchi_init(
176 err_close_services:
177 for (i = 0; i < instance->num_connections; i++) {
178 if (instance->service_handle[i])
179 - vchiq_close_service(instance->service_handle[i]);
180 + vchiq_close_service(vchiq_instance, instance->service_handle[i]);
181 }
182 kfree(instance);
183 err_null:
184 @@ -366,7 +372,7 @@ err_null:
185 return NULL;
186 }
187
188 -int vc_sm_cma_vchi_stop(struct sm_instance **handle)
189 +int vc_sm_cma_vchi_stop(struct vchiq_instance *vchiq_instance, struct sm_instance **handle)
190 {
191 struct sm_instance *instance;
192 u32 i;
193 @@ -385,8 +391,8 @@ int vc_sm_cma_vchi_stop(struct sm_instan
194
195 /* Close all VCHI service connections */
196 for (i = 0; i < instance->num_connections; i++) {
197 - vchiq_use_service(instance->service_handle[i]);
198 - vchiq_close_service(instance->service_handle[i]);
199 + vchiq_use_service(vchiq_instance, instance->service_handle[i]);
200 + vchiq_close_service(vchiq_instance, instance->service_handle[i]);
201 }
202
203 kfree(instance);
204 --- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.h
205 +++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.h
206 @@ -35,7 +35,7 @@ struct sm_instance *vc_sm_cma_vchi_init(
207 /*
208 * Terminates the shared memory service.
209 */
210 -int vc_sm_cma_vchi_stop(struct sm_instance **handle);
211 +int vc_sm_cma_vchi_stop(struct vchiq_instance *vchi_instance, struct sm_instance **handle);
212
213 /*
214 * Ask the shared memory service to free up some memory that was previously