blob: 4a6a50918de06367937307c36e9c2dc3a1acbce6 [file] [log] [blame]
Brian Swetland2eb44eb2008-09-29 16:00:48 -07001/* arch/arm/mach-msm/smd_private.h
2 *
3 * Copyright (C) 2007 Google, Inc.
Eric Holmberg6275b602012-11-19 13:05:04 -07004 * Copyright (c) 2007-2013, The Linux Foundation. All rights reserved.
Brian Swetland2eb44eb2008-09-29 16:00:48 -07005 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16#ifndef _ARCH_ARM_MACH_MSM_MSM_SMD_PRIVATE_H_
17#define _ARCH_ARM_MACH_MSM_MSM_SMD_PRIVATE_H_
18
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070019#include <linux/types.h>
Brian Swetland03e00cd2009-07-01 17:58:37 -070020#include <linux/spinlock.h>
Eric Holmberg6275b602012-11-19 13:05:04 -070021#include <linux/errno.h>
22#include <linux/remote_spinlock.h>
Arun Kumar Neelakantam7cffb332013-01-28 15:43:35 +053023#include <linux/platform_device.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070024#include <mach/msm_smsm.h>
Eric Holmberg7ad623a2012-03-01 14:41:10 -070025#include <mach/msm_smd.h>
Daniel Walker74df1d02010-03-17 10:51:10 -070026
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027#define PC_APPS 0
28#define PC_MODEM 1
29
30#define VERSION_QDSP6 4
31#define VERSION_APPS_SBL 6
32#define VERSION_MODEM_SBL 7
33#define VERSION_APPS 8
34#define VERSION_MODEM 9
35#define VERSION_DSPS 10
36
37#define SMD_HEAP_SIZE 512
Brian Swetland03e00cd2009-07-01 17:58:37 -070038
Daniel Walker79848a22010-03-16 15:20:07 -070039struct smem_heap_info {
Brian Swetland2eb44eb2008-09-29 16:00:48 -070040 unsigned initialized;
41 unsigned free_offset;
42 unsigned heap_remaining;
43 unsigned reserved;
44};
45
Daniel Walker79848a22010-03-16 15:20:07 -070046struct smem_heap_entry {
Brian Swetland2eb44eb2008-09-29 16:00:48 -070047 unsigned allocated;
48 unsigned offset;
49 unsigned size;
Jeff Hugobdc734d2012-03-26 16:05:39 -060050 unsigned reserved; /* bits 1:0 reserved, bits 31:2 aux smem base addr */
Brian Swetland2eb44eb2008-09-29 16:00:48 -070051};
Jeff Hugobdc734d2012-03-26 16:05:39 -060052#define BASE_ADDR_MASK 0xfffffffc
Brian Swetland2eb44eb2008-09-29 16:00:48 -070053
Daniel Walker79848a22010-03-16 15:20:07 -070054struct smem_proc_comm {
Brian Swetland2eb44eb2008-09-29 16:00:48 -070055 unsigned command;
56 unsigned status;
57 unsigned data1;
58 unsigned data2;
59};
60
Daniel Walker79848a22010-03-16 15:20:07 -070061struct smem_shared {
Brian Swetland2eb44eb2008-09-29 16:00:48 -070062 struct smem_proc_comm proc_comm[4];
63 unsigned version[32];
64 struct smem_heap_info heap_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070065 struct smem_heap_entry heap_toc[SMD_HEAP_SIZE];
Brian Swetland2eb44eb2008-09-29 16:00:48 -070066};
67
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068#if defined(CONFIG_MSM_SMD_PKG4)
Daniel Walker79848a22010-03-16 15:20:07 -070069struct smsm_interrupt_info {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070 uint32_t aArm_en_mask;
71 uint32_t aArm_interrupts_pending;
72 uint32_t aArm_wakeup_reason;
73 uint32_t aArm_rpc_prog;
74 uint32_t aArm_rpc_proc;
75 char aArm_smd_port_name[20];
76 uint32_t aArm_gpio_info;
Brian Swetland2eb44eb2008-09-29 16:00:48 -070077};
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078#elif defined(CONFIG_MSM_SMD_PKG3)
79struct smsm_interrupt_info {
80 uint32_t aArm_en_mask;
81 uint32_t aArm_interrupts_pending;
82 uint32_t aArm_wakeup_reason;
83};
84#elif !defined(CONFIG_MSM_SMD)
Steve Mucklef132c6c2012-06-06 18:30:57 -070085/* Don't trigger the error */
Arve Hjønnevågec9d3d12009-06-16 14:48:21 -070086#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070087#error No SMD Package Specified; aborting
Arve Hjønnevågec9d3d12009-06-16 14:48:21 -070088#endif
Brian Swetland2eb44eb2008-09-29 16:00:48 -070089
90#define SZ_DIAG_ERR_MSG 0xC8
91#define ID_DIAG_ERR_MSG SMEM_DIAG_ERR_MESSAGE
92#define ID_SMD_CHANNELS SMEM_SMD_BASE_ID
93#define ID_SHARED_STATE SMEM_SMSM_SHARED_STATE
94#define ID_CH_ALLOC_TBL SMEM_CHANNEL_ALLOC_TBL
95
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096#define SMD_SS_CLOSED 0x00000000
97#define SMD_SS_OPENING 0x00000001
98#define SMD_SS_OPENED 0x00000002
99#define SMD_SS_FLUSHING 0x00000003
100#define SMD_SS_CLOSING 0x00000004
101#define SMD_SS_RESET 0x00000005
102#define SMD_SS_RESET_OPENING 0x00000006
Brian Swetland2eb44eb2008-09-29 16:00:48 -0700103
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700104#define SMD_BUF_SIZE 8192
105#define SMD_CHANNELS 64
106#define SMD_HEADER_SIZE 20
Brian Swetland2eb44eb2008-09-29 16:00:48 -0700107
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108/* 'type' field of smd_alloc_elm structure
109 * has the following breakup
110 * bits 0-7 -> channel type
111 * bits 8-11 -> xfer type
112 * bits 12-31 -> reserved
113 */
Brian Swetland03e00cd2009-07-01 17:58:37 -0700114struct smd_alloc_elm {
115 char name[20];
116 uint32_t cid;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117 uint32_t type;
Brian Swetland03e00cd2009-07-01 17:58:37 -0700118 uint32_t ref_count;
119};
120
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121#define SMD_CHANNEL_TYPE(x) ((x) & 0x000000FF)
122#define SMD_XFER_TYPE(x) (((x) & 0x00000F00) >> 8)
123
Brian Swetland03e00cd2009-07-01 17:58:37 -0700124struct smd_half_channel {
125 unsigned state;
126 unsigned char fDSR;
127 unsigned char fCTS;
128 unsigned char fCD;
129 unsigned char fRI;
130 unsigned char fHEAD;
131 unsigned char fTAIL;
132 unsigned char fSTATE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133 unsigned char fBLOCKREADINTR;
Brian Swetland03e00cd2009-07-01 17:58:37 -0700134 unsigned tail;
135 unsigned head;
Brian Swetland03e00cd2009-07-01 17:58:37 -0700136};
137
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600138struct smd_half_channel_word_access {
139 unsigned state;
140 unsigned fDSR;
141 unsigned fCTS;
142 unsigned fCD;
143 unsigned fRI;
144 unsigned fHEAD;
145 unsigned fTAIL;
146 unsigned fSTATE;
147 unsigned fBLOCKREADINTR;
148 unsigned tail;
149 unsigned head;
Daniel Walker79848a22010-03-16 15:20:07 -0700150};
Brian Swetland03e00cd2009-07-01 17:58:37 -0700151
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600152struct smd_half_channel_access {
Arun Kumar Neelakantam604e7312012-12-10 14:14:19 +0530153 void (*set_state)(volatile void __iomem *half_channel, unsigned data);
154 unsigned (*get_state)(volatile void __iomem *half_channel);
155 void (*set_fDSR)(volatile void __iomem *half_channel,
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600156 unsigned char data);
Arun Kumar Neelakantam604e7312012-12-10 14:14:19 +0530157 unsigned (*get_fDSR)(volatile void __iomem *half_channel);
158 void (*set_fCTS)(volatile void __iomem *half_channel,
159 unsigned char data);
160 unsigned (*get_fCTS)(volatile void __iomem *half_channel);
161 void (*set_fCD)(volatile void __iomem *half_channel,
162 unsigned char data);
163 unsigned (*get_fCD)(volatile void __iomem *half_channel);
164 void (*set_fRI)(volatile void __iomem *half_channel,
165 unsigned char data);
166 unsigned (*get_fRI)(volatile void __iomem *half_channel);
167 void (*set_fHEAD)(volatile void __iomem *half_channel,
168 unsigned char data);
169 unsigned (*get_fHEAD)(volatile void __iomem *half_channel);
170 void (*set_fTAIL)(volatile void __iomem *half_channel,
171 unsigned char data);
172 unsigned (*get_fTAIL)(volatile void __iomem *half_channel);
173 void (*set_fSTATE)(volatile void __iomem *half_channel,
174 unsigned char data);
175 unsigned (*get_fSTATE)(volatile void __iomem *half_channel);
176 void (*set_fBLOCKREADINTR)(volatile void __iomem *half_channel,
177 unsigned char data);
178 unsigned (*get_fBLOCKREADINTR)(volatile void __iomem *half_channel);
179 void (*set_tail)(volatile void __iomem *half_channel, unsigned data);
180 unsigned (*get_tail)(volatile void __iomem *half_channel);
181 void (*set_head)(volatile void __iomem *half_channel, unsigned data);
182 unsigned (*get_head)(volatile void __iomem *half_channel);
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600183};
Brian Swetland03e00cd2009-07-01 17:58:37 -0700184
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600185int is_word_access_ch(unsigned ch_type);
Brian Swetland03e00cd2009-07-01 17:58:37 -0700186
Jeff Hugo918b2dc2012-03-21 13:42:09 -0600187struct smd_half_channel_access *get_half_ch_funcs(unsigned ch_type);
Brian Swetland03e00cd2009-07-01 17:58:37 -0700188
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700189struct smem_ram_ptn {
190 char name[16];
191 unsigned start;
192 unsigned size;
Brian Swetland03e00cd2009-07-01 17:58:37 -0700193
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700194 /* RAM Partition attribute: READ_ONLY, READWRITE etc. */
195 unsigned attr;
Brian Swetland03e00cd2009-07-01 17:58:37 -0700196
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700197 /* RAM Partition category: EBI0, EBI1, IRAM, IMEM */
198 unsigned category;
199
200 /* RAM Partition domain: APPS, MODEM, APPS & MODEM (SHARED) etc. */
201 unsigned domain;
202
203 /* RAM Partition type: system, bootloader, appsboot, apps etc. */
Brian Swetland03e00cd2009-07-01 17:58:37 -0700204 unsigned type;
205
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700206 /* reserved for future expansion without changing version number */
207 unsigned reserved2, reserved3, reserved4, reserved5;
208} __attribute__ ((__packed__));
209
Arun Kumar Neelakantam7cffb332013-01-28 15:43:35 +0530210struct smd_channel {
211 volatile void __iomem *send; /* some variant of smd_half_channel */
212 volatile void __iomem *recv; /* some variant of smd_half_channel */
213 unsigned char *send_data;
214 unsigned char *recv_data;
215 unsigned fifo_size;
216 unsigned fifo_mask;
217 struct list_head ch_list;
218
219 unsigned current_packet;
220 unsigned n;
221 void *priv;
222 void (*notify)(void *priv, unsigned flags);
223
224 int (*read)(smd_channel_t *ch, void *data, int len, int user_buf);
225 int (*write)(smd_channel_t *ch, const void *data, int len,
226 int user_buf);
227 int (*read_avail)(smd_channel_t *ch);
228 int (*write_avail)(smd_channel_t *ch);
229 int (*read_from_cb)(smd_channel_t *ch, void *data, int len,
230 int user_buf);
231
232 void (*update_state)(smd_channel_t *ch);
233 unsigned last_state;
234 void (*notify_other_cpu)(smd_channel_t *ch);
235
236 char name[20];
237 struct platform_device pdev;
238 unsigned type;
239
240 int pending_pkt_sz;
241
242 char is_pkt_ch;
243
244 /*
245 * private internal functions to access *send and *recv.
246 * never to be exported outside of smd
247 */
248 struct smd_half_channel_access *half_ch;
249};
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700250
251struct smem_ram_ptable {
252 #define _SMEM_RAM_PTABLE_MAGIC_1 0x9DA5E0A8
253 #define _SMEM_RAM_PTABLE_MAGIC_2 0xAF9EC4E2
254 unsigned magic[2];
255 unsigned version;
256 unsigned reserved1;
257 unsigned len;
258 struct smem_ram_ptn parts[32];
259 unsigned buf;
260} __attribute__ ((__packed__));
261
262/* SMEM RAM Partition */
263enum {
264 DEFAULT_ATTRB = ~0x0,
265 READ_ONLY = 0x0,
266 READWRITE,
Brian Swetland03e00cd2009-07-01 17:58:37 -0700267};
268
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700269enum {
270 DEFAULT_CATEGORY = ~0x0,
271 SMI = 0x0,
272 EBI1,
273 EBI2,
274 QDSP6,
275 IRAM,
276 IMEM,
277 EBI0_CS0,
278 EBI0_CS1,
279 EBI1_CS0,
280 EBI1_CS1,
281 SDRAM = 0xE,
282};
Brian Swetland03e00cd2009-07-01 17:58:37 -0700283
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700284enum {
285 DEFAULT_DOMAIN = 0x0,
286 APPS_DOMAIN,
287 MODEM_DOMAIN,
288 SHARED_DOMAIN,
289};
Brian Swetland03e00cd2009-07-01 17:58:37 -0700290
Naveen Ramaraj76483ad2011-09-06 14:25:44 -0700291enum {
292 SYS_MEMORY = 1, /* system memory*/
293 BOOT_REGION_MEMORY1, /* boot loader memory 1*/
294 BOOT_REGION_MEMORY2, /* boot loader memory 2,reserved*/
295 APPSBL_MEMORY, /* apps boot loader memory*/
296 APPS_MEMORY, /* apps usage memory*/
297};
Brian Swetland03e00cd2009-07-01 17:58:37 -0700298
Brian Swetland03e00cd2009-07-01 17:58:37 -0700299extern spinlock_t smem_lock;
300
Brian Swetland03e00cd2009-07-01 17:58:37 -0700301
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700302void smd_diag(void);
Daniel Walker79848a22010-03-16 15:20:07 -0700303
Eric Holmberg7ad623a2012-03-01 14:41:10 -0700304struct interrupt_stat {
305 uint32_t smd_in_count;
306 uint32_t smd_out_hardcode_count;
307 uint32_t smd_out_config_count;
Arun Kumar Neelakantamac7c02d2012-10-16 22:17:55 +0530308 uint32_t smd_interrupt_id;
Daniel Walkerbf83de42010-03-16 16:29:44 -0700309
Eric Holmberg7ad623a2012-03-01 14:41:10 -0700310 uint32_t smsm_in_count;
311 uint32_t smsm_out_hardcode_count;
312 uint32_t smsm_out_config_count;
Arun Kumar Neelakantamac7c02d2012-10-16 22:17:55 +0530313 uint32_t smsm_interrupt_id;
Eric Holmberg7ad623a2012-03-01 14:41:10 -0700314};
315extern struct interrupt_stat interrupt_stats[NUM_SMD_SUBSYSTEMS];
Daniel Walker74df1d02010-03-17 10:51:10 -0700316
Eric Holmberg6275b602012-11-19 13:05:04 -0700317/* used for unit testing spinlocks */
318remote_spinlock_t *smem_get_remote_spinlock(void);
Brian Swetland2eb44eb2008-09-29 16:00:48 -0700319#endif