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