2 * Creation Date: <2004/08/28 18:38:22 greg>
3 * Time-stamp: <2004/08/28 18:38:22 greg>
7 * Misc device node methods
9 * Copyright (C) 2004 Greg Watson
11 * Based on MOL specific code which is
13 * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
22 #include "libopenbios/bindings.h"
23 #include "libc/string.h"
24 #include "pearpc/pearpc.h"
25 #include "libopenbios/ofmem.h"
27 /************************************************************************/
28 /* RTAS (run-time abstraction services) */
29 /************************************************************************/
32 DECLARE_NODE( rtas
, INSTALL_OPEN
, 0, "+/rtas" );
34 /* ( physbase -- rtas_callback ) */
36 rtas_instantiate( void )
39 int s
=0x1000, size
= (int)of_rtas_end
- (int)of_rtas_start
;
44 virt
= ofmem_claim_virt( 0, s
, 0x1000 );
45 ofmem_map( physbase
, virt
, s
, -1 );
46 memcpy( (char*)virt
, of_rtas_start
, size
);
48 printk("RTAS instantiated at %08x\n", physbase
);
49 flush_icache_range( (char*)virt
, (char*)virt
+ size
);
54 NODE_METHODS( rtas
) = {
55 { "instantiate", rtas_instantiate
},
56 { "instantiate-rtas", rtas_instantiate
},
61 /************************************************************************/
63 /************************************************************************/
65 DECLARE_NODE( video_stdout
, INSTALL_OPEN
, 0, "Tdisplay" );
67 /* ( addr len -- actual ) */
72 char *addr
= (char*)POP();
76 console_draw_fstr(addr
, len
);
81 NODE_METHODS( video_stdout
) = {
82 { "write", stdout_write
},
86 /************************************************************************/
88 /************************************************************************/
90 DECLARE_NODE( tty
, INSTALL_OPEN
, 0, "/packages/terminal-emulator" );
92 /* ( addr len -- actual ) */
97 char *p
= (char*)POP();
112 /* ( addr len -- actual ) */
117 char *p
= (char*)POP();
118 for( i
=0; i
<len
; i
++ )
123 NODE_METHODS( tty
) = {
124 { "read", tty_read
},
125 { "write", tty_write
},
128 /************************************************************************/
129 /* client interface 'quiesce' */
130 /************************************************************************/
132 DECLARE_NODE( ciface
, 0, 0, "/packages/client-iface" );
136 ciface_quiesce( unsigned long args
[], unsigned long ret
[] )
140 /* This seems to be the correct thing to do - but I'm not sure */
141 asm volatile("mfmsr %0" : "=r" (msr
) : );
142 msr
&= ~(MSR_IR
| MSR_DR
);
143 asm volatile("mtmsr %0" :: "r" (msr
) );
145 printk("=============================================================\n\n");
150 ciface_milliseconds( unsigned long args
[], unsigned long ret
[] )
152 extern unsigned long get_timer_freq();
153 static unsigned long mticks
=0, usecs
=0;
156 asm volatile("mftb %0" : "=r" (t
) : );
158 usecs
+= get_timer_freq() / 1000000 * ( t
-mticks
);
165 NODE_METHODS( ciface
) = {
166 { "quiesce", ciface_quiesce
},
167 { "milliseconds", ciface_milliseconds
},
171 /************************************************************************/
172 /* MMU/memory methods */
173 /************************************************************************/
175 DECLARE_NODE( memory
, INSTALL_OPEN
, 0, "/memory" );
176 DECLARE_NODE( mmu
, INSTALL_OPEN
, 0, "/cpu@0" );
177 DECLARE_NODE( mmu_ciface
, 0, 0, "/packages/client-iface" );
180 /* ( phys size align --- base ) */
187 ucell ret
= ofmem_claim_phys( phys
, size
, align
);
189 if( ret
== (ucell
)-1 ) {
190 printk("MEM: claim failure\n");
197 /* ( phys size --- ) */
204 /* ( phys size align --- base ) */
211 ucell ret
= ofmem_claim_virt( phys
, size
, align
);
214 printk("MMU: CLAIM failure\n");
221 /* ( phys size --- ) */
228 /* ( phys virt size mode -- [ret???] ) */
238 /* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */
239 ret
= ofmem_map( phys
, virt
, size
, mode
);
242 printk("MMU: map failure\n");
248 /* ( virt size -- ) */
255 /* ( virt -- false | phys mode true ) */
257 mmu_translate( void )
261 ucell phys
= ofmem_translate( virt
, &mode
);
272 /* ( virt size align -- baseaddr|-1 ) */
279 ucell ret
= ofmem_claim( virt
, size
, align
);
281 /* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */
285 /* ( virt size -- ) */
287 ciface_release( void )
294 NODE_METHODS( memory
) = {
295 { "claim", mem_claim
},
296 { "release", mem_release
},
299 NODE_METHODS( mmu
) = {
300 { "claim", mmu_claim
},
301 { "release", mmu_release
},
303 { "unmap", mmu_unmap
},
304 { "translate", mmu_translate
},
307 NODE_METHODS( mmu_ciface
) = {
308 { "cif-claim", ciface_claim
},
309 { "cif-release", ciface_release
},
313 /************************************************************************/
315 /************************************************************************/
318 node_methods_init( void )
321 REGISTER_NODE( rtas
);
323 REGISTER_NODE( video_stdout
);
324 REGISTER_NODE( ciface
);
325 REGISTER_NODE( memory
);
326 REGISTER_NODE( mmu
);
327 REGISTER_NODE( mmu_ciface
);
328 REGISTER_NODE( tty
);