18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
38c2ecf20Sopenharmony_ci * reserved.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
68c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
78c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
88c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the NetLogic
98c2ecf20Sopenharmony_ci * license below:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
128c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
138c2ecf20Sopenharmony_ci * are met:
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
168c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
178c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
188c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
198c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
208c2ecf20Sopenharmony_ci *    distribution.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
238c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
248c2ecf20Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
258c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
268c2ecf20Sopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
278c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
288c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
298c2ecf20Sopenharmony_ci * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
308c2ecf20Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
318c2ecf20Sopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
328c2ecf20Sopenharmony_ci * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <linux/delay.h>
368c2ecf20Sopenharmony_ci#include <linux/threads.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <asm/asm.h>
398c2ecf20Sopenharmony_ci#include <asm/asm-offsets.h>
408c2ecf20Sopenharmony_ci#include <asm/mipsregs.h>
418c2ecf20Sopenharmony_ci#include <asm/addrspace.h>
428c2ecf20Sopenharmony_ci#include <asm/string.h>
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#include <asm/netlogic/haldefs.h>
458c2ecf20Sopenharmony_ci#include <asm/netlogic/common.h>
468c2ecf20Sopenharmony_ci#include <asm/netlogic/mips-extns.h>
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#include <asm/netlogic/xlr/iomap.h>
498c2ecf20Sopenharmony_ci#include <asm/netlogic/xlr/pic.h>
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciint xlr_wakeup_secondary_cpus(void)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	struct nlm_soc_info *nodep;
548c2ecf20Sopenharmony_ci	unsigned int i, j, boot_cpu;
558c2ecf20Sopenharmony_ci	volatile u32 *cpu_ready = nlm_get_boot_data(BOOT_CPU_READY);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	/*
588c2ecf20Sopenharmony_ci	 *  In case of RMI boot, hit with NMI to get the cores
598c2ecf20Sopenharmony_ci	 *  from bootloader to linux code.
608c2ecf20Sopenharmony_ci	 */
618c2ecf20Sopenharmony_ci	nodep = nlm_get_node(0);
628c2ecf20Sopenharmony_ci	boot_cpu = hard_smp_processor_id();
638c2ecf20Sopenharmony_ci	nlm_set_nmi_handler(nlm_rmiboot_preboot);
648c2ecf20Sopenharmony_ci	for (i = 0; i < NR_CPUS; i++) {
658c2ecf20Sopenharmony_ci		if (i == boot_cpu || !cpumask_test_cpu(i, &nlm_cpumask))
668c2ecf20Sopenharmony_ci			continue;
678c2ecf20Sopenharmony_ci		nlm_pic_send_ipi(nodep->picbase, i, 1, 1); /* send NMI */
688c2ecf20Sopenharmony_ci	}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* Fill up the coremask early */
718c2ecf20Sopenharmony_ci	nodep->coremask = 1;
728c2ecf20Sopenharmony_ci	for (i = 1; i < nlm_cores_per_node(); i++) {
738c2ecf20Sopenharmony_ci		for (j = 1000000; j > 0; j--) {
748c2ecf20Sopenharmony_ci			if (cpu_ready[i * NLM_THREADS_PER_CORE])
758c2ecf20Sopenharmony_ci				break;
768c2ecf20Sopenharmony_ci			udelay(10);
778c2ecf20Sopenharmony_ci		}
788c2ecf20Sopenharmony_ci		if (j != 0)
798c2ecf20Sopenharmony_ci			nodep->coremask |= (1u << i);
808c2ecf20Sopenharmony_ci		else
818c2ecf20Sopenharmony_ci			pr_err("Failed to wakeup core %d\n", i);
828c2ecf20Sopenharmony_ci	}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	return 0;
858c2ecf20Sopenharmony_ci}
86