diff options
author | David S. Miller <davem@davemloft.net> | 2008-12-04 23:28:22 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-12-05 20:00:13 -0500 |
commit | dfa76060be85dd48d3803bc26f6a6d2e93e812f0 (patch) | |
tree | 6e0256581241b0db0da33ce5afbd4017a61e38d8 /arch | |
parent | ab04323e5b8c50d6e8f7f4a3e4118ba5fcba61a1 (diff) |
sparc: Create common area for OF device layer code.
This is where common code implementations will go as we unify
32-bit and 64-bit OF device tree code.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/sparc/kernel/Makefile | 1 | ||||
-rw-r--r-- | arch/sparc/kernel/prom_32.c | 94 | ||||
-rw-r--r-- | arch/sparc/kernel/prom_64.c | 94 | ||||
-rw-r--r-- | arch/sparc/kernel/prom_common.c | 121 |
4 files changed, 122 insertions, 188 deletions
diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile index cd13d7fcfccf..d0d63b1ab02e 100644 --- a/arch/sparc/kernel/Makefile +++ b/arch/sparc/kernel/Makefile | |||
@@ -35,6 +35,7 @@ obj-y += ptrace_$(BITS).o | |||
35 | obj-y += unaligned_$(BITS).o | 35 | obj-y += unaligned_$(BITS).o |
36 | obj-y += una_asm_$(BITS).o | 36 | obj-y += una_asm_$(BITS).o |
37 | obj-$(CONFIG_SPARC32) += muldiv.o | 37 | obj-$(CONFIG_SPARC32) += muldiv.o |
38 | obj-y += prom_common.o | ||
38 | obj-y += prom_$(BITS).o | 39 | obj-y += prom_$(BITS).o |
39 | obj-y += of_device_$(BITS).o | 40 | obj-y += of_device_$(BITS).o |
40 | 41 | ||
diff --git a/arch/sparc/kernel/prom_32.c b/arch/sparc/kernel/prom_32.c index 715455ba3689..e41df66192e5 100644 --- a/arch/sparc/kernel/prom_32.c +++ b/arch/sparc/kernel/prom_32.c | |||
@@ -27,100 +27,6 @@ | |||
27 | 27 | ||
28 | #include "prom.h" | 28 | #include "prom.h" |
29 | 29 | ||
30 | struct device_node *of_find_node_by_phandle(phandle handle) | ||
31 | { | ||
32 | struct device_node *np; | ||
33 | |||
34 | for (np = allnodes; np != 0; np = np->allnext) | ||
35 | if (np->node == handle) | ||
36 | break; | ||
37 | |||
38 | return np; | ||
39 | } | ||
40 | EXPORT_SYMBOL(of_find_node_by_phandle); | ||
41 | |||
42 | int of_getintprop_default(struct device_node *np, const char *name, int def) | ||
43 | { | ||
44 | struct property *prop; | ||
45 | int len; | ||
46 | |||
47 | prop = of_find_property(np, name, &len); | ||
48 | if (!prop || len != 4) | ||
49 | return def; | ||
50 | |||
51 | return *(int *) prop->value; | ||
52 | } | ||
53 | EXPORT_SYMBOL(of_getintprop_default); | ||
54 | |||
55 | DEFINE_MUTEX(of_set_property_mutex); | ||
56 | EXPORT_SYMBOL(of_set_property_mutex); | ||
57 | |||
58 | int of_set_property(struct device_node *dp, const char *name, void *val, int len) | ||
59 | { | ||
60 | struct property **prevp; | ||
61 | void *new_val; | ||
62 | int err; | ||
63 | |||
64 | new_val = kmalloc(len, GFP_KERNEL); | ||
65 | if (!new_val) | ||
66 | return -ENOMEM; | ||
67 | |||
68 | memcpy(new_val, val, len); | ||
69 | |||
70 | err = -ENODEV; | ||
71 | |||
72 | write_lock(&devtree_lock); | ||
73 | prevp = &dp->properties; | ||
74 | while (*prevp) { | ||
75 | struct property *prop = *prevp; | ||
76 | |||
77 | if (!strcasecmp(prop->name, name)) { | ||
78 | void *old_val = prop->value; | ||
79 | int ret; | ||
80 | |||
81 | mutex_lock(&of_set_property_mutex); | ||
82 | ret = prom_setprop(dp->node, (char *) name, val, len); | ||
83 | mutex_unlock(&of_set_property_mutex); | ||
84 | |||
85 | err = -EINVAL; | ||
86 | if (ret >= 0) { | ||
87 | prop->value = new_val; | ||
88 | prop->length = len; | ||
89 | |||
90 | if (OF_IS_DYNAMIC(prop)) | ||
91 | kfree(old_val); | ||
92 | |||
93 | OF_MARK_DYNAMIC(prop); | ||
94 | |||
95 | err = 0; | ||
96 | } | ||
97 | break; | ||
98 | } | ||
99 | prevp = &(*prevp)->next; | ||
100 | } | ||
101 | write_unlock(&devtree_lock); | ||
102 | |||
103 | /* XXX Upate procfs if necessary... */ | ||
104 | |||
105 | return err; | ||
106 | } | ||
107 | EXPORT_SYMBOL(of_set_property); | ||
108 | |||
109 | int of_find_in_proplist(const char *list, const char *match, int len) | ||
110 | { | ||
111 | while (len > 0) { | ||
112 | int l; | ||
113 | |||
114 | if (!strcmp(list, match)) | ||
115 | return 1; | ||
116 | l = strlen(list) + 1; | ||
117 | list += l; | ||
118 | len -= l; | ||
119 | } | ||
120 | return 0; | ||
121 | } | ||
122 | EXPORT_SYMBOL(of_find_in_proplist); | ||
123 | |||
124 | static unsigned int prom_early_allocated; | 30 | static unsigned int prom_early_allocated; |
125 | 31 | ||
126 | static void * __init prom_early_alloc(unsigned long size) | 32 | static void * __init prom_early_alloc(unsigned long size) |
diff --git a/arch/sparc/kernel/prom_64.c b/arch/sparc/kernel/prom_64.c index 651448d3cc5a..1f5666a94884 100644 --- a/arch/sparc/kernel/prom_64.c +++ b/arch/sparc/kernel/prom_64.c | |||
@@ -32,100 +32,6 @@ | |||
32 | 32 | ||
33 | #include "prom.h" | 33 | #include "prom.h" |
34 | 34 | ||
35 | struct device_node *of_find_node_by_phandle(phandle handle) | ||
36 | { | ||
37 | struct device_node *np; | ||
38 | |||
39 | for (np = allnodes; np; np = np->allnext) | ||
40 | if (np->node == handle) | ||
41 | break; | ||
42 | |||
43 | return np; | ||
44 | } | ||
45 | EXPORT_SYMBOL(of_find_node_by_phandle); | ||
46 | |||
47 | int of_getintprop_default(struct device_node *np, const char *name, int def) | ||
48 | { | ||
49 | struct property *prop; | ||
50 | int len; | ||
51 | |||
52 | prop = of_find_property(np, name, &len); | ||
53 | if (!prop || len != 4) | ||
54 | return def; | ||
55 | |||
56 | return *(int *) prop->value; | ||
57 | } | ||
58 | EXPORT_SYMBOL(of_getintprop_default); | ||
59 | |||
60 | DEFINE_MUTEX(of_set_property_mutex); | ||
61 | EXPORT_SYMBOL(of_set_property_mutex); | ||
62 | |||
63 | int of_set_property(struct device_node *dp, const char *name, void *val, int len) | ||
64 | { | ||
65 | struct property **prevp; | ||
66 | void *new_val; | ||
67 | int err; | ||
68 | |||
69 | new_val = kmalloc(len, GFP_KERNEL); | ||
70 | if (!new_val) | ||
71 | return -ENOMEM; | ||
72 | |||
73 | memcpy(new_val, val, len); | ||
74 | |||
75 | err = -ENODEV; | ||
76 | |||
77 | write_lock(&devtree_lock); | ||
78 | prevp = &dp->properties; | ||
79 | while (*prevp) { | ||
80 | struct property *prop = *prevp; | ||
81 | |||
82 | if (!strcasecmp(prop->name, name)) { | ||
83 | void *old_val = prop->value; | ||
84 | int ret; | ||
85 | |||
86 | mutex_lock(&of_set_property_mutex); | ||
87 | ret = prom_setprop(dp->node, name, val, len); | ||
88 | mutex_unlock(&of_set_property_mutex); | ||
89 | |||
90 | err = -EINVAL; | ||
91 | if (ret >= 0) { | ||
92 | prop->value = new_val; | ||
93 | prop->length = len; | ||
94 | |||
95 | if (OF_IS_DYNAMIC(prop)) | ||
96 | kfree(old_val); | ||
97 | |||
98 | OF_MARK_DYNAMIC(prop); | ||
99 | |||
100 | err = 0; | ||
101 | } | ||
102 | break; | ||
103 | } | ||
104 | prevp = &(*prevp)->next; | ||
105 | } | ||
106 | write_unlock(&devtree_lock); | ||
107 | |||
108 | /* XXX Upate procfs if necessary... */ | ||
109 | |||
110 | return err; | ||
111 | } | ||
112 | EXPORT_SYMBOL(of_set_property); | ||
113 | |||
114 | int of_find_in_proplist(const char *list, const char *match, int len) | ||
115 | { | ||
116 | while (len > 0) { | ||
117 | int l; | ||
118 | |||
119 | if (!strcmp(list, match)) | ||
120 | return 1; | ||
121 | l = strlen(list) + 1; | ||
122 | list += l; | ||
123 | len -= l; | ||
124 | } | ||
125 | return 0; | ||
126 | } | ||
127 | EXPORT_SYMBOL(of_find_in_proplist); | ||
128 | |||
129 | static unsigned int prom_early_allocated __initdata; | 35 | static unsigned int prom_early_allocated __initdata; |
130 | 36 | ||
131 | static void * __init prom_early_alloc(unsigned long size) | 37 | static void * __init prom_early_alloc(unsigned long size) |
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c new file mode 100644 index 000000000000..ded8c628811f --- /dev/null +++ b/arch/sparc/kernel/prom_common.c | |||
@@ -0,0 +1,121 @@ | |||
1 | /* prom_common.c: OF device tree support common code. | ||
2 | * | ||
3 | * Paul Mackerras August 1996. | ||
4 | * Copyright (C) 1996-2005 Paul Mackerras. | ||
5 | * | ||
6 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. | ||
7 | * {engebret|bergner}@us.ibm.com | ||
8 | * | ||
9 | * Adapted for sparc by David S. Miller davem@davemloft.net | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version | ||
14 | * 2 of the License, or (at your option) any later version. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/errno.h> | ||
20 | #include <linux/mutex.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/of.h> | ||
23 | #include <asm/prom.h> | ||
24 | #include <asm/oplib.h> | ||
25 | |||
26 | #include "prom.h" | ||
27 | |||
28 | struct device_node *of_find_node_by_phandle(phandle handle) | ||
29 | { | ||
30 | struct device_node *np; | ||
31 | |||
32 | for (np = allnodes; np; np = np->allnext) | ||
33 | if (np->node == handle) | ||
34 | break; | ||
35 | |||
36 | return np; | ||
37 | } | ||
38 | EXPORT_SYMBOL(of_find_node_by_phandle); | ||
39 | |||
40 | int of_getintprop_default(struct device_node *np, const char *name, int def) | ||
41 | { | ||
42 | struct property *prop; | ||
43 | int len; | ||
44 | |||
45 | prop = of_find_property(np, name, &len); | ||
46 | if (!prop || len != 4) | ||
47 | return def; | ||
48 | |||
49 | return *(int *) prop->value; | ||
50 | } | ||
51 | EXPORT_SYMBOL(of_getintprop_default); | ||
52 | |||
53 | DEFINE_MUTEX(of_set_property_mutex); | ||
54 | EXPORT_SYMBOL(of_set_property_mutex); | ||
55 | |||
56 | int of_set_property(struct device_node *dp, const char *name, void *val, int len) | ||
57 | { | ||
58 | struct property **prevp; | ||
59 | void *new_val; | ||
60 | int err; | ||
61 | |||
62 | new_val = kmalloc(len, GFP_KERNEL); | ||
63 | if (!new_val) | ||
64 | return -ENOMEM; | ||
65 | |||
66 | memcpy(new_val, val, len); | ||
67 | |||
68 | err = -ENODEV; | ||
69 | |||
70 | write_lock(&devtree_lock); | ||
71 | prevp = &dp->properties; | ||
72 | while (*prevp) { | ||
73 | struct property *prop = *prevp; | ||
74 | |||
75 | if (!strcasecmp(prop->name, name)) { | ||
76 | void *old_val = prop->value; | ||
77 | int ret; | ||
78 | |||
79 | mutex_lock(&of_set_property_mutex); | ||
80 | ret = prom_setprop(dp->node, name, val, len); | ||
81 | mutex_unlock(&of_set_property_mutex); | ||
82 | |||
83 | err = -EINVAL; | ||
84 | if (ret >= 0) { | ||
85 | prop->value = new_val; | ||
86 | prop->length = len; | ||
87 | |||
88 | if (OF_IS_DYNAMIC(prop)) | ||
89 | kfree(old_val); | ||
90 | |||
91 | OF_MARK_DYNAMIC(prop); | ||
92 | |||
93 | err = 0; | ||
94 | } | ||
95 | break; | ||
96 | } | ||
97 | prevp = &(*prevp)->next; | ||
98 | } | ||
99 | write_unlock(&devtree_lock); | ||
100 | |||
101 | /* XXX Upate procfs if necessary... */ | ||
102 | |||
103 | return err; | ||
104 | } | ||
105 | EXPORT_SYMBOL(of_set_property); | ||
106 | |||
107 | int of_find_in_proplist(const char *list, const char *match, int len) | ||
108 | { | ||
109 | while (len > 0) { | ||
110 | int l; | ||
111 | |||
112 | if (!strcmp(list, match)) | ||
113 | return 1; | ||
114 | l = strlen(list) + 1; | ||
115 | list += l; | ||
116 | len -= l; | ||
117 | } | ||
118 | return 0; | ||
119 | } | ||
120 | EXPORT_SYMBOL(of_find_in_proplist); | ||
121 | |||