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