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