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