Adrian Bunk | b00dc83 | 2008-05-19 16:52:27 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * tree.c: Basic device tree traversal/scanning for the Linux |
| 3 | * prom library. |
| 4 | * |
| 5 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) |
| 6 | * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 7 | */ |
| 8 | |
| 9 | #include <linux/string.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/sched.h> |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 13 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include <asm/openprom.h> |
| 16 | #include <asm/oplib.h> |
David S. Miller | b3e13fb | 2007-07-12 15:55:55 -0700 | [diff] [blame] | 17 | #include <asm/ldc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 19 | static phandle prom_node_to_node(const char *type, phandle node) |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 20 | { |
| 21 | unsigned long args[5]; |
| 22 | |
| 23 | args[0] = (unsigned long) type; |
| 24 | args[1] = 1; |
| 25 | args[2] = 1; |
| 26 | args[3] = (unsigned int) node; |
| 27 | args[4] = (unsigned long) -1; |
| 28 | |
| 29 | p1275_cmd_direct(args); |
| 30 | |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 31 | return (phandle) args[4]; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /* Return the child of node 'node' or zero if no this node has no |
| 35 | * direct descendent. |
| 36 | */ |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 37 | inline phandle __prom_getchild(phandle node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 39 | return prom_node_to_node("child", node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Denis Efremov | dbebe0d | 2013-05-09 14:36:54 +0400 | [diff] [blame] | 42 | phandle prom_getchild(phandle node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 44 | phandle cnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 46 | if ((s32)node == -1) |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 47 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | cnode = __prom_getchild(node); |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 49 | if ((s32)cnode == -1) |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 50 | return 0; |
| 51 | return cnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 53 | EXPORT_SYMBOL(prom_getchild); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 55 | inline phandle prom_getparent(phandle node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 57 | phandle cnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 59 | if ((s32)node == -1) |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 60 | return 0; |
| 61 | cnode = prom_node_to_node("parent", node); |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 62 | if ((s32)cnode == -1) |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 63 | return 0; |
| 64 | return cnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /* Return the next sibling of node 'node' or zero if no more siblings |
| 68 | * at this level of depth in the tree. |
| 69 | */ |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 70 | inline phandle __prom_getsibling(phandle node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 72 | return prom_node_to_node(prom_peer_name, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Denis Efremov | dbebe0d | 2013-05-09 14:36:54 +0400 | [diff] [blame] | 75 | phandle prom_getsibling(phandle node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 77 | phandle sibnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 79 | if ((s32)node == -1) |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 80 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | sibnode = __prom_getsibling(node); |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 82 | if ((s32)sibnode == -1) |
David S. Miller | d82ace7 | 2006-02-09 02:52:44 -0800 | [diff] [blame] | 83 | return 0; |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return sibnode; |
| 86 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 87 | EXPORT_SYMBOL(prom_getsibling); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | /* Return the length in bytes of property 'prop' at node 'node'. |
| 90 | * Return -1 on error. |
| 91 | */ |
Denis Efremov | dbebe0d | 2013-05-09 14:36:54 +0400 | [diff] [blame] | 92 | int prom_getproplen(phandle node, const char *prop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 94 | unsigned long args[6]; |
| 95 | |
| 96 | if (!node || !prop) |
| 97 | return -1; |
| 98 | |
| 99 | args[0] = (unsigned long) "getproplen"; |
| 100 | args[1] = 2; |
| 101 | args[2] = 1; |
| 102 | args[3] = (unsigned int) node; |
| 103 | args[4] = (unsigned long) prop; |
| 104 | args[5] = (unsigned long) -1; |
| 105 | |
| 106 | p1275_cmd_direct(args); |
| 107 | |
| 108 | return (int) args[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 110 | EXPORT_SYMBOL(prom_getproplen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | /* Acquire a property 'prop' at node 'node' and place it in |
| 113 | * 'buffer' which has a size of 'bufsize'. If the acquisition |
| 114 | * was successful the length will be returned, else -1 is returned. |
| 115 | */ |
Denis Efremov | dbebe0d | 2013-05-09 14:36:54 +0400 | [diff] [blame] | 116 | int prom_getproperty(phandle node, const char *prop, |
| 117 | char *buffer, int bufsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 119 | unsigned long args[8]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | int plen; |
| 121 | |
| 122 | plen = prom_getproplen(node, prop); |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 123 | if ((plen > bufsize) || (plen == 0) || (plen == -1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return -1; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 125 | |
| 126 | args[0] = (unsigned long) prom_getprop_name; |
| 127 | args[1] = 4; |
| 128 | args[2] = 1; |
| 129 | args[3] = (unsigned int) node; |
| 130 | args[4] = (unsigned long) prop; |
| 131 | args[5] = (unsigned long) buffer; |
| 132 | args[6] = bufsize; |
| 133 | args[7] = (unsigned long) -1; |
| 134 | |
| 135 | p1275_cmd_direct(args); |
| 136 | |
| 137 | return (int) args[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 139 | EXPORT_SYMBOL(prom_getproperty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | /* Acquire an integer property and return its value. Returns -1 |
| 142 | * on failure. |
| 143 | */ |
Denis Efremov | dbebe0d | 2013-05-09 14:36:54 +0400 | [diff] [blame] | 144 | int prom_getint(phandle node, const char *prop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | int intprop; |
| 147 | |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 148 | if (prom_getproperty(node, prop, (char *) &intprop, sizeof(int)) != -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | return intprop; |
| 150 | |
| 151 | return -1; |
| 152 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 153 | EXPORT_SYMBOL(prom_getint); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | /* Acquire an integer property, upon error return the passed default |
| 156 | * integer. |
| 157 | */ |
| 158 | |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 159 | int prom_getintdefault(phandle node, const char *property, int deflt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
| 161 | int retval; |
| 162 | |
| 163 | retval = prom_getint(node, property); |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 164 | if (retval == -1) |
| 165 | return deflt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | return retval; |
| 168 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 169 | EXPORT_SYMBOL(prom_getintdefault); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | /* Acquire a boolean property, 1=TRUE 0=FALSE. */ |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 172 | int prom_getbool(phandle node, const char *prop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
| 174 | int retval; |
| 175 | |
| 176 | retval = prom_getproplen(node, prop); |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 177 | if (retval == -1) |
| 178 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return 1; |
| 180 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 181 | EXPORT_SYMBOL(prom_getbool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | /* Acquire a property whose value is a string, returns a null |
| 184 | * string on error. The char pointer is the user supplied string |
| 185 | * buffer. |
| 186 | */ |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 187 | void prom_getstring(phandle node, const char *prop, char *user_buf, |
| 188 | int ubuf_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | int len; |
| 191 | |
| 192 | len = prom_getproperty(node, prop, user_buf, ubuf_size); |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 193 | if (len != -1) |
| 194 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | user_buf[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 197 | EXPORT_SYMBOL(prom_getstring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | /* Does the device at node 'node' have name 'name'? |
| 200 | * YES = 1 NO = 0 |
| 201 | */ |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 202 | int prom_nodematch(phandle node, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
| 204 | char namebuf[128]; |
| 205 | prom_getproperty(node, "name", namebuf, sizeof(namebuf)); |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 206 | if (strcmp(namebuf, name) == 0) |
| 207 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | /* Search siblings at 'node_start' for a node with name |
| 212 | * 'nodename'. Return node if successful, zero if not. |
| 213 | */ |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 214 | phandle prom_searchsiblings(phandle node_start, const char *nodename) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 216 | phandle thisnode; |
| 217 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | char promlib_buf[128]; |
| 219 | |
| 220 | for(thisnode = node_start; thisnode; |
| 221 | thisnode=prom_getsibling(thisnode)) { |
| 222 | error = prom_getproperty(thisnode, "name", promlib_buf, |
| 223 | sizeof(promlib_buf)); |
| 224 | /* Should this ever happen? */ |
| 225 | if(error == -1) continue; |
| 226 | if(strcmp(nodename, promlib_buf)==0) return thisnode; |
| 227 | } |
| 228 | |
| 229 | return 0; |
| 230 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 231 | EXPORT_SYMBOL(prom_searchsiblings); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 233 | static const char *prom_nextprop_name = "nextprop"; |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | /* Return the first property type for node 'node'. |
| 236 | * buffer should be at least 32B in length |
| 237 | */ |
Denis Efremov | dbebe0d | 2013-05-09 14:36:54 +0400 | [diff] [blame] | 238 | char *prom_firstprop(phandle node, char *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 240 | unsigned long args[7]; |
| 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | *buffer = 0; |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 243 | if ((s32)node == -1) |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 244 | return buffer; |
| 245 | |
| 246 | args[0] = (unsigned long) prom_nextprop_name; |
| 247 | args[1] = 3; |
| 248 | args[2] = 1; |
| 249 | args[3] = (unsigned int) node; |
| 250 | args[4] = 0; |
| 251 | args[5] = (unsigned long) buffer; |
| 252 | args[6] = (unsigned long) -1; |
| 253 | |
| 254 | p1275_cmd_direct(args); |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return buffer; |
| 257 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 258 | EXPORT_SYMBOL(prom_firstprop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | /* Return the property type string after property type 'oprop' |
| 261 | * at node 'node' . Returns NULL string if no more |
| 262 | * property types for this node. |
| 263 | */ |
Denis Efremov | dbebe0d | 2013-05-09 14:36:54 +0400 | [diff] [blame] | 264 | char *prom_nextprop(phandle node, const char *oprop, char *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 266 | unsigned long args[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | char buf[32]; |
| 268 | |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 269 | if ((s32)node == -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | *buffer = 0; |
| 271 | return buffer; |
| 272 | } |
| 273 | if (oprop == buffer) { |
| 274 | strcpy (buf, oprop); |
| 275 | oprop = buf; |
| 276 | } |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 277 | |
| 278 | args[0] = (unsigned long) prom_nextprop_name; |
| 279 | args[1] = 3; |
| 280 | args[2] = 1; |
| 281 | args[3] = (unsigned int) node; |
| 282 | args[4] = (unsigned long) oprop; |
| 283 | args[5] = (unsigned long) buffer; |
| 284 | args[6] = (unsigned long) -1; |
| 285 | |
| 286 | p1275_cmd_direct(args); |
| 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | return buffer; |
| 289 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 290 | EXPORT_SYMBOL(prom_nextprop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 292 | phandle prom_finddevice(const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 294 | unsigned long args[5]; |
| 295 | |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 296 | if (!name) |
| 297 | return 0; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 298 | args[0] = (unsigned long) "finddevice"; |
| 299 | args[1] = 1; |
| 300 | args[2] = 1; |
| 301 | args[3] = (unsigned long) name; |
| 302 | args[4] = (unsigned long) -1; |
| 303 | |
| 304 | p1275_cmd_direct(args); |
| 305 | |
| 306 | return (int) args[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 308 | EXPORT_SYMBOL(prom_finddevice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 310 | int prom_node_has_property(phandle node, const char *prop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
| 312 | char buf [32]; |
| 313 | |
| 314 | *buf = 0; |
| 315 | do { |
| 316 | prom_nextprop(node, buf, buf); |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 317 | if (!strcmp(buf, prop)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return 1; |
| 319 | } while (*buf); |
| 320 | return 0; |
| 321 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 322 | EXPORT_SYMBOL(prom_node_has_property); |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* Set property 'pname' at node 'node' to value 'value' which has a length |
| 325 | * of 'size' bytes. Return the number of bytes the prom accepted. |
| 326 | */ |
| 327 | int |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 328 | prom_setprop(phandle node, const char *pname, char *value, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 330 | unsigned long args[8]; |
| 331 | |
David S. Miller | b3e13fb | 2007-07-12 15:55:55 -0700 | [diff] [blame] | 332 | if (size == 0) |
| 333 | return 0; |
| 334 | if ((pname == 0) || (value == 0)) |
| 335 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
David S. Miller | b3e13fb | 2007-07-12 15:55:55 -0700 | [diff] [blame] | 337 | #ifdef CONFIG_SUN_LDOMS |
| 338 | if (ldom_domaining_enabled) { |
| 339 | ldom_set_var(pname, value); |
| 340 | return 0; |
| 341 | } |
| 342 | #endif |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 343 | args[0] = (unsigned long) "setprop"; |
| 344 | args[1] = 4; |
| 345 | args[2] = 1; |
| 346 | args[3] = (unsigned int) node; |
| 347 | args[4] = (unsigned long) pname; |
| 348 | args[5] = (unsigned long) value; |
| 349 | args[6] = size; |
| 350 | args[7] = (unsigned long) -1; |
| 351 | |
| 352 | p1275_cmd_direct(args); |
| 353 | |
| 354 | return (int) args[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
Sam Ravnborg | 917c366 | 2009-01-08 16:58:20 -0800 | [diff] [blame] | 356 | EXPORT_SYMBOL(prom_setprop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 358 | inline phandle prom_inst2pkg(int inst) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 360 | unsigned long args[5]; |
Andres Salomon | 8d12556 | 2010-10-08 14:18:11 -0700 | [diff] [blame] | 361 | phandle node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 363 | args[0] = (unsigned long) "instance-to-package"; |
| 364 | args[1] = 1; |
| 365 | args[2] = 1; |
| 366 | args[3] = (unsigned int) inst; |
| 367 | args[4] = (unsigned long) -1; |
| 368 | |
| 369 | p1275_cmd_direct(args); |
| 370 | |
| 371 | node = (int) args[4]; |
Andres Salomon | 4a3a255 | 2010-11-11 22:42:06 -0800 | [diff] [blame] | 372 | if ((s32)node == -1) |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 373 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | return node; |
| 375 | } |
| 376 | |
David S. Miller | c73fcc8 | 2007-07-20 16:59:26 -0700 | [diff] [blame] | 377 | int prom_ihandle2path(int handle, char *buffer, int bufsize) |
| 378 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 379 | unsigned long args[7]; |
| 380 | |
| 381 | args[0] = (unsigned long) "instance-to-path"; |
| 382 | args[1] = 3; |
| 383 | args[2] = 1; |
| 384 | args[3] = (unsigned int) handle; |
| 385 | args[4] = (unsigned long) buffer; |
| 386 | args[5] = bufsize; |
| 387 | args[6] = (unsigned long) -1; |
| 388 | |
| 389 | p1275_cmd_direct(args); |
| 390 | |
| 391 | return (int) args[6]; |
David S. Miller | c73fcc8 | 2007-07-20 16:59:26 -0700 | [diff] [blame] | 392 | } |