From patchwork Tue Jan 20 11:17:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 43345 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 959CB2034D for ; Tue, 20 Jan 2015 11:19:21 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id u10sf1539787lbd.3 for ; Tue, 20 Jan 2015 03:19:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=nCCBTnFWKRgMMc1eLXsBpLMdfWF7eZWzYDQGMWUfm1I=; b=cUo562YnfPOfyqrfrONX3GDc+Quc1TQgkKAVyTbyX6pWSJj1TAb9VF/bJ3dfMsfTaa VnjE/UdtZNUO3gsv+T3sG9sYfPjTgOPH/r4+FnBe0u5fJRbCwkiX/Qh2oQuvEp7rwwJu mObK+jABWXjfsLQ7h1RQz0LYLDenQrwHz/I0i66k2cFXCUukkLA1CkuFLHx+NyIJerqv XrNo2czigJiS3m+my4V/6GPkJSkI2TVLfexRvlzLCFC9QEvIUj+k6PgaGcoRyWVakQxO 6eYcmPKJiMk9YrRMlWpnPwvUKx1HAPLdCXFnkl38cknFpFC+8vWYRR3xkAlVb33sQ1h4 CPyQ== X-Gm-Message-State: ALoCoQmo4yB1aEkOw+KelWl8Bt0j5x8sk2TyHbuAQABILrHOyR2lg7ktpPxeE8wqp89Bnu9i5oxl X-Received: by 10.112.64.197 with SMTP id q5mr4325925lbs.4.1421752760518; Tue, 20 Jan 2015 03:19:20 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.41 with SMTP id bd9ls177439lab.14.gmail; Tue, 20 Jan 2015 03:19:20 -0800 (PST) X-Received: by 10.112.119.201 with SMTP id kw9mr36911231lbb.99.1421752760320; Tue, 20 Jan 2015 03:19:20 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id rk9si14979688lbb.13.2015.01.20.03.19.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Jan 2015 03:19:20 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id p9so9610838lbv.4 for ; Tue, 20 Jan 2015 03:19:20 -0800 (PST) X-Received: by 10.152.234.35 with SMTP id ub3mr37629052lac.70.1421752760210; Tue, 20 Jan 2015 03:19:20 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp1380723lbb; Tue, 20 Jan 2015 03:19:19 -0800 (PST) X-Received: by 10.140.95.179 with SMTP id i48mr16204492qge.4.1421752757595; Tue, 20 Jan 2015 03:19:17 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id u3si951306qaf.94.2015.01.20.03.19.16 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 20 Jan 2015 03:19:17 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YDWq1-0006EC-WC; Tue, 20 Jan 2015 11:19:14 +0000 Received: from mail-qc0-f181.google.com ([209.85.216.181]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YDWpu-0006BY-5U for lng-odp@lists.linaro.org; Tue, 20 Jan 2015 11:19:06 +0000 Received: by mail-qc0-f181.google.com with SMTP id l6so21507702qcy.12 for ; Tue, 20 Jan 2015 03:19:01 -0800 (PST) X-Received: by 10.140.106.100 with SMTP id d91mr35282920qgf.18.1421752740994; Tue, 20 Jan 2015 03:19:00 -0800 (PST) Received: from mcpro03.emea.nsn-net.net (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id t2sm14975907qae.6.2015.01.20.03.18.58 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Jan 2015 03:19:00 -0800 (PST) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Tue, 20 Jan 2015 13:17:57 +0200 Message-Id: <1421752692-24439-2-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1421752692-24439-1-git-send-email-petri.savolainen@linaro.org> References: <1421752692-24439-1-git-send-email-petri.savolainen@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH v2 01/16] api: event: Add odp_event_t X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: petri.savolainen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 * Added odp_event.h and odp_event.c * Added odp_event_t type and type conversion functions Signed-off-by: Petri Savolainen --- platform/linux-generic/Makefile.am | 2 + platform/linux-generic/include/api/odp.h | 1 + platform/linux-generic/include/api/odp_buffer.h | 22 ++++++++ platform/linux-generic/include/api/odp_event.h | 59 ++++++++++++++++++++++ platform/linux-generic/include/api/odp_packet.h | 21 ++++++++ .../linux-generic/include/api/odp_platform_types.h | 6 +++ platform/linux-generic/include/api/odp_timer.h | 13 +++++ platform/linux-generic/odp_buffer.c | 10 ++++ platform/linux-generic/odp_event.c | 26 ++++++++++ platform/linux-generic/odp_packet.c | 10 ++++ platform/linux-generic/odp_timer.c | 9 ++++ 11 files changed, 179 insertions(+) create mode 100644 platform/linux-generic/include/api/odp_event.h create mode 100644 platform/linux-generic/odp_event.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index a699ea6..712d75c 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -19,6 +19,7 @@ include_HEADERS = \ $(top_srcdir)/platform/linux-generic/include/api/odp_cpumask.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_crypto.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_debug.h \ + $(top_srcdir)/platform/linux-generic/include/api/odp_event.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_hints.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_init.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_packet_flags.h \ @@ -80,6 +81,7 @@ __LIB__libodp_la_SOURCES = \ odp_classification.c \ odp_cpumask.c \ odp_crypto.c \ + odp_event.c \ odp_init.c \ odp_impl.c \ odp_linux.c \ diff --git a/platform/linux-generic/include/api/odp.h b/platform/linux-generic/include/api/odp.h index 1cc7ce0..49357b0 100644 --- a/platform/linux-generic/include/api/odp.h +++ b/platform/linux-generic/include/api/odp.h @@ -49,6 +49,7 @@ extern "C" { #include #include #include +#include #ifdef __cplusplus } diff --git a/platform/linux-generic/include/api/odp_buffer.h b/platform/linux-generic/include/api/odp_buffer.h index 0670464..5f825a2 100644 --- a/platform/linux-generic/include/api/odp_buffer.h +++ b/platform/linux-generic/include/api/odp_buffer.h @@ -29,6 +29,28 @@ extern "C" { /** + * Get buffer handle from event + * + * Converts an ODP_EVENT_BUFFER type event to a buffer. + * + * @param ev Event handle + * + * @return Buffer handle + * + * @see odp_event_type() + */ +odp_buffer_t odp_buffer_from_event(odp_event_t ev); + +/** + * Convert buffer handle to event + * + * @param buf Buffer handle + * + * @return Event handle + */ +odp_event_t odp_buffer_to_event(odp_buffer_t buf); + +/** * Buffer start address * * @param buf Buffer handle diff --git a/platform/linux-generic/include/api/odp_event.h b/platform/linux-generic/include/api/odp_event.h new file mode 100644 index 0000000..48e5c22 --- /dev/null +++ b/platform/linux-generic/include/api/odp_event.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +/** + * @file + * + * ODP event + */ + +#ifndef ODP_EVENT_H_ +#define ODP_EVENT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +#include +#include + +/** @defgroup odp_event ODP EVENT + * Operations on an event. + * @{ + */ + + +/** + * Event type + * + * @param event Event handle + * + * @return Event type or ODP_EVENT_TYPE_INVALID + */ +int odp_event_type(odp_event_t event); + +/**< Invalid event type */ +#define ODP_EVENT_TYPE_INVALID (-1) +/**< Packet event */ +#define ODP_EVENT_PACKET (ODP_EVENT_TYPE_INVALID + 1) +/**< Buffer event */ +#define ODP_EVENT_BUFFER (ODP_EVENT_TYPE_INVALID + 2) +/**< Timeout event */ +#define ODP_EVENT_TIMEOUT (ODP_EVENT_TYPE_INVALID + 3) + + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/api/odp_packet.h b/platform/linux-generic/include/api/odp_packet.h index 920a593..5ab96c6 100644 --- a/platform/linux-generic/include/api/odp_packet.h +++ b/platform/linux-generic/include/api/odp_packet.h @@ -113,6 +113,27 @@ odp_packet_t odp_packet_from_buffer(odp_buffer_t buf); */ odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt); +/** + * Get packet handle from event + * + * Converts an ODP_EVENT_PACKET type event to a packet. + * + * @param ev Event handle + * + * @return Packet handle + * + * @see odp_event_type() + */ +odp_packet_t odp_packet_from_event(odp_event_t ev); + +/** + * Convert packet handle to event + * + * @param buf Packet handle + * + * @return Event handle + */ +odp_event_t odp_packet_to_event(odp_packet_t pkt); /* * diff --git a/platform/linux-generic/include/api/odp_platform_types.h b/platform/linux-generic/include/api/odp_platform_types.h index 0a00219..8fe8135 100644 --- a/platform/linux-generic/include/api/odp_platform_types.h +++ b/platform/linux-generic/include/api/odp_platform_types.h @@ -65,6 +65,12 @@ typedef uint32_t odp_pktio_t; /** odp_pktio_t value to indicate any port */ #define ODP_PKTIO_ANY ((odp_pktio_t)~0) +/** ODP event */ +typedef odp_buffer_t odp_event_t; + +/** Invalid event */ +#define ODP_EVENT_INVALID ODP_BUFFER_INVALID + /** * ODP shared memory block */ diff --git a/platform/linux-generic/include/api/odp_timer.h b/platform/linux-generic/include/api/odp_timer.h index 69402ef..cb17b7b 100644 --- a/platform/linux-generic/include/api/odp_timer.h +++ b/platform/linux-generic/include/api/odp_timer.h @@ -21,6 +21,7 @@ extern "C" { #include #include #include +#include #include /** @defgroup odp_timer ODP TIMER @@ -310,6 +311,18 @@ int odp_timer_cancel(odp_timer_t tim, odp_buffer_t *tmo_buf); odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf); /** + * Return timeout handle that is associated with timeout event + * + * Note: any invalid parameters will cause undefined behavior and may cause + * the application to abort or crash. + * + * @param buf An event of type ODP_EVENT_TIMEOUT + * + * @return timeout handle + */ +odp_timeout_t odp_timeout_from_event(odp_event_t ev); + +/** * Check for fresh timeout * If the corresponding timer has been reset or cancelled since this timeout * was enqueued, the timeout is stale (not fresh). diff --git a/platform/linux-generic/odp_buffer.c b/platform/linux-generic/odp_buffer.c index 57ba408..939332a 100644 --- a/platform/linux-generic/odp_buffer.c +++ b/platform/linux-generic/odp_buffer.c @@ -14,6 +14,16 @@ #include +odp_buffer_t odp_buffer_from_event(odp_event_t ev) +{ + return (odp_buffer_t)ev; +} + +odp_event_t odp_buffer_to_event(odp_buffer_t buf) +{ + return (odp_event_t)buf; +} + void *odp_buffer_addr(odp_buffer_t buf) { odp_buffer_hdr_t *hdr = odp_buf_to_hdr(buf); diff --git a/platform/linux-generic/odp_event.c b/platform/linux-generic/odp_event.c new file mode 100644 index 0000000..c646f42 --- /dev/null +++ b/platform/linux-generic/odp_event.c @@ -0,0 +1,26 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +int odp_event_type(odp_event_t event) +{ + odp_buffer_t buf; + + buf = odp_buffer_from_event(event); + + switch (odp_buffer_type(buf)) { + case ODP_BUFFER_TYPE_RAW: + return ODP_EVENT_BUFFER; + case ODP_BUFFER_TYPE_PACKET: + return ODP_EVENT_PACKET; + case ODP_BUFFER_TYPE_TIMEOUT: + return ODP_EVENT_TIMEOUT; + default: + return ODP_EVENT_TYPE_INVALID; + } +} diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 257abec..ebe3b55 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -75,6 +75,16 @@ odp_buffer_t odp_packet_to_buffer(odp_packet_t pkt) return (odp_buffer_t)pkt; } +odp_packet_t odp_packet_from_event(odp_event_t ev) +{ + return (odp_packet_t)ev; +} + +odp_event_t odp_packet_to_event(odp_packet_t pkt) +{ + return (odp_event_t)pkt; +} + /* * * Pointers and lengths diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 3ba32a1..d926ada 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -802,6 +803,14 @@ odp_timeout_t odp_timeout_from_buf(odp_buffer_t buf) return (odp_timeout_t)timeout_hdr_from_buf(buf); } +odp_timeout_t odp_timeout_from_event(odp_event_t ev) +{ + /* This check not mandated by the API specification */ + if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) + ODP_ABORT("Event not a timeout"); + return (odp_timeout_t)timeout_hdr_from_buf(odp_buffer_from_event(ev)); +} + int odp_timeout_fresh(odp_timeout_t tmo) { const odp_timeout_hdr_t *hdr = (odp_timeout_hdr_t *)tmo;