7e4100f96a8c19fcb18db3be224e7c11c5a8c3bf
[openwrt/staging/jogo.git] /
1 From f94642597f63c71b2ccffddd4f447190c131af56 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] staging: mmal-vchiq: Allocate and free components as
5 required
6
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.
10
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
12 ---
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(-)
16
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");
22
23 -/* maximum number of components supported */
24 -#define VCHIQ_MMAL_MAX_COMPONENTS 4
25 +/*
26 + * maximum number of components supported.
27 + * This matches the maximum permitted by default on the VPU
28 + */
29 +#define VCHIQ_MMAL_MAX_COMPONENTS 64
30
31 /*#define FULL_MSG_DUMP 1*/
32
33 @@ -174,8 +177,6 @@ struct vchiq_mmal_instance {
34 /* protect accesses to context_map */
35 struct mutex context_map_lock;
36
37 - /* component to use next */
38 - int component_idx;
39 struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
40
41 /* ordered workqueue to process all bulk operations */
42 @@ -1632,18 +1633,24 @@ int vchiq_mmal_component_init(struct vch
43 {
44 int ret;
45 int idx; /* port index */
46 - struct vchiq_mmal_component *component;
47 + struct vchiq_mmal_component *component = NULL;
48
49 if (mutex_lock_interruptible(&instance->vchiq_mutex))
50 return -EINTR;
51
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;
57 + break;
58 + }
59 + }
60 +
61 + if (!component) {
62 ret = -EINVAL; /* todo is this correct error? */
63 goto unlock;
64 }
65
66 - component = &instance->component[instance->component_idx];
67 -
68 ret = create_component(instance, component, name);
69 if (ret < 0) {
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;
73 }
74
75 - instance->component_idx++;
76 -
77 *component_out = component;
78
79 mutex_unlock(&instance->vchiq_mutex);
80 @@ -1705,6 +1710,8 @@ int vchiq_mmal_component_init(struct vch
81 release_component:
82 destroy_component(instance, component);
83 unlock:
84 + if (component)
85 + component->in_use = 0;
86 mutex_unlock(&instance->vchiq_mutex);
87
88 return ret;
89 @@ -1727,6 +1734,8 @@ int vchiq_mmal_component_finalise(struct
90
91 ret = destroy_component(instance, component);
92
93 + component->in_use = 0;
94 +
95 mutex_unlock(&instance->vchiq_mutex);
96
97 return ret;
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 {
101 };
102
103 struct vchiq_mmal_component {
104 + u32 in_use:1;
105 bool enabled;
106 u32 handle; /* VideoCore handle for component */
107 u32 inputs; /* Number of input ports */