DeviceQueue: added functionality to keep track of buffers/regions
authorRoni Häcki <roni.haecki@inf.ethz.ch>
Wed, 5 Oct 2016 14:19:37 +0000 (16:19 +0200)
committerRoni Häcki <roni.haecki@inf.ethz.ch>
Wed, 5 Oct 2016 14:19:37 +0000 (16:19 +0200)
Signed-off-by: Roni Häcki <roni.haecki@inf.ethz.ch>

include/devif/queue_interface.h
lib/devif/backends/net/solarflare/devif_backend_solarflare.c
lib/devif/queue_interface.c
lib/devif/queue_interface_internal.c
lib/devif/queue_interface_internal.h

index bb1712b..34e4fdd 100644 (file)
@@ -17,6 +17,7 @@
 #define DEVQ_BUF_FLAG_TX_LAST 0x4
 
 
+
 typedef uint32_t regionid_t;
 typedef uint32_t bufferid_t;
 
@@ -147,7 +148,14 @@ struct devq {
     struct region_pool* pool;
  
     // Funciton pointers
-    struct devq_func_pointer f;   
+    struct devq_func_pointer f;
+
+    // exported devq
+    /* Depending on the side of the channel (if there are two), 
+       adding/removing regions and enqueueing/dequeueing buffers
+       has to be handeled differently in the bookkeeping part
+    */ 
+    bool exp;
 };
 
 /*
index b0b6cb8..cb3beb0 100644 (file)
@@ -466,7 +466,7 @@ errval_t sfn5122f_queue_create(struct sfn5122f_queue** q, sfn5122f_event_cb_t cb
     queue->device = malloc(sizeof(sfn5122f_t));
     sfn5122f_initialize(queue->device, queue->device_va);
 
-    err = devq_init(&queue->q);
+    err = devq_init(&queue->q, false);
     if (err_is_fail(err)) {
         return err;
     }
index 18a88f3..5bf0d63 100644 (file)
@@ -52,12 +52,16 @@ errval_t devq_enqueue(struct devq *q,
        access. In the device case, we keep track of the buffers the device
        actually has access to.
     */
-    err = region_pool_get_buffer_id_from_region(q->pool, region_id, base,
-                                                buffer_id);
+    if (q->exp) {
+        err = region_pool_return_buffer_to_region(q->pool, region_id, base);
+    } else {
+        err = region_pool_get_buffer_id_from_region(q->pool, region_id, base,
+                                                    buffer_id);
+    }
+
     if (err_is_fail(err)) {
         return err;
     }
-
     err = q->f.enq(q, region_id, *buffer_id, base, length, 
                    misc_flags);
 
@@ -102,8 +106,14 @@ errval_t devq_dequeue(struct devq *q,
        actually has access to.
     */
     // Add buffer to free ones
-    err = region_pool_return_buffer_id_to_region(q->pool, *region_id,
-                                                 *buffer_id);
+    if (q->exp) {
+
+        err = region_pool_set_buffer_id_from_region(q->pool, *region_id,
+                                                    *base, *buffer_id);
+    } else {
+        err = region_pool_return_buffer_id_to_region(q->pool, *region_id,
+                                                     *buffer_id);
+    }
 
     if (err_is_fail(err)) {
         return err;
@@ -137,6 +147,7 @@ errval_t devq_register(struct devq *q,
                        regionid_t* region_id)
 {
     errval_t err;
+
     err = region_pool_add_region(q->pool, cap, region_id); 
     if (err_is_fail(err)) {
         return err;
index aaec672..021f74f 100644 (file)
   * @brief creates a queue 
   *
   * @param q             Return pointer to the devq (handle)
+  * @param exp           If we keep track of no longer owned buffers
+  *                      or buffers that we own         
   *
   * @returns error on failure or SYS_ERR_OK on success
   */
 
-errval_t devq_init(struct devq *q)
+errval_t devq_init(struct devq *q, bool exp)
 {
     
     errval_t err;
-
+    q->exp = exp;
     err = region_pool_init(&(q->pool));
-    if (err_is_fail(err)) {
-        return err;
-    }
     
-    return SYS_ERR_OK;
+    return err;
 }
 
 
@@ -54,10 +53,25 @@ errval_t devq_destroy(struct devq *q)
     errval_t err;
 
     err = region_pool_destroy(q->pool);
-    if (err_is_fail(err)) {
-        return err;
-    }
 
-    return SYS_ERR_OK;
+    return err;
+}
+
+
+errval_t devq_add_region(struct devq* q, struct capref cap,
+                         regionid_t rid)
+{
+    errval_t err;
+    
+    err = region_pool_add_region_with_id(q->pool, cap, rid);
+    return err;
 }
 
+errval_t devq_remove_region(struct devq* q, regionid_t rid)
+{
+    errval_t err;
+    struct capref cap; 
+   
+    err = region_pool_remove_region(q->pool, rid, &cap);
+    return err;
+}
index 9b7f33a..2cca7eb 100644 (file)
 
 #include <devif/queue_interface.h>
 
-errval_t devq_init(struct devq *q);
+errval_t devq_init(struct devq *q, bool exp);
 errval_t devq_destroy(struct devq *q);
 
+errval_t devq_add_region(struct devq*, struct capref cap,
+                         regionid_t rid);
+
+errval_t devq_remove_region(struct devq*, regionid_t rid);
 
 #endif /* QUEUE_INTERFACE_INTERNAL_H_ */