1 /* Kernel only exports for kernel add-ons 2 ** 3 ** Distributed under the terms of the OpenBeOS License. 4 */ 5 #ifndef _KERNEL_EXPORT_H 6 #define _KERNEL_EXPORT_H 7 8 9 #include <SupportDefs.h> 10 #include <OS.h> 11 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /*-------------------------------------------------------------*/ 18 19 /* disable/restore interrupts on the current CPU */ 20 21 typedef ulong cpu_status; 22 23 extern cpu_status disable_interrupts(void); 24 extern void restore_interrupts(cpu_status status); 25 26 27 /* spinlocks. Note that acquire/release should be called with 28 * interrupts disabled. 29 */ 30 31 typedef vint32 spinlock; 32 33 extern void acquire_spinlock(spinlock *lock); 34 extern void release_spinlock(spinlock *lock); 35 36 37 /* interrupt handling support for device drivers */ 38 39 /* Values returned by interrupt handlers */ 40 #define B_UNHANDLED_INTERRUPT 0 /* pass to next handler */ 41 #define B_HANDLED_INTERRUPT 1 /* don't pass on */ 42 #define B_INVOKE_SCHEDULER 2 /* don't pass on; invoke the scheduler */ 43 44 typedef int32 (*interrupt_handler)(void *data); 45 46 extern long install_io_interrupt_handler(long interrupt_number, 47 interrupt_handler handler, void *data, ulong flags); 48 extern long remove_io_interrupt_handler(long interrupt_number, 49 interrupt_handler handler, void *data); 50 51 52 /*-------------------------------------------------------------*/ 53 /* timer interrupts services */ 54 55 /* The BeOS qent structure is probably part of a general double linked list 56 * interface used all over the kernel; a struct is required to have a qent 57 * entry struct as first element, so it can be linked to other elements 58 * easily. The key field is probably just an id, eventually used to order 59 * the list. 60 * Since we don't use this kind of interface, but we have to provide it 61 * to keep compatibility, we can use the qent struct for other purposes... 62 * 63 * ToDo: don't do this! Drop source compatibility, but don't overdefine those values! 64 */ 65 typedef struct qent { 66 int64 key; /* We use this as the sched time */ 67 struct qent *next; /* This is used as a pointer to next timer */ 68 struct qent *prev; /* This can be used for callback args */ 69 } qent; 70 71 typedef struct timer timer; 72 typedef int32 (*timer_hook)(timer *); 73 74 struct timer { 75 qent entry; 76 uint16 flags; 77 uint16 cpu; 78 timer_hook hook; 79 bigtime_t period; 80 }; 81 82 #define B_ONE_SHOT_ABSOLUTE_TIMER 1 83 #define B_ONE_SHOT_RELATIVE_TIMER 2 84 #define B_PERIODIC_TIMER 3 85 86 extern status_t add_timer(timer *t, timer_hook hook, bigtime_t period, int32 flags); 87 extern bool cancel_timer(timer *t); 88 89 90 /*-------------------------------------------------------------*/ 91 /* kernel threads */ 92 93 extern thread_id spawn_kernel_thread(thread_func function, const char *threadName, 94 int32 priority, void *arg); 95 96 97 /*-------------------------------------------------------------*/ 98 /* signal functions */ 99 100 extern int send_signal_etc(pid_t thread, uint sig, uint32 flags); 101 extern int has_signals_pending(void *_thread); 102 103 104 /*-------------------------------------------------------------*/ 105 /* snooze functions */ 106 107 extern status_t snooze_etc(bigtime_t usecs, int timebase, uint32 flags); 108 109 110 /*-------------------------------------------------------------*/ 111 /* virtual memory buffer functions */ 112 113 #define B_DMA_IO 0x00000001 114 #define B_READ_DEVICE 0x00000002 115 116 typedef struct { 117 void *address; /* address in physical memory */ 118 ulong size; /* size of block */ 119 } physical_entry; 120 121 extern long lock_memory(void *buffer, ulong numBytes, ulong flags); 122 extern long unlock_memory(void *buffer, ulong numBytes, ulong flags); 123 extern long get_memory_map(const void *buffer, ulong size, 124 physical_entry *table, long numEntries); 125 126 /* address specifications for mapping physical memory */ 127 #define B_ANY_KERNEL_BLOCK_ADDRESS (B_ANY_KERNEL_ADDRESS + 1) 128 129 /* area protection flags for the kernel */ 130 #define B_KERNEL_READ_AREA 16 131 #define B_KERNEL_WRITE_AREA 32 132 133 /* call to map physical memory - typically used for memory-mapped i/o */ 134 135 extern area_id map_physical_memory(const char *areaName, void *physicalAddress, 136 size_t size, uint32 flags, uint32 protection, void **mappedAddress); 137 138 139 /* MTR attributes for mapping physical memory (Intel Architecture only) */ 140 // ToDo: what have those to do here? 141 #define B_MTR_UC 0x10000000 142 #define B_MTR_WC 0x20000000 143 #define B_MTR_WT 0x30000000 144 #define B_MTR_WP 0x40000000 145 #define B_MTR_WB 0x50000000 146 #define B_MTR_MASK 0xf0000000 147 148 149 /*-------------------------------------------------------------*/ 150 /* hardware inquiry */ 151 152 /* platform_type return value is defined in OS.h */ 153 154 extern platform_type platform(); 155 156 #if __POWERPC__ 157 extern long motherboard_version(void); 158 extern long io_card_version(void); 159 #endif 160 161 /*-------------------------------------------------------------*/ 162 /* primitive kernel debugging facilities */ 163 164 /* Standard debug output is on... 165 * mac: modem port 166 * pc: com1 167 * ...at 19.2 kbaud, no parity, 8 bit, 1 stop bit. 168 * 169 * Note: the kernel settings file can override these defaults 170 */ 171 172 #if __GNUC__ 173 extern void dprintf(const char *format, ...) /* just like printf */ 174 __attribute__ ((format (__printf__, 1, 2))); 175 extern void kprintf(const char *fmt, ...) /* only for debugger cmds */ 176 __attribute__ ((format (__printf__, 1, 2))); 177 #else 178 extern void dprintf(const char *format, ...); /* just like printf */ 179 extern void kprintf(const char *fmt, ...); /* only for debugger cmds */ 180 #endif 181 182 extern bool set_dprintf_enabled(bool new_state); /* returns old state */ 183 184 extern void panic(const char *format, ...); 185 186 extern void kernel_debugger(const char *message); /* enter kernel debugger */ 187 extern uint32 parse_expression(const char *string); /* utility for debugger cmds */ 188 189 /* special return codes for kernel debugger */ 190 #define B_KDEBUG_CONT 2 191 #define B_KDEBUG_QUIT 3 192 193 typedef int (*debugger_command_hook)(int argc, char **argv); 194 195 extern int add_debugger_command(char *name, debugger_command_hook hook, char *help); 196 extern int remove_debugger_command(char *name, debugger_command_hook hook); 197 198 extern status_t load_driver_symbols(const char *driverName); 199 200 201 /*-------------------------------------------------------------*/ 202 /* misc */ 203 204 extern void spin(bigtime_t microseconds); 205 /* does a busy delay loop for at least "microseconds" */ 206 207 typedef void (*daemon_hook)(void *arg, int iteration); 208 209 extern status_t register_kernel_daemon(daemon_hook hook, void *arg, int frequency); 210 extern status_t unregister_kernel_daemon(daemon_hook hook, void *arg); 211 212 extern void call_all_cpus(void (*f)(void *, int), void *cookie); 213 214 /* safe methods to access user memory without having to lock it */ 215 extern status_t user_memcpy(void *to, const void *from, size_t size); 216 extern ssize_t user_strlcpy(char *to, const char *from, size_t size); 217 extern status_t user_memset(void *start, char c, size_t count); 218 219 #ifdef __cplusplus 220 } 221 #endif 222 223 #endif /* _KERNEL_EXPORT_H */ 224