VMCS_SM_CMD_CLEAN_INVALID,
VMCS_SM_CMD_CLEAN_INVALID2,
+ VMCS_SM_CMD_IMPORT_DMABUF,
+
VMCS_SM_CMD_LAST /* Do no delete */
};
} s[0];
};
+struct vmcs_sm_ioctl_import_dmabuf {
+ /* user -> kernel */
+ int dmabuf_fd;
+ enum vmcs_sm_cache_e cached;
+ char name[VMCS_SM_RESOURCE_NAME];
+
+ /* kernel -> user */
+ unsigned int handle;
+};
+
/* IOCTL numbers */
#define VMCS_SM_IOCTL_MEM_ALLOC\
_IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC,\
_IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_MAP,\
struct vmcs_sm_ioctl_walk)
+#define VMCS_SM_IOCTL_MEM_IMPORT_DMABUF\
+ _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_IMPORT_DMABUF,\
+ struct vmcs_sm_ioctl_import_dmabuf)
+
/* ---- Variable Externs ------------------------------------------------- */
/* ---- Function Prototypes ---------------------------------------------- */
out:
return rc;
}
+
+/* Imports a dmabuf, and binds it to a VCSM handle and MEM_HANDLE_T
+**
+** Returns: 0 on error
+** a non-zero opaque handle on success.
+**
+** On success, the user must invoke vcsm_lock with the returned opaque
+** handle to gain access to the memory associated with the opaque handle.
+** When finished using the memory, the user calls vcsm_unlock_xx (see those
+** function definition for more details on the one that can be used).
+** Use vcsm_release to detach from the dmabuf (VideoCore may still hold
+** a reference to the buffer until it has finished with the buffer).
+**
+*/
+unsigned int vcsm_import_dmabuf( int dmabuf, char *name )
+{
+ struct vmcs_sm_ioctl_import_dmabuf import;
+ int rc;
+
+ if ( vcsm_handle == VCSM_INVALID_HANDLE )
+ {
+ vcos_log_error( "[%s]: [%d]: invalid device or invalid handle!",
+ __func__,
+ getpid() );
+
+ rc = -1;
+ goto error;
+ }
+
+ memset( &import, 0, sizeof(import) );
+
+ /* Map the buffer on videocore via the VCSM (Videocore Shared Memory) interface. */
+ import.dmabuf_fd = dmabuf;
+ import.cached = VMCS_SM_CACHE_NONE; //Support no caching for now - makes it easier for cache management
+ if ( name != NULL )
+ {
+ memcpy ( import.name, name, 32 );
+ }
+ rc = ioctl( vcsm_handle,
+ VMCS_SM_IOCTL_MEM_IMPORT_DMABUF,
+ &import );
+
+ if ( rc < 0 || import.handle == 0 )
+ {
+ vcos_log_error( "[%s]: [%d] [%s]: ioctl mem-import-dmabuf FAILED [%d] (hdl: %x)",
+ __func__,
+ getpid(),
+ import.name,
+ rc,
+ import.handle );
+ goto error;
+ }
+
+ vcos_log_trace( "[%s]: [%d] [%s]: ioctl mem-import-dmabuf %d (hdl: %x)",
+ __func__,
+ getpid(),
+ import.name,
+ rc,
+ import.handle );
+
+ return import.handle;
+
+error:
+ if ( import.handle )
+ {
+ vcsm_free( import.handle );
+ }
+ return 0;
+}
int vcsm_clean_invalid2( struct vcsm_user_clean_invalid2_s *s );
+unsigned int vcsm_import_dmabuf( int dmabuf, char *name );
+
#ifdef __cplusplus
}
#endif
#ifdef MEM_WRAP_HACK
extern MEM_HANDLE_T mem_wrap(void *p, uint32_t size, uint32_t align, MEM_FLAG_T flags, const char *desc);
+
+typedef void (*MEM_WRAP_TERM_T)(void */*priv*/, MEM_HANDLE_T /*term_handle*/, void */*p*/, int /*size*/);
+
+/*
+ int mem_wrap_set_on_term(MEM_HANDLE_T handle, MEM_WRAP_TERM_T term_cb, void *cb_priv);
+
+ Adds an additional release callback for wrapped MEM_HANDLE_T.
+ This allows the underlying allocator to release the wrapped memory.
+ The MEM_HANDLE_T must NOT be accessed with mem_lock/mem_acquire etc
+ from the callback context as the handle is already partially released.
+*/
+extern int mem_wrap_set_on_term(MEM_HANDLE_T handle, MEM_WRAP_TERM_T term_cb, void *cb_priv);
+
#endif
/*