2009-11-24 21:10:49 +00:00
|
|
|
/*
|
|
|
|
* Support for dynamic reconfiguration for PCI, Memory, and CPU
|
|
|
|
* Hotplug and Dynamic Logical Partitioning on RPA platforms.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Nathan Fontenot
|
|
|
|
* Copyright (C) 2009 IBM Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version
|
|
|
|
* 2 as published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/kref.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/cpu.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2012-10-02 16:57:57 +00:00
|
|
|
#include <linux/of.h>
|
2009-11-26 09:58:55 +00:00
|
|
|
#include "offline_states.h"
|
2009-11-24 21:10:49 +00:00
|
|
|
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/rtas.h>
|
|
|
|
|
|
|
|
struct cc_workarea {
|
|
|
|
u32 drc_index;
|
|
|
|
u32 zero;
|
|
|
|
u32 name_offset;
|
|
|
|
u32 prop_length;
|
|
|
|
u32 prop_offset;
|
|
|
|
};
|
|
|
|
|
2010-09-10 09:40:32 +00:00
|
|
|
void dlpar_free_cc_property(struct property *prop)
|
2009-11-24 21:10:49 +00:00
|
|
|
{
|
|
|
|
kfree(prop->name);
|
|
|
|
kfree(prop->value);
|
|
|
|
kfree(prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct property *dlpar_parse_cc_property(struct cc_workarea *ccwa)
|
|
|
|
{
|
|
|
|
struct property *prop;
|
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
prop = kzalloc(sizeof(*prop), GFP_KERNEL);
|
|
|
|
if (!prop)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
name = (char *)ccwa + ccwa->name_offset;
|
|
|
|
prop->name = kstrdup(name, GFP_KERNEL);
|
|
|
|
|
|
|
|
prop->length = ccwa->prop_length;
|
|
|
|
value = (char *)ccwa + ccwa->prop_offset;
|
2010-09-15 08:05:49 +00:00
|
|
|
prop->value = kmemdup(value, prop->length, GFP_KERNEL);
|
2009-11-24 21:10:49 +00:00
|
|
|
if (!prop->value) {
|
|
|
|
dlpar_free_cc_property(prop);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_node *dlpar_parse_cc_node(struct cc_workarea *ccwa)
|
|
|
|
{
|
|
|
|
struct device_node *dn;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
dn = kzalloc(sizeof(*dn), GFP_KERNEL);
|
|
|
|
if (!dn)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* The configure connector reported name does not contain a
|
2011-03-31 01:57:33 +00:00
|
|
|
* preceding '/', so we allocate a buffer large enough to
|
2009-11-24 21:10:49 +00:00
|
|
|
* prepend this to the full_name.
|
|
|
|
*/
|
|
|
|
name = (char *)ccwa + ccwa->name_offset;
|
2010-03-10 11:15:01 +00:00
|
|
|
dn->full_name = kasprintf(GFP_KERNEL, "/%s", name);
|
2009-11-24 21:10:49 +00:00
|
|
|
if (!dn->full_name) {
|
|
|
|
kfree(dn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dlpar_free_one_cc_node(struct device_node *dn)
|
|
|
|
{
|
|
|
|
struct property *prop;
|
|
|
|
|
|
|
|
while (dn->properties) {
|
|
|
|
prop = dn->properties;
|
|
|
|
dn->properties = prop->next;
|
|
|
|
dlpar_free_cc_property(prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dn->full_name);
|
|
|
|
kfree(dn);
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:40:32 +00:00
|
|
|
void dlpar_free_cc_nodes(struct device_node *dn)
|
2009-11-24 21:10:49 +00:00
|
|
|
{
|
|
|
|
if (dn->child)
|
|
|
|
dlpar_free_cc_nodes(dn->child);
|
|
|
|
|
|
|
|
if (dn->sibling)
|
|
|
|
dlpar_free_cc_nodes(dn->sibling);
|
|
|
|
|
|
|
|
dlpar_free_one_cc_node(dn);
|
|
|
|
}
|
|
|
|
|
2011-08-14 14:30:30 +00:00
|
|
|
#define COMPLETE 0
|
2009-11-24 21:10:49 +00:00
|
|
|
#define NEXT_SIBLING 1
|
|
|
|
#define NEXT_CHILD 2
|
|
|
|
#define NEXT_PROPERTY 3
|
|
|
|
#define PREV_PARENT 4
|
|
|
|
#define MORE_MEMORY 5
|
|
|
|
#define CALL_AGAIN -2
|
|
|
|
#define ERR_CFG_USE -9003
|
|
|
|
|
|
|
|
struct device_node *dlpar_configure_connector(u32 drc_index)
|
|
|
|
{
|
|
|
|
struct device_node *dn;
|
|
|
|
struct device_node *first_dn = NULL;
|
|
|
|
struct device_node *last_dn = NULL;
|
|
|
|
struct property *property;
|
|
|
|
struct property *last_property = NULL;
|
|
|
|
struct cc_workarea *ccwa;
|
2010-08-18 09:58:46 +00:00
|
|
|
char *data_buf;
|
2009-11-24 21:10:49 +00:00
|
|
|
int cc_token;
|
2010-08-18 09:58:46 +00:00
|
|
|
int rc = -1;
|
2009-11-24 21:10:49 +00:00
|
|
|
|
|
|
|
cc_token = rtas_token("ibm,configure-connector");
|
|
|
|
if (cc_token == RTAS_UNKNOWN_SERVICE)
|
|
|
|
return NULL;
|
|
|
|
|
2010-08-18 09:58:46 +00:00
|
|
|
data_buf = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
|
|
|
|
if (!data_buf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ccwa = (struct cc_workarea *)&data_buf[0];
|
2009-11-24 21:10:49 +00:00
|
|
|
ccwa->drc_index = drc_index;
|
|
|
|
ccwa->zero = 0;
|
|
|
|
|
2010-08-18 09:58:46 +00:00
|
|
|
do {
|
|
|
|
/* Since we release the rtas_data_buf lock between configure
|
|
|
|
* connector calls we want to re-populate the rtas_data_buffer
|
|
|
|
* with the contents of the previous call.
|
|
|
|
*/
|
|
|
|
spin_lock(&rtas_data_buf_lock);
|
|
|
|
|
|
|
|
memcpy(rtas_data_buf, data_buf, RTAS_DATA_BUF_SIZE);
|
|
|
|
rc = rtas_call(cc_token, 2, 1, NULL, rtas_data_buf, NULL);
|
|
|
|
memcpy(data_buf, rtas_data_buf, RTAS_DATA_BUF_SIZE);
|
|
|
|
|
|
|
|
spin_unlock(&rtas_data_buf_lock);
|
|
|
|
|
2009-11-24 21:10:49 +00:00
|
|
|
switch (rc) {
|
2011-08-14 14:30:30 +00:00
|
|
|
case COMPLETE:
|
|
|
|
break;
|
|
|
|
|
2009-11-24 21:10:49 +00:00
|
|
|
case NEXT_SIBLING:
|
|
|
|
dn = dlpar_parse_cc_node(ccwa);
|
|
|
|
if (!dn)
|
|
|
|
goto cc_error;
|
|
|
|
|
|
|
|
dn->parent = last_dn->parent;
|
|
|
|
last_dn->sibling = dn;
|
|
|
|
last_dn = dn;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NEXT_CHILD:
|
|
|
|
dn = dlpar_parse_cc_node(ccwa);
|
|
|
|
if (!dn)
|
|
|
|
goto cc_error;
|
|
|
|
|
|
|
|
if (!first_dn)
|
|
|
|
first_dn = dn;
|
|
|
|
else {
|
|
|
|
dn->parent = last_dn;
|
|
|
|
if (last_dn)
|
|
|
|
last_dn->child = dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_dn = dn;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NEXT_PROPERTY:
|
|
|
|
property = dlpar_parse_cc_property(ccwa);
|
|
|
|
if (!property)
|
|
|
|
goto cc_error;
|
|
|
|
|
|
|
|
if (!last_dn->properties)
|
|
|
|
last_dn->properties = property;
|
|
|
|
else
|
|
|
|
last_property->next = property;
|
|
|
|
|
|
|
|
last_property = property;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PREV_PARENT:
|
|
|
|
last_dn = last_dn->parent;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CALL_AGAIN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MORE_MEMORY:
|
|
|
|
case ERR_CFG_USE:
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "Unexpected Error (%d) "
|
|
|
|
"returned from configure-connector\n", rc);
|
|
|
|
goto cc_error;
|
|
|
|
}
|
2010-08-18 09:58:46 +00:00
|
|
|
} while (rc);
|
2009-11-24 21:10:49 +00:00
|
|
|
|
2010-08-18 09:58:46 +00:00
|
|
|
cc_error:
|
|
|
|
kfree(data_buf);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
if (first_dn)
|
|
|
|
dlpar_free_cc_nodes(first_dn);
|
|
|
|
|
|
|
|
return NULL;
|
2009-11-24 21:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return first_dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_node *derive_parent(const char *path)
|
|
|
|
{
|
|
|
|
struct device_node *parent;
|
|
|
|
char *last_slash;
|
|
|
|
|
|
|
|
last_slash = strrchr(path, '/');
|
|
|
|
if (last_slash == path) {
|
|
|
|
parent = of_find_node_by_path("/");
|
|
|
|
} else {
|
|
|
|
char *parent_path;
|
|
|
|
int parent_path_len = last_slash - path + 1;
|
|
|
|
parent_path = kmalloc(parent_path_len, GFP_KERNEL);
|
|
|
|
if (!parent_path)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
strlcpy(parent_path, path, parent_path_len);
|
|
|
|
parent = of_find_node_by_path(parent_path);
|
|
|
|
kfree(parent_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dlpar_attach_node(struct device_node *dn)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
of_node_set_flag(dn, OF_DYNAMIC);
|
|
|
|
kref_init(&dn->kref);
|
|
|
|
dn->parent = derive_parent(dn->full_name);
|
|
|
|
if (!dn->parent)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-10-02 16:57:57 +00:00
|
|
|
rc = of_attach_node(dn);
|
2011-06-21 03:35:55 +00:00
|
|
|
if (rc) {
|
2009-11-24 21:10:49 +00:00
|
|
|
printk(KERN_ERR "Failed to add device node %s\n",
|
|
|
|
dn->full_name);
|
2011-06-21 03:35:55 +00:00
|
|
|
return rc;
|
2009-11-24 21:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(dn->parent);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dlpar_detach_node(struct device_node *dn)
|
|
|
|
{
|
2012-10-02 16:57:57 +00:00
|
|
|
int rc;
|
2009-11-24 21:10:49 +00:00
|
|
|
|
2012-10-02 16:57:57 +00:00
|
|
|
rc = of_detach_node(dn);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
of_node_put(dn); /* Must decrement the refcount */
|
2009-11-24 21:10:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DR_ENTITY_SENSE 9003
|
|
|
|
#define DR_ENTITY_PRESENT 1
|
|
|
|
#define DR_ENTITY_UNUSABLE 2
|
|
|
|
#define ALLOCATION_STATE 9003
|
|
|
|
#define ALLOC_UNUSABLE 0
|
|
|
|
#define ALLOC_USABLE 1
|
|
|
|
#define ISOLATION_STATE 9001
|
|
|
|
#define ISOLATE 0
|
|
|
|
#define UNISOLATE 1
|
|
|
|
|
|
|
|
int dlpar_acquire_drc(u32 drc_index)
|
|
|
|
{
|
|
|
|
int dr_status, rc;
|
|
|
|
|
|
|
|
rc = rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status,
|
|
|
|
DR_ENTITY_SENSE, drc_index);
|
|
|
|
if (rc || dr_status != DR_ENTITY_UNUSABLE)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
rc = rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_USABLE);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = rtas_set_indicator(ISOLATION_STATE, drc_index, UNISOLATE);
|
|
|
|
if (rc) {
|
|
|
|
rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_UNUSABLE);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dlpar_release_drc(u32 drc_index)
|
|
|
|
{
|
|
|
|
int dr_status, rc;
|
|
|
|
|
|
|
|
rc = rtas_call(rtas_token("get-sensor-state"), 2, 2, &dr_status,
|
|
|
|
DR_ENTITY_SENSE, drc_index);
|
|
|
|
if (rc || dr_status != DR_ENTITY_PRESENT)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
rc = rtas_set_indicator(ISOLATION_STATE, drc_index, ISOLATE);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_UNUSABLE);
|
|
|
|
if (rc) {
|
|
|
|
rtas_set_indicator(ISOLATION_STATE, drc_index, UNISOLATE);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-24 21:13:32 +00:00
|
|
|
#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
|
2009-11-24 21:10:49 +00:00
|
|
|
|
2009-12-08 09:48:44 +00:00
|
|
|
static int dlpar_online_cpu(struct device_node *dn)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
unsigned int cpu;
|
|
|
|
int len, nthreads, i;
|
|
|
|
const u32 *intserv;
|
|
|
|
|
|
|
|
intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", &len);
|
|
|
|
if (!intserv)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nthreads = len / sizeof(u32);
|
|
|
|
|
|
|
|
cpu_maps_update_begin();
|
|
|
|
for (i = 0; i < nthreads; i++) {
|
|
|
|
for_each_present_cpu(cpu) {
|
|
|
|
if (get_hard_smp_processor_id(cpu) != intserv[i])
|
|
|
|
continue;
|
|
|
|
BUG_ON(get_cpu_current_state(cpu)
|
|
|
|
!= CPU_STATE_OFFLINE);
|
|
|
|
cpu_maps_update_done();
|
|
|
|
rc = cpu_up(cpu);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
cpu_maps_update_begin();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cpu == num_possible_cpus())
|
|
|
|
printk(KERN_WARNING "Could not find cpu to online "
|
|
|
|
"with physical id 0x%x\n", intserv[i]);
|
|
|
|
}
|
|
|
|
cpu_maps_update_done();
|
|
|
|
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-24 21:13:32 +00:00
|
|
|
static ssize_t dlpar_cpu_probe(const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct device_node *dn;
|
|
|
|
unsigned long drc_index;
|
|
|
|
char *cpu_name;
|
|
|
|
int rc;
|
|
|
|
|
2009-11-26 09:59:05 +00:00
|
|
|
cpu_hotplug_driver_lock();
|
2009-11-24 21:13:32 +00:00
|
|
|
rc = strict_strtoul(buf, 0, &drc_index);
|
2009-11-26 09:59:05 +00:00
|
|
|
if (rc) {
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-24 21:13:32 +00:00
|
|
|
|
|
|
|
dn = dlpar_configure_connector(drc_index);
|
2009-11-26 09:59:05 +00:00
|
|
|
if (!dn) {
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-24 21:13:32 +00:00
|
|
|
|
|
|
|
/* configure-connector reports cpus as living in the base
|
|
|
|
* directory of the device tree. CPUs actually live in the
|
|
|
|
* cpus directory so we need to fixup the full_name.
|
|
|
|
*/
|
2010-03-10 11:15:01 +00:00
|
|
|
cpu_name = kasprintf(GFP_KERNEL, "/cpus%s", dn->full_name);
|
2009-11-24 21:13:32 +00:00
|
|
|
if (!cpu_name) {
|
|
|
|
dlpar_free_cc_nodes(dn);
|
2009-11-26 09:59:05 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
2009-11-24 21:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dn->full_name);
|
|
|
|
dn->full_name = cpu_name;
|
|
|
|
|
|
|
|
rc = dlpar_acquire_drc(drc_index);
|
|
|
|
if (rc) {
|
|
|
|
dlpar_free_cc_nodes(dn);
|
2009-11-26 09:59:05 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
2009-11-24 21:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = dlpar_attach_node(dn);
|
|
|
|
if (rc) {
|
|
|
|
dlpar_release_drc(drc_index);
|
|
|
|
dlpar_free_cc_nodes(dn);
|
2010-04-02 02:47:13 +00:00
|
|
|
goto out;
|
2009-11-24 21:13:32 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 09:48:44 +00:00
|
|
|
rc = dlpar_online_cpu(dn);
|
2009-11-26 09:59:05 +00:00
|
|
|
out:
|
|
|
|
cpu_hotplug_driver_unlock();
|
2009-11-26 09:58:55 +00:00
|
|
|
|
2009-11-24 21:13:32 +00:00
|
|
|
return rc ? rc : count;
|
|
|
|
}
|
|
|
|
|
2009-12-08 09:48:44 +00:00
|
|
|
static int dlpar_offline_cpu(struct device_node *dn)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
unsigned int cpu;
|
|
|
|
int len, nthreads, i;
|
|
|
|
const u32 *intserv;
|
|
|
|
|
|
|
|
intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", &len);
|
|
|
|
if (!intserv)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nthreads = len / sizeof(u32);
|
|
|
|
|
|
|
|
cpu_maps_update_begin();
|
|
|
|
for (i = 0; i < nthreads; i++) {
|
|
|
|
for_each_present_cpu(cpu) {
|
|
|
|
if (get_hard_smp_processor_id(cpu) != intserv[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (get_cpu_current_state(cpu) == CPU_STATE_OFFLINE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (get_cpu_current_state(cpu) == CPU_STATE_ONLINE) {
|
2010-07-22 16:43:44 +00:00
|
|
|
set_preferred_offline_state(cpu, CPU_STATE_OFFLINE);
|
2009-12-08 09:48:44 +00:00
|
|
|
cpu_maps_update_done();
|
|
|
|
rc = cpu_down(cpu);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
cpu_maps_update_begin();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The cpu is in CPU_STATE_INACTIVE.
|
|
|
|
* Upgrade it's state to CPU_STATE_OFFLINE.
|
|
|
|
*/
|
|
|
|
set_preferred_offline_state(cpu, CPU_STATE_OFFLINE);
|
|
|
|
BUG_ON(plpar_hcall_norets(H_PROD, intserv[i])
|
|
|
|
!= H_SUCCESS);
|
|
|
|
__cpu_die(cpu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cpu == num_possible_cpus())
|
|
|
|
printk(KERN_WARNING "Could not find cpu to offline "
|
|
|
|
"with physical id 0x%x\n", intserv[i]);
|
|
|
|
}
|
|
|
|
cpu_maps_update_done();
|
|
|
|
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-24 21:13:32 +00:00
|
|
|
static ssize_t dlpar_cpu_release(const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct device_node *dn;
|
|
|
|
const u32 *drc_index;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
dn = of_find_node_by_path(buf);
|
|
|
|
if (!dn)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
drc_index = of_get_property(dn, "ibm,my-drc-index", NULL);
|
|
|
|
if (!drc_index) {
|
|
|
|
of_node_put(dn);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-11-26 09:59:05 +00:00
|
|
|
cpu_hotplug_driver_lock();
|
2009-12-08 09:48:44 +00:00
|
|
|
rc = dlpar_offline_cpu(dn);
|
2009-11-26 09:58:55 +00:00
|
|
|
if (rc) {
|
|
|
|
of_node_put(dn);
|
2009-11-26 09:59:05 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
2009-11-26 09:58:55 +00:00
|
|
|
}
|
|
|
|
|
2009-11-24 21:13:32 +00:00
|
|
|
rc = dlpar_release_drc(*drc_index);
|
|
|
|
if (rc) {
|
|
|
|
of_node_put(dn);
|
2009-11-26 09:59:05 +00:00
|
|
|
goto out;
|
2009-11-24 21:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = dlpar_detach_node(dn);
|
|
|
|
if (rc) {
|
|
|
|
dlpar_acquire_drc(*drc_index);
|
2009-11-26 09:59:05 +00:00
|
|
|
goto out;
|
2009-11-24 21:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(dn);
|
2009-11-26 09:59:05 +00:00
|
|
|
out:
|
|
|
|
cpu_hotplug_driver_unlock();
|
|
|
|
return rc ? rc : count;
|
2009-11-24 21:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init pseries_dlpar_init(void)
|
|
|
|
{
|
|
|
|
ppc_md.cpu_probe = dlpar_cpu_probe;
|
|
|
|
ppc_md.cpu_release = dlpar_cpu_release;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
machine_device_initcall(pseries, pseries_dlpar_init);
|
|
|
|
|
|
|
|
#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
|