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 * This is little more than a stub at the moment. It should be
135 * fleshed out so that it works for both SMT and non-SMT, no
136 * matter if the passed cpu is odd or even.
137 * For SMT enabled, returns 0 for even-numbered cpu; otherwise 1.
138 * For SMT disabled, returns 0 for all cpus.
140 u32 cbe_get_hw_thread_id(int cpu)
144 EXPORT_SYMBOL_GPL(cbe_get_hw_thread_id);
146 void __init cbe_regs_init(void)
149 struct device_node *cpu;
151 /* Build local fast map of CPUs */
152 for_each_possible_cpu(i)
153 cbe_thread_map[i].cpu_node = of_get_cpu_node(i, NULL);
155 /* Find maps for each device tree CPU */
156 for_each_node_by_type(cpu, "cpu") {
157 struct cbe_regs_map *map = &cbe_regs_maps[cbe_regs_map_count++];
159 /* That hack must die die die ! */
160 const struct address_prop {
161 unsigned long address;
163 } __attribute__((packed)) *prop;
166 if (cbe_regs_map_count > MAX_CBE) {
167 printk(KERN_ERR "cbe_regs: More BE chips than supported"
169 cbe_regs_map_count--;
173 for_each_possible_cpu(i)
174 if (cbe_thread_map[i].cpu_node == cpu)
175 cbe_thread_map[i].regs = map;
177 prop = get_property(cpu, "pervasive", NULL);
179 map->pmd_regs = ioremap(prop->address, prop->len);
181 prop = get_property(cpu, "iic", NULL);
183 map->iic_regs = ioremap(prop->address, prop->len);
185 prop = (struct address_prop *)get_property(cpu, "mic-tm",
188 map->mic_tm_regs = ioremap(prop->address, prop->len);