Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 1 | /* |
Mitchel Humpherys | 6b4c68c | 2013-02-06 12:03:20 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 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_SHARED_H |
| 15 | #define ADSPRPC_SHARED_H |
| 16 | |
Mitchel Humpherys | 6b4c68c | 2013-02-06 12:03:20 -0800 | [diff] [blame] | 17 | #include <linux/types.h> |
| 18 | |
Mitchel Humpherys | 0d99a79 | 2013-03-05 13:41:14 -0800 | [diff] [blame] | 19 | #define FASTRPC_IOCTL_INVOKE _IOWR('R', 1, struct fastrpc_ioctl_invoke) |
| 20 | #define FASTRPC_IOCTL_MMAP _IOWR('R', 2, struct fastrpc_ioctl_mmap) |
| 21 | #define FASTRPC_IOCTL_MUNMAP _IOWR('R', 3, struct fastrpc_ioctl_munmap) |
Mitchel Humpherys | cf5d3c8 | 2013-07-10 12:53:18 -0700 | [diff] [blame] | 22 | #define FASTRPC_IOCTL_INVOKE_FD _IOWR('R', 4, struct fastrpc_ioctl_invoke_fd) |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 23 | #define FASTRPC_SMD_GUID "fastrpcsmd-apps-dsp" |
| 24 | #define DEVICE_NAME "adsprpc-smd" |
| 25 | |
| 26 | /* Retrives number of input buffers from the scalars parameter */ |
| 27 | #define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0x0ff) |
| 28 | |
| 29 | /* Retrives number of output buffers from the scalars parameter */ |
| 30 | #define REMOTE_SCALARS_OUTBUFS(sc) (((sc) >> 8) & 0x0ff) |
| 31 | |
| 32 | /* Retrives number of input handles from the scalars parameter */ |
| 33 | #define REMOTE_SCALARS_INHANDLES(sc) (((sc) >> 4) & 0x0f) |
| 34 | |
| 35 | /* Retrives number of output handles from the scalars parameter */ |
| 36 | #define REMOTE_SCALARS_OUTHANDLES(sc) ((sc) & 0x0f) |
| 37 | |
| 38 | #define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\ |
| 39 | REMOTE_SCALARS_OUTBUFS(sc) +\ |
| 40 | REMOTE_SCALARS_INHANDLES(sc) +\ |
| 41 | REMOTE_SCALARS_OUTHANDLES(sc)) |
| 42 | |
| 43 | #define REMOTE_SCALARS_MAKEX(attr, method, in, out, oin, oout) \ |
| 44 | ((((uint32_t) (attr) & 0x7) << 29) | \ |
| 45 | (((uint32_t) (method) & 0x1f) << 24) | \ |
| 46 | (((uint32_t) (in) & 0xff) << 16) | \ |
| 47 | (((uint32_t) (out) & 0xff) << 8) | \ |
| 48 | (((uint32_t) (oin) & 0x0f) << 4) | \ |
| 49 | ((uint32_t) (oout) & 0x0f)) |
| 50 | |
| 51 | #define REMOTE_SCALARS_MAKE(method, in, out) \ |
| 52 | REMOTE_SCALARS_MAKEX(0, method, in, out, 0, 0) |
| 53 | |
| 54 | |
| 55 | #ifndef VERIFY_PRINT_ERROR |
| 56 | #define VERIFY_EPRINTF(format, args) (void)0 |
| 57 | #endif |
| 58 | |
| 59 | #ifndef VERIFY_PRINT_INFO |
| 60 | #define VERIFY_IPRINTF(args) (void)0 |
| 61 | #endif |
| 62 | |
| 63 | #ifndef VERIFY |
| 64 | #define __STR__(x) #x ":" |
| 65 | #define __TOSTR__(x) __STR__(x) |
| 66 | #define __FILE_LINE__ __FILE__ ":" __TOSTR__(__LINE__) |
| 67 | |
Mitchel Humpherys | 42e806e | 2012-09-30 22:27:53 -0700 | [diff] [blame] | 68 | #define VERIFY(err, val) \ |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 69 | do {\ |
| 70 | VERIFY_IPRINTF(__FILE_LINE__"info: calling: " #val "\n");\ |
| 71 | if (0 == (val)) {\ |
Mitchel Humpherys | 42e806e | 2012-09-30 22:27:53 -0700 | [diff] [blame] | 72 | (err) = (err) == 0 ? -1 : (err);\ |
| 73 | VERIFY_EPRINTF(__FILE_LINE__"error: %d: " #val "\n", (err));\ |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 74 | } else {\ |
| 75 | VERIFY_IPRINTF(__FILE_LINE__"info: passed: " #val "\n");\ |
| 76 | } \ |
| 77 | } while (0) |
| 78 | #endif |
| 79 | |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 80 | #define remote_arg_t union remote_arg |
| 81 | |
| 82 | struct remote_buf { |
| 83 | void *pv; /* buffer pointer */ |
| 84 | int len; /* length of buffer */ |
| 85 | }; |
| 86 | |
| 87 | union remote_arg { |
| 88 | struct remote_buf buf; /* buffer info */ |
Mitchel Humpherys | 42e806e | 2012-09-30 22:27:53 -0700 | [diff] [blame] | 89 | uint32_t h; /* remote handle */ |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | struct fastrpc_ioctl_invoke { |
Mitchel Humpherys | 42e806e | 2012-09-30 22:27:53 -0700 | [diff] [blame] | 93 | uint32_t handle; /* remote handle */ |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 94 | uint32_t sc; /* scalars describing the data */ |
| 95 | remote_arg_t *pra; /* remote arguments list */ |
| 96 | }; |
| 97 | |
Mitchel Humpherys | cf5d3c8 | 2013-07-10 12:53:18 -0700 | [diff] [blame] | 98 | struct fastrpc_ioctl_invoke_fd { |
| 99 | struct fastrpc_ioctl_invoke inv; |
| 100 | int *fds; /* fd list */ |
| 101 | }; |
| 102 | |
Mitchel Humpherys | 0d99a79 | 2013-03-05 13:41:14 -0800 | [diff] [blame] | 103 | struct fastrpc_ioctl_munmap { |
| 104 | uint32_t vaddrout; /* address to unmap */ |
| 105 | int size; /* size */ |
| 106 | }; |
| 107 | |
| 108 | |
| 109 | struct fastrpc_ioctl_mmap { |
| 110 | int fd; /* ion fd */ |
| 111 | uint32_t flags; /* flags for dsp to map with */ |
| 112 | uint32_t vaddrin; /* optional virtual address */ |
| 113 | int size; /* size */ |
| 114 | uint32_t vaddrout; /* dsps virtual address */ |
| 115 | }; |
| 116 | |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 117 | struct smq_null_invoke { |
| 118 | struct smq_invoke_ctx *ctx; /* invoke caller context */ |
Mitchel Humpherys | 42e806e | 2012-09-30 22:27:53 -0700 | [diff] [blame] | 119 | uint32_t handle; /* handle to invoke */ |
Mitchel Humpherys | 79d361e | 2012-08-29 16:20:15 -0700 | [diff] [blame] | 120 | uint32_t sc; /* scalars structure describing the data */ |
| 121 | }; |
| 122 | |
| 123 | struct smq_phy_page { |
| 124 | uint32_t addr; /* physical address */ |
| 125 | uint32_t size; /* size of contiguous region */ |
| 126 | }; |
| 127 | |
| 128 | struct smq_invoke_buf { |
| 129 | int num; /* number of contiguous regions */ |
| 130 | int pgidx; /* index to start of contiguous region */ |
| 131 | }; |
| 132 | |
| 133 | struct smq_invoke { |
| 134 | struct smq_null_invoke header; |
| 135 | struct smq_phy_page page; /* remote arg and list of pages address */ |
| 136 | }; |
| 137 | |
| 138 | struct smq_msg { |
| 139 | uint32_t pid; /* process group id */ |
| 140 | uint32_t tid; /* thread id */ |
| 141 | struct smq_invoke invoke; |
| 142 | }; |
| 143 | |
| 144 | struct smq_invoke_rsp { |
| 145 | struct smq_invoke_ctx *ctx; /* invoke caller context */ |
| 146 | int retval; /* invoke return value */ |
| 147 | }; |
| 148 | |
| 149 | static inline struct smq_invoke_buf *smq_invoke_buf_start(remote_arg_t *pra, |
| 150 | uint32_t sc) |
| 151 | { |
| 152 | int len = REMOTE_SCALARS_LENGTH(sc); |
| 153 | return (struct smq_invoke_buf *)(&pra[len]); |
| 154 | } |
| 155 | |
| 156 | static inline struct smq_phy_page *smq_phy_page_start(uint32_t sc, |
| 157 | struct smq_invoke_buf *buf) |
| 158 | { |
| 159 | int nTotal = REMOTE_SCALARS_INBUFS(sc) + REMOTE_SCALARS_OUTBUFS(sc); |
| 160 | return (struct smq_phy_page *)(&buf[nTotal]); |
| 161 | } |
| 162 | |
| 163 | static inline int smq_invoke_buf_size(uint32_t sc, int nPages) |
| 164 | { |
| 165 | struct smq_phy_page *start = smq_phy_page_start(sc, 0); |
| 166 | return (int)(&(start[nPages])); |
| 167 | } |
| 168 | |
| 169 | #endif |