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