2 * Support for dynamic reconfiguration for PCI, Memory, and CPU
3 * Hotplug and Dynamic Logical Partitioning on RPA platforms.
5 * Copyright (C) 2009 Nathan Fontenot
6 * Copyright (C) 2009 IBM Corporation
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.
13 #include <linux/kernel.h>
14 #include <linux/notifier.h>
15 #include <linux/spinlock.h>
16 #include <linux/cpu.h>
17 #include <linux/slab.h>
19 #include "offline_states.h"
22 #include <asm/machdep.h>
23 #include <asm/uaccess.h>
34 void dlpar_free_cc_property(struct property
*prop
)
41 static struct property
*dlpar_parse_cc_property(struct cc_workarea
*ccwa
)
43 struct property
*prop
;
47 prop
= kzalloc(sizeof(*prop
), GFP_KERNEL
);
51 name
= (char *)ccwa
+ ccwa
->name_offset
;
52 prop
->name
= kstrdup(name
, GFP_KERNEL
);
54 prop
->length
= ccwa
->prop_length
;
55 value
= (char *)ccwa
+ ccwa
->prop_offset
;
56 prop
->value
= kmemdup(value
, prop
->length
, GFP_KERNEL
);
58 dlpar_free_cc_property(prop
);
65 static struct device_node
*dlpar_parse_cc_node(struct cc_workarea
*ccwa
,
68 struct device_node
*dn
;
71 /* If parent node path is "/" advance path to NULL terminator to
72 * prevent double leading slashs in full_name.
77 dn
= kzalloc(sizeof(*dn
), GFP_KERNEL
);
81 name
= (char *)ccwa
+ ccwa
->name_offset
;
82 dn
->full_name
= kasprintf(GFP_KERNEL
, "%s/%s", path
, name
);
88 of_node_set_flag(dn
, OF_DYNAMIC
);
93 static void dlpar_free_one_cc_node(struct device_node
*dn
)
95 struct property
*prop
;
97 while (dn
->properties
) {
98 prop
= dn
->properties
;
99 dn
->properties
= prop
->next
;
100 dlpar_free_cc_property(prop
);
103 kfree(dn
->full_name
);
107 void dlpar_free_cc_nodes(struct device_node
*dn
)
110 dlpar_free_cc_nodes(dn
->child
);
113 dlpar_free_cc_nodes(dn
->sibling
);
115 dlpar_free_one_cc_node(dn
);
119 #define NEXT_SIBLING 1
121 #define NEXT_PROPERTY 3
122 #define PREV_PARENT 4
123 #define MORE_MEMORY 5
124 #define CALL_AGAIN -2
125 #define ERR_CFG_USE -9003
127 struct device_node
*dlpar_configure_connector(u32 drc_index
,
128 struct device_node
*parent
)
130 struct device_node
*dn
;
131 struct device_node
*first_dn
= NULL
;
132 struct device_node
*last_dn
= NULL
;
133 struct property
*property
;
134 struct property
*last_property
= NULL
;
135 struct cc_workarea
*ccwa
;
137 const char *parent_path
= parent
->full_name
;
141 cc_token
= rtas_token("ibm,configure-connector");
142 if (cc_token
== RTAS_UNKNOWN_SERVICE
)
145 data_buf
= kzalloc(RTAS_DATA_BUF_SIZE
, GFP_KERNEL
);
149 ccwa
= (struct cc_workarea
*)&data_buf
[0];
150 ccwa
->drc_index
= drc_index
;
154 /* Since we release the rtas_data_buf lock between configure
155 * connector calls we want to re-populate the rtas_data_buffer
156 * with the contents of the previous call.
158 spin_lock(&rtas_data_buf_lock
);
160 memcpy(rtas_data_buf
, data_buf
, RTAS_DATA_BUF_SIZE
);
161 rc
= rtas_call(cc_token
, 2, 1, NULL
, rtas_data_buf
, NULL
);
162 memcpy(data_buf
, rtas_data_buf
, RTAS_DATA_BUF_SIZE
);
164 spin_unlock(&rtas_data_buf_lock
);
171 dn
= dlpar_parse_cc_node(ccwa
, parent_path
);
175 dn
->parent
= last_dn
->parent
;
176 last_dn
->sibling
= dn
;
182 parent_path
= last_dn
->full_name
;
184 dn
= dlpar_parse_cc_node(ccwa
, parent_path
);
192 dn
->parent
= last_dn
;
201 property
= dlpar_parse_cc_property(ccwa
);
205 if (!last_dn
->properties
)
206 last_dn
->properties
= property
;
208 last_property
->next
= property
;
210 last_property
= property
;
214 last_dn
= last_dn
->parent
;
215 parent_path
= last_dn
->parent
->full_name
;
224 printk(KERN_ERR
"Unexpected Error (%d) "
225 "returned from configure-connector\n", rc
);
235 dlpar_free_cc_nodes(first_dn
);
243 static struct device_node
*derive_parent(const char *path
)
245 struct device_node
*parent
;
248 last_slash
= strrchr(path
, '/');
249 if (last_slash
== path
) {
250 parent
= of_find_node_by_path("/");
253 int parent_path_len
= last_slash
- path
+ 1;
254 parent_path
= kmalloc(parent_path_len
, GFP_KERNEL
);
258 strlcpy(parent_path
, path
, parent_path_len
);
259 parent
= of_find_node_by_path(parent_path
);
266 int dlpar_attach_node(struct device_node
*dn
)
270 dn
->parent
= derive_parent(dn
->full_name
);
274 rc
= of_attach_node(dn
);
276 printk(KERN_ERR
"Failed to add device node %s\n",
281 of_node_put(dn
->parent
);
285 int dlpar_detach_node(struct device_node
*dn
)
287 struct device_node
*child
;
290 child
= of_get_next_child(dn
, NULL
);
292 dlpar_detach_node(child
);
293 child
= of_get_next_child(dn
, child
);
296 rc
= of_detach_node(dn
);
300 of_node_put(dn
); /* Must decrement the refcount */
304 #define DR_ENTITY_SENSE 9003
305 #define DR_ENTITY_PRESENT 1
306 #define DR_ENTITY_UNUSABLE 2
307 #define ALLOCATION_STATE 9003
308 #define ALLOC_UNUSABLE 0
309 #define ALLOC_USABLE 1
310 #define ISOLATION_STATE 9001
314 int dlpar_acquire_drc(u32 drc_index
)
318 rc
= rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status
,
319 DR_ENTITY_SENSE
, drc_index
);
320 if (rc
|| dr_status
!= DR_ENTITY_UNUSABLE
)
323 rc
= rtas_set_indicator(ALLOCATION_STATE
, drc_index
, ALLOC_USABLE
);
327 rc
= rtas_set_indicator(ISOLATION_STATE
, drc_index
, UNISOLATE
);
329 rtas_set_indicator(ALLOCATION_STATE
, drc_index
, ALLOC_UNUSABLE
);
336 int dlpar_release_drc(u32 drc_index
)
340 rc
= rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status
,
341 DR_ENTITY_SENSE
, drc_index
);
342 if (rc
|| dr_status
!= DR_ENTITY_PRESENT
)
345 rc
= rtas_set_indicator(ISOLATION_STATE
, drc_index
, ISOLATE
);
349 rc
= rtas_set_indicator(ALLOCATION_STATE
, drc_index
, ALLOC_UNUSABLE
);
351 rtas_set_indicator(ISOLATION_STATE
, drc_index
, UNISOLATE
);
358 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
360 static int dlpar_online_cpu(struct device_node
*dn
)
364 int len
, nthreads
, i
;
367 intserv
= of_get_property(dn
, "ibm,ppc-interrupt-server#s", &len
);
371 nthreads
= len
/ sizeof(u32
);
373 cpu_maps_update_begin();
374 for (i
= 0; i
< nthreads
; i
++) {
375 for_each_present_cpu(cpu
) {
376 if (get_hard_smp_processor_id(cpu
) != intserv
[i
])
378 BUG_ON(get_cpu_current_state(cpu
)
379 != CPU_STATE_OFFLINE
);
380 cpu_maps_update_done();
384 cpu_maps_update_begin();
388 if (cpu
== num_possible_cpus())
389 printk(KERN_WARNING
"Could not find cpu to online "
390 "with physical id 0x%x\n", intserv
[i
]);
392 cpu_maps_update_done();
399 static ssize_t
dlpar_cpu_probe(const char *buf
, size_t count
)
401 struct device_node
*dn
, *parent
;
402 unsigned long drc_index
;
405 rc
= strict_strtoul(buf
, 0, &drc_index
);
409 parent
= of_find_node_by_path("/cpus");
413 dn
= dlpar_configure_connector(drc_index
, parent
);
419 rc
= dlpar_acquire_drc(drc_index
);
421 dlpar_free_cc_nodes(dn
);
425 rc
= dlpar_attach_node(dn
);
427 dlpar_release_drc(drc_index
);
428 dlpar_free_cc_nodes(dn
);
432 rc
= dlpar_online_cpu(dn
);
439 static int dlpar_offline_cpu(struct device_node
*dn
)
443 int len
, nthreads
, i
;
446 intserv
= of_get_property(dn
, "ibm,ppc-interrupt-server#s", &len
);
450 nthreads
= len
/ sizeof(u32
);
452 cpu_maps_update_begin();
453 for (i
= 0; i
< nthreads
; i
++) {
454 for_each_present_cpu(cpu
) {
455 if (get_hard_smp_processor_id(cpu
) != intserv
[i
])
458 if (get_cpu_current_state(cpu
) == CPU_STATE_OFFLINE
)
461 if (get_cpu_current_state(cpu
) == CPU_STATE_ONLINE
) {
462 set_preferred_offline_state(cpu
, CPU_STATE_OFFLINE
);
463 cpu_maps_update_done();
467 cpu_maps_update_begin();
473 * The cpu is in CPU_STATE_INACTIVE.
474 * Upgrade it's state to CPU_STATE_OFFLINE.
476 set_preferred_offline_state(cpu
, CPU_STATE_OFFLINE
);
477 BUG_ON(plpar_hcall_norets(H_PROD
, intserv
[i
])
482 if (cpu
== num_possible_cpus())
483 printk(KERN_WARNING
"Could not find cpu to offline "
484 "with physical id 0x%x\n", intserv
[i
]);
486 cpu_maps_update_done();
493 static ssize_t
dlpar_cpu_release(const char *buf
, size_t count
)
495 struct device_node
*dn
;
496 const u32
*drc_index
;
499 dn
= of_find_node_by_path(buf
);
503 drc_index
= of_get_property(dn
, "ibm,my-drc-index", NULL
);
509 rc
= dlpar_offline_cpu(dn
);
515 rc
= dlpar_release_drc(*drc_index
);
521 rc
= dlpar_detach_node(dn
);
523 dlpar_acquire_drc(*drc_index
);
532 static int __init
pseries_dlpar_init(void)
534 ppc_md
.cpu_probe
= dlpar_cpu_probe
;
535 ppc_md
.cpu_release
= dlpar_cpu_release
;
539 machine_device_initcall(pseries
, pseries_dlpar_init
);
541 #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
This page took 0.041676 seconds and 5 git commands to generate.