]>
Commit | Line | Data |
---|---|---|
dfa76060 DM |
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 [email protected] | |
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> | |
e63829de | 25 | #include <asm/leon.h> |
dfa76060 DM |
26 | |
27 | #include "prom.h" | |
28 | ||
ad07aed8 DM |
29 | struct device_node *of_console_device; |
30 | EXPORT_SYMBOL(of_console_device); | |
31 | ||
32 | char *of_console_path; | |
33 | EXPORT_SYMBOL(of_console_path); | |
34 | ||
35 | char *of_console_options; | |
36 | EXPORT_SYMBOL(of_console_options); | |
37 | ||
dfa76060 DM |
38 | int of_getintprop_default(struct device_node *np, const char *name, int def) |
39 | { | |
40 | struct property *prop; | |
41 | int len; | |
42 | ||
43 | prop = of_find_property(np, name, &len); | |
44 | if (!prop || len != 4) | |
45 | return def; | |
46 | ||
47 | return *(int *) prop->value; | |
48 | } | |
49 | EXPORT_SYMBOL(of_getintprop_default); | |
50 | ||
51 | DEFINE_MUTEX(of_set_property_mutex); | |
52 | EXPORT_SYMBOL(of_set_property_mutex); | |
53 | ||
54 | int of_set_property(struct device_node *dp, const char *name, void *val, int len) | |
55 | { | |
56 | struct property **prevp; | |
57 | void *new_val; | |
58 | int err; | |
59 | ||
60 | new_val = kmalloc(len, GFP_KERNEL); | |
61 | if (!new_val) | |
62 | return -ENOMEM; | |
63 | ||
64 | memcpy(new_val, val, len); | |
65 | ||
66 | err = -ENODEV; | |
67 | ||
1c9d80dd | 68 | mutex_lock(&of_set_property_mutex); |
dfa76060 DM |
69 | write_lock(&devtree_lock); |
70 | prevp = &dp->properties; | |
71 | while (*prevp) { | |
72 | struct property *prop = *prevp; | |
73 | ||
74 | if (!strcasecmp(prop->name, name)) { | |
75 | void *old_val = prop->value; | |
76 | int ret; | |
77 | ||
6016a363 | 78 | ret = prom_setprop(dp->phandle, name, val, len); |
dfa76060 DM |
79 | |
80 | err = -EINVAL; | |
81 | if (ret >= 0) { | |
82 | prop->value = new_val; | |
83 | prop->length = len; | |
84 | ||
85 | if (OF_IS_DYNAMIC(prop)) | |
86 | kfree(old_val); | |
87 | ||
88 | OF_MARK_DYNAMIC(prop); | |
89 | ||
90 | err = 0; | |
91 | } | |
92 | break; | |
93 | } | |
94 | prevp = &(*prevp)->next; | |
95 | } | |
96 | write_unlock(&devtree_lock); | |
1c9d80dd | 97 | mutex_unlock(&of_set_property_mutex); |
dfa76060 DM |
98 | |
99 | /* XXX Upate procfs if necessary... */ | |
100 | ||
101 | return err; | |
102 | } | |
103 | EXPORT_SYMBOL(of_set_property); | |
104 | ||
105 | int of_find_in_proplist(const char *list, const char *match, int len) | |
106 | { | |
107 | while (len > 0) { | |
108 | int l; | |
109 | ||
110 | if (!strcmp(list, match)) | |
111 | return 1; | |
112 | l = strlen(list) + 1; | |
113 | list += l; | |
114 | len -= l; | |
115 | } | |
116 | return 0; | |
117 | } | |
118 | EXPORT_SYMBOL(of_find_in_proplist); | |
119 | ||
23dc758e DM |
120 | unsigned int prom_early_allocated __initdata; |
121 | ||
9bdf6bab | 122 | #include "../../../drivers/of/pdt.c" |