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