From patchwork Tue Dec 6 14:23:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 86827 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp2012648qgi; Tue, 6 Dec 2016 05:25:25 -0800 (PST) X-Received: by 10.233.216.71 with SMTP id u68mr61210978qkf.161.1481030725935; Tue, 06 Dec 2016 05:25:25 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d5si11675079qkb.75.2016.12.06.05.25.25; Tue, 06 Dec 2016 05:25:25 -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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 95B2D60C7B; Tue, 6 Dec 2016 13:25:25 +0000 (UTC) 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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL 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 E479760C07; Tue, 6 Dec 2016 13:24:41 +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 2F5C860C7B; Tue, 6 Dec 2016 13:24:30 +0000 (UTC) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by lists.linaro.org (Postfix) with ESMTPS id CA54D60C70 for ; Tue, 6 Dec 2016 13:24:09 +0000 (UTC) Received: by mail-wm0-f41.google.com with SMTP id a197so128258642wmd.0 for ; Tue, 06 Dec 2016 05:24:09 -0800 (PST) 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=/7KPAnqHjJkMjeJKa4Zs0PQxf9MAJVor8wsRdih2HQU=; b=SorCgpEuucRjSyZcDetws9z+kfE/OvcXQoSnFb/1nq/5c8c5Gk4PseB4ksISZOKz1o sX0wSHXKNdA7fhucdUgCXvlUXMvCxC2yogM/AbsUmuUtiLJ3tlagJBVeAufGrdY7ZjNY 9+zlWJ0SaOLENep3QM1eKNmFHy+PoWkv+ONYbvzMFTasYnjBbLXEJsCXHAFPsUn7KhTr JFnx5dX63U2fwzo9628ujiqfpQM4H8u6s0qPq7FsIUD7hzWfVMq9Z41bXdg5Qh34d6Nr yETa/vNzdkKkBQWDidoH+r+LXrDmV7rDQ3KY7aUtZQrkFEaFvGZopQCFnrgi/lEW6wgQ MzaQ== X-Gm-Message-State: AKaTC031WBg9GD29skIqryW01hLvk4c1ShTOgtnXgj+1O/5nHeHmKIldfWHCoR0suzyJwsnCpJs= X-Received: by 10.46.5.136 with SMTP id 130mr27202210ljf.36.1481030648552; Tue, 06 Dec 2016 05:24:08 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id 204sm3806471ljj.33.2016.12.06.05.24.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 05:24:07 -0800 (PST) From: Christophe Milard To: maxim.uvarov@linaro.com, mike.holmes@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, francois.ozog@linaro.org, lng-odp@lists.linaro.org Date: Tue, 6 Dec 2016 15:23:33 +0100 Message-Id: <1481034217-16689-2-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481034217-16689-1-git-send-email-christophe.milard@linaro.org> References: <1481034217-16689-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv3 1/5] drv: adding driver registration interface (stub) 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" The enumerator class, enumerator instance, devio and driver registration functions prototypes (and a draft of their parameters) are defined, the goal being to define the registration framework only. Signed-off-by: Christophe Milard --- include/odp/drv/spec/driver.h | 311 ++++++++++++++++++++++++++++++++++++++++++ platform/Makefile.inc | 1 + 2 files changed, 312 insertions(+) create mode 100644 include/odp/drv/spec/driver.h -- 2.7.4 diff --git a/include/odp/drv/spec/driver.h b/include/odp/drv/spec/driver.h new file mode 100644 index 0000000..feb3523 --- /dev/null +++ b/include/odp/drv/spec/driver.h @@ -0,0 +1,311 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODPDRV driver + */ + +#ifndef ODPDRV_DRIVER_H_ +#define ODPDRV_DRIVER_H_ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @addtogroup odpdrv_driver +* @details +* enumerator and driver interface to ODP +* +* 1) ODP load the different modules (i.e. it loads shared libraries, *.so). +* In the context of drivers, shared libraries may contain enumerators, +* drivers and devios. These register in step 2. +* +* 2) odpdrv_enum_class_register(int (probe*)()...) +* -----------------------------------------------------------> +* odrdrv_driver_register(int (probe*)()...) +* -----------------------------------------------------------> +* odpdrv devio register() +* -----------------------------------------------------------> +* A number of device_enumerator_classes are registered at the ODP startup. +* Many classes are expected: static, ACPI, PCI, switchdev, virtual, DPAA2... +* A number of drivers also register to ODP (passing their own probe function). +* A number of device IO may also register to ODP (defining available devices +* interfaces). +* +* 3) ODP calls the probe function of each enumerator class +* <----------------------------------------------------------- +* odrdrv_emum_register(int (probe*)()...) +* -----------------------------------------------------------> +* -----------------------------------------------------------> +* -----------------------------------------------------------> +* odrdrv_devio_register(...) +* -----------------------------------------------------------> +* -----------------------------------------------------------> +* -----------------------------------------------------------> +* ODP calls the probe function of each registered enumerator_class. +* This result in the enumerator_class registering some +* enumerators (instances of the class) by calling +* odrdrv_emumerator_register() for each instance. +* A given enumerator_class may create many enumerators based on its platform: +* For instance Linux defines a number of PCI domains that can be viewed as +* multiple PCI enumerators. In addition, it could be considered that each PCI +* root of each processor socket in a NUMA environment has its own PCI +* enumerator. +* For enumerator class PCI, there could be one instance for each PCI +* domain. +* Note that the probe function of a given class may be recalled at any time +* (Hotplug) +* The devios delivered with their enumarator may also register at this stage. +* +* 4) For each enumerator instance , odp calls the probe function to retrieve +* the list of devices enumerated by the given enumerator instance. +* Note that the probe function of a given enumerator may be recalled at any +* time(Hotplug) +* +* 5) The driver framework calls the drivers probe(D,I) functions of the +* drivers, with device D and devio I as parameter, assuming that: +* -devio I was on the driver supported list of devio (and version matches) +* -the devio I is registered and found its enumerator (E) api +* (name and version) +* -device D was enumerated by enumerator E. +* The return value of the driver probe function tells whether the driver +* can handle the device or not. +* +* @{ +*/ + +/* forward declarations for a top down description of structures */ +typedef struct odpdrv_enum_class_t odpdrv_enum_class_t; +typedef struct odpdrv_enum_t odpdrv_enum_t; +typedef struct odpdrv_enumerated_dev_t odpdrv_enumerated_dev_t; +typedef struct odpdrv_driver_t odpdrv_driver_t; + +/** maximum size for driver and enumerator names: */ +#define ODPDRV_NAME_MAX_SZ 32 + +/** maximum size for the enumerator dependent address: */ +#define ODPDRV_NAME_ADDR_SZ 64 + +/** The maximum number of interfaces an driver may support: */ +#define ODPDRV_MAX_DEVIOS 3 + +/** +* Parameter to be given at enumerator class registration: +*/ +typedef struct odpdrv_enum_class_t { + /** enumerator name: mostly used for debug purpose. + * Name must be unique (e.g. "PCI-DPAA2") + */ + const char name[ODPDRV_NAME_MAX_SZ]; + + /** enumerator api_name and version are used by the driver + * to make sure the device being received at probe time is understood: + * E.g. "PCI" + * the format of the enum_dev part for the odpdrv_enumerated_dev_t + * structure is identified by the api-name and version below + */ + const char enum_api_name[ODPDRV_NAME_MAX_SZ]; + uint32_t enum_api_version; + + /** Probe function: + * called by ODP to get the enumerator class instances registered + */ + int (*probe)(void); + + /** remove function: + * free whatever resource the class may have allocated. + */ + int (*remove)(void); +} odpdrv_enum_class_t; + +/** +* Parameter to be given at enumerator (instance) registration: +*/ +typedef struct odpdrv_enum_t { + /** class name + * identifies the class of the enumerator + */ + const char class_name[ODPDRV_NAME_MAX_SZ]; + + /** Probe function: + * called by ODP to get the enumerated device list + */ + odpdrv_enumerated_dev_t* (*probe)(void); + + /** remove function: + * free the list of enumerated devices. + * This function is called in reverse order to device list creation + */ + int (*remove)(odpdrv_enumerated_dev_t *devlist); + + /** register event notifier function for hotplug events: + */ + int (*register_notifier)(void (*event_handler) (void)); +} odpdrv_enum_t; + +/** This structure defines a generic enumerated device, or actually the +* common part between all devices, the enumerator specific part being pointed +* by the enum_dev field below. +*/ +typedef struct odpdrv_enumerated_dev_t { + /** enumerator which enumerated the device: + * + */ + odpdrv_enum_t *enumerator; + + /** device address: + * an enumerator dependent string giving the device address, + * e.g. "0000.23.12.1" for PCI domain 0, bus 23, device 12, function 1. + * This string identifies the device uniquely. + * Filled at enumeration time. + */ + const char address[ODPDRV_NAME_ADDR_SZ]; + + /** enumerator dependent part + * This part is allocated by the enumerator and is enumerator dependent + * (i.e. different devices types will have different contents for + * enum_dev). + */ + void *enum_dev; + + /** next pointer for lists + */ + odpdrv_enumerated_dev_t *next; + +} odpdrv_enumerated_dev_t; + +/** + * Parameter to be given at devio registration: + */ +typedef struct odpdrv_devio_t { + /** devio name + * identifies the device IO module in its enumerator domain + * (i.e:many devios may have the same name, but none of them should + * have a common enumerator class) + */ + const char name[ODPDRV_NAME_MAX_SZ]; + + /** version: + * Identifies the devio API version (to be matched with driver + * requests). + */ + uint32_t version; + + /** enumerator class name + * The enumerator this devio depends on. + */ + const char enumerator_class_name[ODPDRV_NAME_MAX_SZ]; + + /** ops + * pointer to a devio ops structure (specific to each devio) + */ + void *ops; +} odpdrv_devio_t; + +/** +* Parameter to be given at driver registration: +*/ +typedef struct odpdrv_driver_t { + /** driver name + * the driver name (the pair {driver-name, enum-api-name} must + * be unique) + */ + const char name[ODPDRV_NAME_MAX_SZ]; + + /** enumerator api name + * the enumerator api name this driver works with + */ + const char enum_api_name[ODPDRV_NAME_MAX_SZ]; + + /** enumerator version + * requested enumerator api version + */ + uint32_t enum_api_version; + + /** supported devios: + * the list of supported devio: one of the following devio + * (with correct version) must be available for the driver to work: + */ + struct { + const char devio_name[ODPDRV_NAME_MAX_SZ]; + uint32_t devio_version; + } devios[ODPDRV_MAX_DEVIOS]; + + /** Probe function: + * called by ODP to see if the driver can drive a given device + * + */ + int (*probe)(odpdrv_enumerated_dev_t *dev); + + /** remove function: + * Only called with devices whose probe() returned true + * + */ + int (*remove)(odpdrv_enumerated_dev_t *dev); + +} odpdrv_driver_t; + +/** +* Register an enumerator class. +* A call to this function should be made by all enumerator classes at init +* time. +* (called by an init function in the enumerator class, probably using gcc/clang +* __constructor__ attribute. +* +* @param enum_class Pointer to a enumerator registration structure. +* @return 0 on success, non-zero on error. On error, enumerators classes +* should release allocated resources and return. +*/ +int odrdrv_enum_class_register(odpdrv_enum_class_t *enum_class); + +/** +* Register an enumerator. +* A call to this function should be made by all enumerators at init time. +* (called as a result of probing the enumerator class) +* +* @param enumerator Pointer to a enumerator registration structure. +* @return 0 on success, non-zero on error. On error, enumerators +* should release allocated resources and return. +*/ +int odpdrv_enum_register(odpdrv_enum_t *enumerator); + +/** +* Register an devio. +* A call to this function should be made by all devios at init time. +* (probably called as a result of probing the enumerator class, but could +* also be separated modules) +* +* @param devio Pointer to a devio registration structure. +* @return 0 on success, non-zero on error. +*/ +int odpdrv_devio_register(odpdrv_devio_t *devio); + +/** +* Register a Driver. +* A call to this function should be made by all drivers at init time. +* (called by an init function in the driver, probably using gcc/clang +* __constructor__ attribute. +* +* @param odpdrv_driver_t Pointer to a driver registration structure. +* @return 0 on success, non-zero on error. On error, drivers +* should release allocated resources and return. +*/ +int odpdrv_driver_register(odpdrv_driver_t *driver); + +/** +* @} +*/ + +#ifdef __cplusplus +} +#endif + +#include +#endif diff --git a/platform/Makefile.inc b/platform/Makefile.inc index b31b95b..69ee878 100644 --- a/platform/Makefile.inc +++ b/platform/Makefile.inc @@ -67,6 +67,7 @@ odpdrvspecinclude_HEADERS = \ $(top_srcdir)/include/odp/drv/spec/barrier.h \ $(top_srcdir)/include/odp/drv/spec/byteorder.h \ $(top_srcdir)/include/odp/drv/spec/compiler.h \ + $(top_srcdir)/include/odp/drv/spec/driver.h \ $(top_srcdir)/include/odp/drv/spec/shm.h \ $(top_srcdir)/include/odp/drv/spec/spinlock.h \ $(top_srcdir)/include/odp/drv/spec/std_types.h \