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>
13 #include <asm/pgtable.h>
15 #include <asm/ptrace.h>
22 * Current implementation uses "cpu" nodes. We build our own mapping
23 * array of cpu numbers to cpu nodes locally for now to allow interrupt
24 * time code to have a fast path rather than call of_get_cpu_node(). If
25 * we implement cpu hotplug, we'll have to install an appropriate norifier
26 * in order to release references to the cpu going away
28 static struct cbe_regs_map
30 struct device_node *cpu_node;
31 struct cbe_pmd_regs __iomem *pmd_regs;
32 struct cbe_iic_regs __iomem *iic_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)
46 for (i = 0; i < cbe_regs_map_count; i++)
47 if (cbe_regs_maps[i].cpu_node == np)
48 return &cbe_regs_maps[i];
52 struct cbe_pmd_regs __iomem *cbe_get_pmd_regs(struct device_node *np)
54 struct cbe_regs_map *map = cbe_find_map(np);
60 struct cbe_pmd_regs __iomem *cbe_get_cpu_pmd_regs(int cpu)
62 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
69 struct cbe_iic_regs __iomem *cbe_get_iic_regs(struct device_node *np)
71 struct cbe_regs_map *map = cbe_find_map(np);
76 struct cbe_iic_regs __iomem *cbe_get_cpu_iic_regs(int cpu)
78 struct cbe_regs_map *map = cbe_thread_map[cpu].regs;
84 void __init cbe_regs_init(void)
87 struct device_node *cpu;
89 /* Build local fast map of CPUs */
90 for_each_possible_cpu(i)
91 cbe_thread_map[i].cpu_node = of_get_cpu_node(i, NULL);
93 /* Find maps for each device tree CPU */
94 for_each_node_by_type(cpu, "cpu") {
95 struct cbe_regs_map *map = &cbe_regs_maps[cbe_regs_map_count++];
97 /* That hack must die die die ! */
99 unsigned long address;
101 } __attribute__((packed)) *prop;
104 if (cbe_regs_map_count > MAX_CBE) {
105 printk(KERN_ERR "cbe_regs: More BE chips than supported"
107 cbe_regs_map_count--;
111 for_each_possible_cpu(i)
112 if (cbe_thread_map[i].cpu_node == cpu)
113 cbe_thread_map[i].regs = map;
115 prop = (struct address_prop *)get_property(cpu, "pervasive",
118 map->pmd_regs = ioremap(prop->address, prop->len);
120 prop = (struct address_prop *)get_property(cpu, "iic",
123 map->iic_regs = ioremap(prop->address, prop->len);