mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 18:09:56 +00:00
staging: vc04_services: Add new vc-sm-cma driver
This new driver allows contiguous memory blocks to be imported into the VideoCore VPU memory map, and manages the lifetime of those objects, only releasing the source dmabuf once the VPU has confirmed it has finished with it. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Correct DMA configuration. Now that VCHIQ is setting up the DMA configuration as our parent device, don't try to configure it during probe. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Use a void* pointer as the handle within the kernel The driver was using an unsigned int as the handle to the outside world, and doing a nasty cast to the struct dmabuf when handed it back. This breaks badly with a 64 bit kernel where the pointer doesn't fit in an unsigned int. Switch to using a void* within the kernel. Reality is that it is a struct dma_buf*, but advertising it as such to other drivers seems to encourage the use of it as such, and I'm not sure on the implications of that. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Fix up for 64bit builds There were a number of logging lines that were using inappropriate formatting under 64bit kernels. The kernel_id field passed to/from the VPU was being abused for storing the struct vc_sm_buffer *. This breaks with 64bit kernels, so change to using an IDR. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc_sm_cma: Remove erroneous misc_deregister Code from the misc /dev node was still present in bcm2835_vc_sm_cma_remove, which caused a NULL deref. Remove it. See #2885. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Remove the debugfs directory on remove Without removing that, reloading the driver fails. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Use devm_ allocs for sm_state. Use managed allocations for sm_state, removing reliance on manual management. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Don't fail if debugfs calls fail. Return codes from debugfs calls should never alter the flow of the main code. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Ensure mutex and idr are destroyed map_lock and kernelid_map are created in probe, but not released in release should the vcsm service not connect (eg running the cutdown firmware). Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Remove obsolete comment and make function static Removes obsolete comment about wanting to pass a function pointer into mmal-vchiq as we now do. As the function is passed as a function pointer, the function itself can be static. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Add in allocation for VPU requests. Module has to change from tristate to bool as all CMA functions are boolean. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Update TODO. The driver is already a platform driver, so that can be deleted from the TODO. There are no known issues that need to be resolved. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Add in userspace allocation API Replacing the functionality from the older vc-sm driver, add in a userspace API that allows allocation of buffers, and importing of dma-bufs. The driver hands out dma-buf fds, therefore much of the handling around lifespan and odd mmaps from the old driver goes away. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vcsm-cma: Add cache control ioctls The old driver allowed for direct cache manipulation and that was used by various clients. Replicate here. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vcsm-cma: Alter dev node permissions to 0666 Until the udev rules are updated, open up access to this node by default. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vcsm-cma: Drop logging level on messages in vc_sm_release_resource They weren't errors but were logged as such. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vcsm-cma: Fixup the alloc code handling of kernel_id The allocation code had been copied in from an old branch prior to having added the IDR for 64bit support. It was therefore pushing a pointer into the kernel_id field instead of an IDR handle, the lookup therefore failed, and we never released the buffer. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vcsm-cma: Remove cache manipulation ioctl from ARM64 The cache flushing ioctls are used by the Pi3 HEVC hw-assisted decoder as it needs finer grained flushing control than dma_ops allow. These cache calls are not present for ARM64, therefore disable them. We are not actively supporting 64bit kernels at present, and the use case of the HEVC decoder is fairly limited. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vcsm-cma: Rework to use dma APIs, not CMA Due to a misunderstanding of the DMA mapping APIs, I made the wrong decision on how to implement this. Rework to use dma_alloc_coherent instead of the CMA API. This also allows it to be built as a module easily. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc-sm-cma: Fix the few remaining coding style issues Fix a few minor checkpatch complaints to make the driver clean Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> staging: vc04_services: fix compiling in separate directory The vc04_services Makefiles do not respect the O=path argument correctly: include paths in CFLAGS are given relatively to object path, not source path. Compiling in a separate directory yields #include errors. Signed-off-by: Marek Behún <marek.behun@nic.cz> vc-sm-cma: Fix compatibility ioctl This code path hasn't been used previously. Fixed up after testing with kodi on 32-bit userland and 64-bit kernel Signed-off-by: popcornmix <popcornmix@gmail.com>
This commit is contained in:
committed by
popcornmix
parent
815fa665da
commit
af0d60faf8
@@ -23,6 +23,7 @@ source "drivers/staging/vc04_services/bcm2835-audio/Kconfig"
|
||||
|
||||
source "drivers/staging/vc04_services/bcm2835-camera/Kconfig"
|
||||
source "drivers/staging/vc04_services/vchiq-mmal/Kconfig"
|
||||
source "drivers/staging/vc04_services/vc-sm-cma/Kconfig"
|
||||
|
||||
endif
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ vchiq-objs := \
|
||||
obj-$(CONFIG_SND_BCM2835) += bcm2835-audio/
|
||||
obj-$(CONFIG_VIDEO_BCM2835) += bcm2835-camera/
|
||||
obj-$(CONFIG_BCM2835_VCHIQ_MMAL) += vchiq-mmal/
|
||||
obj-$(CONFIG_BCM_VC_SM_CMA) += vc-sm-cma/
|
||||
|
||||
ccflags-y += -D__VCCOREVER__=0x04000000
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@ obj-$(CONFIG_VIDEO_BCM2835) += bcm2835-v4l2.o
|
||||
|
||||
ccflags-y += \
|
||||
-I $(srctree)/$(src)/.. \
|
||||
-Idrivers/staging/vc04_services \
|
||||
-Idrivers/staging/vc04_services/vchiq-mmal \
|
||||
-I$(srctree)/drivers/staging/vc04_services \
|
||||
-I$(srctree)/drivers/staging/vc04_services/vchiq-mmal \
|
||||
-D__VCCOREVER__=0x04000000
|
||||
|
||||
10
drivers/staging/vc04_services/vc-sm-cma/Kconfig
Normal file
10
drivers/staging/vc04_services/vc-sm-cma/Kconfig
Normal file
@@ -0,0 +1,10 @@
|
||||
config BCM_VC_SM_CMA
|
||||
tristate "VideoCore Shared Memory (CMA) driver"
|
||||
depends on BCM2835_VCHIQ
|
||||
select RBTREE
|
||||
select DMA_SHARED_BUFFER
|
||||
help
|
||||
Say Y here to enable the shared memory interface that
|
||||
supports sharing dmabufs with VideoCore.
|
||||
This operates over the VCHIQ interface to a service
|
||||
running on VideoCore.
|
||||
8
drivers/staging/vc04_services/vc-sm-cma/Makefile
Normal file
8
drivers/staging/vc04_services/vc-sm-cma/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
ccflags-y += -I$(srctree)/drivers/staging/vc04_services -I$(srctree)/drivers/staging/vc04_services/interface/vchi -I$(srctree)/drivers/staging/vc04_services/interface/vchiq_arm
|
||||
# -I"drivers/staging/android/ion/" -I"$(srctree)/fs/"
|
||||
ccflags-y += -D__VCCOREVER__=0
|
||||
|
||||
vc-sm-cma-$(CONFIG_BCM_VC_SM_CMA) := \
|
||||
vc_sm.o vc_sm_cma_vchi.o
|
||||
|
||||
obj-$(CONFIG_BCM_VC_SM_CMA) += vc-sm-cma.o
|
||||
1
drivers/staging/vc04_services/vc-sm-cma/TODO
Normal file
1
drivers/staging/vc04_services/vc-sm-cma/TODO
Normal file
@@ -0,0 +1 @@
|
||||
No currently outstanding tasks except some clean-up.
|
||||
1736
drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
Normal file
1736
drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
Normal file
File diff suppressed because it is too large
Load Diff
84
drivers/staging/vc04_services/vc-sm-cma/vc_sm.h
Normal file
84
drivers/staging/vc04_services/vc-sm-cma/vc_sm.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
|
||||
/*
|
||||
* VideoCore Shared Memory driver using CMA.
|
||||
*
|
||||
* Copyright: 2018, Raspberry Pi (Trading) Ltd
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VC_SM_H
|
||||
#define VC_SM_H
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/dma-direction.h>
|
||||
#include <linux/kref.h>
|
||||
#include <linux/mm_types.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/rbtree.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/shrinker.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/miscdevice.h>
|
||||
|
||||
#define VC_SM_MAX_NAME_LEN 32
|
||||
|
||||
enum vc_sm_vpu_mapping_state {
|
||||
VPU_NOT_MAPPED,
|
||||
VPU_MAPPED,
|
||||
VPU_UNMAPPING
|
||||
};
|
||||
|
||||
struct vc_sm_alloc_data {
|
||||
unsigned long num_pages;
|
||||
void *priv_virt;
|
||||
struct sg_table *sg_table;
|
||||
};
|
||||
|
||||
struct vc_sm_imported {
|
||||
struct dma_buf *dma_buf;
|
||||
struct dma_buf_attachment *attach;
|
||||
struct sg_table *sgt;
|
||||
};
|
||||
|
||||
struct vc_sm_buffer {
|
||||
struct list_head global_buffer_list; /* Global list of buffers. */
|
||||
|
||||
/* Index in the kernel_id idr so that we can find the
|
||||
* mmal_msg_context again when servicing the VCHI reply.
|
||||
*/
|
||||
int kernel_id;
|
||||
|
||||
size_t size;
|
||||
|
||||
/* Lock over all the following state for this buffer */
|
||||
struct mutex lock;
|
||||
struct list_head attachments;
|
||||
|
||||
char name[VC_SM_MAX_NAME_LEN];
|
||||
|
||||
int in_use:1; /* Kernel is still using this resource */
|
||||
int imported:1; /* Imported dmabuf */
|
||||
|
||||
enum vc_sm_vpu_mapping_state vpu_state;
|
||||
u32 vc_handle; /* VideoCore handle for this buffer */
|
||||
int vpu_allocated; /*
|
||||
* The VPU made this allocation. Release the
|
||||
* local dma_buf when the VPU releases the
|
||||
* resource.
|
||||
*/
|
||||
|
||||
/* DMABUF related fields */
|
||||
struct dma_buf *dma_buf;
|
||||
dma_addr_t dma_addr;
|
||||
void *cookie;
|
||||
|
||||
struct vc_sm_privdata_t *private;
|
||||
|
||||
union {
|
||||
struct vc_sm_alloc_data alloc;
|
||||
struct vc_sm_imported import;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
505
drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.c
Normal file
505
drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.c
Normal file
@@ -0,0 +1,505 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* VideoCore Shared Memory CMA allocator
|
||||
*
|
||||
* Copyright: 2018, Raspberry Pi (Trading) Ltd
|
||||
* Copyright 2011-2012 Broadcom Corporation. All rights reserved.
|
||||
*
|
||||
* Based on vmcs_sm driver from Broadcom Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
/* ---- Include Files ----------------------------------------------------- */
|
||||
#include <linux/completion.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/semaphore.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
#include "vc_sm_cma_vchi.h"
|
||||
|
||||
#define VC_SM_VER 1
|
||||
#define VC_SM_MIN_VER 0
|
||||
|
||||
/* ---- Private Constants and Types -------------------------------------- */
|
||||
|
||||
/* Command blocks come from a pool */
|
||||
#define SM_MAX_NUM_CMD_RSP_BLKS 32
|
||||
|
||||
struct sm_cmd_rsp_blk {
|
||||
struct list_head head; /* To create lists */
|
||||
/* To be signaled when the response is there */
|
||||
struct completion cmplt;
|
||||
|
||||
u16 id;
|
||||
u16 length;
|
||||
|
||||
u8 msg[VC_SM_MAX_MSG_LEN];
|
||||
|
||||
uint32_t wait:1;
|
||||
uint32_t sent:1;
|
||||
uint32_t alloc:1;
|
||||
|
||||
};
|
||||
|
||||
struct sm_instance {
|
||||
u32 num_connections;
|
||||
struct vchi_service_handle * vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
|
||||
struct task_struct *io_thread;
|
||||
struct completion io_cmplt;
|
||||
|
||||
vpu_event_cb vpu_event;
|
||||
|
||||
/* Mutex over the following lists */
|
||||
struct mutex lock;
|
||||
u32 trans_id;
|
||||
struct list_head cmd_list;
|
||||
struct list_head rsp_list;
|
||||
struct list_head dead_list;
|
||||
|
||||
struct sm_cmd_rsp_blk free_blk[SM_MAX_NUM_CMD_RSP_BLKS];
|
||||
|
||||
/* Mutex over the free_list */
|
||||
struct mutex free_lock;
|
||||
struct list_head free_list;
|
||||
|
||||
struct semaphore free_sema;
|
||||
|
||||
};
|
||||
|
||||
/* ---- Private Variables ------------------------------------------------ */
|
||||
|
||||
/* ---- Private Function Prototypes -------------------------------------- */
|
||||
|
||||
/* ---- Private Functions ------------------------------------------------ */
|
||||
static int
|
||||
bcm2835_vchi_msg_queue(struct vchi_service_handle * handle,
|
||||
void *data,
|
||||
unsigned int size)
|
||||
{
|
||||
return vchi_queue_kernel_message(handle,
|
||||
data,
|
||||
size);
|
||||
}
|
||||
|
||||
static struct
|
||||
sm_cmd_rsp_blk *vc_vchi_cmd_create(struct sm_instance *instance,
|
||||
enum vc_sm_msg_type id, void *msg,
|
||||
u32 size, int wait)
|
||||
{
|
||||
struct sm_cmd_rsp_blk *blk;
|
||||
struct vc_sm_msg_hdr_t *hdr;
|
||||
|
||||
if (down_interruptible(&instance->free_sema)) {
|
||||
blk = kmalloc(sizeof(*blk), GFP_KERNEL);
|
||||
if (!blk)
|
||||
return NULL;
|
||||
|
||||
blk->alloc = 1;
|
||||
init_completion(&blk->cmplt);
|
||||
} else {
|
||||
mutex_lock(&instance->free_lock);
|
||||
blk =
|
||||
list_first_entry(&instance->free_list,
|
||||
struct sm_cmd_rsp_blk, head);
|
||||
list_del(&blk->head);
|
||||
mutex_unlock(&instance->free_lock);
|
||||
}
|
||||
|
||||
blk->sent = 0;
|
||||
blk->wait = wait;
|
||||
blk->length = sizeof(*hdr) + size;
|
||||
|
||||
hdr = (struct vc_sm_msg_hdr_t *)blk->msg;
|
||||
hdr->type = id;
|
||||
mutex_lock(&instance->lock);
|
||||
instance->trans_id++;
|
||||
/*
|
||||
* Retain the top bit for identifying asynchronous events, or VPU cmds.
|
||||
*/
|
||||
instance->trans_id &= ~0x80000000;
|
||||
hdr->trans_id = instance->trans_id;
|
||||
blk->id = instance->trans_id;
|
||||
mutex_unlock(&instance->lock);
|
||||
|
||||
if (size)
|
||||
memcpy(hdr->body, msg, size);
|
||||
|
||||
return blk;
|
||||
}
|
||||
|
||||
static void
|
||||
vc_vchi_cmd_delete(struct sm_instance *instance, struct sm_cmd_rsp_blk *blk)
|
||||
{
|
||||
if (blk->alloc) {
|
||||
kfree(blk);
|
||||
return;
|
||||
}
|
||||
|
||||
mutex_lock(&instance->free_lock);
|
||||
list_add(&blk->head, &instance->free_list);
|
||||
mutex_unlock(&instance->free_lock);
|
||||
up(&instance->free_sema);
|
||||
}
|
||||
|
||||
static void vc_sm_cma_vchi_rx_ack(struct sm_instance *instance,
|
||||
struct sm_cmd_rsp_blk *cmd,
|
||||
struct vc_sm_result_t *reply,
|
||||
u32 reply_len)
|
||||
{
|
||||
mutex_lock(&instance->lock);
|
||||
list_for_each_entry(cmd,
|
||||
&instance->rsp_list,
|
||||
head) {
|
||||
if (cmd->id == reply->trans_id)
|
||||
break;
|
||||
}
|
||||
mutex_unlock(&instance->lock);
|
||||
|
||||
if (&cmd->head == &instance->rsp_list) {
|
||||
//pr_debug("%s: received response %u, throw away...",
|
||||
pr_err("%s: received response %u, throw away...",
|
||||
__func__,
|
||||
reply->trans_id);
|
||||
} else if (reply_len > sizeof(cmd->msg)) {
|
||||
pr_err("%s: reply too big (%u) %u, throw away...",
|
||||
__func__, reply_len,
|
||||
reply->trans_id);
|
||||
} else {
|
||||
memcpy(cmd->msg, reply,
|
||||
reply_len);
|
||||
complete(&cmd->cmplt);
|
||||
}
|
||||
}
|
||||
|
||||
static int vc_sm_cma_vchi_videocore_io(void *arg)
|
||||
{
|
||||
struct sm_instance *instance = arg;
|
||||
struct sm_cmd_rsp_blk *cmd = NULL, *cmd_tmp;
|
||||
struct vc_sm_result_t *reply;
|
||||
u32 reply_len;
|
||||
s32 status;
|
||||
int svc_use = 1;
|
||||
|
||||
while (1) {
|
||||
if (svc_use)
|
||||
vchi_service_release(instance->vchi_handle[0]);
|
||||
svc_use = 0;
|
||||
|
||||
if (wait_for_completion_interruptible(&instance->io_cmplt))
|
||||
continue;
|
||||
|
||||
vchi_service_use(instance->vchi_handle[0]);
|
||||
svc_use = 1;
|
||||
|
||||
do {
|
||||
/*
|
||||
* Get new command and move it to response list
|
||||
*/
|
||||
mutex_lock(&instance->lock);
|
||||
if (list_empty(&instance->cmd_list)) {
|
||||
/* no more commands to process */
|
||||
mutex_unlock(&instance->lock);
|
||||
break;
|
||||
}
|
||||
cmd = list_first_entry(&instance->cmd_list,
|
||||
struct sm_cmd_rsp_blk, head);
|
||||
list_move(&cmd->head, &instance->rsp_list);
|
||||
cmd->sent = 1;
|
||||
mutex_unlock(&instance->lock);
|
||||
|
||||
/* Send the command */
|
||||
status =
|
||||
bcm2835_vchi_msg_queue(instance->vchi_handle[0],
|
||||
cmd->msg, cmd->length);
|
||||
if (status) {
|
||||
pr_err("%s: failed to queue message (%d)",
|
||||
__func__, status);
|
||||
}
|
||||
|
||||
/* If no reply is needed then we're done */
|
||||
if (!cmd->wait) {
|
||||
mutex_lock(&instance->lock);
|
||||
list_del(&cmd->head);
|
||||
mutex_unlock(&instance->lock);
|
||||
vc_vchi_cmd_delete(instance, cmd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
complete(&cmd->cmplt);
|
||||
continue;
|
||||
}
|
||||
|
||||
} while (1);
|
||||
|
||||
while (!vchi_msg_peek(instance->vchi_handle[0], (void **)&reply,
|
||||
&reply_len, VCHI_FLAGS_NONE)) {
|
||||
if (reply->trans_id & 0x80000000) {
|
||||
/* Async event or cmd from the VPU */
|
||||
if (instance->vpu_event)
|
||||
instance->vpu_event(instance, reply,
|
||||
reply_len);
|
||||
} else {
|
||||
vc_sm_cma_vchi_rx_ack(instance, cmd, reply,
|
||||
reply_len);
|
||||
}
|
||||
|
||||
vchi_msg_remove(instance->vchi_handle[0]);
|
||||
}
|
||||
|
||||
/* Go through the dead list and free them */
|
||||
mutex_lock(&instance->lock);
|
||||
list_for_each_entry_safe(cmd, cmd_tmp, &instance->dead_list,
|
||||
head) {
|
||||
list_del(&cmd->head);
|
||||
vc_vchi_cmd_delete(instance, cmd);
|
||||
}
|
||||
mutex_unlock(&instance->lock);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vc_sm_cma_vchi_callback(void *param,
|
||||
const enum vchi_callback_reason reason,
|
||||
void *msg_handle)
|
||||
{
|
||||
struct sm_instance *instance = param;
|
||||
|
||||
(void)msg_handle;
|
||||
|
||||
switch (reason) {
|
||||
case VCHI_CALLBACK_MSG_AVAILABLE:
|
||||
complete(&instance->io_cmplt);
|
||||
break;
|
||||
|
||||
case VCHI_CALLBACK_SERVICE_CLOSED:
|
||||
pr_info("%s: service CLOSED!!", __func__);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct sm_instance *vc_sm_cma_vchi_init(struct vchi_instance_handle * vchi_instance,
|
||||
unsigned int num_connections,
|
||||
vpu_event_cb vpu_event)
|
||||
{
|
||||
u32 i;
|
||||
struct sm_instance *instance;
|
||||
int status;
|
||||
|
||||
pr_debug("%s: start", __func__);
|
||||
|
||||
if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
|
||||
pr_err("%s: unsupported number of connections %u (max=%u)",
|
||||
__func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
|
||||
|
||||
goto err_null;
|
||||
}
|
||||
/* Allocate memory for this instance */
|
||||
instance = kzalloc(sizeof(*instance), GFP_KERNEL);
|
||||
|
||||
/* Misc initialisations */
|
||||
mutex_init(&instance->lock);
|
||||
init_completion(&instance->io_cmplt);
|
||||
INIT_LIST_HEAD(&instance->cmd_list);
|
||||
INIT_LIST_HEAD(&instance->rsp_list);
|
||||
INIT_LIST_HEAD(&instance->dead_list);
|
||||
INIT_LIST_HEAD(&instance->free_list);
|
||||
sema_init(&instance->free_sema, SM_MAX_NUM_CMD_RSP_BLKS);
|
||||
mutex_init(&instance->free_lock);
|
||||
for (i = 0; i < SM_MAX_NUM_CMD_RSP_BLKS; i++) {
|
||||
init_completion(&instance->free_blk[i].cmplt);
|
||||
list_add(&instance->free_blk[i].head, &instance->free_list);
|
||||
}
|
||||
|
||||
/* Open the VCHI service connections */
|
||||
instance->num_connections = num_connections;
|
||||
for (i = 0; i < num_connections; i++) {
|
||||
struct service_creation params = {
|
||||
.version = VCHI_VERSION_EX(VC_SM_VER, VC_SM_MIN_VER),
|
||||
.service_id = VC_SM_SERVER_NAME,
|
||||
.callback = vc_sm_cma_vchi_callback,
|
||||
.callback_param = instance,
|
||||
};
|
||||
|
||||
status = vchi_service_open(vchi_instance,
|
||||
¶ms, &instance->vchi_handle[i]);
|
||||
if (status) {
|
||||
pr_err("%s: failed to open VCHI service (%d)",
|
||||
__func__, status);
|
||||
|
||||
goto err_close_services;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the thread which takes care of all io to/from videoocore. */
|
||||
instance->io_thread = kthread_create(&vc_sm_cma_vchi_videocore_io,
|
||||
(void *)instance, "SMIO");
|
||||
if (!instance->io_thread) {
|
||||
pr_err("%s: failed to create SMIO thread", __func__);
|
||||
|
||||
goto err_close_services;
|
||||
}
|
||||
instance->vpu_event = vpu_event;
|
||||
set_user_nice(instance->io_thread, -10);
|
||||
wake_up_process(instance->io_thread);
|
||||
|
||||
pr_debug("%s: success - instance %p", __func__, instance);
|
||||
return instance;
|
||||
|
||||
err_close_services:
|
||||
for (i = 0; i < instance->num_connections; i++) {
|
||||
if (instance->vchi_handle[i])
|
||||
vchi_service_close(instance->vchi_handle[i]);
|
||||
}
|
||||
kfree(instance);
|
||||
err_null:
|
||||
pr_debug("%s: FAILED", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int vc_sm_cma_vchi_stop(struct sm_instance **handle)
|
||||
{
|
||||
struct sm_instance *instance;
|
||||
u32 i;
|
||||
|
||||
if (!handle) {
|
||||
pr_err("%s: invalid pointer to handle %p", __func__, handle);
|
||||
goto lock;
|
||||
}
|
||||
|
||||
if (!*handle) {
|
||||
pr_err("%s: invalid handle %p", __func__, *handle);
|
||||
goto lock;
|
||||
}
|
||||
|
||||
instance = *handle;
|
||||
|
||||
/* Close all VCHI service connections */
|
||||
for (i = 0; i < instance->num_connections; i++) {
|
||||
s32 success;
|
||||
|
||||
vchi_service_use(instance->vchi_handle[i]);
|
||||
|
||||
success = vchi_service_close(instance->vchi_handle[i]);
|
||||
}
|
||||
|
||||
kfree(instance);
|
||||
|
||||
*handle = NULL;
|
||||
return 0;
|
||||
|
||||
lock:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int vc_sm_cma_vchi_send_msg(struct sm_instance *handle,
|
||||
enum vc_sm_msg_type msg_id, void *msg,
|
||||
u32 msg_size, void *result, u32 result_size,
|
||||
u32 *cur_trans_id, u8 wait_reply)
|
||||
{
|
||||
int status = 0;
|
||||
struct sm_instance *instance = handle;
|
||||
struct sm_cmd_rsp_blk *cmd_blk;
|
||||
|
||||
if (!handle) {
|
||||
pr_err("%s: invalid handle", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!msg) {
|
||||
pr_err("%s: invalid msg pointer", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cmd_blk =
|
||||
vc_vchi_cmd_create(instance, msg_id, msg, msg_size, wait_reply);
|
||||
if (!cmd_blk) {
|
||||
pr_err("[%s]: failed to allocate global tracking resource",
|
||||
__func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (cur_trans_id)
|
||||
*cur_trans_id = cmd_blk->id;
|
||||
|
||||
mutex_lock(&instance->lock);
|
||||
list_add_tail(&cmd_blk->head, &instance->cmd_list);
|
||||
mutex_unlock(&instance->lock);
|
||||
complete(&instance->io_cmplt);
|
||||
|
||||
if (!wait_reply)
|
||||
/* We're done */
|
||||
return 0;
|
||||
|
||||
/* Wait for the response */
|
||||
if (wait_for_completion_interruptible(&cmd_blk->cmplt)) {
|
||||
mutex_lock(&instance->lock);
|
||||
if (!cmd_blk->sent) {
|
||||
list_del(&cmd_blk->head);
|
||||
mutex_unlock(&instance->lock);
|
||||
vc_vchi_cmd_delete(instance, cmd_blk);
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
list_move(&cmd_blk->head, &instance->dead_list);
|
||||
mutex_unlock(&instance->lock);
|
||||
complete(&instance->io_cmplt);
|
||||
return -EINTR; /* We're done */
|
||||
}
|
||||
|
||||
if (result && result_size) {
|
||||
memcpy(result, cmd_blk->msg, result_size);
|
||||
} else {
|
||||
struct vc_sm_result_t *res =
|
||||
(struct vc_sm_result_t *)cmd_blk->msg;
|
||||
status = (res->success == 0) ? 0 : -ENXIO;
|
||||
}
|
||||
|
||||
mutex_lock(&instance->lock);
|
||||
list_del(&cmd_blk->head);
|
||||
mutex_unlock(&instance->lock);
|
||||
vc_vchi_cmd_delete(instance, cmd_blk);
|
||||
return status;
|
||||
}
|
||||
|
||||
int vc_sm_cma_vchi_free(struct sm_instance *handle, struct vc_sm_free_t *msg,
|
||||
u32 *cur_trans_id)
|
||||
{
|
||||
return vc_sm_cma_vchi_send_msg(handle, VC_SM_MSG_TYPE_FREE,
|
||||
msg, sizeof(*msg), 0, 0, cur_trans_id, 0);
|
||||
}
|
||||
|
||||
int vc_sm_cma_vchi_import(struct sm_instance *handle, struct vc_sm_import *msg,
|
||||
struct vc_sm_import_result *result, u32 *cur_trans_id)
|
||||
{
|
||||
return vc_sm_cma_vchi_send_msg(handle, VC_SM_MSG_TYPE_IMPORT,
|
||||
msg, sizeof(*msg), result, sizeof(*result),
|
||||
cur_trans_id, 1);
|
||||
}
|
||||
|
||||
int vc_sm_cma_vchi_client_version(struct sm_instance *handle,
|
||||
struct vc_sm_version *msg,
|
||||
struct vc_sm_result_t *result,
|
||||
u32 *cur_trans_id)
|
||||
{
|
||||
return vc_sm_cma_vchi_send_msg(handle, VC_SM_MSG_TYPE_CLIENT_VERSION,
|
||||
//msg, sizeof(*msg), result, sizeof(*result),
|
||||
//cur_trans_id, 1);
|
||||
msg, sizeof(*msg), NULL, 0,
|
||||
cur_trans_id, 0);
|
||||
}
|
||||
|
||||
int vc_sm_vchi_client_vc_mem_req_reply(struct sm_instance *handle,
|
||||
struct vc_sm_vc_mem_request_result *msg,
|
||||
uint32_t *cur_trans_id)
|
||||
{
|
||||
return vc_sm_cma_vchi_send_msg(handle,
|
||||
VC_SM_MSG_TYPE_VC_MEM_REQUEST_REPLY,
|
||||
msg, sizeof(*msg), 0, 0, cur_trans_id,
|
||||
0);
|
||||
}
|
||||
63
drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.h
Normal file
63
drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
|
||||
/*
|
||||
* VideoCore Shared Memory CMA allocator
|
||||
*
|
||||
* Copyright: 2018, Raspberry Pi (Trading) Ltd
|
||||
* Copyright 2011-2012 Broadcom Corporation. All rights reserved.
|
||||
*
|
||||
* Based on vmcs_sm driver from Broadcom Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __VC_SM_CMA_VCHI_H__INCLUDED__
|
||||
#define __VC_SM_CMA_VCHI_H__INCLUDED__
|
||||
|
||||
#include "interface/vchi/vchi.h"
|
||||
|
||||
#include "vc_sm_defs.h"
|
||||
|
||||
/*
|
||||
* Forward declare.
|
||||
*/
|
||||
struct sm_instance;
|
||||
|
||||
typedef void (*vpu_event_cb)(struct sm_instance *instance,
|
||||
struct vc_sm_result_t *reply, int reply_len);
|
||||
|
||||
/*
|
||||
* Initialize the shared memory service, opens up vchi connection to talk to it.
|
||||
*/
|
||||
struct sm_instance *vc_sm_cma_vchi_init(struct vchi_instance_handle * vchi_instance,
|
||||
unsigned int num_connections,
|
||||
vpu_event_cb vpu_event);
|
||||
|
||||
/*
|
||||
* Terminates the shared memory service.
|
||||
*/
|
||||
int vc_sm_cma_vchi_stop(struct sm_instance **handle);
|
||||
|
||||
/*
|
||||
* Ask the shared memory service to free up some memory that was previously
|
||||
* allocated by the vc_sm_cma_vchi_alloc function call.
|
||||
*/
|
||||
int vc_sm_cma_vchi_free(struct sm_instance *handle, struct vc_sm_free_t *msg,
|
||||
u32 *cur_trans_id);
|
||||
|
||||
/*
|
||||
* Import a contiguous block of memory and wrap it in a GPU MEM_HANDLE_T.
|
||||
*/
|
||||
int vc_sm_cma_vchi_import(struct sm_instance *handle, struct vc_sm_import *msg,
|
||||
struct vc_sm_import_result *result,
|
||||
u32 *cur_trans_id);
|
||||
|
||||
int vc_sm_cma_vchi_client_version(struct sm_instance *handle,
|
||||
struct vc_sm_version *msg,
|
||||
struct vc_sm_result_t *result,
|
||||
u32 *cur_trans_id);
|
||||
|
||||
int vc_sm_vchi_client_vc_mem_req_reply(struct sm_instance *handle,
|
||||
struct vc_sm_vc_mem_request_result *msg,
|
||||
uint32_t *cur_trans_id);
|
||||
|
||||
#endif /* __VC_SM_CMA_VCHI_H__INCLUDED__ */
|
||||
300
drivers/staging/vc04_services/vc-sm-cma/vc_sm_defs.h
Normal file
300
drivers/staging/vc04_services/vc-sm-cma/vc_sm_defs.h
Normal file
@@ -0,0 +1,300 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
|
||||
/*
|
||||
* VideoCore Shared Memory CMA allocator
|
||||
*
|
||||
* Copyright: 2018, Raspberry Pi (Trading) Ltd
|
||||
*
|
||||
* Based on vc_sm_defs.h from the vmcs_sm driver Copyright Broadcom Corporation.
|
||||
* All IPC messages are copied across to this file, even if the vc-sm-cma
|
||||
* driver is not currently using them.
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __VC_SM_DEFS_H__INCLUDED__
|
||||
#define __VC_SM_DEFS_H__INCLUDED__
|
||||
|
||||
/* FourCC code used for VCHI connection */
|
||||
#define VC_SM_SERVER_NAME MAKE_FOURCC("SMEM")
|
||||
|
||||
/* Maximum message length */
|
||||
#define VC_SM_MAX_MSG_LEN (sizeof(union vc_sm_msg_union_t) + \
|
||||
sizeof(struct vc_sm_msg_hdr_t))
|
||||
#define VC_SM_MAX_RSP_LEN (sizeof(union vc_sm_msg_union_t))
|
||||
|
||||
/* Resource name maximum size */
|
||||
#define VC_SM_RESOURCE_NAME 32
|
||||
|
||||
/*
|
||||
* Version to be reported to the VPU
|
||||
* VPU assumes 0 (aka 1) which does not require the released callback, nor
|
||||
* expect the client to handle VC_MEM_REQUESTS.
|
||||
* Version 2 requires the released callback, and must support VC_MEM_REQUESTS.
|
||||
*/
|
||||
#define VC_SM_PROTOCOL_VERSION 2
|
||||
|
||||
enum vc_sm_msg_type {
|
||||
/* Message types supported for HOST->VC direction */
|
||||
|
||||
/* Allocate shared memory block */
|
||||
VC_SM_MSG_TYPE_ALLOC,
|
||||
/* Lock allocated shared memory block */
|
||||
VC_SM_MSG_TYPE_LOCK,
|
||||
/* Unlock allocated shared memory block */
|
||||
VC_SM_MSG_TYPE_UNLOCK,
|
||||
/* Unlock allocated shared memory block, do not answer command */
|
||||
VC_SM_MSG_TYPE_UNLOCK_NOANS,
|
||||
/* Free shared memory block */
|
||||
VC_SM_MSG_TYPE_FREE,
|
||||
/* Resize a shared memory block */
|
||||
VC_SM_MSG_TYPE_RESIZE,
|
||||
/* Walk the allocated shared memory block(s) */
|
||||
VC_SM_MSG_TYPE_WALK_ALLOC,
|
||||
|
||||
/* A previously applied action will need to be reverted */
|
||||
VC_SM_MSG_TYPE_ACTION_CLEAN,
|
||||
|
||||
/*
|
||||
* Import a physical address and wrap into a MEM_HANDLE_T.
|
||||
* Release with VC_SM_MSG_TYPE_FREE.
|
||||
*/
|
||||
VC_SM_MSG_TYPE_IMPORT,
|
||||
/*
|
||||
*Tells VC the protocol version supported by this client.
|
||||
* 2 supports the async/cmd messages from the VPU for final release
|
||||
* of memory, and for VC allocations.
|
||||
*/
|
||||
VC_SM_MSG_TYPE_CLIENT_VERSION,
|
||||
/* Response to VC request for memory */
|
||||
VC_SM_MSG_TYPE_VC_MEM_REQUEST_REPLY,
|
||||
|
||||
/*
|
||||
* Asynchronous/cmd messages supported for VC->HOST direction.
|
||||
* Signalled by setting the top bit in vc_sm_result_t trans_id.
|
||||
*/
|
||||
|
||||
/*
|
||||
* VC has finished with an imported memory allocation.
|
||||
* Release any Linux reference counts on the underlying block.
|
||||
*/
|
||||
VC_SM_MSG_TYPE_RELEASED,
|
||||
/* VC request for memory */
|
||||
VC_SM_MSG_TYPE_VC_MEM_REQUEST,
|
||||
|
||||
VC_SM_MSG_TYPE_MAX
|
||||
};
|
||||
|
||||
/* Type of memory to be allocated */
|
||||
enum vc_sm_alloc_type_t {
|
||||
VC_SM_ALLOC_CACHED,
|
||||
VC_SM_ALLOC_NON_CACHED,
|
||||
};
|
||||
|
||||
/* Message header for all messages in HOST->VC direction */
|
||||
struct vc_sm_msg_hdr_t {
|
||||
u32 type;
|
||||
u32 trans_id;
|
||||
u8 body[0];
|
||||
|
||||
};
|
||||
|
||||
/* Request to allocate memory (HOST->VC) */
|
||||
struct vc_sm_alloc_t {
|
||||
/* type of memory to allocate */
|
||||
enum vc_sm_alloc_type_t type;
|
||||
/* byte amount of data to allocate per unit */
|
||||
u32 base_unit;
|
||||
/* number of unit to allocate */
|
||||
u32 num_unit;
|
||||
/* alignment to be applied on allocation */
|
||||
u32 alignment;
|
||||
/* identity of who allocated this block */
|
||||
u32 allocator;
|
||||
/* resource name (for easier tracking on vc side) */
|
||||
char name[VC_SM_RESOURCE_NAME];
|
||||
|
||||
};
|
||||
|
||||
/* Result of a requested memory allocation (VC->HOST) */
|
||||
struct vc_sm_alloc_result_t {
|
||||
/* Transaction identifier */
|
||||
u32 trans_id;
|
||||
|
||||
/* Resource handle */
|
||||
u32 res_handle;
|
||||
/* Pointer to resource buffer */
|
||||
u32 res_mem;
|
||||
/* Resource base size (bytes) */
|
||||
u32 res_base_size;
|
||||
/* Resource number */
|
||||
u32 res_num;
|
||||
|
||||
};
|
||||
|
||||
/* Request to free a previously allocated memory (HOST->VC) */
|
||||
struct vc_sm_free_t {
|
||||
/* Resource handle (returned from alloc) */
|
||||
u32 res_handle;
|
||||
/* Resource buffer (returned from alloc) */
|
||||
u32 res_mem;
|
||||
|
||||
};
|
||||
|
||||
/* Request to lock a previously allocated memory (HOST->VC) */
|
||||
struct vc_sm_lock_unlock_t {
|
||||
/* Resource handle (returned from alloc) */
|
||||
u32 res_handle;
|
||||
/* Resource buffer (returned from alloc) */
|
||||
u32 res_mem;
|
||||
|
||||
};
|
||||
|
||||
/* Request to resize a previously allocated memory (HOST->VC) */
|
||||
struct vc_sm_resize_t {
|
||||
/* Resource handle (returned from alloc) */
|
||||
u32 res_handle;
|
||||
/* Resource buffer (returned from alloc) */
|
||||
u32 res_mem;
|
||||
/* Resource *new* size requested (bytes) */
|
||||
u32 res_new_size;
|
||||
|
||||
};
|
||||
|
||||
/* Result of a requested memory lock (VC->HOST) */
|
||||
struct vc_sm_lock_result_t {
|
||||
/* Transaction identifier */
|
||||
u32 trans_id;
|
||||
|
||||
/* Resource handle */
|
||||
u32 res_handle;
|
||||
/* Pointer to resource buffer */
|
||||
u32 res_mem;
|
||||
/*
|
||||
* Pointer to former resource buffer if the memory
|
||||
* was reallocated
|
||||
*/
|
||||
u32 res_old_mem;
|
||||
|
||||
};
|
||||
|
||||
/* Generic result for a request (VC->HOST) */
|
||||
struct vc_sm_result_t {
|
||||
/* Transaction identifier */
|
||||
u32 trans_id;
|
||||
|
||||
s32 success;
|
||||
|
||||
};
|
||||
|
||||
/* Request to revert a previously applied action (HOST->VC) */
|
||||
struct vc_sm_action_clean_t {
|
||||
/* Action of interest */
|
||||
enum vc_sm_msg_type res_action;
|
||||
/* Transaction identifier for the action of interest */
|
||||
u32 action_trans_id;
|
||||
|
||||
};
|
||||
|
||||
/* Request to remove all data associated with a given allocator (HOST->VC) */
|
||||
struct vc_sm_free_all_t {
|
||||
/* Allocator identifier */
|
||||
u32 allocator;
|
||||
};
|
||||
|
||||
/* Request to import memory (HOST->VC) */
|
||||
struct vc_sm_import {
|
||||
/* type of memory to allocate */
|
||||
enum vc_sm_alloc_type_t type;
|
||||
/* pointer to the VC (ie physical) address of the allocated memory */
|
||||
u32 addr;
|
||||
/* size of buffer */
|
||||
u32 size;
|
||||
/* opaque handle returned in RELEASED messages */
|
||||
u32 kernel_id;
|
||||
/* Allocator identifier */
|
||||
u32 allocator;
|
||||
/* resource name (for easier tracking on vc side) */
|
||||
char name[VC_SM_RESOURCE_NAME];
|
||||
};
|
||||
|
||||
/* Result of a requested memory import (VC->HOST) */
|
||||
struct vc_sm_import_result {
|
||||
/* Transaction identifier */
|
||||
u32 trans_id;
|
||||
|
||||
/* Resource handle */
|
||||
u32 res_handle;
|
||||
};
|
||||
|
||||
/* Notification that VC has finished with an allocation (VC->HOST) */
|
||||
struct vc_sm_released {
|
||||
/* cmd type / trans_id */
|
||||
u32 cmd;
|
||||
|
||||
/* pointer to the VC (ie physical) address of the allocated memory */
|
||||
u32 addr;
|
||||
/* size of buffer */
|
||||
u32 size;
|
||||
/* opaque handle returned in RELEASED messages */
|
||||
u32 kernel_id;
|
||||
u32 vc_handle;
|
||||
};
|
||||
|
||||
/*
|
||||
* Client informing VC as to the protocol version it supports.
|
||||
* >=2 requires the released callback, and supports VC asking for memory.
|
||||
* Failure means that the firmware doesn't support this call, and therefore the
|
||||
* client should either fail, or NOT rely on getting the released callback.
|
||||
*/
|
||||
struct vc_sm_version {
|
||||
u32 version;
|
||||
};
|
||||
|
||||
/* Request FROM VideoCore for some memory */
|
||||
struct vc_sm_vc_mem_request {
|
||||
/* cmd type */
|
||||
u32 cmd;
|
||||
|
||||
/* trans_id (from VPU) */
|
||||
u32 trans_id;
|
||||
/* size of buffer */
|
||||
u32 size;
|
||||
/* alignment of buffer */
|
||||
u32 align;
|
||||
/* resource name (for easier tracking) */
|
||||
char name[VC_SM_RESOURCE_NAME];
|
||||
/* VPU handle for the resource */
|
||||
u32 vc_handle;
|
||||
};
|
||||
|
||||
/* Response from the kernel to provide the VPU with some memory */
|
||||
struct vc_sm_vc_mem_request_result {
|
||||
/* Transaction identifier for the VPU */
|
||||
u32 trans_id;
|
||||
/* pointer to the physical address of the allocated memory */
|
||||
u32 addr;
|
||||
/* opaque handle returned in RELEASED messages */
|
||||
u32 kernel_id;
|
||||
};
|
||||
|
||||
/* Union of ALL messages */
|
||||
union vc_sm_msg_union_t {
|
||||
struct vc_sm_alloc_t alloc;
|
||||
struct vc_sm_alloc_result_t alloc_result;
|
||||
struct vc_sm_free_t free;
|
||||
struct vc_sm_lock_unlock_t lock_unlock;
|
||||
struct vc_sm_action_clean_t action_clean;
|
||||
struct vc_sm_resize_t resize;
|
||||
struct vc_sm_lock_result_t lock_result;
|
||||
struct vc_sm_result_t result;
|
||||
struct vc_sm_free_all_t free_all;
|
||||
struct vc_sm_import import;
|
||||
struct vc_sm_import_result import_result;
|
||||
struct vc_sm_version version;
|
||||
struct vc_sm_released released;
|
||||
struct vc_sm_vc_mem_request vc_request;
|
||||
struct vc_sm_vc_mem_request_result vc_request_result;
|
||||
};
|
||||
|
||||
#endif /* __VC_SM_DEFS_H__INCLUDED__ */
|
||||
28
drivers/staging/vc04_services/vc-sm-cma/vc_sm_knl.h
Normal file
28
drivers/staging/vc04_services/vc-sm-cma/vc_sm_knl.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
|
||||
/*
|
||||
* VideoCore Shared Memory CMA allocator
|
||||
*
|
||||
* Copyright: 2018, Raspberry Pi (Trading) Ltd
|
||||
*
|
||||
* Based on vc_sm_defs.h from the vmcs_sm driver Copyright Broadcom Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __VC_SM_KNL_H__INCLUDED__
|
||||
#define __VC_SM_KNL_H__INCLUDED__
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
#error "This interface is for kernel use only..."
|
||||
#endif
|
||||
|
||||
/* Free a previously allocated or imported shared memory handle and block. */
|
||||
int vc_sm_cma_free(void *handle);
|
||||
|
||||
/* Get an internal resource handle mapped from the external one. */
|
||||
int vc_sm_cma_int_handle(void *handle);
|
||||
|
||||
/* Import a block of memory into the GPU space. */
|
||||
int vc_sm_cma_import_dmabuf(struct dma_buf *dmabuf, void **handle);
|
||||
|
||||
#endif /* __VC_SM_KNL_H__INCLUDED__ */
|
||||
@@ -4,5 +4,5 @@ bcm2835-mmal-vchiq-objs := mmal-vchiq.o
|
||||
obj-$(CONFIG_BCM2835_VCHIQ_MMAL) += bcm2835-mmal-vchiq.o
|
||||
|
||||
ccflags-y += \
|
||||
-Idrivers/staging/vc04_services \
|
||||
-I$(srctree)/drivers/staging/vc04_services \
|
||||
-D__VCCOREVER__=0x04000000
|
||||
|
||||
114
include/linux/broadcom/vc_sm_cma_ioctl.h
Normal file
114
include/linux/broadcom/vc_sm_cma_ioctl.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
|
||||
/*
|
||||
* Copyright 2019 Raspberry Pi (Trading) Ltd. All rights reserved.
|
||||
*
|
||||
* Based on vmcs_sm_ioctl.h Copyright Broadcom Corporation.
|
||||
*/
|
||||
|
||||
#ifndef __VC_SM_CMA_IOCTL_H
|
||||
#define __VC_SM_CMA_IOCTL_H
|
||||
|
||||
/* ---- Include Files ---------------------------------------------------- */
|
||||
|
||||
#if defined(__KERNEL__)
|
||||
#include <linux/types.h> /* Needed for standard types */
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
/* ---- Constants and Types ---------------------------------------------- */
|
||||
|
||||
#define VC_SM_CMA_RESOURCE_NAME 32
|
||||
#define VC_SM_CMA_RESOURCE_NAME_DEFAULT "sm-host-resource"
|
||||
|
||||
/* Type define used to create unique IOCTL number */
|
||||
#define VC_SM_CMA_MAGIC_TYPE 'J'
|
||||
|
||||
/* IOCTL commands on /dev/vc-sm-cma */
|
||||
enum vc_sm_cma_cmd_e {
|
||||
VC_SM_CMA_CMD_ALLOC = 0x5A, /* Start at 0x5A arbitrarily */
|
||||
|
||||
VC_SM_CMA_CMD_IMPORT_DMABUF,
|
||||
|
||||
VC_SM_CMA_CMD_CLEAN_INVALID2,
|
||||
|
||||
VC_SM_CMA_CMD_LAST /* Do not delete */
|
||||
};
|
||||
|
||||
/* Cache type supported, conveniently matches the user space definition in
|
||||
* user-vcsm.h.
|
||||
*/
|
||||
enum vc_sm_cma_cache_e {
|
||||
VC_SM_CMA_CACHE_NONE,
|
||||
VC_SM_CMA_CACHE_HOST,
|
||||
VC_SM_CMA_CACHE_VC,
|
||||
VC_SM_CMA_CACHE_BOTH,
|
||||
};
|
||||
|
||||
/* IOCTL Data structures */
|
||||
struct vc_sm_cma_ioctl_alloc {
|
||||
/* user -> kernel */
|
||||
__u32 size;
|
||||
__u32 num;
|
||||
__u32 cached; /* enum vc_sm_cma_cache_e */
|
||||
__u32 pad;
|
||||
__u8 name[VC_SM_CMA_RESOURCE_NAME];
|
||||
|
||||
/* kernel -> user */
|
||||
__s32 handle;
|
||||
__u32 vc_handle;
|
||||
__u64 dma_addr;
|
||||
};
|
||||
|
||||
struct vc_sm_cma_ioctl_import_dmabuf {
|
||||
/* user -> kernel */
|
||||
__s32 dmabuf_fd;
|
||||
__u32 cached; /* enum vc_sm_cma_cache_e */
|
||||
__u8 name[VC_SM_CMA_RESOURCE_NAME];
|
||||
|
||||
/* kernel -> user */
|
||||
__s32 handle;
|
||||
__u32 vc_handle;
|
||||
__u32 size;
|
||||
__u32 pad;
|
||||
__u64 dma_addr;
|
||||
};
|
||||
|
||||
/*
|
||||
* Cache functions to be set to struct vc_sm_cma_ioctl_clean_invalid2
|
||||
* invalidate_mode.
|
||||
*/
|
||||
#define VC_SM_CACHE_OP_NOP 0x00
|
||||
#define VC_SM_CACHE_OP_INV 0x01
|
||||
#define VC_SM_CACHE_OP_CLEAN 0x02
|
||||
#define VC_SM_CACHE_OP_FLUSH 0x03
|
||||
|
||||
struct vc_sm_cma_ioctl_clean_invalid2 {
|
||||
__u32 op_count;
|
||||
__u32 pad;
|
||||
struct vc_sm_cma_ioctl_clean_invalid_block {
|
||||
__u32 invalidate_mode;
|
||||
__u32 block_count;
|
||||
void * __user start_address;
|
||||
__u32 block_size;
|
||||
__u32 inter_block_stride;
|
||||
} s[0];
|
||||
};
|
||||
|
||||
/* IOCTL numbers */
|
||||
#define VC_SM_CMA_IOCTL_MEM_ALLOC\
|
||||
_IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_ALLOC,\
|
||||
struct vc_sm_cma_ioctl_alloc)
|
||||
|
||||
#define VC_SM_CMA_IOCTL_MEM_IMPORT_DMABUF\
|
||||
_IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_IMPORT_DMABUF,\
|
||||
struct vc_sm_cma_ioctl_import_dmabuf)
|
||||
|
||||
#define VC_SM_CMA_IOCTL_MEM_CLEAN_INVALID2\
|
||||
_IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_CLEAN_INVALID2,\
|
||||
struct vc_sm_cma_ioctl_clean_invalid2)
|
||||
|
||||
#endif /* __VC_SM_CMA_IOCTL_H */
|
||||
Reference in New Issue
Block a user