Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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