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