xref: /haiku/headers/private/kernel/platform/openfirmware/openfirmware.h (revision 22440f4105cafc95cc1d49f9bc65bb395c527d86)
1 /*
2  * Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef OPEN_FIRMWARE_H
6 #define OPEN_FIRMWARE_H
7 
8 
9 #include <SupportDefs.h>
10 
11 
12 #define OF_FAILED	(-1)
13 
14 
15 /* global device tree/properties access */
16 extern int gChosen;
17 
18 
19 template<typename AddressType>
20 struct of_region {
21 	AddressType base;
22 	uint32 size;
23 } _PACKED;
24 
25 struct of_arguments {
26 	const char	*name;
27 	int			num_args;
28 	int			num_returns;
29 	int			data[0];
30 
31 #ifdef __cplusplus
32 	int &Argument(int index) { return data[index]; }
33 	int &ReturnValue(int index) { return data[num_args + index]; }
34 #endif
35 };
36 
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 extern status_t of_init(int (*openFirmwareEntry)(void *));
43 
44 /* device tree functions */
45 extern int of_finddevice(const char *device);
46 extern int of_child(int node);
47 extern int of_peer(int node);
48 extern int of_parent(int node);
49 extern int of_instance_to_path(int instance, char *pathBuffer, int bufferSize);
50 extern int of_instance_to_package(int instance);
51 extern int of_getprop(int package, const char *property, void *buffer,
52 	int bufferSize);
53 extern int of_setprop(int package, const char *property, const void *buffer,
54 	int bufferSize);
55 extern int of_nextprop(int package, const char *previousProperty,
56 	char *nextProperty);
57 extern int of_getproplen(int package, const char *property);
58 extern int of_package_to_path(int package, char *pathBuffer, int bufferSize);
59 
60 /* I/O functions */
61 extern int of_open(const char *nodeName);
62 extern void of_close(int handle);
63 extern int of_read(int handle, void *buffer, int bufferSize);
64 extern int of_write(int handle, const void *buffer, int bufferSize);
65 extern int of_seek(int handle, off_t pos);
66 
67 /* memory functions */
68 extern int of_release(void *virtualAddress, int size);
69 extern void *of_claim(void *virtualAddress, int size, int align);
70 
71 /* misc functions */
72 extern int of_call_client_function(const char *method, int numArgs,
73 	int numReturns, ...);
74 extern int of_interpret(const char *command, int numArgs, int numReturns, ...);
75 extern int of_call_method(int handle, const char *method, int numArgs,
76 	int numReturns, ...);
77 extern int of_test(const char *service);
78 extern int of_milliseconds(void);
79 extern void of_exit(void);
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif	/* OPEN_FIRMWARE_H */
86