2003-01-27 16:48:39 +03:00
|
|
|
/* Kernel only exports for kernel add-ons
|
2005-04-27 05:08:35 +04:00
|
|
|
*
|
|
|
|
* Copyright 2005, Haiku Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-09-20 02:33:58 +04:00
|
|
|
#ifndef _KERNEL_EXPORT_H
|
|
|
|
#define _KERNEL_EXPORT_H
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
#include <SupportDefs.h>
|
|
|
|
#include <OS.h>
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/*-------------------------------------------------------------*/
|
2005-04-27 05:08:35 +04:00
|
|
|
/* interrupts and spinlocks */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* disable/restore interrupts on the current CPU */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
typedef ulong cpu_status;
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern cpu_status disable_interrupts(void);
|
|
|
|
extern void restore_interrupts(cpu_status status);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* spinlocks. Note that acquire/release should be called with
|
|
|
|
* interrupts disabled.
|
|
|
|
*/
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
typedef vint32 spinlock;
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern void acquire_spinlock(spinlock *lock);
|
|
|
|
extern void release_spinlock(spinlock *lock);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* interrupt handling support for device drivers */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2005-04-27 05:08:35 +04:00
|
|
|
typedef int32 (*interrupt_handler)(void *data);
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* Values returned by interrupt handlers */
|
|
|
|
#define B_UNHANDLED_INTERRUPT 0 /* pass to next handler */
|
|
|
|
#define B_HANDLED_INTERRUPT 1 /* don't pass on */
|
|
|
|
#define B_INVOKE_SCHEDULER 2 /* don't pass on; invoke the scheduler */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2005-04-27 05:08:35 +04:00
|
|
|
/* Flags that can be passed to install_io_interrupt_handler() */
|
|
|
|
#define B_NO_ENABLE_COUNTER 1
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2005-04-27 05:08:35 +04:00
|
|
|
extern status_t install_io_interrupt_handler(long interrupt_number,
|
2003-01-27 16:48:39 +03:00
|
|
|
interrupt_handler handler, void *data, ulong flags);
|
2005-04-27 05:08:35 +04:00
|
|
|
extern status_t remove_io_interrupt_handler(long interrupt_number,
|
2003-01-27 16:48:39 +03:00
|
|
|
interrupt_handler handler, void *data);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/* timer interrupts services */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* The BeOS qent structure is probably part of a general double linked list
|
2002-10-26 20:13:36 +04:00
|
|
|
* interface used all over the kernel; a struct is required to have a qent
|
|
|
|
* entry struct as first element, so it can be linked to other elements
|
|
|
|
* easily. The key field is probably just an id, eventually used to order
|
|
|
|
* the list.
|
|
|
|
* Since we don't use this kind of interface, but we have to provide it
|
|
|
|
* to keep compatibility, we can use the qent struct for other purposes...
|
2003-01-27 16:48:39 +03:00
|
|
|
*
|
|
|
|
* ToDo: don't do this! Drop source compatibility, but don't overdefine those values!
|
2002-10-26 20:13:36 +04:00
|
|
|
*/
|
2003-01-27 16:48:39 +03:00
|
|
|
typedef struct qent {
|
2002-10-26 20:13:36 +04:00
|
|
|
int64 key; /* We use this as the sched time */
|
2003-01-27 16:48:39 +03:00
|
|
|
struct qent *next; /* This is used as a pointer to next timer */
|
|
|
|
struct qent *prev; /* This can be used for callback args */
|
|
|
|
} qent;
|
|
|
|
|
|
|
|
typedef struct timer timer;
|
|
|
|
typedef int32 (*timer_hook)(timer *);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
struct timer {
|
2003-01-27 16:48:39 +03:00
|
|
|
qent entry;
|
|
|
|
uint16 flags;
|
|
|
|
uint16 cpu;
|
|
|
|
timer_hook hook;
|
|
|
|
bigtime_t period;
|
2002-09-20 02:33:58 +04:00
|
|
|
};
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
#define B_ONE_SHOT_ABSOLUTE_TIMER 1
|
|
|
|
#define B_ONE_SHOT_RELATIVE_TIMER 2
|
|
|
|
#define B_PERIODIC_TIMER 3
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern status_t add_timer(timer *t, timer_hook hook, bigtime_t period, int32 flags);
|
|
|
|
extern bool cancel_timer(timer *t);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/* kernel threads */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern thread_id spawn_kernel_thread(thread_func function, const char *threadName,
|
2004-06-11 19:39:56 +04:00
|
|
|
int32 priority, void *arg);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/* signal functions */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern int send_signal_etc(pid_t thread, uint sig, uint32 flags);
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/* virtual memory buffer functions */
|
|
|
|
|
|
|
|
#define B_DMA_IO 0x00000001
|
|
|
|
#define B_READ_DEVICE 0x00000002
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
typedef struct {
|
2003-01-27 16:48:39 +03:00
|
|
|
void *address; /* address in physical memory */
|
|
|
|
ulong size; /* size of block */
|
2002-09-20 02:33:58 +04:00
|
|
|
} physical_entry;
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern long lock_memory(void *buffer, ulong numBytes, ulong flags);
|
|
|
|
extern long unlock_memory(void *buffer, ulong numBytes, ulong flags);
|
|
|
|
extern long get_memory_map(const void *buffer, ulong size,
|
|
|
|
physical_entry *table, long numEntries);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* address specifications for mapping physical memory */
|
|
|
|
#define B_ANY_KERNEL_BLOCK_ADDRESS (B_ANY_KERNEL_ADDRESS + 1)
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2004-12-14 01:00:23 +03:00
|
|
|
/* area protection flags for the kernel */
|
|
|
|
#define B_KERNEL_READ_AREA 16
|
|
|
|
#define B_KERNEL_WRITE_AREA 32
|
2005-01-26 01:55:13 +03:00
|
|
|
#define B_USER_CLONEABLE_AREA 256
|
2004-12-14 01:00:23 +03:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* call to map physical memory - typically used for memory-mapped i/o */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern area_id map_physical_memory(const char *areaName, void *physicalAddress,
|
|
|
|
size_t size, uint32 flags, uint32 protection, void **mappedAddress);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* MTR attributes for mapping physical memory (Intel Architecture only) */
|
|
|
|
// ToDo: what have those to do here?
|
2002-09-20 02:33:58 +04:00
|
|
|
#define B_MTR_UC 0x10000000
|
|
|
|
#define B_MTR_WC 0x20000000
|
|
|
|
#define B_MTR_WT 0x30000000
|
|
|
|
#define B_MTR_WP 0x40000000
|
|
|
|
#define B_MTR_WB 0x50000000
|
|
|
|
#define B_MTR_MASK 0xf0000000
|
|
|
|
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/* hardware inquiry */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
/* platform_type return value is defined in OS.h */
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern platform_type platform();
|
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
#if __POWERPC__
|
2003-01-27 16:48:39 +03:00
|
|
|
extern long motherboard_version(void);
|
|
|
|
extern long io_card_version(void);
|
2002-09-20 02:33:58 +04:00
|
|
|
#endif
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/* primitive kernel debugging facilities */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/* Standard debug output is on...
|
|
|
|
* mac: modem port
|
|
|
|
* pc: com1
|
|
|
|
* ...at 19.2 kbaud, no parity, 8 bit, 1 stop bit.
|
|
|
|
*
|
|
|
|
* Note: the kernel settings file can override these defaults
|
|
|
|
*/
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
#if __GNUC__
|
2003-01-27 16:48:39 +03:00
|
|
|
extern void dprintf(const char *format, ...) /* just like printf */
|
2002-09-20 02:33:58 +04:00
|
|
|
__attribute__ ((format (__printf__, 1, 2)));
|
2003-01-27 16:48:39 +03:00
|
|
|
extern void kprintf(const char *fmt, ...) /* only for debugger cmds */
|
2002-09-20 02:33:58 +04:00
|
|
|
__attribute__ ((format (__printf__, 1, 2)));
|
|
|
|
#else
|
2003-01-27 16:48:39 +03:00
|
|
|
extern void dprintf(const char *format, ...); /* just like printf */
|
|
|
|
extern void kprintf(const char *fmt, ...); /* only for debugger cmds */
|
2002-09-20 02:33:58 +04:00
|
|
|
#endif
|
|
|
|
|
2006-07-25 23:46:36 +04:00
|
|
|
extern void dump_block(const char *buffer, int size, const char *prefix);
|
|
|
|
/* hexdumps given buffer */
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern bool set_dprintf_enabled(bool new_state); /* returns old state */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2006-08-26 21:49:43 +04:00
|
|
|
#if __GNUC__
|
|
|
|
extern void panic(const char *format, ...) __attribute__ ((format (__printf__, 1, 2)));
|
|
|
|
#else
|
2003-01-27 16:48:39 +03:00
|
|
|
extern void panic(const char *format, ...);
|
2006-08-26 21:49:43 +04:00
|
|
|
#endif
|
2003-01-27 16:48:39 +03:00
|
|
|
|
|
|
|
extern void kernel_debugger(const char *message); /* enter kernel debugger */
|
2004-06-08 10:25:18 +04:00
|
|
|
extern uint32 parse_expression(const char *string); /* utility for debugger cmds */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
|
|
|
/* special return codes for kernel debugger */
|
|
|
|
#define B_KDEBUG_CONT 2
|
|
|
|
#define B_KDEBUG_QUIT 3
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
typedef int (*debugger_command_hook)(int argc, char **argv);
|
|
|
|
|
|
|
|
extern int add_debugger_command(char *name, debugger_command_hook hook, char *help);
|
|
|
|
extern int remove_debugger_command(char *name, debugger_command_hook hook);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-02-14 17:27:34 +03:00
|
|
|
extern status_t load_driver_symbols(const char *driverName);
|
2003-02-10 00:05:37 +03:00
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
/* misc */
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
extern void spin(bigtime_t microseconds);
|
|
|
|
/* does a busy delay loop for at least "microseconds" */
|
|
|
|
|
2004-05-24 03:14:49 +04:00
|
|
|
typedef void (*daemon_hook)(void *arg, int iteration);
|
2003-01-27 16:48:39 +03:00
|
|
|
|
|
|
|
extern status_t register_kernel_daemon(daemon_hook hook, void *arg, int frequency);
|
|
|
|
extern status_t unregister_kernel_daemon(daemon_hook hook, void *arg);
|
|
|
|
|
|
|
|
extern void call_all_cpus(void (*f)(void *, int), void *cookie);
|
2002-09-20 02:33:58 +04:00
|
|
|
|
2004-09-29 14:22:34 +04:00
|
|
|
/* safe methods to access user memory without having to lock it */
|
|
|
|
extern status_t user_memcpy(void *to, const void *from, size_t size);
|
|
|
|
extern ssize_t user_strlcpy(char *to, const char *from, size_t size);
|
|
|
|
extern status_t user_memset(void *start, char c, size_t count);
|
|
|
|
|
2002-09-20 02:33:58 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-27 16:48:39 +03:00
|
|
|
#endif /* _KERNEL_EXPORT_H */
|