Check-in older changes from FDIF conversion.
authorGerd Zellweger <mail@gerdzellweger.com>
Mon, 12 Jun 2017 11:44:17 +0000 (13:44 +0200)
committerGerd Zellweger <mail@gerdzellweger.com>
Wed, 14 Jun 2017 14:37:36 +0000 (16:37 +0200)
Signed-off-by: Gerd Zellweger <mail@gerdzellweger.com>

if/ddomain.if
include/driverkit/driverkit.h
lib/driverkit/ddomain_service.c
lib/driverkit/modules.c
platforms/Hakefile
usr/drivers/domain/drivertpl.c
usr/drivers/omap44xx/fdif/Hakefile
usr/drivers/omap44xx/fdif/fdif.c
usr/drivers/omap44xx/fdif/fdif_domain.c [new file with mode: 0644]

index 160b645..15274e6 100644 (file)
@@ -12,7 +12,9 @@ interface ddomain "Kaluga <-> Driver Domain Interface" {
     /**
      * Creates a new driver within the driver domain.
      */
-    message create(char cls[clen, 256], char name[nlen, 256], cap cap, uint64 flags);
+    message create(char cls[clen, 256], char name[nlen, 256],
+                   char a1[a1len, 256], char a2[a2len, 256], char a3[a3len, 256], char a4[a4len, 256], 
+                   cap cap1, cap cap2, cap cap3, cap cap4, uint64 flags);
     message create_response(iref devif, iref control, errval err);
 
     /**
index 4b69b40..1a42f8c 100644 (file)
@@ -25,7 +25,7 @@ struct bfdriver_instance {
     void* dstate; //< Driver state. This is owned by the driver implementation.
 };
 
-typedef errval_t(*driver_init_fn)(struct bfdriver_instance*, const char*, uint64_t flags, struct capref, iref_t*);
+typedef errval_t(*driver_init_fn)(struct bfdriver_instance*, const char*, uint64_t flags, struct capref*, size_t, char**, size_t, iref_t*);
 typedef errval_t(*driver_attach_fn)(struct bfdriver_instance*);
 typedef errval_t(*driver_detach_fn)(struct bfdriver_instance*);
 typedef errval_t(*driver_set_sleep_level_fn)(struct bfdriver_instance*, uint32_t level);
@@ -40,7 +40,7 @@ struct bfdriver {
     driver_destroy_fn destroy;
 };
 
-errval_t driverkit_create_driver(const char* cls, const char* name, struct capref caps, uint64_t flags, iref_t* dev, iref_t* ctrl);
+errval_t driverkit_create_driver(const char* cls, const char* name, struct capref* caps, size_t caps_len, char** args, size_t args_len, uint64_t flags, iref_t* dev, iref_t* ctrl);
 errval_t driverkit_destroy(const char* name);
 void driverkit_list(struct bfdriver**, size_t*);
 struct bfdriver* driverkit_lookup_cls(const char*);
index 6d1ecc2..f5cce51 100644 (file)
@@ -48,11 +48,28 @@ static struct bind_state {
  * \param flags   Flags for the driver instance.
  */
 static void create_handler(struct ddomain_binding* binding, const char* cls, size_t cls_len,
-                           const char* name, size_t nlen, struct capref cap, uint64_t flags) {
+                           const char* name, size_t nlen,
+                           const char* a1, size_t a1len, const char* a2, size_t a2len, const char* a3, size_t a3len, const char* a4, size_t a4len,
+                           struct capref cap1, struct capref cap2, struct capref cap3, struct capref cap4,
+                           uint64_t flags) {
     DRIVERKIT_DEBUG("Driver domain got create message from kaluga for %s\n", cls);
 
     iref_t dev = 0, ctrl = 0;
-    errval_t err = driverkit_create_driver(cls, name, cap, flags, &dev, &ctrl);
+
+    // This array is owned by the driver after create:
+    struct capref* cap_array = calloc(sizeof(struct capref), 4);
+    cap_array[0] = cap1;
+    cap_array[1] = cap2;
+    cap_array[2] = cap3;
+    cap_array[3] = cap4;
+
+    char** args_array = calloc(sizeof(char*), 4);
+    args_array[0] = a1 != NULL ? strdup(a1) : NULL;
+    args_array[1] = a2 != NULL ? strdup(a2) : NULL;
+    args_array[2] = a3 != NULL ? strdup(a3) : NULL;
+    args_array[3] = a4 != NULL ? strdup(a4) : NULL;
+
+    errval_t err = driverkit_create_driver(cls, name, cap_array, 4, args_array, 4, flags, &dev, &ctrl);
     if (err_is_fail(err)) {
         DEBUG_ERR(err, "Instantiating driver failed, report this back to Kaluga.");
     }
index c01705b..d3c63e8 100644 (file)
@@ -147,8 +147,9 @@ errval_t driverkit_destroy(const char* name) {
  * \return      Error status of driver creation.
  */
 errval_t driverkit_create_driver(const char* cls, const char* name,
-                                 struct capref caps, uint64_t flags,
-                                 iref_t* device, iref_t* control)
+                                 struct capref* caps, size_t caps_len,
+                                 char** args, size_t args_len,
+                                 uint64_t flags, iref_t* device, iref_t* control)
 {
     assert(cls != NULL);
     assert(name != NULL);
@@ -174,7 +175,7 @@ errval_t driverkit_create_driver(const char* cls, const char* name,
     }
     inst->driver = drv;
 
-    err = drv->init(inst, name, flags, caps, device);
+    err = drv->init(inst, name, flags, caps, caps_len, args, args_len, device);
     if (err_is_fail(err)) {
         DEBUG_ERR(err, "Can't initialize the device");
         free_driver_instance(inst);
index c4c5d77..ebc7857 100644 (file)
@@ -269,7 +269,8 @@ let bin_rcce_lu = [ "/sbin/" ++ f | f <- [
                         "serial_omap44xx",
                         "serial_kernel",
                         "angler",
-                        "corectrl"
+                        "corectrl",
+                        "fdif"
                         ] ]
 
     -- ARMv7-A modules for Versatile Express EMM board (GEM5, qemu)
index 667aff6..f90341e 100644 (file)
@@ -60,7 +60,8 @@ struct uart_driver_state {
  * \retval SYS_ERR_OK Device initialized successfully.
  * \retval LIB_ERR_MALLOC_FAIL Unable to allocate memory for the driver.
  */
-static errval_t init(struct bfdriver_instance* bfi, const char* name, uint64_t flags, struct capref c, iref_t* dev) {
+static errval_t init(struct bfdriver_instance* bfi, const char* name, uint64_t flags,
+                     struct capref* caps, size_t caps_len, char** args, size_t args_len, iref_t* dev) {
     DRIVER_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
 
     bfi->dstate = malloc(sizeof(struct uart_driver_state));
index dd2acc7..9ac4dac 100644 (file)
@@ -7,18 +7,26 @@
 -- ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
 --
 -- Hakefile for omap44xx fdif driver
--- 
+--
 --------------------------------------------------------------------------
 
 [
-    build application { target = "fdif",
-                    cFiles = (find withSuffices [".c"]),
-                    mackerelDevices = [
-                        "omap/omap44xx_cam_prm",
-                        "omap/omap44xx_cam_cm2",
-                        "omap/omap44xx_fdif",
-                        "omap/omap44xx_device_prm" ],
-                    addLibraries = ["driverkit"],
-                    architectures = ["armv7"]
-                  }
+  build library {
+    target = "fdif_module",
+    cFiles = [ "fdif.c", "picture.c"],
+    mackerelDevices = [
+        "omap/omap44xx_cam_prm",
+        "omap/omap44xx_cam_cm2",
+        "omap/omap44xx_fdif",
+        "omap/omap44xx_device_prm" ],
+    architectures = ["armv7"],
+    addLibraries = libDeps [ "driverkit" ]
+  },
+
+  build application {
+    target = "fdif",
+    cFiles = [ "fdif_domain.c"],
+    addModules = ["fdif_module"],
+    addLinkFlags = ["-T" ++ Config.source_dir ++ "/lib/driverkit/bfdrivers.ld" ]
+  }
 ]
index 556f811..26ce8d8 100644 (file)
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <barrelfish/barrelfish.h>
+#include <driverkit/driverkit.h>
+
 
 #include <barrelfish/barrelfish.h>
 #include <barrelfish/waitset.h>
 #include <dev/omap/omap44xx_fdif_dev.h>
 
 #define FDIF_IRQ (32+69)
-
 #define PRINT_BUFFER_SIZE (1024*1024)
-static char printbuf[PRINT_BUFFER_SIZE];
-
-static omap44xx_cam_prm_t dev;
-static omap44xx_fdif_t devfdif;
-static omap44xx_cam_cm2_t devclk;
 
 extern struct gimage lena_image;
 
-static void manage_clocks(void)
+struct fdif_driver_state {
+    uint32_t level;
+    omap44xx_cam_prm_t dev;
+    omap44xx_fdif_t devfdif;
+    omap44xx_cam_cm2_t devclk;
+    char printbuf[PRINT_BUFFER_SIZE];
+};
+
+static void manage_clocks(struct fdif_driver_state* st)
 {
     FDIF_DEBUG("Enable the clocks in domain CD_CAM\n");
 
@@ -47,17 +55,17 @@ static void manage_clocks(void)
     err = map_device_register(0x4A009000, 4096, &vbase);
     assert(err_is_ok(err));
 
-    omap44xx_cam_cm2_initialize(&devclk, (mackerel_addr_t)vbase);
-    //omap44xx_cam_cm2_cm_cam_staticdep_l3_1_statdep_wrf(&devclk, 0x1);
-    //omap44xx_cam_cm2_cm_cam_staticdep_memif_statdep_wrf(&devclk, 0x1);
-    //omap44xx_cam_cm2_cm_cam_staticdep_ivahd_statdep_wrf(&devclk, 0x1);
+    omap44xx_cam_cm2_initialize(&st->devclk, (mackerel_addr_t)vbase);
+    //omap44xx_cam_cm2_cm_cam_staticdep_l3_1_statdep_wrf(&st->devclk, 0x1);
+    //omap44xx_cam_cm2_cm_cam_staticdep_memif_statdep_wrf(&st->devclk, 0x1);
+    //omap44xx_cam_cm2_cm_cam_staticdep_ivahd_statdep_wrf(&st->devclk, 0x1);
 
     // Explicit enable && Force SW wakeup
-    omap44xx_cam_cm2_cm_cam_fdif_clkctrl_modulemode_wrf(&devclk, 0x2);
-    omap44xx_cam_cm2_cm_cam_clkstctrl_clktrctrl_wrf(&devclk, 0x2);
+    omap44xx_cam_cm2_cm_cam_fdif_clkctrl_modulemode_wrf(&st->devclk, 0x2);
+    omap44xx_cam_cm2_cm_cam_clkstctrl_clktrctrl_wrf(&st->devclk, 0x2);
 }
 
-static void manage_power(void)
+static void manage_power(struct fdif_driver_state* st)
 {
     FDIF_DEBUG("Power-on the PD_CAM domain for fdif\n");
 
@@ -67,34 +75,34 @@ static void manage_power(void)
     err = map_device_register(0x4A307000, 4096, &vbase);
     assert(err_is_ok(err));
 
-    omap44xx_cam_prm_initialize(&dev, (mackerel_addr_t)vbase);
-    omap44xx_cam_prm_pm_cam_pwrstctrl_powerstate_wrf(&dev, 0x3);
+    omap44xx_cam_prm_initialize(&st->dev, (mackerel_addr_t)vbase);
+    omap44xx_cam_prm_pm_cam_pwrstctrl_powerstate_wrf(&st->dev, 0x3);
 
     FDIF_DEBUG("%s:%d: Power OFF -> ON\n", __FUNCTION__, __LINE__);
-    while (omap44xx_cam_prm_pm_cam_pwrstst_powerstatest_rdf(&dev)
+    while (omap44xx_cam_prm_pm_cam_pwrstst_powerstatest_rdf(&st->dev)
             != 0x3);
     FDIF_DEBUG("%s:%d: Power is on.\n", __FUNCTION__, __LINE__);
 }
 
-static void read_result(void)
+static void read_result(struct fdif_driver_state* st)
 {
     printf("Face detection completed:\n");
     printf("Read the results...\n");
 
-    int faces = omap44xx_fdif_fd_dnum_dnum_rdf(&devfdif);
+    int faces = omap44xx_fdif_fd_dnum_dnum_rdf(&st->devfdif);
     printf("Faces found: %d\n", faces);
-    //omap44xx_fdif_pr(printbuf, PRINT_BUFFER_SIZE, &devfdif);
-    //printf("%s\n", printbuf);
+    //omap44xx_fdif_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devfdif);
+    //printf("%s\n", st->printbuf);
 
     for (int i = 0; i < faces; i++) {
         printf("Face %d:\n", i);
-        int x = omap44xx_fdif_fd_centerx_centerx_rdf(&devfdif, i);
-        int y = omap44xx_fdif_fd_centery_centery_rdf(&devfdif, i);
+        int x = omap44xx_fdif_fd_centerx_centerx_rdf(&st->devfdif, i);
+        int y = omap44xx_fdif_fd_centery_centery_rdf(&st->devfdif, i);
         printf("Position (X,Y): %d %d\n", x, y);
 
-        int size = omap44xx_fdif_fd_confsize_size_rdf(&devfdif, i);
-        int confidence = omap44xx_fdif_fd_confsize_conf_rdf(&devfdif, i);
-        int angle = omap44xx_fdif_fd_angle_angle_rdf(&devfdif, i);
+        int size = omap44xx_fdif_fd_confsize_size_rdf(&st->devfdif, i);
+        int confidence = omap44xx_fdif_fd_confsize_conf_rdf(&st->devfdif, i);
+        int angle = omap44xx_fdif_fd_angle_angle_rdf(&st->devfdif, i);
         printf("Size: %d Confidence: %d Angle: %d\n", size, confidence, angle);
     }
 }
@@ -104,50 +112,51 @@ static void read_result(void)
  */
 static void irq_handler(void *args)
 {
-    read_result();
+    struct fdif_driver_state* st = (struct fdif_driver_state*) args;
+    read_result(st);
 
-    omap44xx_fdif_fdif_ctrl_pr(printbuf, PRINT_BUFFER_SIZE, &devfdif);
-    printf("%s\n", printbuf);
+    omap44xx_fdif_fdif_ctrl_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devfdif);
+    printf("%s\n", st->printbuf);
 
-    omap44xx_cam_cm2_pr(printbuf, PRINT_BUFFER_SIZE, &devclk);
-    printf("%s\n", printbuf);
+    omap44xx_cam_cm2_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devclk);
+    printf("%s\n", st->printbuf);
 
-    omap44xx_cam_prm_pr(printbuf, PRINT_BUFFER_SIZE, &dev);
-    printf("%s\n", printbuf);
+    omap44xx_cam_prm_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->dev);
+    printf("%s\n", st->printbuf);
 
 
-    omap44xx_fdif_fdif_irqstatus_finish_irq_wrf(&devfdif, 2, 1);
+    omap44xx_fdif_fdif_irqstatus_finish_irq_wrf(&st->devfdif, 2, 1);
 
     // Go in Standby Mode
     // Again, module seems to go in standby just fine after its done
     // processing.
     //printf("%s:%d: go in standby\n", __FUNCTION__, __LINE__);
-    //omap44xx_fdif_fdif_ctrl_mstandby_wrf(&devfdif, 0x1);
-    //while(omap44xx_fdif_fdif_ctrl_mstandby_hdshk_rdf(&devfdif) != 0x0);
+    //omap44xx_fdif_fdif_ctrl_mstandby_wrf(&st->devfdif, 0x1);
+    //while(omap44xx_fdif_fdif_ctrl_mstandby_hdshk_rdf(&st->devfdif) != 0x0);
 
     // Disable Module Clocks
-    omap44xx_cam_cm2_cm_cam_clkstctrl_clktrctrl_wrf(&devclk, 0x1);
-    omap44xx_cam_cm2_cm_cam_fdif_clkctrl_modulemode_wrf(&devclk, 0x0);
+    omap44xx_cam_cm2_cm_cam_clkstctrl_clktrctrl_wrf(&st->devclk, 0x1);
+    omap44xx_cam_cm2_cm_cam_fdif_clkctrl_modulemode_wrf(&st->devclk, 0x0);
 
     // Going Powermode ON-INACTIVE
-    omap44xx_cam_prm_pm_cam_pwrstctrl_powerstate_wrf(&dev, 0x2);
+    omap44xx_cam_prm_pm_cam_pwrstctrl_powerstate_wrf(&st->dev, 0x2);
     FDIF_DEBUG("%s:%d: Power ON -> ON-INACTIVE\n", __FUNCTION__, __LINE__);
-    while (omap44xx_cam_prm_pm_cam_pwrstst_powerstatest_rdf(&dev)
+    while (omap44xx_cam_prm_pm_cam_pwrstst_powerstatest_rdf(&st->dev)
             != 0x2);
 
     // Going Powermode ON-INACTIVE -> OFF
     // Must use lowpoerstatechange for that
     FDIF_DEBUG("%s:%d: Power ON-INACTIVE -> OFF\n", __FUNCTION__, __LINE__);
-    omap44xx_cam_prm_pm_cam_pwrstctrl_powerstate_wrf(&dev, 0x0);
-    omap44xx_cam_prm_pm_cam_pwrstctrl_lowpowerstatechange_wrf(&dev, 0x1);
-    while (omap44xx_cam_prm_pm_cam_pwrstctrl_lowpowerstatechange_rdf(&dev)
+    omap44xx_cam_prm_pm_cam_pwrstctrl_powerstate_wrf(&st->dev, 0x0);
+    omap44xx_cam_prm_pm_cam_pwrstctrl_lowpowerstatechange_wrf(&st->dev, 0x1);
+    while (omap44xx_cam_prm_pm_cam_pwrstctrl_lowpowerstatechange_rdf(&st->dev)
             != 0x0);
 
-    omap44xx_cam_cm2_pr(printbuf, PRINT_BUFFER_SIZE, &devclk);
-    FDIF_DEBUG("%s\n", printbuf);
+    omap44xx_cam_cm2_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devclk);
+    FDIF_DEBUG("%s\n", st->printbuf);
 
-    omap44xx_cam_prm_pr(printbuf, PRINT_BUFFER_SIZE, &dev);
-    FDIF_DEBUG("%s\n", printbuf);
+    omap44xx_cam_prm_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->dev);
+    FDIF_DEBUG("%s\n", st->printbuf);
 }
 
 /*
@@ -155,14 +164,14 @@ static void irq_handler(void *args)
  *
  * \see OMAP TRM 9.4.1.2.1.1 Main Sequence – FDIF Polling Method
  */
-static void __attribute__((__unused__)) enable_poll_mode(void)
+static void __attribute__((__unused__)) enable_poll_mode(struct fdif_driver_state* st)
 {
-    omap44xx_fdif_fd_ctrl_run_wrf(&devfdif, 0x1);
+    omap44xx_fdif_fd_ctrl_run_wrf(&st->devfdif, 0x1);
 
     FDIF_DEBUG("%s:%d: Waiting until fdif is done...\n", __FUNCTION__, __LINE__);
-    while (omap44xx_fdif_fd_ctrl_finish_rdf(&devfdif) != 0x1);
+    while (omap44xx_fdif_fd_ctrl_finish_rdf(&st->devfdif) != 0x1);
 
-    read_result();
+    read_result(st);
 }
 
 
@@ -171,21 +180,17 @@ static void __attribute__((__unused__)) enable_poll_mode(void)
  *
  * See OMAP TRM 9.4.1.2.1.2 Main Sequence – FDIF Interrupt Method
  */
-static void enable_irq_mode(void)
+static void enable_irq_mode(struct fdif_driver_state* st)
 {
     errval_t err;
 
-    omap44xx_fdif_fdif_irqenable_set_finish_irq_wrf(&devfdif, 2, 1);
+    omap44xx_fdif_fdif_irqenable_set_finish_irq_wrf(&st->devfdif, 2, 1);
 
     // Register interrupt handler in kernel
-    err = inthandler_setup_arm(irq_handler, NULL, FDIF_IRQ);
+    err = inthandler_setup_arm(irq_handler, st, FDIF_IRQ);
     assert(err_is_ok(err));
 
-    omap44xx_fdif_fd_ctrl_run_wrf(&devfdif, 0x1);
-
-    while (1) {
-        event_dispatch(get_default_waitset());
-    }
+    omap44xx_fdif_fd_ctrl_run_wrf(&st->devfdif, 0x1);
 }
 
 /*
@@ -193,32 +198,54 @@ static void enable_irq_mode(void)
  *
  * See OMAP TRM 9.4.1.2.1.3 Subsequence – Set Image Parameters
  */
-static void set_image_params(genpaddr_t picaddr, genpaddr_t wkaddr)
+static void set_image_params(struct fdif_driver_state* st, genpaddr_t picaddr, genpaddr_t wkaddr)
 {
     // make sure 5 least significant bits are 0!
-    omap44xx_fdif_fdif_picaddr_wr(&devfdif, picaddr);
-    omap44xx_fdif_fdif_wkaddr_wr(&devfdif, wkaddr);
+    omap44xx_fdif_fdif_picaddr_wr(&st->devfdif, picaddr);
+    omap44xx_fdif_fdif_wkaddr_wr(&st->devfdif, wkaddr);
 
-    omap44xx_fdif_fd_dcond_min_wrf(&devfdif, 0x0); // 40 pixel
-    omap44xx_fdif_fd_dcond_dir_wrf(&devfdif, 0x0); // up?
+    omap44xx_fdif_fd_dcond_min_wrf(&st->devfdif, 0x0); // 40 pixel
+    omap44xx_fdif_fd_dcond_dir_wrf(&st->devfdif, 0x0); // up?
 
-    omap44xx_fdif_fd_startx_startx_wrf(&devfdif, 0x0);
-    omap44xx_fdif_fd_starty_starty_wrf(&devfdif, 0x0);
+    omap44xx_fdif_fd_startx_startx_wrf(&st->devfdif, 0x0);
+    omap44xx_fdif_fd_starty_starty_wrf(&st->devfdif, 0x0);
 
-    omap44xx_fdif_fd_sizex_sizex_wrf(&devfdif, 0x140); // TODO
-    omap44xx_fdif_fd_sizey_sizey_wrf(&devfdif, 0xf0); // TODO
-    omap44xx_fdif_fd_lhit_lhit_wrf(&devfdif, 0x5);
+    omap44xx_fdif_fd_sizex_sizex_wrf(&st->devfdif, 0x140); // TODO
+    omap44xx_fdif_fd_sizey_sizey_wrf(&st->devfdif, 0xf0); // TODO
+    omap44xx_fdif_fd_lhit_lhit_wrf(&st->devfdif, 0x5);
 }
 
-/*
- * \brief Face detection on OMAP4460
+/**
+ * Driver initialization function. This function is called by the driver domain
+ * (see also 'create_handler' in ddomain_service.c).
+ * Typically through a request from the device manager.
+ *
+ * The init function is supposed to set `dev` to the exported service iref.
+ * The init function may use `bfi->dstate` to store additional state about the device.
  *
- * We support poll-based mode as well as interrupt-based mode. The
- * default setting is to use polling for its simplicity. If interrups is
- * given as command line argument, interrupts will be used instead.
+ * \param[in]   bfi   The instance of this driver.
+ * \param[in]   name  The name of this driver instance.
+ * \param[in]   flags Additional flags (The exact flags supported is device/driver specific).
+ * \param[in]   c     Capabilities (for registers etc.) as provided by the device manager.
+ *                    The exact layout of the `c` is device specific.
+ * \param[out]  dev   The service iref over which the device can be contacted.
+ *
+ * \retval SYS_ERR_OK Device initialized successfully.
+ * \retval LIB_ERR_MALLOC_FAIL Unable to allocate memory for the driver.
  */
-int main(int argc, char **argv)
-{
+static errval_t init(struct bfdriver_instance* bfi, const char* name, uint64_t flags,
+                     struct capref* caps, size_t caps_len, char** args, size_t args_len, iref_t* dev) {
+    FDIF_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    bfi->dstate = malloc(sizeof(struct fdif_driver_state));
+    if (bfi->dstate == NULL) {
+        return LIB_ERR_MALLOC_FAIL;
+    }
+    assert(bfi->dstate != NULL);
+
+    struct fdif_driver_state* st = (struct fdif_driver_state*)bfi->dstate;
+
+    // 1. Initialize the device:
     size_t img_size = 320 * 240 * 8; // 75 KB
     size_t working_size = img_size; // 51.25 KB is enough
     size_t retbytes;
@@ -230,26 +257,26 @@ int main(int argc, char **argv)
     // Face detect Module
     err = map_device_register(0x4A10A000, 4096, &vbase);
     assert(err_is_ok(err));
-    omap44xx_fdif_initialize(&devfdif, (mackerel_addr_t)vbase);
+    omap44xx_fdif_initialize(&st->devfdif, (mackerel_addr_t)vbase);
 
     FDIF_DEBUG("FDIF Global Initialization\n");
 
-    manage_clocks();
-    manage_power();
+    manage_clocks(st);
+    manage_power(st);
 
-    omap44xx_fdif_fdif_sysconfig_softreset_wrf(&devfdif, 1);
-    while (omap44xx_fdif_fdif_sysconfig_softreset_rdf(&devfdif) != 0);
+    omap44xx_fdif_fdif_sysconfig_softreset_wrf(&st->devfdif, 1);
+    while (omap44xx_fdif_fdif_sysconfig_softreset_rdf(&st->devfdif) != 0);
 
-    omap44xx_fdif_fdif_sysconfig_pr(printbuf, PRINT_BUFFER_SIZE, &devfdif);
-    printf("%s\n", printbuf);
+    omap44xx_fdif_fdif_sysconfig_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devfdif);
+    printf("%s\n", st->printbuf);
 
-    omap44xx_fdif_fdif_sysconfig_idlemode_wrf(&devfdif, 0x2);
-    omap44xx_fdif_fdif_sysconfig_standbymode_wrf(&devfdif, 0x2);
+    omap44xx_fdif_fdif_sysconfig_idlemode_wrf(&st->devfdif, 0x2);
+    omap44xx_fdif_fdif_sysconfig_standbymode_wrf(&st->devfdif, 0x2);
 
-    omap44xx_fdif_fdif_sysconfig_pr(printbuf, PRINT_BUFFER_SIZE, &devfdif);
-    printf("%s\n", printbuf);
+    omap44xx_fdif_fdif_sysconfig_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devfdif);
+    printf("%s\n", st->printbuf);
 
-    omap44xx_fdif_fdif_ctrl_max_tags_wrf(&devfdif, 0xA);
+    omap44xx_fdif_fdif_ctrl_max_tags_wrf(&st->devfdif, 0xA);
 
     struct capref img_cap;
     struct capref workarea_cap;
@@ -285,20 +312,86 @@ int main(int argc, char **argv)
     err = invoke_frame_identify(workarea_cap, &wkret);
     assert (err_is_ok(err));
 
-    set_image_params(ret.base, wkret.base);
+    set_image_params(st, ret.base, wkret.base);
 
     // The following will set cm_cam_fdif_clkctrl_stdbysy to 0x0 (not in standby)
     // but it is apparently not needed (because we are in smart standby and
     // wake-up with magic as soon as we need it...?)
     //printf("%s:%d: // Wake up from standby\n", __FUNCTION__, __LINE__);
-    //omap44xx_fdif_fdif_ctrl_mstandby_wrf(&devfdif, 0x0);
-    //while(omap44xx_fdif_fdif_ctrl_mstandby_hdshk_rdf(&devfdif) != 0x1);
+    //omap44xx_fdif_fdif_ctrl_mstandby_wrf(&st->devfdif, 0x0);
+    //while(omap44xx_fdif_fdif_ctrl_mstandby_hdshk_rdf(&st->devfdif) != 0x1);
+    enable_irq_mode(st);
+
+    // 2. Export service to talk to the device:
+
+    // 3. Set iref of your exported service (this is reported back to Kaluga)
+
+    return SYS_ERR_OK;
+}
 
-#if defined(FDIF_IRQ)
-    enable_irq_mode();
-#else
-    enable_poll_mode();
-#endif
+/**
+ * Instructs driver to attach to the device.
+ * This function is only called if the driver has previously detached
+ * from the device (see also detach).
+ *
+ * \note After detachment the driver can not assume anything about the
+ * configuration of the device.
+ *
+ * \param[in]   bfi   The instance of this driver.
+ * \retval SYS_ERR_OK Device initialized successfully.
+ */
+static errval_t attach(struct bfdriver_instance* bfi) {
+    FDIF_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
 
-    return 0;
+    return SYS_ERR_OK;
 }
+
+/**
+ * Instructs driver to detach from the device.
+ * The driver must yield any control over to the device after this function returns.
+ * The device may be left in any state.
+ *
+ * \param[in]   bfi   The instance of this driver.
+ * \retval SYS_ERR_OK Device initialized successfully.
+ */
+static errval_t detach(struct bfdriver_instance* bfi) {
+    FDIF_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * Instructs the driver to go in a particular sleep state.
+ * Supported states are platform/device specific.
+ *
+ * \param[in]   bfi   The instance of this driver.
+ * \retval SYS_ERR_OK Device initialized successfully.
+ */
+static errval_t set_sleep_level(struct bfdriver_instance* bfi, uint32_t level) {
+    FDIF_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    struct fdif_driver_state* uds = bfi->dstate;
+    uds->level = level;
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * Destroys this driver instance.
+ *
+ * \param[in]   bfi   The instance of this driver.
+ * \retval SYS_ERR_OK Device initialized successfully.
+ */
+static errval_t destroy(struct bfdriver_instance* bfi) {
+    FDIF_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+    struct fdif_driver_state* uds = bfi->dstate;
+    free(uds);
+    bfi->dstate = NULL;
+
+    // XXX: Tear-down the service
+    bfi->device = 0x0;
+
+    return SYS_ERR_OK;
+}
+
+DEFINE_MODULE(fdif, init, attach, detach, set_sleep_level, destroy);
diff --git a/usr/drivers/omap44xx/fdif/fdif_domain.c b/usr/drivers/omap44xx/fdif/fdif_domain.c
new file mode 100644 (file)
index 0000000..3e8de12
--- /dev/null
@@ -0,0 +1,25 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <barrelfish/barrelfish.h>
+#include <driverkit/driverkit.h>
+#include <barrelfish/nameservice_client.h>
+
+int main(int argc, char** argv)
+{
+    size_t drivers = 0;
+    struct bfdriver* cur = NULL;
+    driverkit_list(&cur, &drivers);
+    for (size_t i=0; i<drivers; i++) {
+        printf("%s:%s:%d: Found device driver class = %s\n", __FILE__, __FUNCTION__, __LINE__, cur->name);
+        cur += 1;
+    }
+
+    iref_t dev, ctrl;
+    driverkit_create_driver("fdif", "fdif_inst", NULL, 0, NULL, 0, 0, &dev, &ctrl);
+
+    messages_handler_loop();
+    return 0;
+}