From patchwork Fri Jan 8 20:29:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59393 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp752674lbb; Fri, 8 Jan 2016 11:40:50 -0800 (PST) X-Received: by 10.140.93.166 with SMTP id d35mr20308113qge.29.1452282050177; Fri, 08 Jan 2016 11:40:50 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v17si8922981qhb.37.2016.01.08.11.40.49; Fri, 08 Jan 2016 11:40:50 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B90E9617B4; Fri, 8 Jan 2016 19:40:49 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=XFBj8Jvq; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id EF99261795; Fri, 8 Jan 2016 19:33:26 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D34C561CC7; Fri, 8 Jan 2016 19:33:21 +0000 (UTC) Received: from mail-lf0-f54.google.com (mail-lf0-f54.google.com [209.85.215.54]) by lists.linaro.org (Postfix) with ESMTPS id 6072F61795 for ; Fri, 8 Jan 2016 19:31:43 +0000 (UTC) Received: by mail-lf0-f54.google.com with SMTP id d17so15374541lfb.1 for ; Fri, 08 Jan 2016 11:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eVYtBuIlsK4DCFwczY+nqgcrlFrepvhfWQ79XxyIIuY=; b=XFBj8JvqUVBYzTU7Hi/DPY+ZfBXGS/EznKOk2ctZ9r9qM2RoFcWED19kD044eOzA0a izJBI/cwIOG0V4hccIhdWu1QlOG7JlGR3UgrxO2AGcN1kBIM9c0HSL6lFkTt9WAj9TLo dV/Xej30DV8l1xnPJlgjlb2MU6zHMg6R3bHVY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eVYtBuIlsK4DCFwczY+nqgcrlFrepvhfWQ79XxyIIuY=; b=kCKn3uVgxtZ2VbVyFY5r2ScF6gKtmvsOnu4Cjh0qp06f+4qVhEyUepriUqjvu9Mxss YXqct/sqHgLexkxNTuug6DNTINyUx5Bto8JdNtRhcCRsOIk0XvPdbuhc799mE9jWvnmd Xe3xtlU1Y1qnzF4KbUCvWUfEZ2iYEe37d2C5+iQl39FCTA7pKCjnc7EQQ7Qb6u04OMrC 36J8S7IO42N7KyTGv9QQm35uMesU49Mr1edqs7BKw1b2TcwpYMWAYtwxpvZ//qmOVwpg sUDnoCmcmQt3sGdfuo0IZ8Qb5Oqd5tKVb7stSJ2mS9RY032pdQstEE7FP15JIL7Cu9fw kcAA== X-Gm-Message-State: ALoCoQnYRMtNXA8LnYT+3c12kAzuCN0M8q6sdBXqC+vTeisYyNZfjOQSi4ErZksIZKJ3ucDEsw4UWTQAeeGm1bV57jj6wuaK+g== X-Received: by 10.25.18.66 with SMTP id h63mr33041342lfi.11.1452281502333; Fri, 08 Jan 2016 11:31:42 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id l204sm2085534lfg.49.2016.01.08.11.31.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:31:41 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, stuart.haslam@linaro.org, maxim.uvarov@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org, edavis@broadcom.com Date: Fri, 8 Jan 2016 21:29:51 +0100 Message-Id: <1452285014-60320-9-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> References: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API-NEXT RFC 08/31] linux-generic: defining PCI api X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Defining the internal implementation of a PCI device and related methods. Signed-off-by: Christophe Milard --- platform/linux-generic/Makefile.am | 3 + platform/linux-generic/include/odp/pci.h | 36 +++++++ .../linux-generic/include/odp/plat/pci_types.h | 40 ++++++++ platform/linux-generic/include/odp_pci_internal.h | 103 +++++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 platform/linux-generic/include/odp/pci.h create mode 100644 platform/linux-generic/include/odp/plat/pci_types.h create mode 100644 platform/linux-generic/include/odp_pci_internal.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index d0938c9..1e1015d 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -33,6 +33,7 @@ odpinclude_HEADERS = \ $(srcdir)/include/odp/packet_flags.h \ $(srcdir)/include/odp/packet.h \ $(srcdir)/include/odp/packet_io.h \ + $(srcdir)/include/odp/pci.h \ $(srcdir)/include/odp/pool.h \ $(srcdir)/include/odp/queue.h \ $(srcdir)/include/odp/random.h \ @@ -68,6 +69,7 @@ odpplatinclude_HEADERS = \ $(srcdir)/include/odp/plat/event_types.h \ $(srcdir)/include/odp/plat/packet_types.h \ $(srcdir)/include/odp/plat/packet_io_types.h \ + $(srcdir)/include/odp/plat/pci_types.h \ $(srcdir)/include/odp/plat/pool_types.h \ $(srcdir)/include/odp/plat/queue_types.h \ $(srcdir)/include/odp/plat/rwlock_types.h \ @@ -105,6 +107,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_netmap.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ + ${srcdir}/include/odp_pci_internal.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ ${srcdir}/include/odp_queue_internal.h \ diff --git a/platform/linux-generic/include/odp/pci.h b/platform/linux-generic/include/odp/pci.h new file mode 100644 index 0000000..e00841e --- /dev/null +++ b/platform/linux-generic/include/odp/pci.h @@ -0,0 +1,36 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP PCI interface + */ + +#include + +#ifndef ODP_PLAT_PCI_H_ +#define ODP_PLAT_PCI_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @ingroup odp_pci + * @{ + */ + +/** + * @} + */ + +#include + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp/plat/pci_types.h b/platform/linux-generic/include/odp/plat/pci_types.h new file mode 100644 index 0000000..f9e3551 --- /dev/null +++ b/platform/linux-generic/include/odp/plat/pci_types.h @@ -0,0 +1,40 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP PCI interface + */ + +#ifndef ODP_PCI_TYPES_H_ +#define ODP_PCI_TYPES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** @addtogroup odp_pci + * @{ + */ + +/** PCI device */ +typedef ODP_HANDLE_T(odp_pci_dev_t); +#define ODP_PCI_DEV_INVALID _odp_cast_scalar(odp_pci_dev_t, 0) + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp_pci_internal.h b/platform/linux-generic/include/odp_pci_internal.h new file mode 100644 index 0000000..aa00f13 --- /dev/null +++ b/platform/linux-generic/include/odp_pci_internal.h @@ -0,0 +1,103 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP pci interface - implementation internal + */ + +#ifndef ODP_PCI_INTERNAL_H_ +#define ODP_PCI_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** @addtogroup odp_pci + * @{ + */ + +/** Maximum number of PCI resources. */ +#define _ODP_PCI_MAX_RESOURCE 6 + +/** PCI address length (something like "0000:06:00.0" + NULL) */ +#define _ODP_PCI_ADDR_LEN 13 + +/** + * A structure describing an ID for a PCI device. + */ +typedef struct pci_id_t { + uint16_t vendor_id; /**< Vendor ID or PCI_ANY_ID. */ + uint16_t device_id; /**< Device ID or PCI_ANY_ID. */ + uint16_t subsystem_vendor_id; /**< Subsystem vendor ID or PCI_ANY_ID. */ + uint16_t subsystem_device_id; /**< Subsystem device ID or PCI_ANY_ID. */ +} pci_id_t; + +/** + * PCI resource (BAR map region) + */ +typedef struct pci_resource_t { + /** address (virtual, in user space) of the BAR region */ + void *addr; + /** size of the region, in bytes */ + uint64_t size; +} pci_resource_t; + +/** + * PCI device + */ +typedef struct pci_dev_t { + /** the address of the device:format: "0000:23:00.0" */ + char pci_address[_ODP_PCI_ADDR_LEN]; + /** PCI id for this device */ + pci_id_t pci_id; + /** the -up to 6- different PCI BAR regions that the device may have */ + pci_resource_t bar_maps[_ODP_PCI_MAX_RESOURCE]; + /** A pointer to whatever the PCI implementation (vfio, uio) needs */ + void *implementation_data; +} pci_dev_t; + +/** + * Initialise and map the PCI interface for the given pci address, + * + * @param pci_addr pci address to the baord that should be initialized and + * mapped, i.e. something like: "0000:23:00.0" + * @param pktio The packetio handle the interface belongs to. + * + * @returns a odp_pci_dev_t handle (PCI device) + * or ODP_PCI_DEV_INVALID on error, + */ +odp_pci_dev_t _odp_pci_init(const char *pci_addr); + +/** + * Release a PCI device + * + * @param pci_dev A handle to a pci device + * + */ +void _odp_pci_release(odp_pci_dev_t pci_dev); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif