Commit e1c0af4f authored by Umang Jain's avatar Umang Jain Committed by Greg Kroah-Hartman

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: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarUmang Jain <umang.jain@ideasonboard.com>
Link: https://lore.kernel.org/r/20240412075743.60712-5-umang.jain@ideasonboard.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8c9753f6
...@@ -545,7 +545,8 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state ...@@ -545,7 +545,8 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state
dev_dbg(&pdev->dev, "arm: vchiq_init - done (slots %pK, phys %pad)\n", dev_dbg(&pdev->dev, "arm: vchiq_init - done (slots %pK, phys %pad)\n",
vchiq_slot_zero, &slot_phys); vchiq_slot_zero, &slot_phys);
vchiq_call_connected_callbacks(); mutex_init(&drv_mgmt->connected_mutex);
vchiq_call_connected_callbacks(drv_mgmt);
return 0; return 0;
} }
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#define MAX_ELEMENTS 8 #define MAX_ELEMENTS 8
#define MSG_QUEUE_SIZE 128 #define MSG_QUEUE_SIZE 128
#define VCHIQ_DRV_MAX_CALLBACKS 10
struct rpi_firmware; struct rpi_firmware;
enum USE_TYPE_E { enum USE_TYPE_E {
...@@ -34,6 +36,13 @@ struct vchiq_platform_info { ...@@ -34,6 +36,13 @@ struct vchiq_platform_info {
struct vchiq_drv_mgmt { struct vchiq_drv_mgmt {
struct rpi_firmware *fw; struct rpi_firmware *fw;
const struct vchiq_platform_info *info; const struct vchiq_platform_info *info;
bool connected;
int num_deferred_callbacks;
/* Protects connected and num_deferred_callbacks */
struct mutex connected_mutex;
void (*deferred_callback[VCHIQ_DRV_MAX_CALLBACKS])(void);
}; };
struct user_service { struct user_service {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include "vchiq_arm.h"
#include "vchiq_bus.h" #include "vchiq_bus.h"
static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv) 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) ...@@ -77,6 +78,8 @@ vchiq_device_register(struct device *parent, const char *name)
device->dev.dma_mask = &device->dev.coherent_dma_mask; device->dev.dma_mask = &device->dev.coherent_dma_mask;
device->dev.release = vchiq_device_release; device->dev.release = vchiq_device_release;
device->drv_mgmt = dev_get_drvdata(parent);
of_dma_configure(&device->dev, parent->of_node, true); of_dma_configure(&device->dev, parent->of_node, true);
ret = device_register(&device->dev); ret = device_register(&device->dev);
......
...@@ -9,8 +9,11 @@ ...@@ -9,8 +9,11 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
struct vchiq_drv_mgmt;
struct vchiq_device { struct vchiq_device {
struct device dev; struct device dev;
struct vchiq_drv_mgmt *drv_mgmt;
}; };
struct vchiq_driver { struct vchiq_driver {
......
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright (c) 2010-2012 Broadcom. All rights reserved. */ /* Copyright (c) 2010-2012 Broadcom. All rights reserved. */
#include "vchiq_arm.h"
#include "vchiq_connected.h" #include "vchiq_connected.h"
#include "vchiq_core.h" #include "vchiq_core.h"
#include <linux/module.h> #include <linux/module.h>
...@@ -8,11 +9,6 @@ ...@@ -8,11 +9,6 @@
#define MAX_CALLBACKS 10 #define MAX_CALLBACKS 10
static int g_connected;
static int g_num_deferred_callbacks;
static void (*g_deferred_callback[MAX_CALLBACKS])(void);
static DEFINE_MUTEX(g_connected_mutex);
/* /*
* This function is used to defer initialization until the vchiq stack is * This function is used to defer initialization until the vchiq stack is
* initialized. If the stack is already initialized, then the callback will * initialized. If the stack is already initialized, then the callback will
...@@ -21,24 +17,26 @@ static DEFINE_MUTEX(g_connected_mutex); ...@@ -21,24 +17,26 @@ static DEFINE_MUTEX(g_connected_mutex);
*/ */
void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void)) void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void))
{ {
if (mutex_lock_killable(&g_connected_mutex)) struct vchiq_drv_mgmt *drv_mgmt = device->drv_mgmt;
if (mutex_lock_killable(&drv_mgmt->connected_mutex))
return; return;
if (g_connected) { if (drv_mgmt->connected) {
/* We're already connected. Call the callback immediately. */ /* We're already connected. Call the callback immediately. */
callback(); callback();
} else { } else {
if (g_num_deferred_callbacks >= MAX_CALLBACKS) { if (drv_mgmt->num_deferred_callbacks >= MAX_CALLBACKS) {
dev_err(&device->dev, dev_err(&device->dev,
"core: There already %d callback registered - please increase MAX_CALLBACKS\n", "core: There already %d callback registered - please increase MAX_CALLBACKS\n",
g_num_deferred_callbacks); drv_mgmt->num_deferred_callbacks);
} else { } else {
g_deferred_callback[g_num_deferred_callbacks] = drv_mgmt->deferred_callback[drv_mgmt->num_deferred_callbacks] =
callback; callback;
g_num_deferred_callbacks++; drv_mgmt->num_deferred_callbacks++;
} }
} }
mutex_unlock(&g_connected_mutex); mutex_unlock(&drv_mgmt->connected_mutex);
} }
EXPORT_SYMBOL(vchiq_add_connected_callback); EXPORT_SYMBOL(vchiq_add_connected_callback);
...@@ -46,17 +44,17 @@ EXPORT_SYMBOL(vchiq_add_connected_callback); ...@@ -46,17 +44,17 @@ EXPORT_SYMBOL(vchiq_add_connected_callback);
* This function is called by the vchiq stack once it has been connected to * This function is called by the vchiq stack once it has been connected to
* the videocore and clients can start to use the stack. * the videocore and clients can start to use the stack.
*/ */
void vchiq_call_connected_callbacks(void) void vchiq_call_connected_callbacks(struct vchiq_drv_mgmt *drv_mgmt)
{ {
int i; int i;
if (mutex_lock_killable(&g_connected_mutex)) if (mutex_lock_killable(&drv_mgmt->connected_mutex))
return; return;
for (i = 0; i < g_num_deferred_callbacks; i++) for (i = 0; i < drv_mgmt->num_deferred_callbacks; i++)
g_deferred_callback[i](); drv_mgmt->deferred_callback[i]();
g_num_deferred_callbacks = 0; drv_mgmt->num_deferred_callbacks = 0;
g_connected = 1; drv_mgmt->connected = true;
mutex_unlock(&g_connected_mutex); mutex_unlock(&drv_mgmt->connected_mutex);
} }
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#ifndef VCHIQ_CONNECTED_H #ifndef VCHIQ_CONNECTED_H
#define VCHIQ_CONNECTED_H #define VCHIQ_CONNECTED_H
struct vchiq_drv_mgmt;
void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void)); void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void));
void vchiq_call_connected_callbacks(void); void vchiq_call_connected_callbacks(struct vchiq_drv_mgmt *mgmt);
#endif /* VCHIQ_CONNECTED_H */ #endif /* VCHIQ_CONNECTED_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment