2 Copyright © 2008-2014, The AROS Development Team. All rights reserved.
11 static int32_t (*ofw_call
)(void *args
);
17 void ofw_init(void *ofw
)
23 handle
= ofw_find_device("/chosen");
27 ofw_get_prop(handle
, "stdin", &stdin
, sizeof(stdin
));
28 ofw_get_prop(handle
, "stdout", &stdout
, sizeof(stdout
));
33 int32_t ofw_test(const char *name
)
55 void * ofw_peer(void * phandle
)
65 void * sibling_phandle
;
75 return args
.sibling_phandle
;
78 void * ofw_child(void * phandle
)
98 return args
.child_phandle
;
101 void * ofw_parent(void * phandle
)
111 void * parent_phandle
;
121 return args
.parent_phandle
;
124 int32_t ofw_get_prop_len(void * phandle
, const char *name
)
148 int32_t ofw_get_prop(void * phandle
, const char *name
, void * buf
, uint32_t buflen
)
165 phandle
, name
, buf
, buflen
,
174 int32_t ofw_next_prop(void * phandle
, const char *previous
, void * buf
)
183 const char *previous
;
190 phandle
, previous
, buf
,
199 int32_t ofw_set_prop(void * phandle
, const char *name
, void * buf
, uint32_t buflen
)
216 phandle
, name
, buf
, buflen
,
225 void * ofw_find_device(char *dev
)
249 void * ofw_open(const char *dev
)
272 void ofw_close(void * ihandle
)
290 int32_t ofw_read(void * ihandle
, void * addr
, uint32_t len
)
316 int32_t ofw_write(void * ihandle
, void * addr
, uint32_t len
)
342 int32_t ofw_seek(void * ihandle
, uint32_t pos_hi
, uint32_t pos_lo
)
358 ihandle
, pos_hi
, pos_lo
,
367 typedef struct __pool
{
374 pool_t
*mempool
= NULL
;
376 void * __claim(uint32_t size
)
382 mempool
= ofw_claim(0, 4096, 4096);
383 if (mempool
!= (void*)-1)
385 mempool
->first_free
= (char*)mempool
+ sizeof(pool_t
);
386 mempool
->length
= 4096;
387 mempool
->free
= 4096 - sizeof(pool_t
);
388 mempool
->next
= NULL
;
392 if (size
>= (4096 - sizeof(pool_t
)))
394 ptr
= ofw_claim(0, size
, 4096);
395 if (ptr
== (void*)-1)
412 p
= ofw_claim(0, 4096, 4096);
416 p
->first_free
= (char*)p
+ sizeof(pool_t
);
418 p
->free
= 4096 - sizeof(pool_t
);
427 p
->first_free
+= size
;
435 void * ofw_claim(void * virt
, uint32_t size
, uint32_t align
)
457 return args
.baseaddr
;
460 void ofw_release(void * virt
, uint32_t size
)
479 int32_t ofw_instantiate_rtas(void * ihandle
, void * rtas_base
, void **rtas_entry
)
496 "instantiate-rtas", ihandle
, rtas_base
,
501 *rtas_entry
= args
.rtas_entry
;
502 return args
.callback
;
505 int32_t ofw_load(void * ihandle
, void * addr
, int32_t *size
)
522 "load", ihandle
, addr
,
528 return args
.callback
;
531 int32_t ofw_interpret(const char *cmd
)
554 int32_t ofw_rtas_token(const char *service
)
556 void *handle
= ofw_find_device("/rtas");
561 ofw_get_prop(handle
, service
, &token
, sizeof(token
));
569 int ofw_get_properties(void *phandle
, ofw_node_t
*node
)
572 char *previous
= NULL
;
573 ofw_property_t
*prop
= NULL
;
576 while(ofw_next_prop(phandle
, previous
, property
) > 0)
578 int name_len
= strlen(property
) + 1;
579 int prop_len
= ofw_get_prop_len(phandle
, property
);
581 // printf(" property '%s'(%d) length %d\n", property, name_len, prop_len);
583 prop
= __claim(sizeof(ofw_property_t
) + name_len
+ prop_len
);
590 prop
->op_name
= (char *)&prop
->op_storage
[0];
591 prop
->op_value
= &prop
->op_storage
[name_len
];
593 memcpy(prop
->op_name
, property
, name_len
);
594 prop
->op_length
= prop_len
;
595 ofw_get_prop(phandle
, property
, prop
->op_value
, prop_len
);
597 add_tail(&node
->on_properties
, &prop
->op_node
);
598 previous
= prop
->op_name
;
604 int ofw_build_tree(void *phandle
, ofw_node_t
*node
, int depth
)
608 ofw_node_t
*child
= NULL
;
611 for (i
=0; i
< depth
; i
++)
614 // printf("ofw_build_tree(%p, %p('%s'), %d)\n", phandle, node, node->on_name, depth);
616 /* Get properties of the node */
617 ofw_get_properties(phandle
, node
);
619 hnd
= ofw_child(phandle
);
622 int name_len
= ofw_get_prop_len(hnd
, "name");
627 child
= __claim(sizeof(ofw_node_t
) + name_len
);
637 child
->on_name
= (char*)child
->on_storage
;
638 ofw_get_prop(hnd
, "name", child
->on_name
, name_len
-1);
641 child
->on_name
= NULL
;
643 new_list(&child
->on_children
);
644 new_list(&child
->on_properties
);
646 add_tail(&node
->on_children
, &child
->on_node
);
648 retval
= ofw_build_tree(hnd
, child
, depth
+ 1);
659 ofw_node_t
*ofw_scan_tree()
661 void *p_root
= ofw_peer(NULL
);
662 ofw_node_t
*root
= __claim(sizeof(ofw_node_t
) + 2);
666 memcpy(root
->on_storage
, "/", 2);
667 root
->on_name
= (char*)root
->on_storage
;
668 new_list(&root
->on_children
);
669 new_list(&root
->on_properties
);
671 ofw_build_tree(p_root
, root
, 0);
677 /* Copy a string property into allocated memory */
678 char *ofw_GetString(void *handle
, const char *prop
)
680 int32_t len
= ofw_get_prop_len(handle
, prop
);
681 char *str
= ofw_claim(NULL
, len
+ 1, 4);
683 ofw_get_prop(handle
, prop
, str
, 255);