xref: /linux/arch/arm/include/asm/smp_plat.h (revision 787047eea24a2443c366679ae6b5a3873a33b64e)
1e616c591SRussell King /*
2e616c591SRussell King  * ARM specific SMP header, this contains our implementation
3e616c591SRussell King  * details.
4e616c591SRussell King  */
5e616c591SRussell King #ifndef __ASMARM_SMP_PLAT_H
6e616c591SRussell King #define __ASMARM_SMP_PLAT_H
7e616c591SRussell King 
87f124aafSLorenzo Pieralisi #include <linux/cpumask.h>
97f124aafSLorenzo Pieralisi #include <linux/err.h>
107f124aafSLorenzo Pieralisi 
11eba1c718SJuri Lelli #include <asm/cpu.h>
12e616c591SRussell King #include <asm/cputype.h>
13e616c591SRussell King 
14f00ec48fSRussell King /*
15f00ec48fSRussell King  * Return true if we are running on a SMP platform
16f00ec48fSRussell King  */
17f00ec48fSRussell King static inline bool is_smp(void)
18f00ec48fSRussell King {
19f00ec48fSRussell King #ifndef CONFIG_SMP
20f00ec48fSRussell King 	return false;
21f00ec48fSRussell King #elif defined(CONFIG_SMP_ON_UP)
22f00ec48fSRussell King 	extern unsigned int smp_on_up;
23f00ec48fSRussell King 	return !!smp_on_up;
24f00ec48fSRussell King #else
25f00ec48fSRussell King 	return true;
26f00ec48fSRussell King #endif
27f00ec48fSRussell King }
28f00ec48fSRussell King 
29eba1c718SJuri Lelli /**
30eba1c718SJuri Lelli  * smp_cpuid_part() - return part id for a given cpu
31eba1c718SJuri Lelli  * @cpu:	logical cpu id.
32eba1c718SJuri Lelli  *
33eba1c718SJuri Lelli  * Return: part id of logical cpu passed as argument.
34eba1c718SJuri Lelli  */
35eba1c718SJuri Lelli static inline unsigned int smp_cpuid_part(int cpu)
36eba1c718SJuri Lelli {
37eba1c718SJuri Lelli 	struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpu);
38eba1c718SJuri Lelli 
39eba1c718SJuri Lelli 	return is_smp() ? cpu_info->cpuid & ARM_CPU_PART_MASK :
40eba1c718SJuri Lelli 			  read_cpuid_part();
41eba1c718SJuri Lelli }
42eba1c718SJuri Lelli 
43e616c591SRussell King /* all SMP configurations have the extended CPUID registers */
445c709e69SWill Deacon #ifndef CONFIG_MMU
455c709e69SWill Deacon #define tlb_ops_need_broadcast()	0
465c709e69SWill Deacon #else
47e616c591SRussell King static inline int tlb_ops_need_broadcast(void)
48e616c591SRussell King {
497511db9dSTony Lindgren 	if (!is_smp())
507511db9dSTony Lindgren 		return 0;
517511db9dSTony Lindgren 
52e616c591SRussell King 	return ((read_cpuid_ext(CPUID_EXT_MMFR3) >> 12) & 0xf) < 2;
53e616c591SRussell King }
545c709e69SWill Deacon #endif
55e616c591SRussell King 
5685848dd7SCatalin Marinas #if !defined(CONFIG_SMP) || __LINUX_ARM_ARCH__ >= 7
5785848dd7SCatalin Marinas #define cache_ops_need_broadcast()	0
5885848dd7SCatalin Marinas #else
592ef7f3dbSRussell King static inline int cache_ops_need_broadcast(void)
602ef7f3dbSRussell King {
617511db9dSTony Lindgren 	if (!is_smp())
627511db9dSTony Lindgren 		return 0;
637511db9dSTony Lindgren 
642ef7f3dbSRussell King 	return ((read_cpuid_ext(CPUID_EXT_MMFR3) >> 12) & 0xf) < 1;
652ef7f3dbSRussell King }
6685848dd7SCatalin Marinas #endif
672ef7f3dbSRussell King 
68eb50439bSWill Deacon /*
69eb50439bSWill Deacon  * Logical CPU mapping.
70eb50439bSWill Deacon  */
7118d7f152SLorenzo Pieralisi extern u32 __cpu_logical_map[];
72eb50439bSWill Deacon #define cpu_logical_map(cpu)	__cpu_logical_map[cpu]
737f124aafSLorenzo Pieralisi /*
747f124aafSLorenzo Pieralisi  * Retrieve logical cpu index corresponding to a given MPIDR[23:0]
757f124aafSLorenzo Pieralisi  *  - mpidr: MPIDR[23:0] to be used for the look-up
767f124aafSLorenzo Pieralisi  *
777f124aafSLorenzo Pieralisi  * Returns the cpu logical index or -EINVAL on look-up error
787f124aafSLorenzo Pieralisi  */
797f124aafSLorenzo Pieralisi static inline int get_logical_index(u32 mpidr)
807f124aafSLorenzo Pieralisi {
817f124aafSLorenzo Pieralisi 	int cpu;
827f124aafSLorenzo Pieralisi 	for (cpu = 0; cpu < nr_cpu_ids; cpu++)
837f124aafSLorenzo Pieralisi 		if (cpu_logical_map(cpu) == mpidr)
847f124aafSLorenzo Pieralisi 			return cpu;
857f124aafSLorenzo Pieralisi 	return -EINVAL;
867f124aafSLorenzo Pieralisi }
87eb50439bSWill Deacon 
887604537bSLorenzo Pieralisi /*
897604537bSLorenzo Pieralisi  * NOTE ! Assembly code relies on the following
907604537bSLorenzo Pieralisi  * structure memory layout in order to carry out load
917604537bSLorenzo Pieralisi  * multiple from its base address. For more
927604537bSLorenzo Pieralisi  * information check arch/arm/kernel/sleep.S
937604537bSLorenzo Pieralisi  */
948cf72172SLorenzo Pieralisi struct mpidr_hash {
957604537bSLorenzo Pieralisi 	u32	mask; /* used by sleep.S */
967604537bSLorenzo Pieralisi 	u32	shift_aff[3]; /* used by sleep.S */
978cf72172SLorenzo Pieralisi 	u32	bits;
988cf72172SLorenzo Pieralisi };
998cf72172SLorenzo Pieralisi 
1008cf72172SLorenzo Pieralisi extern struct mpidr_hash mpidr_hash;
1018cf72172SLorenzo Pieralisi 
1028cf72172SLorenzo Pieralisi static inline u32 mpidr_hash_size(void)
1038cf72172SLorenzo Pieralisi {
1048cf72172SLorenzo Pieralisi 	return 1 << mpidr_hash.bits;
1058cf72172SLorenzo Pieralisi }
1062103f6cbSStephen Warren 
107fee3fd4fSGeert Uytterhoeven extern int platform_can_secondary_boot(void);
1082103f6cbSStephen Warren extern int platform_can_cpu_hotplug(void);
1092103f6cbSStephen Warren 
110*787047eeSStephen Boyd #ifdef CONFIG_HOTPLUG_CPU
111*787047eeSStephen Boyd extern int platform_can_hotplug_cpu(unsigned int cpu);
112*787047eeSStephen Boyd #else
113*787047eeSStephen Boyd static inline int platform_can_hotplug_cpu(unsigned int cpu)
114*787047eeSStephen Boyd {
115*787047eeSStephen Boyd 	return 0;
116*787047eeSStephen Boyd }
117*787047eeSStephen Boyd #endif
118*787047eeSStephen Boyd 
119e616c591SRussell King #endif
120