Adapted the Xeon Phi driver to make use of the DMA driver library
authorReto Achermann <acreto@student.ethz.ch>
Sun, 27 Jul 2014 12:55:16 +0000 (14:55 +0200)
committerStefan Kaestle <stefan.kaestle@inf.ethz.ch>
Wed, 20 Aug 2014 21:39:56 +0000 (23:39 +0200)
14 files changed:
errors/errno.fugu
if/Hakefile
if/xeon_phi_dma.if [deleted file]
include/dma/dma_service.h
lib/dma/Hakefile
lib/dma/dma_service.c
lib/xeon_phi/Hakefile
usr/drivers/xeon_phi/Hakefile
usr/drivers/xeon_phi/dma_service.c [new file with mode: 0644]
usr/drivers/xeon_phi/dma_service.h [new file with mode: 0644]
usr/drivers/xeon_phi/main_card.c
usr/drivers/xeon_phi/main_host.c
usr/drivers/xeon_phi/service.c
usr/drivers/xeon_phi/xeon_phi_internal.h

index 8542702..432930f 100755 (executable)
@@ -1074,6 +1074,9 @@ errors dma DMA_ERR_ {
     failure CHAN_IDLE             "There were no finished requests on the channel",
     failure REQUEST_UNFINISHED    "The request is still in operation",
     failure REQUEST_UNSUPPORTED   "Request is not supported by this device/channel",
+    failure REQUEST_TOO_LARGE     "Request size is too large",
+    failure REQUEST_ID            "Request with that ID does not exist",
+    failure ALIGNMENT             "The address / size is worngly alined",
     failure MEM_OVERLAP           "The memory regions overlap",
     failure MEM_NOT_REGISTERED    "The memory region was not registered",
     failure MEM_OUT_OF_RANGE      "Memory region is out of supported range",
index f2800f8..201862a 100644 (file)
@@ -76,7 +76,6 @@
                "xeon_phi_driver",
                "xeon_phi_manager",
                "xeon_phi_messaging",
-               "xeon_phi_dma",
                "virtio",
                "block_service",
                "bulk_ctrl",
diff --git a/if/xeon_phi_dma.if b/if/xeon_phi_dma.if
deleted file mode 100644 (file)
index b3f3d41..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/** \file
- *  \brief Xeon Phi Service Interface
- */
-
-/*
- * 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, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
- */
-
-interface xeon_phi_dma "Xeon Phi DMA Interface" {
-
-    typedef uint64 id;
-    
-       /**
-        * \brief registers a memory region to be used for DMA transfers
-        * 
-        * \param IN  memory    the memory region to register
-        * \param OUT msgerr    the result of the operation
-        * 
-        * Note: either local or remote memory must be registered
-        */
-    rpc register(in cap memory, out errval msgerr);
-    
-
-    /**
-     * \brief deregisters a memory region to be used for DMA transfers
-     * 
-     * \param IN  memory    the memory region to register
-     * \param OUT msgerr    the result of the operation
-     * 
-     * Note: either local or remote memory must be registered
-     */
-    rpc deregister(in cap memory, out errval msgerr);
-  
-    /**
-     * \brief issues a new DMA transfer request to the Xeon Phi DMA controller
-     * 
-     * \param IN  src    source address for the transfer 
-     * \param IN  dsc    destination address of the transfer
-     * \param IN  length size of the transfer in bytes
-     * \param OUT err    result of the transfer request
-     * \param OUT id     returns the id of the transfer
-     */
-    rpc exec(in uint64 src, in uint64 dst, in uint64 length, 
-             out errval err, out id id);
-    
-    /**
-     * \brief stops a initiated DMA transfer
-     * 
-     * \param IN  id    the id of the completed transfer
-     * \param OUT err   the result of
-     */
-    rpc stop(in id id, out errval err);
-    
-    /**
-     * \brief DMA transfer done notification
-     * 
-     * \param id    the id of the completed transfer
-     * \param err   the result of the transfer
-     */
-    message done(id id, errval err);
-    
-};
\ No newline at end of file
index 34e0aa2..9f8d655 100644 (file)
@@ -23,7 +23,7 @@ typedef struct dma_svc_st* dma_svc_handle_t;
 struct dma_service_cb
 {
     /** informs about the new connection on the service */
-    errval_t (*connect)(void **user_st);
+    errval_t (*connect)(void *arg, void **user_st);
 
     /** registers a memory region to be used */
     errval_t (*addregion)(dma_svc_handle_t svc_handle,
@@ -45,12 +45,14 @@ struct dma_service_cb
  * \brief initializes the DMA service and registers with the DMA manager
  *
  * \param cb        Callback function pointers
+ * \param arg       Argument passed to the connect callback
  * \param svc_iref  Returns the exported iref
  *
  * \returns SYS_ERR_OK on success
  *          errval on error
  */
 errval_t dma_service_init(struct dma_service_cb *cb,
+                          void *arg,
                           iref_t *svc_iref);
 
 /**
@@ -58,6 +60,7 @@ errval_t dma_service_init(struct dma_service_cb *cb,
  *
  * \param svc_name  The name of the service for nameservice registration
  * \param cb        Callback function pointers
+ * \param arg       Argument passed to the connect callback
  * \param svc_iref  Returns the exported iref
  *
  * \returns SYS_ERR_OK on success
@@ -65,6 +68,7 @@ errval_t dma_service_init(struct dma_service_cb *cb,
  */
 errval_t dma_service_init_with_name(char *svc_name,
                                     struct dma_service_cb *cb,
+                                    void *arg,
                                     iref_t *svc_iref);
 
 /**
index 0e31f32..be29c2f 100644 (file)
     flounderBindings = [ "dma", "dma_mgr" ],
     flounderExtraBindings = [ ("dma_mgr",["rpcclient"]) ],
     flounderDefs = [ "dma" ]
+  },
+  
+  build library { 
+    target = "dma_client",
+    cFiles = [
+      "dma_mem_mgr.c",
+      "dma_mem_utils.c",
+      "dma_mgr_client.c",
+      "dma_device.c",
+      "dma_channel.c",
+      "dma_request.c",
+      "dma_ring.c",
+      "dma_descriptor.c",
+      "dma_bench.c",
+      "client/dma_client_device.c",
+      "client/dma_client_channel.c",
+      "client/dma_client_request.c"
+    ],
+    addIncludes = [ "include" ],
+    addLibraries = libDeps [ "bench" ],
+    flounderBindings = [ "dma", "dma_mgr" ],
+    flounderDefs = [ "dma" ],
+    flounderExtraBindings = [ ("dma_mgr",["rpcclient"]) ]
   }
 ]
 
index 066dc1d..1f4f9c3 100644 (file)
@@ -44,6 +44,9 @@ enum dma_svc_state
 /// represents the current state of the exporting process
 static enum dma_svc_state dma_svc_state = DMA_SVC_STATE_EXPORTING;
 
+/// error while exporting
+static errval_t dma_svc_err;
+
 /// our own iref of the exported service
 static iref_t dma_svc_iref;
 
@@ -209,6 +212,13 @@ static errval_t dma_done_tx(struct txq_msg_st *msg_st)
  * ----------------------------------------------------------------------------
  */
 
+struct export_arg
+{
+    errval_t err;
+    void *user_st;
+};
+
+
 static errval_t svc_connect_cb(void *st,
                                struct dma_binding *binding)
 {
@@ -230,7 +240,7 @@ static errval_t svc_connect_cb(void *st,
              (txq_register_fn_t) binding->register_send,
              sizeof(struct dma_svc_reply_st));
 
-    err = event_handlers->connect(&state->usr_st);
+    err = event_handlers->connect(st, &state->usr_st);
     if (err_is_fail(err)) {
         /* reject the connection */
         DMASVC_DEBUG("application rejected the connection: %s\n",
@@ -250,7 +260,7 @@ static void svc_export_cb(void *st,
                           errval_t err,
                           iref_t iref)
 {
-    *((errval_t *) st) = err;
+    dma_svc_err = err;
 
     if (err_is_fail(err)) {
         dma_svc_state = DMA_SVC_STATE_EXPORT_FAIL;
@@ -271,20 +281,22 @@ static void svc_export_cb(void *st,
  * \brief initializes the DMA service and registers with the DMA manager
  *
  * \param cb        Callback function pointers
+ * \param arg       Argument passed to the connect callback
  * \param svc_iref  Returns the exported iref
  *
- *
  * \returns SYS_ERR_OK on success
  *          errval on error
  */
 errval_t dma_service_init(struct dma_service_cb *cb,
+                          void *arg,
                           iref_t *svc_iref)
 {
-    errval_t err, export_err;
+    errval_t err;
 
     DMASVC_DEBUG("Initializing DMA service...\n");
 
-    err = dma_export(&export_err, svc_export_cb, svc_connect_cb,
+
+    err = dma_export(arg, svc_export_cb, svc_connect_cb,
                      get_default_waitset(),
                      IDC_EXPORT_FLAGS_DEFAULT);
     if (err_is_fail(err)) {
@@ -296,7 +308,7 @@ errval_t dma_service_init(struct dma_service_cb *cb,
     }
 
     if (dma_svc_state == DMA_SVC_STATE_EXPORT_FAIL) {
-        return export_err;
+        return dma_svc_err;
     }
 
     dma_svc_state = DMA_SVC_STATE_RUNNING;
@@ -316,6 +328,7 @@ errval_t dma_service_init(struct dma_service_cb *cb,
  *
  * \param svc_name  The name of the service for nameservice registration
  * \param cb        Callback function pointers
+ * \param arg       Argument passed to the connect callback
  * \param svc_iref  Returns the exported iref
  *
  * \returns SYS_ERR_OK on success
@@ -323,13 +336,14 @@ errval_t dma_service_init(struct dma_service_cb *cb,
  */
 errval_t dma_service_init_with_name(char *svc_name,
                                     struct dma_service_cb *cb,
+                                    void *arg,
                                     iref_t *svc_iref)
 {
-    errval_t err, export_err;
+    errval_t err;
 
     DMASVC_DEBUG("Initializing DMA service...\n");
 
-    err = dma_export(&export_err, svc_export_cb, svc_connect_cb,
+    err = dma_export(arg, svc_export_cb, svc_connect_cb,
                      get_default_waitset(),
                      IDC_EXPORT_FLAGS_DEFAULT);
     if (err_is_fail(err)) {
@@ -341,7 +355,7 @@ errval_t dma_service_init_with_name(char *svc_name,
     }
 
     if (dma_svc_state == DMA_SVC_STATE_EXPORT_FAIL) {
-        return export_err;
+        return dma_svc_err;
     }
 
     dma_svc_state = DMA_SVC_STATE_NS_REGISTERING;
index bb2f5f3..0e25dcd 100644 (file)
 -- 
 --------------------------------------------------------------------------
 
-[ build library { target = "xeon_phi_manager_client",
-                      cFiles = [ "xeon_phi_manager_client.c" ],
-                      flounderDefs = ["xeon_phi_manager"],
-                      flounderBindings = ["xeon_phi_manager"],
-                      architectures = ["x86_64"]
-                },
-  build library { target = "xeon_phi_messaging",
-                      cFiles = [ "xeon_phi_messaging.c" ],
-                      flounderDefs = ["xeon_phi_messaging"],
-                      flounderBindings = ["xeon_phi_messaging"],
-                      architectures = ["k1om", "x86_64"]
-                },
-  build library { target = "xeon_phi_messaging_client",
-                      cFiles = [ "xeon_phi_messaging_client.c" ],
-                      flounderDefs = ["xeon_phi_messaging"],
-                      flounderBindings = ["xeon_phi_messaging"],
-                      architectures = ["k1om", "x86_64"]
-                },
-  build library { target = "xeon_phi_dma_client",
-                      cFiles = [ "xeon_phi_dma_client.c" ],
-                      flounderDefs = ["xeon_phi_dma"],
-                      flounderBindings = ["xeon_phi_dma"],
-                      architectures = ["k1om", "x86_64"]
-                }                   
+[ build library { 
+       target = "xeon_phi_manager_client",
+       architectures = ["x86_64"],
+       cFiles = [ "xeon_phi_manager_client.c" ],
+    flounderDefs = ["xeon_phi_manager"],
+    flounderBindings = ["xeon_phi_manager"]
+  },
+                
+  build library { 
+       target = "xeon_phi_messaging",
+    architectures = [
+      "k1om", 
+      "x86_64"
+    ],
+    cFiles = [ "xeon_phi_messaging.c" ],
+    flounderDefs = ["xeon_phi_messaging"],
+    flounderBindings = ["xeon_phi_messaging"]
+  },
+  
+  build library { 
+       target = "xeon_phi_messaging_client",
+    architectures = [
+      "k1om", 
+      "x86_64"
+    ],
+    cFiles = [ "xeon_phi_messaging_client.c" ],
+    flounderDefs = ["xeon_phi_messaging"],
+    flounderBindings = ["xeon_phi_messaging"]
+  }                  
 ]
index 8fdfedf..4114bd8 100644 (file)
 -- 
 --------------------------------------------------------------------------
 
-[ build application { target = "xeon_phi",
-                      cFiles = [ "main_host.c",
-                                 "xeon_phi.c", 
-                                 "boot.c", 
-                                 "serial.c", 
-                                 "interrupts.c", 
-                                 "service.c",
-                                 "spawn.c", 
-                                 "smpt.c",
-                                 "sysmem_caps.c",
-                                 "messaging.c", 
-                                 "sleep.c",
-                                 "dma/dma.c",
-                                 "dma/dma_channel.c",
-                                 "dma/dma_descriptor_ring.c",
-                                 "dma/dma_mem.c",
-                                 "dma/dma_service.c",
-                                 "dma/dma_benchmark.c"  ],
-                      addLibraries = libDeps ["skb", 
-                                              "pci", 
-                                              "spawndomain", 
-                                              "elf", 
-                                              "vfs",
-                                              "lwip",
-                                              "bench", 
-                                              "xeon_phi_manager_client", 
-                                               "xeon_phi_messaging", 
-                                               "mm"],
-                 --     flounderExtraDefs = [ ("monitor_blocking",["rpcclient"]) ],
-                      flounderDefs = ["xeon_phi_manager", "xeon_phi_driver", "xeon_phi_messaging", "xeon_phi_dma"],
-                      flounderBindings = ["xeon_phi_driver", "xeon_phi_messaging", "xeon_phi_dma"],
-                      architectures= ["x86_64"],
-                      mackerelDevices = [ "xeon_phi/xeon_phi_apic", 
-                                          "xeon_phi/xeon_phi_boot", 
-                                          "xeon_phi/xeon_phi_serial",
-                                          "xeon_phi/xeon_phi_smpt", 
-                                          "xeon_phi/xeon_phi_irq",
-                                          "xeon_phi/xeon_phi_dma"]
-                    },
+[ 
+  build application { 
+       target = "xeon_phi",
+       architectures= ["x86_64"],
+    cFiles = [ 
+      "main_host.c",
+      "xeon_phi.c", 
+         "boot.c", 
+         "serial.c", 
+         "interrupts.c", 
+         "service.c",
+         "spawn.c", 
+         "smpt.c",
+         "sysmem_caps.c",
+         "messaging.c", 
+         "sleep.c",
+         "dma_service.c"
+       ],
+    addLibraries = libDeps [
+      "skb", 
+      "pci", 
+      "spawndomain",
+      "dma", 
+      "dma_service",
+      "elf", 
+      "vfs",
+      "lwip",
+      "bench", 
+      "xeon_phi_manager_client", 
+      "xeon_phi_messaging", 
+      "mm"
+    ],
+    flounderDefs = [
+      "xeon_phi_manager", 
+      "xeon_phi_driver", 
+      "xeon_phi_messaging"
+    ],
+    flounderBindings = [
+      "xeon_phi_driver", 
+      "xeon_phi_messaging"
+    ],
+    mackerelDevices = [ 
+      "xeon_phi/xeon_phi_apic", 
+      "xeon_phi/xeon_phi_boot", 
+      "xeon_phi/xeon_phi_serial",
+      "xeon_phi/xeon_phi_smpt", 
+      "xeon_phi/xeon_phi_irq"
+    ]
+  },
                     
-                    build application { target = "xeon_phi",
-                      cFiles = [ "main_card.c",
-                                 "sysmem_caps.c",
-                                 "spawn.c",
-                                 "smpt.c",
-                                 "messaging.c",
-                                 "dma/dma.c",
-                                 "dma/dma_channel.c",
-                                 "dma/dma_descriptor_ring.c",
-                                 "dma/dma_mem.c",
-                                 "dma/dma_service.c",
-                                 "dma/dma_benchmark.c"    ],                      
-                      flounderDefs = ["xeon_phi_messaging", "xeon_phi_dma"],
-                      flounderBindings = ["xeon_phi_messaging", "xeon_phi_dma"],
-                      addLibraries = libDeps [ "mm", "spawndomain", "xeon_phi_messaging", "bench" ],
-                      architectures= ["k1om"],
-                      mackerelDevices = [ "xeon_phi/xeon_phi_apic", 
-                                          "xeon_phi/xeon_phi_boot", 
-                                          "xeon_phi/xeon_phi_serial",
-                                          "xeon_phi/xeon_phi_smpt", 
-                                          "xeon_phi/xeon_phi_irq",
-                                          "xeon_phi/xeon_phi_dma"]
-                    }
+  build application { 
+    target = "xeon_phi",
+    architectures= ["k1om"],
+       cFiles = [ 
+         "main_card.c",
+         "sysmem_caps.c",
+         "spawn.c",
+         "smpt.c",
+         "messaging.c",
+         "dma_service.c" 
+       ],                      
+       flounderDefs = [
+         "xeon_phi_messaging"
+       ],
+       flounderBindings = [
+         "xeon_phi_messaging"
+       ],
+       addLibraries = libDeps [ 
+         "mm", 
+         "spawndomain", 
+         "dma",
+         "dma_service",
+         "xeon_phi_messaging", 
+         "bench" ],
+       mackerelDevices = [ 
+         "xeon_phi/xeon_phi_apic", 
+         "xeon_phi/xeon_phi_boot", 
+         "xeon_phi/xeon_phi_serial",
+         "xeon_phi/xeon_phi_smpt", 
+         "xeon_phi/xeon_phi_irq"
+       ]
+  }
 ]
 
 
diff --git a/usr/drivers/xeon_phi/dma_service.c b/usr/drivers/xeon_phi/dma_service.c
new file mode 100644 (file)
index 0000000..e5e0c64
--- /dev/null
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 2014 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 <barrelfish/barrelfish.h>
+#include <dma/xeon_phi/xeon_phi_dma.h>
+#include <dma/xeon_phi/xeon_phi_dma_device.h>
+#include <dma/xeon_phi/xeon_phi_dma_request.h>
+#include <dma/dma_service.h>
+#include <dma/dma_mem_mgr.h>
+#include <dma/dma_manager_client.h>
+
+#include <xeon_phi/xeon_phi.h>
+
+#include "xeon_phi_internal.h"
+#include "dma_service.h"
+
+struct user_st
+{
+    struct dma_mem_mgr *mem_mgr;
+    struct xeon_phi *phi;
+    uint64_t num_req;
+};
+
+static void memcpy_req_cb(errval_t err,
+                          dma_req_id_t id,
+                          void *st)
+{
+    XDMA_DEBUG("memcpy_req_cb %lx, %s\n", id, err_getstring(err));
+    dma_service_send_done(st, err, id);
+}
+
+static lpaddr_t translate_address(void *arg,
+                                  lpaddr_t addr,
+                                  size_t size)
+{
+#ifdef __k1om__
+    if ((addr + size) > (1UL << 40)) {
+        return 0;
+    }
+    return addr;
+#else
+    struct xeon_phi *phi = ((struct user_st *)arg)->phi;
+    lpaddr_t apt_lo = phi->apt.pbase;
+    lpaddr_t apt_hi = phi->apt.pbase + phi->apt.bytes;
+    if ((addr >= apt_lo) && ((addr + size) <= apt_hi)) {
+        /* we are within the GDDR range */
+        return addr - apt_lo;
+    } else if ((addr + size)< XEON_PHI_SYSMEM_SIZE) {
+        /*
+         * Xeon Phi does not support more host memory,
+         * assume host memory starts at 0x0
+         */
+        return addr + XEON_PHI_SYSMEM_BASE;
+    } else {
+        return 0;
+    }
+#endif
+}
+
+/*
+ * ---------------------------------------------------------------------------
+ * Callbacks for the service events
+ * ---------------------------------------------------------------------------
+ */
+
+/*
+ * \brief callback handler for new connect requests
+ *
+ * \param arg       argument passed on the init function
+ * \param user_st   pointer to store the user state
+ *
+ * \returns SYS_ERR_OK if the connection is accepted
+ *          errval if connection is rejected
+ */
+static errval_t dma_svc_connect_cb(void *arg,
+                                   void **user_st)
+{
+    errval_t err;
+
+    struct user_st *st = calloc(1, sizeof(*st));
+    if (st == NULL) {
+        return LIB_ERR_MALLOC_FAIL;
+    }
+
+    XDMA_DEBUG("dma_svc_connect_cb user_st = %p\n", st);
+
+    err = dma_mem_mgr_init(&st->mem_mgr, 0x0, (1UL << 48) - 1);
+    if (err_is_fail(err)) {
+        free(st);
+        return err;
+    }
+
+    st->phi = arg;
+
+    dma_mem_mgr_set_convert_fn(st->mem_mgr, translate_address, st);
+
+    *user_st = st;
+
+    return SYS_ERR_OK;
+}
+
+/**
+ * \brief registers a memory region with the client such that it can be used later
+ *
+ * \param user_st   pointer to stored user state
+ * \param cap       the capability to register
+ *
+ * \returns SYS_ERR_OK if the memory region was accepted
+ *          errval if the memory region was rejected
+ */
+static errval_t dma_svc_addregion_cb(dma_svc_handle_t svc_handle,
+                                     struct capref cap)
+{
+    struct user_st *user_st = dma_service_get_user_state(svc_handle);
+
+    XDMA_DEBUG("dma_svc_addregion_cb user_st = %p\n", user_st);
+
+    return dma_mem_register(user_st->mem_mgr, cap);
+}
+
+/**
+ * \brief deregisters a memory region with the client
+ *
+ * \param user_st   pointer to stored user state
+ * \param cap       the capability to deregister
+ *
+ * \returns SYS_ERR_OK if the memory region was removed
+ *          errval if the memory region removal was rejected
+ */
+static errval_t dma_svc_removeregion_cb(dma_svc_handle_t svc_handle,
+                                        struct capref cap)
+{
+    struct user_st *user_st = dma_service_get_user_state(svc_handle);
+
+    XDMA_DEBUG("dma_svc_removeregion_cb user_st = %p\n", user_st);
+
+    return dma_mem_deregister(user_st->mem_mgr, cap);
+}
+
+/**
+ * \brief executes a DMA memcpy
+ *
+ * \param user_st   pointer to stored user state
+ * \param dst       the physical destination address
+ * \param src       the physical source address
+ * \param bytes     size of the transfer in bytes
+ * \param id        returns the DMA request ID of the transfer
+ *
+ * \returns SYS_ERR_OK if the memory region was removed
+ *          errval if the memory region removal was rejected
+ */
+static errval_t dma_svc_memcpy_cb(dma_svc_handle_t svc_handle,
+                                  lpaddr_t dst,
+                                  lpaddr_t src,
+                                  size_t bytes,
+                                  dma_req_id_t *id)
+{
+    errval_t err;
+
+    struct user_st *st = dma_service_get_user_state(svc_handle);
+
+    XDMA_DEBUG("dma_svc_memcpy_cb user_st = %p\n", st);
+
+    lpaddr_t dma_dst, dma_src;
+    err = dma_mem_verify(st->mem_mgr, dst, bytes, &dma_dst);
+    if (err_is_fail(err)) {
+        return err;
+    }
+    err = dma_mem_verify(st->mem_mgr, src, bytes, &dma_src);
+    if (err_is_fail(err)) {
+        return err;
+    }
+
+    XDMA_DEBUG("[%016lx]->[%016lx] of %lu bytes\n", dma_src, dma_dst, bytes);
+
+    /* both addresses are valid and have been translated now */
+    struct dma_device *dev = st->phi->dma;
+    assert(dev);
+
+    struct dma_req_setup setup = {
+        .type = DMA_REQ_TYPE_MEMCPY,
+        .done_cb = memcpy_req_cb,
+        .cb_arg = svc_handle,
+        .args = {
+            .memcpy = {
+                .src = dma_src,
+                .dst = dma_dst,
+                .bytes = bytes
+            }
+        }
+    };
+
+    return dma_request_memcpy(dev, &setup, id);
+}
+
+static struct dma_service_cb dma_svc_cb = {
+    .connect = dma_svc_connect_cb,
+    .addregion = dma_svc_addregion_cb,
+    .removeregion = dma_svc_removeregion_cb,
+    .memcpy = dma_svc_memcpy_cb
+};
+
+/**
+ * \brief initializes the Xeon Phi DMA devices and the service
+ *
+ * \param phi   Xeon Phi handle
+ *
+ * \returns SYS_ERR_OK on success
+ */
+errval_t xdma_service_init(struct xeon_phi *phi)
+{
+    errval_t err;
+
+    void *mmio_base = NULL;
+#ifdef __k1om__
+    mmio_base = (void *) (phi->mmio.vbase);
+#else
+    mmio_base = (void *) XEON_PHI_MMIO_TO_SBOX(phi);
+#endif
+
+    struct xeon_phi_dma_device *dev;
+    err = xeon_phi_dma_device_init(mmio_base, &dev);
+    if (err_is_fail(err)) {
+        return err;
+    }
+
+    phi->dma = (struct dma_device *)dev;
+
+    iref_t svc_iref;
+    char svc_name[30];
+    uint8_t numa_node = (disp_get_core_id() >= 20);
+    snprintf(svc_name, 30, "%s.%u", XEON_PHI_DMA_SERVICE_NAME, numa_node);
+    err = dma_service_init_with_name(svc_name, &dma_svc_cb, phi, &svc_iref);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "Failed to start the DMA service");
+    }
+#ifndef __k1om__
+    err = dma_manager_register_driver(0, 1ULL << 40, DMA_DEV_TYPE_XEON_PHI,
+                                      svc_iref);
+    if (err_is_fail(err)) {
+        USER_PANIC_ERR(err, "Failed to register with the DMA manager\n");
+    }
+#endif
+    return SYS_ERR_OK;
+}
+
diff --git a/usr/drivers/xeon_phi/dma_service.h b/usr/drivers/xeon_phi/dma_service.h
new file mode 100644 (file)
index 0000000..9ff8f98
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014 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.
+ */
+
+#ifndef XEON_PHI_DMA_SERVICE_H_
+#define XEON_PHI_DMA_SERVICE_H_
+
+#include <dma/dma.h>
+#include <dma/dma_device.h>
+
+/**
+ * \brief initializes the Xeon Phi DMA devices and the service
+ *
+ * \param phi   Xeon Phi handle
+ *
+ * \returns SYS_ERR_OK on success
+ */
+errval_t xdma_service_init(struct xeon_phi *phi);
+
+/**
+ *
+ */
+static inline errval_t xdma_service_poll(struct xeon_phi *phi)
+{
+    return dma_device_poll_channels(phi->dma);
+}
+
+#endif /* XEON_PHI_DMA_SERVICE_H_ */
index 1459cf6..19504f2 100644 (file)
@@ -22,9 +22,8 @@
 
 #include "xeon_phi_internal.h"
 #include "messaging.h"
-#include "service.h"
+#include "dma_service.h"
 #include "sysmem_caps.h"
-#include "dma/dma.h"
 #include "smpt.h"
 
 static struct xeon_phi xphi;
@@ -107,7 +106,7 @@ int main(int argc,
         USER_PANIC_ERR(err, "could not map the mmio space");
     }
 
-    err = dma_init(&xphi);
+    err = xdma_service_init(&xphi);
     if (err_is_fail(err)) {
         USER_PANIC_ERR(err, "Could not initialize the dma engine.\n");
     }
@@ -145,7 +144,7 @@ int main(int argc,
         uint8_t idle = 0x1;
         err = messaging_poll(&xphi);
         idle = idle && (err_no(err) == LIB_ERR_NO_EVENT);
-        err = dma_poll_channels(&xphi);
+        err = xdma_service_poll(&xphi);
         idle = idle && (err_no(err) == XEON_PHI_ERR_DMA_IDLE);
         err = event_dispatch_non_block(get_default_waitset());
         if (err_is_fail(err)) {
index 649d94c..a7956a6 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "xeon_phi_internal.h"
 #include "smpt.h"
-#include "dma/dma.h"
+#include "dma_service.h"
 #include "service.h"
 #include "messaging.h"
 #include "sysmem_caps.h"
@@ -124,7 +124,7 @@ int main(int argc,
         USER_PANIC_ERR(err, "could not boot the card\n");
     }
 
-    err = dma_init(&xphi);
+    err = xdma_service_init(&xphi);
     if (err_is_fail(err)) {
         USER_PANIC_ERR(err, "could not initialize the DMA engine\n");
     }
index a2df4ec..e635497 100644 (file)
@@ -23,7 +23,7 @@
 #include "xeon_phi_internal.h"
 #include "service.h"
 #include "messaging.h"
-#include "dma/dma.h"
+#include "dma_service.h"
 #include "smpt.h"
 
 static uint32_t is_exported;
@@ -465,8 +465,8 @@ errval_t service_start(struct xeon_phi *phi)
         uint8_t idle = 0x1;
         err = messaging_poll(phi);
         idle = idle && (err_no(err) == LIB_ERR_NO_EVENT);
-        err = dma_poll_channels(phi);
-        idle = idle && (err_no(err) == XEON_PHI_ERR_DMA_IDLE);
+        err = xdma_service_poll(phi);
+        idle = idle && (err_no(err) == DMA_ERR_DEVICE_IDLE);
         err = handle_messages(idle);
         if (err_is_fail(err)) {
             return err;
index ac28e35..b5a8a81 100644 (file)
@@ -47,9 +47,9 @@
 #define XEON_PHI_HOST_SBOX_OFFSET      0x00010000
 
 #define XEON_PHI_MMIO_TO_SBOX(phi) \
-    ((mackerel_addr_t)((lvaddr_t)(phi->mmio.vbase)+XEON_PHI_HOST_SBOX_OFFSET))
+    ((void *)((lvaddr_t)(phi->mmio.vbase)+XEON_PHI_HOST_SBOX_OFFSET))
 #define XEON_PHI_MMIO_TO_DBOX(phi) \
-    ((mackerel_addr_t)((lvaddr_t)(phi->mmio.vbase)+XEON_PHI_HOST_DBOX_OFFSET))
+    ((void *)((lvaddr_t)(phi->mmio.vbase)+XEON_PHI_HOST_DBOX_OFFSET))
 
 /*
  * --------------------------------------------------------------------------
@@ -120,7 +120,7 @@ struct xeon_phi
 
     struct smpt_info *smpt;  ///< pointer to the SMPT information struct
     struct irq_info *irq;   ///< pointer to the IRQ information struct
-    struct dma_info *dma;   ///< pointer to the DMA information struct
+    struct dma_device *dma;   ///< pointer to the DMA information struct
     struct msg_info *msg;   ///< pointer to the Messaging information struct
 };