summaryrefslogtreecommitdiff
path: root/libddekit/ddekit
diff options
context:
space:
mode:
Diffstat (limited to 'libddekit/ddekit')
-rw-r--r--libddekit/ddekit/assert.h23
-rw-r--r--libddekit/ddekit/condvar.h53
-rw-r--r--libddekit/ddekit/debug.h8
-rw-r--r--libddekit/ddekit/initcall.h42
-rw-r--r--libddekit/ddekit/inline.h2
-rw-r--r--libddekit/ddekit/interrupt.h57
-rw-r--r--libddekit/ddekit/lock.h83
-rw-r--r--libddekit/ddekit/memory.h144
-rw-r--r--libddekit/ddekit/panic.h16
-rw-r--r--libddekit/ddekit/pci.h199
-rw-r--r--libddekit/ddekit/pgtab.h86
-rw-r--r--libddekit/ddekit/printf.h35
-rw-r--r--libddekit/ddekit/resources.h14
-rw-r--r--libddekit/ddekit/semaphore.h50
-rw-r--r--libddekit/ddekit/thread.h145
-rw-r--r--libddekit/ddekit/timer.h59
-rw-r--r--libddekit/ddekit/types.h22
17 files changed, 1038 insertions, 0 deletions
diff --git a/libddekit/ddekit/assert.h b/libddekit/ddekit/assert.h
new file mode 100644
index 00000000..5d593662
--- /dev/null
+++ b/libddekit/ddekit/assert.h
@@ -0,0 +1,23 @@
+#ifndef _ddekit_assert_h
+#define _ddekit_assert_h
+
+#include "ddekit/printf.h"
+#include "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/ddekit/condvar.h b/libddekit/ddekit/condvar.h
new file mode 100644
index 00000000..129a718d
--- /dev/null
+++ b/libddekit/ddekit/condvar.h
@@ -0,0 +1,53 @@
+#ifndef _ddekit_condvar_h
+#define _ddekit_condvar_h
+
+/** \file ddekit/condvar.h */
+#include "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/ddekit/debug.h b/libddekit/ddekit/debug.h
new file mode 100644
index 00000000..79a8e7b5
--- /dev/null
+++ b/libddekit/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/ddekit/initcall.h b/libddekit/ddekit/initcall.h
new file mode 100644
index 00000000..6befa31c
--- /dev/null
+++ b/libddekit/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) \
+ 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/ddekit/inline.h b/libddekit/ddekit/inline.h
new file mode 100644
index 00000000..e59a5c68
--- /dev/null
+++ b/libddekit/ddekit/inline.h
@@ -0,0 +1,2 @@
+#define INLINE __inline__ __attribute__((always_inline))
+
diff --git a/libddekit/ddekit/interrupt.h b/libddekit/ddekit/interrupt.h
new file mode 100644
index 00000000..3f789210
--- /dev/null
+++ b/libddekit/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 "ddekit/thread.h"
+
+#define DDEKIT_IRQ_PRIO 2
+
+/**
+ * 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/ddekit/lock.h b/libddekit/ddekit/lock.h
new file mode 100644
index 00000000..dd398b38
--- /dev/null
+++ b/libddekit/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 "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/ddekit/memory.h b/libddekit/ddekit/memory.h
new file mode 100644
index 00000000..051a4d9e
--- /dev/null
+++ b/libddekit/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/ddekit/panic.h b/libddekit/ddekit/panic.h
new file mode 100644
index 00000000..1468675f
--- /dev/null
+++ b/libddekit/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/ddekit/pci.h b/libddekit/ddekit/pci.h
new file mode 100644
index 00000000..5a5fd29b
--- /dev/null
+++ b/libddekit/ddekit/pci.h
@@ -0,0 +1,199 @@
+#ifndef _ddekit_pci_h
+#define _ddekit_pci_h
+
+#include "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/ddekit/pgtab.h b/libddekit/ddekit/pgtab.h
new file mode 100644
index 00000000..8964b713
--- /dev/null
+++ b/libddekit/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 "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/ddekit/printf.h b/libddekit/ddekit/printf.h
new file mode 100644
index 00000000..6dafa18d
--- /dev/null
+++ b/libddekit/ddekit/printf.h
@@ -0,0 +1,35 @@
+#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);
+
+void dump_stack(void);
+
+/** 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/ddekit/resources.h b/libddekit/ddekit/resources.h
new file mode 100644
index 00000000..657295a0
--- /dev/null
+++ b/libddekit/ddekit/resources.h
@@ -0,0 +1,14 @@
+#ifndef _ddekit_resources_h
+#define _ddekit_resources_h
+
+#include "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);
+long ddekit_random (void);
+
+#endif
diff --git a/libddekit/ddekit/semaphore.h b/libddekit/ddekit/semaphore.h
new file mode 100644
index 00000000..c959919d
--- /dev/null
+++ b/libddekit/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/ddekit/thread.h b/libddekit/ddekit/thread.h
new file mode 100644
index 00000000..8ed52013
--- /dev/null
+++ b/libddekit/ddekit/thread.h
@@ -0,0 +1,145 @@
+#ifndef _ddekit_thread_h
+#define _ddekit_thread_h
+
+/** \defgroup DDEKit_threads */
+
+#include "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));
+
+/** Get the name, a thread registered with DDEKit.
+ *
+ * \ingroup DDEKit_threads
+ */
+const char *ddekit_thread_get_name(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/ddekit/timer.h b/libddekit/ddekit/timer.h
new file mode 100644
index 00000000..387f2078
--- /dev/null
+++ b/libddekit/ddekit/timer.h
@@ -0,0 +1,59 @@
+#ifndef _ddekit_timer_h
+#define _ddekit_timer_h
+
+#include "ddekit/thread.h"
+
+#define jiffies (fetch_jiffies())
+#define HZ 100
+
+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);
+extern unsigned long fetch_jiffies (void);
+
+#endif
diff --git a/libddekit/ddekit/types.h b/libddekit/ddekit/types.h
new file mode 100644
index 00000000..83d92c65
--- /dev/null
+++ b/libddekit/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