Skip to content

Commit e1c0af4

Browse files
Umang Jaingregkh
authored andcommitted
staging: vc04_services: Move variables for tracking connections
Connections to the vchiq driver are tracked using global variables. Drop those and introduce them as members of struct vchiq_drv_mgmt. Hence, struct vchiq_drv_mgmt will be used to track the connections. Also, store a vchiq_drv_mgmt pointer to struct vchiq_device to have easy access to struct vchiq_drv_mgmt across vchiq devices. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Link: https://lore.kernel.org/r/20240412075743.60712-5-umang.jain@ideasonboard.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8c9753f commit e1c0af4

6 files changed

Lines changed: 37 additions & 21 deletions

File tree

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state
545545
dev_dbg(&pdev->dev, "arm: vchiq_init - done (slots %pK, phys %pad)\n",
546546
vchiq_slot_zero, &slot_phys);
547547

548-
vchiq_call_connected_callbacks();
548+
mutex_init(&drv_mgmt->connected_mutex);
549+
vchiq_call_connected_callbacks(drv_mgmt);
549550

550551
return 0;
551552
}

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#define MAX_ELEMENTS 8
2121
#define MSG_QUEUE_SIZE 128
2222

23+
#define VCHIQ_DRV_MAX_CALLBACKS 10
24+
2325
struct rpi_firmware;
2426

2527
enum USE_TYPE_E {
@@ -34,6 +36,13 @@ struct vchiq_platform_info {
3436
struct vchiq_drv_mgmt {
3537
struct rpi_firmware *fw;
3638
const struct vchiq_platform_info *info;
39+
40+
bool connected;
41+
int num_deferred_callbacks;
42+
/* Protects connected and num_deferred_callbacks */
43+
struct mutex connected_mutex;
44+
45+
void (*deferred_callback[VCHIQ_DRV_MAX_CALLBACKS])(void);
3746
};
3847

3948
struct user_service {

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_bus.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/slab.h>
1212
#include <linux/string.h>
1313

14+
#include "vchiq_arm.h"
1415
#include "vchiq_bus.h"
1516

1617
static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
@@ -77,6 +78,8 @@ vchiq_device_register(struct device *parent, const char *name)
7778
device->dev.dma_mask = &device->dev.coherent_dma_mask;
7879
device->dev.release = vchiq_device_release;
7980

81+
device->drv_mgmt = dev_get_drvdata(parent);
82+
8083
of_dma_configure(&device->dev, parent->of_node, true);
8184

8285
ret = device_register(&device->dev);

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_bus.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
#include <linux/device.h>
1010
#include <linux/mod_devicetable.h>
1111

12+
struct vchiq_drv_mgmt;
13+
1214
struct vchiq_device {
1315
struct device dev;
16+
struct vchiq_drv_mgmt *drv_mgmt;
1417
};
1518

1619
struct vchiq_driver {
Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
22
/* Copyright (c) 2010-2012 Broadcom. All rights reserved. */
33

4+
#include "vchiq_arm.h"
45
#include "vchiq_connected.h"
56
#include "vchiq_core.h"
67
#include <linux/module.h>
78
#include <linux/mutex.h>
89

910
#define MAX_CALLBACKS 10
1011

11-
static int g_connected;
12-
static int g_num_deferred_callbacks;
13-
static void (*g_deferred_callback[MAX_CALLBACKS])(void);
14-
static DEFINE_MUTEX(g_connected_mutex);
15-
1612
/*
1713
* This function is used to defer initialization until the vchiq stack is
1814
* initialized. If the stack is already initialized, then the callback will
@@ -21,42 +17,44 @@ static DEFINE_MUTEX(g_connected_mutex);
2117
*/
2218
void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void))
2319
{
24-
if (mutex_lock_killable(&g_connected_mutex))
20+
struct vchiq_drv_mgmt *drv_mgmt = device->drv_mgmt;
21+
22+
if (mutex_lock_killable(&drv_mgmt->connected_mutex))
2523
return;
2624

27-
if (g_connected) {
25+
if (drv_mgmt->connected) {
2826
/* We're already connected. Call the callback immediately. */
2927
callback();
3028
} else {
31-
if (g_num_deferred_callbacks >= MAX_CALLBACKS) {
29+
if (drv_mgmt->num_deferred_callbacks >= MAX_CALLBACKS) {
3230
dev_err(&device->dev,
3331
"core: There already %d callback registered - please increase MAX_CALLBACKS\n",
34-
g_num_deferred_callbacks);
32+
drv_mgmt->num_deferred_callbacks);
3533
} else {
36-
g_deferred_callback[g_num_deferred_callbacks] =
34+
drv_mgmt->deferred_callback[drv_mgmt->num_deferred_callbacks] =
3735
callback;
38-
g_num_deferred_callbacks++;
36+
drv_mgmt->num_deferred_callbacks++;
3937
}
4038
}
41-
mutex_unlock(&g_connected_mutex);
39+
mutex_unlock(&drv_mgmt->connected_mutex);
4240
}
4341
EXPORT_SYMBOL(vchiq_add_connected_callback);
4442

4543
/*
4644
* This function is called by the vchiq stack once it has been connected to
4745
* the videocore and clients can start to use the stack.
4846
*/
49-
void vchiq_call_connected_callbacks(void)
47+
void vchiq_call_connected_callbacks(struct vchiq_drv_mgmt *drv_mgmt)
5048
{
5149
int i;
5250

53-
if (mutex_lock_killable(&g_connected_mutex))
51+
if (mutex_lock_killable(&drv_mgmt->connected_mutex))
5452
return;
5553

56-
for (i = 0; i < g_num_deferred_callbacks; i++)
57-
g_deferred_callback[i]();
54+
for (i = 0; i < drv_mgmt->num_deferred_callbacks; i++)
55+
drv_mgmt->deferred_callback[i]();
5856

59-
g_num_deferred_callbacks = 0;
60-
g_connected = 1;
61-
mutex_unlock(&g_connected_mutex);
57+
drv_mgmt->num_deferred_callbacks = 0;
58+
drv_mgmt->connected = true;
59+
mutex_unlock(&drv_mgmt->connected_mutex);
6260
}

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#ifndef VCHIQ_CONNECTED_H
77
#define VCHIQ_CONNECTED_H
88

9+
struct vchiq_drv_mgmt;
10+
911
void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void));
10-
void vchiq_call_connected_callbacks(void);
12+
void vchiq_call_connected_callbacks(struct vchiq_drv_mgmt *mgmt);
1113

1214
#endif /* VCHIQ_CONNECTED_H */

0 commit comments

Comments
 (0)