]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - arch/powerpc/platforms/pseries/dlpar.c
a2450b8a50a5eaaf3bbab9fc402bbf8997c00ed4
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
);
94 static void dlpar_free_one_cc_node(struct device_node
*dn
)
96 struct property
*prop
;
98 while (dn
->properties
) {
99 prop
= dn
->properties
;
100 dn
->properties
= prop
->next
;
101 dlpar_free_cc_property(prop
);
104 kfree(dn
->full_name
);
108 void dlpar_free_cc_nodes(struct device_node
*dn
)
111 dlpar_free_cc_nodes(dn
->child
);
114 dlpar_free_cc_nodes(dn
->sibling
);
116 dlpar_free_one_cc_node(dn
);
120 #define NEXT_SIBLING 1
122 #define NEXT_PROPERTY 3
123 #define PREV_PARENT 4
124 #define MORE_MEMORY 5
125 #define CALL_AGAIN -2
126 #define ERR_CFG_USE -9003
128 struct device_node
*dlpar_configure_connector(u32 drc_index
,
129 struct device_node
*parent
)
131 struct device_node
*dn
;
132 struct device_node
*first_dn
= NULL
;
133 struct device_node
*last_dn
= NULL
;
134 struct property
*property
;
135 struct property
*last_property
= NULL
;
136 struct cc_workarea
*ccwa
;
138 const char *parent_path
= parent
->full_name
;
142 cc_token
= rtas_token("ibm,configure-connector");
143 if (cc_token
== RTAS_UNKNOWN_SERVICE
)
146 data_buf
= kzalloc(RTAS_DATA_BUF_SIZE
, GFP_KERNEL
);
150 ccwa
= (struct cc_workarea
*)&data_buf
[0];
151 ccwa
->drc_index
= drc_index
;
155 /* Since we release the rtas_data_buf lock between configure
156 * connector calls we want to re-populate the rtas_data_buffer
157 * with the contents of the previous call.
159 spin_lock(&rtas_data_buf_lock
);
161 memcpy(rtas_data_buf
, data_buf
, RTAS_DATA_BUF_SIZE
);
162 rc
= rtas_call(cc_token
, 2, 1, NULL
, rtas_data_buf
, NULL
);
163 memcpy(data_buf
, rtas_data_buf
, RTAS_DATA_BUF_SIZE
);
165 spin_unlock(&rtas_data_buf_lock
);
172 dn
= dlpar_parse_cc_node(ccwa
, parent_path
);
176 dn
->parent
= last_dn
->parent
;
177 last_dn
->sibling
= dn
;
183 parent_path
= last_dn
->full_name
;
185 dn
= dlpar_parse_cc_node(ccwa
, parent_path
);
193 dn
->parent
= last_dn
;
202 property
= dlpar_parse_cc_property(ccwa
);
206 if (!last_dn
->properties
)
207 last_dn
->properties
= property
;
209 last_property
->next
= property
;
211 last_property
= property
;
215 last_dn
= last_dn
->parent
;
216 parent_path
= last_dn
->parent
->full_name
;
225 printk(KERN_ERR
"Unexpected Error (%d) "
226 "returned from configure-connector\n", rc
);
236 dlpar_free_cc_nodes(first_dn
);
244 static struct device_node
*derive_parent(const char *path
)
246 struct device_node
*parent
;
249 last_slash
= strrchr(path
, '/');
250 if (last_slash
== path
) {
251 parent
= of_find_node_by_path("/");
254 int parent_path_len
= last_slash
- path
+ 1;
255 parent_path
= kmalloc(parent_path_len
, GFP_KERNEL
);
259 strlcpy(parent_path
, path
, parent_path_len
);
260 parent
= of_find_node_by_path(parent_path
);
267 int dlpar_attach_node(struct device_node
*dn
)
271 dn
->parent
= derive_parent(dn
->full_name
);
275 rc
= of_attach_node(dn
);
277 printk(KERN_ERR
"Failed to add device node %s\n",
282 of_node_put(dn
->parent
);
286 int dlpar_detach_node(struct device_node
*dn
)
288 struct device_node
*child
;
291 child
= of_get_next_child(dn
, NULL
);
293 dlpar_detach_node(child
);
294 child
= of_get_next_child(dn
, child
);
297 rc
= of_detach_node(dn
);
301 of_node_put(dn
); /* Must decrement the refcount */
305 #define DR_ENTITY_SENSE 9003
306 #define DR_ENTITY_PRESENT 1
307 #define DR_ENTITY_UNUSABLE 2
308 #define ALLOCATION_STATE 9003
309 #define ALLOC_UNUSABLE 0
310 #define ALLOC_USABLE 1
311 #define ISOLATION_STATE 9001
315 int dlpar_acquire_drc(u32 drc_index
)
319 rc
= rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status
,
320 DR_ENTITY_SENSE
, drc_index
);
321 if (rc
|| dr_status
!= DR_ENTITY_UNUSABLE
)
324 rc
= rtas_set_indicator(ALLOCATION_STATE
, drc_index
, ALLOC_USABLE
);
328 rc
= rtas_set_indicator(ISOLATION_STATE
, drc_index
, UNISOLATE
);
330 rtas_set_indicator(ALLOCATION_STATE
, drc_index
, ALLOC_UNUSABLE
);
337 int dlpar_release_drc(u32 drc_index
)
341 rc
= rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status
,
342 DR_ENTITY_SENSE
, drc_index
);
343 if (rc
|| dr_status
!= DR_ENTITY_PRESENT
)
346 rc
= rtas_set_indicator(ISOLATION_STATE
, drc_index
, ISOLATE
);
350 rc
= rtas_set_indicator(ALLOCATION_STATE
, drc_index
, ALLOC_UNUSABLE
);
352 rtas_set_indicator(ISOLATION_STATE
, drc_index
, UNISOLATE
);
359 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
361 static int dlpar_online_cpu(struct device_node
*dn
)
365 int len
, nthreads
, i
;
368 intserv
= of_get_property(dn
, "ibm,ppc-interrupt-server#s", &len
);
372 nthreads
= len
/ sizeof(u32
);
374 cpu_maps_update_begin();
375 for (i
= 0; i
< nthreads
; i
++) {
376 for_each_present_cpu(cpu
) {
377 if (get_hard_smp_processor_id(cpu
) != intserv
[i
])
379 BUG_ON(get_cpu_current_state(cpu
)
380 != CPU_STATE_OFFLINE
);
381 cpu_maps_update_done();
385 cpu_maps_update_begin();
389 if (cpu
== num_possible_cpus())
390 printk(KERN_WARNING
"Could not find cpu to online "
391 "with physical id 0x%x\n", intserv
[i
]);
393 cpu_maps_update_done();
400 static ssize_t
dlpar_cpu_probe(const char *buf
, size_t count
)
402 struct device_node
*dn
, *parent
;
406 rc
= kstrtou32(buf
, 0, &drc_index
);
410 parent
= of_find_node_by_path("/cpus");
414 dn
= dlpar_configure_connector(drc_index
, parent
);
420 rc
= dlpar_acquire_drc(drc_index
);
422 dlpar_free_cc_nodes(dn
);
426 rc
= dlpar_attach_node(dn
);
428 dlpar_release_drc(drc_index
);
429 dlpar_free_cc_nodes(dn
);
433 rc
= dlpar_online_cpu(dn
);
440 static int dlpar_offline_cpu(struct device_node
*dn
)
444 int len
, nthreads
, i
;
447 intserv
= of_get_property(dn
, "ibm,ppc-interrupt-server#s", &len
);
451 nthreads
= len
/ sizeof(u32
);
453 cpu_maps_update_begin();
454 for (i
= 0; i
< nthreads
; i
++) {
455 for_each_present_cpu(cpu
) {
456 if (get_hard_smp_processor_id(cpu
) != intserv
[i
])
459 if (get_cpu_current_state(cpu
) == CPU_STATE_OFFLINE
)
462 if (get_cpu_current_state(cpu
) == CPU_STATE_ONLINE
) {
463 set_preferred_offline_state(cpu
, CPU_STATE_OFFLINE
);
464 cpu_maps_update_done();
468 cpu_maps_update_begin();
474 * The cpu is in CPU_STATE_INACTIVE.
475 * Upgrade it's state to CPU_STATE_OFFLINE.
477 set_preferred_offline_state(cpu
, CPU_STATE_OFFLINE
);
478 BUG_ON(plpar_hcall_norets(H_PROD
, intserv
[i
])
483 if (cpu
== num_possible_cpus())
484 printk(KERN_WARNING
"Could not find cpu to offline "
485 "with physical id 0x%x\n", intserv
[i
]);
487 cpu_maps_update_done();
494 static ssize_t
dlpar_cpu_release(const char *buf
, size_t count
)
496 struct device_node
*dn
;
497 const u32
*drc_index
;
500 dn
= of_find_node_by_path(buf
);
504 drc_index
= of_get_property(dn
, "ibm,my-drc-index", NULL
);
510 rc
= dlpar_offline_cpu(dn
);
516 rc
= dlpar_release_drc(*drc_index
);
522 rc
= dlpar_detach_node(dn
);
524 dlpar_acquire_drc(*drc_index
);
533 static int __init
pseries_dlpar_init(void)
535 ppc_md
.cpu_probe
= dlpar_cpu_probe
;
536 ppc_md
.cpu_release
= dlpar_cpu_release
;
540 machine_device_initcall(pseries
, pseries_dlpar_init
);
542 #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */