1 From 9daa20076f689c9d3f32446b5a73a0f0e20651ca Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Mon, 24 Sep 2018 16:51:13 +0100
4 Subject: [PATCH 268/703] staging: mmal-vchiq: Allocate and free components as
7 The existing code assumed that there would only ever be 4 components,
8 and never freed the entries once used.
9 Allow arbitrary creation and destruction of components.
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
13 .../vc04_services/vchiq-mmal/mmal-vchiq.c | 29 ++++++++++++-------
14 .../vc04_services/vchiq-mmal/mmal-vchiq.h | 1 +
15 2 files changed, 20 insertions(+), 10 deletions(-)
17 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
18 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
19 @@ -38,8 +38,11 @@ MODULE_AUTHOR("Dave Stevenson, <dave.ste
20 MODULE_LICENSE("GPL");
21 MODULE_VERSION("0.0.1");
23 -/* maximum number of components supported */
24 -#define VCHIQ_MMAL_MAX_COMPONENTS 4
26 + * maximum number of components supported.
27 + * This matches the maximum permitted by default on the VPU
29 +#define VCHIQ_MMAL_MAX_COMPONENTS 64
31 /*#define FULL_MSG_DUMP 1*/
33 @@ -174,8 +177,6 @@ struct vchiq_mmal_instance {
34 /* protect accesses to context_map */
35 struct mutex context_map_lock;
37 - /* component to use next */
39 struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
41 /* ordered workqueue to process all bulk operations */
42 @@ -1632,18 +1633,24 @@ int vchiq_mmal_component_init(struct vch
45 int idx; /* port index */
46 - struct vchiq_mmal_component *component;
47 + struct vchiq_mmal_component *component = NULL;
49 if (mutex_lock_interruptible(&instance->vchiq_mutex))
52 - if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
53 + for (idx = 0; idx < VCHIQ_MMAL_MAX_COMPONENTS; idx++) {
54 + if (!instance->component[idx].in_use) {
55 + component = &instance->component[idx];
56 + component->in_use = 1;
62 ret = -EINVAL; /* todo is this correct error? */
66 - component = &instance->component[instance->component_idx];
68 ret = create_component(instance, component, name);
70 pr_err("%s: failed to create component %d (Not enough GPU mem?)\n",
71 @@ -1694,8 +1701,6 @@ int vchiq_mmal_component_init(struct vch
72 goto release_component;
75 - instance->component_idx++;
77 *component_out = component;
79 mutex_unlock(&instance->vchiq_mutex);
80 @@ -1705,6 +1710,8 @@ int vchiq_mmal_component_init(struct vch
82 destroy_component(instance, component);
85 + component->in_use = 0;
86 mutex_unlock(&instance->vchiq_mutex);
89 @@ -1727,6 +1734,8 @@ int vchiq_mmal_component_finalise(struct
91 ret = destroy_component(instance, component);
93 + component->in_use = 0;
95 mutex_unlock(&instance->vchiq_mutex);
98 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
99 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
100 @@ -82,6 +82,7 @@ struct vchiq_mmal_port {
103 struct vchiq_mmal_component {
106 u32 handle; /* VideoCore handle for component */
107 u32 inputs; /* Number of input ports */