2 * Creation Date: <2002/10/03 20:55:02 samuel>
3 * Time-stamp: <2002/10/29 13:00:23 samuel>
9 * Copyright (C) 2002, 2003 Samuel Rydh (samuel@ibrium.se)
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
18 #include "osi_calls.h"
21 /* OSI_PromClose (free linux side device tree) */
25 return OSI_PromIface( kPromClose, 0 );
28 /* ret: 0 no more peers, -1 if error */
30 prom_peer( mol_phandle_t phandle )
32 return OSI_PromIface( kPromPeer, phandle );
35 /* ret: 0 no child, -1 if error */
37 prom_child( mol_phandle_t phandle )
39 return OSI_PromIface( kPromChild, phandle );
42 /* ret: 0 if root node, -1 if error */
44 prom_parent( mol_phandle_t phandle )
46 return OSI_PromIface( kPromParent, phandle );
51 prom_package_to_path( mol_phandle_t phandle, char *buf, long buflen )
53 return OSI_PromIface2( kPromPackageToPath, phandle, (int)buf, buflen );
58 prom_get_prop_len( mol_phandle_t phandle, const char *name )
60 return OSI_PromIface1( kPromGetPropLen, phandle, (int)name );
63 /* ret: prop len or -1 if error */
65 prom_get_prop( mol_phandle_t phandle, const char *name, char *buf, long buflen )
67 return OSI_PromIface3( kPromGetProp, phandle, (int)name, (int)buf, buflen );
70 /* ret: prop len or -1 if error */
72 prom_get_prop_by_path( const char *path, const char *name, char *buf, long buflen )
74 mol_phandle_t ph = prom_find_device(path);
75 return (ph != -1)? prom_get_prop( ph, name, buf, buflen) : -1;
78 /* ret: -1 error, 0 last prop, 1 otherwise */
80 prom_next_prop( mol_phandle_t phandle, const char *prev, char *buf )
82 return OSI_PromIface2( kPromNextProp, phandle, (int)prev, (int)buf );
85 /* ret: -1 if error */
87 prom_set_prop( mol_phandle_t phandle, const char *name, char *buf, long buflen )
89 return OSI_PromIface3( kPromSetProp, phandle, (int)name, (int)buf, buflen );
92 /* ret: -1 if error */
94 prom_create_node( const char *path )
96 return OSI_PromPathIface( kPromCreateNode, path );
99 /* ret: -1 if not found */
101 prom_find_device( const char *path )
104 char buf2[256], ch, *p;
109 if( (ph=OSI_PromPathIface( kPromFindDevice, path )) != -1 )
111 else if( path[0] == '/' )
114 /* might be an alias */
115 if( !(p=strpbrk(path, "@:/")) )
116 p = (char*)path + strlen(path);
120 if( (ph=prom_get_prop(prom_find_device("/aliases"), path, buf2, sizeof(buf2))) == -1 )
123 strncat( buf2, p, sizeof(buf2) );
125 if( buf2[0] != '/' ) {
126 printk("Error: aliases must be absolute!\n");
129 ph = OSI_PromPathIface( kPromFindDevice, buf2 );
135 /************************************************************************/
136 /* search the tree for nodes with matching device_type */
137 /************************************************************************/
140 prom_find_device_type_( mol_phandle_t ph, const char *type, int *icount, int index )
145 if( ph == -1 || !ph )
147 if( prom_get_prop( ph, "device_type", buf, sizeof(buf)) > 0 )
148 if( !strcmp(buf, type) )
149 if( (*icount)++ == index )
151 if( (ph2=prom_find_device_type_( prom_peer(ph), type, icount, index )) != -1 )
153 if( (ph2=prom_find_device_type_( prom_child(ph), type, icount, index )) != -1 )
159 prom_find_device_type( const char *type, int index )
162 return prom_find_device_type_( prom_peer(0), type, &count, index );
166 /************************************************************************/
167 /* device tree tweaking */
168 /************************************************************************/
172 prom_change_phandle( mol_phandle_t old_ph, mol_phandle_t new_ph )
174 return OSI_PromIface1( kPromChangePHandle, old_ph, (int)new_ph );