1 /* ++++++++++ 2 KernelExport.h 3 4 Functions exported from the kernel for driver use that are not already 5 prototyped elsewhere. 6 7 Copyright 1996-98, Be Incorporated. 8 +++++ */ 9 10 11 #ifndef _KERNEL_EXPORT_H 12 #define _KERNEL_EXPORT_H 13 14 #include <BeBuild.h> 15 #include <SupportDefs.h> 16 #include <OS.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 23 /* --- 24 kernel threads 25 --- */ 26 27 extern _IMPEXP_KERNEL thread_id spawn_kernel_thread ( 28 thread_func function, 29 const char *thread_name, 30 long priority, 31 void *arg 32 ); 33 34 35 /* --- 36 disable/restore interrupt enable flag on current cpu 37 --- */ 38 39 typedef ulong cpu_status; 40 41 extern _IMPEXP_KERNEL cpu_status disable_interrupts(void); 42 extern _IMPEXP_KERNEL void restore_interrupts(cpu_status status); 43 44 45 /* --- 46 spinlocks. Note that acquire/release should be called with 47 interrupts disabled. 48 --- */ 49 50 typedef vint32 spinlock; 51 52 extern _IMPEXP_KERNEL void acquire_spinlock (spinlock *lock); 53 extern _IMPEXP_KERNEL void release_spinlock (spinlock *lock); 54 55 56 /* --- 57 An interrupt handler returns one of the following values: 58 --- */ 59 60 #define B_UNHANDLED_INTERRUPT 0 /* pass to next handler */ 61 #define B_HANDLED_INTERRUPT 1 /* don't pass on */ 62 #define B_INVOKE_SCHEDULER 2 /* don't pass on; invoke the scheduler */ 63 64 typedef int32 (*interrupt_handler) (void *data); 65 66 /* interrupt handling support for device drivers */ 67 68 extern _IMPEXP_KERNEL long install_io_interrupt_handler ( 69 long interrupt_number, 70 interrupt_handler handler, 71 void *data, 72 ulong flags 73 ); 74 extern _IMPEXP_KERNEL long remove_io_interrupt_handler ( 75 long interrupt_number, 76 interrupt_handler handler, 77 void *data 78 ); 79 80 /* --- 81 timer interrupts services 82 --- */ 83 84 typedef struct timer timer; 85 typedef struct qent qent; 86 typedef int32 (*timer_hook)(timer *); 87 88 /** 89 * The BeOS qent structure is probably part of a general double linked list 90 * interface used all over the kernel; a struct is required to have a qent 91 * entry struct as first element, so it can be linked to other elements 92 * easily. The key field is probably just an id, eventually used to order 93 * the list. 94 * Since we don't use this kind of interface, but we have to provide it 95 * to keep compatibility, we can use the qent struct for other purposes... 96 */ 97 struct qent { 98 int64 key; /* We use this as the sched time */ 99 qent *next; /* This is used as a pointer to next timer */ 100 qent *prev; /* This can be used for callback args */ 101 }; 102 103 struct timer { 104 qent entry; 105 uint16 flags; 106 uint16 cpu; 107 timer_hook hook; 108 bigtime_t period; 109 }; 110 111 status_t add_timer(timer *t, timer_hook h, bigtime_t, int32 f); 112 bool cancel_timer(timer *t); 113 114 #define B_ONE_SHOT_ABSOLUTE_TIMER 1 115 #define B_ONE_SHOT_RELATIVE_TIMER 2 116 #define B_PERIODIC_TIMER 3 117 118 /* --- 119 signal functions 120 --- */ 121 122 extern _IMPEXP_KERNEL int send_signal_etc(pid_t thid, uint sig, uint32 flags); 123 extern _IMPEXP_KERNEL int has_signals_pending(void *thr); 124 125 126 /* --- 127 snooze functions 128 --- */ 129 130 extern _IMPEXP_KERNEL status_t snooze_etc(bigtime_t usecs, int timebase, uint32 flags); 131 132 133 /* --- 134 virtual memory buffer functions 135 --- */ 136 137 #define B_DMA_IO 0x00000001 138 #define B_READ_DEVICE 0x00000002 139 140 typedef struct { 141 void *address; /* address in physical memory */ 142 ulong size; /* size of block */ 143 } physical_entry; 144 145 extern _IMPEXP_KERNEL long lock_memory ( 146 void *buf, /* -> virtual buffer to lock (make resident) */ 147 ulong num_bytes, /* size of virtual buffer */ 148 ulong flags 149 ); 150 151 extern _IMPEXP_KERNEL long unlock_memory ( 152 void *buf, /* -> virtual buffer to unlock */ 153 ulong num_bytes, /* size of virtual buffer */ 154 ulong flags 155 ); 156 157 extern _IMPEXP_KERNEL long get_memory_map ( 158 const void *address, /* -> virtual buffer to translate */ 159 ulong size, /* size of virtual buffer */ 160 physical_entry *table, /* -> caller supplied table */ 161 long num_entries /* # entries in table */ 162 ); 163 164 165 /* ----- 166 address specifications for mapping physical memory 167 ----- */ 168 169 #define B_ANY_KERNEL_BLOCK_ADDRESS ((B_ANY_KERNEL_ADDRESS)+1) 170 171 /* ----- 172 MTR attributes for mapping physical memory (Intel Architecture only) 173 ----- */ 174 175 #define B_MTR_UC 0x10000000 176 #define B_MTR_WC 0x20000000 177 #define B_MTR_WT 0x30000000 178 #define B_MTR_WP 0x40000000 179 #define B_MTR_WB 0x50000000 180 #define B_MTR_MASK 0xf0000000 181 182 /* ----- 183 call to map physical memory - typically used for memory-mapped i/o 184 ----- */ 185 186 extern _IMPEXP_KERNEL area_id map_physical_memory ( 187 const char *area_name, 188 void *physical_address, 189 size_t size, 190 uint32 flags, 191 uint32 protection, 192 void **mapped_address 193 ); 194 195 196 /* ----- 197 hardware inquiry 198 ----- */ 199 200 /* platform_type return value is defined in OS.h */ 201 202 extern _IMPEXP_KERNEL platform_type platform(); 203 #if __POWERPC__ 204 extern _IMPEXP_KERNEL long motherboard_version (void); 205 extern _IMPEXP_KERNEL long io_card_version (void); 206 #endif 207 208 209 /* --- 210 primitive kernel debugging facilities. Debug output is on... 211 212 bebox: serial port 4 213 mac: modem port 214 pc: com1 215 216 ...at 19.2 kbaud, no parity, 8 bit, 1 stop bit. 217 --- */ 218 219 #if __GNUC__ 220 extern _IMPEXP_KERNEL void dprintf (const char *format, ...) /* just like printf */ 221 __attribute__ ((format (__printf__, 1, 2))); 222 extern _IMPEXP_KERNEL void kprintf (const char *fmt, ...) /* only for debugger cmds */ 223 __attribute__ ((format (__printf__, 1, 2))); 224 #else 225 extern _IMPEXP_KERNEL void dprintf (const char *format, ...); /* just like printf */ 226 extern _IMPEXP_KERNEL void kprintf (const char *fmt, ...); /* only for debugger cmds */ 227 #endif 228 extern _IMPEXP_KERNEL bool set_dprintf_enabled (bool new_state); /* returns old state */ 229 230 extern _IMPEXP_KERNEL void panic(const char *format, ...); 231 232 extern _IMPEXP_KERNEL void kernel_debugger (const char *message); /* enter kernel debugger */ 233 extern _IMPEXP_KERNEL ulong parse_expression (char *str); /* util for debugger cmds */ 234 235 /* special return codes for kernel debugger */ 236 #define B_KDEBUG_CONT 2 237 #define B_KDEBUG_QUIT 3 238 239 extern _IMPEXP_KERNEL int add_debugger_command (char *name, /* add a cmd to debugger */ 240 int (*func)(int argc, char **argv), 241 char *help); 242 extern _IMPEXP_KERNEL int remove_debugger_command (char *name, /* remove a cmd from debugger */ 243 int (*func)(int argc, char **argv)); 244 245 /* ----- 246 misc 247 ----- */ 248 249 extern _IMPEXP_KERNEL void spin (bigtime_t num_microseconds); 250 extern _IMPEXP_KERNEL int register_kernel_daemon(void (*func)(void *, int), void *arg, int freq); 251 extern _IMPEXP_KERNEL int unregister_kernel_daemon(void (*func)(void *, int), void *arg); 252 extern _IMPEXP_KERNEL void call_all_cpus(void (*f)(void*, int), void* cookie); 253 254 extern _IMPEXP_KERNEL int load_driver_symbols(const char *driver_name); 255 256 #ifdef __cplusplus 257 } 258 #endif 259 260 #endif 261