Skip to content

Commit 42a2f66

Browse files
Umang Jaingregkh
authored andcommitted
staging: vc04_services: Move global g_state to vchiq_state
The patch intended to drop the g_state pointer. g_state is supposed to be a central place to track the state via vchiq_state. This is now moved to be contained in the struct vchiq_drv_mgmt. As a result vchiq_get_state() is also removed. In order to have access to vchiq_drv_mgmt, vchiq_initialise() and vchiq_mmal_init() are modified to receive a struct device pointer as one of their function parameter The vchiq_state pointer is now passed directly to vchiq_dump_platform_instances() to get access to the state instead getting it via vchiq_get_state(). For the char device, struct miscdevice is retrieved by struct file's private data in vchiq_open and struct vchiq_drv_mgmt is retrieved thereafter. Removal of global variable members is now addressed hence, drop the corresponding item from the TODO list. Signed-off-by: Umang Jain <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7f56c60 commit 42a2f66

File tree

12 files changed

+37
-55
lines changed

12 files changed

+37
-55
lines changed

drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "bcm2835.h"
88
#include "vc_vchi_audioserv_defs.h"
99

10+
#include "../interface/vchiq_arm/vchiq_arm.h"
11+
1012
struct bcm2835_audio_instance {
1113
struct device *dev;
1214
unsigned int service_handle;
@@ -175,10 +177,11 @@ static void vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)
175177

176178
int bcm2835_new_vchi_ctx(struct device *dev, struct bcm2835_vchi_ctx *vchi_ctx)
177179
{
180+
struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(dev->parent);
178181
int ret;
179182

180183
/* Initialize and create a VCHI connection */
181-
ret = vchiq_initialise(&vchi_ctx->instance);
184+
ret = vchiq_initialise(&mgmt->state, &vchi_ctx->instance);
182185
if (ret) {
183186
dev_err(dev, "failed to initialise VCHI instance (ret=%d)\n",
184187
ret);

drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ static int mmal_init(struct bcm2835_mmal_dev *dev)
15551555
u32 param_size;
15561556
struct vchiq_mmal_component *camera;
15571557

1558-
ret = vchiq_mmal_init(&dev->instance);
1558+
ret = vchiq_mmal_init(dev->v4l2_dev.dev, &dev->instance);
15591559
if (ret < 0) {
15601560
v4l2_err(&dev->v4l2_dev, "%s: vchiq mmal init failed %d\n",
15611561
__func__, ret);
@@ -1854,7 +1854,7 @@ static int bcm2835_mmal_probe(struct vchiq_device *device)
18541854
return ret;
18551855
}
18561856

1857-
ret = vchiq_mmal_init(&instance);
1857+
ret = vchiq_mmal_init(&device->dev, &instance);
18581858
if (ret < 0)
18591859
return ret;
18601860

drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct vchiq_element {
4848
};
4949

5050
struct vchiq_instance;
51+
struct vchiq_state;
5152

5253
struct vchiq_service_base {
5354
int fourcc;
@@ -78,7 +79,8 @@ struct vchiq_service_params_kernel {
7879
short version_min; /* Update for incompatible changes */
7980
};
8081

81-
extern int vchiq_initialise(struct vchiq_instance **pinstance);
82+
extern int vchiq_initialise(struct vchiq_state *state,
83+
struct vchiq_instance **pinstance);
8284
extern int vchiq_shutdown(struct vchiq_instance *instance);
8385
extern int vchiq_connect(struct vchiq_instance *instance);
8486
extern int vchiq_open_service(struct vchiq_instance *instance,

drivers/staging/vc04_services/interface/TODO

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ The code follows the 80 characters limitation yet tends to go 3 or 4 levels of
4141
indentation deep making it very unpleasant to read. This is specially relevant
4242
in the character driver ioctl code and in the core thread functions.
4343

44-
* Get rid of all non essential global structures and create a proper per
45-
device structure
46-
47-
The first thing one generally sees in a probe function is a memory allocation
48-
for all the device specific data. This structure is then passed all over the
49-
driver. This is good practice since it makes the driver work regardless of the
50-
number of devices probed.
51-
5244
* Clean up Sparse warnings from __user annotations. See
5345
vchiq_irq_queue_bulk_tx_rx(). Ensure that the address of "&waiter->bulk_waiter"
5446
is never disclosed to userspace.

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

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
#define KEEPALIVE_VER 1
6060
#define KEEPALIVE_VER_MIN KEEPALIVE_VER
6161

62-
struct vchiq_state g_state;
63-
6462
/*
6563
* The devices implemented in the VCHIQ firmware are not discoverable,
6664
* so we need to maintain a list of them in order to register them with
@@ -698,9 +696,8 @@ void vchiq_dump_platform_state(struct seq_file *f)
698696
}
699697

700698
#define VCHIQ_INIT_RETRIES 10
701-
int vchiq_initialise(struct vchiq_instance **instance_out)
699+
int vchiq_initialise(struct vchiq_state *state, struct vchiq_instance **instance_out)
702700
{
703-
struct vchiq_state *state;
704701
struct vchiq_instance *instance = NULL;
705702
int i, ret;
706703

@@ -710,7 +707,6 @@ int vchiq_initialise(struct vchiq_instance **instance_out)
710707
* block forever.
711708
*/
712709
for (i = 0; i < VCHIQ_INIT_RETRIES; i++) {
713-
state = vchiq_get_state();
714710
if (state)
715711
break;
716712
usleep_range(500, 600);
@@ -1026,9 +1022,10 @@ add_completion(struct vchiq_instance *instance, enum vchiq_reason reason,
10261022
void *bulk_userdata)
10271023
{
10281024
struct vchiq_completion_data_kernel *completion;
1025+
struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(instance->state->dev);
10291026
int insert;
10301027

1031-
DEBUG_INITIALISE(g_state.local);
1028+
DEBUG_INITIALISE(mgmt->state.local);
10321029

10331030
insert = instance->completion_insert;
10341031
while ((insert - instance->completion_remove) >= MAX_COMPLETIONS) {
@@ -1091,11 +1088,12 @@ service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,
10911088
* containing the original callback and the user state structure, which
10921089
* contains a circular buffer for completion records.
10931090
*/
1091+
struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(instance->state->dev);
10941092
struct user_service *user_service;
10951093
struct vchiq_service *service;
10961094
bool skip_completion = false;
10971095

1098-
DEBUG_INITIALISE(g_state.local);
1096+
DEBUG_INITIALISE(mgmt->state.local);
10991097

11001098
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
11011099

@@ -1200,9 +1198,8 @@ service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,
12001198
bulk_userdata);
12011199
}
12021200

1203-
void vchiq_dump_platform_instances(struct seq_file *f)
1201+
void vchiq_dump_platform_instances(struct vchiq_state *state, struct seq_file *f)
12041202
{
1205-
struct vchiq_state *state = vchiq_get_state();
12061203
int i;
12071204

12081205
if (!state)
@@ -1277,23 +1274,6 @@ void vchiq_dump_platform_service_state(struct seq_file *f,
12771274
seq_puts(f, "\n");
12781275
}
12791276

1280-
struct vchiq_state *
1281-
vchiq_get_state(void)
1282-
{
1283-
if (!g_state.remote) {
1284-
pr_err("%s: g_state.remote == NULL\n", __func__);
1285-
return NULL;
1286-
}
1287-
1288-
if (g_state.remote->initialised != 1) {
1289-
pr_notice("%s: g_state.remote->initialised != 1 (%d)\n",
1290-
__func__, g_state.remote->initialised);
1291-
return NULL;
1292-
}
1293-
1294-
return &g_state;
1295-
}
1296-
12971277
/*
12981278
* Autosuspend related functionality
12991279
*/
@@ -1327,7 +1307,7 @@ vchiq_keepalive_thread_func(void *v)
13271307
.version_min = KEEPALIVE_VER_MIN
13281308
};
13291309

1330-
ret = vchiq_initialise(&instance);
1310+
ret = vchiq_initialise(state, &instance);
13311311
if (ret) {
13321312
dev_err(state->dev, "suspend: %s: vchiq_initialise failed %d\n", __func__, ret);
13331313
goto exit;
@@ -1775,7 +1755,7 @@ static int vchiq_probe(struct platform_device *pdev)
17751755
mgmt->info = info;
17761756
platform_set_drvdata(pdev, mgmt);
17771757

1778-
err = vchiq_platform_init(pdev, &g_state);
1758+
err = vchiq_platform_init(pdev, &mgmt->state);
17791759
if (err)
17801760
goto failed_platform_init;
17811761

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ struct vchiq_drv_mgmt {
5252
unsigned int fragments_size;
5353

5454
void __iomem *regs;
55+
56+
struct vchiq_state state;
5557
};
5658

5759
struct user_service {
@@ -98,11 +100,6 @@ struct vchiq_instance {
98100
struct vchiq_debugfs_node debugfs_node;
99101
};
100102

101-
extern struct vchiq_state g_state;
102-
103-
extern struct vchiq_state *
104-
vchiq_get_state(void);
105-
106103
int
107104
vchiq_use_service(struct vchiq_instance *instance, unsigned int handle);
108105

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3505,7 +3505,7 @@ void vchiq_dump_state(struct seq_file *f, struct vchiq_state *state)
35053505

35063506
vchiq_dump_shared_state(f, state, state->remote, "Remote");
35073507

3508-
vchiq_dump_platform_instances(f);
3508+
vchiq_dump_platform_instances(state, f);
35093509

35103510
for (i = 0; i < state->unused_service; i++) {
35113511
struct vchiq_service *service = find_service_by_port(state, i);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ void remote_event_signal(struct vchiq_state *state, struct remote_event *event);
527527

528528
void vchiq_dump_platform_state(struct seq_file *f);
529529

530-
void vchiq_dump_platform_instances(struct seq_file *f);
530+
void vchiq_dump_platform_instances(struct vchiq_state *state, struct seq_file *f);
531531

532532
void vchiq_dump_platform_service_state(struct seq_file *f, struct vchiq_service *service);
533533

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ static int debugfs_trace_show(struct seq_file *f, void *offset)
4242

4343
static int vchiq_dump_show(struct seq_file *f, void *offset)
4444
{
45-
vchiq_dump_state(f, &g_state);
45+
struct vchiq_instance *instance = f->private;
46+
47+
vchiq_dump_state(f, instance->state);
48+
4649
return 0;
4750
}
4851
DEFINE_SHOW_ATTRIBUTE(vchiq_dump);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int vchiq_ioc_dequeue_message(struct vchiq_instance *instance,
208208
struct vchiq_header *header;
209209
int ret;
210210

211-
DEBUG_INITIALISE(g_state.local);
211+
DEBUG_INITIALISE(instance->state->local);
212212
DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
213213
service = find_service_for_instance(instance, args->handle);
214214
if (!service)
@@ -435,7 +435,7 @@ static int vchiq_ioc_await_completion(struct vchiq_instance *instance,
435435
int remove;
436436
int ret;
437437

438-
DEBUG_INITIALISE(g_state.local);
438+
DEBUG_INITIALISE(instance->state->local);
439439

440440
DEBUG_TRACE(AWAIT_COMPLETION_LINE);
441441
if (!instance->connected)
@@ -1163,7 +1163,9 @@ vchiq_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
11631163

11641164
static int vchiq_open(struct inode *inode, struct file *file)
11651165
{
1166-
struct vchiq_state *state = vchiq_get_state();
1166+
struct miscdevice *vchiq_miscdev = file->private_data;
1167+
struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(vchiq_miscdev->parent);
1168+
struct vchiq_state *state = &mgmt->state;
11671169
struct vchiq_instance *instance;
11681170

11691171
dev_dbg(state->dev, "arm: vchiq open\n");
@@ -1196,7 +1198,7 @@ static int vchiq_open(struct inode *inode, struct file *file)
11961198
static int vchiq_release(struct inode *inode, struct file *file)
11971199
{
11981200
struct vchiq_instance *instance = file->private_data;
1199-
struct vchiq_state *state = vchiq_get_state();
1201+
struct vchiq_state *state = instance->state;
12001202
struct vchiq_service *service;
12011203
int ret = 0;
12021204
int i;

drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <media/videobuf2-vmalloc.h>
2727

2828
#include "../include/linux/raspberrypi/vchiq.h"
29+
#include "../interface/vchiq_arm/vchiq_arm.h"
2930
#include "mmal-common.h"
3031
#include "mmal-vchiq.h"
3132
#include "mmal-msg.h"
@@ -1852,7 +1853,7 @@ int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
18521853
}
18531854
EXPORT_SYMBOL_GPL(vchiq_mmal_finalise);
18541855

1855-
int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
1856+
int vchiq_mmal_init(struct device *dev, struct vchiq_mmal_instance **out_instance)
18561857
{
18571858
int status;
18581859
int err = -ENODEV;
@@ -1865,6 +1866,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
18651866
.callback = mmal_service_callback,
18661867
.userdata = NULL,
18671868
};
1869+
struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(dev->parent);
18681870

18691871
/* compile time checks to ensure structure size as they are
18701872
* directly (de)serialised from memory.
@@ -1880,7 +1882,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
18801882
BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
18811883

18821884
/* create a vchi instance */
1883-
status = vchiq_initialise(&vchiq_instance);
1885+
status = vchiq_initialise(&mgmt->state, &vchiq_instance);
18841886
if (status) {
18851887
pr_err("Failed to initialise VCHI instance (status=%d)\n",
18861888
status);

drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
2626

2727
struct vchiq_mmal_instance;
28+
struct device;
2829

2930
enum vchiq_mmal_es_type {
3031
MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
@@ -94,7 +95,7 @@ struct vchiq_mmal_component {
9495
u32 client_component; /* Used to ref back to client struct */
9596
};
9697

97-
int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
98+
int vchiq_mmal_init(struct device *dev, struct vchiq_mmal_instance **out_instance);
9899
int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
99100

100101
/* Initialise a mmal component and its ports

0 commit comments

Comments
 (0)