Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/smd.c |
| 2 | * |
| 3 | * Copyright (C) 2007 Google, Inc. |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 4 | * Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved. |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 5 | * Author: Brian Swetland <swetland@google.com> |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/cdev.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/wait.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/irq.h> |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/slab.h> |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 28 | #include <linux/delay.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 29 | #include <linux/io.h> |
| 30 | #include <linux/termios.h> |
| 31 | #include <linux/ctype.h> |
| 32 | #include <linux/remote_spinlock.h> |
| 33 | #include <linux/uaccess.h> |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 34 | #include <linux/kfifo.h> |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 35 | #include <mach/msm_smd.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | #include <mach/msm_iomap.h> |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 37 | #include <mach/system.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | #include <mach/subsystem_notif.h> |
Angshuman Sarkar | ead67bd | 2011-09-21 20:13:12 +0530 | [diff] [blame] | 39 | #include <mach/socinfo.h> |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 40 | |
| 41 | #include "smd_private.h" |
| 42 | #include "proc_comm.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | #include "modem_notifier.h" |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 44 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 45 | #if defined(CONFIG_ARCH_QSD8X50) || defined(CONFIG_ARCH_MSM8X60) \ |
Jeff Hugo | 56b933a | 2011-09-28 14:42:05 -0600 | [diff] [blame] | 46 | || defined(CONFIG_ARCH_MSM8960) || defined(CONFIG_ARCH_FSM9XXX) \ |
Jeff Hugo | 0c0f5e9 | 2011-09-28 13:55:45 -0600 | [diff] [blame] | 47 | || defined(CONFIG_ARCH_MSM9615) || defined(CONFIG_ARCH_APQ8064) |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 48 | #define CONFIG_QDSP6 1 |
| 49 | #endif |
| 50 | |
Jeff Hugo | 0c0f5e9 | 2011-09-28 13:55:45 -0600 | [diff] [blame] | 51 | #if defined(CONFIG_ARCH_MSM8X60) || defined(CONFIG_ARCH_MSM8960) \ |
| 52 | || defined(CONFIG_ARCH_APQ8064) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 53 | #define CONFIG_DSPS 1 |
| 54 | #endif |
| 55 | |
Jeff Hugo | 0c0f5e9 | 2011-09-28 13:55:45 -0600 | [diff] [blame] | 56 | #if defined(CONFIG_ARCH_MSM8960) \ |
| 57 | || defined(CONFIG_ARCH_APQ8064) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 58 | #define CONFIG_WCNSS 1 |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 59 | #define CONFIG_DSPS_SMSM 1 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 60 | #endif |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 61 | |
| 62 | #define MODULE_NAME "msm_smd" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 63 | #define SMEM_VERSION 0x000B |
| 64 | #define SMD_VERSION 0x00020000 |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 65 | #define SMSM_SNAPSHOT_CNT 64 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 66 | |
| 67 | uint32_t SMSM_NUM_ENTRIES = 8; |
| 68 | uint32_t SMSM_NUM_HOSTS = 3; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 69 | |
| 70 | enum { |
| 71 | MSM_SMD_DEBUG = 1U << 0, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 72 | MSM_SMSM_DEBUG = 1U << 1, |
| 73 | MSM_SMD_INFO = 1U << 2, |
| 74 | MSM_SMSM_INFO = 1U << 3, |
| 75 | }; |
| 76 | |
| 77 | struct smsm_shared_info { |
| 78 | uint32_t *state; |
| 79 | uint32_t *intr_mask; |
| 80 | uint32_t *intr_mux; |
| 81 | }; |
| 82 | |
| 83 | static struct smsm_shared_info smsm_info; |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 84 | struct kfifo smsm_snapshot_fifo; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 85 | |
| 86 | struct smsm_size_info_type { |
| 87 | uint32_t num_hosts; |
| 88 | uint32_t num_entries; |
| 89 | uint32_t reserved0; |
| 90 | uint32_t reserved1; |
| 91 | }; |
| 92 | |
| 93 | struct smsm_state_cb_info { |
| 94 | struct list_head cb_list; |
| 95 | uint32_t mask; |
| 96 | void *data; |
| 97 | void (*notify)(void *data, uint32_t old_state, uint32_t new_state); |
| 98 | }; |
| 99 | |
| 100 | struct smsm_state_info { |
| 101 | struct list_head callbacks; |
| 102 | uint32_t last_value; |
| 103 | }; |
| 104 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 105 | struct interrupt_config_item { |
| 106 | /* must be initialized */ |
| 107 | irqreturn_t (*irq_handler)(int req, void *data); |
| 108 | /* outgoing interrupt config (set from platform data) */ |
| 109 | uint32_t out_bit_pos; |
| 110 | void __iomem *out_base; |
| 111 | uint32_t out_offset; |
| 112 | }; |
| 113 | |
| 114 | struct interrupt_config { |
| 115 | struct interrupt_config_item smd; |
| 116 | struct interrupt_config_item smsm; |
| 117 | }; |
| 118 | |
| 119 | static irqreturn_t smd_modem_irq_handler(int irq, void *data); |
| 120 | static irqreturn_t smd_dsp_irq_handler(int irq, void *data); |
| 121 | static irqreturn_t smd_dsps_irq_handler(int irq, void *data); |
| 122 | static irqreturn_t smd_wcnss_irq_handler(int irq, void *data); |
| 123 | static irqreturn_t smsm_irq_handler(int irq, void *data); |
| 124 | |
| 125 | static struct interrupt_config private_intr_config[NUM_SMD_SUBSYSTEMS] = { |
| 126 | [SMD_MODEM] = { |
| 127 | .smd.irq_handler = smd_modem_irq_handler, |
| 128 | .smsm.irq_handler = smsm_irq_handler, |
| 129 | }, |
| 130 | [SMD_Q6] = { |
| 131 | .smd.irq_handler = smd_dsp_irq_handler, |
| 132 | .smsm.irq_handler = smsm_irq_handler, |
| 133 | }, |
| 134 | [SMD_DSPS] = { |
| 135 | .smd.irq_handler = smd_dsps_irq_handler, |
| 136 | .smsm.irq_handler = smsm_irq_handler, |
| 137 | }, |
| 138 | [SMD_WCNSS] = { |
| 139 | .smd.irq_handler = smd_wcnss_irq_handler, |
| 140 | .smsm.irq_handler = smsm_irq_handler, |
| 141 | }, |
| 142 | }; |
| 143 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 144 | #define SMSM_STATE_ADDR(entry) (smsm_info.state + entry) |
| 145 | #define SMSM_INTR_MASK_ADDR(entry, host) (smsm_info.intr_mask + \ |
| 146 | entry * SMSM_NUM_HOSTS + host) |
| 147 | #define SMSM_INTR_MUX_ADDR(entry) (smsm_info.intr_mux + entry) |
| 148 | |
| 149 | /* Internal definitions which are not exported in some targets */ |
| 150 | enum { |
| 151 | SMSM_APPS_DEM_I = 3, |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | static int msm_smd_debug_mask; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 155 | module_param_named(debug_mask, msm_smd_debug_mask, |
| 156 | int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 157 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 158 | #if defined(CONFIG_MSM_SMD_DEBUG) |
| 159 | #define SMD_DBG(x...) do { \ |
| 160 | if (msm_smd_debug_mask & MSM_SMD_DEBUG) \ |
| 161 | printk(KERN_DEBUG x); \ |
| 162 | } while (0) |
| 163 | |
| 164 | #define SMSM_DBG(x...) do { \ |
| 165 | if (msm_smd_debug_mask & MSM_SMSM_DEBUG) \ |
| 166 | printk(KERN_DEBUG x); \ |
| 167 | } while (0) |
| 168 | |
| 169 | #define SMD_INFO(x...) do { \ |
| 170 | if (msm_smd_debug_mask & MSM_SMD_INFO) \ |
| 171 | printk(KERN_INFO x); \ |
| 172 | } while (0) |
| 173 | |
| 174 | #define SMSM_INFO(x...) do { \ |
| 175 | if (msm_smd_debug_mask & MSM_SMSM_INFO) \ |
| 176 | printk(KERN_INFO x); \ |
| 177 | } while (0) |
| 178 | #else |
| 179 | #define SMD_DBG(x...) do { } while (0) |
| 180 | #define SMSM_DBG(x...) do { } while (0) |
| 181 | #define SMD_INFO(x...) do { } while (0) |
| 182 | #define SMSM_INFO(x...) do { } while (0) |
| 183 | #endif |
| 184 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 185 | static unsigned last_heap_free = 0xffffffff; |
| 186 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 187 | static inline void smd_write_intr(unsigned int val, |
| 188 | const void __iomem *addr); |
| 189 | |
| 190 | #if defined(CONFIG_ARCH_MSM7X30) |
| 191 | #define MSM_TRIG_A2M_SMD_INT \ |
| 192 | (smd_write_intr(1 << 0, MSM_GCC_BASE + 0x8)) |
| 193 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 194 | (smd_write_intr(1 << 8, MSM_GCC_BASE + 0x8)) |
| 195 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 196 | (smd_write_intr(1 << 5, MSM_GCC_BASE + 0x8)) |
| 197 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 198 | (smd_write_intr(1 << 8, MSM_GCC_BASE + 0x8)) |
| 199 | #define MSM_TRIG_A2DSPS_SMD_INT |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 200 | #define MSM_TRIG_A2DSPS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 201 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 202 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
| 203 | #elif defined(CONFIG_ARCH_MSM8X60) |
| 204 | #define MSM_TRIG_A2M_SMD_INT \ |
| 205 | (smd_write_intr(1 << 3, MSM_GCC_BASE + 0x8)) |
| 206 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 207 | (smd_write_intr(1 << 15, MSM_GCC_BASE + 0x8)) |
| 208 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 209 | (smd_write_intr(1 << 4, MSM_GCC_BASE + 0x8)) |
| 210 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 211 | (smd_write_intr(1 << 14, MSM_GCC_BASE + 0x8)) |
| 212 | #define MSM_TRIG_A2DSPS_SMD_INT \ |
| 213 | (smd_write_intr(1, MSM_SIC_NON_SECURE_BASE + 0x4080)) |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 214 | #define MSM_TRIG_A2DSPS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 215 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 216 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
Stepan Moskovchenko | 0dd0eba | 2011-10-20 18:20:59 -0700 | [diff] [blame] | 217 | #elif defined(CONFIG_ARCH_MSM8960) || defined(CONFIG_ARCH_MSM8930) || \ |
| 218 | defined(CONFIG_ARCH_APQ8064) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 219 | #define MSM_TRIG_A2M_SMD_INT \ |
| 220 | (smd_write_intr(1 << 3, MSM_APCS_GCC_BASE + 0x8)) |
| 221 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 222 | (smd_write_intr(1 << 15, MSM_APCS_GCC_BASE + 0x8)) |
| 223 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 224 | (smd_write_intr(1 << 4, MSM_APCS_GCC_BASE + 0x8)) |
| 225 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 226 | (smd_write_intr(1 << 14, MSM_APCS_GCC_BASE + 0x8)) |
| 227 | #define MSM_TRIG_A2DSPS_SMD_INT \ |
| 228 | (smd_write_intr(1, MSM_SIC_NON_SECURE_BASE + 0x4080)) |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 229 | #define MSM_TRIG_A2DSPS_SMSM_INT \ |
| 230 | (smd_write_intr(1, MSM_SIC_NON_SECURE_BASE + 0x4094)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 231 | #define MSM_TRIG_A2WCNSS_SMD_INT \ |
| 232 | (smd_write_intr(1 << 25, MSM_APCS_GCC_BASE + 0x8)) |
| 233 | #define MSM_TRIG_A2WCNSS_SMSM_INT \ |
| 234 | (smd_write_intr(1 << 23, MSM_APCS_GCC_BASE + 0x8)) |
Jeff Hugo | 56b933a | 2011-09-28 14:42:05 -0600 | [diff] [blame] | 235 | #elif defined(CONFIG_ARCH_MSM9615) |
| 236 | #define MSM_TRIG_A2M_SMD_INT \ |
| 237 | (smd_write_intr(1 << 3, MSM_APCS_GCC_BASE + 0x8)) |
| 238 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 239 | (smd_write_intr(1 << 15, MSM_APCS_GCC_BASE + 0x8)) |
| 240 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 241 | (smd_write_intr(1 << 4, MSM_APCS_GCC_BASE + 0x8)) |
| 242 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 243 | (smd_write_intr(1 << 14, MSM_APCS_GCC_BASE + 0x8)) |
| 244 | #define MSM_TRIG_A2DSPS_SMD_INT |
| 245 | #define MSM_TRIG_A2DSPS_SMSM_INT |
| 246 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 247 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 248 | #elif defined(CONFIG_ARCH_FSM9XXX) |
| 249 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 250 | (smd_write_intr(1 << 10, MSM_GCC_BASE + 0x8)) |
| 251 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 252 | (smd_write_intr(1 << 10, MSM_GCC_BASE + 0x8)) |
| 253 | #define MSM_TRIG_A2M_SMD_INT \ |
| 254 | (smd_write_intr(1 << 0, MSM_GCC_BASE + 0x8)) |
| 255 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 256 | (smd_write_intr(1 << 5, MSM_GCC_BASE + 0x8)) |
| 257 | #define MSM_TRIG_A2DSPS_SMD_INT |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 258 | #define MSM_TRIG_A2DSPS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 259 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 260 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
| 261 | #else |
| 262 | #define MSM_TRIG_A2M_SMD_INT \ |
| 263 | (smd_write_intr(1, MSM_CSR_BASE + 0x400 + (0) * 4)) |
| 264 | #define MSM_TRIG_A2Q6_SMD_INT \ |
| 265 | (smd_write_intr(1, MSM_CSR_BASE + 0x400 + (8) * 4)) |
| 266 | #define MSM_TRIG_A2M_SMSM_INT \ |
| 267 | (smd_write_intr(1, MSM_CSR_BASE + 0x400 + (5) * 4)) |
| 268 | #define MSM_TRIG_A2Q6_SMSM_INT \ |
| 269 | (smd_write_intr(1, MSM_CSR_BASE + 0x400 + (8) * 4)) |
| 270 | #define MSM_TRIG_A2DSPS_SMD_INT |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 271 | #define MSM_TRIG_A2DSPS_SMSM_INT |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 272 | #define MSM_TRIG_A2WCNSS_SMD_INT |
| 273 | #define MSM_TRIG_A2WCNSS_SMSM_INT |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 274 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 275 | |
Jeff Hugo | ee40b15 | 2012-02-09 17:39:47 -0700 | [diff] [blame^] | 276 | /* |
| 277 | * stub out legacy macros if they are not being used so that the legacy |
| 278 | * code compiles even though it is not used |
| 279 | * |
| 280 | * these definitions should not be used in active code and will cause |
| 281 | * an early failure |
| 282 | */ |
| 283 | #ifndef INT_A9_M2A_0 |
| 284 | #define INT_A9_M2A_0 -1 |
| 285 | #endif |
| 286 | #ifndef INT_A9_M2A_5 |
| 287 | #define INT_A9_M2A_5 -1 |
| 288 | #endif |
| 289 | #ifndef INT_ADSP_A11 |
| 290 | #define INT_ADSP_A11 -1 |
| 291 | #endif |
| 292 | #ifndef INT_ADSP_A11_SMSM |
| 293 | #define INT_ADSP_A11_SMSM -1 |
| 294 | #endif |
| 295 | #ifndef INT_DSPS_A11 |
| 296 | #define INT_DSPS_A11 -1 |
| 297 | #endif |
| 298 | #ifndef INT_DSPS_A11_SMSM |
| 299 | #define INT_DSPS_A11_SMSM -1 |
| 300 | #endif |
| 301 | #ifndef INT_WCNSS_A11 |
| 302 | #define INT_WCNSS_A11 -1 |
| 303 | #endif |
| 304 | #ifndef INT_WCNSS_A11_SMSM |
| 305 | #define INT_WCNSS_A11_SMSM -1 |
| 306 | #endif |
| 307 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 308 | #define SMD_LOOPBACK_CID 100 |
| 309 | |
Eric Holmberg | f6d7d1a | 2011-09-23 18:31:04 -0600 | [diff] [blame] | 310 | #define SMEM_SPINLOCK_SMEM_ALLOC "S:3" |
| 311 | static remote_spinlock_t remote_spinlock; |
| 312 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 313 | static LIST_HEAD(smd_ch_list_loopback); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 314 | static void smd_fake_irq_handler(unsigned long arg); |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 315 | static void smsm_cb_snapshot(void); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 316 | |
| 317 | static void notify_smsm_cb_clients_worker(struct work_struct *work); |
| 318 | static DECLARE_WORK(smsm_cb_work, notify_smsm_cb_clients_worker); |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 319 | static DEFINE_MUTEX(smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 320 | static struct smsm_state_info *smsm_states; |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 321 | static int spinlocks_initialized; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 322 | |
| 323 | static inline void smd_write_intr(unsigned int val, |
| 324 | const void __iomem *addr) |
| 325 | { |
| 326 | wmb(); |
| 327 | __raw_writel(val, addr); |
| 328 | } |
| 329 | |
| 330 | #ifdef CONFIG_WCNSS |
| 331 | static inline void wakeup_v1_riva(void) |
| 332 | { |
| 333 | /* |
| 334 | * workaround hack for RIVA v1 hardware bug |
| 335 | * trigger GPIO 40 to wake up RIVA from power collaspe |
| 336 | * not to be sent to customers |
| 337 | */ |
Jeff Hugo | afb8c4a | 2011-10-27 15:57:27 -0600 | [diff] [blame] | 338 | if (SOCINFO_VERSION_MAJOR(socinfo_get_version()) == 1) { |
| 339 | __raw_writel(0x0, MSM_TLMM_BASE + 0x1284); |
| 340 | __raw_writel(0x2, MSM_TLMM_BASE + 0x1284); |
| 341 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 342 | /* end workaround */ |
| 343 | } |
| 344 | #else |
| 345 | static inline void wakeup_v1_riva(void) {} |
| 346 | #endif |
| 347 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 348 | static inline void notify_modem_smd(void) |
| 349 | { |
| 350 | static const struct interrupt_config_item *intr |
| 351 | = &private_intr_config[SMD_MODEM].smd; |
| 352 | if (intr->out_base) |
| 353 | smd_write_intr(intr->out_bit_pos, |
| 354 | intr->out_base + intr->out_offset); |
| 355 | else |
| 356 | MSM_TRIG_A2M_SMD_INT; |
| 357 | } |
| 358 | |
| 359 | static inline void notify_dsp_smd(void) |
| 360 | { |
| 361 | static const struct interrupt_config_item *intr |
| 362 | = &private_intr_config[SMD_Q6].smd; |
| 363 | if (intr->out_base) |
| 364 | smd_write_intr(intr->out_bit_pos, |
| 365 | intr->out_base + intr->out_offset); |
| 366 | else |
| 367 | MSM_TRIG_A2Q6_SMD_INT; |
| 368 | } |
| 369 | |
| 370 | static inline void notify_dsps_smd(void) |
| 371 | { |
| 372 | static const struct interrupt_config_item *intr |
| 373 | = &private_intr_config[SMD_DSPS].smd; |
| 374 | if (intr->out_base) |
| 375 | smd_write_intr(intr->out_bit_pos, |
| 376 | intr->out_base + intr->out_offset); |
| 377 | else |
| 378 | MSM_TRIG_A2DSPS_SMD_INT; |
| 379 | } |
| 380 | |
| 381 | static inline void notify_wcnss_smd(void) |
| 382 | { |
| 383 | static const struct interrupt_config_item *intr |
| 384 | = &private_intr_config[SMD_WCNSS].smd; |
| 385 | wakeup_v1_riva(); |
| 386 | |
| 387 | if (intr->out_base) |
| 388 | smd_write_intr(intr->out_bit_pos, |
| 389 | intr->out_base + intr->out_offset); |
| 390 | else |
| 391 | MSM_TRIG_A2WCNSS_SMD_INT; |
| 392 | } |
| 393 | |
| 394 | static inline void notify_modem_smsm(void) |
| 395 | { |
| 396 | static const struct interrupt_config_item *intr |
| 397 | = &private_intr_config[SMD_MODEM].smsm; |
| 398 | if (intr->out_base) |
| 399 | smd_write_intr(intr->out_bit_pos, |
| 400 | intr->out_base + intr->out_offset); |
| 401 | else |
| 402 | MSM_TRIG_A2M_SMSM_INT; |
| 403 | } |
| 404 | |
| 405 | static inline void notify_dsp_smsm(void) |
| 406 | { |
| 407 | static const struct interrupt_config_item *intr |
| 408 | = &private_intr_config[SMD_Q6].smsm; |
| 409 | if (intr->out_base) |
| 410 | smd_write_intr(intr->out_bit_pos, |
| 411 | intr->out_base + intr->out_offset); |
| 412 | else |
| 413 | MSM_TRIG_A2Q6_SMSM_INT; |
| 414 | } |
| 415 | |
| 416 | static inline void notify_dsps_smsm(void) |
| 417 | { |
| 418 | static const struct interrupt_config_item *intr |
| 419 | = &private_intr_config[SMD_DSPS].smsm; |
| 420 | if (intr->out_base) |
| 421 | smd_write_intr(intr->out_bit_pos, |
| 422 | intr->out_base + intr->out_offset); |
| 423 | else |
| 424 | MSM_TRIG_A2DSPS_SMSM_INT; |
| 425 | } |
| 426 | |
| 427 | static inline void notify_wcnss_smsm(void) |
| 428 | { |
| 429 | static const struct interrupt_config_item *intr |
| 430 | = &private_intr_config[SMD_WCNSS].smsm; |
| 431 | wakeup_v1_riva(); |
| 432 | |
| 433 | if (intr->out_base) |
| 434 | smd_write_intr(intr->out_bit_pos, |
| 435 | intr->out_base + intr->out_offset); |
| 436 | else |
| 437 | MSM_TRIG_A2WCNSS_SMSM_INT; |
| 438 | } |
| 439 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 440 | static void notify_other_smsm(uint32_t smsm_entry, uint32_t notify_mask) |
| 441 | { |
| 442 | /* older protocol don't use smsm_intr_mask, |
| 443 | but still communicates with modem */ |
| 444 | if (!smsm_info.intr_mask || |
| 445 | (__raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_MODEM)) |
| 446 | & notify_mask)) |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 447 | notify_modem_smsm(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 448 | |
| 449 | if (smsm_info.intr_mask && |
| 450 | (__raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_Q6)) |
| 451 | & notify_mask)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 452 | uint32_t mux_val; |
| 453 | |
Eric Holmberg | 6282c5d | 2011-10-27 17:30:57 -0600 | [diff] [blame] | 454 | if (cpu_is_qsd8x50() && smsm_info.intr_mux) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 455 | mux_val = __raw_readl( |
| 456 | SMSM_INTR_MUX_ADDR(SMEM_APPS_Q6_SMSM)); |
| 457 | mux_val++; |
| 458 | __raw_writel(mux_val, |
| 459 | SMSM_INTR_MUX_ADDR(SMEM_APPS_Q6_SMSM)); |
| 460 | } |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 461 | notify_dsp_smsm(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | if (smsm_info.intr_mask && |
| 465 | (__raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_WCNSS)) |
| 466 | & notify_mask)) { |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 467 | notify_wcnss_smsm(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 470 | if (smsm_info.intr_mask && |
| 471 | (__raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_DSPS)) |
| 472 | & notify_mask)) { |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 473 | notify_dsps_smsm(); |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 474 | } |
| 475 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 476 | smsm_cb_snapshot(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 479 | void smd_diag(void) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 480 | { |
| 481 | char *x; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 482 | int size; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 483 | |
| 484 | x = smem_find(ID_DIAG_ERR_MSG, SZ_DIAG_ERR_MSG); |
| 485 | if (x != 0) { |
| 486 | x[SZ_DIAG_ERR_MSG - 1] = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 487 | SMD_INFO("smem: DIAG '%s'\n", x); |
| 488 | } |
| 489 | |
| 490 | x = smem_get_entry(SMEM_ERR_CRASH_LOG, &size); |
| 491 | if (x != 0) { |
| 492 | x[size - 1] = 0; |
| 493 | pr_err("smem: CRASH LOG\n'%s'\n", x); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 497 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 498 | static void handle_modem_crash(void) |
| 499 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 500 | pr_err("MODEM/AMSS has CRASHED\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 501 | smd_diag(); |
| 502 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 503 | /* hard reboot if possible FIXME |
| 504 | if (msm_reset_hook) |
| 505 | msm_reset_hook(); |
| 506 | */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 507 | |
| 508 | /* in this case the modem or watchdog should reboot us */ |
| 509 | for (;;) |
| 510 | ; |
| 511 | } |
| 512 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | int smsm_check_for_modem_crash(void) |
Arve Hjønnevåg | 2837941 | 2009-05-20 16:52:36 -0700 | [diff] [blame] | 514 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 515 | /* if the modem's not ready yet, we have to hope for the best */ |
| 516 | if (!smsm_info.state) |
| 517 | return 0; |
Arve Hjønnevåg | 2837941 | 2009-05-20 16:52:36 -0700 | [diff] [blame] | 518 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 519 | if (__raw_readl(SMSM_STATE_ADDR(SMSM_MODEM_STATE)) & SMSM_RESET) { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 520 | handle_modem_crash(); |
| 521 | return -1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 522 | } |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 523 | return 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 524 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 525 | EXPORT_SYMBOL(smsm_check_for_modem_crash); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 526 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 527 | /* the spinlock is used to synchronize between the |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 528 | * irq handler and code that mutates the channel |
| 529 | * list or fiddles with channel state |
| 530 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 531 | static DEFINE_SPINLOCK(smd_lock); |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 532 | DEFINE_SPINLOCK(smem_lock); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 533 | |
| 534 | /* the mutex is used during open() and close() |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 535 | * operations to avoid races while creating or |
| 536 | * destroying smd_channel structures |
| 537 | */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 538 | static DEFINE_MUTEX(smd_creation_mutex); |
| 539 | |
| 540 | static int smd_initialized; |
| 541 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 542 | struct smd_shared_v1 { |
| 543 | struct smd_half_channel ch0; |
| 544 | unsigned char data0[SMD_BUF_SIZE]; |
| 545 | struct smd_half_channel ch1; |
| 546 | unsigned char data1[SMD_BUF_SIZE]; |
| 547 | }; |
| 548 | |
| 549 | struct smd_shared_v2 { |
| 550 | struct smd_half_channel ch0; |
| 551 | struct smd_half_channel ch1; |
| 552 | }; |
| 553 | |
| 554 | struct smd_channel { |
| 555 | volatile struct smd_half_channel *send; |
| 556 | volatile struct smd_half_channel *recv; |
| 557 | unsigned char *send_data; |
| 558 | unsigned char *recv_data; |
| 559 | unsigned fifo_size; |
| 560 | unsigned fifo_mask; |
| 561 | struct list_head ch_list; |
| 562 | |
| 563 | unsigned current_packet; |
| 564 | unsigned n; |
| 565 | void *priv; |
| 566 | void (*notify)(void *priv, unsigned flags); |
| 567 | |
| 568 | int (*read)(smd_channel_t *ch, void *data, int len, int user_buf); |
| 569 | int (*write)(smd_channel_t *ch, const void *data, int len, |
| 570 | int user_buf); |
| 571 | int (*read_avail)(smd_channel_t *ch); |
| 572 | int (*write_avail)(smd_channel_t *ch); |
| 573 | int (*read_from_cb)(smd_channel_t *ch, void *data, int len, |
| 574 | int user_buf); |
| 575 | |
| 576 | void (*update_state)(smd_channel_t *ch); |
| 577 | unsigned last_state; |
| 578 | void (*notify_other_cpu)(void); |
| 579 | |
| 580 | char name[20]; |
| 581 | struct platform_device pdev; |
| 582 | unsigned type; |
| 583 | |
| 584 | int pending_pkt_sz; |
| 585 | |
| 586 | char is_pkt_ch; |
| 587 | }; |
| 588 | |
| 589 | struct edge_to_pid { |
| 590 | uint32_t local_pid; |
| 591 | uint32_t remote_pid; |
| 592 | }; |
| 593 | |
| 594 | /** |
| 595 | * Maps edge type to local and remote processor ID's. |
| 596 | */ |
| 597 | static struct edge_to_pid edge_to_pids[] = { |
| 598 | [SMD_APPS_MODEM] = {SMSM_APPS, SMSM_MODEM}, |
| 599 | [SMD_APPS_QDSP] = {SMSM_APPS, SMSM_Q6}, |
| 600 | [SMD_MODEM_QDSP] = {SMSM_MODEM, SMSM_Q6}, |
| 601 | [SMD_APPS_DSPS] = {SMSM_APPS, SMSM_DSPS}, |
| 602 | [SMD_MODEM_DSPS] = {SMSM_MODEM, SMSM_DSPS}, |
| 603 | [SMD_QDSP_DSPS] = {SMSM_Q6, SMSM_DSPS}, |
| 604 | [SMD_APPS_WCNSS] = {SMSM_APPS, SMSM_WCNSS}, |
| 605 | [SMD_MODEM_WCNSS] = {SMSM_MODEM, SMSM_WCNSS}, |
| 606 | [SMD_QDSP_WCNSS] = {SMSM_Q6, SMSM_WCNSS}, |
| 607 | [SMD_DSPS_WCNSS] = {SMSM_DSPS, SMSM_WCNSS}, |
Eric Holmberg | 7dfd197 | 2011-09-09 16:07:57 -0600 | [diff] [blame] | 608 | [SMD_APPS_Q6FW] = {SMSM_APPS, SMD_MODEM_Q6_FW}, |
| 609 | [SMD_MODEM_Q6FW] = {SMSM_MODEM, SMD_MODEM_Q6_FW}, |
| 610 | [SMD_QDSP_Q6FW] = {SMSM_Q6, SMD_MODEM_Q6_FW}, |
| 611 | [SMD_DSPS_Q6FW] = {SMSM_DSPS, SMD_MODEM_Q6_FW}, |
| 612 | [SMD_WCNSS_Q6FW] = {SMSM_WCNSS, SMD_MODEM_Q6_FW}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 613 | }; |
| 614 | |
| 615 | struct restart_notifier_block { |
| 616 | unsigned processor; |
| 617 | char *name; |
| 618 | struct notifier_block nb; |
| 619 | }; |
| 620 | |
| 621 | static struct platform_device loopback_tty_pdev = {.name = "LOOPBACK_TTY"}; |
| 622 | |
| 623 | static LIST_HEAD(smd_ch_closed_list); |
| 624 | static LIST_HEAD(smd_ch_closing_list); |
| 625 | static LIST_HEAD(smd_ch_to_close_list); |
| 626 | static LIST_HEAD(smd_ch_list_modem); |
| 627 | static LIST_HEAD(smd_ch_list_dsp); |
| 628 | static LIST_HEAD(smd_ch_list_dsps); |
| 629 | static LIST_HEAD(smd_ch_list_wcnss); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 630 | |
| 631 | static unsigned char smd_ch_allocated[64]; |
| 632 | static struct work_struct probe_work; |
| 633 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 634 | static void finalize_channel_close_fn(struct work_struct *work); |
| 635 | static DECLARE_WORK(finalize_channel_close_work, finalize_channel_close_fn); |
| 636 | static struct workqueue_struct *channel_close_wq; |
| 637 | |
| 638 | static int smd_alloc_channel(struct smd_alloc_elm *alloc_elm); |
| 639 | |
| 640 | /* on smp systems, the probe might get called from multiple cores, |
| 641 | hence use a lock */ |
| 642 | static DEFINE_MUTEX(smd_probe_lock); |
| 643 | |
| 644 | static void smd_channel_probe_worker(struct work_struct *work) |
| 645 | { |
| 646 | struct smd_alloc_elm *shared; |
| 647 | unsigned n; |
| 648 | uint32_t type; |
| 649 | |
| 650 | shared = smem_find(ID_CH_ALLOC_TBL, sizeof(*shared) * 64); |
| 651 | |
| 652 | if (!shared) { |
| 653 | pr_err("%s: allocation table not initialized\n", __func__); |
| 654 | return; |
| 655 | } |
| 656 | |
| 657 | mutex_lock(&smd_probe_lock); |
| 658 | for (n = 0; n < 64; n++) { |
| 659 | if (smd_ch_allocated[n]) |
| 660 | continue; |
| 661 | |
| 662 | /* channel should be allocated only if APPS |
| 663 | processor is involved */ |
| 664 | type = SMD_CHANNEL_TYPE(shared[n].type); |
| 665 | if ((type != SMD_APPS_MODEM) && (type != SMD_APPS_QDSP) && |
| 666 | (type != SMD_APPS_DSPS) && (type != SMD_APPS_WCNSS)) |
| 667 | continue; |
| 668 | if (!shared[n].ref_count) |
| 669 | continue; |
| 670 | if (!shared[n].name[0]) |
| 671 | continue; |
| 672 | |
| 673 | if (!smd_alloc_channel(&shared[n])) |
| 674 | smd_ch_allocated[n] = 1; |
| 675 | else |
| 676 | SMD_INFO("Probe skipping ch %d, not allocated\n", n); |
| 677 | } |
| 678 | mutex_unlock(&smd_probe_lock); |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * Lookup processor ID and determine if it belongs to the proved edge |
| 683 | * type. |
| 684 | * |
| 685 | * @shared2: Pointer to v2 shared channel structure |
| 686 | * @type: Edge type |
| 687 | * @pid: Processor ID of processor on edge |
| 688 | * @local_ch: Channel that belongs to processor @pid |
| 689 | * @remote_ch: Other side of edge contained @pid |
| 690 | * |
| 691 | * Returns 0 for not on edge, 1 for found on edge |
| 692 | */ |
| 693 | static int pid_is_on_edge(struct smd_shared_v2 *shared2, |
| 694 | uint32_t type, uint32_t pid, |
| 695 | struct smd_half_channel **local_ch, |
| 696 | struct smd_half_channel **remote_ch |
| 697 | ) |
| 698 | { |
| 699 | int ret = 0; |
| 700 | struct edge_to_pid *edge; |
| 701 | |
| 702 | *local_ch = 0; |
| 703 | *remote_ch = 0; |
| 704 | |
| 705 | if (!shared2 || (type >= ARRAY_SIZE(edge_to_pids))) |
| 706 | return 0; |
| 707 | |
| 708 | edge = &edge_to_pids[type]; |
| 709 | if (edge->local_pid != edge->remote_pid) { |
| 710 | if (pid == edge->local_pid) { |
| 711 | *local_ch = &shared2->ch0; |
| 712 | *remote_ch = &shared2->ch1; |
| 713 | ret = 1; |
| 714 | } else if (pid == edge->remote_pid) { |
| 715 | *local_ch = &shared2->ch1; |
| 716 | *remote_ch = &shared2->ch0; |
| 717 | ret = 1; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | return ret; |
| 722 | } |
| 723 | |
Eric Holmberg | 2a563c3 | 2011-10-05 14:51:43 -0600 | [diff] [blame] | 724 | static void smd_reset_edge(struct smd_half_channel *ch, unsigned new_state) |
| 725 | { |
| 726 | if (ch->state != SMD_SS_CLOSED) { |
| 727 | ch->state = new_state; |
| 728 | ch->fDSR = 0; |
| 729 | ch->fCTS = 0; |
| 730 | ch->fCD = 0; |
| 731 | ch->fSTATE = 1; |
| 732 | } |
| 733 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 734 | |
| 735 | static void smd_channel_reset_state(struct smd_alloc_elm *shared, |
| 736 | unsigned new_state, unsigned pid) |
| 737 | { |
| 738 | unsigned n; |
| 739 | struct smd_shared_v2 *shared2; |
| 740 | uint32_t type; |
| 741 | struct smd_half_channel *local_ch; |
| 742 | struct smd_half_channel *remote_ch; |
| 743 | |
| 744 | for (n = 0; n < SMD_CHANNELS; n++) { |
| 745 | if (!shared[n].ref_count) |
| 746 | continue; |
| 747 | if (!shared[n].name[0]) |
| 748 | continue; |
| 749 | |
| 750 | type = SMD_CHANNEL_TYPE(shared[n].type); |
| 751 | shared2 = smem_alloc(SMEM_SMD_BASE_ID + n, sizeof(*shared2)); |
| 752 | if (!shared2) |
| 753 | continue; |
| 754 | |
Eric Holmberg | 2a563c3 | 2011-10-05 14:51:43 -0600 | [diff] [blame] | 755 | if (pid_is_on_edge(shared2, type, pid, &local_ch, &remote_ch)) |
| 756 | smd_reset_edge(local_ch, new_state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 757 | |
Eric Holmberg | 2a563c3 | 2011-10-05 14:51:43 -0600 | [diff] [blame] | 758 | /* |
| 759 | * ModemFW is in the same subsystem as ModemSW, but has |
| 760 | * separate SMD edges that need to be reset. |
| 761 | */ |
| 762 | if (pid == SMSM_MODEM && |
| 763 | pid_is_on_edge(shared2, type, SMD_MODEM_Q6_FW, |
| 764 | &local_ch, &remote_ch)) |
| 765 | smd_reset_edge(local_ch, new_state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
| 769 | |
| 770 | void smd_channel_reset(uint32_t restart_pid) |
| 771 | { |
| 772 | struct smd_alloc_elm *shared; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 773 | unsigned long flags; |
| 774 | |
| 775 | SMD_DBG("%s: starting reset\n", __func__); |
| 776 | shared = smem_find(ID_CH_ALLOC_TBL, sizeof(*shared) * 64); |
| 777 | if (!shared) { |
| 778 | pr_err("%s: allocation table not initialized\n", __func__); |
| 779 | return; |
| 780 | } |
| 781 | |
Eric Holmberg | f6d7d1a | 2011-09-23 18:31:04 -0600 | [diff] [blame] | 782 | /* release any held spinlocks */ |
| 783 | remote_spin_release(&remote_spinlock, restart_pid); |
| 784 | remote_spin_release_all(restart_pid); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 785 | |
| 786 | /* reset SMSM entry */ |
| 787 | if (smsm_info.state) { |
| 788 | writel_relaxed(0, SMSM_STATE_ADDR(restart_pid)); |
| 789 | |
Eric Holmberg | 351a63c | 2011-12-02 17:49:43 -0700 | [diff] [blame] | 790 | /* restart SMSM init handshake */ |
| 791 | if (restart_pid == SMSM_MODEM) { |
| 792 | smsm_change_state(SMSM_APPS_STATE, |
Eric Holmberg | 6b2f80e | 2012-01-09 12:22:52 -0700 | [diff] [blame] | 793 | SMSM_INIT | SMSM_SMD_LOOPBACK | SMSM_RESET, |
| 794 | 0); |
Eric Holmberg | 351a63c | 2011-12-02 17:49:43 -0700 | [diff] [blame] | 795 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 796 | |
| 797 | /* notify SMSM processors */ |
| 798 | smsm_irq_handler(0, 0); |
| 799 | MSM_TRIG_A2M_SMSM_INT; |
| 800 | MSM_TRIG_A2Q6_SMSM_INT; |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 801 | MSM_TRIG_A2DSPS_SMSM_INT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | /* change all remote states to CLOSING */ |
| 805 | mutex_lock(&smd_probe_lock); |
| 806 | spin_lock_irqsave(&smd_lock, flags); |
| 807 | smd_channel_reset_state(shared, SMD_SS_CLOSING, restart_pid); |
| 808 | spin_unlock_irqrestore(&smd_lock, flags); |
| 809 | mutex_unlock(&smd_probe_lock); |
| 810 | |
| 811 | /* notify SMD processors */ |
| 812 | mb(); |
| 813 | smd_fake_irq_handler(0); |
| 814 | notify_modem_smd(); |
| 815 | notify_dsp_smd(); |
| 816 | notify_dsps_smd(); |
| 817 | notify_wcnss_smd(); |
| 818 | |
| 819 | /* change all remote states to CLOSED */ |
| 820 | mutex_lock(&smd_probe_lock); |
| 821 | spin_lock_irqsave(&smd_lock, flags); |
| 822 | smd_channel_reset_state(shared, SMD_SS_CLOSED, restart_pid); |
| 823 | spin_unlock_irqrestore(&smd_lock, flags); |
| 824 | mutex_unlock(&smd_probe_lock); |
| 825 | |
| 826 | /* notify SMD processors */ |
| 827 | mb(); |
| 828 | smd_fake_irq_handler(0); |
| 829 | notify_modem_smd(); |
| 830 | notify_dsp_smd(); |
| 831 | notify_dsps_smd(); |
| 832 | notify_wcnss_smd(); |
| 833 | |
| 834 | SMD_DBG("%s: finished reset\n", __func__); |
| 835 | } |
| 836 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 837 | /* how many bytes are available for reading */ |
| 838 | static int smd_stream_read_avail(struct smd_channel *ch) |
| 839 | { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 840 | return (ch->recv->head - ch->recv->tail) & ch->fifo_mask; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /* how many bytes we are free to write */ |
| 844 | static int smd_stream_write_avail(struct smd_channel *ch) |
| 845 | { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 846 | return ch->fifo_mask - |
| 847 | ((ch->send->head - ch->send->tail) & ch->fifo_mask); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | static int smd_packet_read_avail(struct smd_channel *ch) |
| 851 | { |
| 852 | if (ch->current_packet) { |
| 853 | int n = smd_stream_read_avail(ch); |
| 854 | if (n > ch->current_packet) |
| 855 | n = ch->current_packet; |
| 856 | return n; |
| 857 | } else { |
| 858 | return 0; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | static int smd_packet_write_avail(struct smd_channel *ch) |
| 863 | { |
| 864 | int n = smd_stream_write_avail(ch); |
| 865 | return n > SMD_HEADER_SIZE ? n - SMD_HEADER_SIZE : 0; |
| 866 | } |
| 867 | |
| 868 | static int ch_is_open(struct smd_channel *ch) |
| 869 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 870 | return (ch->recv->state == SMD_SS_OPENED || |
| 871 | ch->recv->state == SMD_SS_FLUSHING) |
| 872 | && (ch->send->state == SMD_SS_OPENED); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | /* provide a pointer and length to readable data in the fifo */ |
| 876 | static unsigned ch_read_buffer(struct smd_channel *ch, void **ptr) |
| 877 | { |
| 878 | unsigned head = ch->recv->head; |
| 879 | unsigned tail = ch->recv->tail; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 880 | *ptr = (void *) (ch->recv_data + tail); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 881 | |
| 882 | if (tail <= head) |
| 883 | return head - tail; |
| 884 | else |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 885 | return ch->fifo_size - tail; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 888 | static int read_intr_blocked(struct smd_channel *ch) |
| 889 | { |
| 890 | return ch->recv->fBLOCKREADINTR; |
| 891 | } |
| 892 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 893 | /* advance the fifo read pointer after data from ch_read_buffer is consumed */ |
| 894 | static void ch_read_done(struct smd_channel *ch, unsigned count) |
| 895 | { |
| 896 | BUG_ON(count > smd_stream_read_avail(ch)); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 897 | ch->recv->tail = (ch->recv->tail + count) & ch->fifo_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 898 | wmb(); |
Haley Teng | 7632fba | 2009-10-12 10:38:10 -0700 | [diff] [blame] | 899 | ch->send->fTAIL = 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /* basic read interface to ch_read_{buffer,done} used |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 903 | * by smd_*_read() and update_packet_state() |
| 904 | * will read-and-discard if the _data pointer is null |
| 905 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 906 | static int ch_read(struct smd_channel *ch, void *_data, int len, int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 907 | { |
| 908 | void *ptr; |
| 909 | unsigned n; |
| 910 | unsigned char *data = _data; |
| 911 | int orig_len = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 912 | int r = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 913 | |
| 914 | while (len > 0) { |
| 915 | n = ch_read_buffer(ch, &ptr); |
| 916 | if (n == 0) |
| 917 | break; |
| 918 | |
| 919 | if (n > len) |
| 920 | n = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 921 | if (_data) { |
| 922 | if (user_buf) { |
| 923 | r = copy_to_user(data, ptr, n); |
| 924 | if (r > 0) { |
| 925 | pr_err("%s: " |
| 926 | "copy_to_user could not copy " |
| 927 | "%i bytes.\n", |
| 928 | __func__, |
| 929 | r); |
| 930 | } |
| 931 | } else |
| 932 | memcpy(data, ptr, n); |
| 933 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 934 | |
| 935 | data += n; |
| 936 | len -= n; |
| 937 | ch_read_done(ch, n); |
| 938 | } |
| 939 | |
| 940 | return orig_len - len; |
| 941 | } |
| 942 | |
| 943 | static void update_stream_state(struct smd_channel *ch) |
| 944 | { |
| 945 | /* streams have no special state requiring updating */ |
| 946 | } |
| 947 | |
| 948 | static void update_packet_state(struct smd_channel *ch) |
| 949 | { |
| 950 | unsigned hdr[5]; |
| 951 | int r; |
| 952 | |
| 953 | /* can't do anything if we're in the middle of a packet */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 954 | while (ch->current_packet == 0) { |
| 955 | /* discard 0 length packets if any */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 956 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 957 | /* don't bother unless we can get the full header */ |
| 958 | if (smd_stream_read_avail(ch) < SMD_HEADER_SIZE) |
| 959 | return; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 960 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 961 | r = ch_read(ch, hdr, SMD_HEADER_SIZE, 0); |
| 962 | BUG_ON(r != SMD_HEADER_SIZE); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 963 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 964 | ch->current_packet = hdr[0]; |
| 965 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /* provide a pointer and length to next free space in the fifo */ |
| 969 | static unsigned ch_write_buffer(struct smd_channel *ch, void **ptr) |
| 970 | { |
| 971 | unsigned head = ch->send->head; |
| 972 | unsigned tail = ch->send->tail; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 973 | *ptr = (void *) (ch->send_data + head); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 974 | |
| 975 | if (head < tail) { |
| 976 | return tail - head - 1; |
| 977 | } else { |
| 978 | if (tail == 0) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 979 | return ch->fifo_size - head - 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 980 | else |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 981 | return ch->fifo_size - head; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | |
| 985 | /* advace the fifo write pointer after freespace |
| 986 | * from ch_write_buffer is filled |
| 987 | */ |
| 988 | static void ch_write_done(struct smd_channel *ch, unsigned count) |
| 989 | { |
| 990 | BUG_ON(count > smd_stream_write_avail(ch)); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 991 | ch->send->head = (ch->send->head + count) & ch->fifo_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 992 | wmb(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 993 | ch->send->fHEAD = 1; |
| 994 | } |
| 995 | |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 996 | static void ch_set_state(struct smd_channel *ch, unsigned n) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 997 | { |
| 998 | if (n == SMD_SS_OPENED) { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 999 | ch->send->fDSR = 1; |
| 1000 | ch->send->fCTS = 1; |
| 1001 | ch->send->fCD = 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1002 | } else { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1003 | ch->send->fDSR = 0; |
| 1004 | ch->send->fCTS = 0; |
| 1005 | ch->send->fCD = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1006 | } |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1007 | ch->send->state = n; |
| 1008 | ch->send->fSTATE = 1; |
| 1009 | ch->notify_other_cpu(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | static void do_smd_probe(void) |
| 1013 | { |
| 1014 | struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE; |
| 1015 | if (shared->heap_info.free_offset != last_heap_free) { |
| 1016 | last_heap_free = shared->heap_info.free_offset; |
| 1017 | schedule_work(&probe_work); |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | static void smd_state_change(struct smd_channel *ch, |
| 1022 | unsigned last, unsigned next) |
| 1023 | { |
| 1024 | ch->last_state = next; |
| 1025 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1026 | SMD_INFO("SMD: ch %d %d -> %d\n", ch->n, last, next); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1027 | |
| 1028 | switch (next) { |
| 1029 | case SMD_SS_OPENING: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1030 | if (ch->send->state == SMD_SS_CLOSING || |
| 1031 | ch->send->state == SMD_SS_CLOSED) { |
| 1032 | ch->recv->tail = 0; |
| 1033 | ch->send->head = 0; |
| 1034 | ch->send->fBLOCKREADINTR = 0; |
| 1035 | ch_set_state(ch, SMD_SS_OPENING); |
| 1036 | } |
| 1037 | break; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1038 | case SMD_SS_OPENED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1039 | if (ch->send->state == SMD_SS_OPENING) { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1040 | ch_set_state(ch, SMD_SS_OPENED); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1041 | ch->notify(ch->priv, SMD_EVENT_OPEN); |
| 1042 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1043 | break; |
| 1044 | case SMD_SS_FLUSHING: |
| 1045 | case SMD_SS_RESET: |
| 1046 | /* we should force them to close? */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1047 | break; |
| 1048 | case SMD_SS_CLOSED: |
| 1049 | if (ch->send->state == SMD_SS_OPENED) { |
| 1050 | ch_set_state(ch, SMD_SS_CLOSING); |
| 1051 | ch->current_packet = 0; |
Eric Holmberg | ad4fa8d | 2011-11-11 16:55:13 -0700 | [diff] [blame] | 1052 | ch->pending_pkt_sz = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1053 | ch->notify(ch->priv, SMD_EVENT_CLOSE); |
| 1054 | } |
| 1055 | break; |
| 1056 | case SMD_SS_CLOSING: |
| 1057 | if (ch->send->state == SMD_SS_CLOSED) { |
| 1058 | list_move(&ch->ch_list, |
| 1059 | &smd_ch_to_close_list); |
| 1060 | queue_work(channel_close_wq, |
| 1061 | &finalize_channel_close_work); |
| 1062 | } |
| 1063 | break; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1064 | } |
| 1065 | } |
| 1066 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1067 | static void handle_smd_irq_closing_list(void) |
| 1068 | { |
| 1069 | unsigned long flags; |
| 1070 | struct smd_channel *ch; |
| 1071 | struct smd_channel *index; |
| 1072 | unsigned tmp; |
| 1073 | |
| 1074 | spin_lock_irqsave(&smd_lock, flags); |
| 1075 | list_for_each_entry_safe(ch, index, &smd_ch_closing_list, ch_list) { |
| 1076 | if (ch->recv->fSTATE) |
| 1077 | ch->recv->fSTATE = 0; |
| 1078 | tmp = ch->recv->state; |
| 1079 | if (tmp != ch->last_state) |
| 1080 | smd_state_change(ch, ch->last_state, tmp); |
| 1081 | } |
| 1082 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1083 | } |
| 1084 | |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1085 | static void handle_smd_irq(struct list_head *list, void (*notify)(void)) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1086 | { |
| 1087 | unsigned long flags; |
| 1088 | struct smd_channel *ch; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1089 | unsigned ch_flags; |
| 1090 | unsigned tmp; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1091 | unsigned char state_change; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1092 | |
| 1093 | spin_lock_irqsave(&smd_lock, flags); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1094 | list_for_each_entry(ch, list, ch_list) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1095 | state_change = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1096 | ch_flags = 0; |
| 1097 | if (ch_is_open(ch)) { |
| 1098 | if (ch->recv->fHEAD) { |
| 1099 | ch->recv->fHEAD = 0; |
| 1100 | ch_flags |= 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1101 | } |
| 1102 | if (ch->recv->fTAIL) { |
| 1103 | ch->recv->fTAIL = 0; |
| 1104 | ch_flags |= 2; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1105 | } |
| 1106 | if (ch->recv->fSTATE) { |
| 1107 | ch->recv->fSTATE = 0; |
| 1108 | ch_flags |= 4; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | tmp = ch->recv->state; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1112 | if (tmp != ch->last_state) { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1113 | smd_state_change(ch, ch->last_state, tmp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1114 | state_change = 1; |
| 1115 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1116 | if (ch_flags) { |
| 1117 | ch->update_state(ch); |
| 1118 | ch->notify(ch->priv, SMD_EVENT_DATA); |
| 1119 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1120 | if (ch_flags & 0x4 && !state_change) |
| 1121 | ch->notify(ch->priv, SMD_EVENT_STATUS); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1122 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1123 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1124 | do_smd_probe(); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1127 | static irqreturn_t smd_modem_irq_handler(int irq, void *data) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1128 | { |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1129 | handle_smd_irq(&smd_ch_list_modem, notify_modem_smd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1130 | handle_smd_irq_closing_list(); |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1131 | return IRQ_HANDLED; |
| 1132 | } |
| 1133 | |
| 1134 | static irqreturn_t smd_dsp_irq_handler(int irq, void *data) |
| 1135 | { |
| 1136 | handle_smd_irq(&smd_ch_list_dsp, notify_dsp_smd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1137 | handle_smd_irq_closing_list(); |
| 1138 | return IRQ_HANDLED; |
| 1139 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1140 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1141 | static irqreturn_t smd_dsps_irq_handler(int irq, void *data) |
| 1142 | { |
| 1143 | handle_smd_irq(&smd_ch_list_dsps, notify_dsps_smd); |
| 1144 | handle_smd_irq_closing_list(); |
| 1145 | return IRQ_HANDLED; |
| 1146 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1147 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1148 | static irqreturn_t smd_wcnss_irq_handler(int irq, void *data) |
| 1149 | { |
| 1150 | handle_smd_irq(&smd_ch_list_wcnss, notify_wcnss_smd); |
| 1151 | handle_smd_irq_closing_list(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1152 | return IRQ_HANDLED; |
| 1153 | } |
| 1154 | |
| 1155 | static void smd_fake_irq_handler(unsigned long arg) |
| 1156 | { |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1157 | handle_smd_irq(&smd_ch_list_modem, notify_modem_smd); |
| 1158 | handle_smd_irq(&smd_ch_list_dsp, notify_dsp_smd); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1159 | handle_smd_irq(&smd_ch_list_dsps, notify_dsps_smd); |
| 1160 | handle_smd_irq(&smd_ch_list_wcnss, notify_wcnss_smd); |
| 1161 | handle_smd_irq_closing_list(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | static DECLARE_TASKLET(smd_fake_irq_tasklet, smd_fake_irq_handler, 0); |
| 1165 | |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1166 | static inline int smd_need_int(struct smd_channel *ch) |
| 1167 | { |
| 1168 | if (ch_is_open(ch)) { |
| 1169 | if (ch->recv->fHEAD || ch->recv->fTAIL || ch->recv->fSTATE) |
| 1170 | return 1; |
| 1171 | if (ch->recv->state != ch->last_state) |
| 1172 | return 1; |
| 1173 | } |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1177 | void smd_sleep_exit(void) |
| 1178 | { |
| 1179 | unsigned long flags; |
| 1180 | struct smd_channel *ch; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1181 | int need_int = 0; |
| 1182 | |
| 1183 | spin_lock_irqsave(&smd_lock, flags); |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1184 | list_for_each_entry(ch, &smd_ch_list_modem, ch_list) { |
| 1185 | if (smd_need_int(ch)) { |
| 1186 | need_int = 1; |
| 1187 | break; |
| 1188 | } |
| 1189 | } |
| 1190 | list_for_each_entry(ch, &smd_ch_list_dsp, ch_list) { |
| 1191 | if (smd_need_int(ch)) { |
| 1192 | need_int = 1; |
| 1193 | break; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1194 | } |
| 1195 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1196 | list_for_each_entry(ch, &smd_ch_list_dsps, ch_list) { |
| 1197 | if (smd_need_int(ch)) { |
| 1198 | need_int = 1; |
| 1199 | break; |
| 1200 | } |
| 1201 | } |
| 1202 | list_for_each_entry(ch, &smd_ch_list_wcnss, ch_list) { |
| 1203 | if (smd_need_int(ch)) { |
| 1204 | need_int = 1; |
| 1205 | break; |
| 1206 | } |
| 1207 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1208 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1209 | do_smd_probe(); |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1210 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1211 | if (need_int) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1212 | SMD_DBG("smd_sleep_exit need interrupt\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1213 | tasklet_schedule(&smd_fake_irq_tasklet); |
| 1214 | } |
| 1215 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1216 | EXPORT_SYMBOL(smd_sleep_exit); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1217 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1218 | static int smd_is_packet(struct smd_alloc_elm *alloc_elm) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1219 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1220 | if (SMD_XFER_TYPE(alloc_elm->type) == 1) |
| 1221 | return 0; |
| 1222 | else if (SMD_XFER_TYPE(alloc_elm->type) == 2) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1223 | return 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1224 | |
| 1225 | /* for cases where xfer type is 0 */ |
| 1226 | if (!strncmp(alloc_elm->name, "DAL", 3)) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1227 | return 0; |
| 1228 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1229 | /* for cases where xfer type is 0 */ |
| 1230 | if (!strncmp(alloc_elm->name, "RPCCALL_QDSP", 12)) |
| 1231 | return 0; |
| 1232 | |
| 1233 | if (alloc_elm->cid > 4 || alloc_elm->cid == 1) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1234 | return 1; |
| 1235 | else |
| 1236 | return 0; |
| 1237 | } |
| 1238 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1239 | static int smd_stream_write(smd_channel_t *ch, const void *_data, int len, |
| 1240 | int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1241 | { |
| 1242 | void *ptr; |
| 1243 | const unsigned char *buf = _data; |
| 1244 | unsigned xfer; |
| 1245 | int orig_len = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1246 | int r = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1247 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1248 | SMD_DBG("smd_stream_write() %d -> ch%d\n", len, ch->n); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1249 | if (len < 0) |
| 1250 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1251 | else if (len == 0) |
| 1252 | return 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1253 | |
| 1254 | while ((xfer = ch_write_buffer(ch, &ptr)) != 0) { |
Eric Holmberg | 7a71787 | 2012-02-03 11:58:04 -0700 | [diff] [blame] | 1255 | if (!ch_is_open(ch)) { |
| 1256 | len = orig_len; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1257 | break; |
Eric Holmberg | 7a71787 | 2012-02-03 11:58:04 -0700 | [diff] [blame] | 1258 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1259 | if (xfer > len) |
| 1260 | xfer = len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1261 | if (user_buf) { |
| 1262 | r = copy_from_user(ptr, buf, xfer); |
| 1263 | if (r > 0) { |
| 1264 | pr_err("%s: " |
| 1265 | "copy_from_user could not copy %i " |
| 1266 | "bytes.\n", |
| 1267 | __func__, |
| 1268 | r); |
| 1269 | } |
| 1270 | } else |
| 1271 | memcpy(ptr, buf, xfer); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1272 | ch_write_done(ch, xfer); |
| 1273 | len -= xfer; |
| 1274 | buf += xfer; |
| 1275 | if (len == 0) |
| 1276 | break; |
| 1277 | } |
| 1278 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1279 | if (orig_len - len) |
| 1280 | ch->notify_other_cpu(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1281 | |
| 1282 | return orig_len - len; |
| 1283 | } |
| 1284 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1285 | static int smd_packet_write(smd_channel_t *ch, const void *_data, int len, |
| 1286 | int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1287 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1288 | int ret; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1289 | unsigned hdr[5]; |
| 1290 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1291 | SMD_DBG("smd_packet_write() %d -> ch%d\n", len, ch->n); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1292 | if (len < 0) |
| 1293 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1294 | else if (len == 0) |
| 1295 | return 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1296 | |
| 1297 | if (smd_stream_write_avail(ch) < (len + SMD_HEADER_SIZE)) |
| 1298 | return -ENOMEM; |
| 1299 | |
| 1300 | hdr[0] = len; |
| 1301 | hdr[1] = hdr[2] = hdr[3] = hdr[4] = 0; |
| 1302 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1303 | |
| 1304 | ret = smd_stream_write(ch, hdr, sizeof(hdr), 0); |
| 1305 | if (ret < 0 || ret != sizeof(hdr)) { |
| 1306 | SMD_DBG("%s failed to write pkt header: " |
| 1307 | "%d returned\n", __func__, ret); |
| 1308 | return -1; |
| 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | ret = smd_stream_write(ch, _data, len, user_buf); |
| 1313 | if (ret < 0 || ret != len) { |
| 1314 | SMD_DBG("%s failed to write pkt data: " |
| 1315 | "%d returned\n", __func__, ret); |
| 1316 | return ret; |
| 1317 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1318 | |
| 1319 | return len; |
| 1320 | } |
| 1321 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1322 | static int smd_stream_read(smd_channel_t *ch, void *data, int len, int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1323 | { |
| 1324 | int r; |
| 1325 | |
| 1326 | if (len < 0) |
| 1327 | return -EINVAL; |
| 1328 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1329 | r = ch_read(ch, data, len, user_buf); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1330 | if (r > 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1331 | if (!read_intr_blocked(ch)) |
| 1332 | ch->notify_other_cpu(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1333 | |
| 1334 | return r; |
| 1335 | } |
| 1336 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1337 | static int smd_packet_read(smd_channel_t *ch, void *data, int len, int user_buf) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1338 | { |
| 1339 | unsigned long flags; |
| 1340 | int r; |
| 1341 | |
| 1342 | if (len < 0) |
| 1343 | return -EINVAL; |
| 1344 | |
| 1345 | if (len > ch->current_packet) |
| 1346 | len = ch->current_packet; |
| 1347 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1348 | r = ch_read(ch, data, len, user_buf); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1349 | if (r > 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1350 | if (!read_intr_blocked(ch)) |
| 1351 | ch->notify_other_cpu(); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1352 | |
| 1353 | spin_lock_irqsave(&smd_lock, flags); |
| 1354 | ch->current_packet -= r; |
| 1355 | update_packet_state(ch); |
| 1356 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1357 | |
| 1358 | return r; |
| 1359 | } |
| 1360 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1361 | static int smd_packet_read_from_cb(smd_channel_t *ch, void *data, int len, |
| 1362 | int user_buf) |
| 1363 | { |
| 1364 | int r; |
| 1365 | |
| 1366 | if (len < 0) |
| 1367 | return -EINVAL; |
| 1368 | |
| 1369 | if (len > ch->current_packet) |
| 1370 | len = ch->current_packet; |
| 1371 | |
| 1372 | r = ch_read(ch, data, len, user_buf); |
| 1373 | if (r > 0) |
| 1374 | if (!read_intr_blocked(ch)) |
| 1375 | ch->notify_other_cpu(); |
| 1376 | |
| 1377 | ch->current_packet -= r; |
| 1378 | update_packet_state(ch); |
| 1379 | |
| 1380 | return r; |
| 1381 | } |
| 1382 | |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1383 | #if (defined(CONFIG_MSM_SMD_PKG4) || defined(CONFIG_MSM_SMD_PKG3)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1384 | static int smd_alloc_v2(struct smd_channel *ch) |
| 1385 | { |
| 1386 | struct smd_shared_v2 *shared2; |
| 1387 | void *buffer; |
| 1388 | unsigned buffer_sz; |
| 1389 | |
| 1390 | shared2 = smem_alloc(SMEM_SMD_BASE_ID + ch->n, sizeof(*shared2)); |
| 1391 | if (!shared2) { |
| 1392 | SMD_INFO("smem_alloc failed ch=%d\n", ch->n); |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1393 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1394 | } |
| 1395 | buffer = smem_get_entry(SMEM_SMD_FIFO_BASE_ID + ch->n, &buffer_sz); |
| 1396 | if (!buffer) { |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1397 | SMD_INFO("smem_get_entry failed\n"); |
| 1398 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /* buffer must be a power-of-two size */ |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1402 | if (buffer_sz & (buffer_sz - 1)) { |
| 1403 | SMD_INFO("Buffer size: %u not power of two\n", buffer_sz); |
| 1404 | return -EINVAL; |
| 1405 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1406 | buffer_sz /= 2; |
| 1407 | ch->send = &shared2->ch0; |
| 1408 | ch->recv = &shared2->ch1; |
| 1409 | ch->send_data = buffer; |
| 1410 | ch->recv_data = buffer + buffer_sz; |
| 1411 | ch->fifo_size = buffer_sz; |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | static int smd_alloc_v1(struct smd_channel *ch) |
| 1416 | { |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1417 | return -EINVAL; |
| 1418 | } |
| 1419 | |
| 1420 | #else /* define v1 for older targets */ |
| 1421 | static int smd_alloc_v2(struct smd_channel *ch) |
| 1422 | { |
| 1423 | return -EINVAL; |
| 1424 | } |
| 1425 | |
| 1426 | static int smd_alloc_v1(struct smd_channel *ch) |
| 1427 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1428 | struct smd_shared_v1 *shared1; |
| 1429 | shared1 = smem_alloc(ID_SMD_CHANNELS + ch->n, sizeof(*shared1)); |
| 1430 | if (!shared1) { |
| 1431 | pr_err("smd_alloc_channel() cid %d does not exist\n", ch->n); |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1432 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1433 | } |
| 1434 | ch->send = &shared1->ch0; |
| 1435 | ch->recv = &shared1->ch1; |
| 1436 | ch->send_data = shared1->data0; |
| 1437 | ch->recv_data = shared1->data1; |
| 1438 | ch->fifo_size = SMD_BUF_SIZE; |
| 1439 | return 0; |
| 1440 | } |
| 1441 | |
Angshuman Sarkar | ac7d625 | 2011-09-30 18:20:59 +0530 | [diff] [blame] | 1442 | #endif |
| 1443 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1444 | static int smd_alloc_channel(struct smd_alloc_elm *alloc_elm) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1445 | { |
| 1446 | struct smd_channel *ch; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1447 | |
| 1448 | ch = kzalloc(sizeof(struct smd_channel), GFP_KERNEL); |
| 1449 | if (ch == 0) { |
| 1450 | pr_err("smd_alloc_channel() out of memory\n"); |
Brian Swetland | 34f719b | 2009-10-30 16:22:05 -0700 | [diff] [blame] | 1451 | return -1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1452 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1453 | ch->n = alloc_elm->cid; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1454 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1455 | if (smd_alloc_v2(ch) && smd_alloc_v1(ch)) { |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1456 | kfree(ch); |
Brian Swetland | 34f719b | 2009-10-30 16:22:05 -0700 | [diff] [blame] | 1457 | return -1; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | ch->fifo_mask = ch->fifo_size - 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1461 | ch->type = SMD_CHANNEL_TYPE(alloc_elm->type); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1462 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1463 | if (ch->type == SMD_APPS_MODEM) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1464 | ch->notify_other_cpu = notify_modem_smd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1465 | else if (ch->type == SMD_APPS_QDSP) |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1466 | ch->notify_other_cpu = notify_dsp_smd; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1467 | else if (ch->type == SMD_APPS_DSPS) |
| 1468 | ch->notify_other_cpu = notify_dsps_smd; |
| 1469 | else |
| 1470 | ch->notify_other_cpu = notify_wcnss_smd; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 1471 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1472 | if (smd_is_packet(alloc_elm)) { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1473 | ch->read = smd_packet_read; |
| 1474 | ch->write = smd_packet_write; |
| 1475 | ch->read_avail = smd_packet_read_avail; |
| 1476 | ch->write_avail = smd_packet_write_avail; |
| 1477 | ch->update_state = update_packet_state; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1478 | ch->read_from_cb = smd_packet_read_from_cb; |
| 1479 | ch->is_pkt_ch = 1; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1480 | } else { |
| 1481 | ch->read = smd_stream_read; |
| 1482 | ch->write = smd_stream_write; |
| 1483 | ch->read_avail = smd_stream_read_avail; |
| 1484 | ch->write_avail = smd_stream_write_avail; |
| 1485 | ch->update_state = update_stream_state; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1486 | ch->read_from_cb = smd_stream_read; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1489 | memcpy(ch->name, alloc_elm->name, SMD_MAX_CH_NAME_LEN); |
| 1490 | ch->name[SMD_MAX_CH_NAME_LEN-1] = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1491 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1492 | ch->pdev.name = ch->name; |
| 1493 | ch->pdev.id = ch->type; |
| 1494 | |
| 1495 | SMD_INFO("smd_alloc_channel() '%s' cid=%d\n", |
| 1496 | ch->name, ch->n); |
| 1497 | |
| 1498 | mutex_lock(&smd_creation_mutex); |
| 1499 | list_add(&ch->ch_list, &smd_ch_closed_list); |
| 1500 | mutex_unlock(&smd_creation_mutex); |
| 1501 | |
| 1502 | platform_device_register(&ch->pdev); |
| 1503 | if (!strncmp(ch->name, "LOOPBACK", 8) && ch->type == SMD_APPS_MODEM) { |
| 1504 | /* create a platform driver to be used by smd_tty driver |
| 1505 | * so that it can access the loopback port |
| 1506 | */ |
| 1507 | loopback_tty_pdev.id = ch->type; |
| 1508 | platform_device_register(&loopback_tty_pdev); |
| 1509 | } |
| 1510 | return 0; |
| 1511 | } |
| 1512 | |
| 1513 | static inline void notify_loopback_smd(void) |
| 1514 | { |
| 1515 | unsigned long flags; |
| 1516 | struct smd_channel *ch; |
| 1517 | |
| 1518 | spin_lock_irqsave(&smd_lock, flags); |
| 1519 | list_for_each_entry(ch, &smd_ch_list_loopback, ch_list) { |
| 1520 | ch->notify(ch->priv, SMD_EVENT_DATA); |
| 1521 | } |
| 1522 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1523 | } |
| 1524 | |
| 1525 | static int smd_alloc_loopback_channel(void) |
| 1526 | { |
| 1527 | static struct smd_half_channel smd_loopback_ctl; |
| 1528 | static char smd_loopback_data[SMD_BUF_SIZE]; |
| 1529 | struct smd_channel *ch; |
| 1530 | |
| 1531 | ch = kzalloc(sizeof(struct smd_channel), GFP_KERNEL); |
| 1532 | if (ch == 0) { |
| 1533 | pr_err("%s: out of memory\n", __func__); |
| 1534 | return -1; |
| 1535 | } |
| 1536 | ch->n = SMD_LOOPBACK_CID; |
| 1537 | |
| 1538 | ch->send = &smd_loopback_ctl; |
| 1539 | ch->recv = &smd_loopback_ctl; |
| 1540 | ch->send_data = smd_loopback_data; |
| 1541 | ch->recv_data = smd_loopback_data; |
| 1542 | ch->fifo_size = SMD_BUF_SIZE; |
| 1543 | |
| 1544 | ch->fifo_mask = ch->fifo_size - 1; |
| 1545 | ch->type = SMD_LOOPBACK_TYPE; |
| 1546 | ch->notify_other_cpu = notify_loopback_smd; |
| 1547 | |
| 1548 | ch->read = smd_stream_read; |
| 1549 | ch->write = smd_stream_write; |
| 1550 | ch->read_avail = smd_stream_read_avail; |
| 1551 | ch->write_avail = smd_stream_write_avail; |
| 1552 | ch->update_state = update_stream_state; |
| 1553 | ch->read_from_cb = smd_stream_read; |
| 1554 | |
| 1555 | memset(ch->name, 0, 20); |
| 1556 | memcpy(ch->name, "local_loopback", 14); |
| 1557 | |
| 1558 | ch->pdev.name = ch->name; |
| 1559 | ch->pdev.id = ch->type; |
| 1560 | |
| 1561 | SMD_INFO("%s: '%s' cid=%d\n", __func__, ch->name, ch->n); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1562 | |
| 1563 | mutex_lock(&smd_creation_mutex); |
| 1564 | list_add(&ch->ch_list, &smd_ch_closed_list); |
| 1565 | mutex_unlock(&smd_creation_mutex); |
| 1566 | |
| 1567 | platform_device_register(&ch->pdev); |
Brian Swetland | 34f719b | 2009-10-30 16:22:05 -0700 | [diff] [blame] | 1568 | return 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static void do_nothing_notify(void *priv, unsigned flags) |
| 1572 | { |
| 1573 | } |
| 1574 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1575 | static void finalize_channel_close_fn(struct work_struct *work) |
| 1576 | { |
| 1577 | unsigned long flags; |
| 1578 | struct smd_channel *ch; |
| 1579 | struct smd_channel *index; |
| 1580 | |
Eric Holmberg | bb2b1fa | 2011-10-12 16:41:37 -0600 | [diff] [blame] | 1581 | mutex_lock(&smd_creation_mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1582 | spin_lock_irqsave(&smd_lock, flags); |
| 1583 | list_for_each_entry_safe(ch, index, &smd_ch_to_close_list, ch_list) { |
| 1584 | list_del(&ch->ch_list); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1585 | list_add(&ch->ch_list, &smd_ch_closed_list); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1586 | ch->notify(ch->priv, SMD_EVENT_REOPEN_READY); |
| 1587 | ch->notify = do_nothing_notify; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1588 | } |
| 1589 | spin_unlock_irqrestore(&smd_lock, flags); |
Eric Holmberg | bb2b1fa | 2011-10-12 16:41:37 -0600 | [diff] [blame] | 1590 | mutex_unlock(&smd_creation_mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | struct smd_channel *smd_get_channel(const char *name, uint32_t type) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1594 | { |
| 1595 | struct smd_channel *ch; |
| 1596 | |
| 1597 | mutex_lock(&smd_creation_mutex); |
| 1598 | list_for_each_entry(ch, &smd_ch_closed_list, ch_list) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1599 | if (!strcmp(name, ch->name) && |
| 1600 | (type == ch->type)) { |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1601 | list_del(&ch->ch_list); |
| 1602 | mutex_unlock(&smd_creation_mutex); |
| 1603 | return ch; |
| 1604 | } |
| 1605 | } |
| 1606 | mutex_unlock(&smd_creation_mutex); |
| 1607 | |
| 1608 | return NULL; |
| 1609 | } |
| 1610 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1611 | int smd_named_open_on_edge(const char *name, uint32_t edge, |
| 1612 | smd_channel_t **_ch, |
| 1613 | void *priv, void (*notify)(void *, unsigned)) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1614 | { |
| 1615 | struct smd_channel *ch; |
| 1616 | unsigned long flags; |
| 1617 | |
| 1618 | if (smd_initialized == 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1619 | SMD_INFO("smd_open() before smd_init()\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1620 | return -ENODEV; |
| 1621 | } |
| 1622 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1623 | SMD_DBG("smd_open('%s', %p, %p)\n", name, priv, notify); |
| 1624 | |
| 1625 | ch = smd_get_channel(name, edge); |
Eric Holmberg | bb2b1fa | 2011-10-12 16:41:37 -0600 | [diff] [blame] | 1626 | if (!ch) { |
Eric Holmberg | bb2b1fa | 2011-10-12 16:41:37 -0600 | [diff] [blame] | 1627 | /* check closing list for port */ |
| 1628 | spin_lock_irqsave(&smd_lock, flags); |
| 1629 | list_for_each_entry(ch, &smd_ch_closing_list, ch_list) { |
| 1630 | if (!strncmp(name, ch->name, 20) && |
| 1631 | (edge == ch->type)) { |
| 1632 | /* channel exists, but is being closed */ |
| 1633 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1634 | return -EAGAIN; |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | /* check closing workqueue list for port */ |
| 1639 | list_for_each_entry(ch, &smd_ch_to_close_list, ch_list) { |
| 1640 | if (!strncmp(name, ch->name, 20) && |
| 1641 | (edge == ch->type)) { |
| 1642 | /* channel exists, but is being closed */ |
| 1643 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1644 | return -EAGAIN; |
| 1645 | } |
| 1646 | } |
| 1647 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1648 | |
| 1649 | /* one final check to handle closing->closed race condition */ |
| 1650 | ch = smd_get_channel(name, edge); |
| 1651 | if (!ch) |
| 1652 | return -ENODEV; |
| 1653 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1654 | |
| 1655 | if (notify == 0) |
| 1656 | notify = do_nothing_notify; |
| 1657 | |
| 1658 | ch->notify = notify; |
| 1659 | ch->current_packet = 0; |
| 1660 | ch->last_state = SMD_SS_CLOSED; |
| 1661 | ch->priv = priv; |
| 1662 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1663 | if (edge == SMD_LOOPBACK_TYPE) { |
| 1664 | ch->last_state = SMD_SS_OPENED; |
| 1665 | ch->send->state = SMD_SS_OPENED; |
| 1666 | ch->send->fDSR = 1; |
| 1667 | ch->send->fCTS = 1; |
| 1668 | ch->send->fCD = 1; |
| 1669 | } |
| 1670 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1671 | *_ch = ch; |
| 1672 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1673 | SMD_DBG("smd_open: opening '%s'\n", ch->name); |
| 1674 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1675 | spin_lock_irqsave(&smd_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1676 | if (SMD_CHANNEL_TYPE(ch->type) == SMD_APPS_MODEM) |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1677 | list_add(&ch->ch_list, &smd_ch_list_modem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1678 | else if (SMD_CHANNEL_TYPE(ch->type) == SMD_APPS_QDSP) |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 1679 | list_add(&ch->ch_list, &smd_ch_list_dsp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1680 | else if (SMD_CHANNEL_TYPE(ch->type) == SMD_APPS_DSPS) |
| 1681 | list_add(&ch->ch_list, &smd_ch_list_dsps); |
| 1682 | else if (SMD_CHANNEL_TYPE(ch->type) == SMD_APPS_WCNSS) |
| 1683 | list_add(&ch->ch_list, &smd_ch_list_wcnss); |
| 1684 | else |
| 1685 | list_add(&ch->ch_list, &smd_ch_list_loopback); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1686 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1687 | SMD_DBG("%s: opening ch %d\n", __func__, ch->n); |
| 1688 | |
| 1689 | if (edge != SMD_LOOPBACK_TYPE) |
| 1690 | smd_state_change(ch, ch->last_state, SMD_SS_OPENING); |
| 1691 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1692 | spin_unlock_irqrestore(&smd_lock, flags); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1693 | |
| 1694 | return 0; |
| 1695 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1696 | EXPORT_SYMBOL(smd_named_open_on_edge); |
| 1697 | |
| 1698 | |
| 1699 | int smd_open(const char *name, smd_channel_t **_ch, |
| 1700 | void *priv, void (*notify)(void *, unsigned)) |
| 1701 | { |
| 1702 | return smd_named_open_on_edge(name, SMD_APPS_MODEM, _ch, priv, |
| 1703 | notify); |
| 1704 | } |
| 1705 | EXPORT_SYMBOL(smd_open); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1706 | |
| 1707 | int smd_close(smd_channel_t *ch) |
| 1708 | { |
| 1709 | unsigned long flags; |
| 1710 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1711 | if (ch == 0) |
| 1712 | return -1; |
| 1713 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1714 | SMD_INFO("smd_close(%s)\n", ch->name); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1715 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1716 | spin_lock_irqsave(&smd_lock, flags); |
| 1717 | list_del(&ch->ch_list); |
| 1718 | if (ch->n == SMD_LOOPBACK_CID) { |
| 1719 | ch->send->fDSR = 0; |
| 1720 | ch->send->fCTS = 0; |
| 1721 | ch->send->fCD = 0; |
| 1722 | ch->send->state = SMD_SS_CLOSED; |
| 1723 | } else |
| 1724 | ch_set_state(ch, SMD_SS_CLOSED); |
| 1725 | |
| 1726 | if (ch->recv->state == SMD_SS_OPENED) { |
| 1727 | list_add(&ch->ch_list, &smd_ch_closing_list); |
| 1728 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1729 | } else { |
| 1730 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1731 | ch->notify = do_nothing_notify; |
| 1732 | mutex_lock(&smd_creation_mutex); |
| 1733 | list_add(&ch->ch_list, &smd_ch_closed_list); |
| 1734 | mutex_unlock(&smd_creation_mutex); |
| 1735 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1736 | |
| 1737 | return 0; |
| 1738 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1739 | EXPORT_SYMBOL(smd_close); |
| 1740 | |
| 1741 | int smd_write_start(smd_channel_t *ch, int len) |
| 1742 | { |
| 1743 | int ret; |
| 1744 | unsigned hdr[5]; |
| 1745 | |
| 1746 | if (!ch) { |
| 1747 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1748 | return -ENODEV; |
| 1749 | } |
| 1750 | if (!ch->is_pkt_ch) { |
| 1751 | pr_err("%s: non-packet channel specified\n", __func__); |
| 1752 | return -EACCES; |
| 1753 | } |
| 1754 | if (len < 1) { |
| 1755 | pr_err("%s: invalid length: %d\n", __func__, len); |
| 1756 | return -EINVAL; |
| 1757 | } |
| 1758 | |
| 1759 | if (ch->pending_pkt_sz) { |
| 1760 | pr_err("%s: packet of size: %d in progress\n", __func__, |
| 1761 | ch->pending_pkt_sz); |
| 1762 | return -EBUSY; |
| 1763 | } |
| 1764 | ch->pending_pkt_sz = len; |
| 1765 | |
| 1766 | if (smd_stream_write_avail(ch) < (SMD_HEADER_SIZE)) { |
| 1767 | ch->pending_pkt_sz = 0; |
| 1768 | SMD_DBG("%s: no space to write packet header\n", __func__); |
| 1769 | return -EAGAIN; |
| 1770 | } |
| 1771 | |
| 1772 | hdr[0] = len; |
| 1773 | hdr[1] = hdr[2] = hdr[3] = hdr[4] = 0; |
| 1774 | |
| 1775 | |
| 1776 | ret = smd_stream_write(ch, hdr, sizeof(hdr), 0); |
| 1777 | if (ret < 0 || ret != sizeof(hdr)) { |
| 1778 | ch->pending_pkt_sz = 0; |
| 1779 | pr_err("%s: packet header failed to write\n", __func__); |
| 1780 | return -EPERM; |
| 1781 | } |
| 1782 | return 0; |
| 1783 | } |
| 1784 | EXPORT_SYMBOL(smd_write_start); |
| 1785 | |
| 1786 | int smd_write_segment(smd_channel_t *ch, void *data, int len, int user_buf) |
| 1787 | { |
| 1788 | int bytes_written; |
| 1789 | |
| 1790 | if (!ch) { |
| 1791 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1792 | return -ENODEV; |
| 1793 | } |
| 1794 | if (len < 1) { |
| 1795 | pr_err("%s: invalid length: %d\n", __func__, len); |
| 1796 | return -EINVAL; |
| 1797 | } |
| 1798 | |
| 1799 | if (!ch->pending_pkt_sz) { |
| 1800 | pr_err("%s: no transaction in progress\n", __func__); |
| 1801 | return -ENOEXEC; |
| 1802 | } |
| 1803 | if (ch->pending_pkt_sz - len < 0) { |
| 1804 | pr_err("%s: segment of size: %d will make packet go over " |
| 1805 | "length\n", __func__, len); |
| 1806 | return -EINVAL; |
| 1807 | } |
| 1808 | |
| 1809 | bytes_written = smd_stream_write(ch, data, len, user_buf); |
| 1810 | |
| 1811 | ch->pending_pkt_sz -= bytes_written; |
| 1812 | |
| 1813 | return bytes_written; |
| 1814 | } |
| 1815 | EXPORT_SYMBOL(smd_write_segment); |
| 1816 | |
| 1817 | int smd_write_end(smd_channel_t *ch) |
| 1818 | { |
| 1819 | |
| 1820 | if (!ch) { |
| 1821 | pr_err("%s: Invalid channel specified\n", __func__); |
| 1822 | return -ENODEV; |
| 1823 | } |
| 1824 | if (ch->pending_pkt_sz) { |
| 1825 | pr_err("%s: current packet not completely written\n", __func__); |
| 1826 | return -E2BIG; |
| 1827 | } |
| 1828 | |
| 1829 | return 0; |
| 1830 | } |
| 1831 | EXPORT_SYMBOL(smd_write_end); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1832 | |
| 1833 | int smd_read(smd_channel_t *ch, void *data, int len) |
| 1834 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1835 | return ch->read(ch, data, len, 0); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1836 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1837 | EXPORT_SYMBOL(smd_read); |
| 1838 | |
| 1839 | int smd_read_user_buffer(smd_channel_t *ch, void *data, int len) |
| 1840 | { |
| 1841 | return ch->read(ch, data, len, 1); |
| 1842 | } |
| 1843 | EXPORT_SYMBOL(smd_read_user_buffer); |
| 1844 | |
| 1845 | int smd_read_from_cb(smd_channel_t *ch, void *data, int len) |
| 1846 | { |
| 1847 | return ch->read_from_cb(ch, data, len, 0); |
| 1848 | } |
| 1849 | EXPORT_SYMBOL(smd_read_from_cb); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1850 | |
| 1851 | int smd_write(smd_channel_t *ch, const void *data, int len) |
| 1852 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1853 | return ch->pending_pkt_sz ? -EBUSY : ch->write(ch, data, len, 0); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1854 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1855 | EXPORT_SYMBOL(smd_write); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1856 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1857 | int smd_write_user_buffer(smd_channel_t *ch, const void *data, int len) |
Brian Swetland | 636eb9c | 2009-12-07 15:28:08 -0800 | [diff] [blame] | 1858 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1859 | return ch->pending_pkt_sz ? -EBUSY : ch->write(ch, data, len, 1); |
Brian Swetland | 636eb9c | 2009-12-07 15:28:08 -0800 | [diff] [blame] | 1860 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1861 | EXPORT_SYMBOL(smd_write_user_buffer); |
Brian Swetland | 636eb9c | 2009-12-07 15:28:08 -0800 | [diff] [blame] | 1862 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1863 | int smd_read_avail(smd_channel_t *ch) |
| 1864 | { |
| 1865 | return ch->read_avail(ch); |
| 1866 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1867 | EXPORT_SYMBOL(smd_read_avail); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1868 | |
| 1869 | int smd_write_avail(smd_channel_t *ch) |
| 1870 | { |
| 1871 | return ch->write_avail(ch); |
| 1872 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1873 | EXPORT_SYMBOL(smd_write_avail); |
| 1874 | |
| 1875 | void smd_enable_read_intr(smd_channel_t *ch) |
| 1876 | { |
| 1877 | if (ch) |
| 1878 | ch->send->fBLOCKREADINTR = 0; |
| 1879 | } |
| 1880 | EXPORT_SYMBOL(smd_enable_read_intr); |
| 1881 | |
| 1882 | void smd_disable_read_intr(smd_channel_t *ch) |
| 1883 | { |
| 1884 | if (ch) |
| 1885 | ch->send->fBLOCKREADINTR = 1; |
| 1886 | } |
| 1887 | EXPORT_SYMBOL(smd_disable_read_intr); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1888 | |
| 1889 | int smd_wait_until_readable(smd_channel_t *ch, int bytes) |
| 1890 | { |
| 1891 | return -1; |
| 1892 | } |
| 1893 | |
| 1894 | int smd_wait_until_writable(smd_channel_t *ch, int bytes) |
| 1895 | { |
| 1896 | return -1; |
| 1897 | } |
| 1898 | |
| 1899 | int smd_cur_packet_size(smd_channel_t *ch) |
| 1900 | { |
| 1901 | return ch->current_packet; |
| 1902 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1903 | EXPORT_SYMBOL(smd_cur_packet_size); |
| 1904 | |
| 1905 | int smd_tiocmget(smd_channel_t *ch) |
| 1906 | { |
| 1907 | return (ch->recv->fDSR ? TIOCM_DSR : 0) | |
| 1908 | (ch->recv->fCTS ? TIOCM_CTS : 0) | |
| 1909 | (ch->recv->fCD ? TIOCM_CD : 0) | |
| 1910 | (ch->recv->fRI ? TIOCM_RI : 0) | |
| 1911 | (ch->send->fCTS ? TIOCM_RTS : 0) | |
| 1912 | (ch->send->fDSR ? TIOCM_DTR : 0); |
| 1913 | } |
| 1914 | EXPORT_SYMBOL(smd_tiocmget); |
| 1915 | |
Vamsi Krishna | cb12a10 | 2011-08-17 15:18:26 -0700 | [diff] [blame] | 1916 | /* this api will be called while holding smd_lock */ |
| 1917 | int |
| 1918 | smd_tiocmset_from_cb(smd_channel_t *ch, unsigned int set, unsigned int clear) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1919 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1920 | if (set & TIOCM_DTR) |
| 1921 | ch->send->fDSR = 1; |
| 1922 | |
| 1923 | if (set & TIOCM_RTS) |
| 1924 | ch->send->fCTS = 1; |
| 1925 | |
| 1926 | if (clear & TIOCM_DTR) |
| 1927 | ch->send->fDSR = 0; |
| 1928 | |
| 1929 | if (clear & TIOCM_RTS) |
| 1930 | ch->send->fCTS = 0; |
| 1931 | |
| 1932 | ch->send->fSTATE = 1; |
| 1933 | barrier(); |
| 1934 | ch->notify_other_cpu(); |
Vamsi Krishna | cb12a10 | 2011-08-17 15:18:26 -0700 | [diff] [blame] | 1935 | |
| 1936 | return 0; |
| 1937 | } |
| 1938 | EXPORT_SYMBOL(smd_tiocmset_from_cb); |
| 1939 | |
| 1940 | int smd_tiocmset(smd_channel_t *ch, unsigned int set, unsigned int clear) |
| 1941 | { |
| 1942 | unsigned long flags; |
| 1943 | |
| 1944 | spin_lock_irqsave(&smd_lock, flags); |
| 1945 | smd_tiocmset_from_cb(ch, set, clear); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1946 | spin_unlock_irqrestore(&smd_lock, flags); |
| 1947 | |
| 1948 | return 0; |
| 1949 | } |
| 1950 | EXPORT_SYMBOL(smd_tiocmset); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1951 | |
| 1952 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1953 | /* -------------------------------------------------------------------------- */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1954 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1955 | /* smem_alloc returns the pointer to smem item if it is already allocated. |
| 1956 | * Otherwise, it returns NULL. |
| 1957 | */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1958 | void *smem_alloc(unsigned id, unsigned size) |
| 1959 | { |
| 1960 | return smem_find(id, size); |
| 1961 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1962 | EXPORT_SYMBOL(smem_alloc); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 1963 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1964 | /* smem_alloc2 returns the pointer to smem item. If it is not allocated, |
| 1965 | * it allocates it and then returns the pointer to it. |
| 1966 | */ |
Angshuman Sarkar | 4eade0d | 2011-08-17 14:06:23 +0530 | [diff] [blame] | 1967 | void *smem_alloc2(unsigned id, unsigned size_in) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1968 | { |
| 1969 | struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE; |
| 1970 | struct smem_heap_entry *toc = shared->heap_toc; |
| 1971 | unsigned long flags; |
| 1972 | void *ret = NULL; |
| 1973 | |
| 1974 | if (!shared->heap_info.initialized) { |
| 1975 | pr_err("%s: smem heap info not initialized\n", __func__); |
| 1976 | return NULL; |
| 1977 | } |
| 1978 | |
| 1979 | if (id >= SMEM_NUM_ITEMS) |
| 1980 | return NULL; |
| 1981 | |
| 1982 | size_in = ALIGN(size_in, 8); |
| 1983 | remote_spin_lock_irqsave(&remote_spinlock, flags); |
| 1984 | if (toc[id].allocated) { |
| 1985 | SMD_DBG("%s: %u already allocated\n", __func__, id); |
| 1986 | if (size_in != toc[id].size) |
| 1987 | pr_err("%s: wrong size %u (expected %u)\n", |
| 1988 | __func__, toc[id].size, size_in); |
| 1989 | else |
| 1990 | ret = (void *)(MSM_SHARED_RAM_BASE + toc[id].offset); |
| 1991 | } else if (id > SMEM_FIXED_ITEM_LAST) { |
| 1992 | SMD_DBG("%s: allocating %u\n", __func__, id); |
| 1993 | if (shared->heap_info.heap_remaining >= size_in) { |
| 1994 | toc[id].offset = shared->heap_info.free_offset; |
| 1995 | toc[id].size = size_in; |
| 1996 | wmb(); |
| 1997 | toc[id].allocated = 1; |
| 1998 | |
| 1999 | shared->heap_info.free_offset += size_in; |
| 2000 | shared->heap_info.heap_remaining -= size_in; |
| 2001 | ret = (void *)(MSM_SHARED_RAM_BASE + toc[id].offset); |
| 2002 | } else |
| 2003 | pr_err("%s: not enough memory %u (required %u)\n", |
| 2004 | __func__, shared->heap_info.heap_remaining, |
| 2005 | size_in); |
| 2006 | } |
| 2007 | wmb(); |
| 2008 | remote_spin_unlock_irqrestore(&remote_spinlock, flags); |
| 2009 | return ret; |
| 2010 | } |
Angshuman Sarkar | 4eade0d | 2011-08-17 14:06:23 +0530 | [diff] [blame] | 2011 | EXPORT_SYMBOL(smem_alloc2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2012 | |
| 2013 | void *smem_get_entry(unsigned id, unsigned *size) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2014 | { |
| 2015 | struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE; |
| 2016 | struct smem_heap_entry *toc = shared->heap_toc; |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2017 | int use_spinlocks = spinlocks_initialized; |
| 2018 | void *ret = 0; |
| 2019 | unsigned long flags = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2020 | |
| 2021 | if (id >= SMEM_NUM_ITEMS) |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2022 | return ret; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2023 | |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2024 | if (use_spinlocks) |
| 2025 | remote_spin_lock_irqsave(&remote_spinlock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2026 | /* toc is in device memory and cannot be speculatively accessed */ |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2027 | if (toc[id].allocated) { |
| 2028 | *size = toc[id].size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2029 | barrier(); |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2030 | ret = (void *) (MSM_SHARED_RAM_BASE + toc[id].offset); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2031 | } else { |
| 2032 | *size = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2033 | } |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2034 | if (use_spinlocks) |
| 2035 | remote_spin_unlock_irqrestore(&remote_spinlock, flags); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2036 | |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2037 | return ret; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2038 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2039 | EXPORT_SYMBOL(smem_get_entry); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2040 | |
| 2041 | void *smem_find(unsigned id, unsigned size_in) |
| 2042 | { |
| 2043 | unsigned size; |
| 2044 | void *ptr; |
| 2045 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2046 | ptr = smem_get_entry(id, &size); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2047 | if (!ptr) |
| 2048 | return 0; |
| 2049 | |
| 2050 | size_in = ALIGN(size_in, 8); |
| 2051 | if (size_in != size) { |
| 2052 | pr_err("smem_find(%d, %d): wrong size %d\n", |
| 2053 | id, size_in, size); |
| 2054 | return 0; |
| 2055 | } |
| 2056 | |
| 2057 | return ptr; |
| 2058 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2059 | EXPORT_SYMBOL(smem_find); |
| 2060 | |
| 2061 | static int smsm_cb_init(void) |
| 2062 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2063 | struct smsm_state_info *state_info; |
| 2064 | int n; |
| 2065 | int ret = 0; |
| 2066 | |
| 2067 | smsm_states = kmalloc(sizeof(struct smsm_state_info)*SMSM_NUM_ENTRIES, |
| 2068 | GFP_KERNEL); |
| 2069 | |
| 2070 | if (!smsm_states) { |
| 2071 | pr_err("%s: SMSM init failed\n", __func__); |
| 2072 | return -ENOMEM; |
| 2073 | } |
| 2074 | |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2075 | mutex_lock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2076 | for (n = 0; n < SMSM_NUM_ENTRIES; n++) { |
| 2077 | state_info = &smsm_states[n]; |
| 2078 | state_info->last_value = __raw_readl(SMSM_STATE_ADDR(n)); |
| 2079 | INIT_LIST_HEAD(&state_info->callbacks); |
| 2080 | } |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2081 | mutex_unlock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2082 | |
| 2083 | return ret; |
| 2084 | } |
| 2085 | |
| 2086 | static int smsm_init(void) |
| 2087 | { |
| 2088 | struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE; |
| 2089 | int i; |
| 2090 | struct smsm_size_info_type *smsm_size_info; |
| 2091 | |
| 2092 | i = remote_spin_lock_init(&remote_spinlock, SMEM_SPINLOCK_SMEM_ALLOC); |
| 2093 | if (i) { |
| 2094 | pr_err("%s: remote spinlock init failed %d\n", __func__, i); |
| 2095 | return i; |
| 2096 | } |
Angshuman Sarkar | 7ee0dca | 2011-08-22 21:37:34 +0530 | [diff] [blame] | 2097 | spinlocks_initialized = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2098 | |
| 2099 | smsm_size_info = smem_alloc(SMEM_SMSM_SIZE_INFO, |
| 2100 | sizeof(struct smsm_size_info_type)); |
| 2101 | if (smsm_size_info) { |
| 2102 | SMSM_NUM_ENTRIES = smsm_size_info->num_entries; |
| 2103 | SMSM_NUM_HOSTS = smsm_size_info->num_hosts; |
| 2104 | } |
| 2105 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2106 | i = kfifo_alloc(&smsm_snapshot_fifo, |
| 2107 | sizeof(uint32_t) * SMSM_NUM_ENTRIES * SMSM_SNAPSHOT_CNT, |
| 2108 | GFP_KERNEL); |
| 2109 | if (i) { |
| 2110 | pr_err("%s: SMSM state fifo alloc failed %d\n", __func__, i); |
| 2111 | return i; |
| 2112 | } |
| 2113 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2114 | if (!smsm_info.state) { |
| 2115 | smsm_info.state = smem_alloc2(ID_SHARED_STATE, |
| 2116 | SMSM_NUM_ENTRIES * |
| 2117 | sizeof(uint32_t)); |
| 2118 | |
| 2119 | if (smsm_info.state) { |
| 2120 | __raw_writel(0, SMSM_STATE_ADDR(SMSM_APPS_STATE)); |
| 2121 | if ((shared->version[VERSION_MODEM] >> 16) >= 0xB) |
| 2122 | __raw_writel(0, \ |
| 2123 | SMSM_STATE_ADDR(SMSM_APPS_DEM_I)); |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | if (!smsm_info.intr_mask) { |
| 2128 | smsm_info.intr_mask = smem_alloc2(SMEM_SMSM_CPU_INTR_MASK, |
| 2129 | SMSM_NUM_ENTRIES * |
| 2130 | SMSM_NUM_HOSTS * |
| 2131 | sizeof(uint32_t)); |
| 2132 | |
| 2133 | if (smsm_info.intr_mask) |
| 2134 | for (i = 0; i < SMSM_NUM_ENTRIES; i++) |
| 2135 | __raw_writel(0xffffffff, |
| 2136 | SMSM_INTR_MASK_ADDR(i, SMSM_APPS)); |
| 2137 | } |
| 2138 | |
| 2139 | if (!smsm_info.intr_mux) |
| 2140 | smsm_info.intr_mux = smem_alloc2(SMEM_SMD_SMSM_INTR_MUX, |
| 2141 | SMSM_NUM_INTR_MUX * |
| 2142 | sizeof(uint32_t)); |
| 2143 | |
| 2144 | i = smsm_cb_init(); |
| 2145 | if (i) |
| 2146 | return i; |
| 2147 | |
| 2148 | wmb(); |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
| 2152 | void smsm_reset_modem(unsigned mode) |
| 2153 | { |
| 2154 | if (mode == SMSM_SYSTEM_DOWNLOAD) { |
| 2155 | mode = SMSM_RESET | SMSM_SYSTEM_DOWNLOAD; |
| 2156 | } else if (mode == SMSM_MODEM_WAIT) { |
| 2157 | mode = SMSM_RESET | SMSM_MODEM_WAIT; |
| 2158 | } else { /* reset_mode is SMSM_RESET or default */ |
| 2159 | mode = SMSM_RESET; |
| 2160 | } |
| 2161 | |
| 2162 | smsm_change_state(SMSM_APPS_STATE, mode, mode); |
| 2163 | } |
| 2164 | EXPORT_SYMBOL(smsm_reset_modem); |
| 2165 | |
| 2166 | void smsm_reset_modem_cont(void) |
| 2167 | { |
| 2168 | unsigned long flags; |
| 2169 | uint32_t state; |
| 2170 | |
| 2171 | if (!smsm_info.state) |
| 2172 | return; |
| 2173 | |
| 2174 | spin_lock_irqsave(&smem_lock, flags); |
| 2175 | state = __raw_readl(SMSM_STATE_ADDR(SMSM_APPS_STATE)) \ |
| 2176 | & ~SMSM_MODEM_WAIT; |
| 2177 | __raw_writel(state, SMSM_STATE_ADDR(SMSM_APPS_STATE)); |
| 2178 | wmb(); |
| 2179 | spin_unlock_irqrestore(&smem_lock, flags); |
| 2180 | } |
| 2181 | EXPORT_SYMBOL(smsm_reset_modem_cont); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2182 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2183 | static void smsm_cb_snapshot(void) |
| 2184 | { |
| 2185 | int n; |
| 2186 | uint32_t new_state; |
| 2187 | int ret; |
| 2188 | |
| 2189 | ret = kfifo_avail(&smsm_snapshot_fifo); |
| 2190 | if (ret < (SMSM_NUM_ENTRIES * 4)) { |
| 2191 | pr_err("%s: SMSM snapshot full %d\n", __func__, ret); |
| 2192 | return; |
| 2193 | } |
| 2194 | |
| 2195 | for (n = 0; n < SMSM_NUM_ENTRIES; n++) { |
| 2196 | new_state = __raw_readl(SMSM_STATE_ADDR(n)); |
| 2197 | |
| 2198 | ret = kfifo_in(&smsm_snapshot_fifo, |
| 2199 | &new_state, sizeof(new_state)); |
| 2200 | if (ret != sizeof(new_state)) { |
| 2201 | pr_err("%s: SMSM snapshot failure %d\n", __func__, ret); |
| 2202 | return; |
| 2203 | } |
| 2204 | } |
| 2205 | schedule_work(&smsm_cb_work); |
| 2206 | } |
| 2207 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2208 | static irqreturn_t smsm_irq_handler(int irq, void *data) |
| 2209 | { |
| 2210 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2211 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2212 | if (irq == INT_ADSP_A11_SMSM) { |
Eric Holmberg | 6282c5d | 2011-10-27 17:30:57 -0600 | [diff] [blame] | 2213 | uint32_t mux_val; |
| 2214 | static uint32_t prev_smem_q6_apps_smsm; |
| 2215 | |
| 2216 | if (smsm_info.intr_mux && cpu_is_qsd8x50()) { |
| 2217 | mux_val = __raw_readl( |
| 2218 | SMSM_INTR_MUX_ADDR(SMEM_Q6_APPS_SMSM)); |
| 2219 | if (mux_val != prev_smem_q6_apps_smsm) |
| 2220 | prev_smem_q6_apps_smsm = mux_val; |
| 2221 | } |
| 2222 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2223 | spin_lock_irqsave(&smem_lock, flags); |
| 2224 | smsm_cb_snapshot(); |
| 2225 | spin_unlock_irqrestore(&smem_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2226 | return IRQ_HANDLED; |
| 2227 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2228 | |
| 2229 | spin_lock_irqsave(&smem_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2230 | if (!smsm_info.state) { |
| 2231 | SMSM_INFO("<SM NO STATE>\n"); |
| 2232 | } else { |
| 2233 | unsigned old_apps, apps; |
| 2234 | unsigned modm = __raw_readl(SMSM_STATE_ADDR(SMSM_MODEM_STATE)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2235 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2236 | old_apps = apps = __raw_readl(SMSM_STATE_ADDR(SMSM_APPS_STATE)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2237 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2238 | SMSM_DBG("<SM %08x %08x>\n", apps, modm); |
| 2239 | if (apps & SMSM_RESET) { |
| 2240 | /* If we get an interrupt and the apps SMSM_RESET |
| 2241 | bit is already set, the modem is acking the |
| 2242 | app's reset ack. */ |
Stepan Moskovchenko | a1ca758 | 2011-10-25 14:45:09 -0700 | [diff] [blame] | 2243 | if (!cpu_is_msm8960() && !cpu_is_msm8930()) |
Angshuman Sarkar | ead67bd | 2011-09-21 20:13:12 +0530 | [diff] [blame] | 2244 | apps &= ~SMSM_RESET; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2245 | /* Issue a fake irq to handle any |
| 2246 | * smd state changes during reset |
| 2247 | */ |
| 2248 | smd_fake_irq_handler(0); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2249 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2250 | /* queue modem restart notify chain */ |
| 2251 | modem_queue_start_reset_notify(); |
| 2252 | |
| 2253 | } else if (modm & SMSM_RESET) { |
Stepan Moskovchenko | a1ca758 | 2011-10-25 14:45:09 -0700 | [diff] [blame] | 2254 | if (!cpu_is_msm8960() && !cpu_is_msm8930()) |
Angshuman Sarkar | ead67bd | 2011-09-21 20:13:12 +0530 | [diff] [blame] | 2255 | apps |= SMSM_RESET; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2256 | |
| 2257 | pr_err("\nSMSM: Modem SMSM state changed to SMSM_RESET."); |
| 2258 | modem_queue_start_reset_notify(); |
| 2259 | |
| 2260 | } else if (modm & SMSM_INIT) { |
| 2261 | if (!(apps & SMSM_INIT)) { |
| 2262 | apps |= SMSM_INIT; |
| 2263 | modem_queue_smsm_init_notify(); |
| 2264 | } |
| 2265 | |
| 2266 | if (modm & SMSM_SMDINIT) |
| 2267 | apps |= SMSM_SMDINIT; |
| 2268 | if ((apps & (SMSM_INIT | SMSM_SMDINIT | SMSM_RPCINIT)) == |
| 2269 | (SMSM_INIT | SMSM_SMDINIT | SMSM_RPCINIT)) |
| 2270 | apps |= SMSM_RUN; |
| 2271 | } else if (modm & SMSM_SYSTEM_DOWNLOAD) { |
| 2272 | pr_err("\nSMSM: Modem SMSM state changed to SMSM_SYSTEM_DOWNLOAD."); |
| 2273 | modem_queue_start_reset_notify(); |
| 2274 | } |
| 2275 | |
| 2276 | if (old_apps != apps) { |
| 2277 | SMSM_DBG("<SM %08x NOTIFY>\n", apps); |
| 2278 | __raw_writel(apps, SMSM_STATE_ADDR(SMSM_APPS_STATE)); |
| 2279 | do_smd_probe(); |
| 2280 | notify_other_smsm(SMSM_APPS_STATE, (old_apps ^ apps)); |
| 2281 | } |
| 2282 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2283 | smsm_cb_snapshot(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2284 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2285 | spin_unlock_irqrestore(&smem_lock, flags); |
| 2286 | return IRQ_HANDLED; |
| 2287 | } |
| 2288 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2289 | int smsm_change_intr_mask(uint32_t smsm_entry, |
| 2290 | uint32_t clear_mask, uint32_t set_mask) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2291 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2292 | uint32_t old_mask, new_mask; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2293 | unsigned long flags; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2294 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2295 | if (smsm_entry >= SMSM_NUM_ENTRIES) { |
| 2296 | pr_err("smsm_change_state: Invalid entry %d\n", |
| 2297 | smsm_entry); |
| 2298 | return -EINVAL; |
| 2299 | } |
| 2300 | |
| 2301 | if (!smsm_info.intr_mask) { |
| 2302 | pr_err("smsm_change_intr_mask <SM NO STATE>\n"); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2303 | return -EIO; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2304 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2305 | |
| 2306 | spin_lock_irqsave(&smem_lock, flags); |
| 2307 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2308 | old_mask = __raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_APPS)); |
| 2309 | new_mask = (old_mask & ~clear_mask) | set_mask; |
| 2310 | __raw_writel(new_mask, SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_APPS)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2311 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2312 | wmb(); |
| 2313 | spin_unlock_irqrestore(&smem_lock, flags); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2314 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2315 | return 0; |
| 2316 | } |
| 2317 | EXPORT_SYMBOL(smsm_change_intr_mask); |
| 2318 | |
| 2319 | int smsm_get_intr_mask(uint32_t smsm_entry, uint32_t *intr_mask) |
| 2320 | { |
| 2321 | if (smsm_entry >= SMSM_NUM_ENTRIES) { |
| 2322 | pr_err("smsm_change_state: Invalid entry %d\n", |
| 2323 | smsm_entry); |
| 2324 | return -EINVAL; |
| 2325 | } |
| 2326 | |
| 2327 | if (!smsm_info.intr_mask) { |
| 2328 | pr_err("smsm_change_intr_mask <SM NO STATE>\n"); |
| 2329 | return -EIO; |
| 2330 | } |
| 2331 | |
| 2332 | *intr_mask = __raw_readl(SMSM_INTR_MASK_ADDR(smsm_entry, SMSM_APPS)); |
| 2333 | return 0; |
| 2334 | } |
| 2335 | EXPORT_SYMBOL(smsm_get_intr_mask); |
| 2336 | |
| 2337 | int smsm_change_state(uint32_t smsm_entry, |
| 2338 | uint32_t clear_mask, uint32_t set_mask) |
| 2339 | { |
| 2340 | unsigned long flags; |
| 2341 | uint32_t old_state, new_state; |
| 2342 | |
| 2343 | if (smsm_entry >= SMSM_NUM_ENTRIES) { |
| 2344 | pr_err("smsm_change_state: Invalid entry %d", |
| 2345 | smsm_entry); |
| 2346 | return -EINVAL; |
| 2347 | } |
| 2348 | |
| 2349 | if (!smsm_info.state) { |
| 2350 | pr_err("smsm_change_state <SM NO STATE>\n"); |
| 2351 | return -EIO; |
| 2352 | } |
| 2353 | spin_lock_irqsave(&smem_lock, flags); |
| 2354 | |
| 2355 | old_state = __raw_readl(SMSM_STATE_ADDR(smsm_entry)); |
| 2356 | new_state = (old_state & ~clear_mask) | set_mask; |
| 2357 | __raw_writel(new_state, SMSM_STATE_ADDR(smsm_entry)); |
| 2358 | SMSM_DBG("smsm_change_state %x\n", new_state); |
| 2359 | notify_other_smsm(SMSM_APPS_STATE, (old_state ^ new_state)); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2360 | |
| 2361 | spin_unlock_irqrestore(&smem_lock, flags); |
| 2362 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2363 | return 0; |
| 2364 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2365 | EXPORT_SYMBOL(smsm_change_state); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2366 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2367 | uint32_t smsm_get_state(uint32_t smsm_entry) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2368 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2369 | uint32_t rv = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2370 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2371 | /* needs interface change to return error code */ |
| 2372 | if (smsm_entry >= SMSM_NUM_ENTRIES) { |
| 2373 | pr_err("smsm_change_state: Invalid entry %d", |
| 2374 | smsm_entry); |
| 2375 | return 0; |
| 2376 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2377 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2378 | if (!smsm_info.state) { |
| 2379 | pr_err("smsm_get_state <SM NO STATE>\n"); |
| 2380 | } else { |
| 2381 | rv = __raw_readl(SMSM_STATE_ADDR(smsm_entry)); |
| 2382 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2383 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2384 | return rv; |
| 2385 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2386 | EXPORT_SYMBOL(smsm_get_state); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2387 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2388 | /** |
| 2389 | * Performs SMSM callback client notifiction. |
| 2390 | */ |
| 2391 | void notify_smsm_cb_clients_worker(struct work_struct *work) |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 2392 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2393 | struct smsm_state_cb_info *cb_info; |
| 2394 | struct smsm_state_info *state_info; |
| 2395 | int n; |
| 2396 | uint32_t new_state; |
| 2397 | uint32_t state_changes; |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2398 | int ret; |
| 2399 | int snapshot_size = SMSM_NUM_ENTRIES * sizeof(uint32_t); |
Brian Swetland | 03e00cd | 2009-07-01 17:58:37 -0700 | [diff] [blame] | 2400 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2401 | if (!smd_initialized) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2402 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2403 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2404 | while (kfifo_len(&smsm_snapshot_fifo) >= snapshot_size) { |
| 2405 | mutex_lock(&smsm_lock); |
| 2406 | for (n = 0; n < SMSM_NUM_ENTRIES; n++) { |
| 2407 | state_info = &smsm_states[n]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2408 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2409 | ret = kfifo_out(&smsm_snapshot_fifo, &new_state, |
| 2410 | sizeof(new_state)); |
| 2411 | if (ret != sizeof(new_state)) { |
| 2412 | pr_err("%s: snapshot underflow %d\n", |
| 2413 | __func__, ret); |
| 2414 | mutex_unlock(&smsm_lock); |
| 2415 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2416 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2417 | |
Eric Holmberg | c7e8daf | 2011-12-28 11:49:21 -0700 | [diff] [blame] | 2418 | state_changes = state_info->last_value ^ new_state; |
| 2419 | if (state_changes) { |
| 2420 | list_for_each_entry(cb_info, |
| 2421 | &state_info->callbacks, cb_list) { |
| 2422 | |
| 2423 | if (cb_info->mask & state_changes) |
| 2424 | cb_info->notify(cb_info->data, |
| 2425 | state_info->last_value, |
| 2426 | new_state); |
| 2427 | } |
| 2428 | state_info->last_value = new_state; |
| 2429 | } |
| 2430 | } |
| 2431 | mutex_unlock(&smsm_lock); |
| 2432 | } |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 2435 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2436 | /** |
| 2437 | * Registers callback for SMSM state notifications when the specified |
| 2438 | * bits change. |
| 2439 | * |
| 2440 | * @smsm_entry Processor entry to deregister |
| 2441 | * @mask Bits to deregister (if result is 0, callback is removed) |
| 2442 | * @notify Notification function to deregister |
| 2443 | * @data Opaque data passed in to callback |
| 2444 | * |
| 2445 | * @returns Status code |
| 2446 | * <0 error code |
| 2447 | * 0 inserted new entry |
| 2448 | * 1 updated mask of existing entry |
| 2449 | */ |
| 2450 | int smsm_state_cb_register(uint32_t smsm_entry, uint32_t mask, |
| 2451 | void (*notify)(void *, uint32_t, uint32_t), void *data) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2452 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2453 | struct smsm_state_cb_info *cb_info; |
| 2454 | struct smsm_state_cb_info *cb_found = 0; |
| 2455 | int ret = 0; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2456 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2457 | if (smsm_entry >= SMSM_NUM_ENTRIES) |
| 2458 | return -EINVAL; |
| 2459 | |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2460 | mutex_lock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2461 | |
| 2462 | if (!smsm_states) { |
| 2463 | /* smsm not yet initialized */ |
| 2464 | ret = -ENODEV; |
| 2465 | goto cleanup; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2466 | } |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2467 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2468 | list_for_each_entry(cb_info, |
| 2469 | &smsm_states[smsm_entry].callbacks, cb_list) { |
| 2470 | if ((cb_info->notify == notify) && |
| 2471 | (cb_info->data == data)) { |
| 2472 | cb_info->mask |= mask; |
| 2473 | cb_found = cb_info; |
| 2474 | ret = 1; |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2475 | break; |
| 2476 | } |
| 2477 | } |
| 2478 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2479 | if (!cb_found) { |
| 2480 | cb_info = kmalloc(sizeof(struct smsm_state_cb_info), |
| 2481 | GFP_ATOMIC); |
| 2482 | if (!cb_info) { |
| 2483 | ret = -ENOMEM; |
| 2484 | goto cleanup; |
| 2485 | } |
| 2486 | |
| 2487 | cb_info->mask = mask; |
| 2488 | cb_info->notify = notify; |
| 2489 | cb_info->data = data; |
| 2490 | INIT_LIST_HEAD(&cb_info->cb_list); |
| 2491 | list_add_tail(&cb_info->cb_list, |
| 2492 | &smsm_states[smsm_entry].callbacks); |
| 2493 | } |
| 2494 | |
| 2495 | cleanup: |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2496 | mutex_unlock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2497 | return ret; |
| 2498 | } |
| 2499 | EXPORT_SYMBOL(smsm_state_cb_register); |
| 2500 | |
| 2501 | |
| 2502 | /** |
| 2503 | * Deregisters for SMSM state notifications for the specified bits. |
| 2504 | * |
| 2505 | * @smsm_entry Processor entry to deregister |
| 2506 | * @mask Bits to deregister (if result is 0, callback is removed) |
| 2507 | * @notify Notification function to deregister |
| 2508 | * @data Opaque data passed in to callback |
| 2509 | * |
| 2510 | * @returns Status code |
| 2511 | * <0 error code |
| 2512 | * 0 not found |
| 2513 | * 1 updated mask |
| 2514 | * 2 removed callback |
| 2515 | */ |
| 2516 | int smsm_state_cb_deregister(uint32_t smsm_entry, uint32_t mask, |
| 2517 | void (*notify)(void *, uint32_t, uint32_t), void *data) |
| 2518 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2519 | struct smsm_state_cb_info *cb_info; |
| 2520 | int ret = 0; |
| 2521 | |
| 2522 | if (smsm_entry >= SMSM_NUM_ENTRIES) |
| 2523 | return -EINVAL; |
| 2524 | |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2525 | mutex_lock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2526 | |
| 2527 | if (!smsm_states) { |
| 2528 | /* smsm not yet initialized */ |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2529 | mutex_unlock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2530 | return -ENODEV; |
| 2531 | } |
| 2532 | |
| 2533 | list_for_each_entry(cb_info, |
| 2534 | &smsm_states[smsm_entry].callbacks, cb_list) { |
| 2535 | if ((cb_info->notify == notify) && |
| 2536 | (cb_info->data == data)) { |
| 2537 | cb_info->mask &= ~mask; |
| 2538 | ret = 1; |
| 2539 | if (!cb_info->mask) { |
| 2540 | /* no mask bits set, remove callback */ |
| 2541 | list_del(&cb_info->cb_list); |
| 2542 | kfree(cb_info); |
| 2543 | ret = 2; |
| 2544 | } |
| 2545 | break; |
| 2546 | } |
| 2547 | } |
| 2548 | |
Eric Holmberg | c800290 | 2011-09-16 13:55:57 -0600 | [diff] [blame] | 2549 | mutex_unlock(&smsm_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2550 | return ret; |
| 2551 | } |
| 2552 | EXPORT_SYMBOL(smsm_state_cb_deregister); |
| 2553 | |
| 2554 | |
| 2555 | int smd_core_init(void) |
| 2556 | { |
| 2557 | int r; |
| 2558 | unsigned long flags = IRQF_TRIGGER_RISING; |
| 2559 | SMD_INFO("smd_core_init()\n"); |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2560 | |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2561 | r = request_irq(INT_A9_M2A_0, smd_modem_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2562 | flags, "smd_dev", 0); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2563 | if (r < 0) |
| 2564 | return r; |
| 2565 | r = enable_irq_wake(INT_A9_M2A_0); |
| 2566 | if (r < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2567 | pr_err("smd_core_init: " |
| 2568 | "enable_irq_wake failed for INT_A9_M2A_0\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2569 | |
| 2570 | r = request_irq(INT_A9_M2A_5, smsm_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2571 | flags, "smsm_dev", 0); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2572 | if (r < 0) { |
| 2573 | free_irq(INT_A9_M2A_0, 0); |
| 2574 | return r; |
| 2575 | } |
| 2576 | r = enable_irq_wake(INT_A9_M2A_5); |
| 2577 | if (r < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2578 | pr_err("smd_core_init: " |
| 2579 | "enable_irq_wake failed for INT_A9_M2A_5\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2580 | |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2581 | #if defined(CONFIG_QDSP6) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2582 | #if (INT_ADSP_A11 == INT_ADSP_A11_SMSM) |
| 2583 | flags |= IRQF_SHARED; |
| 2584 | #endif |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2585 | r = request_irq(INT_ADSP_A11, smd_dsp_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2586 | flags, "smd_dev", smd_dsp_irq_handler); |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2587 | if (r < 0) { |
| 2588 | free_irq(INT_A9_M2A_0, 0); |
| 2589 | free_irq(INT_A9_M2A_5, 0); |
| 2590 | return r; |
| 2591 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2592 | |
| 2593 | r = request_irq(INT_ADSP_A11_SMSM, smsm_irq_handler, |
| 2594 | flags, "smsm_dev", smsm_irq_handler); |
| 2595 | if (r < 0) { |
| 2596 | free_irq(INT_A9_M2A_0, 0); |
| 2597 | free_irq(INT_A9_M2A_5, 0); |
| 2598 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
| 2599 | return r; |
| 2600 | } |
| 2601 | |
| 2602 | r = enable_irq_wake(INT_ADSP_A11); |
| 2603 | if (r < 0) |
| 2604 | pr_err("smd_core_init: " |
| 2605 | "enable_irq_wake failed for INT_ADSP_A11\n"); |
| 2606 | |
| 2607 | #if (INT_ADSP_A11 != INT_ADSP_A11_SMSM) |
| 2608 | r = enable_irq_wake(INT_ADSP_A11_SMSM); |
| 2609 | if (r < 0) |
| 2610 | pr_err("smd_core_init: enable_irq_wake " |
| 2611 | "failed for INT_ADSP_A11_SMSM\n"); |
| 2612 | #endif |
| 2613 | flags &= ~IRQF_SHARED; |
Brian Swetland | 37521a3 | 2009-07-01 18:30:47 -0700 | [diff] [blame] | 2614 | #endif |
| 2615 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2616 | #if defined(CONFIG_DSPS) |
| 2617 | r = request_irq(INT_DSPS_A11, smd_dsps_irq_handler, |
| 2618 | flags, "smd_dev", smd_dsps_irq_handler); |
| 2619 | if (r < 0) { |
| 2620 | free_irq(INT_A9_M2A_0, 0); |
| 2621 | free_irq(INT_A9_M2A_5, 0); |
| 2622 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
| 2623 | free_irq(INT_ADSP_A11_SMSM, smsm_irq_handler); |
| 2624 | return r; |
| 2625 | } |
Brian Swetland | 5b0f5a3 | 2009-04-26 18:38:49 -0700 | [diff] [blame] | 2626 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2627 | r = enable_irq_wake(INT_DSPS_A11); |
| 2628 | if (r < 0) |
| 2629 | pr_err("smd_core_init: " |
| 2630 | "enable_irq_wake failed for INT_ADSP_A11\n"); |
Arve Hjønnevåg | ec9d3d1 | 2009-06-16 14:48:21 -0700 | [diff] [blame] | 2631 | #endif |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2632 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2633 | #if defined(CONFIG_WCNSS) |
| 2634 | r = request_irq(INT_WCNSS_A11, smd_wcnss_irq_handler, |
| 2635 | flags, "smd_dev", smd_wcnss_irq_handler); |
| 2636 | if (r < 0) { |
| 2637 | free_irq(INT_A9_M2A_0, 0); |
| 2638 | free_irq(INT_A9_M2A_5, 0); |
| 2639 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
| 2640 | free_irq(INT_ADSP_A11_SMSM, smsm_irq_handler); |
| 2641 | free_irq(INT_DSPS_A11, smd_dsps_irq_handler); |
| 2642 | return r; |
| 2643 | } |
| 2644 | |
| 2645 | r = enable_irq_wake(INT_WCNSS_A11); |
| 2646 | if (r < 0) |
| 2647 | pr_err("smd_core_init: " |
| 2648 | "enable_irq_wake failed for INT_WCNSS_A11\n"); |
| 2649 | |
| 2650 | r = request_irq(INT_WCNSS_A11_SMSM, smsm_irq_handler, |
| 2651 | flags, "smsm_dev", smsm_irq_handler); |
| 2652 | if (r < 0) { |
| 2653 | free_irq(INT_A9_M2A_0, 0); |
| 2654 | free_irq(INT_A9_M2A_5, 0); |
| 2655 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
| 2656 | free_irq(INT_ADSP_A11_SMSM, smsm_irq_handler); |
| 2657 | free_irq(INT_DSPS_A11, smd_dsps_irq_handler); |
| 2658 | free_irq(INT_WCNSS_A11, smd_wcnss_irq_handler); |
| 2659 | return r; |
| 2660 | } |
| 2661 | |
| 2662 | r = enable_irq_wake(INT_WCNSS_A11_SMSM); |
| 2663 | if (r < 0) |
| 2664 | pr_err("smd_core_init: " |
| 2665 | "enable_irq_wake failed for INT_WCNSS_A11_SMSM\n"); |
| 2666 | #endif |
| 2667 | |
Jeff Hugo | 6a8057c | 2011-08-16 13:47:12 -0600 | [diff] [blame] | 2668 | #if defined(CONFIG_DSPS_SMSM) |
| 2669 | r = request_irq(INT_DSPS_A11_SMSM, smsm_irq_handler, |
| 2670 | flags, "smsm_dev", smsm_irq_handler); |
| 2671 | if (r < 0) { |
| 2672 | free_irq(INT_A9_M2A_0, 0); |
| 2673 | free_irq(INT_A9_M2A_5, 0); |
| 2674 | free_irq(INT_ADSP_A11, smd_dsp_irq_handler); |
| 2675 | free_irq(INT_ADSP_A11_SMSM, smsm_irq_handler); |
| 2676 | free_irq(INT_DSPS_A11, smd_dsps_irq_handler); |
| 2677 | free_irq(INT_WCNSS_A11, smd_wcnss_irq_handler); |
| 2678 | free_irq(INT_WCNSS_A11_SMSM, smsm_irq_handler); |
| 2679 | return r; |
| 2680 | } |
| 2681 | |
| 2682 | r = enable_irq_wake(INT_DSPS_A11_SMSM); |
| 2683 | if (r < 0) |
| 2684 | pr_err("smd_core_init: " |
| 2685 | "enable_irq_wake failed for INT_DSPS_A11_SMSM\n"); |
| 2686 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2687 | SMD_INFO("smd_core_init() done\n"); |
| 2688 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2689 | return 0; |
| 2690 | } |
| 2691 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 2692 | static int intr_init(struct interrupt_config_item *private_irq, |
| 2693 | struct smd_irq_config *platform_irq, |
| 2694 | struct platform_device *pdev |
| 2695 | ) |
| 2696 | { |
| 2697 | int irq_id; |
| 2698 | int ret; |
| 2699 | int ret_wake; |
| 2700 | |
| 2701 | private_irq->out_bit_pos = platform_irq->out_bit_pos; |
| 2702 | private_irq->out_offset = platform_irq->out_offset; |
| 2703 | private_irq->out_base = platform_irq->out_base; |
| 2704 | |
| 2705 | irq_id = platform_get_irq_byname( |
| 2706 | pdev, |
| 2707 | platform_irq->irq_name |
| 2708 | ); |
| 2709 | SMD_DBG("smd: %s: register irq: %s id: %d\n", __func__, |
| 2710 | platform_irq->irq_name, irq_id); |
| 2711 | ret = request_irq(irq_id, |
| 2712 | private_irq->irq_handler, |
| 2713 | platform_irq->flags, |
| 2714 | platform_irq->device_name, |
| 2715 | (void *)platform_irq->dev_id |
| 2716 | ); |
| 2717 | if (ret < 0) { |
| 2718 | platform_irq->irq_id = ret; |
| 2719 | } else { |
| 2720 | platform_irq->irq_id = irq_id; |
| 2721 | ret_wake = enable_irq_wake(irq_id); |
| 2722 | if (ret_wake < 0) { |
| 2723 | pr_err("smd: enable_irq_wake failed on %s", |
| 2724 | platform_irq->irq_name); |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | return ret; |
| 2729 | } |
| 2730 | |
| 2731 | int smd_core_platform_init(struct platform_device *pdev) |
| 2732 | { |
| 2733 | int i; |
| 2734 | int ret; |
| 2735 | uint32_t num_ss; |
| 2736 | struct smd_platform *smd_platform_data; |
| 2737 | struct smd_subsystem_config *smd_ss_config_list; |
| 2738 | struct smd_subsystem_config *cfg; |
| 2739 | int err_ret = 0; |
| 2740 | |
| 2741 | smd_platform_data = pdev->dev.platform_data; |
| 2742 | num_ss = smd_platform_data->num_ss_configs; |
| 2743 | smd_ss_config_list = smd_platform_data->smd_ss_configs; |
| 2744 | |
| 2745 | for (i = 0; i < num_ss; i++) { |
| 2746 | cfg = &smd_ss_config_list[i]; |
| 2747 | |
| 2748 | ret = intr_init( |
| 2749 | &private_intr_config[cfg->irq_config_id].smd, |
| 2750 | &cfg->smd_int, |
| 2751 | pdev |
| 2752 | ); |
| 2753 | |
| 2754 | if (ret < 0) { |
| 2755 | err_ret = ret; |
| 2756 | pr_err("smd: register irq failed on %s\n", |
| 2757 | cfg->smd_int.irq_name); |
| 2758 | break; |
| 2759 | } |
| 2760 | |
| 2761 | ret = intr_init( |
| 2762 | &private_intr_config[cfg->irq_config_id].smsm, |
| 2763 | &cfg->smsm_int, |
| 2764 | pdev |
| 2765 | ); |
| 2766 | |
| 2767 | if (ret < 0) { |
| 2768 | err_ret = ret; |
| 2769 | pr_err("smd: register irq failed on %s\n", |
| 2770 | cfg->smsm_int.irq_name); |
| 2771 | break; |
| 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | if (err_ret < 0) { |
| 2776 | pr_err("smd: deregistering IRQs\n"); |
| 2777 | for (i = 0; i < num_ss; ++i) { |
| 2778 | cfg = &smd_ss_config_list[i]; |
| 2779 | |
| 2780 | if (cfg->smd_int.irq_id >= 0) |
| 2781 | free_irq(cfg->smd_int.irq_id, |
| 2782 | (void *)cfg->smd_int.dev_id |
| 2783 | ); |
| 2784 | if (cfg->smsm_int.irq_id >= 0) |
| 2785 | free_irq(cfg->smsm_int.irq_id, |
| 2786 | (void *)cfg->smsm_int.dev_id |
| 2787 | ); |
| 2788 | } |
| 2789 | return err_ret; |
| 2790 | } |
| 2791 | |
| 2792 | SMD_INFO("smd_core_platform_init() done\n"); |
| 2793 | return 0; |
| 2794 | |
| 2795 | } |
| 2796 | |
Gregory Bean | 4416e9e | 2010-07-28 10:22:12 -0700 | [diff] [blame] | 2797 | static int __devinit msm_smd_probe(struct platform_device *pdev) |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2798 | { |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 2799 | int ret; |
Daniel Walker | 0aec66d | 2010-03-18 12:31:08 -0700 | [diff] [blame] | 2800 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 2801 | SMD_INFO("smd probe\n"); |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2802 | INIT_WORK(&probe_work, smd_channel_probe_worker); |
| 2803 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2804 | channel_close_wq = create_singlethread_workqueue("smd_channel_close"); |
| 2805 | if (IS_ERR(channel_close_wq)) { |
| 2806 | pr_err("%s: create_singlethread_workqueue ENOMEM\n", __func__); |
| 2807 | return -ENOMEM; |
| 2808 | } |
| 2809 | |
| 2810 | if (smsm_init()) { |
| 2811 | pr_err("smsm_init() failed\n"); |
| 2812 | return -1; |
| 2813 | } |
| 2814 | |
Angshuman Sarkar | bad32df | 2012-02-01 19:52:52 +0530 | [diff] [blame] | 2815 | if (pdev) { |
| 2816 | if (pdev->dev.of_node) { |
| 2817 | pr_err("SMD: Device tree not currently supported\n"); |
| 2818 | return -ENODEV; |
| 2819 | } else if (pdev->dev.platform_data) { |
| 2820 | ret = smd_core_platform_init(pdev); |
| 2821 | if (ret) { |
| 2822 | pr_err( |
| 2823 | "SMD: smd_core_platform_init() failed\n"); |
| 2824 | return -ENODEV; |
| 2825 | } |
| 2826 | } else { |
| 2827 | ret = smd_core_init(); |
| 2828 | if (ret) { |
| 2829 | pr_err("smd_core_init() failed\n"); |
| 2830 | return -ENODEV; |
| 2831 | } |
| 2832 | } |
| 2833 | } else { |
| 2834 | pr_err("SMD: PDEV not found\n"); |
| 2835 | return -ENODEV; |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2838 | smd_initialized = 1; |
| 2839 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2840 | smd_alloc_loopback_channel(); |
Eric Holmberg | c33d4ab | 2011-10-24 10:28:25 -0600 | [diff] [blame] | 2841 | smsm_irq_handler(0, 0); |
| 2842 | tasklet_schedule(&smd_fake_irq_tasklet); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2843 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2844 | return 0; |
| 2845 | } |
| 2846 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2847 | static int restart_notifier_cb(struct notifier_block *this, |
| 2848 | unsigned long code, |
| 2849 | void *data); |
| 2850 | |
| 2851 | static struct restart_notifier_block restart_notifiers[] = { |
Eric Holmberg | ca7ead2 | 2011-12-01 17:21:15 -0700 | [diff] [blame] | 2852 | {SMD_MODEM, "modem", .nb.notifier_call = restart_notifier_cb}, |
| 2853 | {SMD_Q6, "lpass", .nb.notifier_call = restart_notifier_cb}, |
| 2854 | {SMD_WCNSS, "riva", .nb.notifier_call = restart_notifier_cb}, |
| 2855 | {SMD_DSPS, "dsps", .nb.notifier_call = restart_notifier_cb}, |
Eric Holmberg | 8b0e74f | 2012-02-08 09:56:17 -0700 | [diff] [blame] | 2856 | {SMD_MODEM, "gss", .nb.notifier_call = restart_notifier_cb}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2857 | }; |
| 2858 | |
| 2859 | static int restart_notifier_cb(struct notifier_block *this, |
| 2860 | unsigned long code, |
| 2861 | void *data) |
| 2862 | { |
| 2863 | if (code == SUBSYS_AFTER_SHUTDOWN) { |
| 2864 | struct restart_notifier_block *notifier; |
| 2865 | |
| 2866 | notifier = container_of(this, |
| 2867 | struct restart_notifier_block, nb); |
| 2868 | SMD_INFO("%s: ssrestart for processor %d ('%s')\n", |
| 2869 | __func__, notifier->processor, |
| 2870 | notifier->name); |
| 2871 | |
| 2872 | smd_channel_reset(notifier->processor); |
| 2873 | } |
| 2874 | |
| 2875 | return NOTIFY_DONE; |
| 2876 | } |
| 2877 | |
| 2878 | static __init int modem_restart_late_init(void) |
| 2879 | { |
| 2880 | int i; |
| 2881 | void *handle; |
| 2882 | struct restart_notifier_block *nb; |
| 2883 | |
| 2884 | for (i = 0; i < ARRAY_SIZE(restart_notifiers); i++) { |
| 2885 | nb = &restart_notifiers[i]; |
| 2886 | handle = subsys_notif_register_notifier(nb->name, &nb->nb); |
| 2887 | SMD_DBG("%s: registering notif for '%s', handle=%p\n", |
| 2888 | __func__, nb->name, handle); |
| 2889 | } |
| 2890 | return 0; |
| 2891 | } |
| 2892 | late_initcall(modem_restart_late_init); |
| 2893 | |
Brian Swetland | 2eb44eb | 2008-09-29 16:00:48 -0700 | [diff] [blame] | 2894 | static struct platform_driver msm_smd_driver = { |
| 2895 | .probe = msm_smd_probe, |
| 2896 | .driver = { |
| 2897 | .name = MODULE_NAME, |
| 2898 | .owner = THIS_MODULE, |
| 2899 | }, |
| 2900 | }; |
| 2901 | |
| 2902 | static int __init msm_smd_init(void) |
| 2903 | { |
| 2904 | return platform_driver_register(&msm_smd_driver); |
| 2905 | } |
| 2906 | |
| 2907 | module_init(msm_smd_init); |
| 2908 | |
| 2909 | MODULE_DESCRIPTION("MSM Shared Memory Core"); |
| 2910 | MODULE_AUTHOR("Brian Swetland <swetland@google.com>"); |
| 2911 | MODULE_LICENSE("GPL"); |