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