Our new KernelExport.h header.
Typedefs for debugger and kernel daemon hooks, cleaned up. Added a ToDo item about the "abuse" of the quent structure. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2581 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+125
-173
@@ -1,177 +1,139 @@
|
||||
/* ++++++++++
|
||||
KernelExport.h
|
||||
|
||||
Functions exported from the kernel for driver use that are not already
|
||||
prototyped elsewhere.
|
||||
|
||||
Copyright 1996-98, Be Incorporated.
|
||||
+++++ */
|
||||
|
||||
|
||||
/* Kernel only exports for kernel add-ons
|
||||
**
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
#ifndef _KERNEL_EXPORT_H
|
||||
#define _KERNEL_EXPORT_H
|
||||
|
||||
#include <BeBuild.h>
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ---
|
||||
kernel threads
|
||||
--- */
|
||||
/* disable/restore interrupts on the current CPU */
|
||||
|
||||
extern _IMPEXP_KERNEL thread_id spawn_kernel_thread (
|
||||
thread_func function,
|
||||
const char *thread_name,
|
||||
long priority,
|
||||
void *arg
|
||||
);
|
||||
typedef ulong cpu_status;
|
||||
|
||||
extern cpu_status disable_interrupts(void);
|
||||
extern void restore_interrupts(cpu_status status);
|
||||
|
||||
|
||||
/* ---
|
||||
disable/restore interrupt enable flag on current cpu
|
||||
--- */
|
||||
/* spinlocks. Note that acquire/release should be called with
|
||||
* interrupts disabled.
|
||||
*/
|
||||
|
||||
typedef ulong cpu_status;
|
||||
typedef vint32 spinlock;
|
||||
|
||||
extern _IMPEXP_KERNEL cpu_status disable_interrupts(void);
|
||||
extern _IMPEXP_KERNEL void restore_interrupts(cpu_status status);
|
||||
extern void acquire_spinlock(spinlock *lock);
|
||||
extern void release_spinlock(spinlock *lock);
|
||||
|
||||
|
||||
/* ---
|
||||
spinlocks. Note that acquire/release should be called with
|
||||
interrupts disabled.
|
||||
--- */
|
||||
|
||||
typedef vint32 spinlock;
|
||||
|
||||
extern _IMPEXP_KERNEL void acquire_spinlock (spinlock *lock);
|
||||
extern _IMPEXP_KERNEL void release_spinlock (spinlock *lock);
|
||||
|
||||
|
||||
/* ---
|
||||
An interrupt handler returns one of the following values:
|
||||
--- */
|
||||
|
||||
#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 */
|
||||
|
||||
typedef int32 (*interrupt_handler) (void *data);
|
||||
|
||||
/* interrupt handling support for device drivers */
|
||||
|
||||
extern _IMPEXP_KERNEL long install_io_interrupt_handler (
|
||||
long interrupt_number,
|
||||
interrupt_handler handler,
|
||||
void *data,
|
||||
ulong flags
|
||||
);
|
||||
extern _IMPEXP_KERNEL long remove_io_interrupt_handler (
|
||||
long interrupt_number,
|
||||
interrupt_handler handler,
|
||||
void *data
|
||||
);
|
||||
/* 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 */
|
||||
|
||||
/* ---
|
||||
timer interrupts services
|
||||
--- */
|
||||
typedef int32 (*interrupt_handler)(void *data);
|
||||
|
||||
typedef struct timer timer;
|
||||
typedef struct qent qent;
|
||||
typedef int32 (*timer_hook)(timer *);
|
||||
extern long install_io_interrupt_handler(long interrupt_number,
|
||||
interrupt_handler handler, void *data, ulong flags);
|
||||
extern long remove_io_interrupt_handler(long interrupt_number,
|
||||
interrupt_handler handler, void *data);
|
||||
|
||||
/**
|
||||
* The BeOS qent structure is probably part of a general double linked list
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* timer interrupts services */
|
||||
|
||||
/* The BeOS qent structure is probably part of a general double linked list
|
||||
* 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...
|
||||
*
|
||||
* ToDo: don't do this! Drop source compatibility, but don't overdefine those values!
|
||||
*/
|
||||
struct qent {
|
||||
typedef struct qent {
|
||||
int64 key; /* We use this as the sched time */
|
||||
qent *next; /* This is used as a pointer to next timer */
|
||||
qent *prev; /* This can be used for callback args */
|
||||
};
|
||||
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 *);
|
||||
|
||||
struct timer {
|
||||
qent entry;
|
||||
uint16 flags;
|
||||
uint16 cpu;
|
||||
timer_hook hook;
|
||||
bigtime_t period;
|
||||
qent entry;
|
||||
uint16 flags;
|
||||
uint16 cpu;
|
||||
timer_hook hook;
|
||||
bigtime_t period;
|
||||
};
|
||||
|
||||
status_t add_timer(timer *t, timer_hook h, bigtime_t, int32 f);
|
||||
bool cancel_timer(timer *t);
|
||||
#define B_ONE_SHOT_ABSOLUTE_TIMER 1
|
||||
#define B_ONE_SHOT_RELATIVE_TIMER 2
|
||||
#define B_PERIODIC_TIMER 3
|
||||
|
||||
#define B_ONE_SHOT_ABSOLUTE_TIMER 1
|
||||
#define B_ONE_SHOT_RELATIVE_TIMER 2
|
||||
#define B_PERIODIC_TIMER 3
|
||||
|
||||
/* ---
|
||||
signal functions
|
||||
--- */
|
||||
|
||||
extern _IMPEXP_KERNEL int send_signal_etc(pid_t thid, uint sig, uint32 flags);
|
||||
extern _IMPEXP_KERNEL int has_signals_pending(void *thr);
|
||||
extern status_t add_timer(timer *t, timer_hook hook, bigtime_t period, int32 flags);
|
||||
extern bool cancel_timer(timer *t);
|
||||
|
||||
|
||||
/* ---
|
||||
snooze functions
|
||||
--- */
|
||||
/*-------------------------------------------------------------*/
|
||||
/* kernel threads */
|
||||
|
||||
extern _IMPEXP_KERNEL status_t snooze_etc(bigtime_t usecs, int timebase, uint32 flags);
|
||||
extern thread_id spawn_kernel_thread(thread_func function, const char *threadName,
|
||||
long priority, void *arg);
|
||||
|
||||
|
||||
/* ---
|
||||
virtual memory buffer functions
|
||||
--- */
|
||||
/*-------------------------------------------------------------*/
|
||||
/* signal functions */
|
||||
|
||||
#define B_DMA_IO 0x00000001
|
||||
#define B_READ_DEVICE 0x00000002
|
||||
extern int send_signal_etc(pid_t thread, uint sig, uint32 flags);
|
||||
extern int has_signals_pending(void *_thread);
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* snooze functions */
|
||||
|
||||
extern status_t snooze_etc(bigtime_t usecs, int timebase, uint32 flags);
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* virtual memory buffer functions */
|
||||
|
||||
#define B_DMA_IO 0x00000001
|
||||
#define B_READ_DEVICE 0x00000002
|
||||
|
||||
typedef struct {
|
||||
void *address; /* address in physical memory */
|
||||
ulong size; /* size of block */
|
||||
void *address; /* address in physical memory */
|
||||
ulong size; /* size of block */
|
||||
} physical_entry;
|
||||
|
||||
extern _IMPEXP_KERNEL long lock_memory (
|
||||
void *buf, /* -> virtual buffer to lock (make resident) */
|
||||
ulong num_bytes, /* size of virtual buffer */
|
||||
ulong flags
|
||||
);
|
||||
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);
|
||||
|
||||
extern _IMPEXP_KERNEL long unlock_memory (
|
||||
void *buf, /* -> virtual buffer to unlock */
|
||||
ulong num_bytes, /* size of virtual buffer */
|
||||
ulong flags
|
||||
);
|
||||
/* address specifications for mapping physical memory */
|
||||
#define B_ANY_KERNEL_BLOCK_ADDRESS (B_ANY_KERNEL_ADDRESS + 1)
|
||||
|
||||
extern _IMPEXP_KERNEL long get_memory_map (
|
||||
const void *address, /* -> virtual buffer to translate */
|
||||
ulong size, /* size of virtual buffer */
|
||||
physical_entry *table, /* -> caller supplied table */
|
||||
long num_entries /* # entries in table */
|
||||
);
|
||||
|
||||
/* call to map physical memory - typically used for memory-mapped i/o */
|
||||
|
||||
/* -----
|
||||
address specifications for mapping physical memory
|
||||
----- */
|
||||
extern area_id map_physical_memory(const char *areaName, void *physicalAddress,
|
||||
size_t size, uint32 flags, uint32 protection, void **mappedAddress);
|
||||
|
||||
#define B_ANY_KERNEL_BLOCK_ADDRESS ((B_ANY_KERNEL_ADDRESS)+1)
|
||||
|
||||
/* -----
|
||||
MTR attributes for mapping physical memory (Intel Architecture only)
|
||||
----- */
|
||||
|
||||
/* MTR attributes for mapping physical memory (Intel Architecture only) */
|
||||
// ToDo: what have those to do here?
|
||||
#define B_MTR_UC 0x10000000
|
||||
#define B_MTR_WC 0x20000000
|
||||
#define B_MTR_WT 0x30000000
|
||||
@@ -179,82 +141,72 @@ extern _IMPEXP_KERNEL long get_memory_map (
|
||||
#define B_MTR_WB 0x50000000
|
||||
#define B_MTR_MASK 0xf0000000
|
||||
|
||||
/* -----
|
||||
call to map physical memory - typically used for memory-mapped i/o
|
||||
----- */
|
||||
|
||||
extern _IMPEXP_KERNEL area_id map_physical_memory (
|
||||
const char *area_name,
|
||||
void *physical_address,
|
||||
size_t size,
|
||||
uint32 flags,
|
||||
uint32 protection,
|
||||
void **mapped_address
|
||||
);
|
||||
|
||||
|
||||
/* -----
|
||||
hardware inquiry
|
||||
----- */
|
||||
/*-------------------------------------------------------------*/
|
||||
/* hardware inquiry */
|
||||
|
||||
/* platform_type return value is defined in OS.h */
|
||||
|
||||
extern _IMPEXP_KERNEL platform_type platform();
|
||||
extern platform_type platform();
|
||||
|
||||
#if __POWERPC__
|
||||
extern _IMPEXP_KERNEL long motherboard_version (void);
|
||||
extern _IMPEXP_KERNEL long io_card_version (void);
|
||||
extern long motherboard_version(void);
|
||||
extern long io_card_version(void);
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* primitive kernel debugging facilities */
|
||||
|
||||
/* ---
|
||||
primitive kernel debugging facilities. Debug output is on...
|
||||
|
||||
bebox: serial port 4
|
||||
mac: modem port
|
||||
pc: com1
|
||||
|
||||
...at 19.2 kbaud, no parity, 8 bit, 1 stop bit.
|
||||
--- */
|
||||
/* 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
|
||||
*/
|
||||
|
||||
#if __GNUC__
|
||||
extern _IMPEXP_KERNEL void dprintf (const char *format, ...) /* just like printf */
|
||||
extern void dprintf(const char *format, ...) /* just like printf */
|
||||
__attribute__ ((format (__printf__, 1, 2)));
|
||||
extern _IMPEXP_KERNEL void kprintf (const char *fmt, ...) /* only for debugger cmds */
|
||||
extern void kprintf(const char *fmt, ...) /* only for debugger cmds */
|
||||
__attribute__ ((format (__printf__, 1, 2)));
|
||||
#else
|
||||
extern _IMPEXP_KERNEL void dprintf (const char *format, ...); /* just like printf */
|
||||
extern _IMPEXP_KERNEL void kprintf (const char *fmt, ...); /* only for debugger cmds */
|
||||
extern void dprintf(const char *format, ...); /* just like printf */
|
||||
extern void kprintf(const char *fmt, ...); /* only for debugger cmds */
|
||||
#endif
|
||||
extern _IMPEXP_KERNEL bool set_dprintf_enabled (bool new_state); /* returns old state */
|
||||
|
||||
extern _IMPEXP_KERNEL void panic(const char *format, ...);
|
||||
extern bool set_dprintf_enabled(bool new_state); /* returns old state */
|
||||
|
||||
extern _IMPEXP_KERNEL void kernel_debugger (const char *message); /* enter kernel debugger */
|
||||
extern _IMPEXP_KERNEL ulong parse_expression (char *str); /* util for debugger cmds */
|
||||
extern void panic(const char *format, ...);
|
||||
|
||||
extern void kernel_debugger(const char *message); /* enter kernel debugger */
|
||||
extern ulong parse_expression(char *str); /* utility for debugger cmds */
|
||||
|
||||
/* special return codes for kernel debugger */
|
||||
#define B_KDEBUG_CONT 2
|
||||
#define B_KDEBUG_QUIT 3
|
||||
|
||||
extern _IMPEXP_KERNEL int add_debugger_command (char *name, /* add a cmd to debugger */
|
||||
int (*func)(int argc, char **argv),
|
||||
char *help);
|
||||
extern _IMPEXP_KERNEL int remove_debugger_command (char *name, /* remove a cmd from debugger */
|
||||
int (*func)(int argc, char **argv));
|
||||
typedef int (*debugger_command_hook)(int argc, char **argv);
|
||||
|
||||
/* -----
|
||||
misc
|
||||
----- */
|
||||
extern int add_debugger_command(char *name, debugger_command_hook hook, char *help);
|
||||
extern int remove_debugger_command(char *name, debugger_command_hook hook);
|
||||
|
||||
extern _IMPEXP_KERNEL void spin (bigtime_t num_microseconds);
|
||||
extern _IMPEXP_KERNEL int register_kernel_daemon(void (*func)(void *, int), void *arg, int freq);
|
||||
extern _IMPEXP_KERNEL int unregister_kernel_daemon(void (*func)(void *, int), void *arg);
|
||||
extern _IMPEXP_KERNEL void call_all_cpus(void (*f)(void*, int), void* cookie);
|
||||
|
||||
extern _IMPEXP_KERNEL int load_driver_symbols(const char *driver_name);
|
||||
/*-------------------------------------------------------------*/
|
||||
/* misc */
|
||||
|
||||
extern void spin(bigtime_t microseconds);
|
||||
/* does a busy delay loop for at least "microseconds" */
|
||||
|
||||
typedef int (*daemon_hook)(void *arg, int iteration);
|
||||
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* _KERNEL_EXPORT_H */
|
||||
|
||||
Reference in New Issue
Block a user