2 * Creation Date: <2003/11/18 14:55:05 samuel>
3 * Time-stamp: <2004/03/27 02:03:55 samuel>
9 * Copyright (C) 2003, 2004 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
18 #include "libopenbios/bindings.h"
23 /************************************************************************/
24 /* copy device tree */
25 /************************************************************************/
28 copy_node( mol_phandle_t molph )
30 char name[40], path[80];
37 prom_package_to_path( molph, path, sizeof(path) );
39 /* don't copy /options node */
40 if( !strcmp("/options", path) ) {
41 copy_node( prom_peer(molph) );
46 if( !(ph=find_dev(path)) ) {
54 while( prom_next_prop(molph, name, name) > 0 ) {
55 int len = prom_get_prop_len( molph, name );
59 printk("prop to large (%d)\n", len );
63 /* don't copy /chosen/{stdin,stdout} (XXX: ugly hack...) */
64 if( !strcmp("/chosen", path) )
65 if( !strcmp("stdio", name) || !strcmp("stdout", name) )
69 prom_get_prop( molph, name, p, len );
70 set_property( ph, name, p, len );
74 set_int_property( ph, "MOL,phandle", molph );
75 copy_node( prom_child(molph) );
78 fword("finish-device");
80 activate_device("..");
82 copy_node( prom_peer(molph) );
87 /************************************************************************/
88 /* device tree cloning and tweaking */
89 /************************************************************************/
92 translate_molph( mol_phandle_t molph )
94 static mol_phandle_t cached_molph;
95 static phandle_t cached_ph;
98 if( cached_molph == molph )
101 while( (ph=dt_iterate(ph)) )
102 if( get_int_property(ph, "MOL,phandle", NULL) == molph )
104 cached_molph = molph;
108 printk("failed to translate molph\n");
115 static char *pnames[] = { "interrupt-parent", "interrupt-controller", NULL } ;
120 while( (ph=dt_iterate(ph)) ) {
121 for( pp=pnames; *pp; pp++ ) {
122 phandle_t *p = (phandle_t*)get_property( ph, *pp, &len );
124 *p = translate_molph( *(int*)p );
127 /* need to fix interrupt map properties too */
128 if( (map=(int*)get_property(ph, "interrupt-map", &len)) ) {
129 int i, acells = get_int_property(ph, "#address-cells", NULL);
130 int icells = get_int_property(ph, "#interrupt-cells", NULL);
133 for( i=0; i<len; i++ ) {
135 int ch_acells, ch_icells;
137 i += acells + icells;
138 if( !(ch_ph=translate_molph(map[i])) )
141 ch_acells = get_int_property(ch_ph, "#address-cells", NULL);
142 ch_icells = get_int_property(ch_ph, "#interrupt-cells", NULL);
143 i += ch_acells + icells;
146 printk("interrupt map fixing failure\n");
149 /* delete MOL,phandle properties */
150 for( ph=0; (ph=dt_iterate(ph)) ; ) {
151 push_str("MOL,phandle");
153 fword("(delete-property)");
161 activate_device("/");
162 copy_node( prom_peer(0) );