4 * Accessor routines for the various MMIO register blocks of the CBE
6 * (c) 2006 Benjamin Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
10 #include <linux/config.h>
11 #include <linux/percpu.h>
12 #include <linux/types.h>
15 #include <asm/pgtable.h>
17 #include <asm/ptrace.h>
24 * Current implementation uses "cpu" nodes. We build our own mapping
25 * array of cpu numbers to cpu nodes locally for now to allow interrupt
26 * time code to have a fast path rather than call of_get_cpu_node(). If
27 * we implement cpu hotplug, we'll have to install an appropriate norifier
28 * in order to release references to the cpu going away
30 static struct cbe_regs_map
32 struct device_node
*cpu_node
;
33 struct cbe_pmd_regs __iomem
*pmd_regs
;
34 struct cbe_iic_regs __iomem
*iic_regs
;
35 } cbe_regs_maps
[MAX_CBE
];
36 static int cbe_regs_map_count
;
38 static struct cbe_thread_map
40 struct device_node
*cpu_node
;
41 struct cbe_regs_map
*regs
;
42 } cbe_thread_map
[NR_CPUS
];
44 static struct cbe_regs_map
*cbe_find_map(struct device_node
*np
)
48 for (i
= 0; i
< cbe_regs_map_count
; i
++)
49 if (cbe_regs_maps
[i
].cpu_node
== np
)
50 return &cbe_regs_maps
[i
];
54 struct cbe_pmd_regs __iomem
*cbe_get_pmd_regs(struct device_node
*np
)
56 struct cbe_regs_map
*map
= cbe_find_map(np
);
62 struct cbe_pmd_regs __iomem
*cbe_get_cpu_pmd_regs(int cpu
)
64 struct cbe_regs_map
*map
= cbe_thread_map
[cpu
].regs
;
71 struct cbe_iic_regs __iomem
*cbe_get_iic_regs(struct device_node
*np
)
73 struct cbe_regs_map
*map
= cbe_find_map(np
);
78 struct cbe_iic_regs __iomem
*cbe_get_cpu_iic_regs(int cpu
)
80 struct cbe_regs_map
*map
= cbe_thread_map
[cpu
].regs
;
86 void __init
cbe_regs_init(void)
89 struct device_node
*cpu
;
91 /* Build local fast map of CPUs */
92 for_each_possible_cpu(i
)
93 cbe_thread_map
[i
].cpu_node
= of_get_cpu_node(i
, NULL
);
95 /* Find maps for each device tree CPU */
96 for_each_node_by_type(cpu
, "cpu") {
97 struct cbe_regs_map
*map
= &cbe_regs_maps
[cbe_regs_map_count
++];
99 /* That hack must die die die ! */
100 const struct address_prop
{
101 unsigned long address
;
103 } __attribute__((packed
)) *prop
;
106 if (cbe_regs_map_count
> MAX_CBE
) {
107 printk(KERN_ERR
"cbe_regs: More BE chips than supported"
109 cbe_regs_map_count
--;
113 for_each_possible_cpu(i
)
114 if (cbe_thread_map
[i
].cpu_node
== cpu
)
115 cbe_thread_map
[i
].regs
= map
;
117 prop
= get_property(cpu
, "pervasive", NULL
);
119 map
->pmd_regs
= ioremap(prop
->address
, prop
->len
);
121 prop
= get_property(cpu
, "iic", NULL
);
123 map
->iic_regs
= ioremap(prop
->address
, prop
->len
);