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 } cbe_regs_maps[MAX_CBE];
34 static int cbe_regs_map_count;
36 static struct cbe_thread_map
38 struct device_node *cpu_node;
39 struct cbe_regs_map *regs;
40 } cbe_thread_map[NR_CPUS];
42 static struct cbe_regs_map *cbe_find_map(struct device_node *np)
45 struct device_node *tmp_np;
47 if (strcasecmp(np->type, "spe") == 0) {
48 if (np->data == NULL) {
49 /* walk up path until cpu node was found */
51 while (tmp_np != NULL && strcasecmp(tmp_np->type, "cpu") != 0)
52 tmp_np = tmp_np->parent;
54 np->data = cbe_find_map(tmp_np);
59 for (i = 0; i < cbe_regs_map_count; i++)
60 if (cbe_regs_maps[i].cpu_node == np)
61 return &cbe_regs_maps[i];
65 struct cbe_pmd_regs __iomem *cbe_get_pmd_regs(struct device_node *np)
67 struct cbe_regs_map *map = cbe_find_map(np);
72 EXPORT_SYMBOL_GPL(cbe_get_pmd_regs);
74 struct cbe_pmd_regs __iomem *cbe_get_cpu_pmd_regs(int cpu)
76 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
81 EXPORT_SYMBOL_GPL(cbe_get_cpu_pmd_regs);
83 struct cbe_iic_regs __iomem *cbe_get_iic_regs(struct device_node *np)
85 struct cbe_regs_map *map = cbe_find_map(np);
91 struct cbe_iic_regs __iomem *cbe_get_cpu_iic_regs(int cpu)
93 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
99 struct cbe_mic_tm_regs __iomem *cbe_get_mic_tm_regs(struct device_node *np)
101 struct cbe_regs_map *map = cbe_find_map(np);
104 return map->mic_tm_regs;
107 struct cbe_mic_tm_regs __iomem *cbe_get_cpu_mic_tm_regs(int cpu)
109 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
112 return map->mic_tm_regs;
114 EXPORT_SYMBOL_GPL(cbe_get_cpu_mic_tm_regs);
117 void __init cbe_regs_init(void)
120 struct device_node *cpu;
122 /* Build local fast map of CPUs */
123 for_each_possible_cpu(i)
124 cbe_thread_map[i].cpu_node = of_get_cpu_node(i, NULL);
126 /* Find maps for each device tree CPU */
127 for_each_node_by_type(cpu, "cpu") {
128 struct cbe_regs_map *map = &cbe_regs_maps[cbe_regs_map_count++];
130 /* That hack must die die die ! */
131 const struct address_prop {
132 unsigned long address;
134 } __attribute__((packed)) *prop;
137 if (cbe_regs_map_count > MAX_CBE) {
138 printk(KERN_ERR "cbe_regs: More BE chips than supported"
140 cbe_regs_map_count--;
144 for_each_possible_cpu(i)
145 if (cbe_thread_map[i].cpu_node == cpu)
146 cbe_thread_map[i].regs = map;
148 prop = get_property(cpu, "pervasive", NULL);
150 map->pmd_regs = ioremap(prop->address, prop->len);
152 prop = get_property(cpu, "iic", NULL);
154 map->iic_regs = ioremap(prop->address, prop->len);
156 prop = (struct address_prop *)get_property(cpu, "mic-tm",
159 map->mic_tm_regs = ioremap(prop->address, prop->len);