Rohit Vaswani | d0fb418 | 2012-03-19 18:07:59 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. 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> |
| 20 | #include <linux/proc_fs.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/list.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <linux/kthread.h> |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 25 | #include <linux/time.h> |
Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 26 | #include <linux/wakelock.h> |
| 27 | #include <linux/suspend.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | |
| 29 | #include <asm/current.h> |
| 30 | |
| 31 | #include <mach/peripheral-loader.h> |
| 32 | #include <mach/scm.h> |
| 33 | #include <mach/socinfo.h> |
| 34 | #include <mach/subsystem_notif.h> |
| 35 | #include <mach/subsystem_restart.h> |
| 36 | |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 37 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 38 | #include <mach/restart.h> |
| 39 | #include <mach/board_lge.h> |
| 40 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | #include "smd_private.h" |
| 42 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 43 | struct subsys_soc_restart_order { |
| 44 | const char * const *subsystem_list; |
| 45 | int count; |
| 46 | |
| 47 | struct mutex shutdown_lock; |
| 48 | struct mutex powerup_lock; |
| 49 | struct subsys_data *subsys_ptrs[]; |
| 50 | }; |
| 51 | |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 52 | struct restart_wq_data { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 53 | struct subsys_data *subsys; |
Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 54 | struct wake_lock ssr_wake_lock; |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 55 | char wlname[64]; |
| 56 | int use_restart_order; |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 57 | struct work_struct work; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 60 | struct restart_log { |
| 61 | struct timeval time; |
| 62 | struct subsys_data *subsys; |
| 63 | struct list_head list; |
| 64 | }; |
| 65 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 66 | static int restart_level; |
jihyun.lee | 20b1ec0 | 2012-06-29 09:23:58 -0700 | [diff] [blame^] | 67 | static int enable_ramdumps = 1; |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 68 | struct workqueue_struct *ssr_wq; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 69 | |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 70 | static LIST_HEAD(restart_log_list); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 71 | static LIST_HEAD(subsystem_list); |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 72 | static DEFINE_SPINLOCK(subsystem_list_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 73 | static DEFINE_MUTEX(soc_order_reg_lock); |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 74 | static DEFINE_MUTEX(restart_log_mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | |
| 76 | /* SOC specific restart orders go here */ |
| 77 | |
| 78 | #define DEFINE_SINGLE_RESTART_ORDER(name, order) \ |
| 79 | static struct subsys_soc_restart_order __##name = { \ |
| 80 | .subsystem_list = order, \ |
| 81 | .count = ARRAY_SIZE(order), \ |
| 82 | .subsys_ptrs = {[ARRAY_SIZE(order)] = NULL} \ |
| 83 | }; \ |
| 84 | static struct subsys_soc_restart_order *name[] = { \ |
| 85 | &__##name, \ |
| 86 | } |
| 87 | |
| 88 | /* MSM 8x60 restart ordering info */ |
| 89 | static const char * const _order_8x60_all[] = { |
| 90 | "external_modem", "modem", "lpass" |
| 91 | }; |
| 92 | DEFINE_SINGLE_RESTART_ORDER(orders_8x60_all, _order_8x60_all); |
| 93 | |
| 94 | static const char * const _order_8x60_modems[] = {"external_modem", "modem"}; |
| 95 | DEFINE_SINGLE_RESTART_ORDER(orders_8x60_modems, _order_8x60_modems); |
| 96 | |
| 97 | /* MSM 8960 restart ordering info */ |
| 98 | static const char * const order_8960[] = {"modem", "lpass"}; |
| 99 | |
| 100 | static struct subsys_soc_restart_order restart_orders_8960_one = { |
| 101 | .subsystem_list = order_8960, |
| 102 | .count = ARRAY_SIZE(order_8960), |
| 103 | .subsys_ptrs = {[ARRAY_SIZE(order_8960)] = NULL} |
| 104 | }; |
| 105 | |
| 106 | static struct subsys_soc_restart_order *restart_orders_8960[] = { |
| 107 | &restart_orders_8960_one, |
| 108 | }; |
| 109 | |
| 110 | /* These will be assigned to one of the sets above after |
| 111 | * runtime SoC identification. |
| 112 | */ |
| 113 | static struct subsys_soc_restart_order **restart_orders; |
| 114 | static int n_restart_orders; |
| 115 | |
| 116 | module_param(enable_ramdumps, int, S_IRUGO | S_IWUSR); |
| 117 | |
| 118 | static struct subsys_soc_restart_order *_update_restart_order( |
| 119 | struct subsys_data *subsys); |
| 120 | |
| 121 | int get_restart_level() |
| 122 | { |
| 123 | return restart_level; |
| 124 | } |
| 125 | EXPORT_SYMBOL(get_restart_level); |
| 126 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 127 | static int restart_level_set(const char *val, struct kernel_param *kp) |
| 128 | { |
| 129 | int ret; |
| 130 | int old_val = restart_level; |
| 131 | |
Rohit Vaswani | 56dd22a | 2011-11-11 16:21:28 -0800 | [diff] [blame] | 132 | if (cpu_is_msm9615()) { |
| 133 | pr_err("Only Phase 1 subsystem restart is supported\n"); |
| 134 | return -EINVAL; |
| 135 | } |
| 136 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 137 | ret = param_set_int(val, kp); |
| 138 | if (ret) |
| 139 | return ret; |
| 140 | |
| 141 | switch (restart_level) { |
| 142 | |
| 143 | case RESET_SOC: |
| 144 | case RESET_SUBSYS_COUPLED: |
| 145 | case RESET_SUBSYS_INDEPENDENT: |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 146 | pr_info("Phase %d behavior activated.\n", restart_level); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 147 | break; |
| 148 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 149 | default: |
| 150 | restart_level = old_val; |
| 151 | return -EINVAL; |
| 152 | break; |
| 153 | |
| 154 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | module_param_call(restart_level, restart_level_set, param_get_int, |
| 159 | &restart_level, 0644); |
| 160 | |
| 161 | static struct subsys_data *_find_subsystem(const char *subsys_name) |
| 162 | { |
| 163 | struct subsys_data *subsys; |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 164 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 165 | |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 166 | spin_lock_irqsave(&subsystem_list_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 167 | list_for_each_entry(subsys, &subsystem_list, list) |
| 168 | if (!strncmp(subsys->name, subsys_name, |
| 169 | SUBSYS_NAME_MAX_LENGTH)) { |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 170 | spin_unlock_irqrestore(&subsystem_list_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 171 | return subsys; |
| 172 | } |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 173 | spin_unlock_irqrestore(&subsystem_list_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | |
| 175 | return NULL; |
| 176 | } |
| 177 | |
| 178 | static struct subsys_soc_restart_order *_update_restart_order( |
| 179 | struct subsys_data *subsys) |
| 180 | { |
| 181 | int i, j; |
| 182 | |
| 183 | if (!subsys) |
| 184 | return NULL; |
| 185 | |
| 186 | if (!subsys->name) |
| 187 | return NULL; |
| 188 | |
| 189 | mutex_lock(&soc_order_reg_lock); |
| 190 | for (j = 0; j < n_restart_orders; j++) { |
| 191 | for (i = 0; i < restart_orders[j]->count; i++) |
| 192 | if (!strncmp(restart_orders[j]->subsystem_list[i], |
| 193 | subsys->name, SUBSYS_NAME_MAX_LENGTH)) { |
| 194 | |
| 195 | restart_orders[j]->subsys_ptrs[i] = |
| 196 | subsys; |
| 197 | mutex_unlock(&soc_order_reg_lock); |
| 198 | return restart_orders[j]; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | mutex_unlock(&soc_order_reg_lock); |
| 203 | |
| 204 | return NULL; |
| 205 | } |
| 206 | |
| 207 | static void _send_notification_to_order(struct subsys_data |
| 208 | **restart_list, int count, |
| 209 | enum subsys_notif_type notif_type) |
| 210 | { |
| 211 | int i; |
| 212 | |
| 213 | for (i = 0; i < count; i++) |
| 214 | if (restart_list[i]) |
| 215 | subsys_notif_queue_notification( |
| 216 | restart_list[i]->notif_handle, notif_type); |
| 217 | } |
| 218 | |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 219 | static int max_restarts; |
| 220 | module_param(max_restarts, int, 0644); |
| 221 | |
| 222 | static long max_history_time = 3600; |
| 223 | module_param(max_history_time, long, 0644); |
| 224 | |
| 225 | static void do_epoch_check(struct subsys_data *subsys) |
| 226 | { |
| 227 | int n = 0; |
Jordan Crouse | 75a25ca | 2011-09-09 12:49:57 -0600 | [diff] [blame] | 228 | struct timeval *time_first = NULL, *curr_time; |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 229 | struct restart_log *r_log, *temp; |
| 230 | static int max_restarts_check; |
| 231 | static long max_history_time_check; |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 232 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 233 | int ssr_magic_number = get_ssr_magic_number(); |
| 234 | #endif |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 235 | |
| 236 | mutex_lock(&restart_log_mutex); |
| 237 | |
| 238 | max_restarts_check = max_restarts; |
| 239 | max_history_time_check = max_history_time; |
| 240 | |
| 241 | /* Check if epoch checking is enabled */ |
| 242 | if (!max_restarts_check) |
Vikram Mulukutla | 7a28909 | 2011-09-14 10:08:36 -0700 | [diff] [blame] | 243 | goto out; |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 244 | |
| 245 | r_log = kmalloc(sizeof(struct restart_log), GFP_KERNEL); |
Matt Wagantall | eecca34 | 2011-11-10 20:12:05 -0800 | [diff] [blame] | 246 | if (!r_log) |
| 247 | goto out; |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 248 | r_log->subsys = subsys; |
| 249 | do_gettimeofday(&r_log->time); |
| 250 | curr_time = &r_log->time; |
| 251 | INIT_LIST_HEAD(&r_log->list); |
| 252 | |
| 253 | list_add_tail(&r_log->list, &restart_log_list); |
| 254 | |
| 255 | list_for_each_entry_safe(r_log, temp, &restart_log_list, list) { |
| 256 | |
| 257 | if ((curr_time->tv_sec - r_log->time.tv_sec) > |
| 258 | max_history_time_check) { |
| 259 | |
| 260 | pr_debug("Deleted node with restart_time = %ld\n", |
| 261 | r_log->time.tv_sec); |
| 262 | list_del(&r_log->list); |
| 263 | kfree(r_log); |
| 264 | continue; |
| 265 | } |
| 266 | if (!n) { |
| 267 | time_first = &r_log->time; |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 268 | pr_debug("Time_first: %ld\n", time_first->tv_sec); |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 269 | } |
| 270 | n++; |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 271 | pr_debug("Restart_time: %ld\n", r_log->time.tv_sec); |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Jordan Crouse | 75a25ca | 2011-09-09 12:49:57 -0600 | [diff] [blame] | 274 | if (time_first && n >= max_restarts_check) { |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 275 | if ((curr_time->tv_sec - time_first->tv_sec) < |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 276 | max_history_time_check) { |
| 277 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 278 | msm_set_restart_mode(ssr_magic_number | SUB_UNAB_THD); |
| 279 | #endif |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 280 | panic("Subsystems have crashed %d times in less than " |
| 281 | "%ld seconds!", max_restarts_check, |
| 282 | max_history_time_check); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 283 | } |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Vikram Mulukutla | 7a28909 | 2011-09-14 10:08:36 -0700 | [diff] [blame] | 286 | out: |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 287 | mutex_unlock(&restart_log_mutex); |
| 288 | } |
| 289 | |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 290 | static void subsystem_restart_wq_func(struct work_struct *work) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 291 | { |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 292 | struct restart_wq_data *r_work = container_of(work, |
| 293 | struct restart_wq_data, work); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 294 | struct subsys_data **restart_list; |
| 295 | struct subsys_data *subsys = r_work->subsys; |
| 296 | struct subsys_soc_restart_order *soc_restart_order = NULL; |
| 297 | |
| 298 | struct mutex *powerup_lock; |
| 299 | struct mutex *shutdown_lock; |
| 300 | |
| 301 | int i; |
| 302 | int restart_list_count = 0; |
| 303 | |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 304 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 305 | int ssr_magic_number = get_ssr_magic_number(); |
| 306 | #endif |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 307 | if (r_work->use_restart_order) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 308 | soc_restart_order = subsys->restart_order; |
| 309 | |
| 310 | /* It's OK to not take the registration lock at this point. |
| 311 | * This is because the subsystem list inside the relevant |
| 312 | * restart order is not being traversed. |
| 313 | */ |
| 314 | if (!soc_restart_order) { |
| 315 | restart_list = subsys->single_restart_list; |
| 316 | restart_list_count = 1; |
| 317 | powerup_lock = &subsys->powerup_lock; |
| 318 | shutdown_lock = &subsys->shutdown_lock; |
| 319 | } else { |
| 320 | restart_list = soc_restart_order->subsys_ptrs; |
| 321 | restart_list_count = soc_restart_order->count; |
| 322 | powerup_lock = &soc_restart_order->powerup_lock; |
| 323 | shutdown_lock = &soc_restart_order->shutdown_lock; |
| 324 | } |
| 325 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 326 | pr_debug("[%p]: Attempting to get shutdown lock!\n", current); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 327 | |
| 328 | /* Try to acquire shutdown_lock. If this fails, these subsystems are |
| 329 | * already being restarted - return. |
| 330 | */ |
Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 331 | if (!mutex_trylock(shutdown_lock)) |
| 332 | goto out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 333 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 334 | pr_debug("[%p]: Attempting to get powerup lock!\n", current); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 335 | |
| 336 | /* Now that we've acquired the shutdown lock, either we're the first to |
| 337 | * restart these subsystems or some other thread is doing the powerup |
| 338 | * sequence for these subsystems. In the latter case, panic and bail |
| 339 | * out, since a subsystem died in its powerup sequence. |
| 340 | */ |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 341 | if (!mutex_trylock(powerup_lock)) { |
| 342 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 343 | msm_set_restart_mode(ssr_magic_number | SUB_THD_F_PWR); |
| 344 | #endif |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 345 | panic("%s[%p]: Subsystem died during powerup!", |
| 346 | __func__, current); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 347 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 348 | |
Vikram Mulukutla | 96aecfc | 2011-07-28 18:18:42 -0700 | [diff] [blame] | 349 | do_epoch_check(subsys); |
| 350 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 351 | /* Now it is necessary to take the registration lock. This is because |
| 352 | * the subsystem list in the SoC restart order will be traversed |
| 353 | * and it shouldn't be changed until _this_ restart sequence completes. |
| 354 | */ |
| 355 | mutex_lock(&soc_order_reg_lock); |
| 356 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 357 | pr_debug("[%p]: Starting restart sequence for %s\n", current, |
| 358 | r_work->subsys->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 359 | |
| 360 | _send_notification_to_order(restart_list, |
| 361 | restart_list_count, |
| 362 | SUBSYS_BEFORE_SHUTDOWN); |
| 363 | |
| 364 | for (i = 0; i < restart_list_count; i++) { |
| 365 | |
| 366 | if (!restart_list[i]) |
| 367 | continue; |
| 368 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 369 | pr_info("[%p]: Shutting down %s\n", current, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 370 | restart_list[i]->name); |
| 371 | |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 372 | if (restart_list[i]->shutdown(subsys) < 0) { |
| 373 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 374 | msm_set_restart_mode(ssr_magic_number | SUB_THD_F_SD); |
| 375 | #endif |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 376 | panic("subsys-restart: %s[%p]: Failed to shutdown %s!", |
| 377 | __func__, current, restart_list[i]->name); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 378 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | _send_notification_to_order(restart_list, restart_list_count, |
| 382 | SUBSYS_AFTER_SHUTDOWN); |
| 383 | |
| 384 | /* Now that we've finished shutting down these subsystems, release the |
| 385 | * shutdown lock. If a subsystem restart request comes in for a |
| 386 | * subsystem in _this_ restart order after the unlock below, and |
| 387 | * before the powerup lock is released, panic and bail out. |
| 388 | */ |
| 389 | mutex_unlock(shutdown_lock); |
| 390 | |
| 391 | /* Collect ram dumps for all subsystems in order here */ |
| 392 | for (i = 0; i < restart_list_count; i++) { |
| 393 | if (!restart_list[i]) |
| 394 | continue; |
| 395 | |
| 396 | if (restart_list[i]->ramdump) |
| 397 | if (restart_list[i]->ramdump(enable_ramdumps, |
| 398 | subsys) < 0) |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 399 | pr_warn("%s[%p]: Ramdump failed.\n", |
| 400 | restart_list[i]->name, current); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | _send_notification_to_order(restart_list, |
| 404 | restart_list_count, |
| 405 | SUBSYS_BEFORE_POWERUP); |
| 406 | |
| 407 | for (i = restart_list_count - 1; i >= 0; i--) { |
| 408 | |
| 409 | if (!restart_list[i]) |
| 410 | continue; |
| 411 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 412 | pr_info("[%p]: Powering up %s\n", current, |
| 413 | restart_list[i]->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 414 | |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 415 | if (restart_list[i]->powerup(subsys) < 0) { |
| 416 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 417 | msm_set_restart_mode(ssr_magic_number | SUB_THD_F_PWR); |
| 418 | #endif |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 419 | panic("%s[%p]: Failed to powerup %s!", __func__, |
| 420 | current, restart_list[i]->name); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 421 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | _send_notification_to_order(restart_list, |
| 425 | restart_list_count, |
| 426 | SUBSYS_AFTER_POWERUP); |
| 427 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 428 | pr_info("[%p]: Restart sequence for %s completed.\n", |
| 429 | current, r_work->subsys->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 430 | |
| 431 | mutex_unlock(powerup_lock); |
| 432 | |
| 433 | mutex_unlock(&soc_order_reg_lock); |
| 434 | |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 435 | pr_debug("[%p]: Released powerup lock!\n", current); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 436 | |
Vikram Mulukutla | f6349ae | 2012-02-24 12:21:15 -0800 | [diff] [blame] | 437 | out: |
| 438 | wake_unlock(&r_work->ssr_wake_lock); |
| 439 | wake_lock_destroy(&r_work->ssr_wake_lock); |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 440 | kfree(r_work); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 443 | static void __subsystem_restart(struct subsys_data *subsys) |
| 444 | { |
| 445 | struct restart_wq_data *data = NULL; |
| 446 | int rc; |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 447 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 448 | int ssr_magic_number = get_ssr_magic_number(); |
| 449 | #endif |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 450 | |
| 451 | pr_debug("Restarting %s [level=%d]!\n", subsys->name, |
| 452 | restart_level); |
| 453 | |
| 454 | data = kzalloc(sizeof(struct restart_wq_data), GFP_ATOMIC); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 455 | if (!data) { |
| 456 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 457 | msm_set_restart_mode(ssr_magic_number | SUB_UNAB_THD); |
| 458 | #endif |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 459 | panic("%s: Unable to allocate memory to restart %s.", |
| 460 | __func__, subsys->name); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 461 | } |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 462 | |
| 463 | data->subsys = subsys; |
| 464 | |
| 465 | if (restart_level != RESET_SUBSYS_INDEPENDENT) |
| 466 | data->use_restart_order = 1; |
| 467 | |
| 468 | snprintf(data->wlname, sizeof(data->wlname), "ssr(%s)", subsys->name); |
| 469 | wake_lock_init(&data->ssr_wake_lock, WAKE_LOCK_SUSPEND, data->wlname); |
| 470 | wake_lock(&data->ssr_wake_lock); |
| 471 | |
| 472 | INIT_WORK(&data->work, subsystem_restart_wq_func); |
| 473 | rc = queue_work(ssr_wq, &data->work); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 474 | if (rc < 0) { |
| 475 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 476 | msm_set_restart_mode(ssr_magic_number | SUB_UNAB_THD); |
| 477 | #endif |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 478 | panic("%s: Unable to schedule work to restart %s (%d).", |
| 479 | __func__, subsys->name, rc); |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 480 | } |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 483 | int subsystem_restart(const char *subsys_name) |
| 484 | { |
| 485 | struct subsys_data *subsys; |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 486 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 487 | u32 ssr_magic_number; |
| 488 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 489 | |
| 490 | if (!subsys_name) { |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 491 | pr_err("Invalid subsystem name.\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 492 | return -EINVAL; |
| 493 | } |
| 494 | |
Vikram Mulukutla | 3b24c8c | 2011-12-02 15:12:53 -0800 | [diff] [blame] | 495 | pr_info("Restart sequence requested for %s, restart_level = %d.\n", |
| 496 | subsys_name, restart_level); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 497 | |
| 498 | /* List of subsystems is protected by a lock. New subsystems can |
| 499 | * still come in. |
| 500 | */ |
| 501 | subsys = _find_subsystem(subsys_name); |
| 502 | |
| 503 | if (!subsys) { |
Vikram Mulukutla | a5dd611 | 2011-09-14 14:12:33 -0700 | [diff] [blame] | 504 | pr_warn("Unregistered subsystem %s!\n", subsys_name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 505 | return -EINVAL; |
| 506 | } |
| 507 | |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 508 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 509 | set_ssr_magic_number(subsys_name); |
| 510 | ssr_magic_number = get_ssr_magic_number(); |
| 511 | #endif |
| 512 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | switch (restart_level) { |
| 514 | |
| 515 | case RESET_SUBSYS_COUPLED: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 516 | case RESET_SUBSYS_INDEPENDENT: |
Vikram Mulukutla | 922a4f1 | 2012-04-13 14:36:50 -0700 | [diff] [blame] | 517 | __subsystem_restart(subsys); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 518 | break; |
| 519 | |
| 520 | case RESET_SOC: |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 521 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 522 | msm_set_restart_mode(ssr_magic_number | SUB_RESET_SOC); |
| 523 | #endif |
Vikram Mulukutla | 3b24c8c | 2011-12-02 15:12:53 -0800 | [diff] [blame] | 524 | panic("subsys-restart: Resetting the SoC - %s crashed.", |
| 525 | subsys->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 526 | break; |
| 527 | |
| 528 | default: |
Jaeseong GIM | b849941 | 2012-06-26 10:36:57 -0700 | [diff] [blame] | 529 | #if defined(CONFIG_LGE_CRASH_HANDLER) |
| 530 | msm_set_restart_mode(ssr_magic_number | SUB_UNKNOWN); |
| 531 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 532 | panic("subsys-restart: Unknown restart level!\n"); |
| 533 | break; |
| 534 | |
| 535 | } |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | EXPORT_SYMBOL(subsystem_restart); |
| 540 | |
| 541 | int ssr_register_subsystem(struct subsys_data *subsys) |
| 542 | { |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 543 | unsigned long flags; |
| 544 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 545 | if (!subsys) |
| 546 | goto err; |
| 547 | |
| 548 | if (!subsys->name) |
| 549 | goto err; |
| 550 | |
| 551 | if (!subsys->powerup || !subsys->shutdown) |
| 552 | goto err; |
| 553 | |
| 554 | subsys->notif_handle = subsys_notif_add_subsys(subsys->name); |
| 555 | subsys->restart_order = _update_restart_order(subsys); |
| 556 | subsys->single_restart_list[0] = subsys; |
| 557 | |
| 558 | mutex_init(&subsys->shutdown_lock); |
| 559 | mutex_init(&subsys->powerup_lock); |
| 560 | |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 561 | spin_lock_irqsave(&subsystem_list_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 562 | list_add(&subsys->list, &subsystem_list); |
Vikram Mulukutla | 705e689 | 2012-06-08 17:57:31 -0700 | [diff] [blame] | 563 | spin_unlock_irqrestore(&subsystem_list_lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 564 | |
| 565 | return 0; |
| 566 | |
| 567 | err: |
| 568 | return -EINVAL; |
| 569 | } |
| 570 | EXPORT_SYMBOL(ssr_register_subsystem); |
| 571 | |
Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 572 | static int ssr_panic_handler(struct notifier_block *this, |
| 573 | unsigned long event, void *ptr) |
| 574 | { |
| 575 | struct subsys_data *subsys; |
| 576 | |
| 577 | list_for_each_entry(subsys, &subsystem_list, list) |
| 578 | if (subsys->crash_shutdown) |
| 579 | subsys->crash_shutdown(subsys); |
| 580 | return NOTIFY_DONE; |
| 581 | } |
| 582 | |
| 583 | static struct notifier_block panic_nb = { |
| 584 | .notifier_call = ssr_panic_handler, |
| 585 | }; |
| 586 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 587 | static int __init ssr_init_soc_restart_orders(void) |
| 588 | { |
| 589 | int i; |
| 590 | |
Vikram Mulukutla | 2a7ea7e | 2011-09-06 11:38:47 -0700 | [diff] [blame] | 591 | atomic_notifier_chain_register(&panic_notifier_list, |
| 592 | &panic_nb); |
| 593 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 594 | if (cpu_is_msm8x60()) { |
| 595 | for (i = 0; i < ARRAY_SIZE(orders_8x60_all); i++) { |
| 596 | mutex_init(&orders_8x60_all[i]->powerup_lock); |
| 597 | mutex_init(&orders_8x60_all[i]->shutdown_lock); |
| 598 | } |
| 599 | |
| 600 | for (i = 0; i < ARRAY_SIZE(orders_8x60_modems); i++) { |
| 601 | mutex_init(&orders_8x60_modems[i]->powerup_lock); |
| 602 | mutex_init(&orders_8x60_modems[i]->shutdown_lock); |
| 603 | } |
| 604 | |
| 605 | restart_orders = orders_8x60_all; |
| 606 | n_restart_orders = ARRAY_SIZE(orders_8x60_all); |
| 607 | } |
| 608 | |
Rohit Vaswani | d0fb418 | 2012-03-19 18:07:59 -0700 | [diff] [blame] | 609 | if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_msm9615() || |
| 610 | cpu_is_apq8064()) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 611 | restart_orders = restart_orders_8960; |
| 612 | n_restart_orders = ARRAY_SIZE(restart_orders_8960); |
| 613 | } |
| 614 | |
| 615 | if (restart_orders == NULL || n_restart_orders < 1) { |
| 616 | WARN_ON(1); |
| 617 | return -EINVAL; |
| 618 | } |
| 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static int __init subsys_restart_init(void) |
| 624 | { |
| 625 | int ret = 0; |
| 626 | |
| 627 | restart_level = RESET_SOC; |
| 628 | |
Vikram Mulukutla | 69177e1 | 2012-03-21 20:51:43 -0700 | [diff] [blame] | 629 | ssr_wq = alloc_workqueue("ssr_wq", 0, 0); |
| 630 | |
| 631 | if (!ssr_wq) |
| 632 | panic("Couldn't allocate workqueue for subsystem restart.\n"); |
| 633 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 634 | ret = ssr_init_soc_restart_orders(); |
| 635 | |
| 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | arch_initcall(subsys_restart_init); |
| 640 | |
| 641 | MODULE_DESCRIPTION("Subsystem Restart Driver"); |
| 642 | MODULE_LICENSE("GPL v2"); |