1 /*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15 #ifndef _ASM_TILE_SMP_H
16 #define _ASM_TILE_SMP_H
17
18 #ifdef CONFIG_SMP
19
20 #include <asm/processor.h>
21 #include <linux/cpumask.h>
22 #include <linux/irqreturn.h>
23 #include <hv/hypervisor.h>
24
25 /* Set up this tile to support receiving hypervisor messages */
26 void init_messaging(void);
27
28 /* Set up this tile to support receiving device interrupts and IPIs. */
29 void init_per_tile_IRQs(void);
30
31 /* Send a message to processors specified in mask */
32 void send_IPI_many(const struct cpumask *mask, int tag);
33
34 /* Send a message to all but the sending processor */
35 void send_IPI_allbutself(int tag);
36
37 /* Send a message to a specific processor */
38 void send_IPI_single(int dest, int tag);
39
40 /* Process an IPI message */
41 void evaluate_message(int tag);
42
43 /* Boot a secondary cpu */
44 void online_secondary(void);
45
46 /* Call a function on a specified set of CPUs (may include this one). */
47 extern void on_each_cpu_mask(const struct cpumask *mask,
48 void (*func)(void *), void *info, bool wait);
49
50 /* Topology of the supervisor tile grid, and coordinates of boot processor */
51 extern HV_Topology smp_topology;
52
53 /* Accessors for grid size */
54 #define smp_height (smp_topology.height)
55 #define smp_width (smp_topology.width)
56
57 /* Convenience functions for converting cpu <-> coords. */
cpu_x(int cpu)58 static inline int cpu_x(int cpu)
59 {
60 return cpu % smp_width;
61 }
cpu_y(int cpu)62 static inline int cpu_y(int cpu)
63 {
64 return cpu / smp_width;
65 }
xy_to_cpu(int x,int y)66 static inline int xy_to_cpu(int x, int y)
67 {
68 return y * smp_width + x;
69 }
70
71 /* Hypervisor message tags sent via the tile send_IPI*() routines. */
72 #define MSG_TAG_START_CPU 1
73 #define MSG_TAG_STOP_CPU 2
74 #define MSG_TAG_CALL_FUNCTION_MANY 3
75 #define MSG_TAG_CALL_FUNCTION_SINGLE 4
76
77 /* Hook for the generic smp_call_function_many() routine. */
arch_send_call_function_ipi_mask(struct cpumask * mask)78 static inline void arch_send_call_function_ipi_mask(struct cpumask *mask)
79 {
80 send_IPI_many(mask, MSG_TAG_CALL_FUNCTION_MANY);
81 }
82
83 /* Hook for the generic smp_call_function_single() routine. */
arch_send_call_function_single_ipi(int cpu)84 static inline void arch_send_call_function_single_ipi(int cpu)
85 {
86 send_IPI_single(cpu, MSG_TAG_CALL_FUNCTION_SINGLE);
87 }
88
89 /* Print out the boot string describing which cpus were disabled. */
90 void print_disabled_cpus(void);
91
92 #else /* !CONFIG_SMP */
93
94 #define on_each_cpu_mask(mask, func, info, wait) \
95 do { if (cpumask_test_cpu(0, (mask))) func(info); } while (0)
96
97 #define smp_master_cpu 0
98 #define smp_height 1
99 #define smp_width 1
100 #define cpu_x(cpu) 0
101 #define cpu_y(cpu) 0
102 #define xy_to_cpu(x, y) 0
103
104 #endif /* !CONFIG_SMP */
105
106
107 /* Which cpus may be used as the lotar in a page table entry. */
108 extern struct cpumask cpu_lotar_map;
109 #define cpu_is_valid_lotar(cpu) cpumask_test_cpu((cpu), &cpu_lotar_map)
110
111 #if CHIP_HAS_CBOX_HOME_MAP()
112 /* Which processors are used for hash-for-home mapping */
113 extern struct cpumask hash_for_home_map;
114 #endif
115
116 /* Which cpus can have their cache flushed by hv_flush_remote(). */
117 extern struct cpumask cpu_cacheable_map;
118 #define cpu_cacheable(cpu) cpumask_test_cpu((cpu), &cpu_cacheable_map)
119
120 /* Convert an HV_LOTAR value into a cpu. */
hv_lotar_to_cpu(HV_LOTAR lotar)121 static inline int hv_lotar_to_cpu(HV_LOTAR lotar)
122 {
123 return HV_LOTAR_X(lotar) + (HV_LOTAR_Y(lotar) * smp_width);
124 }
125
126 /*
127 * Extension of <linux/cpumask.h> functionality when you just want
128 * to express a mask or suppression or inclusion region without
129 * being too concerned about exactly which cpus are valid in that region.
130 */
131 int bitmap_parselist_crop(const char *bp, unsigned long *maskp, int nmaskbits);
132
133 #define cpulist_parse_crop(buf, dst) \
134 __cpulist_parse_crop((buf), (dst), NR_CPUS)
__cpulist_parse_crop(const char * buf,struct cpumask * dstp,int nbits)135 static inline int __cpulist_parse_crop(const char *buf, struct cpumask *dstp,
136 int nbits)
137 {
138 return bitmap_parselist_crop(buf, cpumask_bits(dstp), nbits);
139 }
140
141 /* Initialize the IPI subsystem. */
142 void ipi_init(void);
143
144 /* Function for start-cpu message to cause us to jump to. */
145 extern unsigned long start_cpu_function_addr;
146
147 #endif /* _ASM_TILE_SMP_H */
148