Merge branch 'bsdlibc'
authorAdam Turowski <adam.turowski@inf.ethz.ch>
Tue, 11 Jul 2017 13:27:38 +0000 (15:27 +0200)
committerAdam Turowski <adam.turowski@inf.ethz.ch>
Tue, 11 Jul 2017 13:27:38 +0000 (15:27 +0200)
Signed-off-by: Adam Turowski <adam.turowski@inf.ethz.ch>

61 files changed:
errors/errno.fugu
hake/ARMv7.hs
hake/ARMv8.hs
hake/ArchDefaults.hs
hake/K1om.hs
if/Hakefile
if/cm2.if [new file with mode: 0644]
if/ddomain.if
if/twl6030.if [new file with mode: 0644]
include/driverkit/driverkit.h
lib/driverkit/Hakefile
lib/driverkit/dcontrol_service.c
lib/driverkit/ddomain_client.c
lib/driverkit/ddomain_service.c
lib/driverkit/debug.h
lib/driverkit/modules.c
platforms/Hakefile
tools/flounder/Local.hs
usr/drivers/domain/Hakefile
usr/drivers/domain/main.c
usr/drivers/omap44xx/cm2/Hakefile [new file with mode: 0644]
usr/drivers/omap44xx/cm2/cm2.c [moved from usr/drivers/omap44xx/mmchs/cm2.c with 66% similarity]
usr/drivers/omap44xx/cm2/cm2.h [new file with mode: 0644]
usr/drivers/omap44xx/cm2/module.c [new file with mode: 0644]
usr/drivers/omap44xx/cm2/service.c [new file with mode: 0644]
usr/drivers/omap44xx/fdif/Hakefile
usr/drivers/omap44xx/fdif/fdif.c
usr/drivers/omap44xx/fdif/fdif.h
usr/drivers/omap44xx/fdif/fdif_domain.c [deleted file]
usr/drivers/omap44xx/mmchs/Hakefile
usr/drivers/omap44xx/mmchs/cap_slots.h
usr/drivers/omap44xx/mmchs/ctrlmod.c
usr/drivers/omap44xx/mmchs/main.c
usr/drivers/omap44xx/mmchs/mmchs.c
usr/drivers/omap44xx/mmchs/mmchs.h
usr/drivers/omap44xx/mmchs/mmchs_debug.h
usr/drivers/omap44xx/mmchs/mmchs_domain.c [deleted file]
usr/drivers/omap44xx/mmchs/omap44xx_cm2.h [deleted file]
usr/drivers/omap44xx/mmchs/service.c
usr/drivers/omap44xx/sdma/Hakefile
usr/drivers/omap44xx/sdma/main.c
usr/drivers/omap44xx/sdma/omap_sdma.c
usr/drivers/omap44xx/sdma/omap_sdma.h
usr/drivers/omap44xx/sdma/sdma.h
usr/drivers/omap44xx/sdma/service.c
usr/drivers/omap44xx/twl6030/Hakefile [new file with mode: 0644]
usr/drivers/omap44xx/twl6030/i2c.c [moved from usr/drivers/omap44xx/mmchs/i2c.c with 97% similarity]
usr/drivers/omap44xx/twl6030/i2c.h [moved from usr/drivers/omap44xx/mmchs/i2c.h with 90% similarity]
usr/drivers/omap44xx/twl6030/module.c [new file with mode: 0644]
usr/drivers/omap44xx/twl6030/service.c [new file with mode: 0644]
usr/drivers/omap44xx/twl6030/twl6030.c [moved from usr/drivers/omap44xx/mmchs/twl6030.c with 95% similarity]
usr/drivers/omap44xx/twl6030/twl6030.h [moved from usr/drivers/omap44xx/mmchs/twl6030.h with 63% similarity]
usr/kaluga/Hakefile
usr/kaluga/armv7.c
usr/kaluga/armv7_startup.c
usr/kaluga/debug.h
usr/kaluga/driver_domains.c [new file with mode: 0644]
usr/kaluga/driver_domains.h [new file with mode: 0644]
usr/kaluga/driver_startup.h
usr/kaluga/kaluga.h
usr/kaluga/main.c

index 400d117..e41cfc7 100755 (executable)
@@ -820,6 +820,7 @@ errors driverkit DRIVERKIT_ERR_ {
     failure DRIVER_INIT          "There was a problem initializing the driver.",
     failure CONTROL_IFACE_EXPORT "Can't export control interface.",
     failure CONTROL_SERVICE_INIT "Failed to initialize control service.",
+    failure CAP_CAPACITY         "Cap capacity reached, can't send more.",
 };
 
 // errors in PCI/device handling
index 71c6847..567c1df 100644 (file)
@@ -88,8 +88,8 @@ options = (ArchDefaults.options arch archFamily) {
             optLdFlags = ldFlags,
             optLdCxxFlags = ldCxxFlags,
             optLibs = stdLibs,
-            optInterconnectDrivers = ["lmp", "ump"],
-            optFlounderBackends = ["lmp", "ump"]
+            optInterconnectDrivers = ["lmp", "ump", "local"],
+            optFlounderBackends = ["lmp", "ump", "local"]
           }
 
 --
index 4e62cb0..690eafa 100644 (file)
@@ -53,7 +53,7 @@ ourCommonFlags = [ Str "-fno-unwind-tables",
                    Str "-Wno-format"
  ]
 
-cFlags = ArchDefaults.commonCFlags 
+cFlags = ArchDefaults.commonCFlags
          ++ ArchDefaults.commonFlags
          ++ ourCommonFlags
 
@@ -70,11 +70,11 @@ ldCxxFlags = ArchDefaults.ldCxxFlags arch ++ ourLdFlags
 
 stdLibs = ArchDefaults.stdLibs arch
 
-options = (ArchDefaults.options arch archFamily) { 
+options = (ArchDefaults.options arch archFamily) {
             optFlags = cFlags,
             optCxxFlags = cxxFlags,
             optDefines = cDefines,
-            optDependencies = 
+            optDependencies =
                 [ PreDep InstallTree arch "/include/trace_definitions/trace_defs.h",
                   PreDep InstallTree arch "/include/errors/errno.h",
                   PreDep InstallTree arch "/include/barrelfish_kpi/capbits.h",
@@ -83,8 +83,8 @@ options = (ArchDefaults.options arch archFamily) {
             optLdFlags = ldFlags,
             optLdCxxFlags = ldCxxFlags,
             optLibs = stdLibs,
-            optInterconnectDrivers = ["lmp", "ump"],
-            optFlounderBackends = ["lmp", "ump"]
+            optInterconnectDrivers = ["lmp", "ump", "local"],
+            optFlounderBackends = ["lmp", "ump", "local"]
           }
 
 --
@@ -162,7 +162,7 @@ linkKernel opts objs libs name driverType=
         Rules [ Rule ([ Str compiler ] ++
                     map Str Config.cOptFlags ++
                     [ NStr "-T", In BuildTree arch linkscript,
-                      Str "-o", 
+                      Str "-o",
                       Out arch kfull,
                       NStr "-Wl,-Map,", Out arch kernelmap
                     ]
@@ -177,11 +177,11 @@ linkKernel opts objs libs name driverType=
              Rule $ strip opts kfull kdebug kbinary,
              Rule $ debug opts kfull kdebug,
               -- Generate kernel assembly dump
-              Rule [ Str objdump, 
-                     Str "-d", 
+              Rule [ Str objdump,
+                     Str "-d",
                      Str "-M reg-names-raw",
-                     In BuildTree arch kbinary, 
-                     Str ">", 
+                     In BuildTree arch kbinary,
+                     Str ">",
                      Out arch kasmdump ],
               Rule [ Str "cpp",
                      NStr "-I", NoDep SrcTree "src" "/kernel/include/arch/armv8",
index 9484890..fe0de2e 100644 (file)
@@ -313,6 +313,8 @@ linker arch compiler opts objs libs mods bin =
     ++
     [Str "-Wl,--whole-archive"] ++ [ In BuildTree arch l | l <- mods ] ++ [Str "-Wl,--no-whole-archive"]
     ++
+    [ In BuildTree arch l | l <- libs ]
+    ++
     (optLibs opts)
     ++
     [Str "-Wl,--end-group"]
index 4ffac20..80011a3 100644 (file)
@@ -9,7 +9,7 @@
 -- Architectural definitions for Barrelfish on x86_mic.
 --
 -- This architecture is used to build for the Intel Xeon Phi architecture.
--- 
+--
 --------------------------------------------------------------------------
 
 module K1om where
@@ -37,7 +37,7 @@ cxxcompiler = Config.k1om_cxx
 ourCommonFlags = [ Str "-m64",
                    Str "-mno-red-zone",
                    Str "-fPIE",
-                   Str "-fno-stack-protector", 
+                   Str "-fno-stack-protector",
                    Str "-Wno-unused-but-set-variable",
                    Str "-Wno-packed-bitfield-compat",
                    Str "-fno-tree-vectorize",
@@ -53,7 +53,7 @@ ourCommonFlags = [ Str "-m64",
                    Str "-mno-sse4.2",
                    Str "-mno-sse4",
                    Str "-mno-sse4a",
-                   Str "-mno-3dnow", 
+                   Str "-mno-3dnow",
 -- Apparently the MPSS gcc somehow incudes CMOVES?
                    Str "-fno-if-conversion",
 -- specific Xeon Phi architecture
@@ -85,20 +85,20 @@ ldCxxFlags = ArchDefaults.ldCxxFlags arch ++ ourLdFlags
 
 -- adding x86_64 includes to the K1OM architecture
 kernelOptIncludes = [NoDep SrcTree "src" ("/kernel/include/arch/x86_64"),
-                     NoDep SrcTree "src" ("/include/target/x86_64"), 
-                     NoDep SrcTree "src" ("/include/arch/x86_64")] 
+                     NoDep SrcTree "src" ("/include/target/x86_64"),
+                     NoDep SrcTree "src" ("/include/arch/x86_64")]
 
-options = (ArchDefaults.options arch archFamily) { 
+options = (ArchDefaults.options arch archFamily) {
             optFlags = cFlags,
             optCxxFlags = cxxFlags,
             optDefines = cDefines,
             optLdFlags = ldFlags,
             optLdCxxFlags = ldCxxFlags,
-            optInterconnectDrivers = ["lmp", "ump", "multihop"],
-            optFlounderBackends = ["lmp", "ump", "multihop"],
+            optInterconnectDrivers = ["lmp", "ump", "multihop", "local"],
+            optFlounderBackends = ["lmp", "ump", "multihop", "local"],
             optIncludes = ArchDefaults.cStdIncs arch archFamily
                           ++
-                          [NoDep SrcTree "src" ("/include/target/x86_64"), 
+                          [NoDep SrcTree "src" ("/include/target/x86_64"),
                            NoDep SrcTree "src" ("/include/arch/x86_64")]
           }
 
@@ -110,7 +110,7 @@ kernelCFlags = [ Str s | s <- [ "-fno-builtin",
                                 "-nostdinc",
                                 "-std=c99",
                                 "-m64",
-                                "-fPIE", 
+                                "-fPIE",
                                 "-e start",
                                 "-mno-red-zone",
                                 "-Wa,-march=k1om",
@@ -141,7 +141,7 @@ kernelCFlags = [ Str s | s <- [ "-fno-builtin",
                                 "-mno-sse4.2",
                                 "-mno-sse4",
                                 "-mno-sse4a",
-                                "-mno-3dnow", 
+                                "-mno-3dnow",
 -- Apparently the MPSS gcc somehow incudes CMOVES?
                                 "-fno-if-conversion" ] ]
 
@@ -178,32 +178,32 @@ cxxlinker = ArchDefaults.cxxlinker arch cxxcompiler
 
 --
 -- Link the kernel (CPU Driver)
--- 
+--
 linkKernel :: Options -> [String] -> [String]  -> String -> HRule
-linkKernel opts objs libs kbin = 
+linkKernel opts objs libs kbin =
     let linkscript = "/kernel/linker.lds"
     in
       Rules [ Rule ([ Str compiler ] ++
                     map Str Config.cOptFlags ++
                     [ NStr "-T", In BuildTree arch "/kernel/linker.lds",
-                      Str "-o", Out arch kbin 
+                      Str "-o", Out arch kbin
                     ]
                     ++ (optLdFlags opts)
                     ++
                     [ In BuildTree arch o | o <- objs ]
                     ++
                     [ In BuildTree arch l | l <- libs ]
-                    ++ 
+                    ++
                     [ NL, NStr "echo -e '\\0002' | dd of=",
-                      Out arch kbin, 
+                      Out arch kbin,
                       Str "bs=1 seek=16 count=1 conv=notrunc status=noxfer"
                     ]
                    ),
-              Rule [ Str "cpp", 
+              Rule [ Str "cpp",
                      NStr "-I", NoDep SrcTree "src" "/kernel/include/",
-                     Str "-D__ASSEMBLER__", 
+                     Str "-D__ASSEMBLER__",
                      Str "-P", In SrcTree "src" "/kernel/arch/k1om/linker.lds.in",
-                     Out arch linkscript 
+                     Out arch linkscript
                    ],
               -- Produce a stripped binary
               Rule [ Str objcopy,
index 56832e8..f07dd42 100644 (file)
@@ -96,6 +96,8 @@
                "ddomain",
                "dcontrol",
                "net_filter",
+               "twl6030",
+               "cm2",
                "net_sockets"
            ],
              arch <- allArchitectures
diff --git a/if/cm2.if b/if/cm2.if
new file mode 100644 (file)
index 0000000..da5d8d6
--- /dev/null
+++ b/if/cm2.if
@@ -0,0 +1,5 @@
+interface cm2 "Controlling CM2" {
+    rpc enable_i2c(in uint32 index);
+    rpc enable_hsmmc1();
+    rpc get_hsmmc1_base_clock(out uint32 clock);
+};
index 15274e6..3f9315c 100644 (file)
 interface ddomain "Kaluga <-> Driver Domain Interface" {
 
     /**
-     * Creates a new driver within the driver domain.
+     * XXX: Make sure kaluga knows what domain this is.
+     * ideally we could set-up endpoints before spawning something
      */
-    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);
+    message identify(uint64 id);
 
     /**
+     * Creates a new driver within the driver domain.
+     */
+    rpc create(in char cls[clen, 256], in char name[nlen, 256],
+               in char a1[a1len, 256], in char a2[a2len, 256], in char a3[a3len, 256], in char a4[a4len, 256],
+               in cap cap1, in cap cap2, in cap cap3, in cap cap4, in cap cap5, in cap cap6, in uint64 flags,
+               out iref devif, out iref control, out errval err);
+    /**
      * Destroys a driver inside a domain.
      */
     rpc destroy(in char cls[length, 256], out errval err);
diff --git a/if/twl6030.if b/if/twl6030.if
new file mode 100644 (file)
index 0000000..fb49b74
--- /dev/null
@@ -0,0 +1,5 @@
+interface twl6030 "Controlling the Fully Integrated Power Management IC" {
+    rpc vmmc_on();
+    rpc vmmc_off();
+    rpc vmmc_vsel(in uint32 millis);
+};
index b093071..04c37e4 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <barrelfish/types.h>
 #include <errors/errno.h>
+#include <collections/list.h>
 
 struct bfdriver;
 
@@ -46,8 +47,32 @@ void driverkit_list(struct bfdriver**, size_t*);
 struct bfdriver* driverkit_lookup_cls(const char*);
 
 /** driver domain flounder interface */
-errval_t ddomain_communication_init(iref_t kaluga_iref);
+struct domain_instance {
+    uint64_t service_id;
+    collections_listnode* to_spawn;
+    collections_listnode* spawned;
+    struct ddomain_binding *b;
+};
+
+struct driver_instance {
+    char* driver_name;
+    char* inst_name;
+    char** args;
+    size_t cap_idx;
+    struct capref* caps;
+    uint64_t flags;
+    iref_t dev;
+    iref_t control;
+};
+errval_t ddomain_communication_init(iref_t kaluga_iref, uint64_t id);
 errval_t ddomain_controller_init(void);
+struct domain_instance* ddomain_create_domain_instance(uint64_t id);
+struct driver_instance* ddomain_create_driver_instance(char* driver_name, char* inst_name);
+void ddomain_instantiate_driver(struct domain_instance* di, struct driver_instance* drv);
+void ddomain_free_driver_inst(void* arg);
+void ddomain_free_domain_inst(void* arg);
+errval_t ddomain_driver_add_cap(struct driver_instance* drv, struct capref cap);
+void ddomain_wait_for_id(void);
 
 /** driver control flounder interface */
 errval_t dcontrol_service_init(struct bfdriver_instance* bfi, struct waitset* ws);
@@ -55,9 +80,12 @@ errval_t dcontrol_service_init(struct bfdriver_instance* bfi, struct waitset* ws
 errval_t map_device_register(lpaddr_t, size_t, lvaddr_t*);
 errval_t map_device_cap(struct capref, lvaddr_t *);
 
+errval_t driverkit_local_service_register(char* name, void* tbl);
+void* driverkit_local_service_lookup(char* name);
+
 #define __bfdrivers            __attribute__((__section__(".bfdrivers")))
 #define __visible       __attribute__((__externally_visible__))
-#define __aligned8      __attribute__ ((__aligned__ (8)))
+#define __waligned       __attribute__((__aligned__(sizeof(size_t))))
 #define __used          __attribute__((__used__))
 #define ___PASTE(a,b) a##b
 #define __PASTE(a,b) ___PASTE(a,b)
@@ -68,7 +96,7 @@ errval_t map_device_cap(struct capref, lvaddr_t *);
         __used                                      \
         __visible                                   \
         __bfdrivers                                 \
-        __aligned8 = {                              \
+        __waligned =  {                             \
         #name,                                      \
         init_fn,                                    \
         attach_fn,                                  \
index e9da48a..a523769 100644 (file)
@@ -17,6 +17,7 @@
         target = "driverkit",
         flounderDefs = ["ddomain", "dcontrol"],
         flounderBindings = ["ddomain", "dcontrol"],
+        flounderExtraBindings = [ ("ddomain", ["rpcclient"])],
         addLibraries = ["collections"],
         cFiles = (find withSuffices [".c"])
     }
index 3c8a026..93ee51d 100644 (file)
@@ -115,7 +115,7 @@ static void rpc_export_cb(void *st, errval_t err, iref_t iref) {
     assert(bfi->name != NULL);
 
     if (err_is_fail(err)) {
-        DRIVERKIT_DEBUG("Exporting control interface for %s failed.", bfi->name);
+        DRIVERKIT_DEBUG("Exporting control interface for %s failed.\n", bfi->name);
         err = err_push(err, DRIVERKIT_ERR_CONTROL_IFACE_EXPORT);
     }
     else {
@@ -124,7 +124,7 @@ static void rpc_export_cb(void *st, errval_t err, iref_t iref) {
         assert (r > 0);
         err = nameservice_register(service_name, iref);
         if (err_is_fail(err)) {
-            DEBUG_ERR(err, "Can't register control interface with nameserver.");
+            DEBUG_ERR(err, "Can't register control interface with nameserver.\n");
             err = err_push(err, DRIVERKIT_ERR_CONTROL_IFACE_EXPORT);
         }
         else {
@@ -151,6 +151,8 @@ static void rpc_export_cb(void *st, errval_t err, iref_t iref) {
 static errval_t rpc_connect_cb(void *st, struct dcontrol_binding *b)
 {
     struct bfdriver_instance* bfi = (struct bfdriver_instance*) st;
+    assert(bfi != NULL);
+    
     DRIVERKIT_DEBUG("Got a new connection for controlling driver instance %s.\n", bfi->name);
     b->rx_vtbl = rpc_rx_vtbl;
     b->st = st;
index 8353305..d8714ea 100644 (file)
 #include <if/ddomain_defs.h>
 
 #include "debug.h"
-
 #define SERVICE_NAME "ddomain_controller"
 
+#define MAX_CAPS 6
+#define MAX_ARGS 4
+
+static collections_listnode* driver_domain_instances;
+
+void ddomain_free_driver_inst(void* arg) {
+    struct driver_instance* di = (struct driver_instance*) arg;
+    free(di->driver_name);
+    free(di->inst_name);
+    free(di->args);
+    free(di->caps);
+    free(di);
+}
+
+struct domain_instance* ddomain_create_domain_instance(uint64_t id) {
+    struct domain_instance* di = calloc(1, sizeof(struct domain_instance));
+    assert(di != NULL);
+    di->b = NULL;
+    di->service_id = id;
+    collections_list_create(&di->to_spawn, ddomain_free_driver_inst);
+    collections_list_create(&di->spawned, ddomain_free_driver_inst);
+
+    collections_list_insert(driver_domain_instances, di);
+    return di;
+}
+
+struct driver_instance* ddomain_create_driver_instance(char* driver_name, char* inst_name) {
+    struct driver_instance* di = calloc(sizeof(struct driver_instance), 1);
+    assert(di != NULL);
+
+    di->driver_name = strdup(driver_name);
+    assert(di->driver_name);
+    di->inst_name = strdup(inst_name);
+    assert(di->inst_name);
+
+    di->args = calloc(sizeof(char*), MAX_ARGS);
+    assert(di->args);
+    di->caps = calloc(sizeof(struct capref), MAX_CAPS);
+    assert(di->caps);
+
+    return di;
+}
+
+errval_t ddomain_driver_add_cap(struct driver_instance* drv, struct capref cap) {
+    assert(drv != NULL);
+    if (drv->cap_idx < MAX_CAPS) {
+        drv->caps[drv->cap_idx++] = cap;
+        return SYS_ERR_OK;
+    }
+    else {
+        return DRIVERKIT_ERR_CAP_CAPACITY;
+    }
+}
+
+static errval_t create_call(struct ddomain_binding *b, struct driver_instance* drv) {
+    assert(b != NULL);
+    assert(b->rpc_tx_vtbl.create != NULL);
+    assert(drv != NULL);
+
+    errval_t out_err = SYS_ERR_OK;
+    DRIVERKIT_DEBUG("Trying to spawn %s (named %s)\n", drv->driver_name, drv->inst_name);
+    errval_t err = b->rpc_tx_vtbl.create(b, drv->driver_name, strlen(drv->driver_name)+1,
+                                          drv->inst_name, strlen(drv->inst_name)+1,
+                                          drv->args[0], (drv->args[0] != NULL) ? strlen(drv->args[0]) : 0,
+                                          drv->args[1], (drv->args[1] != NULL) ? strlen(drv->args[1]) : 0,
+                                          drv->args[2], (drv->args[2] != NULL) ? strlen(drv->args[2]) : 0,
+                                          drv->args[3], (drv->args[3] != NULL) ? strlen(drv->args[3]) : 0,
+                                          drv->caps[0], drv->caps[1], drv->caps[2], drv->caps[3], drv->caps[4], drv->caps[5],
+                                          drv->flags, &drv->dev, &drv->control, &out_err);
+    if (err_is_fail(err)) {
+        DEBUG_ERR(err, "Failed to create driver %s\n", drv->driver_name);
+        return err;
+    }
+    else {
+        printf("Driver %s created, reachable at [%"PRIuIREF", %"PRIuIREF"]\n", drv->driver_name, drv->dev, drv->control);
+        return out_err;
+    }
+}
+
+void ddomain_instantiate_driver(struct domain_instance* di, struct driver_instance* drv) {
+    // Driver domain not up, make sure we spawn drivers later
+    if (di->b == NULL) {
+        collections_list_insert(di->to_spawn, drv);
+    }
+    // Driver domain up, spawn driver now
+    else {
+        errval_t err = create_call(di->b, drv);
+        if (err_is_fail(err)) {
+            USER_PANIC_ERR(err, "create driver instance failed.");
+        }
+        collections_list_insert(di->spawned, drv);
+    }
+}
+
+void ddomain_free_domain_inst(void* arg) {
+    struct domain_instance* di = (struct domain_instance*) arg;
+    collections_list_release(di->to_spawn);
+    collections_list_release(di->spawned);
+}
+
 static struct export_state {
     struct ddomain_binding* b;
     bool is_done;
@@ -47,25 +146,53 @@ static void rpc_export_cb(void *st, errval_t err, iref_t iref)
     }
 }
 
-static void ddomain_create_response_handler(struct ddomain_binding* binding, iref_t dev, iref_t control, errval_t err) {
-    DRIVERKIT_DEBUG("Driver domain created driver rechable at [%"PRIuIREF", %"PRIuIREF"]\n", dev, control);
+static int32_t find_id(void* data, void* arg) {
+    struct domain_instance* di = (void*) data;
+    uint64_t id = (uint64_t)(uintptr_t) arg;
+    return di->service_id == id;
 }
 
-static void ddomain_destroy_response_handler(struct ddomain_binding* binding, errval_t err) {
-    DRIVERKIT_DEBUG("Driver destroyed [%s]\n", err_getstring(err));
+static void ddomain_identify_handler(struct ddomain_binding* binding, uint64_t id) {
+    DRIVERKIT_DEBUG("Got identify message %"PRIu64".\n", id);
+
+    void* found = collections_list_find_if(driver_domain_instances, find_id, (void*)(uintptr_t) id);
+    if (found) {
+        DRIVERKIT_DEBUG("Found driver for id %"PRIu64"\n", id);
+        struct domain_instance* di = (struct domain_instance*) found;
+        assert(di->service_id == id);
+        di->b = binding;
+
+        void* removed;
+        while ( (removed = collections_list_remove_ith_item(di->to_spawn, 0)) != NULL ) {
+            struct driver_instance* driver = (struct driver_instance*) removed;
+            DRIVERKIT_DEBUG("Trying to spawn %s\n", driver->inst_name);
+            errval_t err = create_call(di->b, driver);
+            if (err_is_fail(err)) {
+                DEBUG_ERR(err, "Can't spawn driver intstance.");
+            }
+            collections_list_insert(di->spawned, driver);
+        }
+    }
+    else {
+        // XXX: Handle gracefully
+        USER_PANIC("Unknown identify call from ddomain...");
+    }
 }
 
 static const struct ddomain_rx_vtbl rpc_rx_vtbl = {
-    .create_response = ddomain_create_response_handler,
-    .destroy_response = ddomain_destroy_response_handler,
+    .identify = ddomain_identify_handler,
 };
 
 static errval_t rpc_connect_cb(void *st, struct ddomain_binding *b)
 {
-    DRIVERKIT_DEBUG("Got a new connection from driver domain.\n");
+    DRIVERKIT_DEBUG("%s:%s:%d: Got a new connection from driver domain.\n", __FILE__, __FUNCTION__, __LINE__);
     rpc_export.b = b;
 
     b->rx_vtbl = rpc_rx_vtbl;
+    // Make sure we can send RPC messages to the client (driver domain)
+    // if we could send/pass endpoints caps directly this whole bootstrapping
+    // mess would be easier.
+    ddomain_rpc_client_init(b);
 
     // Set up continuation queue
     b->st = NULL;
@@ -74,6 +201,8 @@ static errval_t rpc_connect_cb(void *st, struct ddomain_binding *b)
 
 errval_t ddomain_controller_init(void)
 {
+    collections_list_create(&driver_domain_instances, ddomain_free_domain_inst);
+
     rpc_export.err = SYS_ERR_OK;
     rpc_export.is_done = false;
 
@@ -84,25 +213,11 @@ errval_t ddomain_controller_init(void)
         return err;
     }
 
+    DRIVERKIT_DEBUG("%s:%s:%d: Trying to export ddomain interface\n", __FILE__, __FUNCTION__, __LINE__);
     // XXX: broken
     while (!rpc_export.is_done) {
         messages_wait_and_handle_next();
     }
 
-    /*
-    // Hack for testing: wait for 1st controller to connect
-    while(rpc_export.b == NULL) {
-        messages_wait_and_handle_next();
-    }
-
-    struct capref c;
-    err = slot_alloc(&c);
-    assert(err_is_ok(err));
-    err = frame_alloc(&c, 4096, NULL);
-    assert(err_is_ok(err));
-    (rpc_export.b)->tx_vtbl.create((rpc_export.b), NOP_CONT, "uart", 5, "uart_instance", 14, c, 0x0);
-    // end of hack for testing
-    */
-
     return rpc_export.err;
 }
index f5cce51..e4dd6bb 100644 (file)
@@ -49,19 +49,26 @@ static struct bind_state {
  */
 static void create_handler(struct ddomain_binding* binding, const char* cls, size_t cls_len,
                            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,
+                           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, struct capref cap5,  struct capref cap6,
                            uint64_t flags) {
     DRIVERKIT_DEBUG("Driver domain got create message from kaluga for %s\n", cls);
 
     iref_t dev = 0, ctrl = 0;
 
+    static size_t NR_CAPS  = 6;
+    static size_t NR_ARGS = 4;
+
     // This array is owned by the driver after create:
-    struct capref* cap_array = calloc(sizeof(struct capref), 4);
+    struct capref* cap_array = calloc(sizeof(struct capref), NR_CAPS);
     cap_array[0] = cap1;
     cap_array[1] = cap2;
     cap_array[2] = cap3;
     cap_array[3] = cap4;
+    cap_array[4] = cap5;
+    cap_array[5] = cap6;
 
     char** args_array = calloc(sizeof(char*), 4);
     args_array[0] = a1 != NULL ? strdup(a1) : NULL;
@@ -69,14 +76,16 @@ static void create_handler(struct ddomain_binding* binding, const char* cls, siz
     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);
+    DRIVERKIT_DEBUG("Instantiate driver\n");
+    errval_t err = driverkit_create_driver(cls, name, cap_array, NR_CAPS, args_array, NR_ARGS, flags, &dev, &ctrl);
     if (err_is_fail(err)) {
-        DEBUG_ERR(err, "Instantiating driver failed, report this back to Kaluga.");
+        DEBUG_ERR(err, "Instantiating driver failed, report this back to Kaluga.\n");
     }
 
-    err = binding->tx_vtbl.create_response(binding, NOP_CONT, dev, ctrl, err);
+    DRIVERKIT_DEBUG("sending create response to kaluga\n");
+    err = ddomain_create_response__tx(binding, NOP_CONT, dev, ctrl, err);
     if (err_is_fail(err)) {
-        USER_PANIC_ERR(err, "Sending reply failed.");
+        USER_PANIC_ERR(err, "Sending reply failed.\n");
     }
 }
 
@@ -104,7 +113,7 @@ static void destroy_handler(struct ddomain_binding* binding, const char* name, s
  * Stubs table for functions to call on driver instance.
  */
 static const struct ddomain_rx_vtbl rpc_rx_vtbl = {
-    .create = create_handler,
+    .create_call = create_handler,
     .destroy_call = destroy_handler,
 };
 
@@ -139,7 +148,7 @@ out:
  * \param  connect_to iref where to connect.
  * \retval SYS_ERR_OK Connected to the driver manager.
  */
-errval_t ddomain_communication_init(iref_t connect_to)
+errval_t ddomain_communication_init(iref_t connect_to, uint64_t ident)
 {
     rpc_bind.err = SYS_ERR_OK;
     rpc_bind.is_done = false;
@@ -148,11 +157,15 @@ errval_t ddomain_communication_init(iref_t connect_to)
     if (err_is_fail(err)) {
         return err;
     }
-
+    DRIVERKIT_DEBUG("%s:%s:%d: Trying to connect to kaluga...\n", __FILE__, __FUNCTION__, __LINE__);
     // XXX: broken
     while (!rpc_bind.is_done) {
         messages_wait_and_handle_next();
     }
 
+    DRIVERKIT_DEBUG("%s:%s:%d: Send identify %"PRIu64"\n", __FILE__, __FUNCTION__, __LINE__, ident);
+    errval_t send_err = rpc_bind.binding->tx_vtbl.identify(rpc_bind.binding, NOP_CONT, ident);
+    assert(err_is_ok(send_err));
+
     return rpc_bind.err;
 }
index f20d353..46383ef 100644 (file)
 #ifndef __DRIVERKIT_DEBUG__
 #define __DRIVERKIT_DEBUG__
 
-#define ENABLE_DRIVERKIT_DEBUG 1
+//#define ENABLE_DRIVERKIT_DEBUG 1
 
 #if defined(ENABLE_DRIVERKIT_DEBUG) || defined(GLOBAL_DEBUG)
-#define DRIVERKIT_DEBUG(x...) printf("[dkit] " x)
+#define DRIVERKIT_DEBUG(x...) debug_printf("[dkit] " x)
 #else
 #define DRIVERKIT_DEBUG(x...) ((void)0)
 #endif
index d3c63e8..7006c82 100644 (file)
@@ -199,3 +199,16 @@ errval_t driverkit_create_driver(const char* cls, const char* name,
 
     return err;
 }
+
+
+errval_t driverkit_local_service_register(char* name, void* tbl)
+{
+    
+    return SYS_ERR_OK;
+}
+
+void* driverkit_local_service_lookup(char* name)
+{
+
+    return NULL;
+}
index ec7d990..e9a9b2f 100644 (file)
@@ -226,8 +226,7 @@ let bin_rcce_lu = [ "/sbin/" ++ f | f <- [
                            "vnode_map_test",
                            "webserver",
                            "xeon_phi",
-                           "xeon_phi_mgr",
-                           "driverdomain"
+                           "xeon_phi_mgr"
                            ]] ++ modules_common
 
     -- the following are broken in the newidc system
@@ -258,7 +257,6 @@ let bin_rcce_lu = [ "/sbin/" ++ f | f <- [
                         "memtest",
                         "kaluga",
                         "fish",
-                        "sdma",
                         "sdmatest",
                         "sdma_bench",
                         "bulk_sdma",
@@ -268,8 +266,7 @@ let bin_rcce_lu = [ "/sbin/" ++ f | f <- [
                         "serial_kernel",
                         "angler",
                         "corectrl",
-                        "fdif",
-                        "mmchs"
+                        "driverdomain"
                         ] ]
 
     -- ARMv7-A modules for Versatile Express EMM board (GEM5, qemu)
index 9edc4c5..74e9f6b 100644 (file)
@@ -218,7 +218,7 @@ tx_vtbl ifn ml =
 local_connect_handler_fn :: String -> C.Unit
 local_connect_handler_fn ifn = C.FunctionDef C.NoScope (C.TypeName "errval_t")
     (drv_connect_handler_name "local" ifn) local_connect_handler_params [
-    
+
     localvar (C.Ptr $ C.Struct $ export_type ifn) "e" $ Just $ C.Variable "st",
     localvar (C.TypeName "errval_t") "err" Nothing,
     C.SBlank,
index ebe7d5f..a48b20c 100644 (file)
@@ -26,8 +26,9 @@
   build application {
     target = "driverdomain",
     cFiles = [ "main.c"],
-    addModules = ["drivermodule"],
     addLinkFlags = ["-T" ++ Config.source_dir ++ "/lib/driverkit/bfdrivers.ld" ],
-    addLibraries = libDeps [ "driverkit" ]
+    addLibraries = libDeps [ "driverkit", "thc" ],
+    addModules = ["fdif_module", "sdma_module", "cm2_module", "twl6030_module", "mmchs_module"],
+    architectures = ["armv7"]
   }
 ]
index c0604a7..0ecc23e 100644 (file)
@@ -52,15 +52,25 @@ int main(int argc, char** argv)
     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);
+        //printf("%s:%s:%d: Found device driver class = %s\n", __FILE__, __FUNCTION__, __LINE__, cur->name);
         cur += 1;
     }
+    /*for (size_t i=0; i<argc; i++) {
+        printf("%s:%s:%d: argv[i] = %s\n", __FILE__, __FUNCTION__, __LINE__, argv[i]);
+    }*/
 
     iref_t kaluga_iref = 0;
     errval_t err = nameservice_blocking_lookup("ddomain_controller", &kaluga_iref);
     assert(err_is_ok(err));
-    ddomain_communication_init(kaluga_iref);
+    err = ddomain_communication_init(kaluga_iref, atoi(argv[2]));
+    assert(err_is_ok(err));
+
+    while(1) {
+        err = event_dispatch(get_default_waitset());
+        if (err_is_fail(err)) {
+            USER_PANIC_ERR(err, "error in event_dispatch for messages_wait_and_handle_next hack");
+        }
+    }
 
-    messages_handler_loop();
     return 0;
 }
diff --git a/usr/drivers/omap44xx/cm2/Hakefile b/usr/drivers/omap44xx/cm2/Hakefile
new file mode 100644 (file)
index 0000000..6220a45
--- /dev/null
@@ -0,0 +1,25 @@
+--------------------------------------------------------------------------
+-- Copyright (c) 2007-2013, ETH Zurich.
+-- All rights reserved.
+--
+-- This file is distributed under the terms in the attached LICENSE file.
+-- If you do not find this file, copies can be found by writing to:
+-- ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
+--
+-- Hakefile for omap44xx sd-card driver
+--
+--------------------------------------------------------------------------
+
+[
+    build library { target = "cm2_module",
+                    cFiles = [
+                        "cm2.c", "module.c", "service.c"
+                    ],
+                    mackerelDevices = [
+                        "omap/omap44xx_l3init_cm2"
+                    ],
+                    flounderDefs = [ "cm2" ],
+                    flounderBindings = [ "cm2" ],
+                    architectures = ["armv7"]
+    }
+]
similarity index 66%
rename from usr/drivers/omap44xx/mmchs/cm2.c
rename to usr/drivers/omap44xx/cm2/cm2.c
index 0a4d146..44c0c52 100644 (file)
@@ -9,19 +9,16 @@
 #include <barrelfish/barrelfish.h>
 #include <driverkit/driverkit.h>
 
-#include <arch/arm/omap44xx/device_registers.h>
+#include "cm2.h"
 
-#include "mmchs.h"
-#include "cap_slots.h"
-
-void cm2_enable_hsmmc1(struct mmchs_driver_state* st)
+void cm2_enable_hsmmc1(struct cm2_driver_state* st)
 {
     omap44xx_l3init_cm2_cm_l3init_clkstctrl_clktrctrl_wrf(&st->l3init_cm2, 0x2);
     omap44xx_l3init_cm2_cm_l3init_hsmmc1_clkctrl_modulemode_wrf(&st->l3init_cm2, 0x2);
     while (omap44xx_l3init_cm2_cm_l3init_hsmmc1_clkctrl_idlest_rdf(&st->l3init_cm2) != 0x0);
 }
 
-void cm2_enable_i2c(struct mmchs_driver_state* st, size_t i2c_index)
+void cm2_enable_i2c(struct cm2_driver_state* st, size_t i2c_index)
 {
     assert (i2c_index < 4);
 
@@ -30,21 +27,16 @@ void cm2_enable_i2c(struct mmchs_driver_state* st, size_t i2c_index)
             != 0x0);
 }
 
-void cm2_init(struct mmchs_driver_state* st)
+void cm2_init(struct cm2_driver_state* st)
 {
     lvaddr_t l3init_vaddr;
-    errval_t err = map_device_cap(st->caps[CM2_SLOT], &l3init_vaddr);
+    errval_t err = map_device_cap(st->cap, &l3init_vaddr);
     assert(err_is_ok(err));
     omap44xx_l3init_cm2_initialize(&st->l3init_cm2, (mackerel_addr_t)l3init_vaddr);
     omap44xx_l4per_cm2_initialize(&st->l4per_cm2, (mackerel_addr_t)l3init_vaddr);
-
-    lvaddr_t clkgen_vaddr;
-    err = map_device_cap(st->caps[CLKGEN_CM2_SLOT], &clkgen_vaddr);
-    assert(err_is_ok(err));
-    omap44xx_ckgen_cm2_initialize(&st->clkgen_cm2, (mackerel_addr_t)clkgen_vaddr);
 }
 
-int cm2_get_hsmmc1_base_clock(struct mmchs_driver_state* st)
+int cm2_get_hsmmc1_base_clock(struct cm2_driver_state* st)
 {
     return omap44xx_l3init_cm2_cm_l3init_hsmmc1_clkctrl_clksel_rdf(&st->l3init_cm2) == 0x0 ?
            64000000 : 96000000;
diff --git a/usr/drivers/omap44xx/cm2/cm2.h b/usr/drivers/omap44xx/cm2/cm2.h
new file mode 100644 (file)
index 0000000..686fdfd
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012, ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, CAB F.78, Universitaetstr 6, CH-8092 Zurich.
+ */
+
+#ifndef __OMAP44XX_CM2_H__
+#define __OMAP44XX_CM2_H__
+
+#include <barrelfish/barrelfish.h>
+#include <dev/omap/omap44xx_l3init_cm2_dev.h>
+#include <dev/omap/omap44xx_l4per_cm2_dev.h>
+
+
+//#define CM2_DEBUG_ENABLE 1
+
+#if defined(CM2_DEBUG_ENABLE) || defined(GLOBAL_DEBUG)
+#define CM2_DEBUG(x...) printf(x)
+#else
+#define CM2_DEBUG(x...) ((void)0)
+#endif
+
+struct cm2_driver_state {
+    size_t level;
+    struct capref cap;
+    omap44xx_l3init_cm2_t l3init_cm2;
+    omap44xx_l4per_cm2_t l4per_cm2;
+};
+
+/* cm2.c */
+void cm2_enable_i2c(struct cm2_driver_state* st, size_t i2c_index);
+int  cm2_get_hsmmc1_base_clock(struct cm2_driver_state* st);
+void cm2_enable_hsmmc1(struct cm2_driver_state*);
+void cm2_init(struct cm2_driver_state*);
+
+/* service.c */
+void cm2_init_service(struct cm2_driver_state* st, iref_t* iref);
+
+#endif /* __OMAP44XX_CM2_H__ */
diff --git a/usr/drivers/omap44xx/cm2/module.c b/usr/drivers/omap44xx/cm2/module.c
new file mode 100644 (file)
index 0000000..d8e2e4c
--- /dev/null
@@ -0,0 +1,131 @@
+/**
+ * \file
+ * \brief MMCHS Driver main routine.
+ */
+/*
+ * Copyright (c) 2013, ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <barrelfish/barrelfish.h>
+#include <driverkit/driverkit.h>
+
+#include "cm2.h"
+
+/**
+ * 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.
+ *
+ * \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.
+ */
+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) {
+    CM2_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    bfi->dstate = malloc(sizeof(struct cm2_driver_state));
+    if (bfi->dstate == NULL) {
+        return LIB_ERR_MALLOC_FAIL;
+    }
+
+    assert(bfi->dstate != NULL);
+
+    struct cm2_driver_state* st = (struct cm2_driver_state*) bfi->dstate;
+    st->cap = caps[0];
+
+    cm2_init(st);
+    cm2_init_service(st, dev);
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * 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) {
+    CM2_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    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) {
+    CM2_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) {
+    CM2_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    struct cm2_driver_state* uds = bfi->dstate;
+    uds->level = level;
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * Destroys this driver instance. The driver will yield any
+ * control over the device and free any state allocated.
+ *
+ * \param[in]   bfi   The instance of this driver.
+ * \retval SYS_ERR_OK Device initialized successfully.
+ */
+static errval_t destroy(struct bfdriver_instance* bfi) {
+    CM2_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+    struct cm2_driver_state* uds = bfi->dstate;
+    free(uds);
+    bfi->dstate = NULL;
+
+    // XXX: Tear-down the service
+    bfi->device = 0x0;
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * Registers the driver module with the system.
+ */
+DEFINE_MODULE(cm2, init, attach, detach, set_sleep_level, destroy);
diff --git a/usr/drivers/omap44xx/cm2/service.c b/usr/drivers/omap44xx/cm2/service.c
new file mode 100644 (file)
index 0000000..7bb828f
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+ * \file
+ * \brief Implementation of ata_rw28.if interface (to enable working vfs_fat)
+ */
+/*
+ * Copyright (c) 2013, ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include "cm2.h"
+
+#include <barrelfish/barrelfish.h>
+#include <barrelfish/nameservice_client.h>
+#include <if/cm2_defs.h>
+
+static errval_t cm2_enable_i2c_handler(struct cm2_binding *sv, uint32_t index)
+{
+    struct cm2_driver_state* ds = sv->st;
+    cm2_enable_i2c(ds, index);
+    return SYS_ERR_OK;
+}
+
+static errval_t cm2_get_hsmmc1_base_clock_handler(struct cm2_binding *sv, uint32_t* clock)
+{
+    struct cm2_driver_state* ds = sv->st;
+    *clock = cm2_get_hsmmc1_base_clock(ds);
+    return SYS_ERR_OK;
+}
+
+static errval_t cm2_enable_hsmmc1_handler(struct cm2_binding *sv)
+{
+    struct cm2_driver_state* ds = sv->st;
+    cm2_enable_hsmmc1(ds);
+    return SYS_ERR_OK;
+}
+
+static struct export_state {
+    struct cm2_binding* b;
+    bool is_done;
+    errval_t err;
+    iref_t iref;
+} service_export;
+
+static void export_cb(void *st, errval_t err, iref_t iref)
+{
+    service_export.is_done = true;
+    service_export.err = err;
+    service_export.iref = iref;
+
+    if (err_is_ok(err)) {
+        CM2_DEBUG("Exported ddomain service with iref: %"PRIu32"\n", iref);
+        err = nameservice_register("cm2", iref);
+        assert(err_is_ok(err));
+    }
+}
+static const struct cm2_rpc_rx_vtbl rx_vtbl = {
+    .enable_i2c_call = cm2_enable_i2c_handler,
+    .get_hsmmc1_base_clock_call = cm2_get_hsmmc1_base_clock_handler,
+    .enable_hsmmc1_call = cm2_enable_hsmmc1_handler
+};
+
+static errval_t client_connect(void *st, struct cm2_binding *b)
+{
+    service_export.b = b;
+    b->rpc_rx_vtbl = rx_vtbl;
+    b->st = st;
+    return SYS_ERR_OK;
+}
+
+void cm2_init_service(struct cm2_driver_state* st, iref_t* iref)
+{
+    errval_t err;
+    CM2_DEBUG("%s:%d: Starting server\n", __FUNCTION__, __LINE__);
+    err = cm2_export(st, export_cb, client_connect, get_default_waitset(), IDC_EXPORT_FLAGS_DEFAULT);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
+
+    while(!service_export.is_done) {
+        messages_wait_and_handle_next();
+    }
+
+    *iref = service_export.iref;
+    CM2_DEBUG("Service cm2 exported.\n");
+}
index 9ac4dac..913fd73 100644 (file)
         "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" ]
+    architectures = ["armv7"]
   }
 ]
index c938492..fc506c6 100644 (file)
@@ -45,14 +45,14 @@ struct fdif_driver_state {
     char printbuf[PRINT_BUFFER_SIZE];
 };
 
-static void manage_clocks(struct fdif_driver_state* st)
+static void manage_clocks(struct fdif_driver_state* st, struct capref caps[])
 {
     FDIF_DEBUG("Enable the clocks in domain CD_CAM\n");
 
     // Clock domain CAM
     lvaddr_t vbase;
     errval_t err;
-    err = map_device_register(0x4A009000, 4096, &vbase);
+    err = map_device_cap(caps[0], &vbase); // 0x4A009000, 4096
     assert(err_is_ok(err));
 
     omap44xx_cam_cm2_initialize(&st->devclk, (mackerel_addr_t)vbase);
@@ -65,14 +65,14 @@ static void manage_clocks(struct fdif_driver_state* st)
     omap44xx_cam_cm2_cm_cam_clkstctrl_clktrctrl_wrf(&st->devclk, 0x2);
 }
 
-static void manage_power(struct fdif_driver_state* st)
+static void manage_power(struct fdif_driver_state* st, struct capref caps[])
 {
     FDIF_DEBUG("Power-on the PD_CAM domain for fdif\n");
 
     // Power domain CAM
     lvaddr_t vbase;
     errval_t err;
-    err = map_device_register(0x4A307000, 4096, &vbase);
+    err = map_device_cap(caps[2], &vbase); // 0x4A307000, 4096
     assert(err_is_ok(err));
 
     omap44xx_cam_prm_initialize(&st->dev, (mackerel_addr_t)vbase);
@@ -116,13 +116,13 @@ static void irq_handler(void *args)
     read_result(st);
 
     omap44xx_fdif_fdif_ctrl_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devfdif);
-    printf("%s\n", st->printbuf);
+    FDIF_DEBUG("%s\n", st->printbuf);
 
     omap44xx_cam_cm2_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devclk);
-    printf("%s\n", st->printbuf);
+    FDIF_DEBUG("%s\n", st->printbuf);
 
     omap44xx_cam_prm_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->dev);
-    printf("%s\n", st->printbuf);
+    FDIF_DEBUG("%s\n", st->printbuf);
 
 
     omap44xx_fdif_fdif_irqstatus_finish_irq_wrf(&st->devfdif, 2, 1);
@@ -255,26 +255,26 @@ static errval_t init(struct bfdriver_instance* bfi, const char* name, uint64_t f
     lpaddr_t vbase;
 
     // Face detect Module
-    err = map_device_cap(caps[0], &vbase);
+    err = map_device_cap(caps[3], &vbase);
     assert(err_is_ok(err));
     omap44xx_fdif_initialize(&st->devfdif, (mackerel_addr_t)vbase);
 
     FDIF_DEBUG("FDIF Global Initialization\n");
 
-    manage_clocks(st);
-    manage_power(st);
+    manage_clocks(st, caps);
+    manage_power(st, caps);
 
     omap44xx_fdif_fdif_sysconfig_softreset_wrf(&st->devfdif, 1);
     while (omap44xx_fdif_fdif_sysconfig_softreset_rdf(&st->devfdif) != 0);
 
     omap44xx_fdif_fdif_sysconfig_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devfdif);
-    printf("%s\n", st->printbuf);
+    FDIF_DEBUG("%s\n", st->printbuf);
 
     omap44xx_fdif_fdif_sysconfig_idlemode_wrf(&st->devfdif, 0x2);
     omap44xx_fdif_fdif_sysconfig_standbymode_wrf(&st->devfdif, 0x2);
 
     omap44xx_fdif_fdif_sysconfig_pr(st->printbuf, PRINT_BUFFER_SIZE, &st->devfdif);
-    printf("%s\n", st->printbuf);
+    FDIF_DEBUG("%s\n", st->printbuf);
 
     omap44xx_fdif_fdif_ctrl_max_tags_wrf(&st->devfdif, 0xA);
 
index ceb0509..aeb7bc9 100644 (file)
@@ -18,10 +18,17 @@ void play_with_fdif(void);
 struct gimage {
   uint32_t       width;
   uint32_t       height;
-  uint32_t       bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ 
+  uint32_t       bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
   uint8_t    pixel_data[320 * 240];
 };
 
-#define FDIF_DEBUG(x...) printf("fdif: " x)
+//#define FDIF_DEBUG_ON 1
 
-#endif // FDIF_H_
\ No newline at end of file
+#if defined(FDIF_DEBUG_ON) || defined(GLOBAL_DEBUG)
+#define FDIF_DEBUG(x...) debug_printf(x)
+#else
+#define FDIF_DEBUG(x...) ((void)0)
+#endif
+
+
+#endif // FDIF_H_
diff --git a/usr/drivers/omap44xx/fdif/fdif_domain.c b/usr/drivers/omap44xx/fdif/fdif_domain.c
deleted file mode 100644 (file)
index 416f6f0..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-#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>
-
-/// XXX: TODO not needed once kaluga <-> driver domain communicate over dcontrol iface
-static errval_t find_cap_for(lpaddr_t address, size_t size, struct capref* out)
-{
-    errval_t err;
-    struct cnoderef argcn_cnref = {
-        .croot = CPTR_ROOTCN,
-        .cnode = ROOTCN_SLOT_ADDR(ROOTCN_SLOT_ARGCN),
-        .level = CNODE_TYPE_OTHER,
-    };
-
-    struct capref device_cap_iter = {
-        .cnode = argcn_cnref,
-        .slot = 0
-    };
-
-    for (; device_cap_iter.slot < L2_CNODE_SLOTS; device_cap_iter.slot++) {
-        // Get cap data
-        struct capability cap;
-        err = debug_cap_identify(device_cap_iter, &cap);
-        // If cap type was Null, kernel returns error
-        if (err_no(err) == SYS_ERR_IDENTIFY_LOOKUP ||
-            err_no(err) == SYS_ERR_CAP_NOT_FOUND ||
-            err_no(err) == SYS_ERR_LMP_CAPTRANSFER_SRC_LOOKUP) {
-            continue;
-        }
-
-        struct frame_identity fid;
-        err = frame_identify(device_cap_iter, &fid);
-        if (err_is_fail(err)) {
-            DEBUG_ERR(err, "Failure in frame_identify");
-            return err;
-        }
-        assert(err_is_ok(err));
-
-        lpaddr_t address_base = address & ~(BASE_PAGE_SIZE-1);
-        // XXX: should be address+size <= ...
-        // Need to add proper register size
-        if (address_base >= fid.base &&
-                (address_base + size) <= (fid.base + fid.bytes)) {
-            *out = device_cap_iter;
-            return SYS_ERR_OK;
-        }
-    }
-
-    return DRIVERKIT_ERR_NO_CAP_FOUND;
-}
-
-
-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;
-    }
-
-    struct capref* caps = calloc(1, sizeof(struct capref));
-    errval_t err = find_cap_for(0x4A10A000, 4096, &caps[0]);
-    if (err_is_fail(err)) {
-        USER_PANIC_ERR(err, "finding cap failed.");
-    }
-    iref_t dev, ctrl;
-    driverkit_create_driver("fdif", "fdif_inst", caps, 1, NULL, 0, 0, &dev, &ctrl);
-
-    messages_handler_loop();
-    return 0;
-}
index e5f39d5..d3eea2d 100644 (file)
 [
     build library { target = "mmchs_module",
                     cFiles = [
-                        "main.c", "cm2.c", "ctrlmod.c",
-                        "i2c.c", "mmchs.c", "twl6030.c",
-                        "service.c"
+                        "main.c", "ctrlmod.c",
+                        "mmchs.c", "service.c"
                     ],
                     mackerelDevices = [
-                        "ti_i2c",
-                        "ti_twl6030",
                         "omap/omap44xx_mmchs1",
-                        "omap/omap44xx_sysctrl_padconf_core",
-                        "omap/omap44xx_l3init_cm2",
-                        "omap/omap44xx_ckgen_cm2",
-                        "omap/omap44xx_l4per_cm2"
+                        "omap/omap44xx_sysctrl_padconf_core"
                     ],
 
-                    flounderDefs = [ "ata_rw28" ],
+                    flounderDefs = [ "ata_rw28", "cm2", "twl6030" ],
                     flounderBindings = [ "ata_rw28" ],
                     flounderTHCStubs = [ "ata_rw28" ],
 
-                    addLibraries = [ "driverkit", "thc" ],
                     architectures = ["armv7"]
-    },
-
-    build application {
-        target = "mmchs",
-        cFiles = [ "mmchs_domain.c"],
-        addModules = ["mmchs_module"],
-        addLinkFlags = ["-T" ++ Config.source_dir ++ "/lib/driverkit/bfdrivers.ld" ],
-        mackerelDevices = [
-            "ti_i2c",
-            "ti_twl6030",
-            "omap/omap44xx_mmchs1",
-            "omap/omap44xx_sysctrl_padconf_core",
-            "omap/omap44xx_l3init_cm2",
-            "omap/omap44xx_ckgen_cm2",
-            "omap/omap44xx_l4per_cm2"
-        ]
     }
+
 ]
index c2bc327..b3839e4 100644 (file)
 #ifndef __CAP_SLOTS__
 #define __CAP_SLOTS__
 
-#define CM2_SLOT 0
-#define CLKGEN_CM2_SLOT 1
-#define IC2_SLOT 2
-#define L4_PER_HSMMC1_SLOT 3
-#define PADCONF_CORE_SLOT 4
+#define PADCONF_CORE_SLOT 0
+#define L4_PER_HSMMC1_SLOT 1
 
 #endif // __CAP_SLOTS__
index 8c645f2..4f8dca0 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <driverkit/driverkit.h>
 
-#include "twl6030.h"
 #include "omap44xx_ctrlmod.h"
 
 #include "mmchs.h"
@@ -99,7 +98,7 @@ void sdmmc1_enable_power(struct mmchs_driver_state* st)
 
     // Step 3: Program desired SDMMC1_VDDS for MMC I/O in I2C attached power
     // controller (3.0V)
-    errval_t err = ti_twl6030_set_vmmc_vsel(st->twl, 3000);
+    errval_t err = st->twl6030_binding->rpc_tx_vtbl.vmmc_vsel(st->twl6030_binding, 3000);
     assert(err_is_ok(err));
 
     // Step 4: Set VMODE bit according to Step 3 (0x1 == 3.0V)
index 6a9f512..60acc3f 100644 (file)
 #include <assert.h>
 
 #include <barrelfish/barrelfish.h>
+#include <barrelfish/nameservice_client.h>
 #include <driverkit/driverkit.h>
 
 #include "mmchs.h"
 
+
+static void cm2_connected(void *st, errval_t err, struct cm2_binding *b) {
+    MMCHS_DEBUG("Connected to cm2 driver\n");
+    assert(err_is_ok(err));
+    struct mmchs_driver_state* dst = (struct mmchs_driver_state*) st;
+    cm2_rpc_client_init(b);
+    dst->cm2_binding = b;
+}
+
+static void twl6030_connected(void *st, errval_t err, struct twl6030_binding *b) {
+    MMCHS_DEBUG("Connected to twl6030 driver\n");
+    assert(err_is_ok(err));
+    struct mmchs_driver_state* dst = (struct mmchs_driver_state*) st;
+    twl6030_rpc_client_init(b);
+    dst->twl6030_binding = b;
+}
+
+
 /**
  * Driver initialization function. This function is called by the driver domain
  * (see also 'create_handler' in ddomain_service.c).
@@ -51,19 +70,46 @@ static errval_t init(struct bfdriver_instance* bfi, const char* name, uint64_t f
     struct mmchs_driver_state* st = (struct mmchs_driver_state*) bfi->dstate;
     st->caps = caps;
 
+    // Connect to the cm2 driver
+    iref_t cm2_iref;
+    errval_t err = nameservice_lookup("cm2", &cm2_iref);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "finding cm2 service failed.");
+    }
+    err = cm2_bind(cm2_iref, cm2_connected, st, get_default_waitset(), IDC_EXPORT_FLAG_NO_NOTIFY);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
+    while(st->cm2_binding == NULL) {
+        messages_wait_and_handle_next();
+    }
+    assert(st->cm2_binding != NULL);
+
+    // Connect to the twl6030 driver
+    iref_t twl6030_iref;
+    err = nameservice_lookup("twl6030", &twl6030_iref);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "finding cm2 service failed.");
+    }
+    err = twl6030_bind(twl6030_iref, twl6030_connected, st, get_default_waitset(), IDC_EXPORT_FLAG_NO_NOTIFY);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
+    while(st->twl6030_binding == NULL) {
+        messages_wait_and_handle_next();
+    }
+    assert(st->twl6030_binding != NULL);
+
     // 1. Initialize the device:
-    cm2_init(st);
-    ti_twl6030_init(st);
     ctrlmod_init(st);
-    cm2_enable_hsmmc1(st);
+    err = st->cm2_binding->rpc_tx_vtbl.enable_hsmmc1(st->cm2_binding);
+    assert(err_is_ok(err));
     sdmmc1_enable_power(st);
     mmchs_init(st);
 
     // 2. Export service to talk to the device:
-    init_service(st);
-
-    // 3. Set iref of your exported service (this is reported back to Kaluga)
-    *dev = 0x00;
+    // FYI: Making this use THC+thread currently fails somewhere in the THC runtime
+    mmchs_init_service(st, dev);
 
     return SYS_ERR_OK;
 }
index a208ea0..1640464 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <driverkit/driverkit.h>
 #include <arch/arm/omap44xx/device_registers.h>
+#include <if/cm2_defs.h>
 
 #include "mmchs.h"
 #include "cap_slots.h"
@@ -72,7 +73,9 @@ static void mmc_host_and_bus_configuration(struct mmchs_driver_state* st)
     omap44xx_mmchs1_mmchs_sysctl_cen_wrf(&st->mmchs, 0x0);
     omap44xx_mmchs1_mmchs_sysctl_ice_wrf(&st->mmchs, 0x1);
 
-    MMCHS_DEBUG("%s:%d: clksel = %u\n", __FUNCTION__, __LINE__, cm2_get_hsmmc1_base_clock(st));
+    uint32_t clock = 0;
+    st->cm2_binding->rpc_tx_vtbl.get_hsmmc1_base_clock(st->cm2_binding, &clock);
+    MMCHS_DEBUG("%s:%d: clksel = %u\n", __FUNCTION__, __LINE__, clock);
     change_clock_frequency_to_fit_protocol(st, 0x258);
 
     MMCHS_DEBUG("%s:%d: Wait until internal clock is stable.\n", __FUNCTION__, __LINE__);
index 0680279..b11d437 100644 (file)
 
 #include <barrelfish/barrelfish.h>
 #include <dev/omap/omap44xx_mmchs1_dev.h>
-#include <dev/omap/omap44xx_l3init_cm2_dev.h>
-#include <dev/omap/omap44xx_ckgen_cm2_dev.h>
-#include <dev/omap/omap44xx_l4per_cm2_dev.h>
+
+#include <if/twl6030_defs.h>
+#include <if/cm2_defs.h>
 
 #include "mmchs_debug.h"
-#include "omap44xx_cm2.h"
 #include "omap44xx_ctrlmod.h"
-#include "i2c.h"
-#include "twl6030.h"
 
 #define DBUF_SIZE (10*4096)
 
 struct mmchs_driver_state {
     uint64_t level;
+    iref_t iref;
 
-    omap44xx_l3init_cm2_t l3init_cm2;
-    omap44xx_l4per_cm2_t l4per_cm2;
-    omap44xx_ckgen_cm2_t clkgen_cm2;
     omap44xx_sysctrl_padconf_core_t ctrlmod;
     omap44xx_mmchs1_t mmchs;
-    ti_twl6030_t twl;
-
-    struct capref* caps;
 
+    struct cm2_binding* cm2_binding;
+    struct twl6030_binding* twl6030_binding;
 
+    struct capref* caps;
     char dbuf[DBUF_SIZE];
 };
 
@@ -44,6 +39,6 @@ void mmchs_init(struct mmchs_driver_state*);
 errval_t mmchs_read_block(struct mmchs_driver_state*, size_t block_nr, void *buffer);
 errval_t mmchs_write_block(struct mmchs_driver_state*, size_t block_nr, void *buffer);
 
-void init_service(struct mmchs_driver_state*);
+void mmchs_init_service(struct mmchs_driver_state*, iref_t* iref);
 
 #endif // MMCHS2_H
index 74172fa..c9d7f82 100644 (file)
@@ -10,7 +10,7 @@
 #ifndef MMCHS2_DEBUG_H
 #define MMCHS2_DEBUG_H
 
-#define MMCHS_SERVICE_DEBUG 1
+//#define MMCHS_SERVICE_DEBUG 1
 
 #if defined(MMCHS_SERVICE_DEBUG) || defined(GLOBAL_DEBUG)
 #define MMCHS_DEBUG(x...) debug_printf(x)
diff --git a/usr/drivers/omap44xx/mmchs/mmchs_domain.c b/usr/drivers/omap44xx/mmchs/mmchs_domain.c
deleted file mode 100644 (file)
index ccc4ce0..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-#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>
-
-#include "i2c.h"
-#include "twl6030.h"
-#include <arch/arm/omap44xx/device_registers.h>
-#include <maps/omap44xx_map.h>
-
-#include "cap_slots.h"
-
-/// XXX: TODO not needed once kaluga <-> driver domain communicate over dcontrol iface
-static errval_t find_cap_for(lpaddr_t address, size_t size, struct capref* out)
-{
-    errval_t err;
-    struct cnoderef argcn_cnref = {
-        .croot = CPTR_ROOTCN,
-        .cnode = ROOTCN_SLOT_ADDR(ROOTCN_SLOT_ARGCN),
-        .level = CNODE_TYPE_OTHER,
-    };
-
-    struct capref device_cap_iter = {
-        .cnode = argcn_cnref,
-        .slot = 0
-    };
-
-    for (; device_cap_iter.slot < L2_CNODE_SLOTS; device_cap_iter.slot++) {
-        // Get cap data
-        struct capability cap;
-        err = debug_cap_identify(device_cap_iter, &cap);
-        // If cap type was Null, kernel returns error
-        if (err_no(err) == SYS_ERR_IDENTIFY_LOOKUP ||
-            err_no(err) == SYS_ERR_CAP_NOT_FOUND ||
-            err_no(err) == SYS_ERR_LMP_CAPTRANSFER_SRC_LOOKUP) {
-            continue;
-        }
-
-        struct frame_identity fid;
-        err = frame_identify(device_cap_iter, &fid);
-        if (err_is_fail(err)) {
-            DEBUG_ERR(err, "Failure in frame_identify");
-            return err;
-        }
-        assert(err_is_ok(err));
-
-        lpaddr_t address_base = address & ~(BASE_PAGE_SIZE-1);
-        // XXX: should be address+size <= ...
-        // Need to add proper register size
-        if (address_base >= fid.base &&
-                (address_base + size) <= (fid.base + fid.bytes)) {
-            *out = device_cap_iter;
-            return SYS_ERR_OK;
-        }
-    }
-
-    return DRIVERKIT_ERR_NO_CAP_FOUND;
-}
-
-
-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;
-    }
-
-    struct capref* caps = calloc(5, sizeof(struct capref));
-
-
-    errval_t err = find_cap_for(OMAP44XX_CM2, 0x1000, &caps[CM2_SLOT]);
-    if (err_is_fail(err)) {
-        USER_PANIC_ERR(err, "finding cap failed.");
-    }
-    err = find_cap_for(OMAP44XX_CLKGEN_CM2, 0x1000, &caps[CLKGEN_CM2_SLOT]);
-    if (err_is_fail(err)) {
-        USER_PANIC_ERR(err, "finding cap failed.");
-    }
-    err = find_cap_for(i2c_get_pbase(I2C_HC), 0x1000, &caps[IC2_SLOT]);
-    if (err_is_fail(err)) {
-        USER_PANIC_ERR(err, "finding cap failed.");
-    }
-#define SYSCTRL_PADCONF_CORE 0x4a100000u
-    err = find_cap_for(SYSCTRL_PADCONF_CORE, 0x1000, &caps[PADCONF_CORE_SLOT]);
-    if (err_is_fail(err)) {
-        USER_PANIC_ERR(err, "finding cap failed.");
-    }
-    err = find_cap_for(OMAP44XX_MAP_L4_PER_HSMMC1, OMAP44XX_MAP_L4_PER_HSMMC1_SIZE, &caps[L4_PER_HSMMC1_SLOT]);
-    if (err_is_fail(err)) {
-        USER_PANIC_ERR(err, "finding cap failed.");
-    }
-
-    iref_t dev, ctrl;
-    driverkit_create_driver("mmchs", "mmchs_inst", caps, 1, NULL, 0, 0, &dev, &ctrl);
-
-    messages_handler_loop();
-    return 0;
-}
diff --git a/usr/drivers/omap44xx/mmchs/omap44xx_cm2.h b/usr/drivers/omap44xx/mmchs/omap44xx_cm2.h
deleted file mode 100644 (file)
index e88ea4b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2012, ETH Zurich.
- * All rights reserved.
- *
- * This file is distributed under the terms in the attached LICENSE file.
- * If you do not find this file, copies can be found by writing to:
- * ETH Zurich D-INFK, CAB F.78, Universitaetstr 6, CH-8092 Zurich.
- */
-
-#ifndef __OMAP44XX_CM2_H__
-#define __OMAP44XX_CM2_H__
-
-#include <barrelfish/barrelfish.h>
-#include <dev/omap/omap44xx_l3init_cm2_dev.h>
-#include <dev/omap/omap44xx_ckgen_cm2_dev.h>
-#include <dev/omap/omap44xx_l4per_cm2_dev.h>
-
-struct mmchs_driver_state;
-
-void cm2_enable_i2c(struct mmchs_driver_state* st, size_t i2c_index);
-int  cm2_get_hsmmc1_base_clock(struct mmchs_driver_state* st);
-void cm2_enable_hsmmc1(struct mmchs_driver_state*);
-void cm2_init(struct mmchs_driver_state*);
-
-#endif /* __OMAP44XX_CM2_H__ */
index 135d837..5a0fc71 100644 (file)
@@ -21,7 +21,6 @@
 #include <barrelfish/nameservice_client.h>
 
 #include <if/ata_rw28_defs.h>
-#include <if/ata_rw28_thc.h>
 #include <thc/thc.h>
 
 #include "mmchs.h"
 #define SECTION_SIZE 512
 #define SECTION_ROUND_UP(x) ( ((x) + (SECTION_SIZE-1))  & (~(SECTION_SIZE-1)) )
 
-static void read_dma(struct mmchs_driver_state* st, struct ata_rw28_thc_service_binding_t *sv,
+static void read_dma(struct ata_rw28_binding *sv,
                      uint32_t read_size, uint32_t start_lba)
 {
+    struct mmchs_driver_state* st = (struct mmchs_driver_state*)sv->st;
+
     size_t buffer_size = SECTION_ROUND_UP(read_size);
     MMCHS_DEBUG("%s:%d read_size=%d buffer_size=%d\n", __FUNCTION__, __LINE__, read_size, buffer_size);
     void *buffer = malloc(buffer_size);
@@ -45,132 +46,106 @@ static void read_dma(struct mmchs_driver_state* st, struct ata_rw28_thc_service_
         assert(err_is_ok(err));
         bufptr += SECTION_SIZE;
     }
-    sv->send.read_dma(sv, buffer, buffer_size);
-    free(buffer);
+
+    errval_t err = ata_rw28_read_dma_response__tx(sv, MKCLOSURE(free, buffer), buffer, buffer_size);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
 }
 
-static void read_dma_block(struct mmchs_driver_state* st, struct ata_rw28_thc_service_binding_t *sv, uint32_t lba)
+static void read_dma_block(struct ata_rw28_binding *sv, uint32_t lba)
 {
     MMCHS_DEBUG("%s:%d lba=%d\n", __FUNCTION__, __LINE__, lba);
 
+    struct mmchs_driver_state* st = (struct mmchs_driver_state*)sv->st;
+
     void *buffer = malloc(SECTION_SIZE);
     assert(buffer != NULL);
 
     errval_t err = mmchs_read_block(st, lba, buffer);
     assert(err_is_ok(err));
 
-    sv->send.read_dma_block(sv, buffer, SECTION_SIZE);
-    free(buffer);
+    err = ata_rw28_read_dma_block_response__tx(sv, MKCLOSURE(free, buffer), buffer, SECTION_SIZE);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
 }
 
-static void write_dma(struct mmchs_driver_state* st, struct ata_rw28_thc_service_binding_t *sv,
-                      uint8_t *buffer, size_t buffer_len, uint32_t lba)
+/*static void write_dma(struct ata_rw28_binding *sv,
+                      uint8_t *buffer, size_t buffer_size, uint32_t lba)
 {
     MMCHS_DEBUG("%s:%d\n", __FUNCTION__, __LINE__);
-    sv->send.write_dma(sv, LIB_ERR_NOT_IMPLEMENTED);
-}
+    errval_t err = ata_rw28_write_dma_response__tx(sv, MKCLOSURE(free, buffer), LIB_ERR_NOT_IMPLEMENTED);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
+}*/
 
-static void identify_device(struct mmchs_driver_state* st, struct ata_rw28_thc_service_binding_t *sv)
+static void identify_device(struct ata_rw28_binding *sv)
 {
     MMCHS_DEBUG("%s:%d\n", __FUNCTION__, __LINE__);
-    sv->send.identify_device(sv, NULL, 0);
+    errval_t err = ata_rw28_identify_device_response__tx(sv, NOP_CONT, NULL, 0);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
 }
 
-
-static void flush_cache(struct mmchs_driver_state* st, struct ata_rw28_thc_service_binding_t *sv)
+static void flush_cache(struct ata_rw28_binding *sv)
 {
     MMCHS_DEBUG("%s:%d\n", __FUNCTION__, __LINE__);
-    sv->send.flush_cache(sv, SYS_ERR_OK);
+    errval_t err = ata_rw28_flush_cache_response__tx(sv, NOP_CONT, SYS_ERR_OK);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
 }
 
-static void service_client(struct mmchs_driver_state* st, struct ata_rw28_thc_service_binding_t *sv)
+static struct export_state {
+    struct ata_rw28_binding* b;
+    bool is_done;
+    errval_t err;
+    iref_t iref;
+} service_export;
+
+static void export_cb(void *st, errval_t err, iref_t iref)
+{
+    service_export.is_done = true;
+    service_export.err = err;
+    service_export.iref = iref;
+
+    if (err_is_ok(err)) {
+        MMCHS_DEBUG("Exported ddomain service with iref: %"PRIu32"\n", iref);
+        err = nameservice_register("mmchs", iref);
+        assert(err_is_ok(err));
+    }
+}
+static const struct ata_rw28_rx_vtbl rx_vtbl = {
+    .read_dma_call = read_dma,
+    .read_dma_block_call = read_dma_block,
+    //.write_dma_call = write_dma,
+    .identify_device_call = identify_device,
+    .flush_cache_call = flush_cache,
+};
+
+static errval_t client_connect(void *st, struct ata_rw28_binding *b)
 {
-    DO_FINISH({
-        bool stop = false;
-        while (!stop) {
-            ata_rw28_service_msg_t m;
-            sv->recv_any(sv, &m, (struct ata_rw28_service_selector) {
-                .read_dma = 1,
-                .read_dma_block = 1,
-                .write_dma = 1,
-                .identify_device = 1,
-                .flush_cache = 1
-            });
-
-            switch (m.msg) {
-
-            case ata_rw28_read_dma:
-                read_dma(st, sv, m.args.read_dma.in.read_size, m.args.read_dma.in.start_lba);
-                break;
-
-            case ata_rw28_read_dma_block:
-                read_dma_block(st, sv, m.args.read_dma_block.in.lba);
-                break;
-
-            case ata_rw28_write_dma:
-                write_dma(st, sv, m.args.write_dma.in.buffer, m.args.write_dma.in.buffer_size, m.args.write_dma.in.lba);
-                break;
-
-            case ata_rw28_identify_device:
-                identify_device(st, sv);
-                break;
-
-            case ata_rw28_flush_cache:
-                flush_cache(st, sv);
-                break;
-
-            default:
-                assert(!"Unexpected message");
-                break;
-            }
-        }
-    });
+    service_export.b = b;
+    b->st = st;
+    return SYS_ERR_OK;
 }
 
-void init_service(struct mmchs_driver_state* st)
+
+void mmchs_init_service(struct mmchs_driver_state* st, iref_t* iref)
 {
     errval_t err;
-    iref_t iref;
-    struct ata_rw28_thc_service_binding_t *sv;
-    struct ata_rw28_binding *b;
-    struct ata_rw28_thc_export_info info;
-
     MMCHS_DEBUG("%s:%d: Starting server\n", __FUNCTION__, __LINE__);
-    err = ata_rw28_thc_export(&info,
-                              "mmchs",
-                              get_default_waitset(),
-                              IDC_EXPORT_FLAGS_DEFAULT,
-                              &iref);
-
-    MMCHS_DEBUG("%s:%d: Done export iref=%"PRIuIREF"\n", __FUNCTION__, __LINE__, iref);
+    err = ata_rw28_export(st, export_cb, client_connect, get_default_waitset(), IDC_EXPORT_FLAGS_DEFAULT);
     if (err_is_fail(err)) {
-        DEBUG_ERR(err, "export failed");
-        abort();
+        USER_PANIC_ERR(err, "call failed.");
     }
 
-    DO_FINISH({
-        while (1) {
-            MMCHS_DEBUG("%s:%d: Server waiting for connection\n", __FUNCTION__, __LINE__);
-            err = ata_rw28_thc_accept(&info, &b);
-            if (err_is_fail(err)) {
-                DEBUG_ERR(err, "accept failed");
-                abort();
-            }
-
-            sv = malloc(sizeof(struct ata_rw28_thc_service_binding_t));
-            if (sv == NULL) {
-                DEBUG_ERR(err, "malloc failed");
-                abort();
-            }
-
-            err = ata_rw28_thc_init_service(sv, b, b);
-            if (err_is_fail(err)) {
-                DEBUG_ERR(err, "init failed");
-                abort();
-            }
-
-            MMCHS_DEBUG("%s:%d: Got service %p\n", __FUNCTION__, __LINE__, sv);
-            ASYNC({service_client(st, sv);});
-        }
-    });
+    while(!service_export.is_done) {
+        messages_wait_and_handle_next();
+    }
+    *iref = service_export.iref;
+    MMCHS_DEBUG("Service mmchs exported.\n");
 }
index 726a94e..0bb7c21 100644 (file)
 --------------------------------------------------------------------------
 
 [
-    build application { target = "sdma",
-                    cFiles = (find withSuffices [".c"]),
+    build library { target = "sdma_module",
+                    cFiles = ["main.c", "omap_sdma.c", "service.c"],
                     mackerelDevices = [ "omap/omap44xx_sdma" ],
 
                     flounderDefs = [ "omap_sdma" ],
                     flounderBindings = [ "omap_sdma" ],
                     flounderTHCStubs = [ "omap_sdma" ],
 
-                    addLibraries = ["driverkit", "thc"],
                     architectures = ["armv7"]
-                  }
+    }
 ]
index 39afc91..023db11 100644 (file)
 
 #define MIN(a,b) (((a)<(b))?(a):(b))
 
-// Channel State. Filled by the interrupt callback, read by the request task.
-static struct {
-    awe_t *request;
-    errval_t err;
-} channel_state[OMAP44XX_SDMA_NUM_CHANNEL];
-
 /**
  * \brief Interrupt callback which will be called when a channel interrupt
  * occurs.
@@ -38,10 +32,10 @@ static struct {
  * \param channel   Channel which triggered the interrupt
  * \param err       State of the channel, SYS_ERR_OK if transfer completed
  */
-static void sdma_irq_handler(omap_sdma_channel_t channel, errval_t err)
+static void sdma_irq_handler(struct sdma_driver_state* st, omap_sdma_channel_t channel, errval_t err)
 {
-    channel_state[channel].err = err;
-    THCSchedule(channel_state[channel].request);
+    st->channel_state[channel].err = err;
+    THCSchedule(st->channel_state[channel].request);
 }
 
 /**
@@ -50,25 +44,25 @@ static void sdma_irq_handler(omap_sdma_channel_t channel, errval_t err)
  *
  * \param conf   Pointer to valid & initialized channel configuration
  */
-static errval_t run_omap_sdma_transfer(struct omap_sdma_channel_conf *conf)
+static errval_t run_omap_sdma_transfer(struct sdma_driver_state* st, struct omap_sdma_channel_conf *conf)
 {
     errval_t err;
     omap_sdma_channel_t channel;
 
-    err = omap_sdma_allocate_channel(&channel);
+    err = omap_sdma_allocate_channel(st, &channel);
     if (err_is_fail(err)) return err;
 
     // configure and enable allocated channel
-    omap_sdma_set_channel_conf(channel, conf);
-    omap_sdma_enable_channel(channel, true);
+    omap_sdma_set_channel_conf(st, channel, conf);
+    omap_sdma_enable_channel(st, channel, true);
 
     // this task will be rescheduled by the IRQ handler
-    THCSuspend(&channel_state[channel].request);
+    THCSuspend(&st->channel_state[channel].request);
 
     // read status flag set by IRQ handler
-    err = channel_state[channel].err;
+    err = st->channel_state[channel].err;
 
-    omap_sdma_free_channel(channel);
+    omap_sdma_free_channel(st, channel);
 
     return err;
 }
@@ -313,7 +307,7 @@ static errval_t frame_address_2d(struct capref cap, omap_sdma_addr_2d_t *addr,
  * \brief Stub to perform simple frame-to-frame memory copy
  * \see   Flounder definition in if/omap_sdma.if
  */
-errval_t mem_copy(struct capref dst_cap, struct capref src_cap)
+errval_t mem_copy(struct sdma_driver_state* st, struct capref dst_cap, struct capref src_cap)
 {
     errval_t err;
     omap_sdma_count_2d_t count;
@@ -333,7 +327,7 @@ errval_t mem_copy(struct capref dst_cap, struct capref src_cap)
     struct omap_sdma_channel_conf conf;
     init_channel_conf(&conf, dst_id.base, src_id.base, 1, 1, 1, 1, count,
                          omap44xx_sdma_DISABLE_COLOR_MODE, 0);
-    err = run_omap_sdma_transfer(&conf);
+    err = run_omap_sdma_transfer(st, &conf);
 
     return err;
 }
@@ -342,7 +336,7 @@ errval_t mem_copy(struct capref dst_cap, struct capref src_cap)
  * \brief Stub to fill a memory frame with a constant value
  * \see   Flounder definition in if/omap_sdma.if
  */
-errval_t mem_fill(struct capref dst_cap, uint8_t color)
+errval_t mem_fill(struct sdma_driver_state* st, struct capref dst_cap, uint8_t color)
 {
     errval_t err;
     omap_sdma_count_2d_t count;
@@ -357,7 +351,7 @@ errval_t mem_fill(struct capref dst_cap, uint8_t color)
     struct omap_sdma_channel_conf conf;
     init_channel_conf(&conf, dst_id.base, 0, 1, 1, 1, 1, count,
                          omap44xx_sdma_CONSTANT_FILL, color);
-    err = run_omap_sdma_transfer(&conf);
+    err = run_omap_sdma_transfer(st, &conf);
 
     return err;
 }
@@ -366,8 +360,8 @@ errval_t mem_fill(struct capref dst_cap, uint8_t color)
  * \brief Stub to perform a two-dimensional memory copy
  * \see   Flounder definition in if/omap_sdma.if
  */
-errval_t mem_copy_2d(omap_sdma_addr_2d_t dst, omap_sdma_addr_2d_t src,
-                omap_sdma_count_2d_t count, bool transparent, uint32_t color)
+errval_t mem_copy_2d(struct sdma_driver_state* st, omap_sdma_addr_2d_t dst, omap_sdma_addr_2d_t src,
+                     omap_sdma_count_2d_t count, bool transparent, uint32_t color)
 {
     errval_t err;
     lpaddr_t src_start, dst_start;
@@ -390,7 +384,7 @@ errval_t mem_copy_2d(omap_sdma_addr_2d_t dst, omap_sdma_addr_2d_t src,
                          src.x_modify, src.y_modify,
                          count, color_mode, color);
 
-    err = run_omap_sdma_transfer(&conf);
+    err = run_omap_sdma_transfer(st, &conf);
     return err;
 }
 
@@ -398,7 +392,7 @@ errval_t mem_copy_2d(omap_sdma_addr_2d_t dst, omap_sdma_addr_2d_t src,
  * \brief Stub to fill parts of a frame using two-dimensional indeces
  * \see   Flounder definition in if/omap_sdma.if
  */
-errval_t mem_fill_2d(omap_sdma_addr_2d_t dst, omap_sdma_count_2d_t count, uint32_t color)
+errval_t mem_fill_2d(struct sdma_driver_state* st, omap_sdma_addr_2d_t dst, omap_sdma_count_2d_t count, uint32_t color)
 {
     errval_t err;
     lpaddr_t  dst_start;
@@ -411,24 +405,57 @@ errval_t mem_fill_2d(omap_sdma_addr_2d_t dst, omap_sdma_count_2d_t count, uint32
                          dst.x_modify, dst.y_modify, 0, 0,
                          count, omap44xx_sdma_CONSTANT_FILL, color);
 
-    err = run_omap_sdma_transfer(&conf);
+    err = run_omap_sdma_transfer(st, &conf);
     return err;
 }
 
-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) {
+
+    bfi->dstate = malloc(sizeof(struct sdma_driver_state));
+    if (bfi->dstate == NULL) {
+        return LIB_ERR_MALLOC_FAIL;
+    }
+    assert(bfi->dstate != NULL);
+
+    // 1. Initialize the device:
     errval_t err;
     lvaddr_t dev_base;
-
-    err = map_device_register( OMAP44XX_MAP_L4_CFG_SDMA,
-                              OMAP44XX_MAP_L4_CFG_SDMA_SIZE,
-                              &dev_base);
+    err = map_device_cap(caps[0], &dev_base);
     if (err_is_fail(err)) {
         USER_PANIC_ERR(err, "unable to map SDMA registers");
     }
+    omap_sdma_init(bfi->dstate, (mackerel_addr_t)dev_base, sdma_irq_handler);
+
+    // 2. Export service to talk to the device:
+    sdma_init_service(bfi->dstate, dev);
 
-    omap_sdma_init((mackerel_addr_t)dev_base, sdma_irq_handler);
-    start_service();
+    return SYS_ERR_OK;
+}
 
-    return 0;
+static errval_t attach(struct bfdriver_instance* bfi) {
+    return SYS_ERR_OK;
 }
+
+static errval_t detach(struct bfdriver_instance* bfi) {
+    return SYS_ERR_OK;
+}
+
+static errval_t set_sleep_level(struct bfdriver_instance* bfi, uint32_t level) {
+    struct sdma_driver_state* uds = bfi->dstate;
+    uds->level = level;
+    return SYS_ERR_OK;
+}
+
+static errval_t destroy(struct bfdriver_instance* bfi) {
+    struct sdma_driver_state* uds = bfi->dstate;
+    free(uds);
+    bfi->dstate = NULL;
+    // XXX: Tear-down the service
+    bfi->device = 0x0;
+    return SYS_ERR_OK;
+}
+
+
+DEFINE_MODULE(sdma, init, attach, detach, set_sleep_level, destroy);
index d5f6971..e970e5d 100644 (file)
 #include "omap_sdma.h"
 #include <maps/omap44xx_map.h>
 
-static omap44xx_sdma_t devsdma;
-static bool allocated_channel[OMAP44XX_SDMA_NUM_CHANNEL];
-
-static omap_sdma_irq_handler_t irq_callback;
-
 static inline errval_t omap_sdma_read_csr(omap44xx_sdma_dma4_csr_t csr)
 {
     if (omap44xx_sdma_dma4_csr_misaligned_adrs_err_extract(csr)) {
@@ -45,7 +40,8 @@ static inline errval_t omap_sdma_read_csr(omap44xx_sdma_dma4_csr_t csr)
 
 static void omap_sdma_irq_handler(void *arg)
 {
-    uint32_t irqstatus = omap44xx_sdma_dma4_irqstatus_line_rd(&devsdma, OMAP44XX_SDMA_IRQ_LINE);
+    struct sdma_driver_state* st = (struct sdma_driver_state*) arg;
+    uint32_t irqstatus = omap44xx_sdma_dma4_irqstatus_line_rd(&st->devsdma, OMAP44XX_SDMA_IRQ_LINE);
 
     for (omap_sdma_channel_t channel=0; channel<OMAP44XX_SDMA_NUM_CHANNEL; channel++) {
         bool active = (irqstatus >> channel) & 0x1;
@@ -54,7 +50,7 @@ static void omap_sdma_irq_handler(void *arg)
         SDMA_PRINT("interrupt on channel %u\n", channel);
 
         // read out status flags
-        omap44xx_sdma_dma4_csr_t csr = omap44xx_sdma_dma4_csr_rd(&devsdma, channel);
+        omap44xx_sdma_dma4_csr_t csr = omap44xx_sdma_dma4_csr_rd(&st->devsdma, channel);
 
         // check for errors
         errval_t err = omap_sdma_read_csr(csr);
@@ -62,27 +58,27 @@ static void omap_sdma_irq_handler(void *arg)
         if (err_is_ok(err)) {
             // no error found, check for "End of Block" event
             if(omap44xx_sdma_dma4_csr_block_extract(csr)) {
-                irq_callback(channel, err);
+                st->irq_callback(st, channel, err);
             }
         } else {
             // OMAP4460 Multimedia Device Silicon Errata, Revision A:
             // 1.7 sDMA Channel Is Not Disabled After A Transaction Error
             if (err_no(err) == OMAP_SDMA_ERR_TRANSACTION) {
                 // Workaround: disable channel by software
-                omap44xx_sdma_dma4_ccr_enable_wrf(&devsdma, channel, 0);
+                omap44xx_sdma_dma4_ccr_enable_wrf(&st->devsdma, channel, 0);
             }
 
-            irq_callback(channel, err);
+            st->irq_callback(st, channel, err);
         }
 
         // clear all read status flags
-        omap44xx_sdma_dma4_csr_wr(&devsdma, channel, csr);
+        omap44xx_sdma_dma4_csr_wr(&st->devsdma, channel, csr);
     }
 
     SDMA_PRINT("interrupt finished\n");
 
     // clear all set status bits
-    omap44xx_sdma_dma4_irqstatus_line_wr(&devsdma, OMAP44XX_SDMA_IRQ_LINE, irqstatus);
+    omap44xx_sdma_dma4_irqstatus_line_wr(&st->devsdma, OMAP44XX_SDMA_IRQ_LINE, irqstatus);
 }
 
 
@@ -103,9 +99,9 @@ static void omap_sdma_kernel_irq_handler(void)
 }
 #endif
 
-static void omap_sdma_irq_config(omap_sdma_channel_t channel)
+static void omap_sdma_irq_config(struct sdma_driver_state* st, omap_sdma_channel_t channel)
 {
-    omap44xx_sdma_dma4_cicr_t dma4_cicr = omap44xx_sdma_dma4_cicr_rd(&devsdma, channel);
+    omap44xx_sdma_dma4_cicr_t dma4_cicr = omap44xx_sdma_dma4_cicr_rd(&st->devsdma, channel);
 
     dma4_cicr = omap44xx_sdma_dma4_cicr_super_block_ie_insert(dma4_cicr, 0x0);
     dma4_cicr = omap44xx_sdma_dma4_cicr_drain_ie_insert(dma4_cicr, 0x0);
@@ -119,7 +115,7 @@ static void omap_sdma_irq_config(omap_sdma_channel_t channel)
     dma4_cicr = omap44xx_sdma_dma4_cicr_half_ie_insert(dma4_cicr, 0x0);
     dma4_cicr = omap44xx_sdma_dma4_cicr_drop_ie_insert(dma4_cicr, 0x0);
 
-    omap44xx_sdma_dma4_cicr_wr(&devsdma, channel, dma4_cicr);
+    omap44xx_sdma_dma4_cicr_wr(&st->devsdma, channel, dma4_cicr);
 }
 
 /**
@@ -307,7 +303,7 @@ static void inline omap_sdma_channel_conf_assert_transfer_conf(
  * but is it the callers responsibility to ensure that the configuration is
  * sane and valid.
  */
-void omap_sdma_set_channel_conf(omap_sdma_channel_t channel,
+void omap_sdma_set_channel_conf(struct sdma_driver_state* st, omap_sdma_channel_t channel,
                                 struct omap_sdma_channel_conf *conf)
 {
     // check transfer config and size parameters
@@ -321,48 +317,48 @@ void omap_sdma_set_channel_conf(omap_sdma_channel_t channel,
 
     // Channel Control Register
     omap44xx_sdma_dma4_ccr_t dma4_ccr;
-    dma4_ccr = omap44xx_sdma_dma4_ccr_rd(&devsdma, channel);
+    dma4_ccr = omap44xx_sdma_dma4_ccr_rd(&st->devsdma, channel);
     dma4_ccr = omap_sdma_channel_conf_ccr(dma4_ccr, conf);
-    omap44xx_sdma_dma4_ccr_wr(&devsdma, channel, dma4_ccr);
+    omap44xx_sdma_dma4_ccr_wr(&st->devsdma, channel, dma4_ccr);
 
     // Channel Color Register
     omap44xx_sdma_dma4_color_t dma4_color;
-    dma4_color = omap44xx_sdma_dma4_color_rd(&devsdma, channel);
+    dma4_color = omap44xx_sdma_dma4_color_rd(&st->devsdma, channel);
     dma4_color = omap_sdma_channel_conf_color(channel, conf);
-    omap44xx_sdma_dma4_color_wr(&devsdma, channel, dma4_color);
+    omap44xx_sdma_dma4_color_wr(&st->devsdma, channel, dma4_color);
 
     // Channel Link Control Register
     omap44xx_sdma_dma4_clnk_ctrl_t dma4_clnk_ctrl;
-    dma4_clnk_ctrl = omap44xx_sdma_dma4_clnk_ctrl_rd(&devsdma, channel);
+    dma4_clnk_ctrl = omap44xx_sdma_dma4_clnk_ctrl_rd(&st->devsdma, channel);
     dma4_clnk_ctrl = omap_sdma_channel_conf_clnk_ctrl(channel, conf);
-    omap44xx_sdma_dma4_clnk_ctrl_wr(&devsdma, channel, dma4_clnk_ctrl);
+    omap44xx_sdma_dma4_clnk_ctrl_wr(&st->devsdma, channel, dma4_clnk_ctrl);
 
     // Channel Source Destination Parameters
     omap44xx_sdma_dma4_csdp_t dma4_csdp;
-    dma4_csdp = omap44xx_sdma_dma4_csdp_rd(&devsdma, channel);
+    dma4_csdp = omap44xx_sdma_dma4_csdp_rd(&st->devsdma, channel);
     dma4_csdp = omap_sdma_channel_conf_csdp(channel, conf);
-    omap44xx_sdma_dma4_csdp_wr(&devsdma, channel, dma4_csdp);
+    omap44xx_sdma_dma4_csdp_wr(&st->devsdma, channel, dma4_csdp);
 
     // Channel Element Number
-    omap44xx_sdma_dma4_cen_wr(&devsdma, channel, conf->transfer_size.element_number);
+    omap44xx_sdma_dma4_cen_wr(&st->devsdma, channel, conf->transfer_size.element_number);
 
     // Channel Frame Number
-    omap44xx_sdma_dma4_cfn_wr(&devsdma, channel, conf->transfer_size.frame_number);
+    omap44xx_sdma_dma4_cfn_wr(&st->devsdma, channel, conf->transfer_size.frame_number);
 
     // Channel Source Element Index
-    omap44xx_sdma_dma4_csei_wr(&devsdma, channel, conf->src_conf.element_index);
+    omap44xx_sdma_dma4_csei_wr(&st->devsdma, channel, conf->src_conf.element_index);
     // Channel Source Frame Index
-    omap44xx_sdma_dma4_csfi_wr(&devsdma, channel, conf->src_conf.frame_index);
+    omap44xx_sdma_dma4_csfi_wr(&st->devsdma, channel, conf->src_conf.frame_index);
     // Channel Destination Element Index
-    omap44xx_sdma_dma4_cdei_wr(&devsdma, channel, conf->dst_conf.element_index);
+    omap44xx_sdma_dma4_cdei_wr(&st->devsdma, channel, conf->dst_conf.element_index);
     // Channel Destination Frame Index
-    omap44xx_sdma_dma4_cdfi_wr(&devsdma, channel, conf->dst_conf.frame_index);
+    omap44xx_sdma_dma4_cdfi_wr(&st->devsdma, channel, conf->dst_conf.frame_index);
 
     // Channel Source Start Address
-    omap44xx_sdma_dma4_cssa_wr(&devsdma, channel, conf->src_conf.start_address);
+    omap44xx_sdma_dma4_cssa_wr(&st->devsdma, channel, conf->src_conf.start_address);
 
     // Channel Source Destination Address
-    omap44xx_sdma_dma4_cdsa_wr(&devsdma, channel, conf->dst_conf.start_address);
+    omap44xx_sdma_dma4_cdsa_wr(&st->devsdma, channel, conf->dst_conf.start_address);
 }
 
 /**
@@ -374,42 +370,42 @@ void omap_sdma_set_channel_conf(omap_sdma_channel_t channel,
  * It is the callers responsibility to ensure that the channel was configured
  * properly before this function is called.
  */
-void omap_sdma_enable_channel(omap_sdma_channel_t channel, bool interrupt)
+void omap_sdma_enable_channel(struct sdma_driver_state* st, omap_sdma_channel_t channel, bool interrupt)
 {
     assert(channel < OMAP44XX_SDMA_NUM_CHANNEL);
 
     // clear all channel status flags
-    omap44xx_sdma_dma4_csr_wr(&devsdma, channel, 0xFFFFFFFF);
+    omap44xx_sdma_dma4_csr_wr(&st->devsdma, channel, 0xFFFFFFFF);
 
-    uint32_t irqenable = omap44xx_sdma_dma4_irqenable_rd(&devsdma, OMAP44XX_SDMA_IRQ_LINE);
+    uint32_t irqenable = omap44xx_sdma_dma4_irqenable_rd(&st->devsdma, OMAP44XX_SDMA_IRQ_LINE);
     if (interrupt) {
         // set channel
         irqenable |= 1 << channel;
         // reset irq status for this channel
-        omap44xx_sdma_dma4_irqstatus_line_wr(&devsdma, OMAP44XX_SDMA_IRQ_LINE, 1 << channel);
+        omap44xx_sdma_dma4_irqstatus_line_wr(&st->devsdma, OMAP44XX_SDMA_IRQ_LINE, 1 << channel);
     } else {
         // clear channel
         irqenable &= ~(1 << channel);
     }
-    omap44xx_sdma_dma4_irqenable_wr(&devsdma, OMAP44XX_SDMA_IRQ_LINE, irqenable);
+    omap44xx_sdma_dma4_irqenable_wr(&st->devsdma, OMAP44XX_SDMA_IRQ_LINE, irqenable);
 
-    omap44xx_sdma_dma4_ccr_enable_wrf(&devsdma, channel, 1);
+    omap44xx_sdma_dma4_ccr_enable_wrf(&st->devsdma, channel, 1);
 }
 
 /**
  * \brief Poll a enabled channel for completion of the transfer.
  */
-errval_t omap_sdma_poll_channel(omap_sdma_channel_t channel)
+errval_t omap_sdma_poll_channel(struct sdma_driver_state* st, omap_sdma_channel_t channel)
 {
     assert(channel < OMAP44XX_SDMA_NUM_CHANNEL);
 
     // interrupts should be disabled in polling mode
     assert((omap44xx_sdma_dma4_irqenable_rd(
-                &devsdma, OMAP44XX_SDMA_IRQ_LINE) & 1 << channel) == 0x0
+                &st->devsdma, OMAP44XX_SDMA_IRQ_LINE) & 1 << channel) == 0x0
     );
 
     for (;;) {
-        omap44xx_sdma_dma4_csr_t csr = omap44xx_sdma_dma4_csr_rd(&devsdma, channel);
+        omap44xx_sdma_dma4_csr_t csr = omap44xx_sdma_dma4_csr_rd(&st->devsdma, channel);
 
         errval_t err = omap_sdma_read_csr(csr);
 
@@ -425,13 +421,13 @@ errval_t omap_sdma_poll_channel(omap_sdma_channel_t channel)
  * \brief Allocate a SDMA channel. Will return an error if there are no channels
  * available.
  */
-errval_t omap_sdma_allocate_channel(omap_sdma_channel_t *channel)
+errval_t omap_sdma_allocate_channel(struct sdma_driver_state* st, omap_sdma_channel_t *channel)
 {
     assert(channel != NULL);
 
     for (omap_sdma_channel_t c = 0; c<OMAP44XX_SDMA_NUM_CHANNEL; c++) {
-        if (!allocated_channel[c]) {
-            allocated_channel[c] = true;
+        if (!st->allocated_channel[c]) {
+            st->allocated_channel[c] = true;
             *channel = c;
             return SYS_ERR_OK;
         }
@@ -442,10 +438,10 @@ errval_t omap_sdma_allocate_channel(omap_sdma_channel_t *channel)
 /**
  * \brief Frees a previously allocated SDMA channel.
  */
-void omap_sdma_free_channel(omap_sdma_channel_t channel)
+void omap_sdma_free_channel(struct sdma_driver_state* st, omap_sdma_channel_t channel)
 {
-    assert(allocated_channel[channel]);
-    allocated_channel[channel] = false;
+    assert(st->allocated_channel[channel]);
+    st->allocated_channel[channel] = false;
 }
 
 /**
@@ -459,19 +455,19 @@ void omap_sdma_free_channel(omap_sdma_channel_t channel)
  * an interrupt. The source channel and the the reason of the interrupt are
  * passed to the callback as an the argument.
  */
-errval_t omap_sdma_init(mackerel_addr_t dev_base, omap_sdma_irq_handler_t irq_cb)
+errval_t omap_sdma_init(struct sdma_driver_state* st, mackerel_addr_t dev_base, omap_sdma_irq_handler_t irq_cb)
 {
     // init global variables
     STATIC_ASSERT_SIZEOF(bool, 1);
-    memset(allocated_channel, false, OMAP44XX_SDMA_NUM_CHANNEL);
+    memset(st->allocated_channel, false, OMAP44XX_SDMA_NUM_CHANNEL);
 
-    omap44xx_sdma_initialize(&devsdma, dev_base);
+    omap44xx_sdma_initialize(&st->devsdma, dev_base);
 
     // check if we can read the revision
-    assert(omap44xx_sdma_dma4_revision_rd(&devsdma) == 0x10900);
+    assert(omap44xx_sdma_dma4_revision_rd(&st->devsdma) == 0x10900);
 
     assert(irq_cb != NULL);
-    irq_callback = irq_cb;
+    st->irq_callback = irq_cb;
 
     errval_t err = SYS_ERR_OK;
 #ifdef OMAP_SDMA_KERNELBENCH
@@ -489,18 +485,18 @@ errval_t omap_sdma_init(mackerel_addr_t dev_base, omap_sdma_irq_handler_t irq_cb
                             GIC_IRQ_EDGE_TRIGGERED, GIC_IRQ_N_TO_N);
 #else
     // in userspace, register normal interrupt handler
-    err = inthandler_setup_arm(omap_sdma_irq_handler, NULL, OMAP44XX_SDMA_IRQ);
+    err = inthandler_setup_arm(omap_sdma_irq_handler, st, OMAP44XX_SDMA_IRQ);
 #endif
 
     // set fifo depth to maximum burst size
-    omap44xx_sdma_dma4_gcr_max_channel_fifo_depth_wrf(&devsdma, 64);
+    omap44xx_sdma_dma4_gcr_max_channel_fifo_depth_wrf(&st->devsdma, 64);
 
     // configure error and interrupt handling of the device
     for(omap_sdma_channel_t channel = 0;
         channel < OMAP44XX_SDMA_NUM_CHANNEL;
         channel++)
     {
-        omap_sdma_irq_config(channel);
+        omap_sdma_irq_config(st, channel);
     }
 
     return err;
index fcb4600..f0ffb2e 100644 (file)
@@ -14,8 +14,9 @@
 #include <dev/omap/omap44xx_sdma_dev.h>
 
 typedef uint8_t omap_sdma_channel_t;
+struct sdma_driver_state;
 
-typedef void (*omap_sdma_irq_handler_t)(omap_sdma_channel_t, errval_t);
+typedef void (*omap_sdma_irq_handler_t)(struct sdma_driver_state*, omap_sdma_channel_t, errval_t);
 
 typedef uint8_t omap44xx_sdma_color_mode_t;
 #define omap44xx_sdma_DISABLE_COLOR_MODE ((omap44xx_sdma_color_mode_t)0x0)
@@ -38,6 +39,24 @@ typedef uint8_t omap44xx_sdma_color_mode_t;
 #define SDMA_PRINT(...) do{ } while ( false )
 #endif
 
+#include <thc/thc.h>
+
+/// Channel State. Filled by the interrupt callback, read by the request task.
+struct channel_state {
+    awe_t *request;
+    errval_t err;
+};
+
+struct sdma_driver_state {
+    omap44xx_sdma_t devsdma;
+
+    bool allocated_channel[OMAP44XX_SDMA_NUM_CHANNEL];
+    struct channel_state channel_state[OMAP44XX_SDMA_NUM_CHANNEL];
+    omap_sdma_irq_handler_t irq_callback;
+
+    uint32_t level;
+};
+
 struct omap_sdma_transfer_conf {
     lpaddr_t start_address;
     omap44xx_sdma_addr_mode_t addr_mode;
@@ -76,18 +95,18 @@ struct omap_sdma_channel_conf {
     omap_sdma_channel_t next_channel;
 };
 
-errval_t omap_sdma_init(mackerel_addr_t dev_base, omap_sdma_irq_handler_t);
+errval_t omap_sdma_init(struct sdma_driver_state*, mackerel_addr_t, omap_sdma_irq_handler_t);
 
-errval_t omap_sdma_allocate_channel(omap_sdma_channel_t *channel);
-void omap_sdma_free_channel(omap_sdma_channel_t channel);
+errval_t omap_sdma_allocate_channel(struct sdma_driver_state* st, omap_sdma_channel_t *channel);
+void omap_sdma_free_channel(struct sdma_driver_state* st, omap_sdma_channel_t channel);
 
 void omap_sdma_init_channel_conf(struct omap_sdma_channel_conf *conf);
 
-void omap_sdma_set_channel_conf(omap_sdma_channel_t channel,
+void omap_sdma_set_channel_conf(struct sdma_driver_state* st, omap_sdma_channel_t channel,
     struct omap_sdma_channel_conf *conf);
 
-void omap_sdma_enable_channel(omap_sdma_channel_t channel, bool interrupt);
+void omap_sdma_enable_channel(struct sdma_driver_state* st, omap_sdma_channel_t channel, bool interrupt);
 
-errval_t omap_sdma_poll_channel(omap_sdma_channel_t channel);
+errval_t omap_sdma_poll_channel(struct sdma_driver_state* st, omap_sdma_channel_t channel);
 
 #endif // OMAP44XX_SDMA_H_
index b5584ef..9fe0bca 100644 (file)
 #include <if/omap_sdma_defs.h>
 #include <bitmacros.h>
 
-void start_service(void);
+//#define SDMA_DEBUG_ON 1
 
-errval_t mem_copy(struct capref dst_cap, struct capref src_cap);
-errval_t mem_fill(struct capref dst_cap, uint8_t color);
+#if defined(SDMA_DEBUG_ON) || defined(MMCHS_SERVICE_DEBUG) || defined(GLOBAL_DEBUG)
+#define SDMA_DEBUG(x...) printf(x)
+#else
+#define SDMA_DEBUG(x...) ((void)0)
+#endif
+
+struct sdma_driver_state;
+void sdma_init_service(struct sdma_driver_state* st, iref_t* iref);
+
+errval_t mem_copy(struct sdma_driver_state* st, struct capref dst_cap, struct capref src_cap);
+errval_t mem_fill(struct sdma_driver_state* st, struct capref dst_cap, uint8_t color);
 
-errval_t mem_copy_2d(omap_sdma_addr_2d_t dst, omap_sdma_addr_2d_t src,
+errval_t mem_copy_2d(struct sdma_driver_state* st, omap_sdma_addr_2d_t dst, omap_sdma_addr_2d_t src,
                 omap_sdma_count_2d_t count, bool transparent, uint32_t color);
-errval_t mem_fill_2d(omap_sdma_addr_2d_t dst, omap_sdma_count_2d_t count, uint32_t color);
+errval_t mem_fill_2d(struct sdma_driver_state* st, omap_sdma_addr_2d_t dst, omap_sdma_count_2d_t count, uint32_t color);
 #endif
index ae9420c..320a83e 100644 (file)
@@ -1,10 +1,14 @@
+/**
+ * \file
+ * \brief Implementation of ata_rw28.if interface (to enable working vfs_fat)
+ */
 /*
- * Copyright (c) 2014, ETH Zurich.
+ * Copyright (c) 2013, ETH Zurich.
  * All rights reserved.
  *
  * This file is distributed under the terms in the attached LICENSE file.
  * If you do not find this file, copies can be found by writing to:
- * ETH Zurich D-INFK, CAB F.78, Universitaetstr 6, CH-8092 Zurich.
+ * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
  */
 
 #include <stdlib.h>
 
 #include <barrelfish/barrelfish.h>
 #include <barrelfish/nameservice_client.h>
-
 #include <if/omap_sdma_defs.h>
-#include <if/omap_sdma_thc.h>
-#include <thc/thc.h>
 
 #include "sdma.h"
 
-static void run_service(struct omap_sdma_thc_service_binding_t *sv)
-{
-    omap_sdma_service_msg_t msg;
-    bool loop = true;
-
-    // this is the bitmap of messages we are interested in receiving
-    struct omap_sdma_service_selector selector = {
-        .mem_copy = 1, .mem_copy_2d = 1,
-        .mem_fill = 1, .mem_fill_2d = 1,
-    };
-
-    while (loop) {
-        // receive any message
-        sv->recv_any(sv, &msg, selector);
+static errval_t mem_copy_handler(struct omap_sdma_binding *sv, struct capref dst, struct capref src, errval_t* err) {
+    struct sdma_driver_state* ds = sv->st;
+    *err = mem_copy(ds, dst, src);
+    return SYS_ERR_OK;
+}
 
-        errval_t reterr = SYS_ERR_OK;
+static errval_t mem_fill_handler(struct omap_sdma_binding *sv, struct capref dst, uint8_t color, errval_t* err) {
+    struct sdma_driver_state* ds = sv->st;
+    *err = mem_fill(ds, dst, color);
+    return SYS_ERR_OK;
+}
 
-        // dispatch it
-        switch(msg.msg) {
-        case omap_sdma_mem_copy:
-            reterr = mem_copy(
-                msg.args.mem_copy.in.dst,
-                msg.args.mem_copy.in.src);
-            sv->send.mem_copy(sv, reterr);
-            break;
-        case omap_sdma_mem_fill:
-            reterr = mem_fill(
-                msg.args.mem_fill.in.dst,
-                msg.args.mem_fill.in.color);
-            sv->send.mem_fill(sv, reterr);
-            break;
-        case omap_sdma_mem_copy_2d:
-            reterr = mem_copy_2d(
-                msg.args.mem_copy_2d.in.dst,
-                msg.args.mem_copy_2d.in.src,
-                msg.args.mem_copy_2d.in.count,
-                msg.args.mem_copy_2d.in.transparent,
-                msg.args.mem_copy_2d.in.color);
-            sv->send.mem_copy_2d(sv, reterr);
-            break;
-        case omap_sdma_mem_fill_2d:
-            reterr = mem_fill_2d(
-                msg.args.mem_fill_2d.in.dst,
-                msg.args.mem_fill_2d.in.count,
-                msg.args.mem_fill_2d.in.color);
-            sv->send.mem_fill_2d(sv, reterr);
-            break;
-        default:
-            debug_printf("unexpected message: %d\n", msg.msg);
-            loop = false;
-            break;
-        }
-    }
+static errval_t mem_copy_2d_handler(struct omap_sdma_binding *sv,
+                             omap_sdma_addr_2d_t dst, omap_sdma_addr_2d_t src, omap_sdma_count_2d_t count,
+                             bool transparent, uint32_t color, errval_t* err) {
+    struct sdma_driver_state* ds = sv->st;
+    *err = mem_copy_2d(ds, dst, src, count, transparent, color);
+    return SYS_ERR_OK;
+}
 
-    free(sv);
+static errval_t mem_fill_2d_handler(struct omap_sdma_binding *sv,
+                             omap_sdma_addr_2d_t dst, uint32_t color, omap_sdma_count_2d_t count,
+                             errval_t* err) {
+    struct sdma_driver_state* ds = sv->st;
+    *err = mem_fill_2d(ds, dst, count, color);
+    return SYS_ERR_OK;
 }
 
-void start_service(void)
-{
+static struct export_state {
+    struct omap_sdma_binding* b;
+    bool is_done;
     errval_t err;
-
-    struct omap_sdma_thc_export_info e_info;
-    struct omap_sdma_thc_service_binding_t *sv;
-    struct omap_sdma_binding *b;
     iref_t iref;
+} service_export;
 
-    err = omap_sdma_thc_export(&e_info, "sdma",
-                             get_default_waitset(),
-                             IDC_EXPORT_FLAGS_DEFAULT,
-                             &iref);
-    if (err_is_fail(err)) {
-        USER_PANIC_ERR(err, "thc export failed");
+static void export_cb(void *st, errval_t err, iref_t iref)
+{
+    service_export.is_done = true;
+    service_export.err = err;
+    service_export.iref = iref;
+
+    if (err_is_ok(err)) {
+        SDMA_DEBUG("Exported ddomain service with iref: %"PRIu32"\n", iref);
+        err = nameservice_register("sdma", iref);
+        assert(err_is_ok(err));
     }
+}
 
-    DO_FINISH({
-        while(true) {
-            err = omap_sdma_thc_accept(&e_info, &b);
-            if (err_is_fail(err)) {
-                USER_PANIC_ERR(err, "thc accept failed");
-            }
+static const struct omap_sdma_rpc_rx_vtbl rx_vtbl = {
+    .mem_copy_call = mem_copy_handler,
+    .mem_fill_call = mem_fill_handler,
+    .mem_copy_2d_call = mem_copy_2d_handler,
+    .mem_fill_2d_call = mem_fill_2d_handler,
+};
 
-            sv = malloc(sizeof(struct omap_sdma_thc_service_binding_t));
-            assert(sv != NULL);
+static errval_t client_connect(void *st, struct omap_sdma_binding *b)
+{
+    service_export.b = b;
+    b->rpc_rx_vtbl = rx_vtbl;
+    b->st = st;
+    return SYS_ERR_OK;
+}
 
-            err = omap_sdma_thc_init_service(sv, b, b);
-            if (err_is_fail(err)) {
-                USER_PANIC_ERR(err, "thc init failed");
-            }
+void sdma_init_service(struct sdma_driver_state* st, iref_t* iref)
+{
+    errval_t err;
+    SDMA_DEBUG("%s:%d: Starting server\n", __FUNCTION__, __LINE__);
+    err = omap_sdma_export(st, export_cb, client_connect, get_default_waitset(), IDC_EXPORT_FLAGS_DEFAULT);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
 
-            ASYNC({run_service(sv);});
-        }
-    });
+    while(!service_export.is_done) {
+        messages_wait_and_handle_next();
+    }
+    *iref = service_export.iref;
+    SDMA_DEBUG("Service sdma exported.\n");
 }
diff --git a/usr/drivers/omap44xx/twl6030/Hakefile b/usr/drivers/omap44xx/twl6030/Hakefile
new file mode 100644 (file)
index 0000000..0cdb73f
--- /dev/null
@@ -0,0 +1,25 @@
+--------------------------------------------------------------------------
+-- Copyright (c) 2007-2013, ETH Zurich.
+-- All rights reserved.
+--
+-- This file is distributed under the terms in the attached LICENSE file.
+-- If you do not find this file, copies can be found by writing to:
+-- ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
+--
+-- Hakefile for omap44xx sd-card driver
+--
+--------------------------------------------------------------------------
+
+[
+    build library {
+                    target = "twl6030_module",
+                    cFiles = [ "i2c.c", "twl6030.c", "module.c", "service.c" ],
+                    mackerelDevices = [
+                        "ti_i2c",
+                        "ti_twl6030"
+                    ],
+                    flounderDefs = [ "twl6030", "cm2" ],
+                    flounderBindings = [ "twl6030" ],
+                    architectures = ["armv7"]
+    }
+]
similarity index 97%
rename from usr/drivers/omap44xx/mmchs/i2c.c
rename to usr/drivers/omap44xx/twl6030/i2c.c
index 1c361de..8875c00 100644 (file)
@@ -9,14 +9,12 @@
 
 #include <barrelfish/barrelfish.h>
 #include <driverkit/driverkit.h>
+#include <assert.h>
 
 #include <dev/ti_i2c_dev.h>
 
-#include "omap44xx_cm2.h" // for turning on I2C clocks
 #include "i2c.h"
 #include "twl6030.h"
-#include "mmchs.h"
-#include "cap_slots.h"
 
 #if defined(I2C_SERVICE_DEBUG) || defined(MMCHS_SERVICE_DEBUG) || defined(GLOBAL_DEBUG)
 #define I2C_DEBUG(x...) debug_printf(x)
@@ -58,20 +56,22 @@ static int tsc_read(void)
 /*
  * \brief initialize I2C controller `i`.
  */
-void ti_i2c_init(struct mmchs_driver_state* st, int i)
+void ti_i2c_init(struct twl6030_driver_state* st, int i)
 {
     I2C_DEBUG("%s:%d\n", __FUNCTION__, __LINE__);
     // map & initialize mackerel device
     lvaddr_t i2c_vbase;
-    errval_t err = map_device_cap(st->caps[IC2_SLOT], &i2c_vbase);
+    errval_t err = map_device_cap(st->cap, &i2c_vbase);
     assert(err_is_ok(err));
     ti_i2c_initialize(&i2c[i], (mackerel_addr_t)i2c_vbase);
 
     ti_i2c_t *dev = &i2c[i];
 
     // turn on clocks
-    cm2_enable_i2c(st, i);
-
+    assert(st->cm2_binding != NULL);
+    assert(st->cm2_binding->rpc_tx_vtbl.enable_i2c != NULL);
+    err = st->cm2_binding->rpc_tx_vtbl.enable_i2c(st->cm2_binding, i);
+    assert(err_is_ok(err));
     I2C_DEBUG("%s:%d\n", __FUNCTION__, __LINE__);
 
     // TODO?: enable interrupts
@@ -138,8 +138,6 @@ void ti_i2c_init(struct mmchs_driver_state* st, int i)
     //ti_i2c_sysc_pr(prbuf, PBS-1, dev);
     //I2C_DEBUG("%s\n", prbuf);
 
-
-
     return;
 }
 
similarity index 90%
rename from usr/drivers/omap44xx/mmchs/i2c.h
rename to usr/drivers/omap44xx/twl6030/i2c.h
index ad6277e..cefbaa9 100644 (file)
@@ -29,8 +29,8 @@ struct i2c_msg {
     uint8_t *buf;
 };
 
-struct mmchs_driver_state;
-void ti_i2c_init(struct mmchs_driver_state* st, int i);
+struct twl6030_driver_state;
+void ti_i2c_init(struct twl6030_driver_state* st, int i);
 errval_t ti_i2c_transfer(int i, struct i2c_msg *msgs, size_t msgcount);
 lpaddr_t i2c_get_pbase(size_t dev);
 
diff --git a/usr/drivers/omap44xx/twl6030/module.c b/usr/drivers/omap44xx/twl6030/module.c
new file mode 100644 (file)
index 0000000..a6562be
--- /dev/null
@@ -0,0 +1,163 @@
+/**
+ * \file
+ * \brief MMCHS Driver main routine.
+ */
+/*
+ * Copyright (c) 2013, ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <barrelfish/barrelfish.h>
+#include <barrelfish/nameservice_client.h>
+#include <driverkit/driverkit.h>
+
+#include <if/cm2_defs.h>
+
+#include "twl6030.h"
+
+static void cm2_connected(void *st, errval_t err, struct cm2_binding *b) {
+    TWL_DEBUG("Connected to cm2 driver\n");
+    assert(err_is_ok(err));
+    struct twl6030_driver_state* dst = (struct twl6030_driver_state*) st;
+    dst->cm2_binding = b;
+    cm2_rpc_client_init(b);
+}
+
+/**
+ * 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.
+ *
+ * \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.
+ */
+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) {
+    TWL_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    bfi->dstate = malloc(sizeof(struct twl6030_driver_state));
+    if (bfi->dstate == NULL) {
+        return LIB_ERR_MALLOC_FAIL;
+    }
+
+    assert(bfi->dstate != NULL);
+
+    struct twl6030_driver_state* st = (struct twl6030_driver_state*) bfi->dstate;
+    st->cap = caps[0];
+
+    // Connect to the cm2 driver
+    iref_t cm2_iref;
+    errval_t err = nameservice_lookup("cm2", &cm2_iref);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "finding cm2 service failed.");
+    }
+
+    err = cm2_bind(cm2_iref, cm2_connected, st, get_default_waitset(), IDC_EXPORT_FLAG_NO_NOTIFY);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
+
+    while(st->cm2_binding == NULL) {
+        messages_wait_and_handle_next();
+    }
+    assert(st->cm2_binding != NULL);
+
+
+    ti_twl6030_init(st);
+    twl6030_init_service(st, dev);
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * 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) {
+    TWL_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    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) {
+    TWL_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) {
+    TWL_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+
+    struct twl6030_driver_state* uds = bfi->dstate;
+    uds->level = level;
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * Destroys this driver instance. The driver will yield any
+ * control over the device and free any state allocated.
+ *
+ * \param[in]   bfi   The instance of this driver.
+ * \retval SYS_ERR_OK Device initialized successfully.
+ */
+static errval_t destroy(struct bfdriver_instance* bfi) {
+    TWL_DEBUG("%s:%s:%d: %s\n", __FILE__, __FUNCTION__, __LINE__, bfi->driver->name);
+    struct twl6030_driver_state* uds = bfi->dstate;
+    free(uds);
+    bfi->dstate = NULL;
+
+    // XXX: Tear-down the service
+    bfi->device = 0x0;
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * Registers the driver module with the system.
+ *
+ * To link this particular module in your driver domain,
+ * add it to the addModules list in the Hakefile.
+ */
+DEFINE_MODULE(twl6030, init, attach, detach, set_sleep_level, destroy);
diff --git a/usr/drivers/omap44xx/twl6030/service.c b/usr/drivers/omap44xx/twl6030/service.c
new file mode 100644 (file)
index 0000000..462d47e
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+ * \file
+ * \brief Implementation of ata_rw28.if interface (to enable working vfs_fat)
+ */
+/*
+ * Copyright (c) 2013, ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include "twl6030.h"
+
+#include <barrelfish/barrelfish.h>
+#include <barrelfish/nameservice_client.h>
+#include <if/twl6030_defs.h>
+
+
+
+static errval_t vmmc_csel_off(struct twl6030_binding *sv)
+{
+    struct twl6030_driver_state* ds = sv->st;
+    ti_twl6030_vmmc_off(ds->twl);
+    return SYS_ERR_OK;
+}
+
+static errval_t vmmc_on_handler(struct twl6030_binding *sv)
+{
+    struct twl6030_driver_state* ds = sv->st;
+    ti_twl6030_vmmc_on(ds->twl);
+    return SYS_ERR_OK;
+}
+
+static errval_t vmmc_vsel_handler(struct twl6030_binding *sv, uint32_t vsel)
+{
+    struct twl6030_driver_state* ds = sv->st;
+    return ti_twl6030_set_vmmc_vsel(ds->twl, vsel);
+}
+
+static struct export_state {
+    struct twl6030_binding* b;
+    bool is_done;
+    errval_t err;
+    iref_t iref;
+} service_export;
+
+static void export_cb(void *st, errval_t err, iref_t iref)
+{
+    service_export.is_done = true;
+    service_export.err = err;
+    service_export.iref = iref;
+
+    if (err_is_ok(err)) {
+        TWL_DEBUG("Exported ddomain service with iref: %"PRIu32"\n", iref);
+        err = nameservice_register("twl6030", iref);
+        assert(err_is_ok(err));
+    }
+}
+static const struct twl6030_rpc_rx_vtbl rx_vtbl = {
+    .vmmc_on_call = vmmc_on_handler,
+    .vmmc_off_call = vmmc_csel_off,
+    .vmmc_vsel_call = vmmc_vsel_handler,
+};
+
+static errval_t client_connect(void *st, struct twl6030_binding *b)
+{
+    service_export.b = b;
+    b->rpc_rx_vtbl = rx_vtbl;
+    b->st = st;
+    return SYS_ERR_OK;
+}
+
+void twl6030_init_service(struct twl6030_driver_state* st, iref_t* iref)
+{
+    errval_t err;
+    TWL_DEBUG("%s:%d: Starting server\n", __FUNCTION__, __LINE__);
+    err = twl6030_export(st, export_cb, client_connect, get_default_waitset(), IDC_EXPORT_FLAGS_DEFAULT);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
+
+    while(!service_export.is_done) {
+        messages_wait_and_handle_next();
+    }
+    *iref = service_export.iref;
+    TWL_DEBUG("Service twl6030 exported.\n");
+}
similarity index 95%
rename from usr/drivers/omap44xx/mmchs/twl6030.c
rename to usr/drivers/omap44xx/twl6030/twl6030.c
index 716d24e..9940214 100644 (file)
 // I2C slave address for id1 reads and writes is 0x48
 #define ID1_I2C_ADDR 0x48
 
-#include "mmchs_debug.h"
-#if defined(TWL_SERIVCE_DEBUG) || defined(MMCHS_SERVICE_DEBUG) || defined(GLOBAL_DEBUG)
-#define TWL_DEBUG(x...) printf(x)
-#else
-#define TWL_DEBUG(x...) ((void)0)
-#endif
 
 inline uint8_t _ti_twl6030_id1_read_8(void *d, size_t off)
 {
@@ -77,7 +71,7 @@ inline void _ti_twl6030_id1_write_8(void *d, size_t off, uint8_t regval)
     return;
 }
 
-void ti_twl6030_init(struct mmchs_driver_state* st)
+void ti_twl6030_init(struct twl6030_driver_state* st)
 {
     TWL_DEBUG("%s:%d\n", __FUNCTION__, __LINE__);
     ti_i2c_init(st, I2C_HC);
similarity index 63%
rename from usr/drivers/omap44xx/mmchs/twl6030.h
rename to usr/drivers/omap44xx/twl6030/twl6030.h
index 3d5cbd1..fa5c221 100644 (file)
@@ -9,25 +9,42 @@
 #ifndef __TI_TWL6030_H__
 #define __TI_TWL6030_H__
 
-#include <barrelfish/types.h>
+#include <barrelfish/barrelfish.h>
 #include <errors/errno.h>
+#include <if/cm2_defs.h>
 
 // I2C Host controller id
 #define I2C_HC 0
 
+//#define TWL_SERIVCE_DEBUG 1
+
+#if defined(TWL_SERIVCE_DEBUG) || defined(MMCHS_SERVICE_DEBUG) || defined(GLOBAL_DEBUG)
+#define TWL_DEBUG(x...) printf(x)
+#else
+#define TWL_DEBUG(x...) ((void)0)
+#endif
+
 uint8_t _ti_twl6030_id1_read_8(void *d, size_t off);
 void _ti_twl6030_id1_write_8(void *d, size_t off, uint8_t regval);
 #define ti_twl6030_id1_read_8(dev, off) _ti_twl6030_id1_read_8(dev, off)
 #define ti_twl6030_id1_write_8(dev, off, regval) _ti_twl6030_id1_write_8(dev, off, regval)
 #include <dev/ti_twl6030_dev.h>
 
-struct mmchs_driver_state;
-void ti_twl6030_init(struct mmchs_driver_state*);
-errval_t ti_twl6030_set_vmmc_vsel(ti_twl6030_t twl, int millis);
+struct twl6030_driver_state {
+    size_t level;
+    struct capref cap;
+    ti_twl6030_t twl;
+    struct cm2_binding* cm2_binding;
+};
 
+void ti_twl6030_init(struct twl6030_driver_state*);
+errval_t ti_twl6030_set_vmmc_vsel(ti_twl6030_t twl, int millis);
 void ti_twl6030_vmmc_pr(ti_twl6030_t twl);
-
 void ti_twl6030_vmmc_on(ti_twl6030_t twl);
 void ti_twl6030_vmmc_off(ti_twl6030_t twl);
 
+/* service.c */
+void twl6030_init_service(struct twl6030_driver_state* st, iref_t* iref);
+
+
 #endif // __TI_TWL6030_H__
index c934acc..f28caec 100644 (file)
@@ -17,7 +17,8 @@ let commonCFiles = [ "boot_modules.c",
                     "queue.c",
                     "start_cpu.c",
                     "start_pci.c",
-                    "start_int_ctrl.c"
+                    "start_int_ctrl.c",
+                    "driver_domains.c"
                     ] in
 [ build application { target = "kaluga",
                       cFiles = (commonCFiles) ++ [ "x86.c" ],
@@ -27,7 +28,8 @@ let commonCFiles = [ "boot_modules.c",
                       flounderTHCStubs = [ "octopus" ],
                       addLibraries = libDeps [ "skb", "octopus", "vfs",
                                                "spawndomain", "elf", "mm",
-                                               "trace", "int_route_client" ],
+                                               "trace", "int_route_client",
+                                               "driverkit" ],
                       architectures = [ "x86_64", "x86_32" ] },
   build application { target = "kaluga",
                       cFiles = commonCFiles,
@@ -37,7 +39,7 @@ let commonCFiles = [ "boot_modules.c",
                       flounderTHCStubs = [ "octopus" ],
                       addLibraries = libDeps [ "skb", "octopus", "vfs_noblockdev",
                                                "spawndomain", "elf", "mm",
-                                               "trace" ],
+                                               "trace", "driverkit" ],
                       architectures = [ "k1om" ] },
   build application { target = "kaluga",
                       cFiles = commonCFiles ++ [ "armv7.c", "armv7_startup.c" ],
@@ -47,7 +49,7 @@ let commonCFiles = [ "boot_modules.c",
                       flounderTHCStubs = [ "octopus" ],
                       addLibraries = libDeps [ "skb", "octopus", "vfs_ramfs",
                                                "spawndomain", "elf", "mm",
-                                               "trace" ],
+                                               "trace", "driverkit" ],
                       architectures = [ "armv7" ] },
   build application { target = "kaluga",
                       cFiles = commonCFiles ++ [ "armv8.c" ],
@@ -57,6 +59,6 @@ let commonCFiles = [ "boot_modules.c",
                       flounderTHCStubs = [ "octopus" ],
                       addLibraries = libDeps [ "skb", "octopus", "vfs_ramfs",
                                                "spawndomain", "elf", "mm",
-                                               "trace", "int_route_client" ],
+                                               "trace", "int_route_client", "driverkit" ],
                       architectures = [ "armv8" ] }
 ]
index 0983d9f..a4a9120 100644 (file)
 
 #include "kaluga.h"
 
+static void start_driverdomain(char* record) {
+    struct module_info* mi = find_module("driverdomain");
+    if (mi != NULL) {
+        errval_t err = mi->start_function(0, mi, record, NULL);
+        assert(err_is_ok(err));
+    }
+}
+
 static errval_t omap44xx_startup(void)
 {
     errval_t err;
@@ -30,36 +38,21 @@ static errval_t omap44xx_startup(void)
     err = init_cap_manager();
     assert(err_is_ok(err));
 
-    struct module_info* mi = find_module("fdif");
-    if (mi != NULL) {
-        err = mi->start_function(0, mi, "hw.arm.omap44xx.fdif {}", NULL);
-        assert(err_is_ok(err));
-    }
-    mi = find_module("mmchs");
-    if (mi != NULL) {
-        err = mi->start_function(0, mi, "hw.arm.omap44xx.mmchs {}", NULL);
-        assert(err_is_ok(err));
-    }
-    mi = find_module("mmchs2");
-    if (mi != NULL) {
-        err = mi->start_function(0, mi, "hw.arm.omap44xx.mmchs {}", NULL);
-        assert(err_is_ok(err));
-    }
-    mi = find_module("prcm");
+    start_driverdomain("fdif {}");
+    start_driverdomain("sdma {}");
+    start_driverdomain("mmchs { dep1: 'cm2', dep2: 'twl6030' }");
+
+    struct module_info* mi = find_module("prcm");
     if (mi != NULL) {
         err = mi->start_function(0, mi, "hw.arm.omap44xx.prcm {}", NULL);
         assert(err_is_ok(err));
     }
+
     mi = find_module("serial");
     if (mi != NULL) {
         err = mi->start_function(0, mi, "hw.arm.omap44xx.uart {}", NULL);
         assert(err_is_ok(err));
     }
-    mi = find_module("sdma");
-    if (mi != NULL) {
-        err = mi->start_function(0, mi, "hw.arm.omap44xx.sdma {}", NULL);
-        assert(err_is_ok(err));
-    }
 
     mi = find_module("usb_manager");
     if (mi != NULL) {
index f0363a7..23749ca 100644 (file)
@@ -52,7 +52,7 @@ static struct allowed_registers usb = {
 };
 
 static struct allowed_registers fdif = {
-    .binary = "hw.arm.omap44xx.fdif",
+    .binary = "fdif",
     .registers =
     {
         {OMAP44XX_CAM_CM2, 0x1000},
@@ -63,29 +63,31 @@ static struct allowed_registers fdif = {
     }
 };
 
-static struct allowed_registers mmchs = {
-    .binary = "hw.arm.omap44xx.mmchs",
+static struct allowed_registers twl6030 = {
+    .binary = "twl6030",
     .registers =
     {
-        {OMAP44XX_CM2,        0x1000},
-        {OMAP44XX_CLKGEN_CM2, 0x1000},
-        {OMAP44XX_L4PER_CM2,  0x1000},
-        // i2c
         {OMAP44XX_MAP_L4_PER_I2C1, OMAP44XX_MAP_L4_PER_I2C1_SIZE},
-        {OMAP44XX_MAP_L4_PER_I2C2, OMAP44XX_MAP_L4_PER_I2C2_SIZE},
-        {OMAP44XX_MAP_L4_PER_I2C3, OMAP44XX_MAP_L4_PER_I2C3_SIZE},
-        {OMAP44XX_MAP_L4_PER_I2C4, OMAP44XX_MAP_L4_PER_I2C4_SIZE},
-        // ctrlmodules
-        {OMAP44XX_MAP_L4_CFG_SYSCTRL_GENERAL_CORE, OMAP44XX_MAP_L4_CFG_SYSCTRL_GENERAL_CORE_SIZE},
-        {OMAP44XX_MAP_L4_WKUP_SYSCTRL_GENERAL_WKUP, OMAP44XX_MAP_L4_WKUP_SYSCTRL_GENERAL_WKUP_SIZE},
+        {0x0, 0x0}
+    }
+};
+
+static struct allowed_registers cm2 = {
+    .binary = "cm2",
+    .registers =
+    {
+        {OMAP44XX_CM2,        0x1000},
+        {0x0, 0x0}
+    }
+};
+
+
+static struct allowed_registers mmchs = {
+    .binary = "mmchs",
+    .registers =
+    {
         {OMAP44XX_MAP_L4_CFG_SYSCTRL_PADCONF_CORE, OMAP44XX_MAP_L4_CFG_SYSCTRL_PADCONF_CORE_SIZE},
-        {OMAP44XX_MAP_L4_WKUP_SYSCTRL_PADCONF_WKUP, OMAP44XX_MAP_L4_WKUP_SYSCTRL_PADCONF_WKUP_SIZE},
-        // MMCHS
         {OMAP44XX_MAP_L4_PER_HSMMC1, OMAP44XX_MAP_L4_PER_HSMMC1_SIZE},
-        {OMAP44XX_MAP_L4_PER_HSMMC2, OMAP44XX_MAP_L4_PER_HSMMC2_SIZE},
-        {OMAP44XX_MAP_L4_PER_MMC_SD3, OMAP44XX_MAP_L4_PER_MMC_SD3_SIZE},
-        {OMAP44XX_MAP_L4_PER_MMC_SD4, OMAP44XX_MAP_L4_PER_MMC_SD4_SIZE},
-        {OMAP44XX_MAP_L4_PER_MMC_SD5, OMAP44XX_MAP_L4_PER_MMC_SD5_SIZE},
         {0x0, 0x0}
     }
 };
@@ -117,7 +119,7 @@ static struct allowed_registers omap_uart = {
 };
 
 static struct allowed_registers sdma = {
-    .binary = "hw.arm.omap44xx.sdma",
+    .binary = "sdma",
     .registers =
     {
         {OMAP44XX_MAP_L4_CFG_SDMA, OMAP44XX_MAP_L4_CFG_SDMA_SIZE},
@@ -128,6 +130,8 @@ static struct allowed_registers sdma = {
 static struct allowed_registers* omap44xx[] = {
     &usb,
     &fdif,
+    &twl6030,
+    &cm2,
     &mmchs,
     &prcm,
     &omap_uart,
@@ -239,3 +243,98 @@ default_start_function(coreid_t where, struct module_info* driver,
 
     return SYS_ERR_OK;
 }
+
+static void provide_driver_with_caps(struct driver_instance* drv, char* name) {
+    errval_t err;
+
+    struct monitor_blocking_binding *m = get_monitor_blocking_binding();
+    assert(m != NULL);
+
+    uint32_t arch, platform;
+    err = m->rpc_tx_vtbl.get_platform(m, &arch, &platform);
+    assert(err_is_ok(err));
+    assert(arch == PI_ARCH_ARMV7A);
+
+    struct allowed_registers **regs= NULL;
+    switch(platform) {
+    case PI_PLATFORM_OMAP44XX:
+        regs= omap44xx;
+        break;
+    case PI_PLATFORM_VEXPRESS:
+        regs= vexpress;
+        break;
+    default:
+        printf("Unrecognised ARMv7 platform\n");
+        abort();
+    }
+
+
+    KALUGA_DEBUG("%s:%d: Finding caps for driver for %s\n", __FUNCTION__, __LINE__, name);
+    for (size_t i=0; regs[i] != NULL; i++) {
+        if(strcmp(name, regs[i]->binary) != 0) {
+            continue;
+        }
+
+        // Get the device cap from the managed capability tree
+        // put them all in a single cnode
+        for (size_t j=0; regs[i]->registers[j][0] != 0x0; j++) {
+            struct capref device_frame;
+            KALUGA_DEBUG("%s:%d: mapping 0x%"PRIxLPADDR" %"PRIuLPADDR"\n", __FUNCTION__, __LINE__,
+            regs[i]->registers[j][0], regs[i]->registers[j][1]);
+
+            lpaddr_t base = regs[i]->registers[j][0] & ~(BASE_PAGE_SIZE-1);
+            err = get_device_cap(base, regs[i]->registers[j][1], &device_frame);
+            assert(err_is_ok(err));
+
+            KALUGA_DEBUG("get_device_cap worked\n");
+            err = ddomain_driver_add_cap(drv, device_frame);
+            assert(err_is_ok(err));
+        }
+    }
+}
+
+
+/**
+ * \brief Startup function for new-style ARMv7 drivers.
+ *
+ * Launches the driver instance in a driver domain instead.
+ */
+errval_t
+newstyle_start_function(coreid_t where, struct module_info* driver, char* record,
+                        struct driver_argument* int_arg)
+{
+    assert(driver != NULL);
+    assert(record != NULL);
+    errval_t err;
+
+    struct domain_instance* inst = instantiate_driver_domain(where);
+
+    char* dep1;
+    err = oct_read(record, "_ { dep1: %s }", &dep1);
+    if (err_is_ok(err)) {
+        struct driver_instance* drv1 = ddomain_create_driver_instance(dep1, dep1);
+        provide_driver_with_caps(drv1, dep1);
+        free(dep1);
+        ddomain_instantiate_driver(inst, drv1);
+    }
+
+    char* dep2;
+    err = oct_read(record, "_ { dep2: %s }", &dep2);
+    if (err_is_ok(err)) {
+        struct driver_instance* drv2 = ddomain_create_driver_instance(dep2, dep2);
+        provide_driver_with_caps(drv2, dep2);
+        free(dep2);
+        ddomain_instantiate_driver(inst, drv2);
+    }
+
+    char* name;
+    err = oct_read(record, "%s", &name);
+    assert(err_is_ok(err));
+
+    struct driver_instance* drv = ddomain_create_driver_instance(name, name);
+    provide_driver_with_caps(drv, name);
+    free(name);
+
+    ddomain_instantiate_driver(inst, drv);
+    return SYS_ERR_OK;
+}
index 5fec56c..8365793 100644 (file)
@@ -15,8 +15,9 @@
 #ifndef KALUGA_DEBUG_H_
 #define KALUGA_DEBUG_H_
 
+//#define KALUGA_DEBUG_ON
 
-#if defined(KALUGA_SERVICE_DEBUG) || defined(GLOBAL_DEBUG)
+#if defined(KALUGA_DEBUG_ON) || defined(GLOBAL_DEBUG)
 #define KALUGA_DEBUG(x...) debug_printf(x)
 #else
 #define KALUGA_DEBUG(x...) ((void)0)
diff --git a/usr/kaluga/driver_domains.c b/usr/kaluga/driver_domains.c
new file mode 100644 (file)
index 0000000..936d626
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2016, ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <barrelfish/barrelfish.h>
+#include <barrelfish/spawn_client.h>
+
+#include <driverkit/driverkit.h>
+
+#include "kaluga.h"
+
+#define DRIVER_DOMAIN_NAME "driverdomain"
+
+// Add an argument to argc/argv pair. argv must be mallocd!
+static void argv_push(int * argc, char *** argv, char * new_arg){
+    int new_size = *argc + 1;
+    *argv = realloc(*argv, (new_size+1) * sizeof(char*)); // +1 for last NULL entry.
+    if(*argv == NULL){
+        USER_PANIC("Could not allocate argv memory");
+    }
+    *argc = new_size;
+    (*argv)[new_size-1] = new_arg;
+    (*argv)[new_size] = NULL;
+}
+
+static errval_t launch_driver_domain(coreid_t where, uint64_t did, struct module_info* ddomain)
+{
+    assert(ddomain != NULL);
+    errval_t err = SYS_ERR_OK;
+
+    char **argv = NULL;
+    int argc = ddomain->argc;
+    argv = malloc(sizeof(char*)*ddomain->argc); // +1 for trailing NULL
+    assert(argv != NULL);
+
+    memcpy(argv, ddomain->argv, (argc+1) * sizeof(char *));
+    assert(argv[argc] == NULL);
+
+    char* did_str = calloc(26, sizeof(char));
+    assert(did_str != NULL);
+    snprintf(did_str, 26, "%"PRIu64"", did);
+    argv_push(&argc, &argv, did_str);
+
+    err = spawn_program_with_caps(where, ddomain->path, argv,
+                                  environ, NULL_CAP, NULL_CAP,
+                                  0, get_did_ptr(ddomain));
+    if (err_is_fail(err)) {
+        DEBUG_ERR(err, "Spawning %s failed.", ddomain->path);
+    }
+
+    free(argv);
+    return err;
+}
+
+static void wait_for_id(struct domain_instance* di) {
+    while (di->b == NULL) {
+        messages_wait_and_handle_next();
+    }
+    KALUGA_DEBUG("%s:%s:%d: done with waiting for ID\n", __FILE__, __FUNCTION__, __LINE__);
+}
+
+struct domain_instance* instantiate_driver_domain(coreid_t where) {
+    static uint64_t did = 1;
+
+    errval_t err = launch_driver_domain(0, did, find_module(DRIVER_DOMAIN_NAME));
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "call failed.");
+    }
+    struct domain_instance* di = ddomain_create_domain_instance(did);
+    wait_for_id(di);
+
+    did++;
+    return di;
+}
diff --git a/usr/kaluga/driver_domains.h b/usr/kaluga/driver_domains.h
new file mode 100644 (file)
index 0000000..cdedf62
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef DRIVER_DOMAIN_H_
+#define DRIVER_DOMAIN_H_
+
+#include <errors/errno.h>
+
+#include "boot_modules.h"
+
+struct domain_instance* instantiate_driver_domain(coreid_t where);
+
+#endif /* DRIVER_DOMAIN_H_ */
index 9e391a4..ea5e2af 100644 (file)
@@ -11,4 +11,7 @@ errval_t default_start_function(coreid_t, struct module_info*, char*,
 errval_t start_networking(coreid_t, struct module_info*, char*,
         struct driver_argument * arg);
 
+errval_t newstyle_start_function(coreid_t where, struct module_info* driver, char* record,
+        struct driver_argument* int_arg);
+
 #endif /* DRIVER_STARTUP_H_ */
index fb9b82f..5a5f719 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <barrelfish/barrelfish.h>
 #include <octopus/octopus.h>
+#include <driverkit/driverkit.h>
 
 #include "queue.h"
 #include "debug.h"
@@ -19,6 +20,7 @@ extern char **environ;
 #include "start_cpu.h"
 #include "driver_startup.h"
 #include "device_caps.h"
+#include "driver_domains.h"
 #include "int_route/int_model.h"
 
 errval_t arch_startup(char * add_device_db_file);
index 42682e4..f03d3bf 100644 (file)
@@ -49,6 +49,9 @@ static void add_start_function_overrides(void)
     set_start_function("e1000n", start_networking);
     set_start_function("rtl8029", start_networking);
     set_start_function("corectrl", start_boot_driver);
+#ifdef __ARM_ARCH_7A__
+    set_start_function("driverdomain", newstyle_start_function);
+#endif
 }
 
 static void parse_arguments(int argc, char** argv, char ** add_device_db_file, size_t *cpu_count)
@@ -101,6 +104,8 @@ int main(int argc, char** argv)
 
     KALUGA_DEBUG("Kaluga: parse boot modules...\n");
 
+    ddomain_controller_init();
+
     err = init_boot_modules();
     if (err_is_fail(err)) {
         USER_PANIC_ERR(err, "Parse boot modules.");
@@ -115,4 +120,3 @@ int main(int argc, char** argv)
     THCFinish();
     return EXIT_SUCCESS;
 }
-