-/* Search all cpu device nodes for an offline logical cpu. If a
- * device node has a "ibm,my-drc-index" property (meaning this is an
- * LPAR), paranoid-check whether we own the cpu. For each "thread"
- * of a cpu, if it is offline and has the same hw index as before,
- * grab that in preference.
- */
-static unsigned int find_physical_cpu_to_start(unsigned int old_hwindex)
-{
- struct device_node *np = NULL;
- unsigned int best = -1U;
-
- while ((np = of_find_node_by_type(np, "cpu"))) {
- int nr_threads, len;
- u32 *index = (u32 *)get_property(np, "ibm,my-drc-index", NULL);
- u32 *tid = (u32 *)
- get_property(np, "ibm,ppc-interrupt-server#s", &len);
-
- if (!tid)
- tid = (u32 *)get_property(np, "reg", &len);
-
- if (!tid)
- continue;
-
- /* If there is a drc-index, make sure that we own
- * the cpu.
- */
- if (index) {
- int state;
- int rc = rtas_get_sensor(9003, *index, &state);
- if (rc != 0 || state != 1)
- continue;
- }
-
- nr_threads = len / sizeof(u32);
-
- while (nr_threads--) {
- if (0 == query_cpu_stopped(tid[nr_threads])) {
- best = tid[nr_threads];
- if (best == old_hwindex)
- goto out;
- }
- }
- }
-out:
- of_node_put(np);
- return best;
-}
-
-/**
- * smp_startup_cpu() - start the given cpu
- *
- * At boot time, there is nothing to do. At run-time, call RTAS with
- * the appropriate start location, if the cpu is in the RTAS stopped
- * state.
- *
- * Returns:
- * 0 - failure
- * 1 - success
- */
-static inline int __devinit smp_startup_cpu(unsigned int lcpu)
-{
- int status;
- extern void (*pseries_secondary_smp_init)(unsigned int cpu);
- unsigned long start_here = __pa(pseries_secondary_smp_init);
- unsigned int pcpu;
-
- /* At boot time the cpus are already spinning in hold
- * loops, so nothing to do. */
- if (system_state == SYSTEM_BOOTING)
- return 1;
-
- pcpu = find_physical_cpu_to_start(get_hard_smp_processor_id(lcpu));
- if (pcpu == -1U) {
- printk(KERN_INFO "No more cpus available, failing\n");
- return 0;
- }
-
- /* Fixup atomic count: it exited inside IRQ handler. */
- paca[lcpu].xCurrent->thread_info->preempt_count = 0;
- /* Fixup SLB round-robin so next segment (kernel) goes in segment 0 */
- paca[lcpu].xStab_data.next_round_robin = 0;
-
- /* At boot this is done in prom.c. */
- paca[lcpu].xHwProcNum = pcpu;
-
- status = rtas_call(rtas_token("start-cpu"), 3, 1, NULL,
- pcpu, start_here, lcpu);
- if (status != 0) {
- printk(KERN_ERR "start-cpu failed: %i\n", status);
- return 0;
- }
- return 1;
-}
-
-static inline void look_for_more_cpus(void)
-{
- int num_addr_cell, num_size_cell, len, i, maxcpus;
- struct device_node *np;
- unsigned int *ireg;
-
- /* Find the property which will tell us about how many CPUs
- * we're allowed to have. */
- if ((np = find_path_device("/rtas")) == NULL) {
- printk(KERN_ERR "Could not find /rtas in device tree!");
- return;
- }
- num_addr_cell = prom_n_addr_cells(np);
- num_size_cell = prom_n_size_cells(np);
-
- ireg = (unsigned int *)get_property(np, "ibm,lrdr-capacity", &len);
- if (ireg == NULL) {
- /* FIXME: make sure not marked as lrdr_capable() */
- return;
- }
-
- maxcpus = ireg[num_addr_cell + num_size_cell];
- /* DRENG need to account for threads here too */
-
- if (maxcpus > NR_CPUS) {
- printk(KERN_WARNING
- "Partition configured for %d cpus, "
- "operating system maximum is %d.\n", maxcpus, NR_CPUS);
- maxcpus = NR_CPUS;
- } else
- printk(KERN_INFO "Partition configured for %d cpus.\n",
- maxcpus);
-
- /* Make those cpus (which might appear later) possible too. */
- for (i = 0; i < maxcpus; i++)
- cpu_set(i, cpu_possible_map);
-}
-#else /* ... CONFIG_HOTPLUG_CPU */
-static inline int __devinit smp_startup_cpu(unsigned int lcpu)
-{
- return 1;
-}
-static inline void look_for_more_cpus(void)
-{
-}
-#endif /* CONFIG_HOTPLUG_CPU */
-
-static void smp_pSeries_kick_cpu(int nr)