aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/kernel/of_device_32.c
diff options
context:
space:
mode:
authorRobert Reif <reif@earthlink.net>2009-06-04 05:00:02 -0400
committerDavid S. Miller <davem@davemloft.net>2009-06-16 07:56:49 -0400
commitc9f5b7e77c30da25104a3f7f26ac46c07d7b5cb6 (patch)
treee209e70377b4fbaf95168366430884b3b2474d2e /arch/sparc/kernel/of_device_32.c
parentd69864158e24f323e818403c6b89ad4871aea6f6 (diff)
sparc: move of_device common code to of_device_common
This patch moves code common to of_device_32.c and of_device_64.c into of_device_common.h and of_device_common.c. The only functional difference is in sparc32 where of_bus_default_map is used in place of of_bus_sbus_map because they are equivelent. There is still room for further code consolidation with some minor refactoring. Boot tested on sparc32 and compile tested on sparc64. Signed-off-by: Robert Reif <reif@earthlink.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc/kernel/of_device_32.c')
-rw-r--r--arch/sparc/kernel/of_device_32.c195
1 files changed, 3 insertions, 192 deletions
diff --git a/arch/sparc/kernel/of_device_32.c b/arch/sparc/kernel/of_device_32.c
index c8f14c1dc521..90396702ea2c 100644
--- a/arch/sparc/kernel/of_device_32.c
+++ b/arch/sparc/kernel/of_device_32.c
@@ -6,159 +6,11 @@
6#include <linux/mod_devicetable.h> 6#include <linux/mod_devicetable.h>
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/errno.h> 8#include <linux/errno.h>
9#include <linux/irq.h>
9#include <linux/of_device.h> 10#include <linux/of_device.h>
10#include <linux/of_platform.h> 11#include <linux/of_platform.h>
11 12
12static int node_match(struct device *dev, void *data) 13#include "of_device_common.h"
13{
14 struct of_device *op = to_of_device(dev);
15 struct device_node *dp = data;
16
17 return (op->node == dp);
18}
19
20struct of_device *of_find_device_by_node(struct device_node *dp)
21{
22 struct device *dev = bus_find_device(&of_platform_bus_type, NULL,
23 dp, node_match);
24
25 if (dev)
26 return to_of_device(dev);
27
28 return NULL;
29}
30EXPORT_SYMBOL(of_find_device_by_node);
31
32unsigned int irq_of_parse_and_map(struct device_node *node, int index)
33{
34 struct of_device *op = of_find_device_by_node(node);
35
36 if (!op || index >= op->num_irqs)
37 return 0;
38
39 return op->irqs[index];
40}
41EXPORT_SYMBOL(irq_of_parse_and_map);
42
43/* Take the archdata values for IOMMU, STC, and HOSTDATA found in
44 * BUS and propagate to all child of_device objects.
45 */
46void of_propagate_archdata(struct of_device *bus)
47{
48 struct dev_archdata *bus_sd = &bus->dev.archdata;
49 struct device_node *bus_dp = bus->node;
50 struct device_node *dp;
51
52 for (dp = bus_dp->child; dp; dp = dp->sibling) {
53 struct of_device *op = of_find_device_by_node(dp);
54
55 op->dev.archdata.iommu = bus_sd->iommu;
56 op->dev.archdata.stc = bus_sd->stc;
57 op->dev.archdata.host_controller = bus_sd->host_controller;
58 op->dev.archdata.numa_node = bus_sd->numa_node;
59
60 if (dp->child)
61 of_propagate_archdata(op);
62 }
63}
64
65struct bus_type of_platform_bus_type;
66EXPORT_SYMBOL(of_platform_bus_type);
67
68static inline u64 of_read_addr(const u32 *cell, int size)
69{
70 u64 r = 0;
71 while (size--)
72 r = (r << 32) | *(cell++);
73 return r;
74}
75
76static void __init get_cells(struct device_node *dp,
77 int *addrc, int *sizec)
78{
79 if (addrc)
80 *addrc = of_n_addr_cells(dp);
81 if (sizec)
82 *sizec = of_n_size_cells(dp);
83}
84
85/* Max address size we deal with */
86#define OF_MAX_ADDR_CELLS 4
87
88struct of_bus {
89 const char *name;
90 const char *addr_prop_name;
91 int (*match)(struct device_node *parent);
92 void (*count_cells)(struct device_node *child,
93 int *addrc, int *sizec);
94 int (*map)(u32 *addr, const u32 *range,
95 int na, int ns, int pna);
96 unsigned long (*get_flags)(const u32 *addr, unsigned long);
97};
98
99/*
100 * Default translator (generic bus)
101 */
102
103static void of_bus_default_count_cells(struct device_node *dev,
104 int *addrc, int *sizec)
105{
106 get_cells(dev, addrc, sizec);
107}
108
109/* Make sure the least significant 64-bits are in-range. Even
110 * for 3 or 4 cell values it is a good enough approximation.
111 */
112static int of_out_of_range(const u32 *addr, const u32 *base,
113 const u32 *size, int na, int ns)
114{
115 u64 a = of_read_addr(addr, na);
116 u64 b = of_read_addr(base, na);
117
118 if (a < b)
119 return 1;
120
121 b += of_read_addr(size, ns);
122 if (a >= b)
123 return 1;
124
125 return 0;
126}
127
128static int of_bus_default_map(u32 *addr, const u32 *range,
129 int na, int ns, int pna)
130{
131 u32 result[OF_MAX_ADDR_CELLS];
132 int i;
133
134 if (ns > 2) {
135 printk("of_device: Cannot handle size cells (%d) > 2.", ns);
136 return -EINVAL;
137 }
138
139 if (of_out_of_range(addr, range, range + na + pna, na, ns))
140 return -EINVAL;
141
142 /* Start with the parent range base. */
143 memcpy(result, range + na, pna * 4);
144
145 /* Add in the child address offset. */
146 for (i = 0; i < na; i++)
147 result[pna - 1 - i] +=
148 (addr[na - 1 - i] -
149 range[na - 1 - i]);
150
151 memcpy(addr, result, pna * 4);
152
153 return 0;
154}
155
156static unsigned long of_bus_default_get_flags(const u32 *addr, unsigned long flags)
157{
158 if (flags)
159 return flags;
160 return IORESOURCE_MEM;
161}
162 14
163/* 15/*
164 * PCI bus specific translator 16 * PCI bus specific translator
@@ -240,47 +92,6 @@ static unsigned long of_bus_pci_get_flags(const u32 *addr, unsigned long flags)
240 return flags; 92 return flags;
241} 93}
242 94
243/*
244 * SBUS bus specific translator
245 */
246
247static int of_bus_sbus_match(struct device_node *np)
248{
249 struct device_node *dp = np;
250
251 while (dp) {
252 if (!strcmp(dp->name, "sbus") ||
253 !strcmp(dp->name, "sbi"))
254 return 1;
255
256 /* Have a look at use_1to1_mapping(). We're trying
257 * to match SBUS if that's the top-level bus and we
258 * don't have some intervening real bus that provides
259 * ranges based translations.
260 */
261 if (of_find_property(dp, "ranges", NULL) != NULL)
262 break;
263
264 dp = dp->parent;
265 }
266
267 return 0;
268}
269
270static void of_bus_sbus_count_cells(struct device_node *child,
271 int *addrc, int *sizec)
272{
273 if (addrc)
274 *addrc = 2;
275 if (sizec)
276 *sizec = 1;
277}
278
279static int of_bus_sbus_map(u32 *addr, const u32 *range, int na, int ns, int pna)
280{
281 return of_bus_default_map(addr, range, na, ns, pna);
282}
283
284static unsigned long of_bus_sbus_get_flags(const u32 *addr, unsigned long flags) 95static unsigned long of_bus_sbus_get_flags(const u32 *addr, unsigned long flags)
285{ 96{
286 return IORESOURCE_MEM; 97 return IORESOURCE_MEM;
@@ -307,7 +118,7 @@ static struct of_bus of_busses[] = {
307 .addr_prop_name = "reg", 118 .addr_prop_name = "reg",
308 .match = of_bus_sbus_match, 119 .match = of_bus_sbus_match,
309 .count_cells = of_bus_sbus_count_cells, 120 .count_cells = of_bus_sbus_count_cells,
310 .map = of_bus_sbus_map, 121 .map = of_bus_default_map,
311 .get_flags = of_bus_sbus_get_flags, 122 .get_flags = of_bus_sbus_get_flags,
312 }, 123 },
313 /* Default */ 124 /* Default */