From 402830b08dc93a3bf0e23e4b5c4f143a9f616ca3 Mon Sep 17 00:00:00 2001 From: Mitchel Humpherys Date: Wed, 6 Feb 2013 12:03:20 -0800 Subject: [PATCH] msm: ADSPRPC: Cleanup header and source. Cleanup header and source to conform with coding guidelines. Change-Id: I0fba2a7a758930003d5bce9c8ffc0036574736b8 Acked-by: Anatoly Yakovenko Signed-off-by: Mitchel Humpherys --- drivers/char/adsprpc.c | 112 ++++++++++++++++++++++++++++++++- drivers/char/adsprpc.h | 113 ---------------------------------- drivers/char/adsprpc_shared.h | 6 ++ 3 files changed, 116 insertions(+), 115 deletions(-) delete mode 100644 drivers/char/adsprpc.h diff --git a/drivers/char/adsprpc.c b/drivers/char/adsprpc.c index 822da9161811..377331314592 100644 --- a/drivers/char/adsprpc.c +++ b/drivers/char/adsprpc.c @@ -11,8 +11,110 @@ * GNU General Public License for more details. * */ +#include "adsprpc_shared.h" + +#ifdef __KERNEL__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "adsprpc.h" +#include +#include +#include + +#ifndef ION_ADSPRPC_HEAP_ID +#define ION_ADSPRPC_HEAP_ID ION_AUDIO_HEAP_ID +#endif /*ION_ADSPRPC_HEAP_ID*/ + +#define RPC_TIMEOUT (5 * HZ) +#define RPC_HASH_BITS 5 +#define RPC_HASH_SZ (1 << RPC_HASH_BITS) +#define BALIGN 32 + +#define LOCK_MMAP(kernel)\ + do {\ + if (!kernel)\ + down_read(¤t->mm->mmap_sem);\ + } while (0) + +#define UNLOCK_MMAP(kernel)\ + do {\ + if (!kernel)\ + up_read(¤t->mm->mmap_sem);\ + } while (0) + + +static inline uint32_t buf_page_start(void *buf) +{ + uint32_t start = (uint32_t) buf & PAGE_MASK; + return start; +} + +static inline uint32_t buf_page_offset(void *buf) +{ + uint32_t offset = (uint32_t) buf & (PAGE_SIZE - 1); + return offset; +} + +static inline int buf_num_pages(void *buf, int len) +{ + uint32_t start = buf_page_start(buf) >> PAGE_SHIFT; + uint32_t end = (((uint32_t) buf + len - 1) & PAGE_MASK) >> PAGE_SHIFT; + int nPages = end - start + 1; + return nPages; +} + +static inline uint32_t buf_page_size(uint32_t size) +{ + uint32_t sz = (size + (PAGE_SIZE - 1)) & PAGE_MASK; + return sz > PAGE_SIZE ? sz : PAGE_SIZE; +} + +static inline int buf_get_pages(void *addr, int sz, int nr_pages, int access, + struct smq_phy_page *pages, int nr_elems) +{ + struct vm_area_struct *vma; + uint32_t start = buf_page_start(addr); + uint32_t len = nr_pages << PAGE_SHIFT; + unsigned long pfn; + int n = -1, err = 0; + + VERIFY(err, 0 != access_ok(access ? VERIFY_WRITE : VERIFY_READ, + (void __user *)start, len)); + if (err) + goto bail; + VERIFY(err, 0 != (vma = find_vma(current->mm, start))); + if (err) + goto bail; + VERIFY(err, ((uint32_t)addr + sz) <= vma->vm_end); + if (err) + goto bail; + n = 0; + VERIFY(err, 0 == follow_pfn(vma, start, &pfn)); + if (err) + goto bail; + VERIFY(err, nr_elems > 0); + if (err) + goto bail; + pages->addr = __pfn_to_phys(pfn); + pages->size = len; + n++; + bail: + return n; +} + +#endif /*__KERNEL__*/ struct smq_invoke_ctx { struct completion work; @@ -485,9 +587,9 @@ static int fastrpc_init(void) static void free_dev(struct fastrpc_device *dev) { if (dev) { - module_put(THIS_MODULE); free_mem(&dev->buf); kfree(dev); + module_put(THIS_MODULE); } } @@ -609,8 +711,10 @@ static int fastrpc_internal_invoke(struct fastrpc_apps *me, uint32_t kernel, wait_for_completion(&ctx->work); } context_free(ctx); + for (i = 0, b = abufs; i < nbufs; ++i, ++b) free_mem(b); + kfree(abufs); if (dev) { add_dev(me, dev); @@ -746,12 +850,16 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num, return err; } +#ifdef __KERNEL__ + static const struct file_operations fops = { .open = fastrpc_device_open, .release = fastrpc_device_release, .unlocked_ioctl = fastrpc_device_ioctl, }; +#endif /*__KERNEL__*/ + static int __init fastrpc_device_init(void) { struct fastrpc_apps *me = &gfa; diff --git a/drivers/char/adsprpc.h b/drivers/char/adsprpc.h deleted file mode 100644 index 3f1b4a771629..000000000000 --- a/drivers/char/adsprpc.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2012, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -#ifndef ADSPRPC_H -#define ADSPRPC_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "adsprpc_shared.h" - -#ifndef ION_ADSPRPC_HEAP_ID -#define ION_ADSPRPC_HEAP_ID ION_AUDIO_HEAP_ID -#endif - -#define RPC_TIMEOUT (5 * HZ) -#define RPC_HASH_BITS 5 -#define RPC_HASH_SZ (1 << RPC_HASH_BITS) -#define BALIGN 32 - -#define LOCK_MMAP(kernel)\ - do {\ - if (!kernel)\ - down_read(¤t->mm->mmap_sem);\ - } while (0) - -#define UNLOCK_MMAP(kernel)\ - do {\ - if (!kernel)\ - up_read(¤t->mm->mmap_sem);\ - } while (0) - - -static inline uint32_t buf_page_start(void *buf) -{ - uint32_t start = (uint32_t) buf & PAGE_MASK; - return start; -} - -static inline uint32_t buf_page_offset(void *buf) -{ - uint32_t offset = (uint32_t) buf & (PAGE_SIZE - 1); - return offset; -} - -static inline int buf_num_pages(void *buf, int len) -{ - uint32_t start = buf_page_start(buf) >> PAGE_SHIFT; - uint32_t end = (((uint32_t) buf + len - 1) & PAGE_MASK) >> PAGE_SHIFT; - int nPages = end - start + 1; - return nPages; -} - -static inline uint32_t buf_page_size(uint32_t size) -{ - uint32_t sz = (size + (PAGE_SIZE - 1)) & PAGE_MASK; - return sz > PAGE_SIZE ? sz : PAGE_SIZE; -} - -static inline int buf_get_pages(void *addr, int sz, int nr_pages, int access, - struct smq_phy_page *pages, int nr_elems) -{ - struct vm_area_struct *vma; - uint32_t start = buf_page_start(addr); - uint32_t len = nr_pages << PAGE_SHIFT; - unsigned long pfn; - int n = -1, err = 0; - - VERIFY(err, 0 != access_ok(access ? VERIFY_WRITE : VERIFY_READ, - (void __user *)start, len)); - if (err) - goto bail; - VERIFY(err, 0 != (vma = find_vma(current->mm, start))); - if (err) - goto bail; - VERIFY(err, ((uint32_t)addr + sz) <= vma->vm_end); - if (err) - goto bail; - n = 0; - VERIFY(err, 0 == follow_pfn(vma, start, &pfn)); - if (err) - goto bail; - VERIFY(err, nr_elems > 0); - if (err) - goto bail; - pages->addr = __pfn_to_phys(pfn); - pages->size = len; - n++; - bail: - return n; -} - -#endif diff --git a/drivers/char/adsprpc_shared.h b/drivers/char/adsprpc_shared.h index dc6ab6f13ee3..03545637af3f 100644 --- a/drivers/char/adsprpc_shared.h +++ b/drivers/char/adsprpc_shared.h @@ -14,6 +14,12 @@ #ifndef ADSPRPC_SHARED_H #define ADSPRPC_SHARED_H +#ifdef __KERNEL__ +#include +#endif /*__KERNEL__*/ + + + #define FASTRPC_IOCTL_INVOKE _IOWR('R', 1, struct fastrpc_ioctl_invoke) #define FASTRPC_SMD_GUID "fastrpcsmd-apps-dsp" #define DEVICE_NAME "adsprpc-smd"