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 } cbe_thread_map[NR_CPUS];
43 static struct cbe_regs_map *cbe_find_map(struct device_node *np)
46 struct device_node *tmp_np;
48 if (strcasecmp(np->type, "spe") == 0) {
49 if (np->data == NULL) {
50 /* walk up path until cpu node was found */
52 while (tmp_np != NULL && strcasecmp(tmp_np->type, "cpu") != 0)
53 tmp_np = tmp_np->parent;
55 np->data = cbe_find_map(tmp_np);
60 for (i = 0; i < cbe_regs_map_count; i++)
61 if (cbe_regs_maps[i].cpu_node == np)
62 return &cbe_regs_maps[i];
66 struct cbe_pmd_regs __iomem *cbe_get_pmd_regs(struct device_node *np)
68 struct cbe_regs_map *map = cbe_find_map(np);
73 EXPORT_SYMBOL_GPL(cbe_get_pmd_regs);
75 struct cbe_pmd_regs __iomem *cbe_get_cpu_pmd_regs(int cpu)
77 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
82 EXPORT_SYMBOL_GPL(cbe_get_cpu_pmd_regs);
84 struct cbe_pmd_shadow_regs *cbe_get_pmd_shadow_regs(struct device_node *np)
86 struct cbe_regs_map *map = cbe_find_map(np);
89 return &map->pmd_shadow_regs;
92 struct cbe_pmd_shadow_regs *cbe_get_cpu_pmd_shadow_regs(int cpu)
94 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
97 return &map->pmd_shadow_regs;
100 struct cbe_iic_regs __iomem *cbe_get_iic_regs(struct device_node *np)
102 struct cbe_regs_map *map = cbe_find_map(np);
105 return map->iic_regs;
108 struct cbe_iic_regs __iomem *cbe_get_cpu_iic_regs(int cpu)
110 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
113 return map->iic_regs;
116 struct cbe_mic_tm_regs __iomem *cbe_get_mic_tm_regs(struct device_node *np)
118 struct cbe_regs_map *map = cbe_find_map(np);
121 return map->mic_tm_regs;
124 struct cbe_mic_tm_regs __iomem *cbe_get_cpu_mic_tm_regs(int cpu)
126 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
129 return map->mic_tm_regs;
131 EXPORT_SYMBOL_GPL(cbe_get_cpu_mic_tm_regs);
134 void __init cbe_regs_init(void)
137 struct device_node *cpu;
139 /* Build local fast map of CPUs */
140 for_each_possible_cpu(i)
141 cbe_thread_map[i].cpu_node = of_get_cpu_node(i, NULL);
143 /* Find maps for each device tree CPU */
144 for_each_node_by_type(cpu, "cpu") {
145 struct cbe_regs_map *map = &cbe_regs_maps[cbe_regs_map_count++];
147 /* That hack must die die die ! */
148 const struct address_prop {
149 unsigned long address;
151 } __attribute__((packed)) *prop;
154 if (cbe_regs_map_count > MAX_CBE) {
155 printk(KERN_ERR "cbe_regs: More BE chips than supported"
157 cbe_regs_map_count--;
161 for_each_possible_cpu(i)
162 if (cbe_thread_map[i].cpu_node == cpu)
163 cbe_thread_map[i].regs = map;
165 prop = get_property(cpu, "pervasive", NULL);
167 map->pmd_regs = ioremap(prop->address, prop->len);
169 prop = get_property(cpu, "iic", NULL);
171 map->iic_regs = ioremap(prop->address, prop->len);
173 prop = (struct address_prop *)get_property(cpu, "mic-tm",
176 map->mic_tm_regs = ioremap(prop->address, prop->len);