Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/smd_private.h |
| 2 | * |
| 3 | * Copyright (C) 2007 Google, Inc. |
Eric Holmberg | 6275b60 | 2012-11-19 13:05:04 -0700 | [diff] [blame] | 4 | * Copyright (c) 2007-2013, The Linux Foundation. All rights reserved. |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 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 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 19 | #include <linux/types.h> |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 20 | #include <linux/spinlock.h> |
Eric Holmberg | 6275b60 | 2012-11-19 13:05:04 -0700 | [diff] [blame] | 21 | #include <linux/errno.h> |
| 22 | #include <linux/remote_spinlock.h> |
Arun Kumar Neelakantam | 7cffb33 | 2013-01-28 15:43:35 +0530 | [diff] [blame^] | 23 | #include <linux/platform_device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 24 | #include <mach/msm_smsm.h> |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 25 | #include <mach/msm_smd.h> |
Daniel Walker | 74df1d0 | 2010-03-17 10:51:10 -0700 | [diff] [blame] | 26 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | #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 Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 38 | |
Daniel Walker | 79848a2 | 2010-03-16 15:20:07 -0700 | [diff] [blame] | 39 | struct smem_heap_info { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 40 | unsigned initialized; |
| 41 | unsigned free_offset; |
| 42 | unsigned heap_remaining; |
| 43 | unsigned reserved; |
| 44 | }; |
| 45 | |
Daniel Walker | 79848a2 | 2010-03-16 15:20:07 -0700 | [diff] [blame] | 46 | struct smem_heap_entry { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 47 | unsigned allocated; |
| 48 | unsigned offset; |
| 49 | unsigned size; |
Jeff Hugo | bdc734d | 2012-03-26 16:05:39 -0600 | [diff] [blame] | 50 | unsigned reserved; /* bits 1:0 reserved, bits 31:2 aux smem base addr */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 51 | }; |
Jeff Hugo | bdc734d | 2012-03-26 16:05:39 -0600 | [diff] [blame] | 52 | #define BASE_ADDR_MASK 0xfffffffc |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 53 | |
Daniel Walker | 79848a2 | 2010-03-16 15:20:07 -0700 | [diff] [blame] | 54 | struct smem_proc_comm { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 55 | unsigned command; |
| 56 | unsigned status; |
| 57 | unsigned data1; |
| 58 | unsigned data2; |
| 59 | }; |
| 60 | |
Daniel Walker | 79848a2 | 2010-03-16 15:20:07 -0700 | [diff] [blame] | 61 | struct smem_shared { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 62 | struct smem_proc_comm proc_comm[4]; |
| 63 | unsigned version[32]; |
| 64 | struct smem_heap_info heap_info; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 65 | struct smem_heap_entry heap_toc[SMD_HEAP_SIZE]; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 68 | #if defined(CONFIG_MSM_SMD_PKG4) |
Daniel Walker | 79848a2 | 2010-03-16 15:20:07 -0700 | [diff] [blame] | 69 | struct smsm_interrupt_info { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 70 | 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 Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 77 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | #elif defined(CONFIG_MSM_SMD_PKG3) |
| 79 | struct 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 Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 85 | /* Don't trigger the error */ |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 86 | #else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 87 | #error No SMD Package Specified; aborting |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 88 | #endif |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 89 | |
| 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 96 | #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 Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 103 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 104 | #define SMD_BUF_SIZE 8192 |
| 105 | #define SMD_CHANNELS 64 |
| 106 | #define SMD_HEADER_SIZE 20 |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 107 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 108 | /* '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 Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 114 | struct smd_alloc_elm { |
| 115 | char name[20]; |
| 116 | uint32_t cid; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 117 | uint32_t type; |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 118 | uint32_t ref_count; |
| 119 | }; |
| 120 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | #define SMD_CHANNEL_TYPE(x) ((x) & 0x000000FF) |
| 122 | #define SMD_XFER_TYPE(x) (((x) & 0x00000F00) >> 8) |
| 123 | |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 124 | struct 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 133 | unsigned char fBLOCKREADINTR; |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 134 | unsigned tail; |
| 135 | unsigned head; |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
Jeff Hugo | 918b2dc | 2012-03-21 13:42:09 -0600 | [diff] [blame] | 138 | struct 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 Walker | 79848a2 | 2010-03-16 15:20:07 -0700 | [diff] [blame] | 150 | }; |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 151 | |
Jeff Hugo | 918b2dc | 2012-03-21 13:42:09 -0600 | [diff] [blame] | 152 | struct smd_half_channel_access { |
Arun Kumar Neelakantam | 604e731 | 2012-12-10 14:14:19 +0530 | [diff] [blame] | 153 | 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 Hugo | 918b2dc | 2012-03-21 13:42:09 -0600 | [diff] [blame] | 156 | unsigned char data); |
Arun Kumar Neelakantam | 604e731 | 2012-12-10 14:14:19 +0530 | [diff] [blame] | 157 | 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 Hugo | 918b2dc | 2012-03-21 13:42:09 -0600 | [diff] [blame] | 183 | }; |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 184 | |
Jeff Hugo | 918b2dc | 2012-03-21 13:42:09 -0600 | [diff] [blame] | 185 | int is_word_access_ch(unsigned ch_type); |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 186 | |
Jeff Hugo | 918b2dc | 2012-03-21 13:42:09 -0600 | [diff] [blame] | 187 | struct smd_half_channel_access *get_half_ch_funcs(unsigned ch_type); |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 188 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 189 | struct smem_ram_ptn { |
| 190 | char name[16]; |
| 191 | unsigned start; |
| 192 | unsigned size; |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 193 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 194 | /* RAM Partition attribute: READ_ONLY, READWRITE etc. */ |
| 195 | unsigned attr; |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 196 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 197 | /* 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 Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 204 | unsigned type; |
| 205 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 206 | /* reserved for future expansion without changing version number */ |
| 207 | unsigned reserved2, reserved3, reserved4, reserved5; |
| 208 | } __attribute__ ((__packed__)); |
| 209 | |
Arun Kumar Neelakantam | 7cffb33 | 2013-01-28 15:43:35 +0530 | [diff] [blame^] | 210 | struct 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 Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 250 | |
| 251 | struct 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 */ |
| 263 | enum { |
| 264 | DEFAULT_ATTRB = ~0x0, |
| 265 | READ_ONLY = 0x0, |
| 266 | READWRITE, |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 267 | }; |
| 268 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 269 | enum { |
| 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 Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 283 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 284 | enum { |
| 285 | DEFAULT_DOMAIN = 0x0, |
| 286 | APPS_DOMAIN, |
| 287 | MODEM_DOMAIN, |
| 288 | SHARED_DOMAIN, |
| 289 | }; |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 290 | |
Naveen Ramaraj | 76483ad | 2011-09-06 14:25:44 -0700 | [diff] [blame] | 291 | enum { |
| 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 Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 298 | |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 299 | extern spinlock_t smem_lock; |
| 300 | |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 301 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 302 | void smd_diag(void); |
Daniel Walker | 79848a2 | 2010-03-16 15:20:07 -0700 | [diff] [blame] | 303 | |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 304 | struct interrupt_stat { |
| 305 | uint32_t smd_in_count; |
| 306 | uint32_t smd_out_hardcode_count; |
| 307 | uint32_t smd_out_config_count; |
Arun Kumar Neelakantam | ac7c02d | 2012-10-16 22:17:55 +0530 | [diff] [blame] | 308 | uint32_t smd_interrupt_id; |
Daniel Walker | bf83de4 | 2010-03-16 16:29:44 -0700 | [diff] [blame] | 309 | |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 310 | uint32_t smsm_in_count; |
| 311 | uint32_t smsm_out_hardcode_count; |
| 312 | uint32_t smsm_out_config_count; |
Arun Kumar Neelakantam | ac7c02d | 2012-10-16 22:17:55 +0530 | [diff] [blame] | 313 | uint32_t smsm_interrupt_id; |
Eric Holmberg | 7ad623a | 2012-03-01 14:41:10 -0700 | [diff] [blame] | 314 | }; |
| 315 | extern struct interrupt_stat interrupt_stats[NUM_SMD_SUBSYSTEMS]; |
Daniel Walker | 74df1d0 | 2010-03-17 10:51:10 -0700 | [diff] [blame] | 316 | |
Eric Holmberg | 6275b60 | 2012-11-19 13:05:04 -0700 | [diff] [blame] | 317 | /* used for unit testing spinlocks */ |
| 318 | remote_spinlock_t *smem_get_remote_spinlock(void); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 319 | #endif |