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
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(-)
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.
18 u32 int_trans_id; /* Interrupted transaction. */
19 + struct vchiq_instance *vchiq_instance;
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)
27 - struct vchiq_instance *vchiq_instance;
28 struct vc_sm_version version;
29 struct vc_sm_result_t version_result;
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.
35 - ret = vchiq_initialise(&vchiq_instance);
36 + ret = vchiq_initialise(&sm_state->vchiq_instance);
38 pr_err("[%s]: failed to initialise VCHI instance (ret=%d)\n",
40 @@ -1509,7 +1509,7 @@ static void vc_sm_connected_init(void)
44 - ret = vchiq_connect(vchiq_instance);
45 + ret = vchiq_connect(sm_state->vchiq_instance);
47 pr_err("[%s]: failed to connect VCHI instance (ret=%d)\n",
49 @@ -1518,7 +1518,7 @@ static void vc_sm_connected_init(void)
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,
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);
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);
67 @@ -1614,7 +1614,7 @@ static int bcm2835_vc_sm_cma_remove(stru
68 debugfs_remove_recursive(sm_state->dir_root);
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);
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;
81 struct semaphore free_sema;
83 + struct vchiq_instance *vchiq_instance;
86 /* ---- Private Variables ------------------------------------------------ */
87 @@ -79,11 +79,11 @@ struct sm_instance {
89 /* ---- Private Functions ------------------------------------------------ */
91 -bcm2835_vchi_msg_queue(unsigned int handle,
92 +bcm2835_vchi_msg_queue(struct vchiq_instance *vchiq_instance, unsigned int handle,
96 - return vchiq_queue_kernel_message(handle, data, size);
97 + return vchiq_queue_kernel_message(vchiq_instance, handle, data, size);
101 @@ -187,12 +187,12 @@ static int vc_sm_cma_vchi_videocore_io(v
105 - vchiq_release_service(instance->service_handle[0]);
106 + vchiq_release_service(instance->vchiq_instance, instance->service_handle[0]);
109 if (wait_for_completion_interruptible(&instance->io_cmplt))
111 - vchiq_use_service(instance->service_handle[0]);
112 + vchiq_use_service(instance->vchiq_instance, instance->service_handle[0]);
116 @@ -212,7 +212,8 @@ static int vc_sm_cma_vchi_videocore_io(v
117 mutex_unlock(&instance->lock);
118 /* Send the command */
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);
125 pr_err("%s: failed to queue message (%d)",
126 @@ -235,7 +236,8 @@ static int vc_sm_cma_vchi_videocore_io(v
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
140 - vchiq_release_message(instance->service_handle[0],
141 + vchiq_release_message(instance->vchiq_instance,
142 + instance->service_handle[0],
146 @@ -264,15 +267,16 @@ static int vc_sm_cma_vchi_videocore_io(v
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)
156 - struct sm_instance *instance = vchiq_get_service_userdata(handle);
157 + struct sm_instance *instance = vchiq_get_service_userdata(vchiq_instance, handle);
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);
166 @@ -320,6 +324,8 @@ struct sm_instance *vc_sm_cma_vchi_init(
167 list_add(&instance->free_blk[i].head, &instance->free_list);
170 + instance->vchiq_instance = vchiq_instance;
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(
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]);
184 @@ -366,7 +372,7 @@ err_null:
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)
191 struct sm_instance *instance;
193 @@ -385,8 +391,8 @@ int vc_sm_cma_vchi_stop(struct sm_instan
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]);
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(
208 * Terminates the shared memory service.
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);
214 * Ask the shared memory service to free up some memory that was previously