smd_private.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /* arch/arm/mach-msm/smd_private.h
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. * Copyright (c) 2007 QUALCOMM Incorporated
  5. *
  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. #include <linux/platform_device.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/list.h>
  21. #include <linux/io.h>
  22. #include <mach/msm_iomap.h>
  23. struct smem_heap_info {
  24. unsigned initialized;
  25. unsigned free_offset;
  26. unsigned heap_remaining;
  27. unsigned reserved;
  28. };
  29. struct smem_heap_entry {
  30. unsigned allocated;
  31. unsigned offset;
  32. unsigned size;
  33. unsigned reserved;
  34. };
  35. struct smem_proc_comm {
  36. unsigned command;
  37. unsigned status;
  38. unsigned data1;
  39. unsigned data2;
  40. };
  41. #define PC_APPS 0
  42. #define PC_MODEM 1
  43. #define VERSION_SMD 0
  44. #define VERSION_QDSP6 4
  45. #define VERSION_APPS_SBL 6
  46. #define VERSION_MODEM_SBL 7
  47. #define VERSION_APPS 8
  48. #define VERSION_MODEM 9
  49. struct smem_shared {
  50. struct smem_proc_comm proc_comm[4];
  51. unsigned version[32];
  52. struct smem_heap_info heap_info;
  53. struct smem_heap_entry heap_toc[512];
  54. };
  55. #define SMSM_V1_SIZE (sizeof(unsigned) * 8)
  56. #define SMSM_V2_SIZE (sizeof(unsigned) * 4)
  57. #ifdef CONFIG_MSM_SMD_PKG3
  58. struct smsm_interrupt_info {
  59. uint32_t interrupt_mask;
  60. uint32_t pending_interrupts;
  61. uint32_t wakeup_reason;
  62. };
  63. #else
  64. #define DEM_MAX_PORT_NAME_LEN (20)
  65. struct msm_dem_slave_data {
  66. uint32_t sleep_time;
  67. uint32_t interrupt_mask;
  68. uint32_t resources_used;
  69. uint32_t reserved1;
  70. uint32_t wakeup_reason;
  71. uint32_t pending_interrupts;
  72. uint32_t rpc_prog;
  73. uint32_t rpc_proc;
  74. char smd_port_name[DEM_MAX_PORT_NAME_LEN];
  75. uint32_t reserved2;
  76. };
  77. #endif
  78. #define SZ_DIAG_ERR_MSG 0xC8
  79. #define ID_DIAG_ERR_MSG SMEM_DIAG_ERR_MESSAGE
  80. #define ID_SMD_CHANNELS SMEM_SMD_BASE_ID
  81. #define ID_SHARED_STATE SMEM_SMSM_SHARED_STATE
  82. #define ID_CH_ALLOC_TBL SMEM_CHANNEL_ALLOC_TBL
  83. #define SMSM_INIT 0x00000001
  84. #define SMSM_SMDINIT 0x00000008
  85. #define SMSM_RPCINIT 0x00000020
  86. #define SMSM_RESET 0x00000040
  87. #define SMSM_RSA 0x00000080
  88. #define SMSM_RUN 0x00000100
  89. #define SMSM_PWRC 0x00000200
  90. #define SMSM_TIMEWAIT 0x00000400
  91. #define SMSM_TIMEINIT 0x00000800
  92. #define SMSM_PWRC_EARLY_EXIT 0x00001000
  93. #define SMSM_WFPI 0x00002000
  94. #define SMSM_SLEEP 0x00004000
  95. #define SMSM_SLEEPEXIT 0x00008000
  96. #define SMSM_APPS_REBOOT 0x00020000
  97. #define SMSM_SYSTEM_POWER_DOWN 0x00040000
  98. #define SMSM_SYSTEM_REBOOT 0x00080000
  99. #define SMSM_SYSTEM_DOWNLOAD 0x00100000
  100. #define SMSM_PWRC_SUSPEND 0x00200000
  101. #define SMSM_APPS_SHUTDOWN 0x00400000
  102. #define SMSM_SMD_LOOPBACK 0x00800000
  103. #define SMSM_RUN_QUIET 0x01000000
  104. #define SMSM_MODEM_WAIT 0x02000000
  105. #define SMSM_MODEM_BREAK 0x04000000
  106. #define SMSM_MODEM_CONTINUE 0x08000000
  107. #define SMSM_UNKNOWN 0x80000000
  108. #define SMSM_WKUP_REASON_RPC 0x00000001
  109. #define SMSM_WKUP_REASON_INT 0x00000002
  110. #define SMSM_WKUP_REASON_GPIO 0x00000004
  111. #define SMSM_WKUP_REASON_TIMER 0x00000008
  112. #define SMSM_WKUP_REASON_ALARM 0x00000010
  113. #define SMSM_WKUP_REASON_RESET 0x00000020
  114. #ifdef CONFIG_ARCH_MSM7X00A
  115. enum smsm_state_item {
  116. SMSM_STATE_APPS = 1,
  117. SMSM_STATE_MODEM = 3,
  118. SMSM_STATE_COUNT,
  119. };
  120. #else
  121. enum smsm_state_item {
  122. SMSM_STATE_APPS,
  123. SMSM_STATE_MODEM,
  124. SMSM_STATE_HEXAGON,
  125. SMSM_STATE_APPS_DEM,
  126. SMSM_STATE_MODEM_DEM,
  127. SMSM_STATE_QDSP6_DEM,
  128. SMSM_STATE_POWER_MASTER_DEM,
  129. SMSM_STATE_TIME_MASTER_DEM,
  130. SMSM_STATE_COUNT,
  131. };
  132. #endif
  133. void *smem_alloc(unsigned id, unsigned size);
  134. int smsm_change_state(enum smsm_state_item item, uint32_t clear_mask, uint32_t set_mask);
  135. uint32_t smsm_get_state(enum smsm_state_item item);
  136. int smsm_set_sleep_duration(uint32_t delay);
  137. void smsm_print_sleep_info(void);
  138. #define SMEM_NUM_SMD_CHANNELS 64
  139. typedef enum {
  140. /* fixed items */
  141. SMEM_PROC_COMM = 0,
  142. SMEM_HEAP_INFO,
  143. SMEM_ALLOCATION_TABLE,
  144. SMEM_VERSION_INFO,
  145. SMEM_HW_RESET_DETECT,
  146. SMEM_AARM_WARM_BOOT,
  147. SMEM_DIAG_ERR_MESSAGE,
  148. SMEM_SPINLOCK_ARRAY,
  149. SMEM_MEMORY_BARRIER_LOCATION,
  150. /* dynamic items */
  151. SMEM_AARM_PARTITION_TABLE,
  152. SMEM_AARM_BAD_BLOCK_TABLE,
  153. SMEM_RESERVE_BAD_BLOCKS,
  154. SMEM_WM_UUID,
  155. SMEM_CHANNEL_ALLOC_TBL,
  156. SMEM_SMD_BASE_ID,
  157. SMEM_SMEM_LOG_IDX = SMEM_SMD_BASE_ID + SMEM_NUM_SMD_CHANNELS,
  158. SMEM_SMEM_LOG_EVENTS,
  159. SMEM_SMEM_STATIC_LOG_IDX,
  160. SMEM_SMEM_STATIC_LOG_EVENTS,
  161. SMEM_SMEM_SLOW_CLOCK_SYNC,
  162. SMEM_SMEM_SLOW_CLOCK_VALUE,
  163. SMEM_BIO_LED_BUF,
  164. SMEM_SMSM_SHARED_STATE,
  165. SMEM_SMSM_INT_INFO,
  166. SMEM_SMSM_SLEEP_DELAY,
  167. SMEM_SMSM_LIMIT_SLEEP,
  168. SMEM_SLEEP_POWER_COLLAPSE_DISABLED,
  169. SMEM_KEYPAD_KEYS_PRESSED,
  170. SMEM_KEYPAD_STATE_UPDATED,
  171. SMEM_KEYPAD_STATE_IDX,
  172. SMEM_GPIO_INT,
  173. SMEM_MDDI_LCD_IDX,
  174. SMEM_MDDI_HOST_DRIVER_STATE,
  175. SMEM_MDDI_LCD_DISP_STATE,
  176. SMEM_LCD_CUR_PANEL,
  177. SMEM_MARM_BOOT_SEGMENT_INFO,
  178. SMEM_AARM_BOOT_SEGMENT_INFO,
  179. SMEM_SLEEP_STATIC,
  180. SMEM_SCORPION_FREQUENCY,
  181. SMEM_SMD_PROFILES,
  182. SMEM_TSSC_BUSY,
  183. SMEM_HS_SUSPEND_FILTER_INFO,
  184. SMEM_BATT_INFO,
  185. SMEM_APPS_BOOT_MODE,
  186. SMEM_VERSION_FIRST,
  187. SMEM_VERSION_LAST = SMEM_VERSION_FIRST + 24,
  188. SMEM_OSS_RRCASN1_BUF1,
  189. SMEM_OSS_RRCASN1_BUF2,
  190. SMEM_ID_VENDOR0,
  191. SMEM_ID_VENDOR1,
  192. SMEM_ID_VENDOR2,
  193. SMEM_HW_SW_BUILD_ID,
  194. SMEM_SMD_BLOCK_PORT_BASE_ID,
  195. SMEM_SMD_BLOCK_PORT_PROC0_HEAP = SMEM_SMD_BLOCK_PORT_BASE_ID + SMEM_NUM_SMD_CHANNELS,
  196. SMEM_SMD_BLOCK_PORT_PROC1_HEAP = SMEM_SMD_BLOCK_PORT_PROC0_HEAP + SMEM_NUM_SMD_CHANNELS,
  197. SMEM_I2C_MUTEX = SMEM_SMD_BLOCK_PORT_PROC1_HEAP + SMEM_NUM_SMD_CHANNELS,
  198. SMEM_SCLK_CONVERSION,
  199. SMEM_SMD_SMSM_INTR_MUX,
  200. SMEM_SMSM_CPU_INTR_MASK,
  201. SMEM_APPS_DEM_SLAVE_DATA,
  202. SMEM_QDSP6_DEM_SLAVE_DATA,
  203. SMEM_CLKREGIM_BSP,
  204. SMEM_CLKREGIM_SOURCES,
  205. SMEM_SMD_FIFO_BASE_ID,
  206. SMEM_USABLE_RAM_PARTITION_TABLE = SMEM_SMD_FIFO_BASE_ID + SMEM_NUM_SMD_CHANNELS,
  207. SMEM_POWER_ON_STATUS_INFO,
  208. SMEM_DAL_AREA,
  209. SMEM_SMEM_LOG_POWER_IDX,
  210. SMEM_SMEM_LOG_POWER_WRAP,
  211. SMEM_SMEM_LOG_POWER_EVENTS,
  212. SMEM_ERR_CRASH_LOG,
  213. SMEM_ERR_F3_TRACE_LOG,
  214. SMEM_NUM_ITEMS,
  215. } smem_mem_type;
  216. #define SMD_SS_CLOSED 0x00000000
  217. #define SMD_SS_OPENING 0x00000001
  218. #define SMD_SS_OPENED 0x00000002
  219. #define SMD_SS_FLUSHING 0x00000003
  220. #define SMD_SS_CLOSING 0x00000004
  221. #define SMD_SS_RESET 0x00000005
  222. #define SMD_SS_RESET_OPENING 0x00000006
  223. #define SMD_BUF_SIZE 8192
  224. #define SMD_CHANNELS 64
  225. #define SMD_HEADER_SIZE 20
  226. struct smd_alloc_elm {
  227. char name[20];
  228. uint32_t cid;
  229. uint32_t ctype;
  230. uint32_t ref_count;
  231. };
  232. struct smd_half_channel {
  233. unsigned state;
  234. unsigned char fDSR;
  235. unsigned char fCTS;
  236. unsigned char fCD;
  237. unsigned char fRI;
  238. unsigned char fHEAD;
  239. unsigned char fTAIL;
  240. unsigned char fSTATE;
  241. unsigned char fUNUSED;
  242. unsigned tail;
  243. unsigned head;
  244. } __attribute__(( aligned(4), packed ));
  245. /* Only used on SMD package v3 on msm7201a */
  246. struct smd_shared_v1 {
  247. struct smd_half_channel ch0;
  248. unsigned char data0[SMD_BUF_SIZE];
  249. struct smd_half_channel ch1;
  250. unsigned char data1[SMD_BUF_SIZE];
  251. };
  252. /* Used on SMD package v4 */
  253. struct smd_shared_v2 {
  254. struct smd_half_channel ch0;
  255. struct smd_half_channel ch1;
  256. };
  257. struct smd_channel {
  258. volatile struct smd_half_channel *send;
  259. volatile struct smd_half_channel *recv;
  260. unsigned char *send_data;
  261. unsigned char *recv_data;
  262. unsigned fifo_mask;
  263. unsigned fifo_size;
  264. unsigned current_packet;
  265. unsigned n;
  266. struct list_head ch_list;
  267. void *priv;
  268. void (*notify)(void *priv, unsigned flags);
  269. int (*read)(struct smd_channel *ch, void *data, int len);
  270. int (*write)(struct smd_channel *ch, const void *data, int len);
  271. int (*read_avail)(struct smd_channel *ch);
  272. int (*write_avail)(struct smd_channel *ch);
  273. void (*update_state)(struct smd_channel *ch);
  274. unsigned last_state;
  275. void (*notify_other_cpu)(void);
  276. unsigned type;
  277. char name[32];
  278. struct platform_device pdev;
  279. };
  280. #define SMD_TYPE_MASK 0x0FF
  281. #define SMD_TYPE_APPS_MODEM 0x000
  282. #define SMD_TYPE_APPS_DSP 0x001
  283. #define SMD_TYPE_MODEM_DSP 0x002
  284. #define SMD_KIND_MASK 0xF00
  285. #define SMD_KIND_UNKNOWN 0x000
  286. #define SMD_KIND_STREAM 0x100
  287. #define SMD_KIND_PACKET 0x200
  288. extern struct list_head smd_ch_closed_list;
  289. extern struct list_head smd_ch_list_modem;
  290. extern struct list_head smd_ch_list_dsp;
  291. extern spinlock_t smd_lock;
  292. extern spinlock_t smem_lock;
  293. void *smem_find(unsigned id, unsigned size);
  294. void *smem_item(unsigned id, unsigned *size);
  295. uint32_t raw_smsm_get_state(enum smsm_state_item item);
  296. extern void msm_init_last_radio_log(struct module *);
  297. #ifdef CONFIG_MSM_SMD_PKG3
  298. /*
  299. * This allocator assumes an SMD Package v3 which only exists on
  300. * MSM7x00 SoC's.
  301. */
  302. static inline int _smd_alloc_channel(struct smd_channel *ch)
  303. {
  304. struct smd_shared_v1 *shared1;
  305. shared1 = smem_alloc(ID_SMD_CHANNELS + ch->n, sizeof(*shared1));
  306. if (!shared1) {
  307. pr_err("smd_alloc_channel() cid %d does not exist\n", ch->n);
  308. return -1;
  309. }
  310. ch->send = &shared1->ch0;
  311. ch->recv = &shared1->ch1;
  312. ch->send_data = shared1->data0;
  313. ch->recv_data = shared1->data1;
  314. ch->fifo_size = SMD_BUF_SIZE;
  315. return 0;
  316. }
  317. #else
  318. /*
  319. * This allocator assumes an SMD Package v4, the most common
  320. * and the default.
  321. */
  322. static inline int _smd_alloc_channel(struct smd_channel *ch)
  323. {
  324. struct smd_shared_v2 *shared2;
  325. void *buffer;
  326. unsigned buffer_sz;
  327. shared2 = smem_alloc(SMEM_SMD_BASE_ID + ch->n, sizeof(*shared2));
  328. buffer = smem_item(SMEM_SMD_FIFO_BASE_ID + ch->n, &buffer_sz);
  329. if (!buffer)
  330. return -1;
  331. /* buffer must be a power-of-two size */
  332. if (buffer_sz & (buffer_sz - 1))
  333. return -1;
  334. buffer_sz /= 2;
  335. ch->send = &shared2->ch0;
  336. ch->recv = &shared2->ch1;
  337. ch->send_data = buffer;
  338. ch->recv_data = buffer + buffer_sz;
  339. ch->fifo_size = buffer_sz;
  340. return 0;
  341. }
  342. #endif /* CONFIG_MSM_SMD_PKG3 */
  343. #if defined(CONFIG_ARCH_MSM7X30)
  344. static inline void msm_a2m_int(uint32_t irq)
  345. {
  346. writel(1 << irq, MSM_GCC_BASE + 0x8);
  347. }
  348. #else
  349. static inline void msm_a2m_int(uint32_t irq)
  350. {
  351. writel(1, MSM_CSR_BASE + 0x400 + (irq * 4));
  352. }
  353. #endif /* CONFIG_ARCH_MSM7X30 */
  354. #endif