| Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 13 | #define pr_fmt(fmt) "subsys-restart: %s(): " fmt, __func__ |
| 14 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/fs.h> |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/list.h> |
| 22 | #include <linux/io.h> |
| 23 | #include <linux/kthread.h> |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 24 | #include <linux/time.h> |
| Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 25 | #include <linux/wakelock.h> |
| 26 | #include <linux/suspend.h> |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 27 | #include <linux/mutex.h> |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 28 | #include <linux/slab.h> |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 29 | #include <linux/spinlock.h> |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | |
| 31 | #include <asm/current.h> |
| 32 | |
| 33 | #include <mach/peripheral-loader.h> |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | #include <mach/socinfo.h> |
| 35 | #include <mach/subsystem_notif.h> |
| 36 | #include <mach/subsystem_restart.h> |
| 37 | |
| 38 | #include "smd_private.h" |
| 39 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 40 | struct subsys_soc_restart_order { |
| 41 | const char * const *subsystem_list; |
| 42 | int count; |
| 43 | |
| 44 | struct mutex shutdown_lock; |
| 45 | struct mutex powerup_lock; |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 46 | struct subsys_device *subsys_ptrs[]; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 49 | struct restart_log { |
| 50 | struct timeval time; |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 51 | struct subsys_device *dev; |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 52 | struct list_head list; |
| 53 | }; |
| 54 | |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 55 | enum subsys_state { |
| 56 | SUBSYS_OFFLINE, |
| 57 | SUBSYS_ONLINE, |
| 58 | SUBSYS_CRASHED, |
| 59 | }; |
| 60 | |
| 61 | static const char * const subsys_states[] = { |
| 62 | [SUBSYS_OFFLINE] = "OFFLINE", |
| 63 | [SUBSYS_ONLINE] = "ONLINE", |
| 64 | [SUBSYS_CRASHED] = "CRASHED", |
| 65 | }; |
| 66 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 67 | struct subsys_device { |
| 68 | struct subsys_desc *desc; |
| 69 | struct list_head list; |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 70 | struct wake_lock wake_lock; |
| 71 | char wlname[64]; |
| 72 | struct work_struct work; |
| 73 | spinlock_t restart_lock; |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 74 | bool restarting; |
| 75 | enum subsys_state state; |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 76 | |
| 77 | void *notify; |
| 78 | |
| 79 | struct mutex shutdown_lock; |
| 80 | struct mutex powerup_lock; |
| 81 | |
| 82 | void *restart_order; |
| 83 | }; |
| 84 | |
| Jaeseong GIM | cbea936 | 2012-10-10 15:42:17 +0900 | [diff] [blame] | 85 | static int enable_ramdumps; |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 86 | module_param(enable_ramdumps, int, S_IRUGO | S_IWUSR); |
| 87 | |
| Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 88 | struct workqueue_struct *ssr_wq; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 89 | |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 90 | static LIST_HEAD(restart_log_list); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 91 | static LIST_HEAD(subsystem_list); |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 92 | static DEFINE_MUTEX(subsystem_list_lock); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 93 | static DEFINE_MUTEX(soc_order_reg_lock); |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 94 | static DEFINE_MUTEX(restart_log_mutex); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 95 | |
| 96 | /* SOC specific restart orders go here */ |
| 97 | |
| 98 | #define DEFINE_SINGLE_RESTART_ORDER(name, order) \ |
| 99 | static struct subsys_soc_restart_order __##name = { \ |
| 100 | .subsystem_list = order, \ |
| 101 | .count = ARRAY_SIZE(order), \ |
| 102 | .subsys_ptrs = {[ARRAY_SIZE(order)] = NULL} \ |
| 103 | }; \ |
| 104 | static struct subsys_soc_restart_order *name[] = { \ |
| 105 | &__##name, \ |
| 106 | } |
| 107 | |
| 108 | /* MSM 8x60 restart ordering info */ |
| 109 | static const char * const _order_8x60_all[] = { |
| 110 | "external_modem", "modem", "lpass" |
| 111 | }; |
| 112 | DEFINE_SINGLE_RESTART_ORDER(orders_8x60_all, _order_8x60_all); |
| 113 | |
| 114 | static const char * const _order_8x60_modems[] = {"external_modem", "modem"}; |
| 115 | DEFINE_SINGLE_RESTART_ORDER(orders_8x60_modems, _order_8x60_modems); |
| 116 | |
| Flemmard | 3394eca | 2013-04-15 00:20:20 -0700 | [diff] [blame] | 117 | #ifdef CONFIG_MACH_HTC |
| 118 | /* MSM 8960 restart ordering info */ |
| 119 | static const char * const order_8960[] = {"modem", "lpass"}; |
| 120 | |
| 121 | static struct subsys_soc_restart_order restart_orders_8960_one = { |
| 122 | .subsystem_list = order_8960, |
| 123 | .count = ARRAY_SIZE(order_8960), |
| 124 | .subsys_ptrs = {[ARRAY_SIZE(order_8960)] = NULL} |
| 125 | }; |
| 126 | |
| 127 | static struct subsys_soc_restart_order *restart_orders_8960[] = { |
| 128 | &restart_orders_8960_one, |
| 129 | }; |
| 130 | #else |
| Ameya Thakur | 2c0d2f2 | 2012-06-15 15:48:20 -0700 | [diff] [blame] | 131 | /*SGLTE restart ordering info*/ |
| 132 | static const char * const order_8960_sglte[] = {"external_modem", |
| 133 | "modem"}; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 134 | |
| Ameya Thakur | 2c0d2f2 | 2012-06-15 15:48:20 -0700 | [diff] [blame] | 135 | static struct subsys_soc_restart_order restart_orders_8960_fusion_sglte = { |
| 136 | .subsystem_list = order_8960_sglte, |
| 137 | .count = ARRAY_SIZE(order_8960_sglte), |
| 138 | .subsys_ptrs = {[ARRAY_SIZE(order_8960_sglte)] = NULL} |
| 139 | }; |
| 140 | |
| Ameya Thakur | 2c0d2f2 | 2012-06-15 15:48:20 -0700 | [diff] [blame] | 141 | static struct subsys_soc_restart_order *restart_orders_8960_sglte[] = { |
| 142 | &restart_orders_8960_fusion_sglte, |
| 143 | }; |
| Flemmard | 3394eca | 2013-04-15 00:20:20 -0700 | [diff] [blame] | 144 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 145 | |
| Joel King | e4f9890 | 2013-03-25 13:12:27 -0700 | [diff] [blame] | 146 | /* SGLTE2 restart ordering info*/ |
| 147 | static const char * const order_8064_sglte2[] = {"external_modem", |
| 148 | "external_modem_mdm"}; |
| 149 | |
| 150 | static struct subsys_soc_restart_order restart_orders_8064_fusion_sglte2 = { |
| 151 | .subsystem_list = order_8064_sglte2, |
| 152 | .count = ARRAY_SIZE(order_8064_sglte2), |
| 153 | .subsys_ptrs = {[ARRAY_SIZE(order_8064_sglte2)] = NULL} |
| 154 | }; |
| 155 | |
| 156 | static struct subsys_soc_restart_order *restart_orders_8064_sglte2[] = { |
| 157 | &restart_orders_8064_fusion_sglte2, |
| 158 | }; |
| 159 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 160 | /* These will be assigned to one of the sets above after |
| 161 | * runtime SoC identification. |
| 162 | */ |
| 163 | static struct subsys_soc_restart_order **restart_orders; |
| 164 | static int n_restart_orders; |
| 165 | |
| Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 166 | static int restart_level = RESET_SUBSYS_INDEPENDENT; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 167 | |
| 168 | int get_restart_level() |
| 169 | { |
| 170 | return restart_level; |
| 171 | } |
| 172 | EXPORT_SYMBOL(get_restart_level); |
| 173 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | static int restart_level_set(const char *val, struct kernel_param *kp) |
| 175 | { |
| 176 | int ret; |
| 177 | int old_val = restart_level; |
| Joel King | 4e20429 | 2013-04-16 12:48:51 -0700 | [diff] [blame] | 178 | int subtype; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 179 | |
| Rohit Vaswani | 56dd22a | 2011-11-11 16:21:28 -0800 | [diff] [blame] | 180 | if (cpu_is_msm9615()) { |
| 181 | pr_err("Only Phase 1 subsystem restart is supported\n"); |
| 182 | return -EINVAL; |
| 183 | } |
| 184 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 185 | ret = param_set_int(val, kp); |
| 186 | if (ret) |
| 187 | return ret; |
| 188 | |
| 189 | switch (restart_level) { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 190 | case RESET_SUBSYS_INDEPENDENT: |
| Joel King | 4e20429 | 2013-04-16 12:48:51 -0700 | [diff] [blame] | 191 | subtype = socinfo_get_platform_subtype(); |
| 192 | if ((subtype == PLATFORM_SUBTYPE_SGLTE) || |
| 193 | (subtype == PLATFORM_SUBTYPE_SGLTE2)) { |
| Vikram Mulukutla | f68456d | 2012-07-27 15:14:10 -0700 | [diff] [blame] | 194 | pr_info("Phase 3 is currently unsupported. Using phase 2 instead.\n"); |
| 195 | restart_level = RESET_SUBSYS_COUPLED; |
| 196 | } |
| 197 | case RESET_SUBSYS_COUPLED: |
| 198 | case RESET_SOC: |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 199 | pr_info("Phase %d behavior activated.\n", restart_level); |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 200 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 201 | default: |
| 202 | restart_level = old_val; |
| 203 | return -EINVAL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 204 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | module_param_call(restart_level, restart_level_set, param_get_int, |
| 209 | &restart_level, 0644); |
| 210 | |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 211 | static void subsys_set_state(struct subsys_device *subsys, |
| 212 | enum subsys_state state) |
| 213 | { |
| 214 | unsigned long flags; |
| 215 | |
| 216 | spin_lock_irqsave(&subsys->restart_lock, flags); |
| 217 | if (subsys->state != state) { |
| 218 | subsys->state = state; |
| 219 | spin_unlock_irqrestore(&subsys->restart_lock, flags); |
| 220 | return; |
| 221 | } |
| 222 | spin_unlock_irqrestore(&subsys->restart_lock, flags); |
| 223 | } |
| 224 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 225 | static struct subsys_soc_restart_order * |
| 226 | update_restart_order(struct subsys_device *dev) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 227 | { |
| 228 | int i, j; |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 229 | struct subsys_soc_restart_order *order; |
| 230 | const char *name = dev->desc->name; |
| 231 | int len = SUBSYS_NAME_MAX_LENGTH; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 232 | |
| 233 | mutex_lock(&soc_order_reg_lock); |
| 234 | for (j = 0; j < n_restart_orders; j++) { |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 235 | order = restart_orders[j]; |
| 236 | for (i = 0; i < order->count; i++) { |
| 237 | if (!strncmp(order->subsystem_list[i], name, len)) { |
| 238 | order->subsys_ptrs[i] = dev; |
| 239 | goto found; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 240 | } |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 241 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 242 | } |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 243 | order = NULL; |
| 244 | found: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 245 | mutex_unlock(&soc_order_reg_lock); |
| 246 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 247 | return order; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 250 | static int max_restarts; |
| 251 | module_param(max_restarts, int, 0644); |
| 252 | |
| 253 | static long max_history_time = 3600; |
| 254 | module_param(max_history_time, long, 0644); |
| 255 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 256 | static void do_epoch_check(struct subsys_device *dev) |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 257 | { |
| 258 | int n = 0; |
| Jordan Crouse | 75a25ca | 2011-09-09 12:49:57 -0600 | [diff] [blame] | 259 | struct timeval *time_first = NULL, *curr_time; |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 260 | struct restart_log *r_log, *temp; |
| 261 | static int max_restarts_check; |
| 262 | static long max_history_time_check; |
| 263 | |
| 264 | mutex_lock(&restart_log_mutex); |
| 265 | |
| 266 | max_restarts_check = max_restarts; |
| 267 | max_history_time_check = max_history_time; |
| 268 | |
| 269 | /* Check if epoch checking is enabled */ |
| 270 | if (!max_restarts_check) |
| Vikram Mulukutla | 7a28909 | 2011-09-14 10:08:36 -0700 | [diff] [blame] | 271 | goto out; |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 272 | |
| 273 | r_log = kmalloc(sizeof(struct restart_log), GFP_KERNEL); |
| Matt Wagantall | eecca34 | 2011-11-10 20:12:05 -0800 | [diff] [blame] | 274 | if (!r_log) |
| 275 | goto out; |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 276 | r_log->dev = dev; |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 277 | do_gettimeofday(&r_log->time); |
| 278 | curr_time = &r_log->time; |
| 279 | INIT_LIST_HEAD(&r_log->list); |
| 280 | |
| 281 | list_add_tail(&r_log->list, &restart_log_list); |
| 282 | |
| 283 | list_for_each_entry_safe(r_log, temp, &restart_log_list, list) { |
| 284 | |
| 285 | if ((curr_time->tv_sec - r_log->time.tv_sec) > |
| 286 | max_history_time_check) { |
| 287 | |
| 288 | pr_debug("Deleted node with restart_time = %ld\n", |
| 289 | r_log->time.tv_sec); |
| 290 | list_del(&r_log->list); |
| 291 | kfree(r_log); |
| 292 | continue; |
| 293 | } |
| 294 | if (!n) { |
| 295 | time_first = &r_log->time; |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 296 | pr_debug("Time_first: %ld\n", time_first->tv_sec); |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 297 | } |
| 298 | n++; |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 299 | pr_debug("Restart_time: %ld\n", r_log->time.tv_sec); |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| Jordan Crouse | 75a25ca | 2011-09-09 12:49:57 -0600 | [diff] [blame] | 302 | if (time_first && n >= max_restarts_check) { |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 303 | if ((curr_time->tv_sec - time_first->tv_sec) < |
| Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 304 | max_history_time_check) { |
| Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 305 | panic("Subsystems have crashed %d times in less than "\ |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 306 | "%ld seconds!", max_restarts_check, |
| 307 | max_history_time_check); |
| Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 308 | } |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| Vikram Mulukutla | 7a28909 | 2011-09-14 10:08:36 -0700 | [diff] [blame] | 311 | out: |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 312 | mutex_unlock(&restart_log_mutex); |
| 313 | } |
| 314 | |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 315 | static void for_each_subsys_device(struct subsys_device **list, unsigned count, |
| 316 | void *data, void (*fn)(struct subsys_device *, void *)) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 317 | { |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 318 | while (count--) { |
| 319 | struct subsys_device *dev = *list++; |
| 320 | if (!dev) |
| 321 | continue; |
| 322 | fn(dev, data); |
| 323 | } |
| 324 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 325 | |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 326 | static void __send_notification_to_order(struct subsys_device *dev, void *data) |
| 327 | { |
| 328 | enum subsys_notif_type type = (enum subsys_notif_type)data; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 329 | |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 330 | subsys_notif_queue_notification(dev->notify, type); |
| 331 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 332 | |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 333 | static void send_notification_to_order(struct subsys_device **l, unsigned n, |
| 334 | enum subsys_notif_type t) |
| 335 | { |
| 336 | for_each_subsys_device(l, n, (void *)t, __send_notification_to_order); |
| 337 | } |
| 338 | |
| 339 | static void subsystem_shutdown(struct subsys_device *dev, void *data) |
| 340 | { |
| 341 | const char *name = dev->desc->name; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 342 | |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 343 | pr_info("[%p]: Shutting down %s\n", current, name); |
| Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 344 | if (dev->desc->shutdown(dev->desc) < 0) { |
| Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 345 | panic("subsys-restart: [%p]: Failed to shutdown %s!", |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 346 | current, name); |
| Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 347 | } |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 348 | subsys_set_state(dev, SUBSYS_OFFLINE); |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void subsystem_ramdump(struct subsys_device *dev, void *data) |
| 352 | { |
| 353 | const char *name = dev->desc->name; |
| 354 | |
| 355 | if (dev->desc->ramdump) |
| 356 | if (dev->desc->ramdump(enable_ramdumps, dev->desc) < 0) |
| 357 | pr_warn("%s[%p]: Ramdump failed.\n", name, current); |
| 358 | } |
| 359 | |
| 360 | static void subsystem_powerup(struct subsys_device *dev, void *data) |
| 361 | { |
| 362 | const char *name = dev->desc->name; |
| 363 | |
| 364 | pr_info("[%p]: Powering up %s\n", current, name); |
| Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 365 | if (dev->desc->powerup(dev->desc) < 0) { |
| Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 366 | panic("[%p]: Failed to powerup %s!", current, name); |
| Brian Muramatsu | 0f0df2f | 2012-08-01 23:30:40 -0700 | [diff] [blame] | 367 | } |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 368 | subsys_set_state(dev, SUBSYS_ONLINE); |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 371 | static void subsystem_restart_wq_func(struct work_struct *work) |
| 372 | { |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 373 | struct subsys_device *dev = container_of(work, |
| 374 | struct subsys_device, work); |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 375 | struct subsys_device **list; |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 376 | struct subsys_desc *desc = dev->desc; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 377 | struct subsys_soc_restart_order *soc_restart_order = NULL; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 378 | struct mutex *powerup_lock; |
| 379 | struct mutex *shutdown_lock; |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 380 | unsigned count; |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 381 | unsigned long flags; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 382 | |
| Stephen Boyd | a82ee08 | 2012-06-21 12:35:49 -0700 | [diff] [blame] | 383 | if (restart_level != RESET_SUBSYS_INDEPENDENT) |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 384 | soc_restart_order = dev->restart_order; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 385 | |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 386 | /* |
| 387 | * It's OK to not take the registration lock at this point. |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 388 | * This is because the subsystem list inside the relevant |
| 389 | * restart order is not being traversed. |
| 390 | */ |
| 391 | if (!soc_restart_order) { |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 392 | list = &dev; |
| 393 | count = 1; |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 394 | powerup_lock = &dev->powerup_lock; |
| 395 | shutdown_lock = &dev->shutdown_lock; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 396 | } else { |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 397 | list = soc_restart_order->subsys_ptrs; |
| 398 | count = soc_restart_order->count; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 399 | powerup_lock = &soc_restart_order->powerup_lock; |
| 400 | shutdown_lock = &soc_restart_order->shutdown_lock; |
| 401 | } |
| 402 | |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 403 | pr_debug("[%p]: Attempting to get shutdown lock!\n", current); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 404 | |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 405 | /* |
| 406 | * Try to acquire shutdown_lock. If this fails, these subsystems are |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 407 | * already being restarted - return. |
| 408 | */ |
| Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 409 | if (!mutex_trylock(shutdown_lock)) |
| 410 | goto out; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 411 | |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 412 | pr_debug("[%p]: Attempting to get powerup lock!\n", current); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 413 | |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 414 | /* |
| 415 | * Now that we've acquired the shutdown lock, either we're the first to |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 416 | * restart these subsystems or some other thread is doing the powerup |
| 417 | * sequence for these subsystems. In the latter case, panic and bail |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 418 | * out, since a subsystem died in its powerup sequence. This catches |
| 419 | * the case where a subsystem in a restart order isn't the one |
| 420 | * who initiated the original restart but has crashed while the restart |
| 421 | * order is being rebooted. |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 422 | */ |
| Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 423 | if (!mutex_trylock(powerup_lock)) { |
| Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 424 | panic("%s[%p]: Subsystem died during powerup!", |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 425 | __func__, current); |
| Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 426 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 427 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 428 | do_epoch_check(dev); |
| Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 429 | |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 430 | /* |
| 431 | * It's necessary to take the registration lock because the subsystem |
| 432 | * list in the SoC restart order will be traversed and it shouldn't be |
| 433 | * changed until _this_ restart sequence completes. |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 434 | */ |
| 435 | mutex_lock(&soc_order_reg_lock); |
| 436 | |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 437 | pr_debug("[%p]: Starting restart sequence for %s\n", current, |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 438 | desc->name); |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 439 | send_notification_to_order(list, count, SUBSYS_BEFORE_SHUTDOWN); |
| 440 | for_each_subsys_device(list, count, NULL, subsystem_shutdown); |
| 441 | send_notification_to_order(list, count, SUBSYS_AFTER_SHUTDOWN); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 442 | |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 443 | /* |
| 444 | * Now that we've finished shutting down these subsystems, release the |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 445 | * shutdown lock. If a subsystem restart request comes in for a |
| 446 | * subsystem in _this_ restart order after the unlock below, and |
| 447 | * before the powerup lock is released, panic and bail out. |
| 448 | */ |
| 449 | mutex_unlock(shutdown_lock); |
| 450 | |
| 451 | /* Collect ram dumps for all subsystems in order here */ |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 452 | for_each_subsys_device(list, count, NULL, subsystem_ramdump); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 453 | |
| Stephen Boyd | 0daae15 | 2012-05-01 17:36:15 -0700 | [diff] [blame] | 454 | send_notification_to_order(list, count, SUBSYS_BEFORE_POWERUP); |
| 455 | for_each_subsys_device(list, count, NULL, subsystem_powerup); |
| 456 | send_notification_to_order(list, count, SUBSYS_AFTER_POWERUP); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 457 | |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 458 | pr_info("[%p]: Restart sequence for %s completed.\n", |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 459 | current, desc->name); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 460 | |
| 461 | mutex_unlock(powerup_lock); |
| 462 | |
| 463 | mutex_unlock(&soc_order_reg_lock); |
| 464 | |
| Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 465 | pr_debug("[%p]: Released powerup lock!\n", current); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 466 | |
| Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 467 | out: |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 468 | spin_lock_irqsave(&dev->restart_lock, flags); |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 469 | dev->restarting = false; |
| 470 | wake_unlock(&dev->wake_lock); |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 471 | spin_unlock_irqrestore(&dev->restart_lock, flags); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 474 | static void __subsystem_restart_dev(struct subsys_device *dev) |
| Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 475 | { |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 476 | struct subsys_desc *desc = dev->desc; |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 477 | const char *name = dev->desc->name; |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 478 | unsigned long flags; |
| Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 479 | |
| Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 480 | pr_debug("Restarting %s [level=%d]!\n", desc->name, restart_level); |
| Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 481 | |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 482 | /* |
| 483 | * We want to allow drivers to call subsystem_restart{_dev}() as many |
| 484 | * times as they want up until the point where the subsystem is |
| 485 | * shutdown. |
| 486 | */ |
| Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 487 | spin_lock_irqsave(&dev->restart_lock, flags); |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 488 | if (dev->state != SUBSYS_CRASHED) { |
| 489 | if (dev->state == SUBSYS_ONLINE && !dev->restarting) { |
| 490 | dev->restarting = true; |
| 491 | dev->state = SUBSYS_CRASHED; |
| 492 | wake_lock(&dev->wake_lock); |
| 493 | queue_work(ssr_wq, &dev->work); |
| 494 | } else { |
| 495 | panic("Subsystem %s crashed during SSR!", name); |
| 496 | } |
| Stephen Boyd | 77c2274 | 2012-07-24 18:46:45 -0700 | [diff] [blame] | 497 | } |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 498 | spin_unlock_irqrestore(&dev->restart_lock, flags); |
| Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 501 | int subsystem_restart_dev(struct subsys_device *dev) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 502 | { |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 503 | const char *name = dev->desc->name; |
| Vikram Mulukutla | 3944eff | 2012-10-29 18:43:02 -0700 | [diff] [blame] | 504 | |
| 505 | /* |
| 506 | * If a system reboot/shutdown is underway, ignore subsystem errors. |
| 507 | * However, print a message so that we know that a subsystem behaved |
| 508 | * unexpectedly here. |
| 509 | */ |
| 510 | if (system_state == SYSTEM_RESTART |
| 511 | || system_state == SYSTEM_POWER_OFF) { |
| 512 | pr_err("%s crashed during a system poweroff/shutdown.\n", name); |
| 513 | return -EBUSY; |
| 514 | } |
| 515 | |
| Vikram Mulukutla | 3b24c8c | 2011-12-02 15:12:53 -0800 | [diff] [blame] | 516 | pr_info("Restart sequence requested for %s, restart_level = %d.\n", |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 517 | name, restart_level); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 518 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 519 | switch (restart_level) { |
| 520 | |
| 521 | case RESET_SUBSYS_COUPLED: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 522 | case RESET_SUBSYS_INDEPENDENT: |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 523 | __subsystem_restart_dev(dev); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 524 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 525 | case RESET_SOC: |
| Ameya Thakur | 97d4114 | 2012-12-05 17:04:52 -0800 | [diff] [blame] | 526 | panic("subsys-restart: Resetting the SoC - %s crashed.", name); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 527 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 528 | default: |
| Ameya Thakur | 97d4114 | 2012-12-05 17:04:52 -0800 | [diff] [blame] | 529 | panic("subsys-restart: Unknown restart level!\n"); |
| Stephen Boyd | c68ee64 | 2012-05-01 17:02:45 -0700 | [diff] [blame] | 530 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | return 0; |
| 534 | } |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 535 | EXPORT_SYMBOL(subsystem_restart_dev); |
| 536 | |
| 537 | int subsystem_restart(const char *name) |
| 538 | { |
| 539 | struct subsys_device *dev; |
| 540 | |
| 541 | mutex_lock(&subsystem_list_lock); |
| 542 | list_for_each_entry(dev, &subsystem_list, list) |
| 543 | if (!strncmp(dev->desc->name, name, SUBSYS_NAME_MAX_LENGTH)) |
| 544 | goto found; |
| 545 | dev = NULL; |
| 546 | found: |
| 547 | mutex_unlock(&subsystem_list_lock); |
| 548 | if (dev) |
| 549 | return subsystem_restart_dev(dev); |
| 550 | return -ENODEV; |
| 551 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 552 | EXPORT_SYMBOL(subsystem_restart); |
| 553 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 554 | struct subsys_device *subsys_register(struct subsys_desc *desc) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 555 | { |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 556 | struct subsys_device *dev; |
| Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 557 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 558 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 559 | if (!dev) |
| 560 | return ERR_PTR(-ENOMEM); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 561 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 562 | dev->desc = desc; |
| 563 | dev->notify = subsys_notif_add_subsys(desc->name); |
| 564 | dev->restart_order = update_restart_order(dev); |
| Stephen Boyd | 8f57c0f | 2012-09-18 11:31:02 -0700 | [diff] [blame] | 565 | dev->state = SUBSYS_ONLINE; /* Until proper refcounting appears */ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 566 | |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 567 | snprintf(dev->wlname, sizeof(dev->wlname), "ssr(%s)", desc->name); |
| 568 | wake_lock_init(&dev->wake_lock, WAKE_LOCK_SUSPEND, dev->wlname); |
| 569 | INIT_WORK(&dev->work, subsystem_restart_wq_func); |
| 570 | spin_lock_init(&dev->restart_lock); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 571 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 572 | mutex_init(&dev->shutdown_lock); |
| 573 | mutex_init(&dev->powerup_lock); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 574 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 575 | mutex_lock(&subsystem_list_lock); |
| 576 | list_add(&dev->list, &subsystem_list); |
| 577 | mutex_unlock(&subsystem_list_lock); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 578 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 579 | return dev; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 580 | } |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 581 | EXPORT_SYMBOL(subsys_register); |
| 582 | |
| 583 | void subsys_unregister(struct subsys_device *dev) |
| 584 | { |
| 585 | if (IS_ERR_OR_NULL(dev)) |
| 586 | return; |
| 587 | mutex_lock(&subsystem_list_lock); |
| 588 | list_del(&dev->list); |
| 589 | mutex_unlock(&subsystem_list_lock); |
| Stephen Boyd | 497ef40 | 2012-06-21 12:54:40 -0700 | [diff] [blame] | 590 | wake_lock_destroy(&dev->wake_lock); |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 591 | kfree(dev); |
| 592 | } |
| 593 | EXPORT_SYMBOL(subsys_unregister); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 594 | |
| Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 595 | static int ssr_panic_handler(struct notifier_block *this, |
| 596 | unsigned long event, void *ptr) |
| 597 | { |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 598 | struct subsys_device *dev; |
| Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 599 | |
| Stephen Boyd | 0ebf721 | 2012-04-30 20:42:35 -0700 | [diff] [blame] | 600 | list_for_each_entry(dev, &subsystem_list, list) |
| 601 | if (dev->desc->crash_shutdown) |
| 602 | dev->desc->crash_shutdown(dev->desc); |
| Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 603 | return NOTIFY_DONE; |
| 604 | } |
| 605 | |
| 606 | static struct notifier_block panic_nb = { |
| 607 | .notifier_call = ssr_panic_handler, |
| 608 | }; |
| 609 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 610 | static int __init ssr_init_soc_restart_orders(void) |
| 611 | { |
| 612 | int i; |
| 613 | |
| Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 614 | atomic_notifier_chain_register(&panic_notifier_list, |
| 615 | &panic_nb); |
| 616 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 617 | if (cpu_is_msm8x60()) { |
| 618 | for (i = 0; i < ARRAY_SIZE(orders_8x60_all); i++) { |
| 619 | mutex_init(&orders_8x60_all[i]->powerup_lock); |
| 620 | mutex_init(&orders_8x60_all[i]->shutdown_lock); |
| 621 | } |
| 622 | |
| 623 | for (i = 0; i < ARRAY_SIZE(orders_8x60_modems); i++) { |
| 624 | mutex_init(&orders_8x60_modems[i]->powerup_lock); |
| 625 | mutex_init(&orders_8x60_modems[i]->shutdown_lock); |
| 626 | } |
| 627 | |
| 628 | restart_orders = orders_8x60_all; |
| 629 | n_restart_orders = ARRAY_SIZE(orders_8x60_all); |
| 630 | } |
| 631 | |
| Flemmard | 3394eca | 2013-04-15 00:20:20 -0700 | [diff] [blame] | 632 | #ifdef CONFIG_MACH_HTC |
| 633 | restart_orders = restart_orders_8960; |
| 634 | n_restart_orders = ARRAY_SIZE(restart_orders_8960); |
| 635 | #else |
| Vikram Mulukutla | f68456d | 2012-07-27 15:14:10 -0700 | [diff] [blame] | 636 | if (socinfo_get_platform_subtype() == PLATFORM_SUBTYPE_SGLTE) { |
| 637 | restart_orders = restart_orders_8960_sglte; |
| 638 | n_restart_orders = ARRAY_SIZE(restart_orders_8960_sglte); |
| 639 | } |
| Flemmard | 3394eca | 2013-04-15 00:20:20 -0700 | [diff] [blame] | 640 | #endif |
| Vikram Mulukutla | f68456d | 2012-07-27 15:14:10 -0700 | [diff] [blame] | 641 | |
| Joel King | e4f9890 | 2013-03-25 13:12:27 -0700 | [diff] [blame] | 642 | if (socinfo_get_platform_subtype() == PLATFORM_SUBTYPE_SGLTE2) { |
| 643 | restart_orders = restart_orders_8064_sglte2; |
| 644 | n_restart_orders = ARRAY_SIZE(restart_orders_8064_sglte2); |
| 645 | } |
| 646 | |
| Vikram Mulukutla | f68456d | 2012-07-27 15:14:10 -0700 | [diff] [blame] | 647 | for (i = 0; i < n_restart_orders; i++) { |
| 648 | mutex_init(&restart_orders[i]->powerup_lock); |
| 649 | mutex_init(&restart_orders[i]->shutdown_lock); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | if (restart_orders == NULL || n_restart_orders < 1) { |
| 653 | WARN_ON(1); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static int __init subsys_restart_init(void) |
| 660 | { |
| Vikram Mulukutla | 372e15a | 2013-01-22 10:51:17 -0800 | [diff] [blame] | 661 | restart_level = RESET_SOC; |
| 662 | |
| Vikram Mulukutla | 99f84eff | 2012-09-10 19:25:32 -0700 | [diff] [blame] | 663 | ssr_wq = alloc_workqueue("ssr_wq", WQ_CPU_INTENSIVE, 0); |
| Vikram Mulukutla | 0ad34f6 | 2013-01-22 11:01:13 -0800 | [diff] [blame] | 664 | if (!ssr_wq) |
| 665 | panic("%s: out of memory\n", __func__); |
| Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 666 | |
| Iliyan Malchev | a0899ce | 2012-06-29 15:28:25 -0700 | [diff] [blame] | 667 | return ssr_init_soc_restart_orders(); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 668 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 669 | arch_initcall(subsys_restart_init); |
| 670 | |
| 671 | MODULE_DESCRIPTION("Subsystem Restart Driver"); |
| 672 | MODULE_LICENSE("GPL v2"); |