#define VC_SM_DEBUG "debug"
#define VC_SM_WRITE_BUF_SIZE 128
-/* Statistics tracked per resource and globally.
-*/
+/* Statistics tracked per resource and globally. */
enum SM_STATS_T {
/* Attempt. */
ALLOC,
};
-/* Single resource allocation tracked for all devices.
-*/
+/* Single resource allocation tracked for all devices. */
struct sm_mmap {
struct list_head map_list; /* Linked list of maps. */
struct SM_RESOURCE_T *resource; /* Pointer to the resource. */
- pid_t res_pid; /* PID owning that resource. */
+ pid_t res_pid; /* PID owning that resource. */
unsigned int res_vc_hdl; /* Resource handle (videocore). */
unsigned int res_usr_hdl; /* Resource handle (user). */
long unsigned int res_addr; /* Mapped virtual address. */
struct vm_area_struct *vma; /* VM area for this mapping. */
- unsigned int ref_count; /* Reference count to this vma. */
+ unsigned int ref_count; /* Reference count to this vma. */
/* Used to link maps associated with a resource. */
struct list_head resource_map_list;
};
-/* Single resource allocation tracked for each opened device.
-*/
+/* Single resource allocation tracked for each opened device. */
struct SM_RESOURCE_T {
struct list_head resource_list; /* List of resources. */
struct list_head global_resource_list; /* Global list of resources. */
bool map; /* whether to map pages up front */
};
-/* Private file data associated with each opened device.
-*/
+/* Private file data associated with each opened device. */
struct SM_PRIV_DATA_T {
struct list_head resource_list; /* List of resources. */
};
-/* Global state information.
-*/
+/* Global state information. */
struct SM_STATE_T {
struct platform_device *pdev;
struct sm_instance *sm_handle; /* Handle for videocore service. */
return pfn;
}
-/* Carries over to the state statistics the statistics once owned by a deceased
-** resource.
-*/
+/*
+ * Carries over to the state statistics the statistics once owned by a deceased
+ * resource.
+ */
static void vc_sm_resource_deceased(struct SM_RESOURCE_T *p_res, int terminated)
{
if (sm_state != NULL) {
}
}
-/* Fetch a videocore handle corresponding to a mapping of the pid+address
-** returns 0 (ie NULL) if no such handle exists in the global map.
-*/
+/*
+ * Fetch a videocore handle corresponding to a mapping of the pid+address
+ * returns 0 (ie NULL) if no such handle exists in the global map.
+ */
static unsigned int vmcs_sm_vc_handle_from_pid_and_address(unsigned int pid,
unsigned int addr)
{
mutex_lock(&(sm_state->map_lock));
- /* Lookup the resource.
- */
+ /* Lookup the resource. */
if (!list_empty(&sm_state->map_list)) {
list_for_each_entry(map, &sm_state->map_list, map_list) {
if (map->res_pid != pid || map->res_addr != addr)
mutex_unlock(&(sm_state->map_lock));
out:
- /* Use a debug log here as it may be a valid situation that we query
- ** for something that is not mapped, we do not want a kernel log each
- ** time around.
- **
- ** There are other error log that would pop up accordingly if someone
- ** subsequently tries to use something invalid after being told not to
- ** use it...
+ /*
+ * Use a debug log here as it may be a valid situation that we query
+ * for something that is not mapped, we do not want a kernel log each
+ * time around.
+ *
+ * There are other error log that would pop up accordingly if someone
+ * subsequently tries to use something invalid after being told not to
+ * use it...
*/
if (handle == 0) {
pr_debug("[%s]: not a valid map (pid %u, addr %x)\n",
return handle;
}
-/* Fetch a user handle corresponding to a mapping of the pid+address
-** returns 0 (ie NULL) if no such handle exists in the global map.
-*/
+/*
+ * Fetch a user handle corresponding to a mapping of the pid+address
+ * returns 0 (ie NULL) if no such handle exists in the global map.
+ */
static unsigned int vmcs_sm_usr_handle_from_pid_and_address(unsigned int pid,
unsigned int addr)
{
mutex_lock(&(sm_state->map_lock));
- /* Lookup the resource.
- */
+ /* Lookup the resource. */
if (!list_empty(&sm_state->map_list)) {
list_for_each_entry(map, &sm_state->map_list, map_list) {
if (map->res_pid != pid || map->res_addr != addr)
mutex_unlock(&(sm_state->map_lock));
out:
- /* Use a debug log here as it may be a valid situation that we query
+ /*
+ * Use a debug log here as it may be a valid situation that we query
* for something that is not mapped yet.
*
* There are other error log that would pop up accordingly if someone
}
#if defined(DO_NOT_USE)
-/* Fetch an address corresponding to a mapping of the pid+handle
-** returns 0 (ie NULL) if no such address exists in the global map.
-*/
+/*
+ * Fetch an address corresponding to a mapping of the pid+handle
+ * returns 0 (ie NULL) if no such address exists in the global map.
+ */
static unsigned int vmcs_sm_usr_address_from_pid_and_vc_handle(unsigned int pid,
unsigned int hdl)
{
mutex_lock(&(sm_state->map_lock));
- /* Lookup the resource.
- */
+ /* Lookup the resource. */
if (!list_empty(&sm_state->map_list)) {
list_for_each_entry(map, &sm_state->map_list, map_list) {
if (map->res_pid != pid || map->res_vc_hdl != hdl)
mutex_unlock(&(sm_state->map_lock));
out:
- /* Use a debug log here as it may be a valid situation that we query
- ** for something that is not mapped, we do not want a kernel log each
- ** time around.
- **
- ** There are other error log that would pop up accordingly if someone
- ** subsequently tries to use something invalid after being told not to
- ** use it...
+ /*
+ * Use a debug log here as it may be a valid situation that we query
+ * for something that is not mapped, we do not want a kernel log each
+ * time around.
+ *
+ * There are other error log that would pop up accordingly if someone
+ * subsequently tries to use something invalid after being told not to
+ * use it...
*/
if (addr == 0)
pr_debug("[%s]: not a valid map (pid %u, hdl %x)\n",
}
#endif
-/* Fetch an address corresponding to a mapping of the pid+handle
-** returns 0 (ie NULL) if no such address exists in the global map.
-*/
+/*
+ * Fetch an address corresponding to a mapping of the pid+handle
+ * returns 0 (ie NULL) if no such address exists in the global map.
+ */
static unsigned int vmcs_sm_usr_address_from_pid_and_usr_handle(unsigned int
pid,
unsigned int
mutex_lock(&(sm_state->map_lock));
- /* Lookup the resource.
- */
+ /* Lookup the resource. */
if (!list_empty(&sm_state->map_list)) {
list_for_each_entry(map, &sm_state->map_list, map_list) {
if (map->res_pid != pid || map->res_usr_hdl != hdl)
mutex_unlock(&(sm_state->map_lock));
out:
- /* Use a debug log here as it may be a valid situation that we query
+ /*
+ * Use a debug log here as it may be a valid situation that we query
* for something that is not mapped, we do not want a kernel log each
* time around.
*
return addr;
}
-/* Adds a resource mapping to the global data list.
-*/
+/* Adds a resource mapping to the global data list. */
static void vmcs_sm_add_map(struct SM_STATE_T *state,
struct SM_RESOURCE_T *resource, struct sm_mmap *map)
{
mutex_lock(&(state->map_lock));
- /* Add to the global list of mappings
- */
+ /* Add to the global list of mappings */
list_add(&map->map_list, &state->map_list);
- /* Add to the list of mappings for this resource
- */
+ /* Add to the list of mappings for this resource */
list_add(&map->resource_map_list, &resource->map_list);
resource->map_count++;
map->res_usr_hdl, map->res_addr);
}
-/* Removes a resource mapping from the global data list.
-*/
+/* Removes a resource mapping from the global data list. */
static void vmcs_sm_remove_map(struct SM_STATE_T *state,
struct SM_RESOURCE_T *resource,
struct sm_mmap *map)
{
mutex_lock(&(state->map_lock));
- /* Remove from the global list of mappings
- */
+ /* Remove from the global list of mappings */
list_del(&map->map_list);
- /* Remove from the list of mapping for this resource
- */
+ /* Remove from the list of mapping for this resource */
list_del(&map->resource_map_list);
if (resource->map_count > 0)
resource->map_count--;
kfree(map);
}
-/* Read callback for the global state proc entry.
-*/
+/* Read callback for the global state proc entry. */
static int vc_sm_global_state_show(struct seq_file *s, void *v)
{
struct sm_mmap *map = NULL;
seq_printf(s, "\nVC-ServiceHandle 0x%x\n",
(unsigned int)sm_state->sm_handle);
- /* Log all applicable mapping(s).
- */
+ /* Log all applicable mapping(s). */
mutex_lock(&(sm_state->map_lock));
seq_puts(s, "\nResources\n");
{
int ix;
- /* Global state tracked statistics.
- */
+ /* Global state tracked statistics. */
if (sm_state != NULL) {
seq_puts(s, "\nDeceased Resources Statistics\n");
}
#if 0
-/* Read callback for the statistics proc entry.
-*/
+/* Read callback for the statistics proc entry. */
static int vc_sm_statistics_show(struct seq_file *s, void *v)
{
int ix;
if (file_data == NULL)
return 0;
- /* Per process statistics.
- */
+ /* Per process statistics. */
seq_printf(s, "\nStatistics for TGID %d\n", file_data->pid);
.release = single_release,
};
-/* Adds a resource to the private data list which tracks all the allocated
-** data.
-*/
+/*
+ * Adds a resource to the private data list which tracks all the allocated
+ * data.
+ */
static void vmcs_sm_add_resource(struct SM_PRIV_DATA_T *privdata,
struct SM_RESOURCE_T *resource)
{
resource->res_handle, resource->res_size, resource->res_cached);
}
-/* Locates a resource and acquire a reference on it.
-** The resource won't be deleted while there is a reference on it.
-*/
+/*
+ * Locates a resource and acquire a reference on it.
+ * The resource won't be deleted while there is a reference on it.
+ */
static struct SM_RESOURCE_T *vmcs_sm_acquire_resource(struct SM_PRIV_DATA_T
*private,
unsigned int res_guid)
return ret;
}
-/* Locates a resource and acquire a reference on it.
-** The resource won't be deleted while there is a reference on it.
-*/
+/*
+ * Locates a resource and acquire a reference on it.
+ * The resource won't be deleted while there is a reference on it.
+ */
static struct SM_RESOURCE_T *vmcs_sm_acquire_first_resource(
struct SM_PRIV_DATA_T *private)
{
return ret;
}
-/* Locates a resource and acquire a reference on it.
-** The resource won't be deleted while there is a reference on it.
-*/
+/*
+ * Locates a resource and acquire a reference on it.
+ * The resource won't be deleted while there is a reference on it.
+ */
static struct SM_RESOURCE_T *vmcs_sm_acquire_global_resource(unsigned int
res_guid)
{
return ret;
}
-/* Release a previously acquired resource.
-** The resource will be deleted when its refcount reaches 0.
-*/
+/*
+ * Release a previously acquired resource.
+ * The resource will be deleted when its refcount reaches 0.
+ */
static void vmcs_sm_release_resource(struct SM_RESOURCE_T *resource, int force)
{
struct SM_PRIV_DATA_T *private = resource->private;
kfree(resource);
}
-/* Dump the map table for the driver. If process is -1, dumps the whole table,
-** if process is a valid pid (non -1) dump only the entries associated with the
-** pid of interest.
-*/
+/*
+ * Dump the map table for the driver. If process is -1, dumps the whole table,
+ * if process is a valid pid (non -1) dump only the entries associated with the
+ * pid of interest.
+ */
static void vmcs_sm_host_walk_map_per_pid(int pid)
{
struct sm_mmap *map = NULL;
- /* Make sure the device was started properly.
- */
+ /* Make sure the device was started properly. */
if (sm_state == NULL) {
pr_err("[%s]: invalid device\n", __func__);
return;
mutex_lock(&(sm_state->map_lock));
- /* Log all applicable mapping(s).
- */
+ /* Log all applicable mapping(s). */
if (!list_empty(&sm_state->map_list)) {
list_for_each_entry(map, &sm_state->map_list, map_list) {
if (pid == -1 || map->res_pid == pid) {
return;
}
-/* Dump the allocation table from host side point of view. This only dumps the
-** data allocated for this process/device referenced by the file_data.
-*/
+/*
+ * Dump the allocation table from host side point of view. This only dumps the
+ * data allocated for this process/device referenced by the file_data.
+ */
static void vmcs_sm_host_walk_alloc(struct SM_PRIV_DATA_T *file_data)
{
struct SM_RESOURCE_T *resource = NULL;
- /* Make sure the device was started properly.
- */
+ /* Make sure the device was started properly. */
if ((sm_state == NULL) || (file_data == NULL)) {
pr_err("[%s]: invalid device\n", __func__);
return;
return;
}
-/* Create support for private data tracking.
-*/
+/* Create support for private data tracking. */
static struct SM_PRIV_DATA_T *vc_sm_create_priv_data(pid_t id)
{
char alloc_name[32];
return file_data;
}
-/* Open the device. Creates a private state to help track all allocation
-** associated with this device.
-*/
+/*
+ * Open the device. Creates a private state to help track all allocation
+ * associated with this device.
+ */
static int vc_sm_open(struct inode *inode, struct file *file)
{
int ret = 0;
- /* Make sure the device was started properly.
- */
+ /* Make sure the device was started properly. */
if (!sm_state) {
pr_err("[%s]: invalid device\n", __func__);
ret = -EPERM;
return ret;
}
-/* Close the device. Free up all resources still associated with this device
-** at the time.
-*/
+/*
+ * Close the device. Free up all resources still associated with this device
+ * at the time.
+ */
static int vc_sm_release(struct inode *inode, struct file *file)
{
struct SM_PRIV_DATA_T *file_data =
struct SM_RESOURCE_T *resource;
int ret = 0;
- /* Make sure the device was started properly.
- */
+ /* Make sure the device was started properly. */
if (sm_state == NULL || file_data == NULL) {
pr_err("[%s]: invalid device\n", __func__);
ret = -EPERM;
/* Remove the corresponding proc entry. */
debugfs_remove_recursive(file_data->dir_pid);
- /* Terminate the private data.
- */
+ /* Terminate the private data. */
kfree(file_data);
out:
map->ref_count--;
- /* Remove from the map table.
- */
+ /* Remove from the map table. */
if (map->ref_count == 0)
vmcs_sm_remove_map(sm_state, map->resource, map);
}
unsigned long pfn;
int ret = 0;
- /* Lock the resource if necessary.
- */
+ /* Lock the resource if necessary. */
if (!resource->lock_count) {
struct vc_sm_lock_unlock_t lock_unlock;
struct vc_sm_lock_result_t lock_result;
__func__, lock_unlock.res_handle,
(void *)lock_unlock.res_mem);
- /* Lock the videocore allocated resource.
- */
+ /* Lock the videocore allocated resource. */
status = vc_vchi_sm_lock(sm_state->sm_handle,
&lock_unlock, &lock_result, 0);
if (status || !lock_result.res_mem) {
resource->res_stats[LOCK]++;
resource->lock_count++;
- /* Keep track of the new base memory.
- */
+ /* Keep track of the new base memory. */
if (lock_result.res_mem &&
lock_result.res_old_mem &&
(lock_result.res_mem != lock_result.res_old_mem)) {
case 0:
case -ERESTARTSYS:
/*
- * EBUSY is ok: this just means that another thread
- * already did the job.
- */
+ * EBUSY is ok: this just means that another thread
+ * already did the job.
+ */
case -EBUSY:
return VM_FAULT_NOPAGE;
case -ENOMEM:
} while (pgd++, addr = pgd_next, addr != end);
}
-/* Map an allocated data into something that the user space.
-*/
+/* Map an allocated data into something that the user space. */
static int vc_sm_mmap(struct file *file, struct vm_area_struct *vma)
{
int ret = 0;
struct SM_RESOURCE_T *resource = NULL;
struct sm_mmap *map = NULL;
- /* Make sure the device was started properly.
- */
+ /* Make sure the device was started properly. */
if ((sm_state == NULL) || (file_data == NULL)) {
pr_err("[%s]: invalid device\n", __func__);
return -EPERM;
pr_debug("[%s]: private data %p, guid %x\n", __func__, file_data,
((unsigned int)vma->vm_pgoff << PAGE_SHIFT));
- /* We lookup to make sure that the data we are being asked to mmap is
- ** something that we allocated.
- **
- ** We use the offset information as the key to tell us which resource
- ** we are mapping.
+ /*
+ * We lookup to make sure that the data we are being asked to mmap is
+ * something that we allocated.
+ *
+ * We use the offset information as the key to tell us which resource
+ * we are mapping.
*/
resource = vmcs_sm_acquire_resource(file_data,
((unsigned int)vma->vm_pgoff <<
__func__, resource->res_guid, current->tgid, resource->pid,
file_data->pid);
- /* Check permissions.
- */
+ /* Check permissions. */
if (resource->pid && (resource->pid != current->tgid)) {
pr_err("[%s]: current tgid %u != %u owner\n",
__func__, current->tgid, resource->pid);
goto error;
}
- /* Verify that what we are asked to mmap is proper.
- */
+ /* Verify that what we are asked to mmap is proper. */
if (resource->res_size != (unsigned int)(vma->vm_end - vma->vm_start)) {
pr_err("[%s]: size inconsistency (resource: %u - mmap: %u)\n",
__func__,
goto error;
}
- /* Keep track of the tuple in the global resource list such that one
+ /*
+ * Keep track of the tuple in the global resource list such that one
* can do a mapping lookup for address/memory handle.
*/
map = kzalloc(sizeof(*map), GFP_KERNEL);
map->vma = vma;
vmcs_sm_add_map(sm_state, resource, map);
- /* We are not actually mapping the pages, we just provide a fault
- ** handler to allow pages to be mapped when accessed
+ /*
+ * We are not actually mapping the pages, we just provide a fault
+ * handler to allow pages to be mapped when accessed
*/
vma->vm_flags |=
VM_IO | VM_PFNMAP | VM_DONTCOPY | VM_DONTEXPAND;
if ((resource->res_cached == VMCS_SM_CACHE_NONE) ||
(resource->res_cached == VMCS_SM_CACHE_VC)) {
- /* Allocated non host cached memory, honour it.
- */
+ /* Allocated non host cached memory, honour it. */
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
}
return ret;
}
-/* Allocate a shared memory handle and block.
-*/
+/* Allocate a shared memory handle and block. */
int vc_sm_ioctl_alloc(struct SM_PRIV_DATA_T *private,
struct vmcs_sm_ioctl_alloc *ioparam)
{
__func__, alloc.name, alloc.type, ioparam->size,
alloc.base_unit, alloc.num_unit, alloc.alignement);
- /* Allocate local resource to track this allocation.
- */
+ /* Allocate local resource to track this allocation. */
resource = kzalloc(sizeof(*resource), GFP_KERNEL);
if (!resource) {
ret = -ENOMEM;
resource->ref_count++;
resource->pid = current->tgid;
- /* Allocate the videocore resource.
- */
+ /* Allocate the videocore resource. */
status = vc_vchi_sm_alloc(sm_state->sm_handle, &alloc, &result,
&private->int_trans_id);
if (status == -EINTR) {
goto error;
}
- /* Keep track of the resource we created.
- */
+ /* Keep track of the resource we created. */
resource->private = private;
resource->res_handle = result.res_handle;
resource->res_base_mem = (void *)result.res_mem;
resource->res_cached = cached;
resource->map = map;
- /* Kernel/user GUID. This global identifier is used for mmap'ing the
+ /*
+ * Kernel/user GUID. This global identifier is used for mmap'ing the
* allocated region from user space, it is passed as the mmap'ing
* offset, we use it to 'hide' the videocore handle/address.
*/
return ret;
}
-/* Share an allocate memory handle and block.
-*/
+/* Share an allocate memory handle and block.*/
int vc_sm_ioctl_alloc_share(struct SM_PRIV_DATA_T *private,
struct vmcs_sm_ioctl_alloc_share *ioparam)
{
goto error;
}
- /* Allocate local resource to track this allocation.
- */
+ /* Allocate local resource to track this allocation. */
resource = kzalloc(sizeof(*resource), GFP_KERNEL);
if (resource == NULL) {
pr_err("[%s]: failed to allocate local tracking resource\n",
resource->ref_count++;
resource->pid = current->tgid;
- /* Keep track of the resource we created.
- */
+ /* Keep track of the resource we created. */
resource->private = private;
resource->res_handle = shared_resource->res_handle;
resource->res_base_mem = shared_resource->res_base_mem;
return ret;
}
-/* Free a previously allocated shared memory handle and block.
-*/
+/* Free a previously allocated shared memory handle and block.*/
static int vc_sm_ioctl_free(struct SM_PRIV_DATA_T *private,
struct vmcs_sm_ioctl_free *ioparam)
{
return -EINVAL;
}
- /* Check permissions.
- */
+ /* Check permissions. */
if (resource->pid && (resource->pid != current->tgid)) {
pr_err("[%s]: current tgid %u != %u owner\n",
__func__, current->tgid, resource->pid);
return 0;
}
-/* Resize a previously allocated shared memory handle and block.
-*/
+/* Resize a previously allocated shared memory handle and block. */
static int vc_sm_ioctl_resize(struct SM_PRIV_DATA_T *private,
struct vmcs_sm_ioctl_resize *ioparam)
{
struct vc_sm_resize_t resize;
struct SM_RESOURCE_T *resource;
- /* Locate resource from GUID.
- */
+ /* Locate resource from GUID. */
resource = vmcs_sm_acquire_resource(private, ioparam->handle);
if (!resource) {
pr_err("[%s]: failed resource - guid %x\n",
goto error;
}
- /* If the resource is locked, its reference count will be not NULL,
- ** in which case we will not be allowed to resize it anyways, so
- ** reject the attempt here.
+ /*
+ * If the resource is locked, its reference count will be not NULL,
+ * in which case we will not be allowed to resize it anyways, so
+ * reject the attempt here.
*/
if (resource->lock_count != 0) {
pr_err("[%s]: cannot resize - guid %x, ref-cnt %d\n",
goto error;
}
- /* Check permissions.
- */
+ /* Check permissions. */
if (resource->pid && (resource->pid != current->tgid)) {
pr_err("[%s]: current tgid %u != %u owner\n", __func__,
current->tgid, resource->pid);
__func__, ioparam->handle, resize.res_handle,
(void *)resize.res_mem);
- /* Resize the videocore allocated resource.
- */
+ /* Resize the videocore allocated resource. */
status = vc_vchi_sm_resize(sm_state->sm_handle, &resize,
&private->int_trans_id);
if (status == -EINTR) {
__func__, resize.res_handle, resource->res_size,
resize.res_new_size);
- /* Successfully resized, save the information and inform the user.
- */
+ /* Successfully resized, save the information and inform the user. */
ioparam->old_size = resource->res_size;
resource->res_size = resize.res_new_size;
return ret;
}
-/* Lock a previously allocated shared memory handle and block.
-*/
+/* Lock a previously allocated shared memory handle and block. */
static int vc_sm_ioctl_lock(struct SM_PRIV_DATA_T *private,
struct vmcs_sm_ioctl_lock_unlock *ioparam,
int change_cache, enum vmcs_sm_cache_e cache_type,
map = NULL;
- /* Locate resource from GUID.
- */
+ /* Locate resource from GUID. */
resource = vmcs_sm_acquire_resource(private, ioparam->handle);
if (resource == NULL) {
ret = -EINVAL;
goto error;
}
- /* Check permissions.
- */
+ /* Check permissions. */
if (resource->pid && (resource->pid != current->tgid)) {
pr_err("[%s]: current tgid %u != %u owner\n", __func__,
current->tgid, resource->pid);
lock.res_handle = resource->res_handle;
lock.res_mem = (uint32_t)resource->res_base_mem;
- /* Take the lock and get the address to be mapped.
- */
+ /* Take the lock and get the address to be mapped. */
if (vc_addr == 0) {
pr_debug("[%s]: attempt to lock data - guid %x, hdl %x, base address %p\n",
__func__, ioparam->handle, lock.res_handle,
(void *)lock.res_mem);
- /* Lock the videocore allocated resource.
- */
+ /* Lock the videocore allocated resource. */
status = vc_vchi_sm_lock(sm_state->sm_handle, &lock, &result,
&private->int_trans_id);
if (status == -EINTR) {
__func__, lock.res_handle, (void *)result.res_mem,
(void *)lock.res_mem, resource->lock_count);
}
- /* Lock assumed taken already, address to be mapped is known.
- */
+ /* Lock assumed taken already, address to be mapped is known. */
else
resource->res_base_mem = (void *)vc_addr;
resource->res_stats[LOCK]++;
resource->lock_count++;
- /* Keep track of the new base memory allocation if it has changed.
- */
+ /* Keep track of the new base memory allocation if it has changed. */
if ((vc_addr == 0) &&
((void *)result.res_mem) &&
((void *)result.res_old_mem) &&
(result.res_mem != result.res_old_mem)) {
resource->res_base_mem = (void *)result.res_mem;
- /* Kernel allocated resources.
- */
+ /* Kernel allocated resources. */
if (resource->pid == 0) {
if (!list_empty(&resource->map_list)) {
list_for_each_entry_safe(map, map_tmp,
__func__, resource->map_count, private->pid,
current->tgid, ioparam->handle, ioparam->addr);
} else {
- /* Kernel allocated resources.
- */
+ /* Kernel allocated resources. */
if (resource->pid == 0) {
pr_debug("[%s]: attempt mapping kernel resource - guid %x, hdl %x\n",
__func__, ioparam->handle, lock.res_handle);
return ret;
}
-/* Unlock a previously allocated shared memory handle and block.
-*/
+/* Unlock a previously allocated shared memory handle and block.*/
static int vc_sm_ioctl_unlock(struct SM_PRIV_DATA_T *private,
struct vmcs_sm_ioctl_lock_unlock *ioparam,
int flush, int wait_reply, int no_vc_unlock)
map = NULL;
- /* Locate resource from GUID.
- */
+ /* Locate resource from GUID. */
resource = vmcs_sm_acquire_resource(private, ioparam->handle);
if (resource == NULL) {
ret = -EINVAL;
goto error;
}
- /* Check permissions.
- */
+ /* Check permissions. */
if (resource->pid && (resource->pid != current->tgid)) {
pr_err("[%s]: current tgid %u != %u owner\n",
__func__, current->tgid, resource->pid);
__func__, ioparam->handle, unlock.res_handle,
(void *)unlock.res_mem);
- /* User space allocated resources.
- */
+ /* User space allocated resources. */
if (resource->pid) {
/* Flush if requested */
if (resource->res_cached && flush) {
}
if (resource->lock_count) {
- /* Bypass the videocore unlock.
- */
+ /* Bypass the videocore unlock. */
if (no_vc_unlock)
status = 0;
- /* Unlock the videocore allocated resource.
- */
+ /* Unlock the videocore allocated resource. */
else {
status =
vc_vchi_sm_unlock(sm_state->sm_handle, &unlock,
return ret;
}
-/*
- * Import a contiguous block of memory to be shared with VC.
- */
+/* Import a contiguous block of memory to be shared with VC. */
int vc_sm_ioctl_import_dmabuf(struct SM_PRIV_DATA_T *private,
struct vmcs_sm_ioctl_import_dmabuf *ioparam,
struct dma_buf *src_dma_buf)
goto error;
}
- /* Keep track of the resource we created.
- */
+ /* Keep track of the resource we created. */
resource->private = private;
resource->res_handle = result.res_handle;
resource->res_size = import.size;
resource->sgt = sgt;
resource->dma_addr = sg_dma_address(sgt->sgl);
- /* Kernel/user GUID. This global identifier is used for mmap'ing the
+ /*
+ * Kernel/user GUID. This global identifier is used for mmap'ing the
* allocated region from user space, it is passed as the mmap'ing
* offset, we use it to 'hide' the videocore handle/address.
*/
file_data->restart_sys = 0;
}
- /* Now process the command.
- */
+ /* Now process the command. */
switch (cmdnr) {
/* New memory allocation.
*/
{
struct vmcs_sm_ioctl_alloc ioparam;
- /* Get the parameter data.
- */
+ /* Get the parameter data. */
if (copy_from_user
(&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
ret = -EFAULT;
}
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
- /* Share existing memory allocation.
- */
+ /* Share existing memory allocation. */
case VMCS_SM_CMD_ALLOC_SHARE:
{
struct vmcs_sm_ioctl_alloc_share ioparam;
- /* Get the parameter data.
- */
+ /* Get the parameter data. */
if (copy_from_user
(&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
ret = vc_sm_ioctl_alloc_share(file_data, &ioparam);
- /* Copy result back to user.
- */
+ /* Copy result back to user. */
if (!ret
&& copy_to_user((void *)arg, &ioparam,
sizeof(ioparam)) != 0) {
ret = -EFAULT;
}
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
{
struct vmcs_sm_ioctl_import_dmabuf ioparam;
- /* Get the parameter data.
- */
+ /* Get the parameter data. */
if (copy_from_user
(&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
ret = -EFAULT;
}
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
- /* Lock (attempt to) *and* register a cache behavior change.
- */
+ /* Lock (attempt to) *and* register a cache behavior change. */
case VMCS_SM_CMD_LOCK_CACHE:
{
struct vmcs_sm_ioctl_lock_cache ioparam;
struct vmcs_sm_ioctl_lock_unlock lock;
- /* Get parameter data.
- */
+ /* Get parameter data. */
if (copy_from_user
(&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
vc_sm_ioctl_lock(file_data, &lock, 1,
ioparam.cached, 0);
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
- /* Lock (attempt to) existing memory allocation.
- */
+ /* Lock (attempt to) existing memory allocation. */
case VMCS_SM_CMD_LOCK:
{
struct vmcs_sm_ioctl_lock_unlock ioparam;
- /* Get parameter data.
- */
+ /* Get parameter data. */
if (copy_from_user
(&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
ret = vc_sm_ioctl_lock(file_data, &ioparam, 0, 0, 0);
- /* Copy result back to user.
- */
+ /* Copy result back to user. */
if (copy_to_user((void *)arg, &ioparam, sizeof(ioparam))
!= 0) {
pr_err("[%s]: failed to copy-to-user for cmd %x\n",
ret = -EFAULT;
}
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
- /* Unlock (attempt to) existing memory allocation.
- */
+ /* Unlock (attempt to) existing memory allocation. */
case VMCS_SM_CMD_UNLOCK:
{
struct vmcs_sm_ioctl_lock_unlock ioparam;
- /* Get parameter data.
- */
+ /* Get parameter data. */
if (copy_from_user
(&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
ret = vc_sm_ioctl_unlock(file_data, &ioparam, 0, 1, 0);
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
- /* Resize (attempt to) existing memory allocation.
- */
+ /* Resize (attempt to) existing memory allocation. */
case VMCS_SM_CMD_RESIZE:
{
struct vmcs_sm_ioctl_resize ioparam;
- /* Get parameter data.
- */
+ /* Get parameter data. */
if (copy_from_user
(&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
ret = vc_sm_ioctl_resize(file_data, &ioparam);
- /* Copy result back to user.
- */
+ /* Copy result back to user. */
if (copy_to_user((void *)arg, &ioparam, sizeof(ioparam))
!= 0) {
pr_err("[%s]: failed to copy-to-user for cmd %x\n",
__func__, cmdnr);
ret = -EFAULT;
}
-
- /* Done.
- */
goto out;
}
break;
goto out;
}
break;
-/* Walk mapping table on host, information shows up in the
+ /* Walk mapping table on host, information shows up in the
** kernel log.
*/
case VMCS_SM_CMD_HOST_WALK_MAP:
{
struct vmcs_sm_ioctl_walk ioparam;
- /* Get parameter data. */
+ /* Get parameter data. */
if (copy_from_user(&ioparam,
(void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
{
struct vmcs_sm_ioctl_chk ioparam;
- /* Get parameter data.
- */
+ /* Get parameter data. */
if (copy_from_user(&ioparam,
(void *)arg, sizeof(ioparam)) != 0) {
pr_err("[%s]: failed to copy-from-user for cmd %x\n",
vmcs_sm_acquire_resource(file_data, ioparam.handle);
if (resource == NULL)
ret = -EINVAL;
- /* If the resource is cacheable, return additional
+ /*
+ * If the resource is cacheable, return additional
* information that may be needed to flush the cache.
*/
else if ((resource->res_cached == VMCS_SM_CACHE_HOST) ||
ret = -EFAULT;
}
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
ret = -EFAULT;
}
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
}
break;
- /* Maps a user address given process and vc handle.
- */
+ /* Maps a user address given process and vc handle. */
case VMCS_SM_CMD_MAPPED_USR_ADDRESS:
{
struct vmcs_sm_ioctl_map ioparam;
goto out;
}
- /* Locate resource from GUID.
- */
+ /* Locate resource from GUID. */
resource =
vmcs_sm_acquire_resource(file_data, ioparam.handle);
if (resource)
vmcs_sm_release_resource(resource, 0);
- /* Done.
- */
+ /* Done. */
goto out;
}
break;
case 2: /* L1/L2 clean physical range */
case 3: /* L1/L2 clean+invalidate all */
{
- /* Locate resource from GUID.
- */
+ /* Locate resource from GUID. */
resource =
vmcs_sm_acquire_resource(file_data, ioparam.s[i].handle);
return ret;
}
-/* Device operations that we managed in this driver.
-*/
+/* Device operations that we managed in this driver. */
static const struct file_operations vmcs_sm_ops = {
.owner = THIS_MODULE,
.unlocked_ioctl = vc_sm_ioctl,
.mmap = vc_sm_mmap,
};
-/* Creation of device.
-*/
+/* Creation of device. */
static int vc_sm_create_sharedmemory(void)
{
int ret;
goto out;
}
- /* Create a device class for creating dev nodes.
- */
+ /* Create a device class for creating dev nodes. */
sm_state->sm_class = class_create(THIS_MODULE, "vc-sm");
if (IS_ERR(sm_state->sm_class)) {
pr_err("[%s]: unable to create device class\n", __func__);
goto out;
}
- /* Create a character driver.
- */
+ /* Create a character driver. */
ret = alloc_chrdev_region(&sm_state->sm_devid,
DEVICE_MINOR, 1, DEVICE_NAME);
if (ret != 0) {
goto out_chrdev_unreg;
}
- /* Create a device node.
- */
+ /* Create a device node. */
sm_state->sm_dev = device_create(sm_state->sm_class,
NULL,
MKDEV(MAJOR(sm_state->sm_devid),
return ret;
}
-/* Termination of the device.
-*/
+/* Termination of the device. */
static int vc_sm_remove_sharedmemory(void)
{
int ret;
if (sm_state == NULL) {
- /* Nothing to do.
- */
+ /* Nothing to do. */
ret = 0;
goto out;
}
- /* Remove the sharedmemory character driver.
- */
+ /* Remove the sharedmemory character driver. */
cdev_del(&sm_state->sm_cdev);
- /* Unregister region.
- */
+ /* Unregister region. */
unregister_chrdev_region(sm_state->sm_devid, 1);
ret = 0;
pr_info("[%s]: start\n", __func__);
- /* Initialize and create a VCHI connection for the shared memory service
- ** running on videocore.
+ /*
+ * Initialize and create a VCHI connection for the shared memory service
+ * running on videocore.
*/
ret = vchi_initialise(&vchi_instance);
if (ret != 0) {
goto err_remove_shared_memory;
}
- /* Done!
- */
+ /* Done! */
sm_inited = 1;
goto out;
{
pr_debug("[%s]: start\n", __func__);
if (sm_inited) {
- /* Remove shared memory device.
- */
+ /* Remove shared memory device. */
vc_sm_remove_sharedmemory();
- /* Remove all proc entries.
- */
+ /* Remove all proc entries. */
debugfs_remove_recursive(sm_state->dir_root);
- /* Stop the videocore shared memory service.
- */
+ /* Stop the videocore shared memory service. */
vc_vchi_sm_stop(&sm_state->sm_handle);
- /* Free the memory for the state structure.
- */
+ /* Free the memory for the state structure. */
mutex_destroy(&(sm_state->map_lock));
kfree(sm_state);
}
int ret;
struct SM_RESOURCE_T *resource;
- /* Validate we can work with this device.
- */
+ /* Validate we can work with this device. */
if (sm_state == NULL || alloc == NULL || handle == NULL) {
pr_err("[%s]: invalid input\n", __func__);
return -EPERM;
resource->pid = 0;
vmcs_sm_release_resource(resource, 0);
- /* Assign valid handle at this time.
- */
+ /* Assign valid handle at this time. */
*handle = ioparam.handle;
} else {
ret = -ENOMEM;
}
EXPORT_SYMBOL_GPL(vc_sm_alloc);
-/* Get an internal resource handle mapped from the external one.
-*/
+/* Get an internal resource handle mapped from the external one. */
int vc_sm_int_handle(int handle)
{
struct SM_RESOURCE_T *resource;
int ret = 0;
- /* Validate we can work with this device.
- */
+ /* Validate we can work with this device. */
if (sm_state == NULL || handle == 0) {
pr_err("[%s]: invalid input\n", __func__);
return 0;
}
- /* Locate resource from GUID.
- */
+ /* Locate resource from GUID. */
resource = vmcs_sm_acquire_resource(sm_state->data_knl, handle);
if (resource) {
ret = resource->res_handle;
}
EXPORT_SYMBOL_GPL(vc_sm_int_handle);
-/* Free a previously allocated shared memory handle and block.
-*/
+/* Free a previously allocated shared memory handle and block. */
int vc_sm_free(int handle)
{
struct vmcs_sm_ioctl_free ioparam = { handle };
- /* Validate we can work with this device.
- */
+ /* Validate we can work with this device. */
if (sm_state == NULL || handle == 0) {
pr_err("[%s]: invalid input\n", __func__);
return -EPERM;
}
EXPORT_SYMBOL_GPL(vc_sm_free);
-/* Lock a memory handle for use by kernel.
-*/
+/* Lock a memory handle for use by kernel. */
int vc_sm_lock(int handle, VC_SM_LOCK_CACHE_MODE_T mode,
long unsigned int *data)
{
struct vmcs_sm_ioctl_lock_unlock ioparam;
int ret;
- /* Validate we can work with this device.
- */
+ /* Validate we can work with this device. */
if (sm_state == NULL || handle == 0 || data == NULL) {
pr_err("[%s]: invalid input\n", __func__);
return -EPERM;
}
EXPORT_SYMBOL_GPL(vc_sm_lock);
-/* Unlock a memory handle in use by kernel.
-*/
+/* Unlock a memory handle in use by kernel. */
int vc_sm_unlock(int handle, int flush, int no_vc_unlock)
{
struct vmcs_sm_ioctl_lock_unlock ioparam;
- /* Validate we can work with this device.
- */
+ /* Validate we can work with this device. */
if (sm_state == NULL || handle == 0) {
pr_err("[%s]: invalid input\n", __func__);
return -EPERM;
}
EXPORT_SYMBOL_GPL(vc_sm_unlock);
-/* Map a shared memory region for use by kernel.
-*/
+/* Map a shared memory region for use by kernel. */
int vc_sm_map(int handle, unsigned int sm_addr, VC_SM_LOCK_CACHE_MODE_T mode,
long unsigned int *data)
{
struct vmcs_sm_ioctl_lock_unlock ioparam;
int ret;
- /* Validate we can work with this device.
- */
+ /* Validate we can work with this device. */
if (sm_state == NULL || handle == 0 || data == NULL || sm_addr == 0) {
pr_err("[%s]: invalid input\n", __func__);
return -EPERM;