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