4 * Accessor routines for the various MMIO register blocks of the CBE
6 * (c) 2006 Benjamin Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
9 #include <linux/percpu.h>
10 #include <linux/types.h>
11 #include <linux/module.h>
14 #include <asm/pgtable.h>
16 #include <asm/ptrace.h>
21 * Current implementation uses "cpu" nodes. We build our own mapping
22 * array of cpu numbers to cpu nodes locally for now to allow interrupt
23 * time code to have a fast path rather than call of_get_cpu_node(). If
24 * we implement cpu hotplug, we'll have to install an appropriate norifier
25 * in order to release references to the cpu going away
27 static struct cbe_regs_map
29 struct device_node *cpu_node;
30 struct cbe_pmd_regs __iomem *pmd_regs;
31 struct cbe_iic_regs __iomem *iic_regs;
32 struct cbe_mic_tm_regs __iomem *mic_tm_regs;
33 struct cbe_pmd_shadow_regs pmd_shadow_regs;
34 } cbe_regs_maps[MAX_CBE];
35 static int cbe_regs_map_count;
37 static struct cbe_thread_map
39 struct device_node *cpu_node;
40 struct cbe_regs_map *regs;
41 unsigned int thread_id;
43 } cbe_thread_map[NR_CPUS];
45 static cpumask_t cbe_local_mask[MAX_CBE] = { [0 ... MAX_CBE-1] = CPU_MASK_NONE };
46 static cpumask_t cbe_first_online_cpu = CPU_MASK_NONE;
48 static struct cbe_regs_map *cbe_find_map(struct device_node *np)
51 struct device_node *tmp_np;
53 if (strcasecmp(np->type, "spe") == 0) {
54 if (np->data == NULL) {
55 /* walk up path until cpu node was found */
57 while (tmp_np != NULL && strcasecmp(tmp_np->type, "cpu") != 0)
58 tmp_np = tmp_np->parent;
60 np->data = cbe_find_map(tmp_np);
65 for (i = 0; i < cbe_regs_map_count; i++)
66 if (cbe_regs_maps[i].cpu_node == np)
67 return &cbe_regs_maps[i];
71 struct cbe_pmd_regs __iomem *cbe_get_pmd_regs(struct device_node *np)
73 struct cbe_regs_map *map = cbe_find_map(np);
78 EXPORT_SYMBOL_GPL(cbe_get_pmd_regs);
80 struct cbe_pmd_regs __iomem *cbe_get_cpu_pmd_regs(int cpu)
82 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
87 EXPORT_SYMBOL_GPL(cbe_get_cpu_pmd_regs);
89 struct cbe_pmd_shadow_regs *cbe_get_pmd_shadow_regs(struct device_node *np)
91 struct cbe_regs_map *map = cbe_find_map(np);
94 return &map->pmd_shadow_regs;
97 struct cbe_pmd_shadow_regs *cbe_get_cpu_pmd_shadow_regs(int cpu)
99 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
102 return &map->pmd_shadow_regs;
105 struct cbe_iic_regs __iomem *cbe_get_iic_regs(struct device_node *np)
107 struct cbe_regs_map *map = cbe_find_map(np);
110 return map->iic_regs;
113 struct cbe_iic_regs __iomem *cbe_get_cpu_iic_regs(int cpu)
115 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
118 return map->iic_regs;
121 struct cbe_mic_tm_regs __iomem *cbe_get_mic_tm_regs(struct device_node *np)
123 struct cbe_regs_map *map = cbe_find_map(np);
126 return map->mic_tm_regs;
129 struct cbe_mic_tm_regs __iomem *cbe_get_cpu_mic_tm_regs(int cpu)
131 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
134 return map->mic_tm_regs;
136 EXPORT_SYMBOL_GPL(cbe_get_cpu_mic_tm_regs);
138 u32 cbe_get_hw_thread_id(int cpu)
140 return cbe_thread_map[cpu].thread_id;
142 EXPORT_SYMBOL_GPL(cbe_get_hw_thread_id);
144 u32 cbe_cpu_to_node(int cpu)
146 return cbe_thread_map[cpu].cbe_id;
148 EXPORT_SYMBOL_GPL(cbe_cpu_to_node);
150 u32 cbe_node_to_cpu(int node)
152 return find_first_bit( (unsigned long *) &cbe_local_mask[node], sizeof(cpumask_t));
154 EXPORT_SYMBOL_GPL(cbe_node_to_cpu);
156 void __init cbe_regs_init(void)
159 unsigned int thread_id;
160 struct device_node *cpu;
162 /* Build local fast map of CPUs */
163 for_each_possible_cpu(i) {
164 cbe_thread_map[i].cpu_node = of_get_cpu_node(i, &thread_id);
165 cbe_thread_map[i].thread_id = thread_id;
168 /* Find maps for each device tree CPU */
169 for_each_node_by_type(cpu, "cpu") {
170 struct cbe_regs_map *map;
173 /* That hack must die die die ! */
174 const struct address_prop {
175 unsigned long address;
177 } __attribute__((packed)) *prop;
179 cbe_id = cbe_regs_map_count++;
180 map = &cbe_regs_maps[cbe_id];
182 if (cbe_regs_map_count > MAX_CBE) {
183 printk(KERN_ERR "cbe_regs: More BE chips than supported"
185 cbe_regs_map_count--;
190 for_each_possible_cpu(i) {
191 struct cbe_thread_map *thread = &cbe_thread_map[i];
193 if (thread->cpu_node == cpu) {
195 thread->cbe_id = cbe_id;
196 cpu_set(i, cbe_local_mask[cbe_id]);
197 if(thread->thread_id == 0)
198 cpu_set(i, cbe_first_online_cpu);
202 prop = of_get_property(cpu, "pervasive", NULL);
204 map->pmd_regs = ioremap(prop->address, prop->len);
206 prop = of_get_property(cpu, "iic", NULL);
208 map->iic_regs = ioremap(prop->address, prop->len);
210 prop = of_get_property(cpu, "mic-tm", NULL);
212 map->mic_tm_regs = ioremap(prop->address, prop->len);