staging: vchiq_arm: remove some unnecessary global variables
Subsystems (3)
v2 cover staging: vchiq_arm: remove some unnecessary global variables
This patch series aims at removing some unnecessary global structures (namely, 'g_dev' and 'vchiq_states'), in order to make the driver more robust. This is part of an effort to address TODO item "Get rid of all non essential global structures and create a proper per device structure".
Changes since v1:
- added more info in commit messages
- split commit removing the 'vchiq_states' array into several changes to make the review easier.
Adrien Thierry (9):
staging: vchiq_arm: add reference to vchiq device in vchiq_state
staging: vchiq_arm: get rid of global device structure
staging: vchiq_arm: pass vchiq instance to service callbacks
staging: vchiq_arm: pass vchiq instance to 'find_service_by_handle'
staging: vchiq_arm: pass vchiq instance to 'vchiq_get_client_id'
staging: vchiq_arm: pass vchiq instance to
'vchiq_get_service_userdata'
staging: vchiq_arm: pass vchiq instance to 'handle_to_service'
staging: vchiq_arm: use state from vchiq instance
staging: vchiq_arm: remove global 'vchiq_states' array
.../bcm2835-audio/bcm2835-vchiq.c | 40 +++++--- .../include/linux/raspberrypi/vchiq.h | 48 +++++---- .../interface/vchiq_arm/vchiq_arm.c | 92 ++++++++---------- .../interface/vchiq_arm/vchiq_arm.h | 8 +- .../interface/vchiq_arm/vchiq_core.c | 97 ++++++++++--------- .../interface/vchiq_arm/vchiq_core.h | 38 +++----- .../interface/vchiq_arm/vchiq_dev.c | 40 ++++---- .../vc04_services/vchiq-mmal/mmal-vchiq.c | 63 ++++++------ 8 files changed, 217 insertions(+), 209 deletions(-)
base-commit: e41f7a5521d7f03dca99e3207633df71740569dd
Signature · 1 line
2.35.3
PATCH v2 1/9 staging: vchiq_arm: add reference to vchiq device in vchiq_state
Add a reference to the vchiq device in the vchiq_state structure. This allows the device structure to be passed around, which will be useful in order to get rid of the global g_dev structure. This change will also make it possible to use standard kernel logging macros instead of the custom ones.
---
Changes since v1:
- added more info to commit message
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 2 +- .../staging/vc04_services/interface/vchiq_arm/vchiq_core.c | 4 +++- .../staging/vc04_services/interface/vchiq_arm/vchiq_core.h | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +1 -1
@@ -519,7 +519,7 @@ int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state *state) *(char **)&g_fragments_base[i * g_fragments_size] =NULL ;sema_init (&g_free_fragments_sema,MAX_FRAGMENTS ); - err =vchiq_init_state (state, vchiq_slot_zero); + err =vchiq_init_state (state, vchiq_slot_zero, dev);if (err)return err;
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +3 -1
@@ -2142,7 +2142,7 @@ vchiq_init_slots(void *mem_base, int mem_size) }int -vchiq_init_state (struct vchiq_state *state,struct vchiq_slot_zero *slot_zero) +vchiq_init_state (struct vchiq_state *state,struct vchiq_slot_zero *slot_zero,struct device *dev) {struct vchiq_shared_state *local;struct vchiq_shared_state *remote;
@@ -2169,6 +2169,8 @@ vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_zero)memset (state,0 ,sizeof (struct vchiq_state )); + state->dev = dev; +/* * initialize shared state pointers */
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +2 -1
@@ -315,6 +315,7 @@ struct vchiq_slot_zero { };struct vchiq_state { +struct device *dev;int id;int initialised;enum vchiq_connstate conn_state;
@@ -458,7 +459,7 @@ extern struct vchiq_slot_zero * vchiq_init_slots(void *mem_base, int mem_size);extern int -vchiq_init_state (struct vchiq_state *state,struct vchiq_slot_zero *slot_zero); +vchiq_init_state (struct vchiq_state *state,struct vchiq_slot_zero *slot_zero,struct device *dev);extern enum vchiq_status vchiq_connect_internal (struct vchiq_state *state,struct vchiq_instance *instance);
Signature · 1 line
2.35.3
PATCH v2 2/9 staging: vchiq_arm: get rid of global device structure
In reply to Adrien ThierryGet rid of the global g_dev structure.
This is part of an effort to address TODO item "Get rid of all non essential global structures and create a proper per device structure"
I chose to pass the vchiq_instance around instead of the device reference because in order to get rid of the 'vchiq_states' global array in the future, we will need another way to access the vchiq_state in the 'handle_to_service' function. Therefore, we will need to pass the vchiq_instance to it (or the vchiq_state), and also pass it to functions higher up in the caller chain, such as 'vchiq_bulk_transmit' and friends which are used in the bcm2835-audio consumer.
---
Changes since v1:
- added more info to commit message
.../bcm2835-audio/bcm2835-vchiq.c | 7 ++- .../include/linux/raspberrypi/vchiq.h | 12 ++-- .../interface/vchiq_arm/vchiq_arm.c | 63 +++++++++---------- .../interface/vchiq_arm/vchiq_core.c | 14 ++--- .../interface/vchiq_arm/vchiq_core.h | 10 +-- .../interface/vchiq_arm/vchiq_dev.c | 2 +- .../vc04_services/vchiq-mmal/mmal-vchiq.c | 2 +- 7 files changed, 53 insertions(+), 57 deletions(-)
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +4 -3
@@ -322,6 +322,8 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream, unsigned int size, void *src) { struct bcm2835_audio_instance *instance = alsa_stream->instance; +struct bcm2835_vchi_ctx *vchi_ctx = alsa_stream->chip->vchi_ctx; +struct vchiq_instance *vchiq_instance = vchi_ctx->instance; struct vc_audio_msg m = { .type = VC_AUDIO_MSG_TYPE_WRITE, .write.count = size,
@@ -343,9 +345,8 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream, count = size;if (!instance->max_packet) {/* Send the message to the videocore */ - status =vchiq_bulk_transmit (instance->service_handle, src, - count,NULL , -VCHIQ_BULK_MODE_BLOCKING ); + status =vchiq_bulk_transmit (vchiq_instance, instance->service_handle, src, count, +NULL ,VCHIQ_BULK_MODE_BLOCKING ); }else {while (count >0 ) {int bytes =min (instance->max_packet, count);
drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +6 -6
@@ -96,12 +96,12 @@ extern void vchiq_release_message(unsigned int service, struct vchiq_header *header);extern int vchiq_queue_kernel_message (unsigned int handle,void *data,unsigned int size); -extern enum vchiq_status vchiq_bulk_transmit (unsigned int service, -const void *data,unsigned int size,void *userdata, -enum vchiq_bulk_mode mode); -extern enum vchiq_status vchiq_bulk_receive (unsigned int service, -void *data,unsigned int size,void *userdata, -enum vchiq_bulk_mode mode); +extern enum vchiq_status vchiq_bulk_transmit (struct vchiq_instance *instance,unsigned int service, +const void *data,unsigned int size,void *userdata, +enum vchiq_bulk_mode mode); +extern enum vchiq_status vchiq_bulk_receive (struct vchiq_instance *instance,unsigned int service, +void *data,unsigned int size,void *userdata, +enum vchiq_bulk_mode mode);extern void *vchiq_get_service_userdata (unsigned int service);extern enum vchiq_status vchiq_get_peer_version (unsigned int handle,short *peer_version);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +29 -34
222 lines not on this page · raw message
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +7 -7
@@ -1441,7 +1441,7 @@ abort_outstanding_bulks(struct vchiq_service *service, }if (queue->process != queue->local_insert) { -vchiq_complete_bulk (bulk); +vchiq_complete_bulk (service->instance, bulk); vchiq_log_info(SRVTRACE_LEVEL(service), "%s %c%c%c%c d:%d ABORTED - tx len:%d, rx len:%d",
@@ -1769,7 +1769,7 @@ parse_message(struct vchiq_state *state, struct vchiq_header *header)DEBUG_TRACE (PARSE_LINE );WARN_ON (queue->process == queue->local_insert); -vchiq_complete_bulk (bulk); +vchiq_complete_bulk (service->instance, bulk); queue->process++;mutex_unlock (&service->bulk_mutex);DEBUG_TRACE (PARSE_LINE );
@@ -2998,9 +2998,9 @@ vchiq_remove_service(unsigned int handle)* When called in blocking mode, the userdata field points to a bulk_waiter * structure. */ -enum vchiq_status vchiq_bulk_transfer (unsigned int handle,void *offset,void __user *uoffset, -int size,void *userdata,enum vchiq_bulk_mode mode, -enum vchiq_bulk_dir dir) +enum vchiq_status vchiq_bulk_transfer (struct vchiq_instance *instance,unsigned int handle, +void *offset,void __user *uoffset,int size,void *userdata, +enum vchiq_bulk_mode mode,enum vchiq_bulk_dir dir) {struct vchiq_service *service =find_service_by_handle (handle);struct vchiq_bulk_queue *queue;
@@ -3077,7 +3077,7 @@ enum vchiq_status vchiq_bulk_transfer(unsigned int handle, void *offset, void __ bulk->size = size; bulk->actual =VCHIQ_BULK_ACTUAL_ABORTED ; -if (vchiq_prepare_bulk_data (bulk, offset, uoffset, size, dir)) +if (vchiq_prepare_bulk_data (instance, bulk, offset, uoffset, size, dir)) goto unlock_error_exit;wmb ();
@@ -3141,7 +3141,7 @@ enum vchiq_status vchiq_bulk_transfer(unsigned int handle, void *offset, void __ unlock_both_error_exit:mutex_unlock (&state->slot_mutex); cancel_bulk_error_exit: -vchiq_complete_bulk (bulk); +vchiq_complete_bulk (service->instance, bulk); unlock_error_exit:mutex_unlock (&service->bulk_mutex);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +5 -5
@@ -489,8 +489,8 @@ extern void remote_event_pollall(struct vchiq_state *state);extern enum vchiq_status -vchiq_bulk_transfer (unsigned int handle,void *offset,void __user *uoffset, -int size,void *userdata,enum vchiq_bulk_mode mode, +vchiq_bulk_transfer (struct vchiq_instance *instance,unsigned int handle,void *offset, +void __user *uoffset,int size,void *userdata,enum vchiq_bulk_mode mode,enum vchiq_bulk_dir dir); extern int
@@ -556,10 +556,10 @@ vchiq_queue_message(unsigned int handle,void *context, size_t size); -int vchiq_prepare_bulk_data (struct vchiq_bulk *bulk,void *offset,void __user *uoffset, -int size,int dir); +int vchiq_prepare_bulk_data (struct vchiq_instance *instance,struct vchiq_bulk *bulk,void *offset, +void __user *uoffset,int size,int dir); -void vchiq_complete_bulk (struct vchiq_bulk *bulk); +void vchiq_complete_bulk (struct vchiq_instance *instance,struct vchiq_bulk *bulk);void remote_event_signal (struct remote_event *event);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +1 -1
@@ -330,7 +330,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance, userdata = args->userdata; } - status =vchiq_bulk_transfer (args->handle,NULL , args->data, args->size, + status =vchiq_bulk_transfer (instance, args->handle,NULL , args->data, args->size, userdata, args->mode, dir);if (!waiter) {
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c +1 -1
@@ -293,7 +293,7 @@ static void buffer_to_host_work_cb(struct work_struct *work) len =8 ;/* queue the bulk submission */ vchiq_use_service (instance->service_handle); - ret = vchiq_bulk_receive(instance->service_handle, + ret = vchiq_bulk_receive(instance->vchiq_instance, instance->service_handle, msg_context->u.bulk.buffer->buffer,/* Actual receive needs to be a multiple * of 4 bytes
Signature · 1 line
2.35.3
PATCH v2 3/9 staging: vchiq_arm: pass vchiq instance to service callbacks
In reply to Adrien ThierryIn order to remove the 'vchiq_states' global array, we need to pass the vchiq_instance reference to the 'handle_to_service' function, as well as to all functions that call 'handle_to_service'. This will allow accessing the vchiq state through the vchiq instance instead of through the global array.
'handle_to_service' is called by 'service_callback'. Therefore, pass the vchiq instance reference to 'service_callback'. This also requires adding the vchiq instance reference to the service callbacks prototype, and update all other callbacks accordingly.
--- .../staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c | 3 ++- .../vc04_services/include/linux/raspberrypi/vchiq.h | 8 ++++++-- .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 9 ++++----- .../vc04_services/interface/vchiq_arm/vchiq_arm.h | 4 ++-- .../vc04_services/interface/vchiq_arm/vchiq_core.c | 3 ++- drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 3 ++- 6 files changed, 18 insertions(+), 12 deletions(-)
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +2 -1
@@ -89,7 +89,8 @@ static int bcm2835_audio_send_simple(struct bcm2835_audio_instance *instance,return bcm2835_audio_send_msg (instance, &m, wait); } -static enum vchiq_status audio_vchi_callback (enum vchiq_reason reason, +static enum vchiq_status audio_vchi_callback (struct vchiq_instance *vchiq_instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int handle,void *userdata) {
drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +6 -2
@@ -53,9 +53,12 @@ struct vchiq_element {unsigned int size; }; +struct vchiq_instance ; +struct vchiq_service_base {int fourcc; -enum vchiq_status (*callback)(enum vchiq_reason reason, +enum vchiq_status (*callback)(struct vchiq_instance *instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int handle,void *bulk_userdata);
@@ -71,7 +74,8 @@ struct vchiq_completion_data_kernel {struct vchiq_service_params_kernel {int fourcc; -enum vchiq_status (*callback)(enum vchiq_reason reason, +enum vchiq_status (*callback)(struct vchiq_instance *instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int handle,void *bulk_userdata);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +4 -5
@@ -1041,8 +1041,8 @@ add_completion(struct vchiq_instance *instance, enum vchiq_reason reason, }enum vchiq_status -service_callback (enum vchiq_reason reason,struct vchiq_header *header, -unsigned int handle,void *bulk_userdata) +service_callback (struct vchiq_instance *instance,enum vchiq_reason reason, +struct vchiq_header *header,unsigned int handle,void *bulk_userdata) {/* * How do we ensure the callback goes to the right client?
@@ -1052,7 +1052,6 @@ service_callback(enum vchiq_reason reason, struct vchiq_header *header,*/ struct user_service *user_service;struct vchiq_service *service; -struct vchiq_instance *instance;bool skip_completion = false;DEBUG_INITIALISE (g_state.local);
@@ -1067,7 +1066,6 @@ service_callback(enum vchiq_reason reason, struct vchiq_header *header, } user_service = (struct user_service *)service->base.userdata; - instance = user_service->instance;if (!instance || instance->closing) {rcu_read_unlock ();
@@ -1313,7 +1311,8 @@ vchiq_get_state(void)*/ static enum vchiq_status -vchiq_keepalive_vchiq_callback (enum vchiq_reason reason, +vchiq_keepalive_vchiq_callback (struct vchiq_instance *instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int service_user,void *bulk_user) {
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h +2 -2
@@ -138,8 +138,8 @@ static inline int vchiq_register_chrdev(struct device *parent) { return 0; }#endif /* IS_ENABLED(CONFIG_VCHIQ_CDEV) */ extern enum vchiq_status -service_callback (enum vchiq_reason reason,struct vchiq_header *header, -unsigned int handle,void *bulk_userdata); +service_callback (struct vchiq_instance *vchiq_instance,enum vchiq_reason reason, +struct vchiq_header *header,unsigned int handle,void *bulk_userdata);extern void free_bulk_waiter (struct vchiq_instance *instance);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +2 -1
@@ -466,7 +466,8 @@ make_service_callback(struct vchiq_service *service, enum vchiq_reason reason,vchiq_log_trace (vchiq_core_log_level,"%d: callback:%d (%s, %pK, %pK)" , service->state->id, service->localport, reason_names[reason], header, bulk_userdata); - status = service->base.callback (reason, header, service->handle, bulk_userdata); + status = service->base.callback (service->instance, reason, header, service->handle, + bulk_userdata);if (status ==VCHIQ_ERROR ) { vchiq_log_warning(vchiq_core_log_level, "%d: ignoring ERROR from callback to service %x",
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c +2 -1
@@ -548,7 +548,8 @@ static void bulk_abort_cb(struct vchiq_mmal_instance *instance, }/* incoming event service callback */ -static enum vchiq_status service_callback (enum vchiq_reason reason, +static enum vchiq_status service_callback (struct vchiq_instance *vchiq_instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int handle,void *bulk_ctx) {
Signature · 1 line
2.35.3
Re: [PATCH v2 3/9] staging: vchiq_arm: pass vchiq instance to service callbacks
Hi Adrien,
Am 18.05.22 um 21:11 schrieb Adrien Thierry:
Quoted 40 lines
In order to remove the '
vchiq_states' global array, we need to pass thevchiq_instancereference to the 'handle_to_service' function, as well as to all functions that call 'handle_to_service'. This will allow accessing the vchiq state through the vchiq instance instead of through the global array.'
handle_to_service' is called by 'service_callback'. Therefore, pass the vchiq instance reference to 'service_callback'. This also requires adding the vchiq instance reference to the service callbacks prototype, and update all other callbacks accordingly.Signed-off-by Adrien Thierry <[email protected]>--- .../staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c | 3 ++- .../vc04_services/include/linux/raspberrypi/vchiq.h | 8 ++++++-- .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 9 ++++----- .../vc04_services/interface/vchiq_arm/vchiq_arm.h | 4 ++-- .../vc04_services/interface/vchiq_arm/vchiq_core.c | 3 ++- drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 3 ++- 6 files changed, 18 insertions(+), 12 deletions(-)drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +2
-1@@ -89,7 +89,8 @@ static int bcm2835_audio_send_simple(struct bcm2835_audio_instance *instance,return bcm2835_audio_send_msg (instance, &m, wait); } -static enum vchiq_status audio_vchi_callback (enum vchiq_reason reason, +static enum vchiq_status audio_vchi_callback (struct vchiq_instance *vchiq_instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int handle,void *userdata) {drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +0
-0
drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h struct vchiq_element { · line 56
Quoted 4 lines
drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +1
-0@@ -53,9 +53,12 @@ struct vchiq_element {unsigned int size; }; +struct vchiq_instance ;
as far i can see this struct was already declared in this header somewhere below. So please avoid multiple declarations.
Quoted 103 lines
drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +5
-2+struct vchiq_service_base {int fourcc; -enum vchiq_status (*callback)(enum vchiq_reason reason, +enum vchiq_status (*callback)(struct vchiq_instance *instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int handle,void *bulk_userdata);@@ -71,7 +74,8 @@ struct vchiq_completion_data_kernel {struct vchiq_service_params_kernel {int fourcc; -enum vchiq_status (*callback)(enum vchiq_reason reason, +enum vchiq_status (*callback)(struct vchiq_instance *instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int handle,void *bulk_userdata);drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +4
-5@@ -1041,8 +1041,8 @@ add_completion(struct vchiq_instance *instance, enum vchiq_reason reason, }enum vchiq_status -service_callback (enum vchiq_reason reason,struct vchiq_header *header, -unsigned int handle,void *bulk_userdata) +service_callback (struct vchiq_instance *instance,enum vchiq_reason reason, +struct vchiq_header *header,unsigned int handle,void *bulk_userdata) {/* * How do we ensure the callback goes to the right client? @@ -1052,7 +1052,6 @@ service_callback(enum vchiq_reason reason, struct vchiq_header *header,*/ struct user_service *user_service;struct vchiq_service *service; -struct vchiq_instance *instance;bool skip_completion = false;DEBUG_INITIALISE (g_state.local);@@ -1067,7 +1066,6 @@ service_callback(enum vchiq_reason reason, struct vchiq_header *header, } user_service = (struct user_service *)service->base.userdata; - instance = user_service->instance;if (!instance || instance->closing) {rcu_read_unlock ();@@ -1313,7 +1311,8 @@ vchiq_get_state(void)*/ static enum vchiq_status -vchiq_keepalive_vchiq_callback (enum vchiq_reason reason, +vchiq_keepalive_vchiq_callback (struct vchiq_instance *instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int service_user,void *bulk_user) {drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h +2
-2@@ -138,8 +138,8 @@ static inline int vchiq_register_chrdev(struct device *parent) { return 0; }#endif /* IS_ENABLED(CONFIG_VCHIQ_CDEV) */ extern enum vchiq_status -service_callback (enum vchiq_reason reason,struct vchiq_header *header, -unsigned int handle,void *bulk_userdata); +service_callback (struct vchiq_instance *vchiq_instance,enum vchiq_reason reason, +struct vchiq_header *header,unsigned int handle,void *bulk_userdata);extern void free_bulk_waiter (struct vchiq_instance *instance);drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +2
-1@@ -466,7 +466,8 @@ make_service_callback(struct vchiq_service *service, enum vchiq_reason reason,vchiq_log_trace (vchiq_core_log_level,"%d: callback:%d (%s, %pK, %pK)" , service->state->id, service->localport, reason_names[reason], header, bulk_userdata); - status = service->base.callback (reason, header, service->handle, bulk_userdata); + status = service->base.callback (service->instance, reason, header, service->handle, + bulk_userdata);if (status ==VCHIQ_ERROR ) { vchiq_log_warning(vchiq_core_log_level, "%d: ignoring ERROR from callback to service %x",drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c +2
-1@@ -548,7 +548,8 @@ static void bulk_abort_cb(struct vchiq_mmal_instance *instance, }/* incoming event service callback */ -static enum vchiq_status service_callback (enum vchiq_reason reason, +static enum vchiq_status service_callback (struct vchiq_instance *vchiq_instance, +enum vchiq_reason reason,struct vchiq_header *header,unsigned int handle,void *bulk_ctx) {
PATCH v2 4/9 staging: vchiq_arm: pass vchiq instance to 'find_service_by_handle'
In reply to Adrien ThierryIn order to remove the 'vchiq_states' global array, we need to pass the vchiq_instance reference to the 'handle_to_service' function, as well as to all functions that call 'handle_to_service'. This will allow accessing the vchiq state through the vchiq instance instead of through the global array.
'handle_to_service' is called by 'find_service_by_handle'. Therefore, pass the vchiq instance reference to 'find_service_by_handle' and to its callers.
--- .../bcm2835-audio/bcm2835-vchiq.c | 27 +++++---- .../include/linux/raspberrypi/vchiq.h | 26 +++++---- .../interface/vchiq_arm/vchiq_arm.c | 16 +++--- .../interface/vchiq_arm/vchiq_arm.h | 4 +- .../interface/vchiq_arm/vchiq_core.c | 47 ++++++++-------- .../interface/vchiq_arm/vchiq_core.h | 9 +-- .../interface/vchiq_arm/vchiq_dev.c | 36 ++++++------ .../vc04_services/vchiq-mmal/mmal-vchiq.c | 56 +++++++++---------- 8 files changed, 118 insertions(+), 103 deletions(-)
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +16 -11
@@ -25,12 +25,14 @@ MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");static void bcm2835_audio_lock (struct bcm2835_audio_instance *instance) {mutex_lock (&instance->vchi_mutex); -vchiq_use_service (instance->service_handle); +vchiq_use_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle); }static void bcm2835_audio_unlock (struct bcm2835_audio_instance *instance) { -vchiq_release_service (instance->service_handle); +vchiq_release_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);mutex_unlock (&instance->vchi_mutex); }
@@ -44,8 +46,8 @@ static int bcm2835_audio_send_msg_locked(struct bcm2835_audio_instance *instanceinit_completion (&instance->msg_avail_comp); } - status =vchiq_queue_kernel_message (instance->service_handle, - m,sizeof (*m)); + status =vchiq_queue_kernel_message (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle, m,sizeof (*m));if (status) { dev_err(instance->dev, "vchi message queue failed: %d, msg=%d\n",
@@ -115,7 +117,7 @@ static enum vchiq_status audio_vchi_callback(struct vchiq_instance *vchiq_instandev_err (instance->dev,"unexpected callback type=%d\n" , m->type); } -vchiq_release_message (handle, header); +vchiq_release_message (vchiq_instance, instance->service_handle, header);return VCHIQ_SUCCESS ; }
@@ -144,7 +146,8 @@ vc_vchi_audio_init(struct vchiq_instance *vchiq_instance, }/* Finished with the service for now */ -vchiq_release_service (instance->service_handle); +vchiq_release_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);return 0 ; }
@@ -154,10 +157,12 @@ static void vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)int status;mutex_lock (&instance->vchi_mutex); -vchiq_use_service (instance->service_handle); +vchiq_use_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);/* Close all VCHI service connections */ - status =vchiq_close_service (instance->service_handle); + status =vchiq_close_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);if (status) { dev_err(instance->dev, "failed to close VCHI service connection (status=%d)\n",
@@ -227,7 +232,7 @@ int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream) goto deinit;bcm2835_audio_lock (instance); -vchiq_get_peer_version (instance->service_handle, +vchiq_get_peer_version (vchi_ctx->instance, instance->service_handle, &instance->peer_version);bcm2835_audio_unlock (instance);if (instance->peer_version <2 || force_bulk)
@@ -352,8 +357,8 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,while (count >0 ) {int bytes =min (instance->max_packet, count); - status =vchiq_queue_kernel_message (instance->service_handle, - src, bytes); + status =vchiq_queue_kernel_message (vchiq_instance, + instance->service_handle, src, bytes); src += bytes; count -= bytes; }
drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +15 -11
@@ -92,14 +92,17 @@ extern enum vchiq_status vchiq_connect(struct vchiq_instance *instance);extern enum vchiq_status vchiq_open_service (struct vchiq_instance *instance,const struct vchiq_service_params_kernel *params,unsigned int *pservice); -extern enum vchiq_status vchiq_close_service (unsigned int service); -extern enum vchiq_status vchiq_use_service (unsigned int service); -extern enum vchiq_status vchiq_release_service (unsigned int service); -extern void vchiq_msg_queue_push (unsigned int handle,struct vchiq_header *header); -extern void vchiq_release_message (unsigned int service, -struct vchiq_header *header); -extern int vchiq_queue_kernel_message (unsigned int handle,void *data, -unsigned int size); +extern enum vchiq_status vchiq_close_service (struct vchiq_instance *instance, +unsigned int service); +extern enum vchiq_status vchiq_use_service (struct vchiq_instance *instance,unsigned int service); +extern enum vchiq_status vchiq_release_service (struct vchiq_instance *instance, +unsigned int service); +extern void vchiq_msg_queue_push (struct vchiq_instance *instance,unsigned int handle, +struct vchiq_header *header); +extern void vchiq_release_message (struct vchiq_instance *instance,unsigned int service, +struct vchiq_header *header); +extern int vchiq_queue_kernel_message (struct vchiq_instance *instance,unsigned int handle, +void *data,unsigned int size);extern enum vchiq_status vchiq_bulk_transmit (struct vchiq_instance *instance,unsigned int service,const void *data,unsigned int size,void *userdata,enum vchiq_bulk_mode mode);
@@ -107,8 +110,9 @@ extern enum vchiq_status vchiq_bulk_receive(struct vchiq_instance *instance, uns void *data, unsigned int size, void *userdata, enum vchiq_bulk_mode mode);extern void *vchiq_get_service_userdata (unsigned int service); -extern enum vchiq_status vchiq_get_peer_version (unsigned int handle, -short *peer_version); -extern struct vchiq_header *vchiq_msg_hold (unsigned int handle); +extern enum vchiq_status vchiq_get_peer_version (struct vchiq_instance *instance, +unsigned int handle, +short *peer_version); +extern struct vchiq_header *vchiq_msg_hold (struct vchiq_instance *instance,unsigned int handle);#endif /* VCHIQ_H */
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +8 -8
@@ -819,7 +819,7 @@ vchiq_open_service(struct vchiq_instance *instance, *phandle = service->handle; status =vchiq_open_service_internal (service, current->pid);if (status !=VCHIQ_SUCCESS ) { -vchiq_remove_service (service->handle); +vchiq_remove_service (instance, service->handle); *phandle =VCHIQ_SERVICE_HANDLE_INVALID ; } }
@@ -914,7 +914,7 @@ vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handlenum vchiq_status status;struct bulk_waiter_node *waiter =NULL , *iter; - service =find_service_by_handle (handle); + service =find_service_by_handle (instance, handle);if (!service)return VCHIQ_ERROR ;
@@ -1381,14 +1381,14 @@ vchiq_keepalive_thread_func(void *v)*/ while (uc--) {atomic_inc (&arm_state->ka_use_ack_count); - status =vchiq_use_service (ka_handle); + status =vchiq_use_service (instance, ka_handle);if (status !=VCHIQ_SUCCESS ) {vchiq_log_error (vchiq_susp_log_level,"%s vchiq_use_service error %d" , __func__, status); } }while (rc--) { - status =vchiq_release_service (ka_handle); + status =vchiq_release_service (instance, ka_handle);if (status !=VCHIQ_SUCCESS ) { vchiq_log_error(vchiq_susp_log_level, "%s vchiq_release_service error %d", __func__,
@@ -1584,10 +1584,10 @@ vchiq_instance_set_trace(struct vchiq_instance *instance, int trace) }enum vchiq_status -vchiq_use_service (unsigned int handle) +vchiq_use_service (struct vchiq_instance *instance,unsigned int handle) {enum vchiq_status ret =VCHIQ_ERROR ; -struct vchiq_service *service =find_service_by_handle (handle); +struct vchiq_service *service =find_service_by_handle (instance, handle);if (service) { ret =vchiq_use_internal (service->state, service,USE_TYPE_SERVICE );
@@ -1598,10 +1598,10 @@ vchiq_use_service(unsigned int handle)EXPORT_SYMBOL (vchiq_use_service);enum vchiq_status -vchiq_release_service (unsigned int handle) +vchiq_release_service (struct vchiq_instance *instance,unsigned int handle) {enum vchiq_status ret =VCHIQ_ERROR ; -struct vchiq_service *service =find_service_by_handle (handle); +struct vchiq_service *service =find_service_by_handle (instance, handle);if (service) { ret =vchiq_release_internal (service->state, service);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h +2 -2
@@ -86,10 +86,10 @@ extern struct vchiq_state *vchiq_get_state (void);enum vchiq_status -vchiq_use_service (unsigned int handle); +vchiq_use_service (struct vchiq_instance *instance,unsigned int handle);extern enum vchiq_status -vchiq_release_service (unsigned int handle); +vchiq_release_service (struct vchiq_instance *instance,unsigned int handle);extern enum vchiq_status vchiq_check_service (struct vchiq_service *service);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +25 -22
144 lines not on this page · raw message
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +5 -4
@@ -522,7 +522,7 @@ handle_to_service(unsigned int handle) }extern struct vchiq_service * -find_service_by_handle (unsigned int handle); +find_service_by_handle (struct vchiq_instance *instance,unsigned int handle);extern struct vchiq_service *find_service_by_port (struct vchiq_state *state,unsigned int localport);
@@ -550,7 +550,7 @@ extern void vchiq_service_put(struct vchiq_service *service); extern enum vchiq_status -vchiq_queue_message(unsigned int handle, +vchiq_queue_message(struct vchiq_instance *instance, unsigned int handle, ssize_t (*copy_callback)(void *context, void *dest, size_t offset, size_t maxsize), void *context,
@@ -597,12 +597,13 @@ void vchiq_set_conn_state(struct vchiq_state *state, enum vchiq_connstate newstavoid vchiq_log_dump_mem (const char *label,u32 addr,const void *void_mem,size_t num_bytes); -enum vchiq_status vchiq_remove_service (unsigned int service); +enum vchiq_status vchiq_remove_service (struct vchiq_instance *instance,unsigned int service);int vchiq_get_client_id (unsigned int service);void vchiq_get_config (struct vchiq_config *config); -int vchiq_set_service_option (unsigned int service,enum vchiq_service_option option,int value); +int vchiq_set_service_option (struct vchiq_instance *instance,unsigned int service, +enum vchiq_service_option option,int value);#endif
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +19 -17
@@ -108,8 +108,8 @@ static ssize_t vchiq_ioc_copy_element_data(void *context, void *dest, }static int -vchiq_ioc_queue_message (unsigned int handle,struct vchiq_element *elements, -unsigned long count) +vchiq_ioc_queue_message (struct vchiq_instance *instance,unsigned int handle, +struct vchiq_element *elements,unsigned long count) {struct vchiq_io_copy_callback_context context;enum vchiq_status status =VCHIQ_SUCCESS ;
@@ -127,7 +127,7 @@ vchiq_ioc_queue_message(unsigned int handle, struct vchiq_element *elements, total_size += elements[i].size; } - status =vchiq_queue_message (handle, vchiq_ioc_copy_element_data, + status =vchiq_queue_message (instance, handle, vchiq_ioc_copy_element_data, &context, total_size);if (status ==VCHIQ_ERROR )
@@ -191,7 +191,7 @@ static int vchiq_ioc_create_service(struct vchiq_instance *instance,if (args->is_open) { status =vchiq_open_service_internal (service, instance->pid);if (status !=VCHIQ_SUCCESS ) { -vchiq_remove_service (service->handle); +vchiq_remove_service (instance, service->handle);return (status ==VCHIQ_RETRY ) ? -EINTR : -EIO ; }
@@ -266,7 +266,7 @@ static int vchiq_ioc_dequeue_message(struct vchiq_instance *instance,/* Copy to user space if msgbuf is not NULL */ if (!args->buf || (copy_to_user (args->buf, header->data, header->size) ==0 )) { ret = header->size; -vchiq_release_message (service->handle, header); +vchiq_release_message (instance, service->handle, header); }else { ret = -EFAULT ; }
@@ -529,7 +529,7 @@ static int vchiq_ioc_await_completion(struct vchiq_instance *instance, }/* Now it has been copied, the message can be released. */ -vchiq_release_message (service->handle, header); +vchiq_release_message (instance, service->handle, header);/* The completion must point to the msgbuf. */ user_completion.header = msgbuf;
@@ -596,7 +596,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg) i =0 ;while ((service =next_service_by_instance (instance->state, instance, &i))) { - status =vchiq_remove_service (service->handle); + status =vchiq_remove_service (instance, service->handle);vchiq_service_put (service);if (status !=VCHIQ_SUCCESS )break ;
@@ -649,7 +649,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)break ;if (put_user (args.handle, &argp->handle)) { -vchiq_remove_service (args.handle); +vchiq_remove_service (instance, args.handle); ret = -EFAULT ; } }break ;
@@ -673,8 +673,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)*/ if (!user_service->close_pending) { status = (cmd ==VCHIQ_IOC_CLOSE_SERVICE ) ? -vchiq_close_service (service->handle) : -vchiq_remove_service (service->handle); +vchiq_close_service (instance, service->handle) : +vchiq_remove_service (instance, service->handle);if (status !=VCHIQ_SUCCESS )break ; }
@@ -731,7 +731,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (copy_from_user (elements, args.elements, args.count *sizeof (struct vchiq_element )) ==0 ) - ret =vchiq_ioc_queue_message (args.handle, elements, + ret =vchiq_ioc_queue_message (instance, args.handle, elements, args.count);else ret = -EFAULT ;
@@ -827,7 +827,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)break ; } - ret =vchiq_set_service_option (args.handle, args.option, + ret =vchiq_set_service_option (instance, args.handle, args.option, args.value); }break ;
@@ -908,6 +908,7 @@ vchiq_compat_ioctl_create_service(struct file *file, unsigned int cmd, {struct vchiq_create_service args;struct vchiq_create_service32 args32; +struct vchiq_instance *instance = file->private_data;long ret;if (copy_from_user (&args32, ptrargs32,sizeof (args32)))
@@ -926,12 +927,12 @@ vchiq_compat_ioctl_create_service(struct file *file, unsigned int cmd, .handle = args32.handle, }; - ret =vchiq_ioc_create_service (file->private_data, &args); + ret =vchiq_ioc_create_service (instance, &args);if (ret <0 )return ret;if (put_user (args.handle, &ptrargs32->handle)) { -vchiq_remove_service (args.handle); +vchiq_remove_service (instance, args.handle);return -EFAULT ; }
@@ -960,6 +961,7 @@ vchiq_compat_ioctl_queue_message(struct file *file,struct vchiq_queue_message args;struct vchiq_queue_message32 args32;struct vchiq_service *service; +struct vchiq_instance *instance = file->private_data;int ret;if (copy_from_user (&args32, arg,sizeof (args32)))
@@ -974,7 +976,7 @@ vchiq_compat_ioctl_queue_message(struct file *file,if (args32.count >MAX_ELEMENTS )return -EINVAL ; - service =find_service_for_instance (file->private_data, args.handle); + service =find_service_for_instance (instance, args.handle);if (!service)return -EINVAL ;
@@ -994,7 +996,7 @@ vchiq_compat_ioctl_queue_message(struct file *file,compat_ptr (element32[count].data); elements[count].size = element32[count].size; } - ret =vchiq_ioc_queue_message (args.handle, elements, + ret =vchiq_ioc_queue_message (instance, args.handle, elements, args.count); }else { ret = -EINVAL ;
@@ -1261,7 +1263,7 @@ static int vchiq_release(struct inode *inode, struct file *file)spin_unlock (&msg_queue_spinlock);if (header) -vchiq_release_message (service->handle, header); +vchiq_release_message (instance, service->handle, header);spin_lock (&msg_queue_spinlock); }
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c +28 -28
202 lines not on this page · raw message
Signature · 1 line
2.35.3
Re: [PATCH v2 4/9] staging: vchiq_arm: pass vchiq instance to 'find_service_by_handle'
Hi Adrien,
Am 18.05.22 um 21:11 schrieb Adrien Thierry:
Quoted 27 lines
In order to remove the '
vchiq_states' global array, we need to pass thevchiq_instancereference to the 'handle_to_service' function, as well as to all functions that call 'handle_to_service'. This will allow accessing the vchiq state through the vchiq instance instead of through the global array.'
handle_to_service' is called by 'find_service_by_handle'. Therefore, pass the vchiq instance reference to 'find_service_by_handle' and to its callers.Signed-off-by Adrien Thierry <[email protected]>--- .../bcm2835-audio/bcm2835-vchiq.c | 27 +++++---- .../include/linux/raspberrypi/vchiq.h | 26 +++++---- .../interface/vchiq_arm/vchiq_arm.c | 16 +++--- .../interface/vchiq_arm/vchiq_arm.h | 4 +- .../interface/vchiq_arm/vchiq_core.c | 47 ++++++++-------- .../interface/vchiq_arm/vchiq_core.h | 9 +-- .../interface/vchiq_arm/vchiq_dev.c | 36 ++++++------ .../vc04_services/vchiq-mmal/mmal-vchiq.c | 56 +++++++++---------- 8 files changed, 118 insertions(+), 103 deletions(-)drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +0
-0
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio"); · line 29
Quoted 6 lines
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +2
-1@@ -25,12 +25,14 @@ MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");static void bcm2835_audio_lock (struct bcm2835_audio_instance *instance) {mutex_lock (&instance->vchi_mutex); -vchiq_use_service (instance->service_handle); +vchiq_use_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);
while being in the interface directory it's clear that "instance" refers to vchiq, but here it is a higher chance to mixing things up. But not sure if it's okay to use an additional variable "vchiq_instance" to clarify here or the naming "instance" is unlucky.
Quoted 75 lines
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +14
-10}static void bcm2835_audio_unlock (struct bcm2835_audio_instance *instance) { -vchiq_release_service (instance->service_handle); +vchiq_release_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);mutex_unlock (&instance->vchi_mutex); }@@ -44,8 +46,8 @@ static int bcm2835_audio_send_msg_locked(struct bcm2835_audio_instance *instanceinit_completion (&instance->msg_avail_comp); } - status =vchiq_queue_kernel_message (instance->service_handle, - m,sizeof (*m)); + status =vchiq_queue_kernel_message (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle, m,sizeof (*m));if (status) { dev_err(instance->dev, "vchi message queue failed: %d, msg=%d\n",@@ -115,7 +117,7 @@ static enum vchiq_status audio_vchi_callback(struct vchiq_instance *vchiq_instandev_err (instance->dev,"unexpected callback type=%d\n" , m->type); } -vchiq_release_message (handle, header); +vchiq_release_message (vchiq_instance, instance->service_handle, header);return VCHIQ_SUCCESS ; }@@ -144,7 +146,8 @@ vc_vchi_audio_init(struct vchiq_instance *vchiq_instance, }/* Finished with the service for now */ -vchiq_release_service (instance->service_handle); +vchiq_release_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);return 0 ; }@@ -154,10 +157,12 @@ static void vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)int status;mutex_lock (&instance->vchi_mutex); -vchiq_use_service (instance->service_handle); +vchiq_use_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);/* Close all VCHI service connections */ - status =vchiq_close_service (instance->service_handle); + status =vchiq_close_service (instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle);if (status) { dev_err(instance->dev, "failed to close VCHI service connection (status=%d)\n",@@ -227,7 +232,7 @@ int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream) goto deinit;bcm2835_audio_lock (instance); -vchiq_get_peer_version (instance->service_handle, +vchiq_get_peer_version (vchi_ctx->instance, instance->service_handle, &instance->peer_version);bcm2835_audio_unlock (instance);if (instance->peer_version <2 || force_bulk)@@ -352,8 +357,8 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,while (count >0 ) {int bytes =min (instance->max_packet, count); - status =vchiq_queue_kernel_message (instance->service_handle, - src, bytes); + status =vchiq_queue_kernel_message (vchiq_instance, + instance->service_handle, src, bytes); src += bytes; count -= bytes; }
PATCH v2 5/9 staging: vchiq_arm: pass vchiq instance to 'vchiq_get_client_id'
In reply to Adrien ThierryIn order to remove the 'vchiq_states' global array, we need to pass the vchiq_instance reference to the 'handle_to_service' function, as well as to all functions that call 'handle_to_service'. This will allow accessing the vchiq state through the vchiq instance instead of through the global array.
'handle_to_service' is called by 'vchiq_get_client_id'. Therefore, pass the vchiq instance reference to it.
--- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c | 2 +- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h | 2 +- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +1 -1
@@ -398,7 +398,7 @@ vchiq_service_put(struct vchiq_service *service) }int -vchiq_get_client_id (unsigned int handle) +vchiq_get_client_id (struct vchiq_instance *instance,unsigned int handle) {struct vchiq_service *service;int id;
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +1 -1
@@ -599,7 +599,7 @@ void vchiq_log_dump_mem(const char *label, u32 addr, const void *void_mem, size_enum vchiq_status vchiq_remove_service (struct vchiq_instance *instance,unsigned int service); -int vchiq_get_client_id (unsigned int service); +int vchiq_get_client_id (struct vchiq_instance *instance,unsigned int service);void vchiq_get_config (struct vchiq_config *config);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +1 -1
@@ -788,7 +788,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case VCHIQ_IOC_GET_CLIENT_ID : {unsigned int handle = (unsigned int )arg; - ret =vchiq_get_client_id (handle); + ret =vchiq_get_client_id (instance, handle); }break ;case VCHIQ_IOC_GET_CONFIG : {
Signature · 1 line
2.35.3
PATCH v2 6/9 staging: vchiq_arm: pass vchiq instance to 'vchiq_get_service_userdata'
In reply to Adrien ThierryIn order to remove the 'vchiq_states' global array, we need to pass the vchiq_instance reference to the 'handle_to_service' function, as well as to all functions that call 'handle_to_service'. This will allow accessing the vchiq state through the vchiq instance instead of through the global array.
'handle_to_service' is called by 'vchiq_get_service_userdata'. Therefore, pass the vchiq instance reference to it.
--- drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c | 3 ++- .../staging/vc04_services/include/linux/raspberrypi/vchiq.h | 2 +- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c | 2 +- drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-)
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +2 -1
@@ -96,7 +96,8 @@ static enum vchiq_status audio_vchi_callback(struct vchiq_instance *vchiq_instanstruct vchiq_header *header, unsigned int handle, void *userdata) { - struct bcm2835_audio_instance *instance = vchiq_get_service_userdata(handle); + struct bcm2835_audio_instance *instance = vchiq_get_service_userdata(vchiq_instance, + handle);struct vc_audio_msg *m;if (reason !=VCHIQ_MESSAGE_AVAILABLE )
drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +1 -1
@@ -109,7 +109,7 @@ extern enum vchiq_status vchiq_bulk_transmit(struct vchiq_instance *instance, unextern enum vchiq_status vchiq_bulk_receive (struct vchiq_instance *instance,unsigned int service,void *data,unsigned int size,void *userdata,enum vchiq_bulk_mode mode); -extern void *vchiq_get_service_userdata (unsigned int service); +extern void *vchiq_get_service_userdata (struct vchiq_instance *instance,unsigned int service);extern enum vchiq_status vchiq_get_peer_version (struct vchiq_instance *instance,unsigned int handle,short *peer_version);
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +1 -1
@@ -411,7 +411,7 @@ vchiq_get_client_id(struct vchiq_instance *instance, unsigned int handle) }void * -vchiq_get_service_userdata (unsigned int handle) +vchiq_get_service_userdata (struct vchiq_instance *instance,unsigned int handle) {void *userdata;struct vchiq_service *service;
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c +1 -1
@@ -553,7 +553,7 @@ static enum vchiq_status service_callback(struct vchiq_instance *vchiq_instance,struct vchiq_header *header, unsigned int handle, void *bulk_ctx) { - struct vchiq_mmal_instance *instance = vchiq_get_service_userdata(handle); + struct vchiq_mmal_instance *instance = vchiq_get_service_userdata(vchiq_instance, handle);u32 msg_len;struct mmal_msg *msg;struct mmal_msg_context *msg_context;
Signature · 1 line
2.35.3
PATCH v2 7/9 staging: vchiq_arm: pass vchiq instance to 'handle_to_service'
In reply to Adrien ThierryIn order to remove the 'vchiq_states' global array, we need to pass the vchiq_instance reference to the 'handle_to_service' function. This will allow accessing the vchiq state through the vchiq instance instead of through the global array.
--- .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 2 +- .../vc04_services/interface/vchiq_arm/vchiq_core.c | 10 +++++----- .../vc04_services/interface/vchiq_arm/vchiq_core.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +1 -1
@@ -1059,7 +1059,7 @@ service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,DEBUG_TRACE (SERVICE_CALLBACK_LINE );rcu_read_lock (); - service =handle_to_service (handle); + service =handle_to_service (instance, handle);if (WARN_ON (!service)) {rcu_read_unlock ();return VCHIQ_SUCCESS ;
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +5 -5
@@ -240,7 +240,7 @@ find_service_by_handle(struct vchiq_instance *instance, unsigned int handle)struct vchiq_service *service;rcu_read_lock (); - service =handle_to_service (handle); + service =handle_to_service (instance, handle);if (service && service->srvstate !=VCHIQ_SRVSTATE_FREE && service->handle == handle &&kref_get_unless_zero (&service->ref_count)) {
@@ -281,7 +281,7 @@ find_service_for_instance(struct vchiq_instance *instance, unsigned int handle)struct vchiq_service *service;rcu_read_lock (); - service =handle_to_service (handle); + service =handle_to_service (instance, handle); if (service && service->srvstate != VCHIQ_SRVSTATE_FREE && service->handle == handle && service->instance == instance &&
@@ -302,7 +302,7 @@ find_closed_service_for_instance(struct vchiq_instance *instance, unsigned int hstruct vchiq_service *service;rcu_read_lock (); - service =handle_to_service (handle); + service =handle_to_service (instance, handle); if (service && (service->srvstate == VCHIQ_SRVSTATE_FREE || service->srvstate == VCHIQ_SRVSTATE_CLOSED) &&
@@ -404,7 +404,7 @@ vchiq_get_client_id(struct vchiq_instance *instance, unsigned int handle)int id;rcu_read_lock (); - service =handle_to_service (handle); + service =handle_to_service (instance, handle); id = service ? service->client_id :0 ;rcu_read_unlock ();return id;
@@ -417,7 +417,7 @@ vchiq_get_service_userdata(struct vchiq_instance *instance, unsigned int handle)struct vchiq_service *service;rcu_read_lock (); - service =handle_to_service (handle); + service =handle_to_service (instance, handle); userdata = service ? service->base.userdata :NULL ;rcu_read_unlock ();return userdata;
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +1 -1
@@ -510,7 +510,7 @@ request_poll(struct vchiq_state *state, struct vchiq_service *service, int poll_type);static inline struct vchiq_service * -handle_to_service (unsigned int handle) +handle_to_service (struct vchiq_instance *instance,unsigned int handle) {int idx = handle & (VCHIQ_MAX_SERVICES -1 ); struct vchiq_state *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
Signature · 1 line
2.35.3
PATCH v2 8/9 staging: vchiq_arm: use state from vchiq instance
In reply to Adrien ThierryIn 'handle_to_service', access the vchiq state from the vchiq instance instead of the global 'vchiq_states' array. This will allow getting rid of the global 'vchiq_states' array.
--- .../vc04_services/interface/vchiq_arm/vchiq_core.c | 7 +++++++ .../vc04_services/interface/vchiq_arm/vchiq_core.h | 12 +----------- 2 files changed, 8 insertions(+), 11 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +7 -0
@@ -13,6 +13,7 @@#include <linux/rcupdate.h> #include <linux/sched/signal.h> +#include "vchiq_arm.h" #include "vchiq_core.h" #define VCHIQ_SLOT_HANDLER_STACK 8192
@@ -234,6 +235,12 @@ set_service_state(struct vchiq_service *service, int newstate) service->srvstate = newstate; } +struct vchiq_service *handle_to_service (struct vchiq_instance *instance,unsigned int handle) +{ +int idx = handle & (VCHIQ_MAX_SERVICES -1 ); + +return rcu_dereference (instance->state->services[idx]); +}struct vchiq_service *find_service_by_handle (struct vchiq_instance *instance,unsigned int handle) {
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +1 -11
@@ -509,17 +509,7 @@ extern void request_poll(struct vchiq_state *state, struct vchiq_service *service, int poll_type); -static inline struct vchiq_service * -handle_to_service (struct vchiq_instance *instance,unsigned int handle) -{ -int idx = handle & (VCHIQ_MAX_SERVICES -1 ); -struct vchiq_state *state = vchiq_states[(handle /VCHIQ_MAX_SERVICES ) & - (VCHIQ_MAX_STATES -1 )]; - -if (!state) -return NULL ; -return rcu_dereference (state->services[idx]); -} +struct vchiq_service *handle_to_service (struct vchiq_instance *instance,unsigned int handle);extern struct vchiq_service *find_service_by_handle (struct vchiq_instance *instance,unsigned int handle);
Signature · 1 line
2.35.3
Re: [PATCH v2 8/9] staging: vchiq_arm: use state from vchiq instance
Hi Adrien,
Am 18.05.22 um 21:11 schrieb Adrien Thierry:
Quoted 23 lines
In '
handle_to_service', access the vchiq state from the vchiq instance instead of the global 'vchiq_states' array. This will allow getting rid of the global 'vchiq_states' array.Signed-off-by Adrien Thierry <[email protected]>--- .../vc04_services/interface/vchiq_arm/vchiq_core.c | 7 +++++++ .../vc04_services/interface/vchiq_arm/vchiq_core.h | 12 +----------- 2 files changed, 8 insertions(+), 11 deletions(-)drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +1
-0@@ -13,6 +13,7 @@#include <linux/rcupdate.h> #include <linux/sched/signal.h> +#include "vchiq_arm.h" #include "vchiq_core.h" #define VCHIQ_SLOT_HANDLER_STACK 8192
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c set_service_state(struct vchiq_service *service, int newstate) · line 242
Quoted 8 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +5
-0@@ -234,6 +235,12 @@ set_service_state(struct vchiq_service *service, int newstate) service->srvstate = newstate; } +struct vchiq_service *handle_to_service (struct vchiq_instance *instance,unsigned int handle) +{ +int idx = handle & (VCHIQ_MAX_SERVICES -1 ); + +return rcu_dereference (instance->state->services[idx]);
looking at vchiq_initialise() and vchiq_get_state() let me think that we cannot assume that instance->state is always different from NULL.
Quoted 27 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +1
-0+}struct vchiq_service *find_service_by_handle (struct vchiq_instance *instance,unsigned int handle) {drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +1
-11@@ -509,17 +509,7 @@ extern void request_poll(struct vchiq_state *state, struct vchiq_service *service, int poll_type); -static inline struct vchiq_service * -handle_to_service (struct vchiq_instance *instance,unsigned int handle) -{ -int idx = handle & (VCHIQ_MAX_SERVICES -1 ); -struct vchiq_state *state = vchiq_states[(handle /VCHIQ_MAX_SERVICES ) & - (VCHIQ_MAX_STATES -1 )]; - -if (!state) -return NULL ; -return rcu_dereference (state->services[idx]); -} +struct vchiq_service *handle_to_service (struct vchiq_instance *instance,unsigned int handle);extern struct vchiq_service *find_service_by_handle (struct vchiq_instance *instance,unsigned int handle);
PATCH v2 9/9 staging: vchiq_arm: remove global 'vchiq_states' array
In reply to Adrien ThierryRemove global 'vchiq_states' array, which is not used anymore.
This is part of an effort to address TODO item "Get rid of all non essential global structures and create a proper per device structure"
--- .../vc04_services/interface/vchiq_arm/vchiq_core.c | 8 -------- .../vc04_services/interface/vchiq_arm/vchiq_core.h | 2 -- 2 files changed, 10 deletions(-)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +0 -8
@@ -162,7 +162,6 @@ int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;DEFINE_SPINLOCK (bulk_waiter_spinlock);static DEFINE_SPINLOCK (quota_spinlock); -struct vchiq_state *vchiq_states[VCHIQ_MAX_STATES ];static unsigned int handle_seq;static const char *const srvstate_names[] = {
@@ -2157,11 +2156,6 @@ vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_zero, schar threadname[16 ];int i, ret; -if (vchiq_states[0 ]) { -pr_err ("%s: VCHIQ state already initialized\n" , __func__); -return -EINVAL ; - } - local = &slot_zero->slave; remote = &slot_zero->master;
@@ -2282,8 +2276,6 @@ vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_zero, swake_up_process (state->recycle_thread);wake_up_process (state->sync_thread); - vchiq_states[0 ] = state; -/* Indicate readiness to the other side */ local->initialised =1 ;
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +0 -2
@@ -450,8 +450,6 @@ extern int vchiq_core_log_level;extern int vchiq_core_msg_log_level;extern int vchiq_sync_log_level; -extern struct vchiq_state *vchiq_states[VCHIQ_MAX_STATES ]; -extern const char *get_conn_state_name (enum vchiq_connstate conn_state);
Signature · 1 line
2.35.3
Hi Adrien,
Am 18.05.22 um 21:11 schrieb Adrien Thierry:
Quoted 4 lines
This patch series aims at removing some unnecessary global structures (namely, '
g_dev' and 'vchiq_states'), in order to make the driver more robust. This is part of an effort to address TODO item "Get rid of all non essential global structures and create a proper per device structure".
sorry for the delay, but i was fighting with some platform regressions in Linux 5.18.
So except of my comments, this series is:
Quoted 8 lines · Stefan Wahren
Hi Adrien,
Am 18.05.22 um 21:11 schrieb Adrien Thierry:
Quoted 4 lines
This patch series aims at removing some unnecessary global structures (namely, '
g_dev' and 'vchiq_states'), in order to make the driver more robust. This is part of an effort to address TODO item "Get rid of all non essential global structures and create a proper per device structure".
Quoted 8 lines
sorry for the delay, but i was fighting with some platform regressions in Linux 5.18.
So except of my comments, this series is:
Tested-by Stefan Wahren <[email protected]>
Hi Stefan,
Not directly related to these patches, but if you don't mind I would like to know what tests in specific are necessary to tag a Tested-by on a vchiq patch?
For instance, running the userland vchiq_test -f on a RPi 3B would be enough?
thanks,
Gaston