diff options
Diffstat (limited to 'libddekit/include')
44 files changed, 2975 insertions, 0 deletions
diff --git a/libddekit/include/.svn/all-wcprops b/libddekit/include/.svn/all-wcprops new file mode 100644 index 00000000..7ba2dd51 --- /dev/null +++ b/libddekit/include/.svn/all-wcprops @@ -0,0 +1,17 @@ +K 25 +svn:wc:ra_dav:version-url +V 50 +/repos/tudos/!svn/ver/457/trunk/l4/pkg/dde/include +END +dde.h +K 25 +svn:wc:ra_dav:version-url +V 56 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/dde.h +END +Makefile +K 25 +svn:wc:ra_dav:version-url +V 59 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/Makefile +END diff --git a/libddekit/include/.svn/entries b/libddekit/include/.svn/entries new file mode 100644 index 00000000..4bc0ab10 --- /dev/null +++ b/libddekit/include/.svn/entries @@ -0,0 +1,99 @@ +9 + +dir +465 +http://svn.tudos.org/repos/tudos/trunk/l4/pkg/dde/include +http://svn.tudos.org/repos/tudos + + + +2009-05-23T02:50:17.774710Z +457 +l4check + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +a704ac0b-3a55-4d43-a2a9-7be6f07c34fb + +dde.h +file + + + + +2009-11-15T17:14:44.000000Z +55a0119faab08988da07a2e0aa7f95a9 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +308 + +ddekit +dir + +Makefile +file + + + + +2009-11-15T17:14:44.000000Z +48ec0344857f2fa21c99f765cc91f0e6 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +276 + diff --git a/libddekit/include/.svn/format b/libddekit/include/.svn/format new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/libddekit/include/.svn/format @@ -0,0 +1 @@ +9 diff --git a/libddekit/include/.svn/text-base/Makefile.svn-base b/libddekit/include/.svn/text-base/Makefile.svn-base new file mode 100644 index 00000000..8d31023f --- /dev/null +++ b/libddekit/include/.svn/text-base/Makefile.svn-base @@ -0,0 +1,9 @@ +PKGDIR ?= .. +L4DIR ?= $(PKGDIR)/../.. + +# All haeder files found in this directory tree will be automatically +# installed in a way that they can be included with +# #include <l4/pkgname/yourfile.h> later. +# No need to list them in this Makefile. + +include $(L4DIR)/mk/include.mk diff --git a/libddekit/include/.svn/text-base/dde.h.svn-base b/libddekit/include/.svn/text-base/dde.h.svn-base new file mode 100644 index 00000000..12f8a81a --- /dev/null +++ b/libddekit/include/.svn/text-base/dde.h.svn-base @@ -0,0 +1,14 @@ +#ifndef l4_ddekit_h +#define l4_ddekit_h + +/* FIXME if this is ddekit.h, it should be moved into dde/ddekit/include/ddekit.h (also + * all headers under include/ddekit) */ + +/** + * Initialize the DDE. Must be called before any other DDE function. + * + * FIXME revisit this one + */ +void ddekit_init(void); + +#endif diff --git a/libddekit/include/Makefile b/libddekit/include/Makefile new file mode 100644 index 00000000..8d31023f --- /dev/null +++ b/libddekit/include/Makefile @@ -0,0 +1,9 @@ +PKGDIR ?= .. +L4DIR ?= $(PKGDIR)/../.. + +# All haeder files found in this directory tree will be automatically +# installed in a way that they can be included with +# #include <l4/pkgname/yourfile.h> later. +# No need to list them in this Makefile. + +include $(L4DIR)/mk/include.mk diff --git a/libddekit/include/dde.h b/libddekit/include/dde.h new file mode 100644 index 00000000..12f8a81a --- /dev/null +++ b/libddekit/include/dde.h @@ -0,0 +1,14 @@ +#ifndef l4_ddekit_h +#define l4_ddekit_h + +/* FIXME if this is ddekit.h, it should be moved into dde/ddekit/include/ddekit.h (also + * all headers under include/ddekit) */ + +/** + * Initialize the DDE. Must be called before any other DDE function. + * + * FIXME revisit this one + */ +void ddekit_init(void); + +#endif diff --git a/libddekit/include/ddekit/.svn/all-wcprops b/libddekit/include/ddekit/.svn/all-wcprops new file mode 100644 index 00000000..e216cf47 --- /dev/null +++ b/libddekit/include/ddekit/.svn/all-wcprops @@ -0,0 +1,107 @@ +K 25 +svn:wc:ra_dav:version-url +V 57 +/repos/tudos/!svn/ver/457/trunk/l4/pkg/dde/include/ddekit +END +panic.h +K 25 +svn:wc:ra_dav:version-url +V 65 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/panic.h +END +interrupt.h +K 25 +svn:wc:ra_dav:version-url +V 69 +/repos/tudos/!svn/ver/301/trunk/l4/pkg/dde/include/ddekit/interrupt.h +END +condvar.h +K 25 +svn:wc:ra_dav:version-url +V 67 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/condvar.h +END +pgtab.h +K 25 +svn:wc:ra_dav:version-url +V 65 +/repos/tudos/!svn/ver/395/trunk/l4/pkg/dde/include/ddekit/pgtab.h +END +initcall.h +K 25 +svn:wc:ra_dav:version-url +V 68 +/repos/tudos/!svn/ver/238/trunk/l4/pkg/dde/include/ddekit/initcall.h +END +assert.h +K 25 +svn:wc:ra_dav:version-url +V 66 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/assert.h +END +printf.h +K 25 +svn:wc:ra_dav:version-url +V 66 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/printf.h +END +types.h +K 25 +svn:wc:ra_dav:version-url +V 65 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/types.h +END +thread.h +K 25 +svn:wc:ra_dav:version-url +V 66 +/repos/tudos/!svn/ver/238/trunk/l4/pkg/dde/include/ddekit/thread.h +END +memory.h +K 25 +svn:wc:ra_dav:version-url +V 66 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/memory.h +END +resources.h +K 25 +svn:wc:ra_dav:version-url +V 69 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/resources.h +END +pci.h +K 25 +svn:wc:ra_dav:version-url +V 63 +/repos/tudos/!svn/ver/455/trunk/l4/pkg/dde/include/ddekit/pci.h +END +inline.h +K 25 +svn:wc:ra_dav:version-url +V 66 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/inline.h +END +timer.h +K 25 +svn:wc:ra_dav:version-url +V 65 +/repos/tudos/!svn/ver/457/trunk/l4/pkg/dde/include/ddekit/timer.h +END +semaphore.h +K 25 +svn:wc:ra_dav:version-url +V 69 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/semaphore.h +END +debug.h +K 25 +svn:wc:ra_dav:version-url +V 65 +/repos/tudos/!svn/ver/174/trunk/l4/pkg/dde/include/ddekit/debug.h +END +lock.h +K 25 +svn:wc:ra_dav:version-url +V 64 +/repos/tudos/!svn/ver/253/trunk/l4/pkg/dde/include/ddekit/lock.h +END diff --git a/libddekit/include/ddekit/.svn/entries b/libddekit/include/ddekit/.svn/entries new file mode 100644 index 00000000..21752264 --- /dev/null +++ b/libddekit/include/ddekit/.svn/entries @@ -0,0 +1,606 @@ +9 + +dir +465 +http://svn.tudos.org/repos/tudos/trunk/l4/pkg/dde/include/ddekit +http://svn.tudos.org/repos/tudos + + + +2009-05-23T02:50:17.774710Z +457 +l4check + + +svn:special svn:externals svn:needs-lock + + + + + + + + + + + +a704ac0b-3a55-4d43-a2a9-7be6f07c34fb + +panic.h +file + + + + +2009-11-15T17:14:44.000000Z +2570239ee2dbc1154cf146aa16bcf547 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +330 + +interrupt.h +file + + + + +2009-11-15T17:14:44.000000Z +ee8b18c79ba7d7cf50a35d8105f68750 +2008-02-16T03:51:13.191963Z +301 +l4check + + + + + + + + + + + + + + + + + + + + + +1586 + +condvar.h +file + + + + +2009-11-15T17:14:44.000000Z +6ad1a17ba32ef17c1345685eda2bb129 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +1239 + +pgtab.h +file + + + + +2009-11-15T17:14:44.000000Z +5991c64662b8e2d95e1202eb4ff6045c +2008-08-14T02:50:25.232552Z +395 +l4check + + + + + + + + + + + + + + + + + + + + + +2086 + +initcall.h +file + + + + +2009-11-15T17:14:44.000000Z +c04d502176e023a054602b5d18ac29e1 +2007-11-08T03:52:28.731143Z +238 +l4check + + + + + + + + + + + + + + + + + + + + + +1135 + +assert.h +file + + + + +2009-11-15T17:14:44.000000Z +ab222d72d5dc9ad29a5c435561818d0c +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +592 + +printf.h +file + + + + +2009-11-15T17:14:44.000000Z +a0e9adfc93ede606218916e4f5d9f437 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +731 + +types.h +file + + + + +2009-11-15T17:14:44.000000Z +a0fd3a957254115d16d6bafe5f23c630 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +616 + +thread.h +file + + + + +2009-11-15T17:14:44.000000Z +1e42c7c3396e9dbb7d238e19e4368e6d +2007-11-08T03:52:28.731143Z +238 +l4check + + + + + + + + + + + + + + + + + + + + + +3877 + +memory.h +file + + + + +2009-11-15T17:14:44.000000Z +980f4cc26bf2735a3518da3d16060500 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +3486 + +resources.h +file + + + + +2009-11-15T17:14:44.000000Z +cdd94bcecf43cb4001bf3f5919704968 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +449 + +pci.h +file + + + + +2009-11-15T17:14:44.000000Z +3d708d2ff3ac2937415cd19bb0ac9e0d +2009-05-20T14:32:55.606606Z +455 +l4check + + + + + + + + + + + + + + + + + + + + + +5045 + +inline.h +file + + + + +2009-11-15T17:14:44.000000Z +0c47197d7519e09e4b8bbd76b56c4b60 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +58 + +timer.h +file + + + + +2009-11-15T17:14:44.000000Z +850acfa4cd49770e7a2f8b511b1cfde4 +2009-05-23T02:50:17.774710Z +457 +l4check + + + + + + + + + + + + + + + + + + + + + +1186 + +semaphore.h +file + + + + +2009-11-15T17:14:44.000000Z +b8f721cb8c9d58ba4d163510c9687843 +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +991 + +debug.h +file + + + + +2009-11-15T17:14:44.000000Z +8a52d2548bcf2855c1d843a074e81ceb +2007-09-08T19:44:13.897747Z +174 +l4check + + + + + + + + + + + + + + + + + + + + + +146 + +lock.h +file + + + + +2009-11-15T17:14:44.000000Z +a8a89bd7ee88b2f8279f2f6716c6ee15 +2007-12-13T03:50:57.801357Z +253 +l4check + + + + + + + + + + + + + + + + + + + + + +2114 + diff --git a/libddekit/include/ddekit/.svn/format b/libddekit/include/ddekit/.svn/format new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/libddekit/include/ddekit/.svn/format @@ -0,0 +1 @@ +9 diff --git a/libddekit/include/ddekit/.svn/text-base/assert.h.svn-base b/libddekit/include/ddekit/.svn/text-base/assert.h.svn-base new file mode 100644 index 00000000..5d572b49 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/assert.h.svn-base @@ -0,0 +1,23 @@ +#ifndef _ddekit_assert_h +#define _ddekit_assert_h + +#include <l4/dde/ddekit/printf.h> +#include <l4/dde/ddekit/panic.h> + +/** \file ddekit/assert.h */ + +/** Assert that an expression is true and panic if not. + * \ingroup DDEKit_util + */ +#define Assert(expr) do \ + { \ + if (!(expr)) { \ + ddekit_print("\033[31;1mDDE: Assertion failed: "#expr"\033[0m\n"); \ + ddekit_printf(" File: %s:%d\n",__FILE__,__LINE__); \ + ddekit_printf(" Function: %s()\n", __FUNCTION__); \ + ddekit_panic("Assertion failed."); \ + }} while (0); + +#endif + +#define assert Assert diff --git a/libddekit/include/ddekit/.svn/text-base/condvar.h.svn-base b/libddekit/include/ddekit/.svn/text-base/condvar.h.svn-base new file mode 100644 index 00000000..b6dc4bd3 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/condvar.h.svn-base @@ -0,0 +1,54 @@ +#ifndef _ddekit_condvar_h +#define _ddekit_condvar_h + +/** \file ddekit/condvar.h */ + +#include <l4/dde/ddekit/lock.h> + +struct ddekit_condvar; +typedef struct ddekit_condvar ddekit_condvar_t; + +/** Initialize conditional variable. + * + * \ingroup DDEKit_synchronization + */ +ddekit_condvar_t * ddekit_condvar_init(void); + +/** Uninitialize conditional variable. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_condvar_deinit(ddekit_condvar_t *cvp); + +/** Wait on a conditional variable. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_condvar_wait(ddekit_condvar_t *cvp, ddekit_lock_t *mp); + +/** Wait on a conditional variable at most until a timeout expires. + * + * \ingroup DDEKit_synchronization + * + * \param cvp pointer to condvar + * \param mp lock + * \param timo timeout in ms + * + * \return 0 success + * \return !=0 timeout + */ +int ddekit_condvar_wait_timed(ddekit_condvar_t *cvp, ddekit_lock_t *mp, int timo); + +/** Send signal to the next one waiting for condvar. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_condvar_signal(ddekit_condvar_t *cvp); + +/** Send signal to all threads waiting for condvar. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_condvar_broadcast(ddekit_condvar_t *cvp); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/debug.h.svn-base b/libddekit/include/ddekit/.svn/text-base/debug.h.svn-base new file mode 100644 index 00000000..79a8e7b5 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/debug.h.svn-base @@ -0,0 +1,8 @@ +#define DDEBUG_QUIET 0 +#define DDEBUG_ERR 1 +#define DDEBUG_WARN 2 +#define DDEBUG_INFO 3 +#define DDEBUG_VERBOSE 4 + +#define DDEBUG_MEM DDEBUG_INFO + diff --git a/libddekit/include/ddekit/.svn/text-base/initcall.h.svn-base b/libddekit/include/ddekit/.svn/text-base/initcall.h.svn-base new file mode 100644 index 00000000..b503cc6a --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/initcall.h.svn-base @@ -0,0 +1,42 @@ +#ifndef _ddekit_initcall_h +#define _ddekit_initcall_h + +// from l4/sys/compiler.h +#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4 +#define L4_STICKY(x) __attribute__((used)) x +#else +#define L4_STICKY(x) __attribute__((unused)) x +#endif + +#define l4str(s) #s + +// from dde_linux/ARCH-x86/ctor.h +typedef void (*l4ddekit_initcall_t)(void); + +#define __l4ddekit_initcall(p) \ + __attribute__ ((__section__ (".l4dde_ctors." #p))) + +/** Define a function to be a DDEKit initcall. + * + * Define a function to be a DDEKit initcall. This function will then be placed + * in a separate linker section of the binary (called .l4dde_ctors). The L4Env + * construction mechanism will execute all constructors in this section during + * application startup. + * + * This is the right place to place Linux' module_init functions & Co. + * + * \param fn function + */ +#define DDEKIT_INITCALL(fn) DDEKIT_CTOR(fn, 1) + +#define DDEKIT_CTOR(fn, prio) \ + static l4ddekit_initcall_t \ + L4_STICKY(__l4ddekit_initcall_##fn) \ + __l4ddekit_initcall(prio) = (void *)fn + +/** + * Runs all registered initcalls. + */ +void ddekit_do_initcalls(void); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/inline.h.svn-base b/libddekit/include/ddekit/.svn/text-base/inline.h.svn-base new file mode 100644 index 00000000..e59a5c68 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/inline.h.svn-base @@ -0,0 +1,2 @@ +#define INLINE __inline__ __attribute__((always_inline)) + diff --git a/libddekit/include/ddekit/.svn/text-base/interrupt.h.svn-base b/libddekit/include/ddekit/.svn/text-base/interrupt.h.svn-base new file mode 100644 index 00000000..bbabedb2 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/interrupt.h.svn-base @@ -0,0 +1,57 @@ +/* + * \brief Hardware-interrupt subsystem + * \author Thomas Friebel <tf13@os.inf.tu-dresden.de> + * \author Christian Helmuth <ch12@os.inf.tu-dresden.de> + * \date 2007-01-26 + * + * DDEKit supports registration of one handler function per interrupt. If any + * specific DDE implementation needs to register more than one handler, + * multiplexing has to be implemented there! + */ + +#ifndef _ddekit_interrupt_h +#define _ddekit_interrupt_h + +#include <l4/dde/ddekit/thread.h> + +#define DDEKIT_IRQ_PRIO 0x11 + +/** + * Attach to hardware interrupt + * + * \param irq IRQ number to attach to + * \param shared set to 1 if interrupt sharing is supported; set to 0 + * otherwise + * \param thread_init called just after DDEKit internal init and before any + * other function + * \param handler IRQ handler for interrupt irq + * \param priv private token (argument for thread_init and handler) + * + * \return pointer to interrupt thread created + */ +ddekit_thread_t *ddekit_interrupt_attach(int irq, int shared, + void(*thread_init)(void *), + void(*handler)(void *), void *priv); + +/** + * Detach from a previously attached interrupt. + * + * \param irq IRQ number + */ +void ddekit_interrupt_detach(int irq); + +/** + * Block interrupt. + * + * \param irq IRQ number to block + */ +void ddekit_interrupt_disable(int irq); + +/** + * Enable interrupt. + * + * \param irq IRQ number to block + */ +void ddekit_interrupt_enable(int irq); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/lock.h.svn-base b/libddekit/include/ddekit/.svn/text-base/lock.h.svn-base new file mode 100644 index 00000000..872acad0 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/lock.h.svn-base @@ -0,0 +1,83 @@ +#ifndef _ddekit_lock_h +#define _ddekit_lock_h + +struct ddekit_lock; + +/** Initialize a DDEKit lock. + * + * \ingroup DDEKit_synchronization + */ +void _ddekit_lock_init (struct ddekit_lock **mtx); + +/** Uninitialize a DDEKit lock. + * + * \ingroup DDEKit_synchronization + */ +void _ddekit_lock_deinit (struct ddekit_lock **mtx); + +/** Acquire a lock. + * + * \ingroup DDEKit_synchronization + */ +void _ddekit_lock_lock (struct ddekit_lock **mtx); + +/** Acquire a lock, non-blocking. + * + * \ingroup DDEKit_synchronization + */ +int _ddekit_lock_try_lock(struct ddekit_lock **mtx); + +/** Unlock function. + * + * \ingroup DDEKit_synchronization + */ +void _ddekit_lock_unlock (struct ddekit_lock **mtx); + +/** Get lock owner. + * + * \ingroup DDEKit_synchronization + */ +int _ddekit_lock_owner(struct ddekit_lock **mtx); + +// definition of ddekit_lock_t +typedef struct ddekit_lock *ddekit_lock_t; + +// common prototypes +static void ddekit_lock_init_locked(ddekit_lock_t *mtx); +static void ddekit_lock_init_unlocked(ddekit_lock_t *mtx); +#define ddekit_lock_init ddekit_lock_init_unlocked +static void ddekit_lock_deinit (ddekit_lock_t *mtx); +static void ddekit_lock_lock (ddekit_lock_t *mtx); +static int ddekit_lock_try_lock(ddekit_lock_t *mtx); // returns 0 on success, != 0 if it would block +static void ddekit_lock_unlock (ddekit_lock_t *mtx); + +// inline implementation or inline call to non-inline implementation +#include <l4/dde/ddekit/inline.h> + +static INLINE void ddekit_lock_init_unlocked(ddekit_lock_t *mtx) { + _ddekit_lock_init(mtx); +} + +static INLINE void ddekit_lock_init_locked(ddekit_lock_t *mtx) { + _ddekit_lock_init(mtx); + _ddekit_lock_lock(mtx); +} + +static INLINE void ddekit_lock_deinit(ddekit_lock_t *mtx) { + _ddekit_lock_deinit(mtx); +} +static INLINE void ddekit_lock_lock(ddekit_lock_t *mtx) { + _ddekit_lock_lock(mtx); +} +static INLINE int ddekit_lock_try_lock(ddekit_lock_t *mtx) { + return _ddekit_lock_try_lock(mtx); +} +static INLINE void ddekit_lock_unlock(ddekit_lock_t *mtx) { + _ddekit_lock_unlock(mtx); +} + +static INLINE int ddekit_lock_owner(ddekit_lock_t *mtx) { + return _ddekit_lock_owner(mtx); +} + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/memory.h.svn-base b/libddekit/include/ddekit/.svn/text-base/memory.h.svn-base new file mode 100644 index 00000000..051a4d9e --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/memory.h.svn-base @@ -0,0 +1,144 @@ +/* + * \brief Memory subsystem + * \author Thomas Friebel <tf13@os.inf.tu-dresden.de> + * \author Christian Helmuth <ch12@os.inf.tu-dresden.de> + * \date 2006-11-03 + */ + +#ifndef _ddekit_memory_h +#define _ddekit_memory_h + + +/******************* + ** Slab facility ** + *******************/ + +struct ddekit_slab; + +/** + * Store user pointer in slab cache + * + * \param slab pointer to slab cache + * \param data user pointer + */ +void ddekit_slab_set_data(struct ddekit_slab * slab, void *data); + +/** + * Read user pointer from slab cache + * + * \param slab pointer to slab cache + * + * \return stored user pointer or 0 + */ +void *ddekit_slab_get_data(struct ddekit_slab * slab); + +/** + * Allocate slab in slab cache + * + * \param slab pointer to slab cache + * + * \return pointer to allocated slab + */ +void *ddekit_slab_alloc(struct ddekit_slab * slab); + +/** + * Deallocate slab in slab cache + * + * \param slab pointer to slab cache + * \param objp pointer to allocated slab + */ +void ddekit_slab_free(struct ddekit_slab * slab, void *objp); + +/** + * Setup page cache for all slabs + * + * \param pages maximal number of memory pages + * + * If 'pages' is too low, memory pages may be given back to the memory server + * (dm_phys) and just to be allocated again later. This hits performance (but + * saves memory). Increase 'pages' to avoid this thrashing-like effect. + * + * If the maximal number of unused pages is exceeded, subsequent deallocation + * will be freed at the memory server. This page cache caches pages from all + * slabs. + */ +void ddekit_slab_setup_page_cache(unsigned pages); + +/** + * Destroy slab cache + * + * \param slab pointer to slab cache structure + */ +void ddekit_slab_destroy(struct ddekit_slab * slab); + +/** + * Initialize slab cache + * + * \param size size of cache objects + * \param contiguous make this slab use physically contiguous memory + * + * \return pointer to new slab cache or 0 on error + */ +struct ddekit_slab * ddekit_slab_init(unsigned size, int contiguous); + + +/********************** + ** Memory allocator ** + **********************/ + +/** + * Allocate large memory block + * + * \param size block size + * \return pointer to new memory block + * + * Allocations via this allocator may be slow (because memory servers are + * involved) and should be used only for large (i.e., > page size) blocks. If + * allocations/deallocations are relatively dynamic this may not be what you + * want. + * + * Allocated blocks have valid virt->phys mappings and are physically + * contiguous. + */ +void *ddekit_large_malloc(int size); + +/** + * Free large memory block + * + * \param p pointer to memory block + */ +void ddekit_large_free(void *p); + +/** FIXME + * contig_malloc() is the lowest-level allocator interface one could implement. + * we should consider to provide vmalloc() too. */ +void *ddekit_contig_malloc( + unsigned long size, + unsigned long low, unsigned long high, + unsigned long alignment, unsigned long boundary +); + + +/***************************** + ** Simple memory allocator ** + *****************************/ + +/** + * Allocate memory block via simple allocator + * + * \param size block size + * \return pointer to new memory block + * + * The blocks allocated via this allocator CANNOT be used for DMA or other + * device operations, i.e., there exists no virt->phys mapping. + */ +void *ddekit_simple_malloc(unsigned size); + +/** + * Free memory block via simple allocator + * + * \param p pointer to memory block + */ +void ddekit_simple_free(void *p); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/panic.h.svn-base b/libddekit/include/ddekit/.svn/text-base/panic.h.svn-base new file mode 100644 index 00000000..1468675f --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/panic.h.svn-base @@ -0,0 +1,16 @@ +#ifndef _ddekit_panic_h +#define _ddekit_panic_h + +/** \defgroup DDEKit_util */ + +/** Panic - print error message and enter the kernel debugger. + * \ingroup DDEKit_util + */ +void ddekit_panic(char *fmt, ...) __attribute__((noreturn)); + +/** Print a debug message. + * \ingroup DDEKit_util + */ +void ddekit_debug(char *fmt, ...); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/pci.h.svn-base b/libddekit/include/ddekit/.svn/text-base/pci.h.svn-base new file mode 100644 index 00000000..9ec7cd4f --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/pci.h.svn-base @@ -0,0 +1,199 @@ +#ifndef _ddekit_pci_h +#define _ddekit_pci_h + +#include <l4/dde/ddekit/types.h> + +/** \defgroup DDEKit_pci */ + +/** Our version of PCI_ANY_ID */ +#define DDEKIT_PCI_ANY_ID (~0) + +/** Copy of L4IO_PCIDEV_RES */ +#define DDEKIT_PCIDEV_RES 12 + +struct ddekit_pci_dev; + +/** PCI resource descriptor. Copied from generic_io. + * + * XXX! + */ +typedef struct ddekit_pci_resource { + unsigned long start; + unsigned long end; + unsigned long flags; +} ddekit_pci_res_t; + +void ddekit_pci_init(void); + +int ddekit_pci_get_device(int nr, int *bus, int *slot, int *func); + +int ddekit_pci_read(int bus, int slot, int func, int pos, int len, ddekit_uint32_t *val); +int ddekit_pci_write(int bus, int slot, int func, int pos, int len, ddekit_uint32_t val); + +/** Read byte from PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val read value + * + * \return 0 success + */ +int ddekit_pci_readb (int bus, int slot, int func, int pos, ddekit_uint8_t *val); + +/** Read word from PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val read value + * + * \return 0 success + */ +int ddekit_pci_readw (int bus, int slot, int func, int pos, ddekit_uint16_t *val); + +/** Read dword from PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val read value + * + * \return 0 success + */ +int ddekit_pci_readl (int bus, int slot, int func, int pos, ddekit_uint32_t *val); + +/** Write byte to PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val value to write + * + * \return 0 success + */ +int ddekit_pci_writeb(int bus, int slot, int func, int pos, ddekit_uint8_t val); + +/** Write word to PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val value to write + * + * \return 0 success + */ +int ddekit_pci_writew(int bus, int slot, int func, int pos, ddekit_uint16_t val); + +/** Write word to PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val value to write + * + * \return 0 success + */ +int ddekit_pci_writel(int bus, int slot, int func, int pos, ddekit_uint32_t val); + +/** Find a PCI device. + * + * \ingroup DDEKit_pci + * + * \param bus pointer to bus number or \ref DDEKIT_PCI_ANY_ID + * \param slot pointer to slot number (devfn >> DEVFN_SLOTSHIFT) or \ref DDEKIT_PCI_ANY_ID + * \param func pointer to func number (devfc & DEVFN_FUNCMASK) or \ref DDEKIT_PCI_ANY_ID + * \param start search device list only behind this device (excluding it!), NULL + * searches whole device list + * + * \retval bus bus number + * \retval slot slot number + * \retval func function number + * + * \return device a valid PCI device + * \return NULL if no device found + */ +struct ddekit_pci_dev * +ddekit_pci_find_device(int *bus, int *slot, int *func, struct ddekit_pci_dev *start); + +/** Enable PCI device + * \ingroup DDEKit_pci + */ +int ddekit_pci_enable_device(struct ddekit_pci_dev *dev); + +/** Disable PCI device + * \ingroup DDEKit_pci + */ +int ddekit_pci_disable_device(struct ddekit_pci_dev *dev); + +/** Enable bus-mastering for device. + * \ingroup DDEKit_pci + */ +void ddekit_pci_set_master(struct ddekit_pci_dev *dev); + +/** Get device vendor ID. + * \ingroup DDEKit_pci + */ +unsigned short ddekit_pci_get_vendor(struct ddekit_pci_dev *dev); + +/** Get device ID. + * \ingroup DDEKit_pci + */ +unsigned short ddekit_pci_get_device_id(struct ddekit_pci_dev *dev); + +/** Get device subvendor ID. + * \ingroup DDEKit_pci + */ +unsigned short ddekit_pci_get_sub_vendor(struct ddekit_pci_dev *dev); + +/** Get subdevice ID. + * \ingroup DDEKit_pci + */ +unsigned short ddekit_pci_get_sub_device(struct ddekit_pci_dev *dev); + +/** Get device class ID. + * \ingroup DDEKit_pci + */ +unsigned ddekit_pci_get_dev_class(struct ddekit_pci_dev *dev); + +/** Get device's IRQ number. + * \ingroup DDEKit_pci + */ +unsigned long ddekit_pci_get_irq(struct ddekit_pci_dev *dev); + +/** Get device name. + * \ingroup DDEKit_pci + */ +char *ddekit_pci_get_name(struct ddekit_pci_dev *dev); + +/** Get device's slot name. + * \ingroup DDEKit_pci + */ +char *ddekit_pci_get_slot_name(struct ddekit_pci_dev *dev); + +/** Get one of the device's resources. + * \ingroup DDEKit_pci + */ +ddekit_pci_res_t *ddekit_pci_get_resource(struct ddekit_pci_dev *dev, unsigned int idx); + +int ddekit_pci_irq_enable(int bus, int slot, int func, int pin, int *irq); + +#endif // _ddekit_pci_h diff --git a/libddekit/include/ddekit/.svn/text-base/pgtab.h.svn-base b/libddekit/include/ddekit/.svn/text-base/pgtab.h.svn-base new file mode 100644 index 00000000..3b68192c --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/pgtab.h.svn-base @@ -0,0 +1,86 @@ +/* + * \brief Virtual page-table facility + * \author Thomas Friebel <tf13@os.inf.tu-dresden.de> + * \author Christian Helmuth <ch12@os.inf.tu-dresden.de> + * \date 2006-11-03 + */ + +#ifndef _ddekit_pgtab_h +#define _ddekit_pgtab_h + +#include <l4/dde/ddekit/types.h> + +/* FIXME Region types may be defined by pgtab users. Do we really need them + * here? */ +enum ddekit_pgtab_type +{ + PTE_TYPE_OTHER, PTE_TYPE_LARGE, PTE_TYPE_UMA, PTE_TYPE_CONTIG +}; + + +/** + * Set virtual->physical mapping for VM region + * + * \param virt virtual start address for region + * \param phys physical start address for region + * \param pages number of pages in region + * \param type pgtab type for region + */ +void ddekit_pgtab_set_region(void *virt, ddekit_addr_t phys, int pages, int type); + + +/** + * Set virtual->physical mapping for VM region given a specific size in bytes. + * + * Internally, DDEKit manages regions with pages. However, DDEs do not need to tangle + * with the underlying mechanism and therefore can use this function that takes care + * of translating a size to an amount of pages. + */ +void ddekit_pgtab_set_region_with_size(void *virt, ddekit_addr_t phys, int size, int type); + + +/** + * Clear virtual->physical mapping for VM region + * + * \param virt virtual start address for region + * \param type pgtab type for region + */ +void ddekit_pgtab_clear_region(void *virt, int type); + +/** + * Get physical address for virtual address + * + * \param virt virtual address + * + * \return physical address + */ +ddekit_addr_t ddekit_pgtab_get_physaddr(const void *virt); + +/** + * Get virtual address for physical address + * + * \param physical physical address + * + * \return virtual address + */ +ddekit_addr_t ddekit_pgtab_get_virtaddr(const ddekit_addr_t physical); + +/** + * Get type of VM region. + * + * \param virt virtual address + + * \return VM region type + */ +int ddekit_pgtab_get_type(const void *virt); + +/** + * Get size of VM region. + * + * \param virt virtual address + * + * \return VM region size (in bytes) + */ +int ddekit_pgtab_get_size(const void *virt); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/printf.h.svn-base b/libddekit/include/ddekit/.svn/text-base/printf.h.svn-base new file mode 100644 index 00000000..35b0dfa1 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/printf.h.svn-base @@ -0,0 +1,33 @@ +#ifndef _ddekit_print_h +#define _ddekit_print_h + +#include <stdarg.h> + +/** Print message. + * \ingroup DDEKit_util + */ +int ddekit_print(const char *); + +/** Print message with format. + * \ingroup DDEKit_util + */ +int ddekit_printf(const char *fmt, ...); + +/** Print message with format list. + * \ingroup DDEKit_util + */ +int ddekit_vprintf(const char *fmt, va_list va); + +/** Log function and message. + * \ingroup DDEKit_util + */ +#define ddekit_log(doit, msg...) \ + do { \ + if (doit) { \ + ddekit_printf("%s(): ", __func__); \ + ddekit_printf(msg); \ + ddekit_printf("\n"); \ + } \ + } while(0); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/resources.h.svn-base b/libddekit/include/ddekit/.svn/text-base/resources.h.svn-base new file mode 100644 index 00000000..e0fa68f0 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/resources.h.svn-base @@ -0,0 +1,13 @@ +#ifndef _ddekit_resources_h +#define _ddekit_resources_h + +#include <l4/dde/ddekit/types.h> + +int ddekit_request_dma(int nr); +int ddekit_release_dma(int nr); +int ddekit_request_io (ddekit_addr_t start, ddekit_addr_t count); +int ddekit_release_io (ddekit_addr_t start, ddekit_addr_t count); +int ddekit_request_mem(ddekit_addr_t start, ddekit_addr_t count, ddekit_addr_t *vaddr); +int ddekit_release_mem(ddekit_addr_t start, ddekit_addr_t count); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/semaphore.h.svn-base b/libddekit/include/ddekit/.svn/text-base/semaphore.h.svn-base new file mode 100644 index 00000000..c959919d --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/semaphore.h.svn-base @@ -0,0 +1,50 @@ +#ifndef _ddekit_semaphore_h +#define _ddekit_semaphore_h + +/** \defgroup DDEKit_synchronization */ + +struct ddekit_sem; +typedef struct ddekit_sem ddekit_sem_t; + +/** Initialize DDEKit semaphore. + * + * \ingroup DDEKit_synchronization + * + * \param value initial semaphore counter + */ +ddekit_sem_t *ddekit_sem_init(int value); + +/** Uninitialize semaphore. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_sem_deinit(ddekit_sem_t *sem); + +/** Semaphore down method. */ +void ddekit_sem_down(ddekit_sem_t *sem); + +/** Semaphore down method, non-blocking. + * + * \ingroup DDEKit_synchronization + * + * \return 0 success + * \return !=0 would block + */ +int ddekit_sem_down_try(ddekit_sem_t *sem); + +/** Semaphore down with timeout. + * + * \ingroup DDEKit_synchronization + * + * \return 0 success + * \return !=0 would block + */ +int ddekit_sem_down_timed(ddekit_sem_t *sem, int timo); + +/** Semaphore up method. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_sem_up(ddekit_sem_t *sem); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/thread.h.svn-base b/libddekit/include/ddekit/.svn/text-base/thread.h.svn-base new file mode 100644 index 00000000..ecd399d9 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/thread.h.svn-base @@ -0,0 +1,162 @@ +#ifndef _ddekit_thread_h +#define _ddekit_thread_h + +/** \defgroup DDEKit_threads */ + +#include <l4/dde/ddekit/lock.h> + +struct ddekit_thread; +typedef struct ddekit_thread ddekit_thread_t; + +/** Create thread + * + * \ingroup DDEKit_threads + * + * Create a new thread running the specified thread function with the specified + * arguments. The thread is assigned the given internal name. + * + * Additionally, DDEKit threads possess a thread-local storage area where they + * may store arbitrary data. + * + * \param fun thread function + * \param arg optional argument to thread function, set to NULL if not needed + * \param name internal thread name + */ +ddekit_thread_t *ddekit_thread_create(void (*fun)(void *), void *arg, const char *name); + +/** Reference to own DDEKit thread id. + * + * \ingroup DDEKit_threads + */ +ddekit_thread_t *ddekit_thread_myself(void); + +/** Initialize thread with given name. + * + * \ingroup DDEKit_threads + * + * This function may be used by threads that were not created using + * \ref ddekit_thread_create. This enables such threads to be handled as if they + * were DDEKit threads. + */ +ddekit_thread_t *ddekit_thread_setup_myself(const char *name); + +/** Get TLS data for a specific thread. + * + * \ingroup DDEKit_threads + * + * \return Pointer to TLS data of this thread. + */ +void *ddekit_thread_get_data(ddekit_thread_t *thread); + +/** Get TLS data for current thread. + * + * \ingroup DDEKit_threads + * + * Same as calling \ref ddekit_thread_get_data with \ref ddekit_thread_myself + * as parameter. + * + * \return Pointer to TLS data of current thread. + */ +void *ddekit_thread_get_my_data(void); + +/** Set TLS data for specific thread. + * + * \ingroup DDEKit_threads + * + * \param thread DDEKit thread + * \param data pointer to thread data + */ +void ddekit_thread_set_data(ddekit_thread_t *thread, void *data); + +/** Set TLS data for current thread. + * + * \ingroup DDEKit_threads + * + * \param data pointer to thread data + */ +void ddekit_thread_set_my_data(void *data); + +/** Sleep for some miliseconds. + * + * \ingroup DDEKit_threads + * + * \param msecs time to sleep in ms. + */ +void ddekit_thread_msleep(unsigned long msecs); + +/** Sleep for some microseconds. + * + * \ingroup DDEKit_threads + * + * \param usecs time to sleep in µs. + */ +void ddekit_thread_usleep(unsigned long usecs); + +/** Sleep for some nanoseconds. + * + * \ingroup DDEKit_threads + * + * \param usecs time to sleep in ns. + */ +void ddekit_thread_nsleep(unsigned long nsecs); + +/** Sleep until a lock becomes unlocked. + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_sleep(ddekit_lock_t *lock); + +/** Wakeup a waiting thread. + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_wakeup(ddekit_thread_t *thread); + +/** Terminate a thread + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_exit(void) __attribute__((noreturn)); + +/** Terminate a thread + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_terminate(ddekit_thread_t *thread); + +/** Get the name, a thread registered with DDEKit. + * + * \ingroup DDEKit_threads + */ +const char *ddekit_thread_get_name(ddekit_thread_t *thread); + +/** Get unique ID of a DDEKit thread. + * + * \ingroup DDEKit_threads + * + * DDEKit does not allow direct access to the thread data + * structure, since this struct contains L4-specific data types. + * However, applications might want to get some kind of ID related + * to a ddekit_thread, for instance to use it as a Linux-like PID. + */ +int ddekit_thread_get_id(ddekit_thread_t *thread); + +/** Hint that this thread is done and may be scheduled somehow. + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_schedule(void); + +/** Hint that this thread is done and may be scheduled somehow. + * + * \ingroup DDEKit_threads + */ +void ddekit_yield(void); + +/** Initialize DDEKit thread subsystem. + * + * \ingroup DDEKit_threads + */ +void ddekit_init_threads(void); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/timer.h.svn-base b/libddekit/include/ddekit/.svn/text-base/timer.h.svn-base new file mode 100644 index 00000000..c352475c --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/timer.h.svn-base @@ -0,0 +1,55 @@ +#ifndef _ddekit_timer_h +#define _ddekit_timer_h + +#include <l4/dde/ddekit/thread.h> + +enum +{ + DDEKIT_INVALID_TIMER_ID = -1, +}; + +/** \defgroup DDEKit_timer + * + * Timer subsystem + * + * DDEKit provides a generic timer implementation that enables users + * to execute a function with some arguments after a certain period + * of time. DDEKit therefore starts a timer thread that executes these + * functions and keeps track of the currently running timers. + */ + +/** Add a timer event. After the absolute timeout has expired, function fn + * is called with args as arguments. + * + * \ingroup DDEKit_timer + * + * \return >=0 valid timer ID + * \return < 0 error + */ +int ddekit_add_timer(void (*fn)(void *), void *args, unsigned long timeout); + +/** Delete timer with the corresponding timer id. + * + * \ingroup DDEKit_timer + */ +int ddekit_del_timer(int timer); + +/** Check whether a timer is pending + * + * \ingroup DDEKit_timer + * + * Linux needs this. + */ +int ddekit_timer_pending(int timer); + +/** Initialization function, startup timer thread + * + * \ingroup DDEKit_timer + */ +void ddekit_init_timers(void); + +/** Get the timer thread. + */ +ddekit_thread_t *ddekit_get_timer_thread(void); + +#endif diff --git a/libddekit/include/ddekit/.svn/text-base/types.h.svn-base b/libddekit/include/ddekit/.svn/text-base/types.h.svn-base new file mode 100644 index 00000000..83d92c65 --- /dev/null +++ b/libddekit/include/ddekit/.svn/text-base/types.h.svn-base @@ -0,0 +1,22 @@ +/* + * \brief Types for ddekit (x86 version) + * \author Thomas Friebel <tf13@os.inf.tu-dresden.de> + * \author Christian Helmuth <ch12@os.inf.tu-dresden.de> + * \date 2006-11-09 + * + * FIXME This is definitely arch-dependent! Move to ARCH-something + */ + +#ifndef _DDEKIT_TYPES_H +#define _DDEKIT_TYPES_H + +typedef signed char ddekit_int8_t; +typedef unsigned char ddekit_uint8_t; +typedef signed short int ddekit_int16_t; +typedef unsigned short int ddekit_uint16_t; +typedef signed int ddekit_int32_t; +typedef unsigned int ddekit_uint32_t; + +typedef unsigned long ddekit_addr_t; + +#endif diff --git a/libddekit/include/ddekit/assert.h b/libddekit/include/ddekit/assert.h new file mode 100644 index 00000000..5d572b49 --- /dev/null +++ b/libddekit/include/ddekit/assert.h @@ -0,0 +1,23 @@ +#ifndef _ddekit_assert_h +#define _ddekit_assert_h + +#include <l4/dde/ddekit/printf.h> +#include <l4/dde/ddekit/panic.h> + +/** \file ddekit/assert.h */ + +/** Assert that an expression is true and panic if not. + * \ingroup DDEKit_util + */ +#define Assert(expr) do \ + { \ + if (!(expr)) { \ + ddekit_print("\033[31;1mDDE: Assertion failed: "#expr"\033[0m\n"); \ + ddekit_printf(" File: %s:%d\n",__FILE__,__LINE__); \ + ddekit_printf(" Function: %s()\n", __FUNCTION__); \ + ddekit_panic("Assertion failed."); \ + }} while (0); + +#endif + +#define assert Assert diff --git a/libddekit/include/ddekit/condvar.h b/libddekit/include/ddekit/condvar.h new file mode 100644 index 00000000..b6dc4bd3 --- /dev/null +++ b/libddekit/include/ddekit/condvar.h @@ -0,0 +1,54 @@ +#ifndef _ddekit_condvar_h +#define _ddekit_condvar_h + +/** \file ddekit/condvar.h */ + +#include <l4/dde/ddekit/lock.h> + +struct ddekit_condvar; +typedef struct ddekit_condvar ddekit_condvar_t; + +/** Initialize conditional variable. + * + * \ingroup DDEKit_synchronization + */ +ddekit_condvar_t * ddekit_condvar_init(void); + +/** Uninitialize conditional variable. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_condvar_deinit(ddekit_condvar_t *cvp); + +/** Wait on a conditional variable. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_condvar_wait(ddekit_condvar_t *cvp, ddekit_lock_t *mp); + +/** Wait on a conditional variable at most until a timeout expires. + * + * \ingroup DDEKit_synchronization + * + * \param cvp pointer to condvar + * \param mp lock + * \param timo timeout in ms + * + * \return 0 success + * \return !=0 timeout + */ +int ddekit_condvar_wait_timed(ddekit_condvar_t *cvp, ddekit_lock_t *mp, int timo); + +/** Send signal to the next one waiting for condvar. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_condvar_signal(ddekit_condvar_t *cvp); + +/** Send signal to all threads waiting for condvar. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_condvar_broadcast(ddekit_condvar_t *cvp); + +#endif diff --git a/libddekit/include/ddekit/debug.h b/libddekit/include/ddekit/debug.h new file mode 100644 index 00000000..79a8e7b5 --- /dev/null +++ b/libddekit/include/ddekit/debug.h @@ -0,0 +1,8 @@ +#define DDEBUG_QUIET 0 +#define DDEBUG_ERR 1 +#define DDEBUG_WARN 2 +#define DDEBUG_INFO 3 +#define DDEBUG_VERBOSE 4 + +#define DDEBUG_MEM DDEBUG_INFO + diff --git a/libddekit/include/ddekit/initcall.h b/libddekit/include/ddekit/initcall.h new file mode 100644 index 00000000..b503cc6a --- /dev/null +++ b/libddekit/include/ddekit/initcall.h @@ -0,0 +1,42 @@ +#ifndef _ddekit_initcall_h +#define _ddekit_initcall_h + +// from l4/sys/compiler.h +#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4 +#define L4_STICKY(x) __attribute__((used)) x +#else +#define L4_STICKY(x) __attribute__((unused)) x +#endif + +#define l4str(s) #s + +// from dde_linux/ARCH-x86/ctor.h +typedef void (*l4ddekit_initcall_t)(void); + +#define __l4ddekit_initcall(p) \ + __attribute__ ((__section__ (".l4dde_ctors." #p))) + +/** Define a function to be a DDEKit initcall. + * + * Define a function to be a DDEKit initcall. This function will then be placed + * in a separate linker section of the binary (called .l4dde_ctors). The L4Env + * construction mechanism will execute all constructors in this section during + * application startup. + * + * This is the right place to place Linux' module_init functions & Co. + * + * \param fn function + */ +#define DDEKIT_INITCALL(fn) DDEKIT_CTOR(fn, 1) + +#define DDEKIT_CTOR(fn, prio) \ + static l4ddekit_initcall_t \ + L4_STICKY(__l4ddekit_initcall_##fn) \ + __l4ddekit_initcall(prio) = (void *)fn + +/** + * Runs all registered initcalls. + */ +void ddekit_do_initcalls(void); + +#endif diff --git a/libddekit/include/ddekit/inline.h b/libddekit/include/ddekit/inline.h new file mode 100644 index 00000000..e59a5c68 --- /dev/null +++ b/libddekit/include/ddekit/inline.h @@ -0,0 +1,2 @@ +#define INLINE __inline__ __attribute__((always_inline)) + diff --git a/libddekit/include/ddekit/interrupt.h b/libddekit/include/ddekit/interrupt.h new file mode 100644 index 00000000..bbabedb2 --- /dev/null +++ b/libddekit/include/ddekit/interrupt.h @@ -0,0 +1,57 @@ +/* + * \brief Hardware-interrupt subsystem + * \author Thomas Friebel <tf13@os.inf.tu-dresden.de> + * \author Christian Helmuth <ch12@os.inf.tu-dresden.de> + * \date 2007-01-26 + * + * DDEKit supports registration of one handler function per interrupt. If any + * specific DDE implementation needs to register more than one handler, + * multiplexing has to be implemented there! + */ + +#ifndef _ddekit_interrupt_h +#define _ddekit_interrupt_h + +#include <l4/dde/ddekit/thread.h> + +#define DDEKIT_IRQ_PRIO 0x11 + +/** + * Attach to hardware interrupt + * + * \param irq IRQ number to attach to + * \param shared set to 1 if interrupt sharing is supported; set to 0 + * otherwise + * \param thread_init called just after DDEKit internal init and before any + * other function + * \param handler IRQ handler for interrupt irq + * \param priv private token (argument for thread_init and handler) + * + * \return pointer to interrupt thread created + */ +ddekit_thread_t *ddekit_interrupt_attach(int irq, int shared, + void(*thread_init)(void *), + void(*handler)(void *), void *priv); + +/** + * Detach from a previously attached interrupt. + * + * \param irq IRQ number + */ +void ddekit_interrupt_detach(int irq); + +/** + * Block interrupt. + * + * \param irq IRQ number to block + */ +void ddekit_interrupt_disable(int irq); + +/** + * Enable interrupt. + * + * \param irq IRQ number to block + */ +void ddekit_interrupt_enable(int irq); + +#endif diff --git a/libddekit/include/ddekit/lock.h b/libddekit/include/ddekit/lock.h new file mode 100644 index 00000000..872acad0 --- /dev/null +++ b/libddekit/include/ddekit/lock.h @@ -0,0 +1,83 @@ +#ifndef _ddekit_lock_h +#define _ddekit_lock_h + +struct ddekit_lock; + +/** Initialize a DDEKit lock. + * + * \ingroup DDEKit_synchronization + */ +void _ddekit_lock_init (struct ddekit_lock **mtx); + +/** Uninitialize a DDEKit lock. + * + * \ingroup DDEKit_synchronization + */ +void _ddekit_lock_deinit (struct ddekit_lock **mtx); + +/** Acquire a lock. + * + * \ingroup DDEKit_synchronization + */ +void _ddekit_lock_lock (struct ddekit_lock **mtx); + +/** Acquire a lock, non-blocking. + * + * \ingroup DDEKit_synchronization + */ +int _ddekit_lock_try_lock(struct ddekit_lock **mtx); + +/** Unlock function. + * + * \ingroup DDEKit_synchronization + */ +void _ddekit_lock_unlock (struct ddekit_lock **mtx); + +/** Get lock owner. + * + * \ingroup DDEKit_synchronization + */ +int _ddekit_lock_owner(struct ddekit_lock **mtx); + +// definition of ddekit_lock_t +typedef struct ddekit_lock *ddekit_lock_t; + +// common prototypes +static void ddekit_lock_init_locked(ddekit_lock_t *mtx); +static void ddekit_lock_init_unlocked(ddekit_lock_t *mtx); +#define ddekit_lock_init ddekit_lock_init_unlocked +static void ddekit_lock_deinit (ddekit_lock_t *mtx); +static void ddekit_lock_lock (ddekit_lock_t *mtx); +static int ddekit_lock_try_lock(ddekit_lock_t *mtx); // returns 0 on success, != 0 if it would block +static void ddekit_lock_unlock (ddekit_lock_t *mtx); + +// inline implementation or inline call to non-inline implementation +#include <l4/dde/ddekit/inline.h> + +static INLINE void ddekit_lock_init_unlocked(ddekit_lock_t *mtx) { + _ddekit_lock_init(mtx); +} + +static INLINE void ddekit_lock_init_locked(ddekit_lock_t *mtx) { + _ddekit_lock_init(mtx); + _ddekit_lock_lock(mtx); +} + +static INLINE void ddekit_lock_deinit(ddekit_lock_t *mtx) { + _ddekit_lock_deinit(mtx); +} +static INLINE void ddekit_lock_lock(ddekit_lock_t *mtx) { + _ddekit_lock_lock(mtx); +} +static INLINE int ddekit_lock_try_lock(ddekit_lock_t *mtx) { + return _ddekit_lock_try_lock(mtx); +} +static INLINE void ddekit_lock_unlock(ddekit_lock_t *mtx) { + _ddekit_lock_unlock(mtx); +} + +static INLINE int ddekit_lock_owner(ddekit_lock_t *mtx) { + return _ddekit_lock_owner(mtx); +} + +#endif diff --git a/libddekit/include/ddekit/memory.h b/libddekit/include/ddekit/memory.h new file mode 100644 index 00000000..051a4d9e --- /dev/null +++ b/libddekit/include/ddekit/memory.h @@ -0,0 +1,144 @@ +/* + * \brief Memory subsystem + * \author Thomas Friebel <tf13@os.inf.tu-dresden.de> + * \author Christian Helmuth <ch12@os.inf.tu-dresden.de> + * \date 2006-11-03 + */ + +#ifndef _ddekit_memory_h +#define _ddekit_memory_h + + +/******************* + ** Slab facility ** + *******************/ + +struct ddekit_slab; + +/** + * Store user pointer in slab cache + * + * \param slab pointer to slab cache + * \param data user pointer + */ +void ddekit_slab_set_data(struct ddekit_slab * slab, void *data); + +/** + * Read user pointer from slab cache + * + * \param slab pointer to slab cache + * + * \return stored user pointer or 0 + */ +void *ddekit_slab_get_data(struct ddekit_slab * slab); + +/** + * Allocate slab in slab cache + * + * \param slab pointer to slab cache + * + * \return pointer to allocated slab + */ +void *ddekit_slab_alloc(struct ddekit_slab * slab); + +/** + * Deallocate slab in slab cache + * + * \param slab pointer to slab cache + * \param objp pointer to allocated slab + */ +void ddekit_slab_free(struct ddekit_slab * slab, void *objp); + +/** + * Setup page cache for all slabs + * + * \param pages maximal number of memory pages + * + * If 'pages' is too low, memory pages may be given back to the memory server + * (dm_phys) and just to be allocated again later. This hits performance (but + * saves memory). Increase 'pages' to avoid this thrashing-like effect. + * + * If the maximal number of unused pages is exceeded, subsequent deallocation + * will be freed at the memory server. This page cache caches pages from all + * slabs. + */ +void ddekit_slab_setup_page_cache(unsigned pages); + +/** + * Destroy slab cache + * + * \param slab pointer to slab cache structure + */ +void ddekit_slab_destroy(struct ddekit_slab * slab); + +/** + * Initialize slab cache + * + * \param size size of cache objects + * \param contiguous make this slab use physically contiguous memory + * + * \return pointer to new slab cache or 0 on error + */ +struct ddekit_slab * ddekit_slab_init(unsigned size, int contiguous); + + +/********************** + ** Memory allocator ** + **********************/ + +/** + * Allocate large memory block + * + * \param size block size + * \return pointer to new memory block + * + * Allocations via this allocator may be slow (because memory servers are + * involved) and should be used only for large (i.e., > page size) blocks. If + * allocations/deallocations are relatively dynamic this may not be what you + * want. + * + * Allocated blocks have valid virt->phys mappings and are physically + * contiguous. + */ +void *ddekit_large_malloc(int size); + +/** + * Free large memory block + * + * \param p pointer to memory block + */ +void ddekit_large_free(void *p); + +/** FIXME + * contig_malloc() is the lowest-level allocator interface one could implement. + * we should consider to provide vmalloc() too. */ +void *ddekit_contig_malloc( + unsigned long size, + unsigned long low, unsigned long high, + unsigned long alignment, unsigned long boundary +); + + +/***************************** + ** Simple memory allocator ** + *****************************/ + +/** + * Allocate memory block via simple allocator + * + * \param size block size + * \return pointer to new memory block + * + * The blocks allocated via this allocator CANNOT be used for DMA or other + * device operations, i.e., there exists no virt->phys mapping. + */ +void *ddekit_simple_malloc(unsigned size); + +/** + * Free memory block via simple allocator + * + * \param p pointer to memory block + */ +void ddekit_simple_free(void *p); + +#endif diff --git a/libddekit/include/ddekit/panic.h b/libddekit/include/ddekit/panic.h new file mode 100644 index 00000000..1468675f --- /dev/null +++ b/libddekit/include/ddekit/panic.h @@ -0,0 +1,16 @@ +#ifndef _ddekit_panic_h +#define _ddekit_panic_h + +/** \defgroup DDEKit_util */ + +/** Panic - print error message and enter the kernel debugger. + * \ingroup DDEKit_util + */ +void ddekit_panic(char *fmt, ...) __attribute__((noreturn)); + +/** Print a debug message. + * \ingroup DDEKit_util + */ +void ddekit_debug(char *fmt, ...); + +#endif diff --git a/libddekit/include/ddekit/pci.h b/libddekit/include/ddekit/pci.h new file mode 100644 index 00000000..9ec7cd4f --- /dev/null +++ b/libddekit/include/ddekit/pci.h @@ -0,0 +1,199 @@ +#ifndef _ddekit_pci_h +#define _ddekit_pci_h + +#include <l4/dde/ddekit/types.h> + +/** \defgroup DDEKit_pci */ + +/** Our version of PCI_ANY_ID */ +#define DDEKIT_PCI_ANY_ID (~0) + +/** Copy of L4IO_PCIDEV_RES */ +#define DDEKIT_PCIDEV_RES 12 + +struct ddekit_pci_dev; + +/** PCI resource descriptor. Copied from generic_io. + * + * XXX! + */ +typedef struct ddekit_pci_resource { + unsigned long start; + unsigned long end; + unsigned long flags; +} ddekit_pci_res_t; + +void ddekit_pci_init(void); + +int ddekit_pci_get_device(int nr, int *bus, int *slot, int *func); + +int ddekit_pci_read(int bus, int slot, int func, int pos, int len, ddekit_uint32_t *val); +int ddekit_pci_write(int bus, int slot, int func, int pos, int len, ddekit_uint32_t val); + +/** Read byte from PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val read value + * + * \return 0 success + */ +int ddekit_pci_readb (int bus, int slot, int func, int pos, ddekit_uint8_t *val); + +/** Read word from PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val read value + * + * \return 0 success + */ +int ddekit_pci_readw (int bus, int slot, int func, int pos, ddekit_uint16_t *val); + +/** Read dword from PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val read value + * + * \return 0 success + */ +int ddekit_pci_readl (int bus, int slot, int func, int pos, ddekit_uint32_t *val); + +/** Write byte to PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val value to write + * + * \return 0 success + */ +int ddekit_pci_writeb(int bus, int slot, int func, int pos, ddekit_uint8_t val); + +/** Write word to PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val value to write + * + * \return 0 success + */ +int ddekit_pci_writew(int bus, int slot, int func, int pos, ddekit_uint16_t val); + +/** Write word to PCI config space. + * + * \ingroup DDEKit_pci + * + * \param bus bus ID + * \param slot slot # + * \param func function # + * \param pos offset in config space + * \retval val value to write + * + * \return 0 success + */ +int ddekit_pci_writel(int bus, int slot, int func, int pos, ddekit_uint32_t val); + +/** Find a PCI device. + * + * \ingroup DDEKit_pci + * + * \param bus pointer to bus number or \ref DDEKIT_PCI_ANY_ID + * \param slot pointer to slot number (devfn >> DEVFN_SLOTSHIFT) or \ref DDEKIT_PCI_ANY_ID + * \param func pointer to func number (devfc & DEVFN_FUNCMASK) or \ref DDEKIT_PCI_ANY_ID + * \param start search device list only behind this device (excluding it!), NULL + * searches whole device list + * + * \retval bus bus number + * \retval slot slot number + * \retval func function number + * + * \return device a valid PCI device + * \return NULL if no device found + */ +struct ddekit_pci_dev * +ddekit_pci_find_device(int *bus, int *slot, int *func, struct ddekit_pci_dev *start); + +/** Enable PCI device + * \ingroup DDEKit_pci + */ +int ddekit_pci_enable_device(struct ddekit_pci_dev *dev); + +/** Disable PCI device + * \ingroup DDEKit_pci + */ +int ddekit_pci_disable_device(struct ddekit_pci_dev *dev); + +/** Enable bus-mastering for device. + * \ingroup DDEKit_pci + */ +void ddekit_pci_set_master(struct ddekit_pci_dev *dev); + +/** Get device vendor ID. + * \ingroup DDEKit_pci + */ +unsigned short ddekit_pci_get_vendor(struct ddekit_pci_dev *dev); + +/** Get device ID. + * \ingroup DDEKit_pci + */ +unsigned short ddekit_pci_get_device_id(struct ddekit_pci_dev *dev); + +/** Get device subvendor ID. + * \ingroup DDEKit_pci + */ +unsigned short ddekit_pci_get_sub_vendor(struct ddekit_pci_dev *dev); + +/** Get subdevice ID. + * \ingroup DDEKit_pci + */ +unsigned short ddekit_pci_get_sub_device(struct ddekit_pci_dev *dev); + +/** Get device class ID. + * \ingroup DDEKit_pci + */ +unsigned ddekit_pci_get_dev_class(struct ddekit_pci_dev *dev); + +/** Get device's IRQ number. + * \ingroup DDEKit_pci + */ +unsigned long ddekit_pci_get_irq(struct ddekit_pci_dev *dev); + +/** Get device name. + * \ingroup DDEKit_pci + */ +char *ddekit_pci_get_name(struct ddekit_pci_dev *dev); + +/** Get device's slot name. + * \ingroup DDEKit_pci + */ +char *ddekit_pci_get_slot_name(struct ddekit_pci_dev *dev); + +/** Get one of the device's resources. + * \ingroup DDEKit_pci + */ +ddekit_pci_res_t *ddekit_pci_get_resource(struct ddekit_pci_dev *dev, unsigned int idx); + +int ddekit_pci_irq_enable(int bus, int slot, int func, int pin, int *irq); + +#endif // _ddekit_pci_h diff --git a/libddekit/include/ddekit/pgtab.h b/libddekit/include/ddekit/pgtab.h new file mode 100644 index 00000000..3b68192c --- /dev/null +++ b/libddekit/include/ddekit/pgtab.h @@ -0,0 +1,86 @@ +/* + * \brief Virtual page-table facility + * \author Thomas Friebel <tf13@os.inf.tu-dresden.de> + * \author Christian Helmuth <ch12@os.inf.tu-dresden.de> + * \date 2006-11-03 + */ + +#ifndef _ddekit_pgtab_h +#define _ddekit_pgtab_h + +#include <l4/dde/ddekit/types.h> + +/* FIXME Region types may be defined by pgtab users. Do we really need them + * here? */ +enum ddekit_pgtab_type +{ + PTE_TYPE_OTHER, PTE_TYPE_LARGE, PTE_TYPE_UMA, PTE_TYPE_CONTIG +}; + + +/** + * Set virtual->physical mapping for VM region + * + * \param virt virtual start address for region + * \param phys physical start address for region + * \param pages number of pages in region + * \param type pgtab type for region + */ +void ddekit_pgtab_set_region(void *virt, ddekit_addr_t phys, int pages, int type); + + +/** + * Set virtual->physical mapping for VM region given a specific size in bytes. + * + * Internally, DDEKit manages regions with pages. However, DDEs do not need to tangle + * with the underlying mechanism and therefore can use this function that takes care + * of translating a size to an amount of pages. + */ +void ddekit_pgtab_set_region_with_size(void *virt, ddekit_addr_t phys, int size, int type); + + +/** + * Clear virtual->physical mapping for VM region + * + * \param virt virtual start address for region + * \param type pgtab type for region + */ +void ddekit_pgtab_clear_region(void *virt, int type); + +/** + * Get physical address for virtual address + * + * \param virt virtual address + * + * \return physical address + */ +ddekit_addr_t ddekit_pgtab_get_physaddr(const void *virt); + +/** + * Get virtual address for physical address + * + * \param physical physical address + * + * \return virtual address + */ +ddekit_addr_t ddekit_pgtab_get_virtaddr(const ddekit_addr_t physical); + +/** + * Get type of VM region. + * + * \param virt virtual address + + * \return VM region type + */ +int ddekit_pgtab_get_type(const void *virt); + +/** + * Get size of VM region. + * + * \param virt virtual address + * + * \return VM region size (in bytes) + */ +int ddekit_pgtab_get_size(const void *virt); + +#endif diff --git a/libddekit/include/ddekit/printf.h b/libddekit/include/ddekit/printf.h new file mode 100644 index 00000000..35b0dfa1 --- /dev/null +++ b/libddekit/include/ddekit/printf.h @@ -0,0 +1,33 @@ +#ifndef _ddekit_print_h +#define _ddekit_print_h + +#include <stdarg.h> + +/** Print message. + * \ingroup DDEKit_util + */ +int ddekit_print(const char *); + +/** Print message with format. + * \ingroup DDEKit_util + */ +int ddekit_printf(const char *fmt, ...); + +/** Print message with format list. + * \ingroup DDEKit_util + */ +int ddekit_vprintf(const char *fmt, va_list va); + +/** Log function and message. + * \ingroup DDEKit_util + */ +#define ddekit_log(doit, msg...) \ + do { \ + if (doit) { \ + ddekit_printf("%s(): ", __func__); \ + ddekit_printf(msg); \ + ddekit_printf("\n"); \ + } \ + } while(0); + +#endif diff --git a/libddekit/include/ddekit/resources.h b/libddekit/include/ddekit/resources.h new file mode 100644 index 00000000..e0fa68f0 --- /dev/null +++ b/libddekit/include/ddekit/resources.h @@ -0,0 +1,13 @@ +#ifndef _ddekit_resources_h +#define _ddekit_resources_h + +#include <l4/dde/ddekit/types.h> + +int ddekit_request_dma(int nr); +int ddekit_release_dma(int nr); +int ddekit_request_io (ddekit_addr_t start, ddekit_addr_t count); +int ddekit_release_io (ddekit_addr_t start, ddekit_addr_t count); +int ddekit_request_mem(ddekit_addr_t start, ddekit_addr_t count, ddekit_addr_t *vaddr); +int ddekit_release_mem(ddekit_addr_t start, ddekit_addr_t count); + +#endif diff --git a/libddekit/include/ddekit/semaphore.h b/libddekit/include/ddekit/semaphore.h new file mode 100644 index 00000000..c959919d --- /dev/null +++ b/libddekit/include/ddekit/semaphore.h @@ -0,0 +1,50 @@ +#ifndef _ddekit_semaphore_h +#define _ddekit_semaphore_h + +/** \defgroup DDEKit_synchronization */ + +struct ddekit_sem; +typedef struct ddekit_sem ddekit_sem_t; + +/** Initialize DDEKit semaphore. + * + * \ingroup DDEKit_synchronization + * + * \param value initial semaphore counter + */ +ddekit_sem_t *ddekit_sem_init(int value); + +/** Uninitialize semaphore. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_sem_deinit(ddekit_sem_t *sem); + +/** Semaphore down method. */ +void ddekit_sem_down(ddekit_sem_t *sem); + +/** Semaphore down method, non-blocking. + * + * \ingroup DDEKit_synchronization + * + * \return 0 success + * \return !=0 would block + */ +int ddekit_sem_down_try(ddekit_sem_t *sem); + +/** Semaphore down with timeout. + * + * \ingroup DDEKit_synchronization + * + * \return 0 success + * \return !=0 would block + */ +int ddekit_sem_down_timed(ddekit_sem_t *sem, int timo); + +/** Semaphore up method. + * + * \ingroup DDEKit_synchronization + */ +void ddekit_sem_up(ddekit_sem_t *sem); + +#endif diff --git a/libddekit/include/ddekit/thread.h b/libddekit/include/ddekit/thread.h new file mode 100644 index 00000000..ecd399d9 --- /dev/null +++ b/libddekit/include/ddekit/thread.h @@ -0,0 +1,162 @@ +#ifndef _ddekit_thread_h +#define _ddekit_thread_h + +/** \defgroup DDEKit_threads */ + +#include <l4/dde/ddekit/lock.h> + +struct ddekit_thread; +typedef struct ddekit_thread ddekit_thread_t; + +/** Create thread + * + * \ingroup DDEKit_threads + * + * Create a new thread running the specified thread function with the specified + * arguments. The thread is assigned the given internal name. + * + * Additionally, DDEKit threads possess a thread-local storage area where they + * may store arbitrary data. + * + * \param fun thread function + * \param arg optional argument to thread function, set to NULL if not needed + * \param name internal thread name + */ +ddekit_thread_t *ddekit_thread_create(void (*fun)(void *), void *arg, const char *name); + +/** Reference to own DDEKit thread id. + * + * \ingroup DDEKit_threads + */ +ddekit_thread_t *ddekit_thread_myself(void); + +/** Initialize thread with given name. + * + * \ingroup DDEKit_threads + * + * This function may be used by threads that were not created using + * \ref ddekit_thread_create. This enables such threads to be handled as if they + * were DDEKit threads. + */ +ddekit_thread_t *ddekit_thread_setup_myself(const char *name); + +/** Get TLS data for a specific thread. + * + * \ingroup DDEKit_threads + * + * \return Pointer to TLS data of this thread. + */ +void *ddekit_thread_get_data(ddekit_thread_t *thread); + +/** Get TLS data for current thread. + * + * \ingroup DDEKit_threads + * + * Same as calling \ref ddekit_thread_get_data with \ref ddekit_thread_myself + * as parameter. + * + * \return Pointer to TLS data of current thread. + */ +void *ddekit_thread_get_my_data(void); + +/** Set TLS data for specific thread. + * + * \ingroup DDEKit_threads + * + * \param thread DDEKit thread + * \param data pointer to thread data + */ +void ddekit_thread_set_data(ddekit_thread_t *thread, void *data); + +/** Set TLS data for current thread. + * + * \ingroup DDEKit_threads + * + * \param data pointer to thread data + */ +void ddekit_thread_set_my_data(void *data); + +/** Sleep for some miliseconds. + * + * \ingroup DDEKit_threads + * + * \param msecs time to sleep in ms. + */ +void ddekit_thread_msleep(unsigned long msecs); + +/** Sleep for some microseconds. + * + * \ingroup DDEKit_threads + * + * \param usecs time to sleep in µs. + */ +void ddekit_thread_usleep(unsigned long usecs); + +/** Sleep for some nanoseconds. + * + * \ingroup DDEKit_threads + * + * \param usecs time to sleep in ns. + */ +void ddekit_thread_nsleep(unsigned long nsecs); + +/** Sleep until a lock becomes unlocked. + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_sleep(ddekit_lock_t *lock); + +/** Wakeup a waiting thread. + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_wakeup(ddekit_thread_t *thread); + +/** Terminate a thread + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_exit(void) __attribute__((noreturn)); + +/** Terminate a thread + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_terminate(ddekit_thread_t *thread); + +/** Get the name, a thread registered with DDEKit. + * + * \ingroup DDEKit_threads + */ +const char *ddekit_thread_get_name(ddekit_thread_t *thread); + +/** Get unique ID of a DDEKit thread. + * + * \ingroup DDEKit_threads + * + * DDEKit does not allow direct access to the thread data + * structure, since this struct contains L4-specific data types. + * However, applications might want to get some kind of ID related + * to a ddekit_thread, for instance to use it as a Linux-like PID. + */ +int ddekit_thread_get_id(ddekit_thread_t *thread); + +/** Hint that this thread is done and may be scheduled somehow. + * + * \ingroup DDEKit_threads + */ +void ddekit_thread_schedule(void); + +/** Hint that this thread is done and may be scheduled somehow. + * + * \ingroup DDEKit_threads + */ +void ddekit_yield(void); + +/** Initialize DDEKit thread subsystem. + * + * \ingroup DDEKit_threads + */ +void ddekit_init_threads(void); + +#endif diff --git a/libddekit/include/ddekit/timer.h b/libddekit/include/ddekit/timer.h new file mode 100644 index 00000000..c352475c --- /dev/null +++ b/libddekit/include/ddekit/timer.h @@ -0,0 +1,55 @@ +#ifndef _ddekit_timer_h +#define _ddekit_timer_h + +#include <l4/dde/ddekit/thread.h> + +enum +{ + DDEKIT_INVALID_TIMER_ID = -1, +}; + +/** \defgroup DDEKit_timer + * + * Timer subsystem + * + * DDEKit provides a generic timer implementation that enables users + * to execute a function with some arguments after a certain period + * of time. DDEKit therefore starts a timer thread that executes these + * functions and keeps track of the currently running timers. + */ + +/** Add a timer event. After the absolute timeout has expired, function fn + * is called with args as arguments. + * + * \ingroup DDEKit_timer + * + * \return >=0 valid timer ID + * \return < 0 error + */ +int ddekit_add_timer(void (*fn)(void *), void *args, unsigned long timeout); + +/** Delete timer with the corresponding timer id. + * + * \ingroup DDEKit_timer + */ +int ddekit_del_timer(int timer); + +/** Check whether a timer is pending + * + * \ingroup DDEKit_timer + * + * Linux needs this. + */ +int ddekit_timer_pending(int timer); + +/** Initialization function, startup timer thread + * + * \ingroup DDEKit_timer + */ +void ddekit_init_timers(void); + +/** Get the timer thread. + */ +ddekit_thread_t *ddekit_get_timer_thread(void); + +#endif diff --git a/libddekit/include/ddekit/types.h b/libddekit/include/ddekit/types.h new file mode 100644 index 00000000..83d92c65 --- /dev/null +++ b/libddekit/include/ddekit/types.h @@ -0,0 +1,22 @@ +/* + * \brief Types for ddekit (x86 version) + * \author Thomas Friebel <tf13@os.inf.tu-dresden.de> + * \author Christian Helmuth <ch12@os.inf.tu-dresden.de> + * \date 2006-11-09 + * + * FIXME This is definitely arch-dependent! Move to ARCH-something + */ + +#ifndef _DDEKIT_TYPES_H +#define _DDEKIT_TYPES_H + +typedef signed char ddekit_int8_t; +typedef unsigned char ddekit_uint8_t; +typedef signed short int ddekit_int16_t; +typedef unsigned short int ddekit_uint16_t; +typedef signed int ddekit_int32_t; +typedef unsigned int ddekit_uint32_t; + +typedef unsigned long ddekit_addr_t; + +#endif |