blob: b9a5cfec1e3abde516ccc4f52de713aa13662ba4 [file] [log] [blame]
Eric Holmberg6275b602012-11-19 13:05:04 -07001/* arch/arm/mach-msm/smp2p_private.h
2 *
3 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef _ARCH_ARM_MACH_MSM_MSM_SMP2P_PRIVATE_H_
15#define _ARCH_ARM_MACH_MSM_MSM_SMP2P_PRIVATE_H_
16
17#include <linux/types.h>
18#include <linux/spinlock.h>
19#include <mach/msm_ipc_logging.h>
20#include "smp2p_private_api.h"
21
22#define SMP2P_MAX_ENTRY 16
23#define SMP2P_LOCAL_VERSION 1
24#define SMP2P_LOCAL_FEATURE 0x0
25
26/* SMEM Item Header Macros */
27#define SMP2P_MAGIC 0x504D5324
28#define SMP2P_LOCAL_PID_MASK 0x0000ffff
29#define SMP2P_LOCAL_PID_BIT 0
30#define SMP2P_REMOTE_PID_MASK 0xffff0000
31#define SMP2P_REMOTE_PID_BIT 16
32#define SMP2P_VERSION_MASK 0x000000ff
33#define SMP2P_VERSION_BIT 0
34#define SMP2P_FEATURE_MASK 0xffffff00
35#define SMP2P_FEATURE_BIT 8
36#define SMP2P_ENT_TOTAL_MASK 0x0000ffff
37#define SMP2P_ENT_TOTAL_BIT 0
38#define SMP2P_ENT_VALID_MASK 0xffff0000
39#define SMP2P_ENT_VALID_BIT 16
40
41#define SMP2P_GET_BITS(hdr_val, mask, bit) \
42 (((hdr_val) & (mask)) >> (bit))
43#define SMP2P_SET_BITS(hdr_val, mask, bit, new_value) \
44 do {\
45 hdr_val = (hdr_val & ~(mask)) \
46 | (((new_value) << (bit)) & (mask)); \
47 } while (0)
48
49#define SMP2P_GET_LOCAL_PID(hdr) \
50 SMP2P_GET_BITS(hdr, SMP2P_LOCAL_PID_MASK, SMP2P_LOCAL_PID_BIT)
51#define SMP2P_SET_LOCAL_PID(hdr, pid) \
52 SMP2P_SET_BITS(hdr, SMP2P_LOCAL_PID_MASK, SMP2P_LOCAL_PID_BIT, pid)
53
54#define SMP2P_GET_REMOTE_PID(hdr) \
55 SMP2P_GET_BITS(hdr, SMP2P_REMOTE_PID_MASK, SMP2P_REMOTE_PID_BIT)
56#define SMP2P_SET_REMOTE_PID(hdr, pid) \
57 SMP2P_SET_BITS(hdr, SMP2P_REMOTE_PID_MASK, SMP2P_REMOTE_PID_BIT, pid)
58
59#define SMP2P_GET_VERSION(hdr) \
60 SMP2P_GET_BITS(hdr, SMP2P_VERSION_MASK, SMP2P_VERSION_BIT)
61#define SMP2P_SET_VERSION(hdr, version) \
62 SMP2P_SET_BITS(hdr, SMP2P_VERSION_MASK, SMP2P_VERSION_BIT, version)
63
64#define SMP2P_GET_FEATURES(hdr) \
65 SMP2P_GET_BITS(hdr, SMP2P_FEATURE_MASK, SMP2P_FEATURE_BIT)
66#define SMP2P_SET_FEATURES(hdr, features) \
67 SMP2P_SET_BITS(hdr, SMP2P_FEATURE_MASK, SMP2P_FEATURE_BIT, features)
68
69#define SMP2P_GET_ENT_TOTAL(hdr) \
70 SMP2P_GET_BITS(hdr, SMP2P_ENT_TOTAL_MASK, SMP2P_ENT_TOTAL_BIT)
71#define SMP2P_SET_ENT_TOTAL(hdr, entries) \
72 SMP2P_SET_BITS(hdr, SMP2P_ENT_TOTAL_MASK, SMP2P_ENT_TOTAL_BIT, entries)
73
74#define SMP2P_GET_ENT_VALID(hdr) \
75 SMP2P_GET_BITS(hdr, SMP2P_ENT_VALID_MASK, SMP2P_ENT_VALID_BIT)
76#define SMP2P_SET_ENT_VALID(hdr, entries) \
77 SMP2P_SET_BITS(hdr, SMP2P_ENT_VALID_MASK, SMP2P_ENT_VALID_BIT,\
78 entries)
79
80/* Loopback Command Macros */
81#define SMP2P_RMT_CMD_TYPE_MASK 0x80000000
82#define SMP2P_RMT_CMD_TYPE_BIT 31
83#define SMP2P_RMT_IGNORE_MASK 0x40000000
84#define SMP2P_RMT_IGNORE_BIT 30
85#define SMP2P_RMT_CMD_MASK 0x3f000000
86#define SMP2P_RMT_CMD_BIT 24
87#define SMP2P_RMT_DATA_MASK 0x00ffffff
88#define SMP2P_RMT_DATA_BIT 0
89
90#define SMP2P_GET_RMT_CMD_TYPE(val) \
91 SMP2P_GET_BITS(val, SMP2P_RMT_CMD_TYPE_MASK, SMP2P_RMT_CMD_TYPE_BIT)
92#define SMP2P_GET_RMT_CMD(val) \
93 SMP2P_GET_BITS(val, SMP2P_RMT_CMD_MASK, SMP2P_RMT_CMD_BIT)
94
95#define SMP2P_GET_RMT_DATA(val) \
96 SMP2P_GET_BITS(val, SMP2P_RMT_DATA_MASK, SMP2P_RMT_DATA_BIT)
97
98#define SMP2P_SET_RMT_CMD_TYPE(val, cmd_type) \
99 SMP2P_SET_BITS(val, SMP2P_RMT_CMD_TYPE_MASK, SMP2P_RMT_CMD_TYPE_BIT, \
100 cmd_type)
101#define SMP2P_SET_RMT_CMD_TYPE_REQ(val) \
102 SMP2P_SET_RMT_CMD_TYPE(val, 1)
103#define SMP2P_SET_RMT_CMD_TYPE_RESP(val) \
104 SMP2P_SET_RMT_CMD_TYPE(val, 0)
105
106#define SMP2P_SET_RMT_CMD(val, cmd) \
107 SMP2P_SET_BITS(val, SMP2P_RMT_CMD_MASK, SMP2P_RMT_CMD_BIT, \
108 cmd)
109#define SMP2P_SET_RMT_DATA(val, data) \
110 SMP2P_SET_BITS(val, SMP2P_RMT_DATA_MASK, SMP2P_RMT_DATA_BIT, data)
111
112enum {
113 SMP2P_LB_CMD_NOOP = 0x0,
114 SMP2P_LB_CMD_ECHO,
115 SMP2P_LB_CMD_CLEARALL,
116 SMP2P_LB_CMD_PINGPONG,
117 SMP2P_LB_CMD_RSPIN_START,
118 SMP2P_LB_CMD_RSPIN_LOCKED,
119 SMP2P_LB_CMD_RSPIN_UNLOCKED,
120 SMP2P_LB_CMD_RSPIN_END,
121};
122#define SMP2P_RLPB_IGNORE 0x40
123#define SMP2P_RLPB_ENTRY_NAME "smp2p"
124
125/* Debug Logging Macros */
126enum {
127 MSM_SMP2P_INFO = 1U << 0,
128 MSM_SMP2P_DEBUG = 1U << 1,
129 MSM_SMP2P_GPIO = 1U << 2,
130};
131
132#define SMP2P_IPC_LOG_STR(x...) do { \
133 if (smp2p_get_log_ctx()) \
134 ipc_log_string(smp2p_get_log_ctx(), x); \
135} while (0)
136
137#define SMP2P_DBG(x...) do { \
138 if (smp2p_get_debug_mask() & MSM_SMP2P_DEBUG) \
139 SMP2P_IPC_LOG_STR(x); \
140} while (0)
141
142#define SMP2P_INFO(x...) do { \
143 if (smp2p_get_debug_mask() & MSM_SMP2P_INFO) \
144 SMP2P_IPC_LOG_STR(x); \
145} while (0)
146
147#define SMP2P_ERR(x...) do { \
148 pr_err(x); \
149 SMP2P_IPC_LOG_STR(x); \
150} while (0)
151
152#define SMP2P_GPIO(x...) do { \
153 if (smp2p_get_debug_mask() & MSM_SMP2P_GPIO) \
154 SMP2P_IPC_LOG_STR(x); \
155} while (0)
156
157
158enum msm_smp2p_edge_state {
159 SMP2P_EDGE_STATE_CLOSED,
160 SMP2P_EDGE_STATE_OPENING,
161 SMP2P_EDGE_STATE_OPENED,
162 SMP2P_EDGE_STATE_FAILED = 0xff,
163};
164
165struct smp2p_smem {
166 uint32_t magic;
167 uint32_t feature_version;
168 uint32_t rem_loc_proc_id;
169 uint32_t valid_total_ent;
170 uint32_t reserved;
171};
172
173struct smp2p_entry_v1 {
174 char name[SMP2P_MAX_ENTRY_NAME];
175 uint32_t entry;
176};
177
178struct smp2p_smem_item {
179 struct smp2p_smem header;
180 struct smp2p_entry_v1 entries[SMP2P_MAX_ENTRY];
181};
182
183/* Mock object for internal loopback testing. */
184struct msm_smp2p_remote_mock {
185 struct smp2p_smem_item remote_item;
186 int rx_interrupt_count;
187 int (*rx_interrupt)(void);
188 void (*tx_interrupt)(void);
189
190 bool item_exists;
191 bool initialized;
192 struct completion cb_completion;
193};
194
195void smp2p_init_header(struct smp2p_smem *header_ptr, int local_pid,
196 int remote_pid, uint32_t features, uint32_t version);
197void *msm_smp2p_get_remote_mock(void);
198int smp2p_remote_mock_rx_interrupt(void);
199int smp2p_reset_mock_edge(void);
200void msm_smp2p_interrupt_handler(int);
201void msm_smp2p_set_remote_mock_exists(bool item_exists);
202void *msm_smp2p_get_remote_mock_smem_item(uint32_t *size);
203void *msm_smp2p_init_rmt_lpb_proc(int remote_pid);
204int msm_smp2p_deinit_rmt_lpb_proc(int remote_pid);
205void *smp2p_get_log_ctx(void);
206int smp2p_get_debug_mask(void);
207
208/* Inbound / outbound Interrupt configuration. */
209struct smp2p_interrupt_config {
210 bool is_configured;
211 uint32_t *out_int_ptr;
212 uint32_t out_int_mask;
213 int in_int_id;
214 const char *name;
215
216 /* interrupt stats */
217 unsigned in_interrupt_count;
218 unsigned out_interrupt_count;
219};
220
221struct smp2p_interrupt_config *smp2p_get_interrupt_config(void);
222const char *smp2p_pid_to_name(int remote_pid);
223struct smp2p_smem *smp2p_get_in_item(int remote_pid);
224struct smp2p_smem *smp2p_get_out_item(int remote_pid, int *state);
225void smp2p_gpio_open_test_entry(const char *name, int remote_pid, bool do_open);
226#endif