23 #include <linux/list.h>
24 #include <linux/export.h>
25 #include <linux/ptrace.h>
26 #include <linux/wait.h>
30 #include <linux/device.h>
49 const unsigned int *prop;
70 static void spu_unmap(
struct spu *spu)
72 if (!firmware_has_feature(FW_FEATURE_LPAR))
79 static int __init spu_map_interrupts_old(
struct spu *spu,
100 isrc |= nid << IIC_IRQ_NODE_SHIFT;
111 static void __iomem *
__init spu_map_prop_old(
struct spu *spu,
115 const struct address_prop {
122 if (prop ==
NULL || proplen !=
sizeof (
struct address_prop))
125 return ioremap(prop->address, prop->len);
128 static int __init spu_map_device_old(
struct spu *spu)
142 spu->local_store_phys = *(
unsigned long *)prop;
145 spu->local_store = (
void __force *)
146 spu_map_prop_old(spu, node,
"local-store");
147 if (!spu->local_store)
153 spu->problem_phys = *(
unsigned long *)prop;
155 spu->problem = spu_map_prop_old(spu, node,
"problem");
159 spu->priv2 = spu_map_prop_old(spu, node,
"priv2");
163 if (!firmware_has_feature(FW_FEATURE_LPAR)) {
164 spu->priv1 = spu_map_prop_old(spu, node,
"priv1");
184 for (i=0; i < 3; i++) {
187 pr_debug(
"spu_new: failed to get irq %d\n", i);
191 pr_debug(
" irq %d no 0x%x on %s\n", i, oirq.specifier[0],
192 oirq.controller->full_name);
194 oirq.specifier, oirq.size);
195 if (spu->irqs[i] ==
NO_IRQ) {
196 pr_debug(
"spu_new: failed to map it !\n");
203 pr_debug(
"failed to map irq %x for spu %s\n", *oirq.specifier,
205 for (; i >= 0; i--) {
206 if (spu->irqs[i] !=
NO_IRQ)
212 static int spu_map_resource(
struct spu *spu,
int nr,
224 *phys = resource.
start;
225 len = resource_size(&resource);
232 static int __init spu_map_device(
struct spu *spu)
241 ret = spu_map_resource(spu, 0, (
void __iomem**)&spu->local_store,
242 &spu->local_store_phys);
244 pr_debug(
"spu_new: failed to map %s resource 0\n",
248 ret = spu_map_resource(spu, 1, (
void __iomem**)&spu->problem,
251 pr_debug(
"spu_new: failed to map %s resource 1\n",
255 ret = spu_map_resource(spu, 2, (
void __iomem**)&spu->priv2,
NULL);
257 pr_debug(
"spu_new: failed to map %s resource 2\n",
261 if (!firmware_has_feature(FW_FEATURE_LPAR))
262 ret = spu_map_resource(spu, 3,
265 pr_debug(
"spu_new: failed to map %s resource 3\n",
270 pr_debug(
" local store : 0x%016lx -> 0x%p\n",
271 spu->local_store_phys, spu->local_store);
272 pr_debug(
" problem state : 0x%016lx -> 0x%p\n",
273 spu->problem_phys, spu->problem);
274 pr_debug(
" priv2 : 0x%p\n", spu->priv2);
275 pr_debug(
" priv1 : 0x%p\n", spu->priv1);
282 pr_debug(
"failed to map spe %s: %d\n", spu->name, ret);
286 static int __init of_enumerate_spus(
int (*
fn)(
void *
data))
298 __func__, node->
name);
303 return ret ? ret :
n;
306 static int __init of_create_spu(
struct spu *spu,
void *data)
310 static int legacy_map = 0, legacy_irq = 0;
312 spu->devnode = of_node_get(spe);
313 spu->spe_id = find_spu_unit_number(spe);
318 " node number too big\n", spe->
full_name, spu->node);
324 ret = spu_map_device(spu);
329 "trying to map old style\n", __func__);
331 ret = spu_map_device_old(spu);
339 ret = spu_map_interrupts(spu, spe);
344 "trying old style irq\n", __func__);
346 ret = spu_map_interrupts_old(spu, spe);
354 pr_debug(
"Using SPE %s %p %p %p %p %d\n", spu->name,
355 spu->local_store, spu->problem, spu->priv1,
356 spu->priv2, spu->number);
365 static int of_destroy_spu(
struct spu *spu)
368 of_node_put(spu->devnode);
374 ctx->
ops->master_start(ctx);
377 static void disable_spu_by_master_run(
struct spu_context *ctx)
379 ctx->
ops->master_stop(ctx);
383 #define QS20_SPES_PER_BE 8
387 static struct spu *spu_lookup_reg(
int node,
u32 reg)
400 static void init_affinity_qs20_harcoded(
void)
403 struct spu *last_spu, *spu;
409 reg = qs20_reg_idxs[
i];
410 spu = spu_lookup_reg(node, reg);
413 spu->has_mem_affinity = qs20_reg_memory[
reg];
416 &last_spu->aff_list);
422 static int of_has_vicinity(
void)
426 for_each_node_by_type(dn,
"spe") {
435 static struct spu *devnode_spu(
int cbe,
struct device_node *dn)
458 for (i=0; i < (lenp /
sizeof(
phandle)); i++) {
459 if (vic_handles[i] == target->phandle)
466 static void init_affinity_node(
int cbe)
468 struct spu *spu, *last_spu;
478 for (added = 1; added <
cbe_spu_info[cbe].n_spus; added++) {
486 for (i = 0; i < (lenp /
sizeof(
phandle)); i++) {
487 if (vic_handles[i] == avoid_ph)
499 if (
strcmp(name,
"spe") == 0) {
500 spu = devnode_spu(cbe, vic_dn);
501 avoid_ph = last_spu_dn->
phandle;
509 spu = neighbour_spu(cbe, vic_dn, last_spu_dn);
512 if (!
strcmp(name,
"mic-tm")) {
513 last_spu->has_mem_affinity = 1;
514 spu->has_mem_affinity = 1;
526 static void init_affinity_fw(
void)
531 init_affinity_node(cbe);
534 static int __init init_affinity(
void)
536 if (of_has_vicinity()) {
539 long root = of_get_flat_dt_root();
540 if (of_flat_dt_is_compatible(root,
"IBM,CPBW-1.0"))
541 init_affinity_qs20_harcoded();
543 printk(
"No affinity configuration found\n");
550 .enumerate_spus = of_enumerate_spus,
551 .create_spu = of_create_spu,
552 .destroy_spu = of_destroy_spu,
553 .enable_spu = enable_spu_by_master_run,
554 .disable_spu = disable_spu_by_master_run,
555 .init_affinity = init_affinity,