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

staging: vc04_services: Move global variables tracking allocated pages

The variables tracking allocated pages fragments in vchiq_arm.c
can be easily moved to struct vchiq_drv_mgmt instead of being global.
This helps us to drop the non-essential global variables in the vchiq
interface.

No functional changes intended in this patch.
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarUmang Jain <umang.jain@ideasonboard.com>
Reviewed-by: default avatarStefan Wahren <wahrenst@gmx.net>
Link: https://lore.kernel.org/r/20240412075743.60712-7-umang.jain@ideasonboard.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f875976e
...@@ -130,12 +130,6 @@ struct vchiq_pagelist_info { ...@@ -130,12 +130,6 @@ struct vchiq_pagelist_info {
}; };
static void __iomem *g_regs; static void __iomem *g_regs;
static unsigned int g_fragments_size;
static char *g_fragments_base;
static char *g_free_fragments;
static struct semaphore g_free_fragments_sema;
static DEFINE_SEMAPHORE(g_free_fragments_mutex, 1);
static int static int
vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, void *data, vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, void *data,
...@@ -414,20 +408,20 @@ create_pagelist(struct vchiq_instance *instance, char *buf, char __user *ubuf, ...@@ -414,20 +408,20 @@ create_pagelist(struct vchiq_instance *instance, char *buf, char __user *ubuf,
(drv_mgmt->info->cache_line_size - 1)))) { (drv_mgmt->info->cache_line_size - 1)))) {
char *fragments; char *fragments;
if (down_interruptible(&g_free_fragments_sema)) { if (down_interruptible(&drv_mgmt->free_fragments_sema)) {
cleanup_pagelistinfo(instance, pagelistinfo); cleanup_pagelistinfo(instance, pagelistinfo);
return NULL; return NULL;
} }
WARN_ON(!g_free_fragments); WARN_ON(!drv_mgmt->free_fragments);
down(&g_free_fragments_mutex); down(&drv_mgmt->free_fragments_mutex);
fragments = g_free_fragments; fragments = drv_mgmt->free_fragments;
WARN_ON(!fragments); WARN_ON(!fragments);
g_free_fragments = *(char **)g_free_fragments; drv_mgmt->free_fragments = *(char **)drv_mgmt->free_fragments;
up(&g_free_fragments_mutex); up(&drv_mgmt->free_fragments_mutex);
pagelist->type = PAGELIST_READ_WITH_FRAGMENTS + pagelist->type = PAGELIST_READ_WITH_FRAGMENTS +
(fragments - g_fragments_base) / g_fragments_size; (fragments - drv_mgmt->fragments_base) / drv_mgmt->fragments_size;
} }
return pagelistinfo; return pagelistinfo;
...@@ -455,10 +449,10 @@ free_pagelist(struct vchiq_instance *instance, struct vchiq_pagelist_info *pagel ...@@ -455,10 +449,10 @@ free_pagelist(struct vchiq_instance *instance, struct vchiq_pagelist_info *pagel
pagelistinfo->scatterlist_mapped = 0; pagelistinfo->scatterlist_mapped = 0;
/* Deal with any partial cache lines (fragments) */ /* Deal with any partial cache lines (fragments) */
if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS && g_fragments_base) { if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS && drv_mgmt->fragments_base) {
char *fragments = g_fragments_base + char *fragments = drv_mgmt->fragments_base +
(pagelist->type - PAGELIST_READ_WITH_FRAGMENTS) * (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS) *
g_fragments_size; drv_mgmt->fragments_size;
int head_bytes, tail_bytes; int head_bytes, tail_bytes;
head_bytes = (drv_mgmt->info->cache_line_size - pagelist->offset) & head_bytes = (drv_mgmt->info->cache_line_size - pagelist->offset) &
...@@ -483,11 +477,11 @@ free_pagelist(struct vchiq_instance *instance, struct vchiq_pagelist_info *pagel ...@@ -483,11 +477,11 @@ free_pagelist(struct vchiq_instance *instance, struct vchiq_pagelist_info *pagel
fragments + drv_mgmt->info->cache_line_size, fragments + drv_mgmt->info->cache_line_size,
tail_bytes); tail_bytes);
down(&g_free_fragments_mutex); down(&drv_mgmt->free_fragments_mutex);
*(char **)fragments = g_free_fragments; *(char **)fragments = drv_mgmt->free_fragments;
g_free_fragments = fragments; drv_mgmt->free_fragments = fragments;
up(&g_free_fragments_mutex); up(&drv_mgmt->free_fragments_mutex);
up(&g_free_fragments_sema); up(&drv_mgmt->free_fragments_sema);
} }
/* Need to mark all the pages dirty. */ /* Need to mark all the pages dirty. */
...@@ -523,11 +517,11 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state ...@@ -523,11 +517,11 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state
if (err < 0) if (err < 0)
return err; return err;
g_fragments_size = 2 * drv_mgmt->info->cache_line_size; drv_mgmt->fragments_size = 2 * drv_mgmt->info->cache_line_size;
/* Allocate space for the channels in coherent memory */ /* Allocate space for the channels in coherent memory */
slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE); slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
frag_mem_size = PAGE_ALIGN(g_fragments_size * MAX_FRAGMENTS); frag_mem_size = PAGE_ALIGN(drv_mgmt->fragments_size * MAX_FRAGMENTS);
slot_mem = dmam_alloc_coherent(dev, slot_mem_size + frag_mem_size, slot_mem = dmam_alloc_coherent(dev, slot_mem_size + frag_mem_size,
&slot_phys, GFP_KERNEL); &slot_phys, GFP_KERNEL);
...@@ -547,15 +541,16 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state ...@@ -547,15 +541,16 @@ static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state
vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] = vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
MAX_FRAGMENTS; MAX_FRAGMENTS;
g_fragments_base = (char *)slot_mem + slot_mem_size; drv_mgmt->fragments_base = (char *)slot_mem + slot_mem_size;
g_free_fragments = g_fragments_base; drv_mgmt->free_fragments = drv_mgmt->fragments_base;
for (i = 0; i < (MAX_FRAGMENTS - 1); i++) { for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
*(char **)&g_fragments_base[i * g_fragments_size] = *(char **)&drv_mgmt->fragments_base[i * drv_mgmt->fragments_size] =
&g_fragments_base[(i + 1) * g_fragments_size]; &drv_mgmt->fragments_base[(i + 1) * drv_mgmt->fragments_size];
} }
*(char **)&g_fragments_base[i * g_fragments_size] = NULL; *(char **)&drv_mgmt->fragments_base[i * drv_mgmt->fragments_size] = NULL;
sema_init(&g_free_fragments_sema, MAX_FRAGMENTS); sema_init(&drv_mgmt->free_fragments_sema, MAX_FRAGMENTS);
sema_init(&drv_mgmt->free_fragments_mutex, 1);
err = vchiq_init_state(state, vchiq_slot_zero, dev); err = vchiq_init_state(state, vchiq_slot_zero, dev);
if (err) if (err)
......
...@@ -44,6 +44,12 @@ struct vchiq_drv_mgmt { ...@@ -44,6 +44,12 @@ struct vchiq_drv_mgmt {
struct mutex connected_mutex; struct mutex connected_mutex;
void (*deferred_callback[VCHIQ_DRV_MAX_CALLBACKS])(void); void (*deferred_callback[VCHIQ_DRV_MAX_CALLBACKS])(void);
struct semaphore free_fragments_sema;
struct semaphore free_fragments_mutex;
char *fragments_base;
char *free_fragments;
unsigned int fragments_size;
}; };
struct user_service { struct user_service {
......
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