Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | #ifndef ADSPRPC_H |
| 15 | #define ADSPRPC_H |
| 16 | |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/completion.h> |
| 19 | #include <linux/pagemap.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/sched.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/cdev.h> |
| 25 | #include <linux/list.h> |
| 26 | #include <linux/hash.h> |
Mitchel Humpherys | 8a72c6f | 2012-09-26 17:52:50 -0700 | [diff] [blame] | 27 | #include <linux/msm_ion.h> |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 28 | #include <mach/msm_smd.h> |
| 29 | #include <mach/ion.h> |
| 30 | #include "adsprpc_shared.h" |
| 31 | |
| 32 | #ifndef ION_ADSPRPC_HEAP_ID |
| 33 | #define ION_ADSPRPC_HEAP_ID ION_AUDIO_HEAP_ID |
| 34 | #endif |
| 35 | |
| 36 | #define RPC_TIMEOUT (5 * HZ) |
| 37 | #define RPC_HASH_BITS 5 |
| 38 | #define RPC_HASH_SZ (1 << RPC_HASH_BITS) |
| 39 | |
| 40 | #define ALIGN_8(a) ALIGN(a, 8) |
| 41 | |
| 42 | #define LOCK_MMAP(kernel)\ |
| 43 | do {\ |
| 44 | if (!kernel)\ |
| 45 | down_read(¤t->mm->mmap_sem);\ |
| 46 | } while (0) |
| 47 | |
| 48 | #define UNLOCK_MMAP(kernel)\ |
| 49 | do {\ |
| 50 | if (!kernel)\ |
| 51 | up_read(¤t->mm->mmap_sem);\ |
| 52 | } while (0) |
| 53 | |
| 54 | |
| 55 | static inline uint32_t buf_page_start(void *buf) |
| 56 | { |
| 57 | uint32_t start = (uint32_t) buf & PAGE_MASK; |
| 58 | return start; |
| 59 | } |
| 60 | |
| 61 | static inline uint32_t buf_page_offset(void *buf) |
| 62 | { |
| 63 | uint32_t offset = (uint32_t) buf & (PAGE_SIZE - 1); |
| 64 | return offset; |
| 65 | } |
| 66 | |
| 67 | static inline int buf_num_pages(void *buf, int len) |
| 68 | { |
| 69 | uint32_t start = buf_page_start(buf) >> PAGE_SHIFT; |
| 70 | uint32_t end = (((uint32_t) buf + len - 1) & PAGE_MASK) >> PAGE_SHIFT; |
| 71 | int nPages = end - start + 1; |
| 72 | return nPages; |
| 73 | } |
| 74 | |
| 75 | static inline uint32_t buf_page_size(uint32_t size) |
| 76 | { |
| 77 | uint32_t sz = (size + (PAGE_SIZE - 1)) & PAGE_MASK; |
| 78 | return sz > PAGE_SIZE ? sz : PAGE_SIZE; |
| 79 | } |
| 80 | |
| 81 | static inline int buf_get_pages(void *addr, int sz, int nr_pages, int access, |
| 82 | struct smq_phy_page *pages, int nr_elems) |
| 83 | { |
| 84 | struct vm_area_struct *vma; |
| 85 | uint32_t start = buf_page_start(addr); |
| 86 | uint32_t len = nr_pages << PAGE_SHIFT; |
| 87 | uint32_t pfn; |
| 88 | int n = -1, err = 0; |
| 89 | |
| 90 | VERIFY(0 != access_ok(access ? VERIFY_WRITE : VERIFY_READ, |
| 91 | (void __user *)start, len)); |
| 92 | VERIFY(0 != (vma = find_vma(current->mm, start))); |
| 93 | VERIFY(((uint32_t)addr + sz) <= vma->vm_end); |
| 94 | n = 0; |
| 95 | VERIFY(0 != (vma->vm_flags & VM_PFNMAP)); |
| 96 | VERIFY(0 != (vma->vm_flags & VM_PFN_AT_MMAP)); |
| 97 | VERIFY(nr_elems > 0); |
| 98 | pfn = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT); |
| 99 | pages->addr = __pfn_to_phys(pfn); |
| 100 | pages->size = len; |
| 101 | n++; |
| 102 | bail: |
| 103 | return n; |
| 104 | } |
| 105 | |
| 106 | #endif |