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