Skip to content

Commit

Permalink
staging: mmal-vchiq: Allocate and free components as required
Browse files Browse the repository at this point in the history
The existing code assumed that there would only ever be 4 components,
and never freed the entries once used.
Allow arbitrary creation and destruction of components.

Signed-off-by: Dave Stevenson <[email protected]>
Signed-off-by: Jacopo Mondi <[email protected]>
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
6by9 authored and gregkh committed Jun 25, 2020
1 parent b18ee53 commit 8c589e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
29 changes: 19 additions & 10 deletions drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
#define USE_VCHIQ_ARM
#include "interface/vchi/vchi.h"

/* maximum number of components supported */
#define VCHIQ_MMAL_MAX_COMPONENTS 4
/*
* maximum number of components supported.
* This matches the maximum permitted by default on the VPU
*/
#define VCHIQ_MMAL_MAX_COMPONENTS 64

/*#define FULL_MSG_DUMP 1*/

Expand Down Expand Up @@ -168,8 +171,6 @@ struct vchiq_mmal_instance {
/* protect accesses to context_map */
struct mutex context_map_lock;

/* component to use next */
int component_idx;
struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];

/* ordered workqueue to process all bulk operations */
Expand Down Expand Up @@ -1626,18 +1627,24 @@ int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
{
int ret;
int idx; /* port index */
struct vchiq_mmal_component *component;
struct vchiq_mmal_component *component = NULL;

if (mutex_lock_interruptible(&instance->vchiq_mutex))
return -EINTR;

if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
for (idx = 0; idx < VCHIQ_MMAL_MAX_COMPONENTS; idx++) {
if (!instance->component[idx].in_use) {
component = &instance->component[idx];
component->in_use = 1;
break;
}
}

if (!component) {
ret = -EINVAL; /* todo is this correct error? */
goto unlock;
}

component = &instance->component[instance->component_idx];

ret = create_component(instance, component, name);
if (ret < 0) {
pr_err("%s: failed to create component %d (Not enough GPU mem?)\n",
Expand Down Expand Up @@ -1688,8 +1695,6 @@ int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
goto release_component;
}

instance->component_idx++;

*component_out = component;

mutex_unlock(&instance->vchiq_mutex);
Expand All @@ -1699,6 +1704,8 @@ int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
release_component:
destroy_component(instance, component);
unlock:
if (component)
component->in_use = 0;
mutex_unlock(&instance->vchiq_mutex);

return ret;
Expand All @@ -1721,6 +1728,8 @@ int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,

ret = destroy_component(instance, component);

component->in_use = 0;

mutex_unlock(&instance->vchiq_mutex);

return ret;
Expand Down
1 change: 1 addition & 0 deletions drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct vchiq_mmal_port {
};

struct vchiq_mmal_component {
u32 in_use:1;
u32 enabled:1;
u32 handle; /* VideoCore handle for component */
u32 inputs; /* Number of input ports */
Expand Down

0 comments on commit 8c589e1

Please sign in to comment.