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#ifndef _NETLOGIC_COMMON_H_
368c2ecf20Sopenharmony_ci#define _NETLOGIC_COMMON_H_
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * Common SMP definitions
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci#define RESET_VEC_PHYS		0x1fc00000
428c2ecf20Sopenharmony_ci#define RESET_VEC_SIZE		8192		/* 8KB reset code and data */
438c2ecf20Sopenharmony_ci#define RESET_DATA_PHYS		(RESET_VEC_PHYS + (1<<10))
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* Offsets of parameters in the RESET_DATA_PHYS area */
468c2ecf20Sopenharmony_ci#define BOOT_THREAD_MODE	0
478c2ecf20Sopenharmony_ci#define BOOT_NMI_LOCK		4
488c2ecf20Sopenharmony_ci#define BOOT_NMI_HANDLER	8
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* CPU ready flags for each CPU */
518c2ecf20Sopenharmony_ci#define BOOT_CPU_READY		2048
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
548c2ecf20Sopenharmony_ci#include <linux/cpumask.h>
558c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
568c2ecf20Sopenharmony_ci#include <asm/irq.h>
578c2ecf20Sopenharmony_ci#include <asm/mach-netlogic/multi-node.h>
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistruct irq_desc;
608c2ecf20Sopenharmony_civoid nlm_smp_function_ipi_handler(struct irq_desc *desc);
618c2ecf20Sopenharmony_civoid nlm_smp_resched_ipi_handler(struct irq_desc *desc);
628c2ecf20Sopenharmony_civoid nlm_smp_irq_init(int hwcpuid);
638c2ecf20Sopenharmony_civoid nlm_boot_secondary_cpus(void);
648c2ecf20Sopenharmony_ciint nlm_wakeup_secondary_cpus(void);
658c2ecf20Sopenharmony_civoid nlm_rmiboot_preboot(void);
668c2ecf20Sopenharmony_civoid nlm_percpu_init(int hwcpuid);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic inline void *
698c2ecf20Sopenharmony_cinlm_get_boot_data(int offset)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	return (void *)(CKSEG1ADDR(RESET_DATA_PHYS) + offset);
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic inline void
758c2ecf20Sopenharmony_cinlm_set_nmi_handler(void *handler)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	void *nmih = nlm_get_boot_data(BOOT_NMI_HANDLER);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	*(int64_t *)nmih = (long)handler;
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/*
838c2ecf20Sopenharmony_ci * Misc.
848c2ecf20Sopenharmony_ci */
858c2ecf20Sopenharmony_civoid nlm_init_boot_cpu(void);
868c2ecf20Sopenharmony_ciunsigned int nlm_get_cpu_frequency(void);
878c2ecf20Sopenharmony_ciextern const struct plat_smp_ops nlm_smp_ops;
888c2ecf20Sopenharmony_ciextern char nlm_reset_entry[], nlm_reset_entry_end[];
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ciextern unsigned int nlm_threads_per_core;
918c2ecf20Sopenharmony_ciextern cpumask_t nlm_cpumask;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct irq_data;
948c2ecf20Sopenharmony_ciuint64_t nlm_pci_irqmask(int node);
958c2ecf20Sopenharmony_civoid nlm_setup_pic_irq(int node, int picirq, int irq, int irt);
968c2ecf20Sopenharmony_civoid nlm_set_pic_extra_ack(int node, int irq,  void (*xack)(struct irq_data *));
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_MSI
998c2ecf20Sopenharmony_civoid nlm_dispatch_msi(int node, int lirq);
1008c2ecf20Sopenharmony_civoid nlm_dispatch_msix(int node, int msixirq);
1018c2ecf20Sopenharmony_ci#endif
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/*
1048c2ecf20Sopenharmony_ci * The NR_IRQs is divided between nodes, each of them has a separate irq space
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_cistatic inline int nlm_irq_to_xirq(int node, int irq)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci	return node * NR_IRQS / NLM_NR_NODES + irq;
1098c2ecf20Sopenharmony_ci}
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_XLR
1128c2ecf20Sopenharmony_ci#define nlm_cores_per_node()	8
1138c2ecf20Sopenharmony_ci#else
1148c2ecf20Sopenharmony_cistatic inline int nlm_cores_per_node(void)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	return ((read_c0_prid() & PRID_IMP_MASK)
1178c2ecf20Sopenharmony_ci				== PRID_IMP_NETLOGIC_XLP9XX) ? 32 : 8;
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci#endif
1208c2ecf20Sopenharmony_cistatic inline int nlm_threads_per_node(void)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	return nlm_cores_per_node() * NLM_THREADS_PER_CORE;
1238c2ecf20Sopenharmony_ci}
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistatic inline int nlm_hwtid_to_node(int hwtid)
1268c2ecf20Sopenharmony_ci{
1278c2ecf20Sopenharmony_ci	return hwtid / nlm_threads_per_node();
1288c2ecf20Sopenharmony_ci}
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ciextern int nlm_cpu_ready[];
1318c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
1328c2ecf20Sopenharmony_ci#endif /* _NETLOGIC_COMMON_H_ */
133