Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/fs/proc/proc_devtree.c (Version 2.6.25) and /linux/fs/proc/proc_devtree.c (Version 2.6.11.8)


  1 /*                                                  1 /*
  2  * proc_devtree.c - handles /proc/device-tree       2  * proc_devtree.c - handles /proc/device-tree
  3  *                                                  3  *
  4  * Copyright 1997 Paul Mackerras                    4  * Copyright 1997 Paul Mackerras
  5  */                                                 5  */
  6 #include <linux/errno.h>                            6 #include <linux/errno.h>
  7 #include <linux/time.h>                             7 #include <linux/time.h>
  8 #include <linux/proc_fs.h>                          8 #include <linux/proc_fs.h>
  9 #include <linux/stat.h>                             9 #include <linux/stat.h>
 10 #include <linux/string.h>                          10 #include <linux/string.h>
 11 #include <asm/prom.h>                              11 #include <asm/prom.h>
 12 #include <asm/uaccess.h>                           12 #include <asm/uaccess.h>
 13                                                    13 
 14 #ifndef HAVE_ARCH_DEVTREE_FIXUPS                   14 #ifndef HAVE_ARCH_DEVTREE_FIXUPS
 15 static inline void set_node_proc_entry(struct  !!  15 static inline void set_node_proc_entry(struct device_node *np, struct proc_dir_entry *de)
 16                                        struct  !!  16 {
                                                   >>  17 }
                                                   >>  18 
                                                   >>  19 static void inline set_node_name_link(struct device_node *np, struct proc_dir_entry *de)
                                                   >>  20 {
                                                   >>  21 }
                                                   >>  22 
                                                   >>  23 static void inline set_node_addr_link(struct device_node *np, struct proc_dir_entry *de)
 17 {                                                  24 {
 18 }                                                  25 }
 19 #endif                                             26 #endif
 20                                                    27 
 21 static struct proc_dir_entry *proc_device_tree     28 static struct proc_dir_entry *proc_device_tree;
 22                                                    29 
 23 /*                                                 30 /*
 24  * Supply data on a read from /proc/device-tre     31  * Supply data on a read from /proc/device-tree/node/property.
 25  */                                                32  */
 26 static int property_read_proc(char *page, char     33 static int property_read_proc(char *page, char **start, off_t off,
 27                               int count, int *     34                               int count, int *eof, void *data)
 28 {                                                  35 {
 29         struct property *pp = data;                36         struct property *pp = data;
 30         int n;                                     37         int n;
 31                                                    38 
 32         if (off >= pp->length) {                   39         if (off >= pp->length) {
 33                 *eof = 1;                          40                 *eof = 1;
 34                 return 0;                          41                 return 0;
 35         }                                          42         }
 36         n = pp->length - off;                      43         n = pp->length - off;
 37         if (n > count)                             44         if (n > count)
 38                 n = count;                         45                 n = count;
 39         else                                       46         else
 40                 *eof = 1;                          47                 *eof = 1;
 41         memcpy(page, (char *)pp->value + off,  !!  48         memcpy(page, pp->value + off, n);
 42         *start = page;                             49         *start = page;
 43         return n;                                  50         return n;
 44 }                                                  51 }
 45                                                    52 
 46 /*                                                 53 /*
 47  * For a node with a name like "gc@10", we mak     54  * For a node with a name like "gc@10", we make symlinks called "gc"
 48  * and "@10" to it.                                55  * and "@10" to it.
 49  */                                                56  */
 50                                                    57 
 51 /*                                                 58 /*
 52  * Add a property to a node                    << 
 53  */                                            << 
 54 static struct proc_dir_entry *                 << 
 55 __proc_device_tree_add_prop(struct proc_dir_en << 
 56                 const char *name)              << 
 57 {                                              << 
 58         struct proc_dir_entry *ent;            << 
 59                                                << 
 60         /*                                     << 
 61          * Unfortunately proc_register puts ea << 
 62          * at the beginning of the list.  So w << 
 63          */                                    << 
 64         ent = create_proc_read_entry(name,     << 
 65                                      strncmp(n << 
 66                                      ? S_IRUGO << 
 67                                      property_ << 
 68         if (ent == NULL)                       << 
 69                 return NULL;                   << 
 70                                                << 
 71         if (!strncmp(name, "security-", 9))    << 
 72                 ent->size = 0; /* don't leak n << 
 73         else                                   << 
 74                 ent->size = pp->length;        << 
 75                                                << 
 76         return ent;                            << 
 77 }                                              << 
 78                                                << 
 79                                                << 
 80 void proc_device_tree_add_prop(struct proc_dir << 
 81 {                                              << 
 82         __proc_device_tree_add_prop(pde, prop, << 
 83 }                                              << 
 84                                                << 
 85 void proc_device_tree_remove_prop(struct proc_ << 
 86                                   struct prope << 
 87 {                                              << 
 88         remove_proc_entry(prop->name, pde);    << 
 89 }                                              << 
 90                                                << 
 91 void proc_device_tree_update_prop(struct proc_ << 
 92                                   struct prope << 
 93                                   struct prope << 
 94 {                                              << 
 95         struct proc_dir_entry *ent;            << 
 96                                                << 
 97         for (ent = pde->subdir; ent != NULL; e << 
 98                 if (ent->data == oldprop)      << 
 99                         break;                 << 
100         if (ent == NULL) {                     << 
101                 printk(KERN_WARNING "device-tr << 
102                        " does not exist\n", ol << 
103         } else {                               << 
104                 ent->data = newprop;           << 
105                 ent->size = newprop->length;   << 
106         }                                      << 
107 }                                              << 
108                                                << 
109 /*                                             << 
110  * Various dodgy firmware might give us nodes  << 
111  * conflicting names. That's generally ok, exc << 
112  * so munge names here to ensure they're uniqu << 
113  */                                            << 
114                                                << 
115 static int duplicate_name(struct proc_dir_entr << 
116 {                                              << 
117         struct proc_dir_entry *ent;            << 
118         int found = 0;                         << 
119                                                << 
120         spin_lock(&proc_subdir_lock);          << 
121                                                << 
122         for (ent = de->subdir; ent != NULL; en << 
123                 if (strcmp(ent->name, name) == << 
124                         found = 1;             << 
125                         break;                 << 
126                 }                              << 
127         }                                      << 
128                                                << 
129         spin_unlock(&proc_subdir_lock);        << 
130                                                << 
131         return found;                          << 
132 }                                              << 
133                                                << 
134 static const char *fixup_name(struct device_no << 
135                 const char *name)              << 
136 {                                              << 
137         char *fixed_name;                      << 
138         int fixup_len = strlen(name) + 2 + 1;  << 
139         int i = 1, size;                       << 
140                                                << 
141 realloc:                                       << 
142         fixed_name = kmalloc(fixup_len, GFP_KE << 
143         if (fixed_name == NULL) {              << 
144                 printk(KERN_ERR "device-tree:  << 
145                                 "name \"%s\"\n << 
146                 return name;                   << 
147         }                                      << 
148                                                << 
149 retry:                                         << 
150         size = snprintf(fixed_name, fixup_len, << 
151         size++; /* account for NULL */         << 
152                                                << 
153         if (size > fixup_len) {                << 
154                 /* We ran out of space, free a << 
155                 kfree(fixed_name);             << 
156                 fixup_len = size;              << 
157                 goto realloc;                  << 
158         }                                      << 
159                                                << 
160         if (duplicate_name(de, fixed_name)) {  << 
161                 /* Multiple duplicates. Retry  << 
162                 i++;                           << 
163                 goto retry;                    << 
164         }                                      << 
165                                                << 
166         printk(KERN_WARNING "device-tree: Dupl << 
167                         "renamed to \"%s\"\n", << 
168                                                << 
169         return fixed_name;                     << 
170 }                                              << 
171                                                << 
172 /*                                             << 
173  * Process a node, adding entries for its chil     59  * Process a node, adding entries for its children and its properties.
174  */                                                60  */
175 void proc_device_tree_add_node(struct device_n !!  61 void proc_device_tree_add_node(struct device_node *np, struct proc_dir_entry *de)
176                                struct proc_dir << 
177 {                                                  62 {
178         struct property *pp;                       63         struct property *pp;
179         struct proc_dir_entry *ent;                64         struct proc_dir_entry *ent;
180         struct device_node *child;             !!  65         struct device_node *child, *sib;
181         const char *p;                         !!  66         const char *p, *at;
                                                   >>  67         int l;
                                                   >>  68         struct proc_dir_entry *list, **lastp, *al;
182                                                    69 
183         set_node_proc_entry(np, de);               70         set_node_proc_entry(np, de);
184         for (child = NULL; (child = of_get_nex !!  71         lastp = &list;
185                 /* Use everything after the la !!  72         for (pp = np->properties; pp != 0; pp = pp->next) {
                                                   >>  73                 /*
                                                   >>  74                  * Unfortunately proc_register puts each new entry
                                                   >>  75                  * at the beginning of the list.  So we rearrange them.
                                                   >>  76                  */
                                                   >>  77                 ent = create_proc_read_entry(pp->name, strncmp(pp->name, "security-", 9) ?
                                                   >>  78                                              S_IRUGO : S_IRUSR, de, property_read_proc, pp);
                                                   >>  79                 if (ent == 0)
                                                   >>  80                         break;
                                                   >>  81                 if (!strncmp(pp->name, "security-", 9))
                                                   >>  82                      ent->size = 0; /* don't leak number of password chars */
                                                   >>  83                 else
                                                   >>  84                      ent->size = pp->length;
                                                   >>  85                 *lastp = ent;
                                                   >>  86                 lastp = &ent->next;
                                                   >>  87         }
                                                   >>  88         child = NULL;
                                                   >>  89         while ((child = of_get_next_child(np, child))) {
186                 p = strrchr(child->full_name,      90                 p = strrchr(child->full_name, '/');
187                 if (!p)                            91                 if (!p)
188                         p = child->full_name;      92                         p = child->full_name;
189                 else                               93                 else
190                         ++p;                       94                         ++p;
191                                                !!  95                 /* chop off '@0' if the name ends with that */
192                 if (duplicate_name(de, p))     !!  96                 l = strlen(p);
193                         p = fixup_name(np, de, !!  97                 if (l > 2 && p[l-2] == '@' && p[l-1] == '')
194                                                !!  98                         l -= 2;
195                 ent = proc_mkdir(p, de);           99                 ent = proc_mkdir(p, de);
196                 if (ent == 0)                     100                 if (ent == 0)
197                         break;                    101                         break;
                                                   >> 102                 *lastp = ent;
                                                   >> 103                 lastp = &ent->next;
198                 proc_device_tree_add_node(chil    104                 proc_device_tree_add_node(child, ent);
199         }                                      << 
200         of_node_put(child);                    << 
201                                                << 
202         for (pp = np->properties; pp != 0; pp  << 
203                 p = pp->name;                  << 
204                                                   105 
205                 if (duplicate_name(de, p))     !! 106                 /*
206                         p = fixup_name(np, de, !! 107                  * If we left the address part on the name, consider
207                                                !! 108                  * adding symlinks from the name and address parts.
208                 ent = __proc_device_tree_add_p !! 109                  */
209                 if (ent == 0)                  !! 110                 if (p[l] != 0 || (at = strchr(p, '@')) == 0)
                                                   >> 111                         continue;
                                                   >> 112 
                                                   >> 113                 /*
                                                   >> 114                  * If this is the first node with a given name property,
                                                   >> 115                  * add a symlink with the name property as its name.
                                                   >> 116                  */
                                                   >> 117                 sib = NULL;
                                                   >> 118                 while ((sib = of_get_next_child(np, sib)) && sib != child)
                                                   >> 119                         if (sib->name && strcmp(sib->name, child->name) == 0)
                                                   >> 120                                 break;
                                                   >> 121                 if (sib == child && strncmp(p, child->name, l) != 0) {
                                                   >> 122                         al = proc_symlink(child->name, de, ent->name);
                                                   >> 123                         if (al == 0) {
                                                   >> 124                                 of_node_put(sib);
                                                   >> 125                                 break;
                                                   >> 126                         }
                                                   >> 127                         set_node_name_link(child, al);
                                                   >> 128                         *lastp = al;
                                                   >> 129                         lastp = &al->next;
                                                   >> 130                 }
                                                   >> 131                 of_node_put(sib);
                                                   >> 132                 /*
                                                   >> 133                  * Add another directory with the @address part as its name.
                                                   >> 134                  */
                                                   >> 135                 al = proc_symlink(at, de, ent->name);
                                                   >> 136                 if (al == 0)
210                         break;                    137                         break;
                                                   >> 138                 set_node_addr_link(child, al);
                                                   >> 139                 *lastp = al;
                                                   >> 140                 lastp = &al->next;
211         }                                         141         }
                                                   >> 142         of_node_put(child);
                                                   >> 143         *lastp = NULL;
                                                   >> 144         de->subdir = list;
212 }                                                 145 }
213                                                   146 
214 /*                                                147 /*
215  * Called on initialization to set up the /pro    148  * Called on initialization to set up the /proc/device-tree subtree
216  */                                               149  */
217 void proc_device_tree_init(void)                  150 void proc_device_tree_init(void)
218 {                                                 151 {
219         struct device_node *root;                 152         struct device_node *root;
220         if ( !have_of )                           153         if ( !have_of )
221                 return;                           154                 return;
222         proc_device_tree = proc_mkdir("device-    155         proc_device_tree = proc_mkdir("device-tree", NULL);
223         if (proc_device_tree == 0)                156         if (proc_device_tree == 0)
224                 return;                           157                 return;
225         root = of_find_node_by_path("/");         158         root = of_find_node_by_path("/");
226         if (root == 0) {                          159         if (root == 0) {
227                 printk(KERN_ERR "/proc/device-    160                 printk(KERN_ERR "/proc/device-tree: can't find root\n");
228                 return;                           161                 return;
229         }                                         162         }
230         proc_device_tree_add_node(root, proc_d    163         proc_device_tree_add_node(root, proc_device_tree);
231         of_node_put(root);                        164         of_node_put(root);
232 }                                                 165 }
233                                                   166 
  This page was automatically generated by the LXR engine.