Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Support for dynamic reconfiguration for PCI, Memory, and CPU |
| 3 | * Hotplug and Dynamic Logical Partitioning on RPA platforms. |
| 4 | * |
| 5 | * Copyright (C) 2009 Nathan Fontenot |
| 6 | * Copyright (C) 2009 IBM Corporation |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License version |
| 10 | * 2 as published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/kref.h> |
| 15 | #include <linux/notifier.h> |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 16 | #include <linux/spinlock.h> |
| 17 | #include <linux/cpu.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Nathan Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 19 | #include <linux/of.h> |
Gautham R Shenoy | b6db63d | 2009-11-26 09:58:55 +0000 | [diff] [blame] | 20 | #include "offline_states.h" |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 21 | |
| 22 | #include <asm/prom.h> |
| 23 | #include <asm/machdep.h> |
| 24 | #include <asm/uaccess.h> |
| 25 | #include <asm/rtas.h> |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 26 | |
| 27 | struct cc_workarea { |
| 28 | u32 drc_index; |
| 29 | u32 zero; |
| 30 | u32 name_offset; |
| 31 | u32 prop_length; |
| 32 | u32 prop_offset; |
| 33 | }; |
| 34 | |
Nathan Fontenot | 2064897 | 2010-09-10 09:40:32 +0000 | [diff] [blame] | 35 | void dlpar_free_cc_property(struct property *prop) |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 36 | { |
| 37 | kfree(prop->name); |
| 38 | kfree(prop->value); |
| 39 | kfree(prop); |
| 40 | } |
| 41 | |
| 42 | static struct property *dlpar_parse_cc_property(struct cc_workarea *ccwa) |
| 43 | { |
| 44 | struct property *prop; |
| 45 | char *name; |
| 46 | char *value; |
| 47 | |
| 48 | prop = kzalloc(sizeof(*prop), GFP_KERNEL); |
| 49 | if (!prop) |
| 50 | return NULL; |
| 51 | |
| 52 | name = (char *)ccwa + ccwa->name_offset; |
| 53 | prop->name = kstrdup(name, GFP_KERNEL); |
| 54 | |
| 55 | prop->length = ccwa->prop_length; |
| 56 | value = (char *)ccwa + ccwa->prop_offset; |
Nishanth Aravamudan | e72ed6b | 2010-09-15 08:05:49 +0000 | [diff] [blame] | 57 | prop->value = kmemdup(value, prop->length, GFP_KERNEL); |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 58 | if (!prop->value) { |
| 59 | dlpar_free_cc_property(prop); |
| 60 | return NULL; |
| 61 | } |
| 62 | |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 63 | return prop; |
| 64 | } |
| 65 | |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 66 | static struct device_node *dlpar_parse_cc_node(struct cc_workarea *ccwa, |
| 67 | const char *path) |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 68 | { |
| 69 | struct device_node *dn; |
| 70 | char *name; |
| 71 | |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 72 | /* If parent node path is "/" advance path to NULL terminator to |
| 73 | * prevent double leading slashs in full_name. |
| 74 | */ |
| 75 | if (!path[1]) |
| 76 | path++; |
| 77 | |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 78 | dn = kzalloc(sizeof(*dn), GFP_KERNEL); |
| 79 | if (!dn) |
| 80 | return NULL; |
| 81 | |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 82 | name = (char *)ccwa + ccwa->name_offset; |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 83 | dn->full_name = kasprintf(GFP_KERNEL, "%s/%s", path, name); |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 84 | if (!dn->full_name) { |
| 85 | kfree(dn); |
| 86 | return NULL; |
| 87 | } |
| 88 | |
Tyrel Datwyler | 1578cb7 | 2013-08-14 22:23:49 -0700 | [diff] [blame] | 89 | of_node_set_flag(dn, OF_DYNAMIC); |
| 90 | kref_init(&dn->kref); |
| 91 | |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 92 | return dn; |
| 93 | } |
| 94 | |
| 95 | static void dlpar_free_one_cc_node(struct device_node *dn) |
| 96 | { |
| 97 | struct property *prop; |
| 98 | |
| 99 | while (dn->properties) { |
| 100 | prop = dn->properties; |
| 101 | dn->properties = prop->next; |
| 102 | dlpar_free_cc_property(prop); |
| 103 | } |
| 104 | |
| 105 | kfree(dn->full_name); |
| 106 | kfree(dn); |
| 107 | } |
| 108 | |
Nathan Fontenot | 2064897 | 2010-09-10 09:40:32 +0000 | [diff] [blame] | 109 | void dlpar_free_cc_nodes(struct device_node *dn) |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 110 | { |
| 111 | if (dn->child) |
| 112 | dlpar_free_cc_nodes(dn->child); |
| 113 | |
| 114 | if (dn->sibling) |
| 115 | dlpar_free_cc_nodes(dn->sibling); |
| 116 | |
| 117 | dlpar_free_one_cc_node(dn); |
| 118 | } |
| 119 | |
Anton Blanchard | 9c74002 | 2011-08-14 14:30:30 +0000 | [diff] [blame] | 120 | #define COMPLETE 0 |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 121 | #define NEXT_SIBLING 1 |
| 122 | #define NEXT_CHILD 2 |
| 123 | #define NEXT_PROPERTY 3 |
| 124 | #define PREV_PARENT 4 |
| 125 | #define MORE_MEMORY 5 |
| 126 | #define CALL_AGAIN -2 |
| 127 | #define ERR_CFG_USE -9003 |
| 128 | |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 129 | struct device_node *dlpar_configure_connector(u32 drc_index, |
| 130 | struct device_node *parent) |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 131 | { |
| 132 | struct device_node *dn; |
| 133 | struct device_node *first_dn = NULL; |
| 134 | struct device_node *last_dn = NULL; |
| 135 | struct property *property; |
| 136 | struct property *last_property = NULL; |
| 137 | struct cc_workarea *ccwa; |
Nathan Fontenot | 93f68f1 | 2010-08-18 09:58:46 +0000 | [diff] [blame] | 138 | char *data_buf; |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 139 | const char *parent_path = parent->full_name; |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 140 | int cc_token; |
Nathan Fontenot | 93f68f1 | 2010-08-18 09:58:46 +0000 | [diff] [blame] | 141 | int rc = -1; |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 142 | |
| 143 | cc_token = rtas_token("ibm,configure-connector"); |
| 144 | if (cc_token == RTAS_UNKNOWN_SERVICE) |
| 145 | return NULL; |
| 146 | |
Nathan Fontenot | 93f68f1 | 2010-08-18 09:58:46 +0000 | [diff] [blame] | 147 | data_buf = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL); |
| 148 | if (!data_buf) |
| 149 | return NULL; |
| 150 | |
| 151 | ccwa = (struct cc_workarea *)&data_buf[0]; |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 152 | ccwa->drc_index = drc_index; |
| 153 | ccwa->zero = 0; |
| 154 | |
Nathan Fontenot | 93f68f1 | 2010-08-18 09:58:46 +0000 | [diff] [blame] | 155 | do { |
| 156 | /* Since we release the rtas_data_buf lock between configure |
| 157 | * connector calls we want to re-populate the rtas_data_buffer |
| 158 | * with the contents of the previous call. |
| 159 | */ |
| 160 | spin_lock(&rtas_data_buf_lock); |
| 161 | |
| 162 | memcpy(rtas_data_buf, data_buf, RTAS_DATA_BUF_SIZE); |
| 163 | rc = rtas_call(cc_token, 2, 1, NULL, rtas_data_buf, NULL); |
| 164 | memcpy(data_buf, rtas_data_buf, RTAS_DATA_BUF_SIZE); |
| 165 | |
| 166 | spin_unlock(&rtas_data_buf_lock); |
| 167 | |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 168 | switch (rc) { |
Anton Blanchard | 9c74002 | 2011-08-14 14:30:30 +0000 | [diff] [blame] | 169 | case COMPLETE: |
| 170 | break; |
| 171 | |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 172 | case NEXT_SIBLING: |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 173 | dn = dlpar_parse_cc_node(ccwa, parent_path); |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 174 | if (!dn) |
| 175 | goto cc_error; |
| 176 | |
| 177 | dn->parent = last_dn->parent; |
| 178 | last_dn->sibling = dn; |
| 179 | last_dn = dn; |
| 180 | break; |
| 181 | |
| 182 | case NEXT_CHILD: |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 183 | if (first_dn) |
| 184 | parent_path = last_dn->full_name; |
| 185 | |
| 186 | dn = dlpar_parse_cc_node(ccwa, parent_path); |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 187 | if (!dn) |
| 188 | goto cc_error; |
| 189 | |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 190 | if (!first_dn) { |
| 191 | dn->parent = parent; |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 192 | first_dn = dn; |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 193 | } else { |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 194 | dn->parent = last_dn; |
| 195 | if (last_dn) |
| 196 | last_dn->child = dn; |
| 197 | } |
| 198 | |
| 199 | last_dn = dn; |
| 200 | break; |
| 201 | |
| 202 | case NEXT_PROPERTY: |
| 203 | property = dlpar_parse_cc_property(ccwa); |
| 204 | if (!property) |
| 205 | goto cc_error; |
| 206 | |
| 207 | if (!last_dn->properties) |
| 208 | last_dn->properties = property; |
| 209 | else |
| 210 | last_property->next = property; |
| 211 | |
| 212 | last_property = property; |
| 213 | break; |
| 214 | |
| 215 | case PREV_PARENT: |
| 216 | last_dn = last_dn->parent; |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 217 | parent_path = last_dn->parent->full_name; |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 218 | break; |
| 219 | |
| 220 | case CALL_AGAIN: |
| 221 | break; |
| 222 | |
| 223 | case MORE_MEMORY: |
| 224 | case ERR_CFG_USE: |
| 225 | default: |
| 226 | printk(KERN_ERR "Unexpected Error (%d) " |
| 227 | "returned from configure-connector\n", rc); |
| 228 | goto cc_error; |
| 229 | } |
Nathan Fontenot | 93f68f1 | 2010-08-18 09:58:46 +0000 | [diff] [blame] | 230 | } while (rc); |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 231 | |
| 232 | cc_error: |
Nathan Fontenot | 93f68f1 | 2010-08-18 09:58:46 +0000 | [diff] [blame] | 233 | kfree(data_buf); |
| 234 | |
| 235 | if (rc) { |
| 236 | if (first_dn) |
| 237 | dlpar_free_cc_nodes(first_dn); |
| 238 | |
| 239 | return NULL; |
| 240 | } |
| 241 | |
| 242 | return first_dn; |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static struct device_node *derive_parent(const char *path) |
| 246 | { |
| 247 | struct device_node *parent; |
| 248 | char *last_slash; |
| 249 | |
| 250 | last_slash = strrchr(path, '/'); |
| 251 | if (last_slash == path) { |
| 252 | parent = of_find_node_by_path("/"); |
| 253 | } else { |
| 254 | char *parent_path; |
| 255 | int parent_path_len = last_slash - path + 1; |
| 256 | parent_path = kmalloc(parent_path_len, GFP_KERNEL); |
| 257 | if (!parent_path) |
| 258 | return NULL; |
| 259 | |
| 260 | strlcpy(parent_path, path, parent_path_len); |
| 261 | parent = of_find_node_by_path(parent_path); |
| 262 | kfree(parent_path); |
| 263 | } |
| 264 | |
| 265 | return parent; |
| 266 | } |
| 267 | |
| 268 | int dlpar_attach_node(struct device_node *dn) |
| 269 | { |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 270 | int rc; |
| 271 | |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 272 | dn->parent = derive_parent(dn->full_name); |
| 273 | if (!dn->parent) |
| 274 | return -ENOMEM; |
| 275 | |
Nathan Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 276 | rc = of_attach_node(dn); |
Akinobu Mita | 3aef19f | 2011-06-21 03:35:55 +0000 | [diff] [blame] | 277 | if (rc) { |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 278 | printk(KERN_ERR "Failed to add device node %s\n", |
| 279 | dn->full_name); |
Akinobu Mita | 3aef19f | 2011-06-21 03:35:55 +0000 | [diff] [blame] | 280 | return rc; |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 283 | of_node_put(dn->parent); |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | int dlpar_detach_node(struct device_node *dn) |
| 288 | { |
Tyrel Datwyler | 5935ff4 | 2013-08-14 22:23:52 -0700 | [diff] [blame] | 289 | struct device_node *child; |
Nathan Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 290 | int rc; |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 291 | |
Tyrel Datwyler | 5935ff4 | 2013-08-14 22:23:52 -0700 | [diff] [blame] | 292 | child = of_get_next_child(dn, NULL); |
| 293 | while (child) { |
| 294 | dlpar_detach_node(child); |
| 295 | child = of_get_next_child(dn, child); |
| 296 | } |
| 297 | |
Nathan Fontenot | 1cf3d8b | 2012-10-02 16:57:57 +0000 | [diff] [blame] | 298 | rc = of_detach_node(dn); |
| 299 | if (rc) |
| 300 | return rc; |
| 301 | |
| 302 | of_node_put(dn); /* Must decrement the refcount */ |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | #define DR_ENTITY_SENSE 9003 |
| 307 | #define DR_ENTITY_PRESENT 1 |
| 308 | #define DR_ENTITY_UNUSABLE 2 |
| 309 | #define ALLOCATION_STATE 9003 |
| 310 | #define ALLOC_UNUSABLE 0 |
| 311 | #define ALLOC_USABLE 1 |
| 312 | #define ISOLATION_STATE 9001 |
| 313 | #define ISOLATE 0 |
| 314 | #define UNISOLATE 1 |
| 315 | |
| 316 | int dlpar_acquire_drc(u32 drc_index) |
| 317 | { |
| 318 | int dr_status, rc; |
| 319 | |
| 320 | rc = rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status, |
| 321 | DR_ENTITY_SENSE, drc_index); |
| 322 | if (rc || dr_status != DR_ENTITY_UNUSABLE) |
| 323 | return -1; |
| 324 | |
| 325 | rc = rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_USABLE); |
| 326 | if (rc) |
| 327 | return rc; |
| 328 | |
| 329 | rc = rtas_set_indicator(ISOLATION_STATE, drc_index, UNISOLATE); |
| 330 | if (rc) { |
| 331 | rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_UNUSABLE); |
| 332 | return rc; |
| 333 | } |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | int dlpar_release_drc(u32 drc_index) |
| 339 | { |
| 340 | int dr_status, rc; |
| 341 | |
| 342 | rc = rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status, |
| 343 | DR_ENTITY_SENSE, drc_index); |
| 344 | if (rc || dr_status != DR_ENTITY_PRESENT) |
| 345 | return -1; |
| 346 | |
| 347 | rc = rtas_set_indicator(ISOLATION_STATE, drc_index, ISOLATE); |
| 348 | if (rc) |
| 349 | return rc; |
| 350 | |
| 351 | rc = rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_UNUSABLE); |
| 352 | if (rc) { |
| 353 | rtas_set_indicator(ISOLATION_STATE, drc_index, UNISOLATE); |
| 354 | return rc; |
| 355 | } |
| 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 360 | #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE |
Nathan Fontenot | ab519a0 | 2009-11-24 21:10:49 +0000 | [diff] [blame] | 361 | |
Nathan Fontenot | 275a64f | 2009-12-08 09:48:44 +0000 | [diff] [blame] | 362 | static int dlpar_online_cpu(struct device_node *dn) |
| 363 | { |
| 364 | int rc = 0; |
| 365 | unsigned int cpu; |
| 366 | int len, nthreads, i; |
| 367 | const u32 *intserv; |
| 368 | |
| 369 | intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", &len); |
| 370 | if (!intserv) |
| 371 | return -EINVAL; |
| 372 | |
| 373 | nthreads = len / sizeof(u32); |
| 374 | |
| 375 | cpu_maps_update_begin(); |
| 376 | for (i = 0; i < nthreads; i++) { |
| 377 | for_each_present_cpu(cpu) { |
| 378 | if (get_hard_smp_processor_id(cpu) != intserv[i]) |
| 379 | continue; |
| 380 | BUG_ON(get_cpu_current_state(cpu) |
| 381 | != CPU_STATE_OFFLINE); |
| 382 | cpu_maps_update_done(); |
| 383 | rc = cpu_up(cpu); |
| 384 | if (rc) |
| 385 | goto out; |
| 386 | cpu_maps_update_begin(); |
| 387 | |
| 388 | break; |
| 389 | } |
| 390 | if (cpu == num_possible_cpus()) |
| 391 | printk(KERN_WARNING "Could not find cpu to online " |
| 392 | "with physical id 0x%x\n", intserv[i]); |
| 393 | } |
| 394 | cpu_maps_update_done(); |
| 395 | |
| 396 | out: |
| 397 | return rc; |
| 398 | |
| 399 | } |
| 400 | |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 401 | static ssize_t dlpar_cpu_probe(const char *buf, size_t count) |
| 402 | { |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 403 | struct device_node *dn, *parent; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 404 | unsigned long drc_index; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 405 | int rc; |
| 406 | |
| 407 | rc = strict_strtoul(buf, 0, &drc_index); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 408 | if (rc) |
| 409 | return -EINVAL; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 410 | |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 411 | parent = of_find_node_by_path("/cpus"); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 412 | if (!parent) |
| 413 | return -ENODEV; |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 414 | |
| 415 | dn = dlpar_configure_connector(drc_index, parent); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 416 | if (!dn) |
| 417 | return -EINVAL; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 418 | |
Tyrel Datwyler | 8d5ff32 | 2013-08-14 22:23:50 -0700 | [diff] [blame] | 419 | of_node_put(parent); |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 420 | |
| 421 | rc = dlpar_acquire_drc(drc_index); |
| 422 | if (rc) { |
| 423 | dlpar_free_cc_nodes(dn); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 424 | return -EINVAL; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | rc = dlpar_attach_node(dn); |
| 428 | if (rc) { |
| 429 | dlpar_release_drc(drc_index); |
| 430 | dlpar_free_cc_nodes(dn); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 431 | return rc; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Nathan Fontenot | 275a64f | 2009-12-08 09:48:44 +0000 | [diff] [blame] | 434 | rc = dlpar_online_cpu(dn); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 435 | if (rc) |
| 436 | return rc; |
Gautham R Shenoy | b6db63d | 2009-11-26 09:58:55 +0000 | [diff] [blame] | 437 | |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 438 | return count; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Nathan Fontenot | 275a64f | 2009-12-08 09:48:44 +0000 | [diff] [blame] | 441 | static int dlpar_offline_cpu(struct device_node *dn) |
| 442 | { |
| 443 | int rc = 0; |
| 444 | unsigned int cpu; |
| 445 | int len, nthreads, i; |
| 446 | const u32 *intserv; |
| 447 | |
| 448 | intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", &len); |
| 449 | if (!intserv) |
| 450 | return -EINVAL; |
| 451 | |
| 452 | nthreads = len / sizeof(u32); |
| 453 | |
| 454 | cpu_maps_update_begin(); |
| 455 | for (i = 0; i < nthreads; i++) { |
| 456 | for_each_present_cpu(cpu) { |
| 457 | if (get_hard_smp_processor_id(cpu) != intserv[i]) |
| 458 | continue; |
| 459 | |
| 460 | if (get_cpu_current_state(cpu) == CPU_STATE_OFFLINE) |
| 461 | break; |
| 462 | |
| 463 | if (get_cpu_current_state(cpu) == CPU_STATE_ONLINE) { |
Robert Jennings | ceddee2 | 2010-07-22 16:43:44 +0000 | [diff] [blame] | 464 | set_preferred_offline_state(cpu, CPU_STATE_OFFLINE); |
Nathan Fontenot | 275a64f | 2009-12-08 09:48:44 +0000 | [diff] [blame] | 465 | cpu_maps_update_done(); |
| 466 | rc = cpu_down(cpu); |
| 467 | if (rc) |
| 468 | goto out; |
| 469 | cpu_maps_update_begin(); |
| 470 | break; |
| 471 | |
| 472 | } |
| 473 | |
| 474 | /* |
| 475 | * The cpu is in CPU_STATE_INACTIVE. |
| 476 | * Upgrade it's state to CPU_STATE_OFFLINE. |
| 477 | */ |
| 478 | set_preferred_offline_state(cpu, CPU_STATE_OFFLINE); |
| 479 | BUG_ON(plpar_hcall_norets(H_PROD, intserv[i]) |
| 480 | != H_SUCCESS); |
| 481 | __cpu_die(cpu); |
| 482 | break; |
| 483 | } |
| 484 | if (cpu == num_possible_cpus()) |
| 485 | printk(KERN_WARNING "Could not find cpu to offline " |
| 486 | "with physical id 0x%x\n", intserv[i]); |
| 487 | } |
| 488 | cpu_maps_update_done(); |
| 489 | |
| 490 | out: |
| 491 | return rc; |
| 492 | |
| 493 | } |
| 494 | |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 495 | static ssize_t dlpar_cpu_release(const char *buf, size_t count) |
| 496 | { |
| 497 | struct device_node *dn; |
| 498 | const u32 *drc_index; |
| 499 | int rc; |
| 500 | |
| 501 | dn = of_find_node_by_path(buf); |
| 502 | if (!dn) |
| 503 | return -EINVAL; |
| 504 | |
| 505 | drc_index = of_get_property(dn, "ibm,my-drc-index", NULL); |
| 506 | if (!drc_index) { |
| 507 | of_node_put(dn); |
| 508 | return -EINVAL; |
| 509 | } |
| 510 | |
Nathan Fontenot | 275a64f | 2009-12-08 09:48:44 +0000 | [diff] [blame] | 511 | rc = dlpar_offline_cpu(dn); |
Gautham R Shenoy | b6db63d | 2009-11-26 09:58:55 +0000 | [diff] [blame] | 512 | if (rc) { |
| 513 | of_node_put(dn); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 514 | return -EINVAL; |
Gautham R Shenoy | b6db63d | 2009-11-26 09:58:55 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 517 | rc = dlpar_release_drc(*drc_index); |
| 518 | if (rc) { |
| 519 | of_node_put(dn); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 520 | return rc; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | rc = dlpar_detach_node(dn); |
| 524 | if (rc) { |
| 525 | dlpar_acquire_drc(*drc_index); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 526 | return rc; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | of_node_put(dn); |
Toshi Kani | 6dedcca | 2013-09-25 15:08:27 -0600 | [diff] [blame] | 530 | |
| 531 | return count; |
Nathan Fontenot | 1a8061c | 2009-11-24 21:13:32 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static int __init pseries_dlpar_init(void) |
| 535 | { |
| 536 | ppc_md.cpu_probe = dlpar_cpu_probe; |
| 537 | ppc_md.cpu_release = dlpar_cpu_release; |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | machine_device_initcall(pseries, pseries_dlpar_init); |
| 542 | |
| 543 | #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ |