Skip to content

Commit df720d3

Browse files
Tim Goverpopcornmix
authored andcommitted
vcsm: VideoCore shared memory service for BCM2835
Add experimental support for the VideoCore shared memory service. This allows user processes to allocate memory from VideoCore's GPU relocatable heap and mmap the buffers. Additionally, the memory handles can passed to other VideoCore services such as MMAL, OpenMax and DispmanX TODO * This driver was originally released for BCM28155 which has a different cache architecture to BCM2835. Consequently, in this release only uncached mappings are supported. However, there's no fundamental reason which cached mappings cannot be support or BCM2835 * More refactoring is required to remove the typedefs. * Re-enable the some of the commented out debug-fs statistics which were disabled when migrating code from proc-fs. * There's a lot of code to support sharing of VCSM in order to support Android. This could probably done more cleanly or perhaps just removed. Signed-off-by: Tim Gover <timgover@gmail.com> config: Disable VC_SM for now to fix hang with cutdown kernel vcsm: Use boolean as it cannot be built as module On building the bcm_vc_sm as a module we get the following error: v7_dma_flush_range and do_munmap are undefined in vc-sm.ko. Fix by making it not an option to build as module vcsm: Add ioctl for custom cache flushing vc-sm: Move headers out of arch directory Signed-off-by: Noralf Trønnes <noralf@tronnes.org> vcsm: Treat EBUSY as success rather than SIGBUS Currently if two cores access the same page concurrently one will return VM_FAULT_NOPAGE and the other VM_FAULT_SIGBUS crashing the user code. Also report when mapping fails. Signed-off-by: popcornmix <popcornmix@gmail.com> vcsm: Provide new ioctl to clean/invalidate a 2D block vcsm: Convert to loading via device tree. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> VCSM: New option to import a DMABUF for VPU use Takes a dmabuf, and then calls over to the VPU to wrap it into a suitable handle. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> vcsm: fix multi-platform build vcsm: add macros for cache functions vcsm: use dma APIs for cache functions * Will handle multi-platform builds vcsm: Fix up macros to avoid breaking numbers used by existing apps vcsm: Define cache operation constants in user header Without this change, users have to use raw values (1, 2, 3) to specify cache operation. Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Support for finding user/vc handle in memory pool vmcs_sm_{usr,vc}_handle_from_pid_and_address() were failing to find handle if specified user pointer is not exactly the one that the memory locking call returned even if the pointer is in range of map/resource. So fixed the functions to match the range. Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Unify cache manipulating functions Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Fix obscure conditions Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Fix memory leaking on clean_invalid2 ioctl handler Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Describe the use of cache operation constants Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Fix obscure conditions again Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Add no-op cache operation constant Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Revert to do page-table-walk-based cache manipulating on some ioctl calls On FLUSH, INVALID, CLEAN_INVALID ioctl calls, cache operations based on page table walk were used in case that the buffer of the cache is not pinned. So reverted to do page-table-based cache manipulating. Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Define cache operation constants in user header Without this change, users have to use raw values (1, 2, 3) to specify cache operation. Signed-off-by: Sugizaki Yukimasa <i.can.speak.c.and.basic@gmail.com> vcsm: Updates for changed vchiq interface vcsm: Fix an NULL dereference in the import_dmabuf error path resource was dereferenced even though it was NULL. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> vcsm: Use struct service_creation vcsm: Fix makefile include on out-of-tree builds The vc_sm module tries to include the 'fs' directory from the $(srctree). $(srctree) is already provided by the build system, and causes the include path to be duplicated. With -Werror this fails to compile. Remove the unnecessary variable. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> vcsm: Remove set but unused variable The 'success' variable is set by the call to vchi_service_close() but never checked. Remove it, keeping the call in place. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> vcsm: Reduce scope of local functions The functions: vc_vchi_sm_send_msg vc_sm_ioctl_alloc vc_sm_ioctl_alloc_share vc_sm_ioctl_import_dmabuf Are declared without a prototype. They are not used outside of this module, thus - convert them to static functions. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> vc_sm: Let it support to build in the non-src folder If we build the kernel with "-O=$non-src-folder", this driver will introdcue a building error because of the header's location. Signed-off-by: Hui Wang <hui.wang@canonical.com>
1 parent d877b9c commit df720d3

11 files changed

Lines changed: 4733 additions & 0 deletions

File tree

‎drivers/char/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
menu "Character devices"
77

8+
source "drivers/char/broadcom/Kconfig"
9+
810
source "drivers/tty/Kconfig"
911

1012
config DEVMEM

‎drivers/char/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ js-rtc-y = rtc.o
5252
obj-$(CONFIG_XILLYBUS) += xillybus/
5353
obj-$(CONFIG_POWERNV_OP_PANEL) += powernv-op-panel.o
5454
obj-$(CONFIG_ADI) += adi.o
55+
obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/

‎drivers/char/broadcom/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ config BCM2708_VCMEM
1616
Helper for videocore memory access and total size allocation.
1717

1818
endif
19+
20+
config BCM_VC_SM
21+
bool "VMCS Shared Memory"
22+
depends on BCM2835_VCHIQ
23+
select BCM2708_VCMEM
24+
select DMA_SHARED_BUFFER
25+
default n
26+
help
27+
Support for the VC shared memory on the Broadcom reference
28+
design. Uses the VCHIQ stack.

‎drivers/char/broadcom/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
2+
obj-$(CONFIG_BCM_VC_SM) += vc_sm/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ccflags-$(CONFIG_BCM_VC_SM) += -Werror -Wall -Wstrict-prototypes -Wno-trigraphs -O2
2+
ccflags-$(CONFIG_BCM_VC_SM) += -I$(srctree)/"drivers/staging/vc04_services" -I$(srctree)/"drivers/staging/vc04_services/interface/vchi" -I$(srctree)/"drivers/staging/vc04_services/interface/vchiq_arm" -I$(srctree)/"fs"
3+
ccflags-$(CONFIG_BCM_VC_SM) += -DOS_ASSERT_FAILURE -D__STDC_VERSION=199901L -D__STDC_VERSION__=199901L -D__VCCOREVER__=0 -D__KERNEL__ -D__linux__
4+
5+
obj-$(CONFIG_BCM_VC_SM) := vc-sm.o
6+
7+
vc-sm-objs := \
8+
vmcs_sm.o \
9+
vc_vchi_sm.o
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/*
2+
****************************************************************************
3+
* Copyright 2011 Broadcom Corporation. All rights reserved.
4+
*
5+
* Unless you and Broadcom execute a separate written software license
6+
* agreement governing use of this software, this software is licensed to you
7+
* under the terms of the GNU General Public License version 2, available at
8+
* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
9+
*
10+
* Notwithstanding the above, under no circumstances may you combine this
11+
* software in any way with any other Broadcom software provided under a
12+
* license other than the GPL, without Broadcom's express prior written
13+
* consent.
14+
****************************************************************************
15+
*/
16+
17+
#ifndef __VC_SM_DEFS_H__INCLUDED__
18+
#define __VC_SM_DEFS_H__INCLUDED__
19+
20+
/* FourCC code used for VCHI connection */
21+
#define VC_SM_SERVER_NAME MAKE_FOURCC("SMEM")
22+
23+
/* Maximum message length */
24+
#define VC_SM_MAX_MSG_LEN (sizeof(union vc_sm_msg_union_t) + \
25+
sizeof(struct vc_sm_msg_hdr_t))
26+
#define VC_SM_MAX_RSP_LEN (sizeof(union vc_sm_msg_union_t))
27+
28+
/* Resource name maximum size */
29+
#define VC_SM_RESOURCE_NAME 32
30+
31+
enum vc_sm_msg_type {
32+
/* Message types supported for HOST->VC direction */
33+
34+
/* Allocate shared memory block */
35+
VC_SM_MSG_TYPE_ALLOC,
36+
/* Lock allocated shared memory block */
37+
VC_SM_MSG_TYPE_LOCK,
38+
/* Unlock allocated shared memory block */
39+
VC_SM_MSG_TYPE_UNLOCK,
40+
/* Unlock allocated shared memory block, do not answer command */
41+
VC_SM_MSG_TYPE_UNLOCK_NOANS,
42+
/* Free shared memory block */
43+
VC_SM_MSG_TYPE_FREE,
44+
/* Resize a shared memory block */
45+
VC_SM_MSG_TYPE_RESIZE,
46+
/* Walk the allocated shared memory block(s) */
47+
VC_SM_MSG_TYPE_WALK_ALLOC,
48+
49+
/* A previously applied action will need to be reverted */
50+
VC_SM_MSG_TYPE_ACTION_CLEAN,
51+
52+
/*
53+
* Import a physical address and wrap into a MEM_HANDLE_T.
54+
* Release with VC_SM_MSG_TYPE_FREE.
55+
*/
56+
VC_SM_MSG_TYPE_IMPORT,
57+
58+
/* Message types supported for VC->HOST direction */
59+
60+
/*
61+
* VC has finished with an imported memory allocation.
62+
* Release any Linux reference counts on the underlying block.
63+
*/
64+
VC_SM_MSG_TYPE_RELEASED,
65+
66+
VC_SM_MSG_TYPE_MAX
67+
};
68+
69+
/* Type of memory to be allocated */
70+
enum vc_sm_alloc_type_t {
71+
VC_SM_ALLOC_CACHED,
72+
VC_SM_ALLOC_NON_CACHED,
73+
};
74+
75+
/* Message header for all messages in HOST->VC direction */
76+
struct vc_sm_msg_hdr_t {
77+
int32_t type;
78+
uint32_t trans_id;
79+
uint8_t body[0];
80+
81+
};
82+
83+
/* Request to allocate memory (HOST->VC) */
84+
struct vc_sm_alloc_t {
85+
/* type of memory to allocate */
86+
enum vc_sm_alloc_type_t type;
87+
/* byte amount of data to allocate per unit */
88+
uint32_t base_unit;
89+
/* number of unit to allocate */
90+
uint32_t num_unit;
91+
/* alignement to be applied on allocation */
92+
uint32_t alignement;
93+
/* identity of who allocated this block */
94+
uint32_t allocator;
95+
/* resource name (for easier tracking on vc side) */
96+
char name[VC_SM_RESOURCE_NAME];
97+
98+
};
99+
100+
/* Result of a requested memory allocation (VC->HOST) */
101+
struct vc_sm_alloc_result_t {
102+
/* Transaction identifier */
103+
uint32_t trans_id;
104+
105+
/* Resource handle */
106+
uint32_t res_handle;
107+
/* Pointer to resource buffer */
108+
uint32_t res_mem;
109+
/* Resource base size (bytes) */
110+
uint32_t res_base_size;
111+
/* Resource number */
112+
uint32_t res_num;
113+
114+
};
115+
116+
/* Request to free a previously allocated memory (HOST->VC) */
117+
struct vc_sm_free_t {
118+
/* Resource handle (returned from alloc) */
119+
uint32_t res_handle;
120+
/* Resource buffer (returned from alloc) */
121+
uint32_t res_mem;
122+
123+
};
124+
125+
/* Request to lock a previously allocated memory (HOST->VC) */
126+
struct vc_sm_lock_unlock_t {
127+
/* Resource handle (returned from alloc) */
128+
uint32_t res_handle;
129+
/* Resource buffer (returned from alloc) */
130+
uint32_t res_mem;
131+
132+
};
133+
134+
/* Request to resize a previously allocated memory (HOST->VC) */
135+
struct vc_sm_resize_t {
136+
/* Resource handle (returned from alloc) */
137+
uint32_t res_handle;
138+
/* Resource buffer (returned from alloc) */
139+
uint32_t res_mem;
140+
/* Resource *new* size requested (bytes) */
141+
uint32_t res_new_size;
142+
143+
};
144+
145+
/* Result of a requested memory lock (VC->HOST) */
146+
struct vc_sm_lock_result_t {
147+
/* Transaction identifier */
148+
uint32_t trans_id;
149+
150+
/* Resource handle */
151+
uint32_t res_handle;
152+
/* Pointer to resource buffer */
153+
uint32_t res_mem;
154+
/*
155+
* Pointer to former resource buffer if the memory
156+
* was reallocated
157+
*/
158+
uint32_t res_old_mem;
159+
160+
};
161+
162+
/* Generic result for a request (VC->HOST) */
163+
struct vc_sm_result_t {
164+
/* Transaction identifier */
165+
uint32_t trans_id;
166+
167+
int32_t success;
168+
169+
};
170+
171+
/* Request to revert a previously applied action (HOST->VC) */
172+
struct vc_sm_action_clean_t {
173+
/* Action of interest */
174+
enum vc_sm_msg_type res_action;
175+
/* Transaction identifier for the action of interest */
176+
uint32_t action_trans_id;
177+
178+
};
179+
180+
/* Request to remove all data associated with a given allocator (HOST->VC) */
181+
struct vc_sm_free_all_t {
182+
/* Allocator identifier */
183+
uint32_t allocator;
184+
};
185+
186+
/* Request to import memory (HOST->VC) */
187+
struct vc_sm_import {
188+
/* type of memory to allocate */
189+
enum vc_sm_alloc_type_t type;
190+
/* pointer to the VC (ie physical) address of the allocated memory */
191+
uint32_t addr;
192+
/* size of buffer */
193+
uint32_t size;
194+
/* opaque handle returned in RELEASED messages */
195+
int32_t kernel_id;
196+
/* Allocator identifier */
197+
uint32_t allocator;
198+
/* resource name (for easier tracking on vc side) */
199+
char name[VC_SM_RESOURCE_NAME];
200+
};
201+
202+
/* Result of a requested memory import (VC->HOST) */
203+
struct vc_sm_import_result {
204+
/* Transaction identifier */
205+
uint32_t trans_id;
206+
207+
/* Resource handle */
208+
uint32_t res_handle;
209+
};
210+
211+
/* Notification that VC has finished with an allocation (VC->HOST) */
212+
struct vc_sm_released {
213+
/* pointer to the VC (ie physical) address of the allocated memory */
214+
uint32_t addr;
215+
/* size of buffer */
216+
uint32_t size;
217+
/* opaque handle returned in RELEASED messages */
218+
int32_t kernel_id;
219+
};
220+
221+
/* Union of ALL messages */
222+
union vc_sm_msg_union_t {
223+
struct vc_sm_alloc_t alloc;
224+
struct vc_sm_alloc_result_t alloc_result;
225+
struct vc_sm_free_t free;
226+
struct vc_sm_lock_unlock_t lock_unlock;
227+
struct vc_sm_action_clean_t action_clean;
228+
struct vc_sm_resize_t resize;
229+
struct vc_sm_lock_result_t lock_result;
230+
struct vc_sm_result_t result;
231+
struct vc_sm_free_all_t free_all;
232+
struct vc_sm_import import;
233+
struct vc_sm_import_result import_result;
234+
struct vc_sm_released released;
235+
};
236+
237+
#endif /* __VC_SM_DEFS_H__INCLUDED__ */
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
****************************************************************************
3+
* Copyright 2011 Broadcom Corporation. All rights reserved.
4+
*
5+
* Unless you and Broadcom execute a separate written software license
6+
* agreement governing use of this software, this software is licensed to you
7+
* under the terms of the GNU General Public License version 2, available at
8+
* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
9+
*
10+
* Notwithstanding the above, under no circumstances may you combine this
11+
* software in any way with any other Broadcom software provided under a
12+
* license other than the GPL, without Broadcom's express prior written
13+
* consent.
14+
****************************************************************************
15+
*/
16+
17+
#ifndef __VC_SM_KNL_H__INCLUDED__
18+
#define __VC_SM_KNL_H__INCLUDED__
19+
20+
#if !defined(__KERNEL__)
21+
#error "This interface is for kernel use only..."
22+
#endif
23+
24+
/* Type of memory to be locked (ie mapped) */
25+
enum vc_sm_lock_cache_mode {
26+
VC_SM_LOCK_CACHED,
27+
VC_SM_LOCK_NON_CACHED,
28+
};
29+
30+
/* Allocate a shared memory handle and block. */
31+
int vc_sm_alloc(struct vc_sm_alloc_t *alloc, int *handle);
32+
33+
/* Free a previously allocated shared memory handle and block. */
34+
int vc_sm_free(int handle);
35+
36+
/* Lock a memory handle for use by kernel. */
37+
int vc_sm_lock(int handle, enum vc_sm_lock_cache_mode mode,
38+
unsigned long *data);
39+
40+
/* Unlock a memory handle in use by kernel. */
41+
int vc_sm_unlock(int handle, int flush, int no_vc_unlock);
42+
43+
/* Get an internal resource handle mapped from the external one. */
44+
int vc_sm_int_handle(int handle);
45+
46+
/* Map a shared memory region for use by kernel. */
47+
int vc_sm_map(int handle, unsigned int sm_addr,
48+
enum vc_sm_lock_cache_mode mode, unsigned long *data);
49+
50+
/* Import a block of memory into the GPU space. */
51+
int vc_sm_import_dmabuf(struct dma_buf *dmabuf, int *handle);
52+
53+
#endif /* __VC_SM_KNL_H__INCLUDED__ */

0 commit comments

Comments
 (0)