From: Kevin Wang <kevin.w...@arm.com>

Signed-off-by: Kevin Wang <kevin.w...@arm.com>
---
/** Email created from pull request 145 (kevinwangsk:cloud_dev_shadow)
 ** https://github.com/Linaro/odp/pull/145
 ** Patch: https://github.com/Linaro/odp/pull/145.patch
 ** Base sha: 0242ecfa64a663b7584054edcf02a8f9913391d6
 ** Merge commit sha: 60587b8ceb232c1d2a8a223e3d4ec0eb1d71ac58
 **/
 platform/linux-generic/Makefile.am                 |   3 +-
 .../{odp_buffer.c => buffer/generic.c}             |  67 ++++++++++----
 platform/linux-generic/buffer/subsystem.c          | 103 ++++++++++++++++++++-
 .../linux-generic/include/odp_buffer_subsystem.h   |   2 +
 4 files changed, 154 insertions(+), 21 deletions(-)
 rename platform/linux-generic/{odp_buffer.c => buffer/generic.c} (76%)

diff --git a/platform/linux-generic/Makefile.am 
b/platform/linux-generic/Makefile.am
index e904046e..3e3e0c22 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -242,7 +242,7 @@ __LIB__libodp_linux_la_SOURCES = \
                           odp_atomic.c \
                           odp_barrier.c \
                           odp_bitmap.c \
-                          odp_buffer.c \
+                          buffer/generic.c \
                           buffer/subsystem.c \
                           odp_byteorder.c \
                           odp_classification.c \
@@ -331,6 +331,7 @@ __LIB__libodp_linux_la_SOURCES += pktio/pcap.c
 endif
 
 pool/generic.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE
+buffer/generic.lo: AM_CFLAGS += -DIM_ACTIVE_MODULE
 
 # Build modular framework into odp-linux library
 modularframeworkdir = $(top_srcdir)/frameworks/modular
diff --git a/platform/linux-generic/odp_buffer.c 
b/platform/linux-generic/buffer/generic.c
similarity index 76%
rename from platform/linux-generic/odp_buffer.c
rename to platform/linux-generic/buffer/generic.c
index b7ea88e6..c896e3d0 100644
--- a/platform/linux-generic/odp_buffer.c
+++ b/platform/linux-generic/buffer/generic.c
@@ -9,29 +9,30 @@
 #include <odp_buffer_internal.h>
 #include <odp_buffer_inlines.h>
 #include <odp_debug_internal.h>
+#include <odp_buffer_subsystem.h>
 
 #include <string.h>
 #include <stdio.h>
 #include <inttypes.h>
 
-odp_buffer_t odp_buffer_from_event(odp_event_t ev)
+static odp_buffer_t generic_buffer_from_event(odp_event_t ev)
 {
        return (odp_buffer_t)ev;
 }
 
-odp_event_t odp_buffer_to_event(odp_buffer_t buf)
+static odp_event_t generic_buffer_to_event(odp_buffer_t buf)
 {
        return (odp_event_t)buf;
 }
 
-void *odp_buffer_addr(odp_buffer_t buf)
+static void *generic_buffer_addr(odp_buffer_t buf)
 {
        odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf);
 
        return hdr->seg[0].data;
 }
 
-uint32_t odp_buffer_size(odp_buffer_t buf)
+static uint32_t generic_buffer_size(odp_buffer_t buf)
 {
        odp_buffer_hdr_t *hdr = buf_hdl_to_hdr(buf);
 
@@ -52,34 +53,34 @@ int odp_buffer_snprint(char *str, uint32_t n, odp_buffer_t 
buf)
        hdr = buf_hdl_to_hdr(buf);
        pool = hdr->pool_ptr;
 
-       len += snprintf(&str[len], n-len,
+       len += snprintf(&str[len], n - len,
                        "Buffer\n");
-       len += snprintf(&str[len], n-len,
+       len += snprintf(&str[len], n - len,
                        "  pool         %" PRIu64 "\n",
                        odp_pool_to_u64(pool->pool_hdl));
-       len += snprintf(&str[len], n-len,
+       len += snprintf(&str[len], n - len,
                        "  addr         %p\n",          hdr->seg[0].data);
-       len += snprintf(&str[len], n-len,
+       len += snprintf(&str[len], n - len,
                        "  size         %" PRIu32 "\n", hdr->size);
-       len += snprintf(&str[len], n-len,
+       len += snprintf(&str[len], n - len,
                        "  type         %i\n",          hdr->type);
 
        return len;
 }
 
-void odp_buffer_print(odp_buffer_t buf)
+static void generic_buffer_print(odp_buffer_t buf)
 {
        int max_len = 512;
        char str[max_len];
        int len;
 
-       len = odp_buffer_snprint(str, max_len-1, buf);
+       len = odp_buffer_snprint(str, max_len - 1, buf);
        str[len] = 0;
 
        ODP_PRINT("\n%s\n", str);
 }
 
-uint64_t odp_buffer_to_u64(odp_buffer_t hdl)
+static uint64_t generic_buffer_to_u64(odp_buffer_t hdl)
 {
        return _odp_pri(hdl);
 }
@@ -265,7 +266,7 @@ void buffer_free_multi(odp_buffer_hdr_t *buf_hdr[], int 
num_total)
        }
 }
 
-odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)
+static odp_buffer_t generic_buffer_alloc(odp_pool_t pool_hdl)
 {
        odp_buffer_t buf;
        pool_t *pool;
@@ -282,7 +283,8 @@ odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)
        return ODP_BUFFER_INVALID;
 }
 
-int odp_buffer_alloc_multi(odp_pool_t pool_hdl, odp_buffer_t buf[], int num)
+static int generic_buffer_alloc_multi(odp_pool_t pool_hdl,
+                                     odp_buffer_t buf[], int num)
 {
        pool_t *pool;
 
@@ -293,24 +295,24 @@ int odp_buffer_alloc_multi(odp_pool_t pool_hdl, 
odp_buffer_t buf[], int num)
        return buffer_alloc_multi(pool, (odp_buffer_hdr_t **)buf, num);
 }
 
-void odp_buffer_free(odp_buffer_t buf)
+static void generic_buffer_free(odp_buffer_t buf)
 {
        buffer_free_multi((odp_buffer_hdr_t **)&buf, 1);
 }
 
-void odp_buffer_free_multi(const odp_buffer_t buf[], int num)
+static void generic_buffer_free_multi(const odp_buffer_t buf[], int num)
 {
        buffer_free_multi((odp_buffer_hdr_t **)(uintptr_t)buf, num);
 }
 
-odp_pool_t odp_buffer_pool(odp_buffer_t buf)
+static odp_pool_t generic_buffer_pool(odp_buffer_t buf)
 {
        pool_t *pool = pool_from_buf(buf);
 
        return pool->pool_hdl;
 }
 
-int odp_buffer_is_valid(odp_buffer_t buf)
+static int generic_buffer_is_valid(odp_buffer_t buf)
 {
        pool_t *pool;
 
@@ -327,3 +329,32 @@ int odp_buffer_is_valid(odp_buffer_t buf)
 
        return 1;
 }
+
+odp_buffer_module_t generic_buffer = {
+       .base = {
+               .name = "generic_buffer",
+               .init_local = NULL,
+               .term_local = NULL,
+               .init_global = NULL,
+               .term_global = NULL,
+               },
+       .buffer_from_event = generic_buffer_from_event,
+       .buffer_to_event = generic_buffer_to_event,
+       .buffer_addr = generic_buffer_addr,
+       .buffer_alloc_multi = generic_buffer_alloc_multi,
+       .buffer_free_multi = generic_buffer_free_multi,
+       .buffer_alloc = generic_buffer_alloc,
+       .buffer_free = generic_buffer_free,
+       .buffer_size = generic_buffer_size,
+       .buffer_is_valid = generic_buffer_is_valid,
+       .buffer_pool = generic_buffer_pool,
+       .buffer_print = generic_buffer_print,
+       .buffer_to_u64 = generic_buffer_to_u64,
+};
+
+ODP_MODULE_CONSTRUCTOR(generic_buffer)
+{
+       odp_module_constructor(&generic_buffer);
+       odp_subsystem_register_module(buffer, &generic_buffer);
+}
+
diff --git a/platform/linux-generic/buffer/subsystem.c 
b/platform/linux-generic/buffer/subsystem.c
index 96ddb012..d47525cf 100644
--- a/platform/linux-generic/buffer/subsystem.c
+++ b/platform/linux-generic/buffer/subsystem.c
@@ -5,13 +5,112 @@
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
+#include <odp/api/buffer.h>
+#include <odp_buffer_subsystem.h>
+#include <odp_debug_internal.h>
 #include <odp_module.h>
 
-#define SUBSYSTEM_VERSION 0x00010000UL
-ODP_SUBSYSTEM_DEFINE(buffer, "memory buffer public APIs", SUBSYSTEM_VERSION);
+ODP_SUBSYSTEM_DEFINE(buffer, "memory buffer public APIs",
+                    BUFFER_SUBSYSTEM_VERSION);
 
 ODP_SUBSYSTEM_CONSTRUCTOR(buffer)
 {
        odp_subsystem_constructor(buffer);
 }
 
+odp_buffer_t odp_buffer_from_event(odp_event_t ev)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_from_event(ev);
+}
+
+odp_event_t odp_buffer_to_event(odp_buffer_t buf)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_to_event(buf);
+}
+
+void *odp_buffer_addr(odp_buffer_t buf)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_addr(buf);
+}
+
+uint32_t odp_buffer_size(odp_buffer_t buf)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_size(buf);
+}
+
+void odp_buffer_print(odp_buffer_t buf)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_print(buf);
+}
+
+uint64_t odp_buffer_to_u64(odp_buffer_t hdl)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_to_u64(hdl);
+}
+
+odp_buffer_t odp_buffer_alloc(odp_pool_t pool_hdl)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_alloc(pool_hdl);
+}
+
+int odp_buffer_alloc_multi(odp_pool_t pool_hdl, odp_buffer_t buf[], int num)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_alloc_multi(pool_hdl, buf, num);
+}
+
+void odp_buffer_free(odp_buffer_t buf)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_free(buf);
+}
+
+void odp_buffer_free_multi(const odp_buffer_t buf[], int num)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_free_multi(buf, num);
+}
+
+odp_pool_t odp_buffer_pool(odp_buffer_t buf)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_pool(buf);
+}
+
+int odp_buffer_is_valid(odp_buffer_t buf)
+{
+       odp_buffer_module_t *mod;
+
+       mod = odp_subsystem_active_module(buffer, mod);
+       return mod->buffer_is_valid(buf);
+}
+
diff --git a/platform/linux-generic/include/odp_buffer_subsystem.h 
b/platform/linux-generic/include/odp_buffer_subsystem.h
index 60f8b646..6b69c06f 100644
--- a/platform/linux-generic/include/odp_buffer_subsystem.h
+++ b/platform/linux-generic/include/odp_buffer_subsystem.h
@@ -16,6 +16,8 @@ extern "C" {
 #include <odp_module.h>
 #include <odp/api/buffer.h>
 
+#define BUFFER_SUBSYSTEM_VERSION 0x00010000UL
+
 /* ODP buffer public APIs subsystem */
 ODP_SUBSYSTEM_DECLARE(buffer);
 

Reply via email to