From patchwork Fri Nov 19 22:24:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DD29C433EF for ; Fri, 19 Nov 2021 22:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234792AbhKSW1p (ORCPT ); Fri, 19 Nov 2021 17:27:45 -0500 Received: from mail-bn8nam11on2050.outbound.protection.outlook.com ([40.107.236.50]:25057 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234745AbhKSW1p (ORCPT ); Fri, 19 Nov 2021 17:27:45 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Or+aHpJ4lbPrVgUthpDbxSfg8goRVPRR45aEmoH86Vt1KRBRcmDjxoENl8pJCNDBOzH875CTUN/WMdzA2K0ANAd+7/fbmEcyOb60Y9Jnq7k2jh2Nj+YBnI6DflCSMIjMbesRyJd3DR71EqgfbBFzbOaxZU3xzHeP8kmGSu0O4jDvZmXpFpu+qXq3Vb5T+OSAjczp685kUxgbQBoNoA+UgvGI7DZ14AhxmgRdq9vsLqFlN38byXNoQmeY2TyHBc5Y+tBUDiYu++OSL3PaFuiEnFYLjLgqo5N/ZPqncxj3Y5ABpH3ubxlnz5TPm3sTRrrzsVOCrUSyXFaGyebNlye8+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+n6r7W3TPGDH7Ay8PmUJGY+wlppbFthoFxtNRG2cJ2I=; b=bi0J8pjInmcLUZFCSyn4qUSnudVGNdZuK+0dxsEAYzlwI6/yrVHchxNfl3CrcZRLcmb8zxcq0ZyMQ9+xxb3wLHgn/J/jiU+qci+K6lAchZj48lsc+LaRdFHrim2whL8RRAAzpvImu7Hg8vuLfcNlZN6rUAFllUWcBE4UwvR6gdfj+xRnPlr+0KdyxT9YE+7AO0+BkmV22b3cqQvLGYA72EWnjuyFnq30Fm491gOLauJVU73pnETpmwrSlCQ+zRuNDRlAcBk6SbTt9QxTHBDF0zFiuTdkFJ9qFouoQzUYbNgI6WXdTnvANP/5ZALzKQyB5Bca09RU91X7VF0TzqNybw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+n6r7W3TPGDH7Ay8PmUJGY+wlppbFthoFxtNRG2cJ2I=; b=XApwNZc6yHHN20LxQL0XSoBmUqRdnc7LlXNOaTAtUJnARUI8JtqnGlxIZ3EhQJLuiF8q+QoI/XhwyB/B7bvMEPhSHBcCh98SXtLF68yTauWwWoJwwOnfpNIm01gNN9wpqIJdF93LxSfqT/v6p+2t5odmNuM2EWuuwiHNnmVRa7c= Received: from DM5PR07CA0137.namprd07.prod.outlook.com (2603:10b6:3:13e::27) by BY5PR02MB6551.namprd02.prod.outlook.com (2603:10b6:a03:1d2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Fri, 19 Nov 2021 22:24:39 +0000 Received: from DM3NAM02FT053.eop-nam02.prod.protection.outlook.com (2603:10b6:3:13e:cafe::5) by DM5PR07CA0137.outlook.office365.com (2603:10b6:3:13e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21 via Frontend Transport; Fri, 19 Nov 2021 22:24:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT053.mail.protection.outlook.com (10.13.5.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:24:39 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:24:38 -0800 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:24:38 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38934 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCJC-0001J1-MG; Fri, 19 Nov 2021 14:24:38 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id D74A060014A; Fri, 19 Nov 2021 14:24:14 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 1/9] Documentation: fpga: Add a document describing XRT Alveo driver infrastructure Date: Fri, 19 Nov 2021 14:24:04 -0800 Message-ID: <20211119222412.1092763-2-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fab5266e-83be-42ec-beaf-08d9abab605e X-MS-TrafficTypeDiagnostic: BY5PR02MB6551: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bqtk+o6945s6qyItPAetLkMMbtzmFBwypm+gDrQuzk/nXLm4YFK6EAHcCSQOPeZPQ9o/BT7SYGClRxRSKrwkRymuUau2gJ+QiHzq0bw983kXjMah9qiASrVCEEoz6Bp3zHuJDhmgcZoFvHw1OpUb4N39B8l+h3rOeN7EI0xx92XBcRkCDP75+TBTCPDJROhyvxfu7yRQjAdWs2To318ooXdsP//EYnGyyCL7lV14wTgGpp+3xp42nf2qHiS6e/GIIwYHYTSTyCB4iB3X7zvpstdrd7fnxJllVQ5L62aQWCsxqo/fE8T/HUyl4niDhdfWxveZs6I+L/Wa1a23qK3JPRV0farMRebpfcVKY104/85L88FM3bstTiCyzp4bOS9oA0lY6TY4nXDgBo/ekcEdm3jXrs6xaPQSfjxgPUxTOFygXmrIitNCgxphY4JhqPeJSFzgTfbh9GgMSsyZdzBCVZGnqMU+9EZf9DOIBr8GCXWh4iP4514y6x/5zZwaJyVuOQ0aUveo3fBbhNxEffeqsVWNew8JYDzffbfx8CC3CuA2y3otRU7Lu2NobWv0cfIuRxFNzaAqaEa9+T0VmsIOoIEBv5ZfT9dCy876O9w4H4h9d/Zy+zq0sdznLSFxnhAs+31uom07qZwXvKKORCxvDh/g5EfioCnGeJFcXPDlDVVQDlATXzMSSLDEpv6pSgbIuLXuD1urDfDlMtakhFTOFPwvQkMg2huxNzEOn0hCaCFy2h49N8cYYGMPQox/Y95nsyMZrtCuogRnG7D4n0iqR2xf6L0bZLUCf118kskyKF69Xe4NgTLS6vktegVF3jtPAoAPtVSa53tBnhWMk1jAzw== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(46966006)(36840700001)(36906005)(36860700001)(4326008)(966005)(8676002)(336012)(2906002)(54906003)(44832011)(70586007)(70206006)(82310400003)(83380400001)(7636003)(508600001)(6666004)(2616005)(356005)(42186006)(36756003)(107886003)(1076003)(26005)(47076005)(30864003)(6916009)(6266002)(316002)(426003)(5660300002)(8936002)(186003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:24:39.3305 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fab5266e-83be-42ec-beaf-08d9abab605e X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT053.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB6551 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org Describe XRT driver architecture and provide basic overview of Xilinx Alveo platform. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- Documentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 510 +++++++++++++++++++++++++++++++++++ MAINTAINERS | 10 + 3 files changed, 521 insertions(+) create mode 100644 Documentation/fpga/xrt.rst diff --git a/Documentation/fpga/index.rst b/Documentation/fpga/index.rst index f80f95667ca2..30134357b70d 100644 --- a/Documentation/fpga/index.rst +++ b/Documentation/fpga/index.rst @@ -8,6 +8,7 @@ fpga :maxdepth: 1 dfl + xrt .. only:: subproject and html diff --git a/Documentation/fpga/xrt.rst b/Documentation/fpga/xrt.rst new file mode 100644 index 000000000000..323ded5c0f4a --- /dev/null +++ b/Documentation/fpga/xrt.rst @@ -0,0 +1,510 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================== +XRTV2 Linux Kernel Driver Overview +================================== + +Authors: + +* Sonal Santan +* Max Zhen +* Lizhi Hou + +XRTV2 drivers are second generation `XRT `_ +drivers which support `Alveo `_ +PCIe platforms from Xilinx. + +XRTV2 drivers support *subsystem* style data driven platforms where driver's +configuration and behavior are determined by metadata provided by the platform +(in *device tree* format). Primary management physical function (MPF) driver +is called **xrt-mgmt**. Primary user physical function (UPF) driver is called +**xrt-user** and is under development. xrt_driver framework and FPGA subsystem +drivers are packaged into a library module called **xrt-lib**, which is shared +by **xrt-mgmt** and **xrt-user** (under development). The xrt_driver framework +implements a ``bus_type`` called **xrt_bus_type** which is used to discover HW +subsystems and facilitate inter HW subsystem interaction. + +Driver Modules +============== + +xrt-lib.ko +---------- + +xrt-lib is the repository of xrt drivers and pure software modules that can +potentially be shared between xrt-mgmt and xrt-user. All these drivers are +structured as **xrt_driver** and are instantiated by xrt-mgmt (or xrt-user under +development) based on the metadata associated with the hardware. The metadata +is in the form of a device tree as mentioned before. + +xrt-lib relies on OF kernel APIs to unflatten the metadata and overlay the +unflattened device tree nodes to system device tree. In xrt-lib module initialization +routine, "/xrt-bus" is created in system device tree, all XRT device +tree nodes and properties will be under "/xrt-bus". + +The xrt-lib infrastructure provides hooks to xrt_drivers for device node +management, user file operations and ioctl callbacks. The core infrastructure also +provides a bus functionality called **xrt_bus_type** for xrt_driver registration, +discovery and inter xrt_driver calls. xrt-lib does not have any dependency on PCIe +subsystem. + +xrt-mgmt.ko +------------ + +The xrt-mgmt driver is a PCIe device driver driving MPF found on Xilinx's Alveo +PCIe device. It creates one or more *group* device and one or more *xleaf* device. +The group and xleaf drivers are in xrt-lib and instantiations of the xrt_driver but +are called group and xleaf to symbolize the logical operation performed by them. + +The xrt-mgmt driver uses xrt-lib APIs to manages the life cycle of multiple group +drivers, which, in turn, manages multiple xleaf drivers. This flexibility allows +xrt-mgmt.ko and xrt-lib.ko to support various HW subsystems exposed by different +Alveo shells. The differences among these Alveo shells is handled in xleaf drivers. +The group driver is part of the infrastructure which provides common services to xleaf +drivers found on various Alveo shells. See :ref:`alveo_platform_overview`. + +The instantiation of specific group driver or xleaf drivers is completely data +driven based on metadata (mostly in device tree format) found through VSEC +capability and inside the firmware files, such as platform xsabin or user xclbin +file. + + +Driver Object Model +=================== + +The driver object model looks like the following:: + + +-----------+ + | of root | + +-----+-----+ + | + +---------+---------+ + | | + +-----------+ +----------+ + | xrt-bus | | ... | + +-----+-----+ +----------+ + | + +-----------+-----------+ + | | + v v + +-----------+ +-----------+ + | group | ... | group | + +-----+-----+ +------+----+ + | | + | | + +-----+----+ +-----+----+ + | | | | + v v v v + +-------+ +-------+ +-------+ +-------+ + | xleaf |..| xleaf | | xleaf |..| xleaf | + +-------+ +-------+ +-------+ +-------+ + +As an example, for Xilinx Alveo U50 before user xclbin download, the tree +looks like the following:: + + +-----------+ + | xrt-bus | + +-----+-----+ + | + +-------------------------+--------------------+ + | | | + v v v + +--------+ +--------+ +--------+ + | group0 | | group1 | | group2 | + +----+---+ +----+---+ +---+----+ + | | | + | | | + +-----+-----+ +----+-----+---+ +-----+-----+----+--------+ + | | | | | | | | | + v v | v v | v v | + +------------+ +------+ | +------+ +------+ | +------+ +-----------+ | + | xmgmt_main | | VSEC | | | GPIO | | QSPI | | | CMC | | AXI-GATE0 | | + +------------+ +------+ | +------+ +------+ | +------+ +-----------+ | + | +---------+ | +------+ +-----------+ | + +>| MAILBOX | +->| ICAP | | AXI-GATE1 |<+ + +---------+ | +------+ +-----------+ + | +-------+ + +->| CALIB | + +-------+ + +After a xclbin is downloaded, group3 will be added and the tree looks like the +following:: + + +-----------+ + | xrt-bus | + +-----+-----+ + | + +-------------------------+--------------------+-----------------+ + | | | | + v v v | + +--------+ +--------+ +--------+ | + | group0 | | group1 | | group2 | | + +----+---+ +----+---+ +---+----+ | + | | | | + | | | | + +-----+-----+ +-----+-----+---+ +-----+-----+----+--------+ | + | | | | | | | | | | + v v | v v | v v | | + +------------+ +------+ | +------+ +------+ | +------+ +-----------+ | | + | xmgmt_main | | VSEC | | | GPIO | | QSPI | | | CMC | | AXI-GATE0 | | | + +------------+ +------+ | +------+ +------+ | +------+ +-----------+ | | + | +---------+ | +------+ +-----------+ | | + +>| MAILBOX | +->| ICAP | | AXI-GATE1 |<+ | + +---------+ | +------+ +-----------+ | + | +-------+ | + +->| CALIB | | + +-------+ | + +---+----+ | + | group3 |<--------------------------------------------+ + +--------+ + | + | + +-------+--------+---+--+--------+------+-------+ + | | | | | | | + v | v | v | v + +--------+ | +--------+ | +--------+ | +-----+ + | CLOCK0 | | | CLOCK1 | | | CLOCK2 | | | UCS | + +--------+ v +--------+ v +--------+ v +-----+ + +-------------+ +-------------+ +-------------+ + | CLOCK-FREQ0 | | CLOCK-FREQ1 | | CLOCK-FREQ2 | + +-------------+ +-------------+ +-------------+ + + +group +----- + +The group driver represents a pseudo device whose life cycle is managed by +root and does not have real IO mem or IRQ resources. It's part of the +infrastructure of the MPF driver and resides in xrt-lib.ko. This driver + +* manages one or more xleaf drivers +* handle requests from xleaf drivers. For example event notifications and + inter xleaf calls. + +In xrt-mgmt, an initial group driver instance will be created by the PCIe driver. +This instance contains xleaf drivers that will trigger group instances to be +created to manage groups of xleaf drivers found on different partitions of +hardware, such as VSEC, Shell, and User. + +xleaf +----- + +The xleaf driver is a xrt_driver whose life cycle is managed by +a group driver and may or may not have real IO mem or IRQ resources. They +manage HW subsystems they are attached to. + +A xleaf driver without real hardware resources manages in-memory states for +xrt-mgmt. These states are shareable by other xleaf drivers. + +Xleaf drivers assigned to specific hardware resources drive a specific subsystem +in the device. To manipulate the subsystem or carry out a task, a xleaf driver +may ask for help from the root via root calls and/or from other leaves via +inter xleaf calls. + +A xleaf can also broadcast events through infrastructure code for other leaves +to process. It can also receive event notification from infrastructure about +certain events, such as post-creation or pre-exit of a particular xleaf. + +xrt_bus_type +------------ + +xrt_bus_type defines a virtual bus which handles xrt_driver probe, remove and match +operations. All xrt_drivers register with xrt_bus_type as part of xrt-lib driver +``module_init`` and un-register as part of xrt-lib driver ``module_exit``. + +FPGA Manager Interaction +======================== + +fpga_manager +------------ + +An instance of fpga_manager is created by xmgmt_main and is used for xclbin +image download. fpga_manager requires the full xclbin image before it can +start programming the FPGA configuration engine via Internal Configuration +Access Port (ICAP) xrt_driver. + +fpga_region +----------- + +For every interface exposed by the currently loaded xclbin/xsabin in the +*parent* fpga_region a new instance of fpga_region is created like a *child* +fpga_region. The device tree of the *parent* fpga_region defines the +resources for a new instance of fpga_bridge which isolates the parent from +child fpga_region. This new instance of fpga_bridge will be used when a +xclbin image is loaded on the child fpga_region. After the xclbin image is +downloaded to the fpga_region, an instance of a group is created for the +fpga_region using the device tree obtained as part of the xclbin. If this +device tree defines any child interfaces, it can trigger the creation of +fpga_bridge and fpga_region for the next region in the chain. + +fpga_bridge +----------- + +Like the fpga_region, an fpga_bridge is created by walking the device tree +of the parent group. The bridge is used for isolation between a parent and +its child. + +Driver Interfaces +================= + +xrt-mgmt Driver Ioctls +---------------------- + +Ioctls exposed by the xrt-mgmt driver to user space are enumerated in the +following table: + +== ===================== ============================ ========================== +# Functionality ioctl request code data format +== ===================== ============================ ========================== +1 FPGA image download XMGMT_IOCICAPDOWNLOAD_AXLF xmgmt_ioc_bitstream_axlf +== ===================== ============================ ========================== + +A user xclbin can be downloaded by using the xbmgmt tool from the XRT open source +suite. See example usage below:: + + xbmgmt partition --program --path /lib/firmware/xilinx/862c7020a250293e32036f19956669e5/test/verify.xclbin --force + +.. _alveo_platform_overview: + +Alveo Platform Overview +======================= + +Alveo platforms are architected as two physical FPGA partitions: *Shell* and +*User*. The Shell provides basic infrastructure for the Alveo platform like +PCIe connectivity, board management, Dynamic Function Exchange (DFX), sensors, +clocking, reset, and security. DFX, partial reconfiguration, is responsible for +loading the user compiled FPGA binary. + +For DFX to work properly, physical partitions require strict HW compatibility +with each other. Every physical partition has two interface UUIDs: the *parent* +UUID and the *child* UUID. For simple single stage platforms, Shell → User forms +the parent child relationship. + +.. note:: + Partition compatibility matching is a key design component of the Alveo platforms + and XRT. Partitions have child and parent relationship. A loaded partition + exposes child partition UUID to advertise its compatibility requirement. When + loading a child partition, the xrt-mgmt driver matches the parent + UUID of the child partition against the child UUID exported by the parent. + The parent and child partition UUIDs are stored in the *xclbin* (for the user) + and the *xsabin* (for the shell). Except for the root UUID exported by VSEC, + the hardware itself does not know about the UUIDs. The UUIDs are stored in + xsabin and xclbin. The image format has a special node called Partition UUIDs + which define the compatibility UUIDs. + + +The physical partitions and their loading are illustrated below:: + + SHELL USER + +-----------+ +-------------------+ + | | | | + | VSEC UUID | CHILD PARENT | LOGIC UUID | + | o------->|<--------o | + | | UUID UUID | | + +-----+-----+ +--------+----------+ + | | + . . + | | + +---+---+ +------+--------+ + | POR | | USER COMPILED | + | FLASH | | XCLBIN | + +-------+ +---------------+ + + +Loading Sequence +---------------- + +The Shell partition is loaded from flash at system boot time. It establishes the +PCIe link and exposes two physical functions to the BIOS. After the OS boots, +the xrt-mgmt driver attaches to the PCIe physical function 0 exposed by the Shell +and then looks for VSEC in the PCIe extended configuration space. Using VSEC, it +determines the logic UUID of the Shell and uses the UUID to load matching *xsabin* +file from Linux firmware directory. The xsabin file contains the metadata to +discover the peripherals that are part of the Shell and the firmware for any +embedded soft processors in the Shell. The xsabin file also contains Partition +UUIDs. + +The Shell exports a child interface UUID which is used for the compatibility +check when loading the user compiled xclbin over the User partition as part of DFX. +When a user requests loading of a specific xclbin, the xrt-mgmt driver reads +the parent interface UUID specified in the xclbin and matches it with the child +interface UUID exported by the Shell to determine if the xclbin is compatible with +the Shell. If the match fails, loading of xclbin is denied. + +xclbin loading is requested using the ICAP_DOWNLOAD_AXLF ioctl command. When loading +a xclbin, the xrt-mgmt driver performs the following *logical* operations: + +1. Copy xclbin from user to kernel memory +2. Sanity check the xclbin contents +3. Isolate the User partition +4. Download the bitstream using the FPGA config engine (ICAP) +5. De-isolate the User partition +6. Program the clocks (ClockWiz) driving the User partition +7. Wait for the memory controller (MIG) calibration +8. Return the loading status back to the caller + +`Platform Loading Overview `_ +provides more detailed information on platform loading. + + +xsabin +------ + +Each Alveo platform comes packaged with its own xsabin. The xsabin is a trusted +component of the platform. For format details refer to :ref:`xsabin_xclbin_container_format` +below. xsabin contains basic information like UUIDs, platform name and metadata in the +form of device tree. See :ref:`device_tree_usage` below for details and example. + +xclbin +------ + +xclbin is compiled by end user using +`Vitis `_ +tool set from Xilinx. The xclbin contains sections describing user compiled +acceleration engines/kernels, memory subsystems, clocking information etc. It also +contains an FPGA bitstream for the user partition, UUIDs, platform name, etc. + + +.. _xsabin_xclbin_container_format: + +xsabin/xclbin Container Format +------------------------------ + +xclbin/xsabin is ELF-like binary container format. It is structured as series of +sections. There is a file header followed by several section headers which is +followed by sections. A section header points to an actual section. There is an +optional signature at the end. The format is defined by the header file ``xclbin.h``. +The following figure illustrates a typical xclbin:: + + + +---------------------+ + | | + | HEADER | + +---------------------+ + | SECTION HEADER | + | | + +---------------------+ + | ... | + | | + +---------------------+ + | SECTION HEADER | + | | + +---------------------+ + | SECTION | + | | + +---------------------+ + | ... | + | | + +---------------------+ + | SECTION | + | | + +---------------------+ + | SIGNATURE | + | (OPTIONAL) | + +---------------------+ + + +xclbin/xsabin files can be packaged, un-packaged and inspected using an XRT +utility called **xclbinutil**. xclbinutil is part of the XRT open source +software stack. The source code for xclbinutil can be found at +https://github.com/Xilinx/XRT/tree/master/src/runtime_src/tools/xclbinutil + +For example, to enumerate the contents of a xclbin/xsabin use the *--info* switch +as shown below:: + + + xclbinutil --info --input /opt/xilinx/firmware/u50/gen3x16-xdma/blp/test/bandwidth.xclbin + xclbinutil --info --input /lib/firmware/xilinx/862c7020a250293e32036f19956669e5/partition.xsabin + + +.. _device_tree_usage: + +Device Tree Usage +----------------- + +The xsabin file stores metadata which advertise HW subsystems present in a +partition. The metadata is stored in device tree format with a well defined +schema. XRT management driver uses this information to create *xrt_devices* and +bind *xrt_drivers* to them. The xrt_drivers could be independent modules or +found in **xrt-lib.ko** kernel module. + +Deployment Models +================= + +Baremetal +--------- + +In bare-metal deployments, both MPF and UPF are visible and accessible. The +xrt-mgmt driver binds to MPF. The xrt-mgmt driver operations are privileged and +available to system administrator. The full stack is illustrated below:: + + HOST + + [XRT-MGMT] [XRT-USER] + | | + | | + +-----+ +-----+ + | MPF | | UPF | + | | | | + | PF0 | | PF1 | + +--+--+ +--+--+ + ......... ^................. ^.......... + | | + | PCIe DEVICE | + | | + +--+------------------+--+ + | SHELL | + | | + +------------------------+ + | USER | + | | + | | + | | + | | + +------------------------+ + + + +Virtualized +----------- + +In virtualized deployments, the privileged MPF is assigned to the host but the +unprivileged UPF is assigned to a guest VM via PCIe pass-through. The xrt-mgmt +driver in host binds to MPF. The xrt-mgmt driver operations are privileged and +only accessible to the MPF. The full stack is illustrated below:: + + + .............. + HOST . VM . + . . + [XRT-MGMT] . [XRT-USER] . + | . | . + | . | . + +-----+ . +-----+ . + | MPF | . | UPF | . + | | . | | . + | PF0 | . | PF1 | . + +--+--+ . +--+--+ . + ......... ^................. ^.......... + | | + | PCIe DEVICE | + | | + +--+------------------+--+ + | SHELL | + | | + +------------------------+ + | USER | + | | + | | + | | + | | + +------------------------+ + + + + + +Platform Security Considerations +================================ + +`Security of Alveo Platform `_ +discusses the deployment options and security implications in great detail. diff --git a/MAINTAINERS b/MAINTAINERS index 80eebc1d9ed5..fd7053bcfdb0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7369,6 +7369,16 @@ F: Documentation/fpga/ F: drivers/fpga/ F: include/linux/fpga/ +FPGA XRT DRIVERS +M: Lizhi Hou +R: Max Zhen +R: Sonal Santan +L: linux-fpga@vger.kernel.org +S: Supported +W: https://github.com/Xilinx/XRT +F: Documentation/fpga/xrt.rst +F: drivers/fpga/xrt/ + FPU EMULATOR M: Bill Metzenthen S: Maintained From patchwork Fri Nov 19 22:24:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75B33C433F5 for ; Fri, 19 Nov 2021 22:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235777AbhKSW1b (ORCPT ); Fri, 19 Nov 2021 17:27:31 -0500 Received: from mail-mw2nam10on2085.outbound.protection.outlook.com ([40.107.94.85]:48097 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235458AbhKSW1b (ORCPT ); Fri, 19 Nov 2021 17:27:31 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=COFuW1+Ck1ly9+JQabjfe5epdoG85iJuM0i58ZK3BhxOhdOcjIpow2dd+g3EZYP1DhjTzi+ykhyYLYzjlFoCm/DXM7l15j7/ydO/V7Yv7O91o4TAUM3aybqH741soRCCvdeN0HiT7+ho0npjhQ2H3rf7MQOkg6hQm1203PpiRMKnsVBBInzk72nVoror1V3fOVOpJDMgb7KVjbGN1p8VTps6pfUDbcSE2e3RViWGs004BRH88u7U5Qe/AbA/XAvcDCmulbULLuMeLeRyWWJDbD+qTtyKUmVg/3AFfgDDr1Fcs6OZHyfnnkHnkqQnkc+//L8uJHKT1d+ocHUGVU1j5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tqCJ9uuK6CYrGXTIrXJQ8gAi2aNPu2y0d2u1DckFUHM=; b=J/hn/PHMzf+PWwQzY8UZ8Y5VgHvnNzbQPGpouvHuepnr41T/VIZqXXFLFBFJ2PLdEouB7GSsH69ZwTmYvNXx7AqS7o/WKsF9fVGqJ/7hFWa8TQ6OaikeoUOu4oriXkz1R6A7y07L8dDMs7Z6Rt7hufRytwNGIdXseDI1AFgySHFSCBr20sV/J8PRY1uuCiOjkQm0YM5sh/5MMQmkWGqOz7bW16zUQ+2vjk9JqQxhCR3QSGL2CuJvMo02tY9YasCPMcmZOjfhMvr0DuHJU4cTorxblUZStufKDzKGEWizsFIZ2+6lkDjYv4NBnsj9AzQSwAOMlGjoM1LpT2eItqb6Gw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tqCJ9uuK6CYrGXTIrXJQ8gAi2aNPu2y0d2u1DckFUHM=; b=CK6uqvVlBgIMuvvDVBLFau80bnUPpmSJd7KRH4yMqAPd81xNBt690Q+l7ip6yd+8++lclhwnHOdCpDIO1I1hrfXFKnuYGU+2TfyZakyEaEJKUC4XV76vqzKEXSuwbFv1ZuNIjAFE5kzGO1Aa2eUCD5+hxCQv3ScZ2IAlS6jLIvk= Received: from DM5PR12CA0010.namprd12.prod.outlook.com (2603:10b6:4:1::20) by DM5PR02MB2266.namprd02.prod.outlook.com (2603:10b6:3:4e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27; Fri, 19 Nov 2021 22:24:27 +0000 Received: from DM3NAM02FT040.eop-nam02.prod.protection.outlook.com (2603:10b6:4:1:cafe::76) by DM5PR12CA0010.outlook.office365.com (2603:10b6:4:1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:24:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT040.mail.protection.outlook.com (10.13.5.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:24:27 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:24:26 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:24:26 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38932 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCJ0-000AM5-JX; Fri, 19 Nov 2021 14:24:26 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id C45E9600061; Fri, 19 Nov 2021 14:24:14 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 2/9] Documentation: devicetree: bindings: add xrt group binding Date: Fri, 19 Nov 2021 14:24:05 -0800 Message-ID: <20211119222412.1092763-3-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5be8d501-5467-49ef-6455-08d9abab5934 X-MS-TrafficTypeDiagnostic: DM5PR02MB2266: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DWKxUfo0oSDwmTDDY3GYPQbPnFkheMjguWy14NUIPjGOaZCiW3Fk2NG0/e7UMW/pkiiWhrvC1RUyHv3Aw8ydC4bvpN0wNZxY6FbsdnMvT97Z1u9rXerJby55T73C0WVkH0CRkjJqWZiNQ9uhOsjycwQ27Kx1qHnngJrpzCxYfxVLm0zjuc5Cnr8631M+3JLy9D+racKSnOxNCmGrpaD9LW9Ij4yAtBteX9zLYUZIWf+u99fI2qd785Yp5yFa/KbHljyDO2aHF49wr1WAbmSJkvFt1NI2zcYP1e+YX6uJ6qEpT9VLigipayc2zFgFTlXUM9Pe+GTBkUzyo8vqWBZtluPd4IrBuv4idLi3n20wIboWdeDJU/qBHLhi3+O3JdRFo/Kh6bMYTr6gTzDbT2FfSgViZnJrNhhuspv7CVy33pNME0mobv73CNx/sdNE1dJoS+DcpT9zropXkgCsORmFa+U5ZUY9O1Tv8lYF8HPB242JiaanmW9x/ueUrv6XeAVVAcMtwjNM2xWool25nsiVg8OUfYE4NBHmjekyIATe7DdFtSiT3HQI3sfeW8CAAbPhhP8pLPmYqIr8kQ7X7O0WDDsOXyE7ZrgliRe+g32OA2PJV7yVUzdjsHpsHNybKQbKQaLog+DFRflIQ9xSVaiiApXxaK6mAXnVGkndNZbf6LeAnV2XsA8YP1ywdCjEar4u5h5KrMLbcgyRlXMBjguA4qQORdF45a//eaFZgr4dv3lrucHaKchnC59HUeW6yqSOhxrXu3L1JdtNcq0MXdz9yjcHuL0yfbpKFtslZmTCz+RXpq6l3y8AfFW3A+1bQM/lsB4+mCjKVjWBijOydzLlTw== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(36840700001)(46966006)(44832011)(1076003)(26005)(8936002)(426003)(2616005)(82310400003)(36756003)(70586007)(36906005)(7636003)(508600001)(336012)(8676002)(4326008)(6666004)(70206006)(47076005)(6266002)(54906003)(5660300002)(42186006)(356005)(36860700001)(6916009)(316002)(186003)(966005)(2906002)(107886003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:24:27.3089 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5be8d501-5467-49ef-6455-08d9abab5934 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT040.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB2266 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org Create device tree binding document for xrt group device. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- .../bindings/xrt/xlnx,xrt-group.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/xrt/xlnx,xrt-group.yaml diff --git a/Documentation/devicetree/bindings/xrt/xlnx,xrt-group.yaml b/Documentation/devicetree/bindings/xrt/xlnx,xrt-group.yaml new file mode 100644 index 000000000000..6cc7a83d7c14 --- /dev/null +++ b/Documentation/devicetree/bindings/xrt/xlnx,xrt-group.yaml @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/xrt/xlnx,xrt-group.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx XRT group for Alveo platforms + +description: | + The xrt group is a pseudo device which is used to manage and + support xrt devices in the same Alveo partition. It is part + of XRT infrastructure. + +maintainers: + - Lizhi Hou + +properties: + compatible: + const: xlnx,xrt-group + + "#address-cells": + const: 3 + + "#size-cells": + const: 2 + + ranges: true + +patternProperties: + "^.*@[0-5],[0-9a-f]+,[0-9a-f]+$": + description: xrt devices belongs to this group + type: object + +required: + - compatible + - "#address-cells" + - "#size-cells" + - ranges + +additionalProperties: false + +examples: + - | + xrt-bus { + #address-cells = <2>; + #size-cells = <2>; + xrt-group@48,0 { + compatible = "xlnx,xrt-group"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0 0 0 0 0xe0000000 0 0x2000000 + 2 0 0 0 0xe4200000 0 0x40000>; + ep_fpga_configuration_00@0,0,1e88000 { + reg = <0 0 0x1e88000 0 0x8000>; + }; + }; + }; From patchwork Fri Nov 19 22:24:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22C8BC433F5 for ; Fri, 19 Nov 2021 22:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235126AbhKSW2U (ORCPT ); Fri, 19 Nov 2021 17:28:20 -0500 Received: from mail-dm6nam10on2060.outbound.protection.outlook.com ([40.107.93.60]:37152 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234745AbhKSW2U (ORCPT ); Fri, 19 Nov 2021 17:28:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FR2holyrp3W0c+YNYtdH9UyBwVSEw1HAbh/w8/eao2la9GvVng57zUtz6jeZvUsJzXytX/9j+ebBLVTs4M90kpJ28qsAhlS8livC1g+ShgeQYtr0/0dJ0VQmDdPdVw/2TLoiJHyExE2nURRh6Uc9CCMFHvaVRLalheZBykmrJ/heh0WbpwpxSjEE/2fpAa4eKmGPb3APEtXoQnbH1KnYp2rMo/aJh4pm95zbcpcuF4t1OYGDB8kyZ1OBYebud6Y38aErc0yNm1iz/n9a9BxAtJUo8lEJ086GO2b+252GuuBL8PPCHfA/0MY+CEtJTt8P7KJNomecdWaNMyeSdNv5Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1igVE7zaLdniu8vfszrZASVNDL49MDeN+YyJ7SpgO6k=; b=KC1J/+4bKzuvf6w/9FD3bigzaLMmN+0pLCawjG1jeKYjKFK1HDA01eJRXb2wVnNuMIZG9nkmxzPy/5vop7MsXrpDdkhbhrDyk9HD7nk1zDT+XVIp/XHwGLqXcMSxEZ0T3lKCH82p76XOXNqZB1PXU8HWtIthikGGijYamBTMkJGL6P/eALfeIdkB8rB/9Np/Oaw60QvTtbqbd/F1HxkGMZz1ZKc8JADCjpOEJv2RTQL9a8OMXGhJImc5TogY/4fHek06mIsAYRyythcCt16CXkOCHm4XqotceIj8TYrosfmGUE/ALfZdqcSce/pc75UC1GYtkXDRErsrP5LRCBH8+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1igVE7zaLdniu8vfszrZASVNDL49MDeN+YyJ7SpgO6k=; b=Y0T3nzB/Gy3R6w7pV9jSv/+GyXfuUAcsegZ5h6iEP+HOL3geUEkf/mJPQT+vKrsuI/pjqcett2qXOTAiwVYXUTQSiGUitt9mKhU4gKsTCSMmcIryJhcgj9YMLsMTRV6uD1HBHFlt7eXOz17m363RcgfqiG2pl/nY8b0c38RCDq4= Received: from DS7PR03CA0242.namprd03.prod.outlook.com (2603:10b6:5:3b3::7) by CO6PR02MB7537.namprd02.prod.outlook.com (2603:10b6:303:b3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Fri, 19 Nov 2021 22:25:14 +0000 Received: from DM3NAM02FT007.eop-nam02.prod.protection.outlook.com (2603:10b6:5:3b3:cafe::e2) by DS7PR03CA0242.outlook.office365.com (2603:10b6:5:3b3::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.24 via Frontend Transport; Fri, 19 Nov 2021 22:25:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT007.mail.protection.outlook.com (10.13.4.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:25:14 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:25:03 -0800 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:25:02 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38938 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCJa-0001M7-SP; Fri, 19 Nov 2021 14:25:02 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 162B760014B; Fri, 19 Nov 2021 14:24:14 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 3/9] of: handle fdt buffer alignment inside unflatten function Date: Fri, 19 Nov 2021 14:24:06 -0800 Message-ID: <20211119222412.1092763-4-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d1f88afb-4b63-467d-0782-08d9abab755e X-MS-TrafficTypeDiagnostic: CO6PR02MB7537: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XRd29BQ9ItvF+qT68WS9VmX2RDUDzGrHLooVzR3+2e2iSnOwPgMV4F9YqVG6eGY9HUz4n34zgwpC5JzJC8bw33UG4LmtRY0xx4i/oCa4jj9SyrnA7jkKSfT8neVghTe2KFTBfx8Y2RzAA2F6bzXCmNRL+CGXBiNabKhid2K21lLyIA/mWLafMnP41/j0cJZK4h4WhKszJYrhAtFF125mh9fgDqZZ4G7ymGfEEHWZyOeUksnz6cvOd0pktGAvT3vlk5sKVAW2H6QVEny0z69Xm4UFOMSyOJ+PygpJ6mp/KFTgWMLG8LpofYUcmBkEPuF8SqJpUlI/BcxZBY77pHNI/hRml2Wew6Lxit6gWNC9Z+vXTfxu+AhvH+VfRzY6CEXz7B+7U9BA/iEuaM1NgXyKVof5u6icrQqPwlto49oCi8R7sLRYFn/r2i78r0bjRNgWf3gMWSKDiza+s5A01O/uSlYytMGTXMS5bj6D81BaYsm8ph0Bq8Uy9L60p0dVOw01HSoRtMDef+uUa6+niOb/DrPRytK804H9/8Qw4b/nUYlP28fyLNWuO8dnfEDg/kuwIU+/jleJc1xZEXOyZ1A9bh7luFSoPH5bF//2AyjDJd20L7G3wjErJI8B3O8XMMWbD68MYFx/LvfHoXD8gP3XUkTBfXWluynJmySihSHLkVs6kSKETsOhk48Qn0zGx4Paf8oM9bB+Dtdz/Y1Iv/1ZfQ== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(36840700001)(46966006)(6916009)(44832011)(54906003)(42186006)(8676002)(36756003)(426003)(336012)(2616005)(47076005)(1076003)(36906005)(4326008)(6266002)(107886003)(316002)(8936002)(82310400003)(26005)(6666004)(2906002)(186003)(508600001)(7636003)(356005)(36860700001)(83380400001)(5660300002)(70586007)(70206006);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:25:14.5580 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d1f88afb-4b63-467d-0782-08d9abab755e X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT007.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR02MB7537 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org Add alignment check to of_fdt_unflatten_tree(). If it is not aligned, allocate a aligned buffer and copy the fdt blob. So the caller does not have to deal with the buffer alignment before calling this function. XRT uses this function to unflatten fdt which is from Alveo firmware. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/of/fdt.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 4546572af24b..d64445e43ceb 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -455,13 +455,28 @@ void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node *dad, struct device_node **mynodes) { + void *new_fdt = NULL, *fdt_align; void *mem; + if (fdt_check_header(blob)) { + pr_err("Invalid fdt blob\n"); + return NULL; + } + fdt_align = (void *)PTR_ALIGN(blob, FDT_ALIGN_SIZE); + if (fdt_align != blob) { + new_fdt = kmalloc(fdt_totalsize(blob) + FDT_ALIGN_SIZE, GFP_KERNEL); + if (!new_fdt) + return NULL; + fdt_align = PTR_ALIGN(new_fdt, FDT_ALIGN_SIZE); + } + mutex_lock(&of_fdt_unflatten_mutex); - mem = __unflatten_device_tree(blob, dad, mynodes, &kernel_tree_alloc, + mem = __unflatten_device_tree(fdt_align, dad, mynodes, &kernel_tree_alloc, true); mutex_unlock(&of_fdt_unflatten_mutex); + kfree(new_fdt); + return mem; } EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); From patchwork Fri Nov 19 22:24:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8150FC433F5 for ; Fri, 19 Nov 2021 22:24:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235003AbhKSW17 (ORCPT ); Fri, 19 Nov 2021 17:27:59 -0500 Received: from mail-bn8nam12on2057.outbound.protection.outlook.com ([40.107.237.57]:15520 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234745AbhKSW17 (ORCPT ); Fri, 19 Nov 2021 17:27:59 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WvRs8+fK6mpAwjmdCa6QOVg41kWLV2QW0N7QVuFxOW3Pcfrl5bJD0N8OU5CVuQ7nZVjScBvhZjA7QBofS6Q5deAhHyjnRXoAOS2VAh/e1yFnX9C8rXw4F0nihVu1y5zO3FDow48f7QLAIklqUILdiFLzrplUAJQcMPhCR09lhvmJrfHWjDXH0x6q3mbBK6S6jPjGmBSpVAUn9bsAQfc8KgLEc245TWCH0Dy77oO0dCxE0OPC0LqtfK6fm49a86mN5Jc81YBLF9s2upHMnXyVRJpd4SgRe1vLb2FHBxzw52BMsGYe2tiYJ40MGpxf30ILFxo8CzPAynHbILA9RSImuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dor8ozB7mx0oWaaCwou5aFQnENTnttIBANnGY2uccQ8=; b=KXJ+h3r8fd0YQ+A5/QeBrYEmyDS9viVqCJo2dpJ9mOPvk4mDNu1+aCvLOGL6K6tIU1csGhZHFDkoJowyapDuY5GEjKuwyjfDP+hEuqzO5hMclp1pmOBws0RzsLfVh4oCkrVDKQCunQYaaac3IPG1q1Jvxa6DdUSrBiq9hwZx7hC5lGvUIhMQszH0iQCLRI8vHmGkoOBJ1iZ5hgUvfem+pQrt8A/aFaQWhqY+m5c/s6lGhFVZDYKPld+7+Gmg5E4IWVrJP8PfWwe8WAOIqXGt1VLU0h8F60U3bWpM4+hVHn1l8m2luaj9Ozk00Lw6rXX8Uo0IINfWlMM2f24B4mebtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dor8ozB7mx0oWaaCwou5aFQnENTnttIBANnGY2uccQ8=; b=iBmZ+WzvMUaBP/9t7V6KSHvcNj0HUxScsO4uhC1OvreLHs+k5t0RvcuG4q/afX6mA8gCPI+KWe0mSxmK5H5Z/j329y2EkNIy9vHggtmM29TQM5vjLFWW3/JyNb+7TqvLAQ/rFqDQs/ZLsjRohly2TBbVfC6Fz27OFU2zNssOM6c= Received: from DS7PR05CA0030.namprd05.prod.outlook.com (2603:10b6:5:3b9::35) by BYAPR02MB5062.namprd02.prod.outlook.com (2603:10b6:a03:6f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Fri, 19 Nov 2021 22:24:52 +0000 Received: from DM3NAM02FT031.eop-nam02.prod.protection.outlook.com (2603:10b6:5:3b9:cafe::cc) by DS7PR05CA0030.outlook.office365.com (2603:10b6:5:3b9::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.11 via Frontend Transport; Fri, 19 Nov 2021 22:24:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT031.mail.protection.outlook.com (10.13.4.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:24:51 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:24:50 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:24:50 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38936 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCJO-000ANC-Nh; Fri, 19 Nov 2021 14:24:50 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id ECEAE600147; Fri, 19 Nov 2021 14:24:14 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 4/9] of: create empty of root Date: Fri, 19 Nov 2021 14:24:07 -0800 Message-ID: <20211119222412.1092763-5-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 121281a7-92cd-4736-ca61-08d9abab678a X-MS-TrafficTypeDiagnostic: BYAPR02MB5062: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jAfEHgx+B9160Mb/DN8mWfV/cXomRauH306W+sy/4NMGdF5V+QoqK50eeSMnIMDe0L6nQ+d0hqO+mluAlytJWqf+v+ElDDBwsu0dAuZb2X90lYTr2WEgNl+dZGZLcMwX+cgXoqLzvNLUK+IFn8UgBlVMRF7iRWgVz3lH4n24VcCcvVpiZt1Ju4j2ylPM3zGYN2wikSgx1C/TFyD+NELOd2uxfuI6ZYxICXnuzNX2OdLyXGm4cHr9l/imLd9mMIK17G/ZGsKmSFMy4Be0y4D+JraYtiDT8cPHY3iMJ1o3LFIwO0pqkRV7ldcZSZ2IlVC7QoMASFqFKPPgOPMJJzGXfA40B7RKhKK1UwQAlD5QTz+KqpSvzhd9glf2YPyJhSjTZJYFxxl6DZE/bkCRCit9DAwCUKOMSoIbC+NNOiV8dnISPFuv7jzGJNmCDo2xLACr/qaA+0H/L0xDLXEQMI5doLVHN8NcQZ7jwUjXTidfSWAjZ16cEATZQqp5jKP1Xucy06zIVutAnQ/2y6tT4m6csHKXjgHfh2mn5yTNbqW7c5eCcAF+3PFGR5CX0++nNDBN7lLTgSuYRTmyYCSeovwHMbluJwUzIcC0GOfS33nr7z0j1JjUHzrx4EshS88fcHNcEqCy/slWd86oh5i/5UEy4/YSPgO8AGicy1yv2KiJAaUaXYJb/bSqZZlN/RlyDQ7kcE4nES8HM+Y9kAc2tCn78g== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(46966006)(36840700001)(36906005)(8936002)(82310400003)(42186006)(26005)(8676002)(508600001)(44832011)(2616005)(54906003)(316002)(6916009)(36756003)(4326008)(5660300002)(426003)(356005)(70586007)(70206006)(83380400001)(107886003)(2906002)(6666004)(36860700001)(1076003)(7636003)(6266002)(186003)(336012)(47076005);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:24:51.3632 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 121281a7-92cd-4736-ca61-08d9abab678a X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT031.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR02MB5062 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org When OF_FLATTREE is selected and there is not a device tree, create an empty device tree root node. of/unittest.c code is referenced. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/of/Makefile | 2 +- drivers/of/fdt.c | 20 ++++++++++++++++++++ drivers/of/fdt_default.dts | 5 +++++ drivers/of/of_private.h | 5 +++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 drivers/of/fdt_default.dts diff --git a/drivers/of/Makefile b/drivers/of/Makefile index c13b982084a3..815f5220465b 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -2,7 +2,7 @@ obj-y = base.o device.o platform.o property.o obj-$(CONFIG_OF_KOBJ) += kobj.o obj-$(CONFIG_OF_DYNAMIC) += dynamic.o -obj-$(CONFIG_OF_FLATTREE) += fdt.o +obj-$(CONFIG_OF_FLATTREE) += fdt.o fdt_default.dtb.o obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o obj-$(CONFIG_OF_PROMTREE) += pdt.o obj-$(CONFIG_OF_ADDRESS) += address.o diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d64445e43ceb..3d6e4543419e 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -481,6 +481,26 @@ void *of_fdt_unflatten_tree(const unsigned long *blob, } EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); +static int __init of_fdt_root_init(void) +{ + struct device_node *np; + + if (of_root) + return 0; + + if (!of_fdt_unflatten_tree((const unsigned long *)__dtb_fdt_default_begin, + NULL, &of_root)) { + pr_warn("%s: unflatten default tree failed\n", __func__); + return -ENODATA; + } + + for_each_of_allnodes(np) + __of_attach_node_sysfs(np); + + return 0; +} +late_initcall(of_fdt_root_init); + /* Everything below here references initial_boot_params directly. */ int __initdata dt_root_addr_cells; int __initdata dt_root_size_cells; diff --git a/drivers/of/fdt_default.dts b/drivers/of/fdt_default.dts new file mode 100644 index 000000000000..d1f12a76dfc6 --- /dev/null +++ b/drivers/of/fdt_default.dts @@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; + +/ { +}; diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 631489f7f8c0..47c6bb47ef25 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -41,6 +41,11 @@ extern struct mutex of_mutex; extern struct list_head aliases_lookup; extern struct kset *of_kset; +#if defined(CONFIG_OF_FLATTREE) +extern u8 __dtb_fdt_default_begin[]; +extern u8 __dtb_fdt_default_end[]; +#endif + #if defined(CONFIG_OF_DYNAMIC) extern int of_property_notify(int action, struct device_node *np, struct property *prop, struct property *old_prop); From patchwork Fri Nov 19 22:24:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF971C433EF for ; Fri, 19 Nov 2021 22:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235839AbhKSW2l (ORCPT ); Fri, 19 Nov 2021 17:28:41 -0500 Received: from mail-bn8nam12on2060.outbound.protection.outlook.com ([40.107.237.60]:24928 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235895AbhKSW2i (ORCPT ); Fri, 19 Nov 2021 17:28:38 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TiHYYdq9r/uqrzwrDMccoBGAowJj83IewxTwN/KizraIUjmfrGOTyaHZf8Mw9tPWmo1trCfd2UTiPMSCliybLeeLp0sLxhyZmYnCI1Wv5AkK2iY0iGOkaYjVlYhmMfDM7nHTd8X0jlvBjddgVhbyH6UqYjZXBvkgnLQOAig4U++xiva8XSwXBiEhGCNeOfTqL8fbpIP4KSZSJRA3J35vGVT4SsgrvBoT7LNKjS/zx5lHo3CzZhQBE1M7v5YsRp50cv4Y34tNHd/r0G/Ht9rPMoeBb9dohqf83CVPBYomP3abPa+CgYg+HkFPe4S3xRiZSygljPE735mxgfliftALrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iXTdzpOJ8obTBvITPBprkb8xjbWWvcxIkFxLtmJx810=; b=R4Rv/aT6KOHh7WCVpmrGldGfnI8oFSgYmUOuGyWJpFUyDkLlCIJMa/05lccAVOw4wde+vfk61YLtSJeEfClunl/tSZDpaPDZnb44w0x/cNqdPPX+YkdPrgkeCfzkWT+D3b7Ud+jffu1Oh3G1RcAascAS9e12vkkgyO6bD0IJZtDkHvdrer91ReZA9YUPTXv3rcObfthR8tDXCQzX9MZsxWHKcl6UiFmyaaGSujENgz/FOqcE70QBMN1jf2aUOOUVEbzAYKlRY4nTtmWn38QoL9ffUxKfSfcC5X9qubGMuGCYyt9ENVoSzkvnk2RHbjK2et/3lX0HRNOiHW72UYTHQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iXTdzpOJ8obTBvITPBprkb8xjbWWvcxIkFxLtmJx810=; b=pt9z8+juD0IA0XAJ3bAdK1aeqVk5KUkG4wAasxTeJDRLOnMv3Nuqd3ugZbScWC37UYzZHFz+zRNAUj6J4WZRh89gADgEVgE45KkGTnTkXT3XR9Dwk9+HW9yXPTTglxP3AKCvLELFbz6VS8VpkYGdqaqs7prNM2EX8FD7VF5Cd1c= Received: from DM5PR10CA0024.namprd10.prod.outlook.com (2603:10b6:4:2::34) by MN2PR02MB6831.namprd02.prod.outlook.com (2603:10b6:208:1d1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.26; Fri, 19 Nov 2021 22:25:29 +0000 Received: from DM3NAM02FT016.eop-nam02.prod.protection.outlook.com (2603:10b6:4:2:cafe::8b) by DM5PR10CA0024.outlook.office365.com (2603:10b6:4:2::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:25:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT016.mail.protection.outlook.com (10.13.4.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:25:27 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:25:27 -0800 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:25:27 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38942 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCJy-0001Q2-VF; Fri, 19 Nov 2021 14:25:26 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 40ED660014F; Fri, 19 Nov 2021 14:24:15 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 5/9] fpga: xrt: xrt-lib initialization Date: Fri, 19 Nov 2021 14:24:08 -0800 Message-ID: <20211119222412.1092763-6-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b3f9dd9a-cde4-467c-677e-08d9abab7d2b X-MS-TrafficTypeDiagnostic: MN2PR02MB6831: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9AO6vd/E78+E3VQxCcIOgY6F/5nPQfN38Lh9CLwSDe9CnMRjT7acb8G+KcbkGr/2hBnPgUHdW9AeN5H6fOMxQdDUBoTJbAofz4/cLEZJ+h90Z0dzfBjaqKd9WwTSentkzrK1PUv0IMEMaRz4oDIiESxyCt8kmC36t0hOkSinuddKECW0to7A43YKayLU0JCbh8LrvSsAbnsAUxbT10jubcG8M6+Pj/MtbsXiInWcoxNrSJ+6fkqWEoASRhlEzFdmXOOHgW4gBUpR2uxiLlJZLJosrRKmiv/HzgxU6YY+/OjHKDgzjCFnAuouauh5oXvpd8ZjKc8XK0cwFq6VAWCuVPtP87h8MRiYr09yHSoRaET6soRzFnEj+JljyP1Jpckqw1PzM+zfxxdpdcVQ4FimPW0CMub7gJlrErzVM8cahA/JmSv6Rg0hYnrV6pD/4iecZ9Mhz4X5i5t5MnQIwcJkpWlXJZNKf2bqW1nBOr3E0I0VYQNxvqWeHcCYoTD4BY/ODSRQKRQNCXfhLfnvQY2TNpAGA6w6af+C0AMTR08YMOCbi7B5jBa9n6dlqaNKhnaxEKSEd91191p2PVm/HBApcEdlxDSnbd4gv3x0UYSq3eMbr6HvDa/BQqcCKk1GmvcuRhNLCPWaQuFDxGafYMWDihlPbuwRzvdqsPn6tP04Ne9evAkWD4MVXyb9E3i55JcIhAaT7AhHENEa0pzTdypujQ== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(36840700001)(46966006)(70586007)(508600001)(70206006)(2616005)(7636003)(47076005)(336012)(426003)(356005)(2906002)(44832011)(316002)(5660300002)(1076003)(8676002)(42186006)(186003)(82310400003)(4326008)(36860700001)(36906005)(6916009)(6666004)(36756003)(54906003)(107886003)(6266002)(8936002)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:25:27.6470 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3f9dd9a-cde4-467c-677e-08d9abab7d2b X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT016.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR02MB6831 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org xrt-lib module initialization routine creates /xrt-bus device tree node Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/fpga/Kconfig | 3 +++ drivers/fpga/Makefile | 3 +++ drivers/fpga/xrt/Kconfig | 6 +++++ drivers/fpga/xrt/lib/Kconfig | 16 +++++++++++++ drivers/fpga/xrt/lib/Makefile | 16 +++++++++++++ drivers/fpga/xrt/lib/lib-drv.c | 41 ++++++++++++++++++++++++++++++++ drivers/fpga/xrt/lib/lib-drv.h | 15 ++++++++++++ drivers/fpga/xrt/lib/xrt-bus.dts | 13 ++++++++++ 8 files changed, 113 insertions(+) create mode 100644 drivers/fpga/xrt/Kconfig create mode 100644 drivers/fpga/xrt/lib/Kconfig create mode 100644 drivers/fpga/xrt/lib/Makefile create mode 100644 drivers/fpga/xrt/lib/lib-drv.c create mode 100644 drivers/fpga/xrt/lib/lib-drv.h create mode 100644 drivers/fpga/xrt/lib/xrt-bus.dts diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig index 991b3f361ec9..93ae387c97c5 100644 --- a/drivers/fpga/Kconfig +++ b/drivers/fpga/Kconfig @@ -243,4 +243,7 @@ config FPGA_MGR_VERSAL_FPGA configure the programmable logic(PL). To compile this as a module, choose M here. + +source "drivers/fpga/xrt/Kconfig" + endif # FPGA diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile index 0bff783d1b61..5bd41cf4c7ec 100644 --- a/drivers/fpga/Makefile +++ b/drivers/fpga/Makefile @@ -49,3 +49,6 @@ obj-$(CONFIG_FPGA_DFL_NIOS_INTEL_PAC_N3000) += dfl-n3000-nios.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o + +# XRT drivers for Alveo +obj-$(CONFIG_FPGA_XRT_LIB) += xrt/lib/ diff --git a/drivers/fpga/xrt/Kconfig b/drivers/fpga/xrt/Kconfig new file mode 100644 index 000000000000..04c3bb5aaf4f --- /dev/null +++ b/drivers/fpga/xrt/Kconfig @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Xilinx Alveo FPGA device configuration +# + +source "drivers/fpga/xrt/lib/Kconfig" diff --git a/drivers/fpga/xrt/lib/Kconfig b/drivers/fpga/xrt/lib/Kconfig new file mode 100644 index 000000000000..bb44956d9f94 --- /dev/null +++ b/drivers/fpga/xrt/lib/Kconfig @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# XRT Alveo FPGA device configuration +# + +config FPGA_XRT_LIB + tristate "XRT Alveo Driver Library" + depends on HWMON && PCI && HAS_IOMEM && OF_FLATTREE && OF_OVERLAY + select REGMAP_MMIO + help + Select this option to enable Xilinx XRT Alveo driver library. This + library is core infrastructure of XRT Alveo FPGA drivers which + provides functions for working with device nodes, iteration and + lookup of platform devices, common interfaces for platform devices, + plumbing of function call and ioctls between platform devices and + parent partitions. diff --git a/drivers/fpga/xrt/lib/Makefile b/drivers/fpga/xrt/lib/Makefile new file mode 100644 index 000000000000..f67bb19ef20a --- /dev/null +++ b/drivers/fpga/xrt/lib/Makefile @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2020-2021 Xilinx, Inc. All rights reserved. +# +# Authors: Sonal.Santan@xilinx.com +# + +FULL_XRT_PATH=$(srctree)/$(src)/.. + +obj-$(CONFIG_FPGA_XRT_LIB) += xrt-lib.o + +xrt-lib-objs := \ + lib-drv.o \ + xrt-bus.dtb.o + +ccflags-y := -I$(FULL_XRT_PATH)/include diff --git a/drivers/fpga/xrt/lib/lib-drv.c b/drivers/fpga/xrt/lib/lib-drv.c new file mode 100644 index 000000000000..d4597cd4767f --- /dev/null +++ b/drivers/fpga/xrt/lib/lib-drv.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + * Lizhi Hou + */ + +#include +#include +#include +#include +#include "lib-drv.h" + +static int xrt_bus_ovcs_id; + +static __init int xrt_lib_init(void) +{ + int ret; + + ret = of_overlay_fdt_apply(__dtb_xrt_bus_begin, + __dtb_xrt_bus_end - __dtb_xrt_bus_begin, + &xrt_bus_ovcs_id); + if (ret) + return ret; + + return 0; +} + +static __exit void xrt_lib_fini(void) +{ + of_overlay_remove(&xrt_bus_ovcs_id); +} + +module_init(xrt_lib_init); +module_exit(xrt_lib_fini); + +MODULE_AUTHOR("XRT Team "); +MODULE_DESCRIPTION("Xilinx Alveo IP Lib driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/fpga/xrt/lib/lib-drv.h b/drivers/fpga/xrt/lib/lib-drv.h new file mode 100644 index 000000000000..4bf8a32c7ec5 --- /dev/null +++ b/drivers/fpga/xrt/lib/lib-drv.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + */ + +#ifndef _LIB_DRV_H_ +#define _LIB_DRV_H_ + +extern u8 __dtb_xrt_bus_begin[]; +extern u8 __dtb_xrt_bus_end[]; + +#endif /* _LIB_DRV_H_ */ diff --git a/drivers/fpga/xrt/lib/xrt-bus.dts b/drivers/fpga/xrt/lib/xrt-bus.dts new file mode 100644 index 000000000000..0720de26851b --- /dev/null +++ b/drivers/fpga/xrt/lib/xrt-bus.dts @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/* + * xrt bus node which is overlayed dynamically when xrt-lib is loaded. + */ +&{/} { + xrt-bus { + #address-cells=<2>; + #size-cells=<2>; + }; +}; From patchwork Fri Nov 19 22:24:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86502C433F5 for ; Fri, 19 Nov 2021 22:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235176AbhKSW22 (ORCPT ); Fri, 19 Nov 2021 17:28:28 -0500 Received: from mail-dm6nam10on2068.outbound.protection.outlook.com ([40.107.93.68]:32161 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235190AbhKSW21 (ORCPT ); Fri, 19 Nov 2021 17:28:27 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GYqUT/fbKSJ7rHmt8fVJIAHnGD7RYBnee/d8ZMMJZXO05CQlWwslKfsNV/29R3ZXt511wLEqjT8gP1vApgbyNqpGZb3lkQ+wd3BIJOWom2ApFgI4l2c3QXf3AztOWXyEJPqQBWGJbIlhT5nJaza4oft2vB3WTp5eNo5aF+d8ndDWN4X9rFa7BQhPU1vUTsJfKJYEtjF2Z/f51WGGEkq5vGON7bIJ8qrdy/e1UORbxiP3UPPWqmaKbNr0OgxHXZN6LUGDiwvx1mrX6kClC4vgkymvMKHxRnhFj9IXfPCNa4mHazX1HlVEUlHspkE+CBJF558pODCcXrpqrIPSYDjGZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jWLCgOntJLI8ZMJ0WIcvcS8gElPjBGa5fgiu/SoYYx4=; b=L05/M4zEqZjYvxmUVGp5yF5Bjz6ygPIvOZkoBfapcj111nm/A1IwwqTM9hVLELSzRhJjnh+whddIHynJDpYXG2VMqyjZ8Y4/q2/6L+Yr3TytFN1bZUUGyO3lrVmYJogJR8Zi5RpehqRmuJTT7LFl0MpJbHJ+PVFYFFi82/zOR+3H+SjWhdnKgipF5o0aXw7VYDD6isYW8Xi740/2D82hJQdoWMLnIGzAzXQblHatcpo/1hcIFeykbh7RDU3CMz3VKdMkWmfGFeFERjVRIAIXjfaGxKY1tB//cAhK8qlPZgB7QnJTr8nbY7vsCQI8e8C9FPDDE/3bV3t3RBhJr6oUSw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jWLCgOntJLI8ZMJ0WIcvcS8gElPjBGa5fgiu/SoYYx4=; b=Dty4mDA4ifJeejSJtgEdh9KOl6v81pXPuMW+UgKQjIbK5FDoqKUr8qlnqG/umeRXJLWVDT7Qq2cQvjv6ElVJvVxE3t+YtVjG8auIzCKJwP6tUBcjBaJfBKa9X3TXnUfStUjOr6TzqdJflAWIzcWREyHCg4W36LepqUUHJviMViA= Received: from DM6PR02CA0159.namprd02.prod.outlook.com (2603:10b6:5:332::26) by BY5PR02MB6485.namprd02.prod.outlook.com (2603:10b6:a03:1d2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Fri, 19 Nov 2021 22:25:23 +0000 Received: from DM3NAM02FT032.eop-nam02.prod.protection.outlook.com (2603:10b6:5:332:cafe::89) by DM6PR02CA0159.outlook.office365.com (2603:10b6:5:332::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22 via Frontend Transport; Fri, 19 Nov 2021 22:25:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT032.mail.protection.outlook.com (10.13.5.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:25:21 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:25:15 -0800 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:25:15 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38940 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCJm-0001PJ-Tr; Fri, 19 Nov 2021 14:25:14 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 2F319600139; Fri, 19 Nov 2021 14:24:15 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 6/9] fpga: xrt: xrt bus and device Date: Fri, 19 Nov 2021 14:24:09 -0800 Message-ID: <20211119222412.1092763-7-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc6196ee-b32e-4e6a-f0a4-08d9abab7945 X-MS-TrafficTypeDiagnostic: BY5PR02MB6485: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MZrrvHwPnMV3UdzC0rzxsC4oArnSkHIy7r7WP8E4v7QikAhrwrF7M96Hy6FOHFg1CB+lw8BKeXm2xDywXhyvDS69Abw/pIHWNiO3liXljptkq5SfIzE4Szi86cUQFmZuIy+0rkcPFyjQqxNNl50BkNNgC+WCjo8vPV6gXwMOdpNp1RemKiY/hROAOsJBH6H3azE63VDooYvTqUP6QjAXxR73Zv4ajNUWuJWwmz9Ukn/niYoMhxCVMffjV7VPw9N5PPP51CFjtglC72AeIskTlAJ8B4sxPZRBVR/01qjZV+Umq3IefcUQCgpPfNOVaEMFPKNAgCDGjrdK9ToR4SYPYkGPgyN6w5V4YCI4FKsWKpwFy4NDtfq+Iq6G+cW44PgHt5xu5scTDRbGzEWYE0zGCK1CnafTPN45OzW2mRHvRaCxB/TqCuiu9qOY5nn4xVUwwN6nKvvu1GHowCKiLXHtu4hjCFok2NqzLDW7ACo16XSVWeZz8Y6XGIPWN/7JTTTvuEL7iRqhl+B8rz6vlunzJJFB5sLQnFHMuvZkXCcQmOAue9Ks4ZHabp4P7ohUyT7uUbGmwiE7wjJMlXS2oQRBzYtF3Al6cCpGyCIcEWZrCqlf4kUdzyGPJBv+NM7Heph4I1mBQmr3idnF7qlC+M2nCUXFjfHYQEG55O4go9HHRxkHgB8W3ZNOMzORZCOPi1qVt4gGgKMSfLdvMl6Qp3CAZA== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(36840700001)(46966006)(82310400003)(6666004)(1076003)(36860700001)(26005)(7636003)(2616005)(426003)(70206006)(70586007)(356005)(186003)(316002)(54906003)(2906002)(36906005)(5660300002)(44832011)(42186006)(6266002)(8936002)(107886003)(336012)(8676002)(4326008)(36756003)(47076005)(508600001)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:25:21.0950 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc6196ee-b32e-4e6a-f0a4-08d9abab7945 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT032.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB6485 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org xrt-lib kernel module infrastructure code to add xrt_bus_type, xrt_driver and xrt_device Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/fpga/xrt/lib/lib-drv.c | 192 +++++++++++++++++++++++++++++++++ include/linux/xrt/xdevice.h | 128 ++++++++++++++++++++++ 2 files changed, 320 insertions(+) create mode 100644 include/linux/xrt/xdevice.h diff --git a/drivers/fpga/xrt/lib/lib-drv.c b/drivers/fpga/xrt/lib/lib-drv.c index d4597cd4767f..3ad02a7c2aac 100644 --- a/drivers/fpga/xrt/lib/lib-drv.c +++ b/drivers/fpga/xrt/lib/lib-drv.c @@ -11,10 +11,195 @@ #include #include #include +#include #include "lib-drv.h" static int xrt_bus_ovcs_id; +#define XRT_DRVNAME(drv) ((drv)->driver.name) + +static DEFINE_IDA(xrt_device_ida); + +static int xrt_bus_match(struct device *dev, struct device_driver *drv) +{ + if (of_driver_match_device(dev, drv)) + return 1; + + return 0; +} + +static int xrt_bus_probe(struct device *dev) +{ + struct xrt_driver *xdrv = to_xrt_drv(dev->driver); + struct xrt_device *xdev = to_xrt_dev(dev); + + return xdrv->probe(xdev); +} + +static void xrt_bus_remove(struct device *dev) +{ + struct xrt_driver *xdrv = to_xrt_drv(dev->driver); + struct xrt_device *xdev = to_xrt_dev(dev); + + if (xdrv->remove) + xdrv->remove(xdev); +} + +struct bus_type xrt_bus_type = { + .name = "xrt", + .match = xrt_bus_match, + .probe = xrt_bus_probe, + .remove = xrt_bus_remove, +}; + +int xrt_register_driver(struct xrt_driver *drv) +{ + const char *drvname = XRT_DRVNAME(drv); + int rc = 0; + + /* Initialize dev_t for char dev node. */ + if (drv->file_ops.xsf_ops.open) { + rc = alloc_chrdev_region(&drv->file_ops.xsf_dev_t, 0, + XRT_MAX_DEVICE_NODES, drvname); + if (rc) { + pr_err("failed to alloc dev minor for %s: %d\n", drvname, rc); + return rc; + } + } else { + drv->file_ops.xsf_dev_t = (dev_t)-1; + } + + drv->driver.bus = &xrt_bus_type; + + rc = driver_register(&drv->driver); + if (rc) { + pr_err("register %s xrt driver failed\n", drvname); + if (drv->file_ops.xsf_dev_t != (dev_t)-1) { + unregister_chrdev_region(drv->file_ops.xsf_dev_t, + XRT_MAX_DEVICE_NODES); + } + return rc; + } + + pr_info("%s registered successfully\n", drvname); + + return 0; +} +EXPORT_SYMBOL_GPL(xrt_register_driver); + +void xrt_unregister_driver(struct xrt_driver *drv) +{ + driver_unregister(&drv->driver); + + if (drv->file_ops.xsf_dev_t != (dev_t)-1) + unregister_chrdev_region(drv->file_ops.xsf_dev_t, XRT_MAX_DEVICE_NODES); + + pr_info("%s unregistered successfully\n", XRT_DRVNAME(drv)); +} +EXPORT_SYMBOL_GPL(xrt_unregister_driver); + +static int xrt_dev_get_instance(void) +{ + int ret; + + ret = ida_alloc_range(&xrt_device_ida, 0, 0x7fffffff, GFP_KERNEL); + if (ret < 0) + return ret; + + return ret; +} + +static void xrt_dev_put_instance(int instance) +{ + ida_free(&xrt_device_ida, instance); +} + +static void xrt_device_release(struct device *dev) +{ + struct xrt_device *xdev = container_of(dev, struct xrt_device, dev); + + kfree(xdev); +} + +void xrt_device_unregister(struct xrt_device *xdev) +{ + if (xdev->state == XRT_DEVICE_STATE_ADDED) + device_del(&xdev->dev); + + vfree(xdev->sdev_data); + kfree(xdev->resource); + + if (xdev->instance != XRT_INVALID_DEVICE_INST) + xrt_dev_put_instance(xdev->instance); + + if (xdev->dev.of_node) + of_node_put(xdev->dev.of_node); + + if (xdev->dev.release == xrt_device_release) + put_device(&xdev->dev); +} + +struct xrt_device * +xrt_device_register(struct device *parent, struct device_node *dn, + struct resource *res, u32 res_num, + void *pdata, size_t data_sz) +{ + struct xrt_device *xdev = NULL; + int ret; + + xdev = kzalloc(sizeof(*xdev), GFP_KERNEL); + if (!xdev) + return NULL; + xdev->instance = XRT_INVALID_DEVICE_INST; + + /* Obtain dev instance number. */ + ret = xrt_dev_get_instance(); + if (ret < 0) { + dev_err(parent, "failed get instance, ret %d", ret); + goto fail; + } + + xdev->instance = ret; + xdev->name = dn->full_name; + device_initialize(&xdev->dev); + xdev->dev.release = xrt_device_release; + xdev->dev.parent = parent; + + xdev->dev.bus = &xrt_bus_type; + dev_set_name(&xdev->dev, "%s.%d", xdev->name, xdev->instance); + + if (res_num > 0) { + xdev->num_resources = res_num; + xdev->resource = kmemdup(res, sizeof(*res) * res_num, GFP_KERNEL); + if (!xdev->resource) + goto fail; + } + + if (data_sz > 0) { + xdev->sdev_data = vzalloc(data_sz); + if (!xdev->sdev_data) + goto fail; + + memcpy(xdev->sdev_data, pdata, data_sz); + } + + ret = device_add(&xdev->dev); + if (ret) { + dev_err(parent, "failed add device, ret %d", ret); + goto fail; + } + xdev->state = XRT_DEVICE_STATE_ADDED; + xdev->dev.of_node = of_node_get(dn); + + return xdev; + +fail: + xrt_device_unregister(xdev); + kfree(xdev); + + return NULL; +} + static __init int xrt_lib_init(void) { int ret; @@ -25,11 +210,18 @@ static __init int xrt_lib_init(void) if (ret) return ret; + ret = bus_register(&xrt_bus_type); + if (ret) { + of_overlay_remove(&xrt_bus_ovcs_id); + return ret; + } + return 0; } static __exit void xrt_lib_fini(void) { + bus_unregister(&xrt_bus_type); of_overlay_remove(&xrt_bus_ovcs_id); } diff --git a/include/linux/xrt/xdevice.h b/include/linux/xrt/xdevice.h new file mode 100644 index 000000000000..0b3fec9ae598 --- /dev/null +++ b/include/linux/xrt/xdevice.h @@ -0,0 +1,128 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Lizhi Hou + */ + +#ifndef _XRT_DEVICE_H_ +#define _XRT_DEVICE_H_ + +#include +#include +#include + +#define XRT_MAX_DEVICE_NODES 128 +#define XRT_INVALID_DEVICE_INST (XRT_MAX_DEVICE_NODES + 1) + +enum { + XRT_DEVICE_STATE_NONE = 0, + XRT_DEVICE_STATE_ADDED +}; + +/* + * struct xrt_device - represent an xrt device on xrt bus + * + * dev: generic device interface. + * id: id of the xrt device. + */ +struct xrt_device { + struct device dev; + const char *name; + u32 instance; + u32 state; + u32 num_resources; + struct resource *resource; + void *sdev_data; +}; + +/* + * If populated by xrt device driver, infra will handle the mechanics of + * char device (un)registration. + */ +enum xrt_dev_file_mode { + /* Infra create cdev, default file name */ + XRT_DEV_FILE_DEFAULT = 0, + /* Infra create cdev, need to encode inst num in file name */ + XRT_DEV_FILE_MULTI_INST, + /* No auto creation of cdev by infra, leaf handles it by itself */ + XRT_DEV_FILE_NO_AUTO, +}; + +struct xrt_dev_file_ops { + const struct file_operations xsf_ops; + dev_t xsf_dev_t; + const char *xsf_dev_name; + enum xrt_dev_file_mode xsf_mode; +}; + +/* + * this struct define the endpoints belong to the same xrt device + */ +struct xrt_dev_ep_names { + const char *ep_name; + const char *compat; +}; + +/* + * struct xrt_driver - represent a xrt device driver + * + * driver: driver model structure. + * id_table: pointer to table of device IDs the driver is interested in. + * { } member terminated. + * probe: mandatory callback for device binding. + * remove: callback for device unbinding. + */ +struct xrt_driver { + struct device_driver driver; + struct xrt_dev_file_ops file_ops; + + /* + * Subdev driver callbacks populated by subdev driver. + */ + int (*probe)(struct xrt_device *xrt_dev); + void (*remove)(struct xrt_device *xrt_dev); + /* + * If leaf_call is defined, these are called by other leaf drivers. + * Note that root driver may call into leaf_call of a group driver. + */ + int (*leaf_call)(struct xrt_device *xrt_dev, u32 cmd, void *arg); +}; + +#define to_xrt_dev(d) container_of(d, struct xrt_device, dev) +#define to_xrt_drv(d) container_of(d, struct xrt_driver, driver) +/* + * module_xrt_driver() - Helper macro for drivers that don't do + * anything special in module init/exit. + */ +#define module_xrt_driver(__xrt_driver) \ + module_driver(__xrt_driver, xrt_register_driver, \ + xrt_unregister_driver) + +static inline void *xrt_get_drvdata(const struct xrt_device *xdev) +{ + return dev_get_drvdata(&xdev->dev); +} + +static inline void xrt_set_drvdata(struct xrt_device *xdev, void *data) +{ + dev_set_drvdata(&xdev->dev, data); +} + +static inline void *xrt_get_xdev_data(struct device *dev) +{ + struct xrt_device *xdev = to_xrt_dev(dev); + + return xdev->sdev_data; +} + +struct xrt_device * +xrt_device_register(struct device *parent, struct device_node *dn, + struct resource *res, u32 res_num, + void *pdata, size_t data_sz); +void xrt_device_unregister(struct xrt_device *xdev); +int xrt_register_driver(struct xrt_driver *drv); +void xrt_unregister_driver(struct xrt_driver *drv); + +#endif /* _XRT_DEVICE_H_ */ From patchwork Fri Nov 19 22:24:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EBDFC433EF for ; Fri, 19 Nov 2021 22:25:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235914AbhKSW2u (ORCPT ); Fri, 19 Nov 2021 17:28:50 -0500 Received: from mail-bn8nam11on2060.outbound.protection.outlook.com ([40.107.236.60]:57281 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235824AbhKSW2r (ORCPT ); Fri, 19 Nov 2021 17:28:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=inlXoMCtbvFpf2zADWawS1DI12TOpzsJBs/QYLsaYvtl6EN6wp39iPf2efLmWhdazAiPAEmjM9pDXs5DYjlL8wmje4ag3z3GfLfMkwEyK0hhRMlP/FmHs3wwV+lpyFED/y0P9/FnSpdp+FcBzocjDB7o1sYJc/H7Y7MVbgDZ2gplNWGU5er0RhoI76lS8/nrXT3Oq1CnNAQOgyRLfCodrfv7bFJegtcpYHr0K5JiBu599dXFN076JyVvsXQCkQKXDr3MQdX4PojV36rJIXJ5i3BRP2mY5y7XmEZDrSypcvBiFMXKtphHOLdec3yJuJ5kCg+nGMNmCgQeyzdL21+BVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tSUAgszNk8jNWzaSQkn0mEGh7RDfYQh4C6ZuMbWeU4c=; b=KignzY5L1Vqidw/0AhDl029vouCTwBrOHlWjqUx4wisyZAmctq/a/+wRTs1RAS6py9lA37CSEYqccdgN6Ew2x+yeW08BgsBdwP16wZ+6mpDmRHj3R6h2YghFk+Il4ihOO/b5JYOEYGB3s5AlgZrFbcjFdKt5zpFXCIFEl6PSq2rHVloaWPBfGn+nq1HTzsNT+cMK0BJPVEJ/CSRdQFni03e7cE2vXvLeHbUB3b4g4n7BQedFsHpvmzxmLRwHgyEZpPHdwY7jVI2FZaCys3qZN8k7C28vR0FXSUWLOqDH3i5r5xb9lUFX5VgtVLCKWZ4HQK2LkJVgZ1EB9SnypZYvuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tSUAgszNk8jNWzaSQkn0mEGh7RDfYQh4C6ZuMbWeU4c=; b=j0KiXbsfcrONwWaRdkr1485niMGqDt2VGDRbMYSc/0fmNObs6YpQN+RO0AkkfNeGGa03OgRv6nyx3wPZ6csen94wtKBapZFbWQyJuLmizlub8iAOWHIV0OClNOTqswoDqZh3yoTMS9/KME2dePhvm9eLfio2LywRQfuQz3RIny8= Received: from DM5PR21CA0039.namprd21.prod.outlook.com (2603:10b6:3:ed::25) by BN7PR02MB5283.namprd02.prod.outlook.com (2603:10b6:408:30::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27; Fri, 19 Nov 2021 22:25:42 +0000 Received: from DM3NAM02FT060.eop-nam02.prod.protection.outlook.com (2603:10b6:3:ed:cafe::8f) by DM5PR21CA0039.outlook.office365.com (2603:10b6:3:ed::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.13 via Frontend Transport; Fri, 19 Nov 2021 22:25:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT060.mail.protection.outlook.com (10.13.4.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:25:42 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:25:39 -0800 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:25:39 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38944 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCKB-0001QY-0M; Fri, 19 Nov 2021 14:25:39 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 53C3B60014E; Fri, 19 Nov 2021 14:24:15 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 7/9] fpga: xrt: lib-xrt xroot APIs Date: Fri, 19 Nov 2021 14:24:10 -0800 Message-ID: <20211119222412.1092763-8-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 23c55147-b12b-41b4-64b1-08d9abab85d9 X-MS-TrafficTypeDiagnostic: BN7PR02MB5283: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:81; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5pTntAnVN+O9e9zgdYdifrYrI6eG/nk6zeT0NopWrUV+OAOJrv4V0VYgmgeq52tDtFbe6tsl3dlTDW97Gezkqr+BKpXJyHN1GQGMLd1sGJvQkLZgAgStoe1HVJWSgTWllhU4BBUJParkElChHXZvX3NuuTbFccqh8LlQSQtPAQ12qf90BgMFi/IHARB6jyTUQ5yIaBYZgFrPrVnP5PnlhtxOI9W6Jej5u/nv9o4/IcA59+gtUQAZjyqApxJ5rKjMwSBdrl9piHB0XH/ylAeE1UNKp3Hr3yB/OAjfO3MzNlGwuXCyqLlklrW8aDX1eVDr/YT/dLL3A30BKktRjP6RoNBkTujIZO0cTJ5wMfFSZkjtaUdGDOZaNcYGWE7FdMxveYtxyZQ6e7sy+wr8gkFbuqyMQ7F7jHEAX7x5shp+zbmT6+RYTExpKTou53HiTNsBBhJRo3oQOwlQSu7q9eHr1eXyqLFsM71ZmAikr/CIS09x7R7zC/bQWgNnPP/tAiFpwZizOYVaYeBHFkh5zhLy4891CxikJzo1T58bOMbr8wmXKqYWcLgoQER8yKsgJi4ZDeQoBAzLalmlNwBnc4rdKn0KgTNsslTsIah47kxJeHtQBe6BldVRLoeizwChK3uBmUS3E/09G2M7p3XsSf41kFDf0V4DptW1EkKyVaT6434VyS4ua1QhW4a65IAo+hnIWzNPM2zLn0hEV/JW1QmIBw== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(36840700001)(46966006)(6666004)(6266002)(47076005)(8676002)(2616005)(426003)(36860700001)(7636003)(336012)(5660300002)(36756003)(44832011)(6916009)(70586007)(356005)(42186006)(508600001)(8936002)(70206006)(36906005)(1076003)(107886003)(316002)(186003)(26005)(54906003)(2906002)(4326008)(82310400003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:25:42.2090 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23c55147-b12b-41b4-64b1-08d9abab85d9 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT060.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB5283 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org lib-xrt infrastructure code to create xrt group device. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/fpga/xrt/include/xroot.h | 30 +++++ drivers/fpga/xrt/lib/Makefile | 1 + drivers/fpga/xrt/lib/xroot.c | 210 +++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 drivers/fpga/xrt/include/xroot.h create mode 100644 drivers/fpga/xrt/lib/xroot.c diff --git a/drivers/fpga/xrt/include/xroot.h b/drivers/fpga/xrt/include/xroot.h new file mode 100644 index 000000000000..6ea1b64b3ae3 --- /dev/null +++ b/drivers/fpga/xrt/include/xroot.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + */ + +#ifndef _XRT_ROOT_H_ +#define _XRT_ROOT_H_ + +struct xroot_range { + __be32 child_addr[3]; + __be32 parent_addr[2]; + __be32 child_size[2]; +}; + +struct xroot_info { + u32 addr; + int num_range; + struct xroot_range *ranges; +}; + +int xroot_probe(struct device *dev, struct xroot_info *info, void **root); +void xroot_remove(void *root); + +int xroot_create_group(void *xr, void *dtb); +void xroot_destroy_group(void *xr, u32 grp_id); + +#endif /* _XRT_ROOT_H_ */ diff --git a/drivers/fpga/xrt/lib/Makefile b/drivers/fpga/xrt/lib/Makefile index f67bb19ef20a..fd2af2cbd1da 100644 --- a/drivers/fpga/xrt/lib/Makefile +++ b/drivers/fpga/xrt/lib/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_FPGA_XRT_LIB) += xrt-lib.o xrt-lib-objs := \ lib-drv.o \ + xroot.o \ xrt-bus.dtb.o ccflags-y := -I$(FULL_XRT_PATH)/include diff --git a/drivers/fpga/xrt/lib/xroot.c b/drivers/fpga/xrt/lib/xroot.c new file mode 100644 index 000000000000..34489a0cc10b --- /dev/null +++ b/drivers/fpga/xrt/lib/xroot.c @@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Xilinx Alveo FPGA Root Functions + * + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + * Lizhi Hou + */ + +#include +#include +#include +#include +#include +#include "xroot.h" + +#define xroot_err(xr, fmt, args...) dev_err((xr)->dev, "%s: " fmt, __func__, ##args) +#define xroot_warn(xr, fmt, args...) dev_warn((xr)->dev, "%s: " fmt, __func__, ##args) +#define xroot_info(xr, fmt, args...) dev_info((xr)->dev, "%s: " fmt, __func__, ##args) +#define xroot_dbg(xr, fmt, args...) dev_dbg((xr)->dev, "%s: " fmt, __func__, ##args) + +struct xroot { + struct device *dev; + struct list_head groups; + u32 addr; + struct xroot_range *ranges; + int num_range; + struct ida grp_ida; +}; + +struct xroot_group { + struct list_head node; + struct xroot *xr; + struct xrt_device *grp_dev; + struct property ranges; + struct of_changeset chgset; + bool chgset_applied; + void *dn_mem; + char *name; + int id; +}; + +#define XRT_GROUP "xrt-group" +#define MAX_GRP_NAME_LEN 64 + +static void xroot_cleanup_group(struct xroot_group *grp) +{ + if (grp->grp_dev) + xrt_device_unregister(grp->grp_dev); + if (grp->chgset_applied) + of_changeset_revert(&grp->chgset); + of_changeset_destroy(&grp->chgset); + + if (grp->id >= 0) + ida_free(&grp->xr->grp_ida, grp->id); + kfree(grp->dn_mem); + kfree(grp->name); +} + +void xroot_destroy_group(void *root, u32 grp_id) +{ + struct xroot *xr = root; + struct xroot_group *grp; + + list_for_each_entry(grp, &xr->groups, node) { + if (grp->id == grp_id) + break; + } + if (list_entry_is_head(grp, &xr->groups, node)) + return; + + list_del(&grp->node); + + xroot_cleanup_group(grp); + kfree(grp); +} +EXPORT_SYMBOL_GPL(xroot_destroy_group); + +/* + * Create XRT group device. + * + * Unflatten the device tree blob attached to the group and + * overlay the device nodes under /xrt-bus. Then create group device + * and link it to device node. + */ +int xroot_create_group(void *root, void *dtb) +{ + struct device_node *dn, *bus, *grp_dn; + struct xroot *xr = root; + struct xroot_group *grp; + int ret; + + grp = kzalloc(sizeof(*grp), GFP_KERNEL); + if (!grp) + return -ENOMEM; + + bus = of_find_node_by_path("/xrt-bus"); + if (!bus) { + kfree(grp); + return -EINVAL; + } + grp->xr = xr; + of_changeset_init(&grp->chgset); + + ret = ida_alloc(&xr->grp_ida, GFP_KERNEL); + if (ret < 0) + goto failed; + + grp->id = ret; + + grp->name = kzalloc(MAX_GRP_NAME_LEN, GFP_KERNEL); + if (!grp->name) { + ret = -ENOMEM; + goto failed; + } + snprintf(grp->name, MAX_GRP_NAME_LEN, "%s@%x,%x", XRT_GROUP, xr->addr, grp->id); + + grp->dn_mem = of_fdt_unflatten_tree(dtb, NULL, &grp_dn); + if (!grp->dn_mem) { + ret = -EINVAL; + goto failed; + } + + of_node_get(grp_dn); + grp_dn->full_name = grp->name; + grp_dn->parent = bus; + for (dn = grp_dn; dn; dn = of_find_all_nodes(dn)) + of_changeset_attach_node(&grp->chgset, dn); + + grp->ranges.name = "ranges"; + grp->ranges.length = xr->num_range * sizeof(*xr->ranges); + grp->ranges.value = xr->ranges; + ret = of_changeset_add_property(&grp->chgset, grp_dn, &grp->ranges); + if (ret) + goto failed; + + ret = of_changeset_apply(&grp->chgset); + if (ret) + goto failed; + grp->chgset_applied = true; + + of_node_put(bus); + bus = NULL; + + grp->grp_dev = xrt_device_register(xr->dev, grp_dn, NULL, 0, NULL, 0); + if (!grp->grp_dev) { + ret = -EFAULT; + goto failed; + } + + if (device_attach(&grp->grp_dev->dev) != 1) { + ret = -EFAULT; + xroot_err(xr, "failed to attach"); + goto failed; + } + + list_add(&grp->node, &xr->groups); + + return grp->id; + +failed: + if (bus) + of_node_put(bus); + xroot_cleanup_group(grp); + return ret; +} +EXPORT_SYMBOL_GPL(xroot_create_group); + +int xroot_probe(struct device *dev, struct xroot_info *info, void **root) +{ + struct xroot *xr = NULL; + + dev_info(dev, "%s: probing...", __func__); + + xr = devm_kzalloc(dev, sizeof(*xr), GFP_KERNEL); + if (!xr) + return -ENOMEM; + + xr->dev = dev; + INIT_LIST_HEAD(&xr->groups); + + xr->addr = info->addr; + xr->num_range = info->num_range; + xr->ranges = devm_kzalloc(dev, sizeof(*info->ranges) * info->num_range, GFP_KERNEL); + if (!xr->ranges) + return -ENOMEM; + + memcpy(&xr->ranges, info->ranges, sizeof(*info->ranges) * info->num_range); + ida_init(&xr->grp_ida); + + *root = xr; + return 0; +} +EXPORT_SYMBOL_GPL(xroot_probe); + +void xroot_remove(void *root) +{ + struct xroot *xr = (struct xroot *)root; + struct xroot_group *grp, *tmp; + + xroot_info(xr, "leaving..."); + list_for_each_entry_safe(grp, tmp, &xr->groups, node) { + list_del(&grp->node); + xroot_cleanup_group(grp); + kfree(grp); + } +} +EXPORT_SYMBOL_GPL(xroot_remove); From patchwork Fri Nov 19 22:24:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D0DEC433F5 for ; Fri, 19 Nov 2021 22:26:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236139AbhKSW3F (ORCPT ); Fri, 19 Nov 2021 17:29:05 -0500 Received: from mail-dm6nam12on2065.outbound.protection.outlook.com ([40.107.243.65]:20472 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236006AbhKSW3A (ORCPT ); Fri, 19 Nov 2021 17:29:00 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gv4iPE1cKXmsApq5ZfYOqHuVQ37phcRuYWCGg4THW9jIKm5WAf32fXaHLFDA6/S2wExtWRY+EQv2GmaT4+oHYd2Qso+KmF1fXRlPcrDPtWmCssToQ8jnC8TcXjzK5D9pSrEm0V0Fu4ZxvE2izxb4s3YuwnjsMBb+jRCvjkDGOcY1q/alY9MviQh2dLYCMGkV0DeRxafI73YYeey0BQzuB0EB4Q7fuAg323UOn3VX7fQquJ/rU4e9AjQFrLP2y/w3tz2R4SMmY9d26NZsELmL55koDOnPXuXhCI/WRSULzGvnC5bjiS2evNbGwQMz+rgKJSzdWPo9qUg1hD2A7OGYBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yLUPyaD2WNOJF2FSI+3UYA5mUG/m0S9MTFkcQnHq1JQ=; b=P0HyUtm7yxXQEWNtMkiEjJ/e56SvOeOlY9EzAqQlKJopQxTgq4mrzJYgm6i/bvfiFH4YAaAfGuSyHEvsg8H6S25DUn5rg7BPiIKs/SKn4HRvP98BpiaVWFga5Zde3YNZd1aoYNZw63xO2iteamMLXG8xhAzCKsuEUIISP1SOZSi8/isa7pMTzFfzLs5U80x+4NlcejFTBzO/qi/48iKJhqVl5Zlzysw45jajXE4J8RZxZCtXEl8GfKEQ/reNbuCQMyClVQNMc3HFhcF7zJiRpziZPzTJK5LP3qtj7PXTCO7WhzgD1qULv520EDdQpdOuIdOH1mGRNlnIRf+Rsf7Tng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yLUPyaD2WNOJF2FSI+3UYA5mUG/m0S9MTFkcQnHq1JQ=; b=e8I97U6oCBZFXoX2iLlPsSv6buuwY8nCvfKRpm5KQPPioclESous8zmOVPvK1BCTs0cvqyCni6LPMhFhSyMktgUnJC633xDwnWmgbb47kwjUUbT+0eFac4FKuqNbDP9moj82st0c9tNy94KDAGqEZiClu23pDs862rIVEbbClT8= Received: from DM6PR07CA0051.namprd07.prod.outlook.com (2603:10b6:5:74::28) by BN7PR02MB5347.namprd02.prod.outlook.com (2603:10b6:408:25::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Fri, 19 Nov 2021 22:25:55 +0000 Received: from DM3NAM02FT029.eop-nam02.prod.protection.outlook.com (2603:10b6:5:74:cafe::7b) by DM6PR07CA0051.outlook.office365.com (2603:10b6:5:74::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:25:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT029.mail.protection.outlook.com (10.13.4.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:25:55 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:25:51 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:25:51 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38946 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCKN-000Aik-1z; Fri, 19 Nov 2021 14:25:51 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 68775600150; Fri, 19 Nov 2021 14:24:15 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 8/9] fpga: xrt: xrt group device driver Date: Fri, 19 Nov 2021 14:24:11 -0800 Message-ID: <20211119222412.1092763-9-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e2c12089-0f75-42f5-1e73-08d9abab8daa X-MS-TrafficTypeDiagnostic: BN7PR02MB5347: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:199; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vsjgjzu2Ih3UlFBm/wDsy3MHqsYoV++wYtS3WUp/IMCpL8K2dsFLm7ShD/UUHXSgpN841L59pZpr0XJ+DoCE/WARa/ymsePdQ265mBFbDFbfDU+HX4+YFfH/3mtOx6okxyimYCVbOqmxV918BDcnjRgiVGkyJAt63yn5JFkXnBpW/jv3Ddpviydq+245ZePD8brcSF+oLgdXm8yh909FA/PdwCATcIkw28F4nmJYMhmdXBbChwvae4pzqdl062UGhwjhSSHsgMSKsafFn+OAFEz9bnflHi/k9L/LCbOfDd2XUVL7k4DNSaN8LWWMya5yVEfkeUDFol7Ohm56lkF04SltO4DzeYymWy1GrzlSYxwnGIM+7BG4Q4sB1xPKR/ffPgRuZwHV0IJKKpsPWIVC7U9wXh9VTsXZKab1OOrKg/s6PBjRJ+woJPD/y0603KAN4fRWqU/rG5bluyIpoo/cKKISP5MWaQpZFiIRhQR4uj7ojsPlcgxh2YidaTQja44bBrobR0tQGqpedsstgoeKqPc7MfubzmIJmKn2/4oNXmNY2mKZBlLdzhvuXyVfwHsg1nbxuNhwx6olL2aesHJbLif8fGwM/eYjhXTRObEAgFSqOZLwWCU2wZomNO4xuPLuyN68Yt3DYHd3FOGlDJ1sX0CMDPN9gqsJ/tXThvzn53yQ3JB/VuSjY6M9QuzHN1YRsuk3vLlAe2bF9RRdCBHWKg== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(36840700001)(46966006)(2616005)(1076003)(6266002)(8676002)(70206006)(6666004)(426003)(82310400003)(70586007)(186003)(7636003)(8936002)(107886003)(54906003)(36906005)(316002)(5660300002)(508600001)(356005)(47076005)(26005)(42186006)(6916009)(336012)(44832011)(2906002)(36860700001)(4326008)(36756003)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:25:55.3219 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2c12089-0f75-42f5-1e73-08d9abab8daa X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT029.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB5347 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org group driver that manages life cycle of a bunch of leaf driver instances. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/fpga/xrt/lib/Makefile | 1 + drivers/fpga/xrt/lib/group.c | 94 ++++++++++++++++++++++++++++++++++ drivers/fpga/xrt/lib/lib-drv.c | 18 ++++++- drivers/fpga/xrt/lib/lib-drv.h | 13 +++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 drivers/fpga/xrt/lib/group.c diff --git a/drivers/fpga/xrt/lib/Makefile b/drivers/fpga/xrt/lib/Makefile index fd2af2cbd1da..abf7d5341a69 100644 --- a/drivers/fpga/xrt/lib/Makefile +++ b/drivers/fpga/xrt/lib/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_FPGA_XRT_LIB) += xrt-lib.o xrt-lib-objs := \ lib-drv.o \ xroot.o \ + group.o \ xrt-bus.dtb.o ccflags-y := -I$(FULL_XRT_PATH)/include diff --git a/drivers/fpga/xrt/lib/group.c b/drivers/fpga/xrt/lib/group.c new file mode 100644 index 000000000000..feafc45ddb52 --- /dev/null +++ b/drivers/fpga/xrt/lib/group.c @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Xilinx Alveo FPGA Group Driver + * + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + */ + +#include +#include +#include +#include +#include "lib-drv.h" +#include "xroot.h" + +#define XRT_GRP "xrt_group" + +struct xgroup_leaf { + struct list_head node; + struct xrt_device *leaf_dev; +}; + +struct xgroup { + struct xrt_device *xdev; + struct list_head leaves; +}; + +static int xrt_grp_probe(struct xrt_device *xdev) +{ + struct xgroup_leaf *leaf; + struct xgroup *xg = NULL; + struct device_node *dn; + + dev_info(&xdev->dev, "probing\n"); + + xg = devm_kzalloc(&xdev->dev, sizeof(*xg), GFP_KERNEL); + if (!xg) + return -ENOMEM; + + xg->xdev = xdev; + INIT_LIST_HEAD(&xg->leaves); + xrt_set_drvdata(xdev, xg); + + for_each_child_of_node(xdev->dev.of_node, dn) { + leaf = kmalloc(sizeof(*leaf), GFP_KERNEL); + if (!leaf) + break; + + leaf->leaf_dev = xrt_device_register(&xdev->dev, dn, NULL, 0, NULL, 0); + if (!leaf->leaf_dev) { + kfree(leaf); + continue; + } + list_add(&leaf->node, &xg->leaves); + } + + return 0; +} + +static void xrt_grp_remove(struct xrt_device *xdev) +{ + struct xgroup *xg = xrt_get_drvdata(xdev); + struct xgroup_leaf *leaf, *tmp; + + list_for_each_entry_safe(leaf, tmp, &xg->leaves, node) { + list_del(&leaf->node); + xrt_device_unregister(leaf->leaf_dev); + kfree(leaf); + } +} + +static int xrt_grp_leaf_call(struct xrt_device *xdev, u32 cmd, void *arg) +{ + return 0; +} + +static const struct of_device_id group_match[] = { + { .compatible = "xlnx,xrt-group" }, + { } +}; + +static struct xrt_driver xrt_group_driver = { + .driver = { + .name = XRT_GRP, + .of_match_table = group_match, + }, + .probe = xrt_grp_probe, + .remove = xrt_grp_remove, + .leaf_call = xrt_grp_leaf_call, +}; + +XRT_LEAF_INIT_FINI_FUNC(group); diff --git a/drivers/fpga/xrt/lib/lib-drv.c b/drivers/fpga/xrt/lib/lib-drv.c index 3ad02a7c2aac..c9c654f692d4 100644 --- a/drivers/fpga/xrt/lib/lib-drv.c +++ b/drivers/fpga/xrt/lib/lib-drv.c @@ -200,9 +200,17 @@ xrt_device_register(struct device *parent, struct device_node *dn, return NULL; } +/* + * Leaf driver's module init/fini callbacks. This is not a open infrastructure for dynamic + * plugging in drivers. All drivers should be statically added. + */ +static void (*leaf_init_fini_cbs[])(bool) = { + group_leaf_init_fini, +}; + static __init int xrt_lib_init(void) { - int ret; + int ret, i; ret = of_overlay_fdt_apply(__dtb_xrt_bus_begin, __dtb_xrt_bus_end - __dtb_xrt_bus_begin, @@ -216,11 +224,19 @@ static __init int xrt_lib_init(void) return ret; } + for (i = 0; i < ARRAY_SIZE(leaf_init_fini_cbs); i++) + leaf_init_fini_cbs[i](true); + return 0; } static __exit void xrt_lib_fini(void) { + int i; + + for (i = 0; i < ARRAY_SIZE(leaf_init_fini_cbs); i++) + leaf_init_fini_cbs[i](false); + bus_unregister(&xrt_bus_type); of_overlay_remove(&xrt_bus_ovcs_id); } diff --git a/drivers/fpga/xrt/lib/lib-drv.h b/drivers/fpga/xrt/lib/lib-drv.h index 4bf8a32c7ec5..02d9b3731351 100644 --- a/drivers/fpga/xrt/lib/lib-drv.h +++ b/drivers/fpga/xrt/lib/lib-drv.h @@ -9,6 +9,19 @@ #ifndef _LIB_DRV_H_ #define _LIB_DRV_H_ +/* Module's init/fini routines for leaf driver in xrt-lib module */ +#define XRT_LEAF_INIT_FINI_FUNC(name) \ +void name##_leaf_init_fini(bool init) \ +{ \ + if (init) \ + xrt_register_driver(&xrt_##name##_driver); \ + else \ + xrt_unregister_driver(&xrt_##name##_driver); \ +} + +/* Module's init/fini routines for leaf driver in xrt-lib module */ +void group_leaf_init_fini(bool init); + extern u8 __dtb_xrt_bus_begin[]; extern u8 __dtb_xrt_bus_end[]; From patchwork Fri Nov 19 22:24:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12629637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17D04C433FE for ; Fri, 19 Nov 2021 22:26:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236085AbhKSW3P (ORCPT ); Fri, 19 Nov 2021 17:29:15 -0500 Received: from mail-bn7nam10on2045.outbound.protection.outlook.com ([40.107.92.45]:14176 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236249AbhKSW3N (ORCPT ); Fri, 19 Nov 2021 17:29:13 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JsG8fufoL2y9aOLRmvrPLnmx7BabbPkPKQi2XNE8RFe8RrKHFAlI3ISXDFBS5s1yGphnaIl6bRYOJcYe04PQbLJjJ1YWZHZWUFu7rEV1JNtDggdt6QUvH/S15mvl/5tA/rUlXQa3VBha9TwgY+xErDEfsG46XBjfsLcdj6Mr1BxHh7hgdNHTDH/c21UvVD4jaafr6SztY3v43GqvMDnX1ztMIVW+Wr9fkz8zYjbRhdsCGFHTd2a1QzD2Sr2d/rX72+z7wbRZNcVmcvFxQmxoQso82JH66VsxnrEv2JHDOzoUkvTrJSOoF+fIQN8oaKQkkoFHroBWQFndrb5LSFsAMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=k1Ey3/POUl+NF+ZRAhx6QOTyuuqjqPz/mTLghsQ4G80=; b=b74kMD2YY2FVrtJ5lOLbiy8n1pM9XCg0KOt1ovXeh06+qSRaO271t4omLYg0QxJGxyHNTYC4vPDIDVv+ggK596VxNe/eYqTqHM/ncrsqSlfYpPuM7Pz/v1rKoQCJmCIAMHr7h34NiFamItR/djAYeuN2W+hIJo/el1BZhpXpYYXdXcd4sav5D/PG4FZ/UDdtkDLmFsW8gDgfECYjSz7iKORT6cr543FZLcMmHYN2Kd4sfKl43xK+QU28Z+XpnDMKPhwZX44UPT0VskyRVrLkyX0iCwf54+uNy78iOqF5flxUwntnO7YVw4qsmgu91pKI0He/mRBvfQWJbQ6YXZPHzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=infradead.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k1Ey3/POUl+NF+ZRAhx6QOTyuuqjqPz/mTLghsQ4G80=; b=ScCP4lWfbFNkvoaUsnSmMqFXBAOn6iLnVPwQRFj4eyuZ5FgtUszRaGxyZNOztvRNtssNUamoSRMxZd+C/uk3Q8W05s4NPix0UadW/onOQ8V2zUJIrkRSBG1WMahbUTscLiUAgUfHKCIhOrfNnfJT0KDi2ibaziNelGq+bY5XGp4= Received: from DM5PR06CA0038.namprd06.prod.outlook.com (2603:10b6:3:5d::24) by DM5PR02MB3895.namprd02.prod.outlook.com (2603:10b6:4:b9::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Fri, 19 Nov 2021 22:26:07 +0000 Received: from DM3NAM02FT021.eop-nam02.prod.protection.outlook.com (2603:10b6:3:5d:cafe::94) by DM5PR06CA0038.outlook.office365.com (2603:10b6:3:5d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21 via Frontend Transport; Fri, 19 Nov 2021 22:26:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT021.mail.protection.outlook.com (10.13.4.249) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 22:26:07 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Fri, 19 Nov 2021 14:26:03 -0800 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Fri, 19 Nov 2021 14:26:03 -0800 Envelope-to: dwmw2@infradead.org, mdf@kernel.org, robh@kernel.org, trix@redhat.com, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Received: from [172.19.72.93] (port=38948 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1moCKZ-0001Rw-3U; Fri, 19 Nov 2021 14:26:03 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 7F8BF600152; Fri, 19 Nov 2021 14:24:15 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V2 XRT Alveo Infrastructure 9/9] fpga: xrt: management physical function driver Date: Fri, 19 Nov 2021 14:24:12 -0800 Message-ID: <20211119222412.1092763-10-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211119222412.1092763-1-lizhi.hou@xilinx.com> References: <20211119222412.1092763-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe0d756e-820f-46dd-b607-08d9abab94be X-MS-TrafficTypeDiagnostic: DM5PR02MB3895: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:85; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W1U+1AOBcd1toZrlm1aNtKe61hw9YfAG/OG3oSWp1pHPoKdSpweIxSc2ctrjUCsp/osaAThCe9P+voWUVXS21DezfYBla0P5LmFodoDOySGvPXALIEL7UsRajTGFhzJzZiQv+usyY6EF0poI7MrbkuSH0cJtP+aV6qoYk4eit9Cldshz2pRTpY4szyo46cPaItWNR2WqXMJfRv/+KE8bVdoQClwcjTAEUxCZ43HHZp2Gj44P4lPuaERWMVOnYeGExkPB9y0uNoPquWaoDGPhQmuhyLO7vzDdfsNZ8mL+WcaEjmGBp6UPZkIxLkYLJkjzWDdel1HrNNmxsg/dksHUKH3J2UIaH4fQ6y+re17GUEgMSP+8Ni461CW8JGIFFsKX1S5B2m31JESLnfEYmoCORRZhtCwz6qpS3AEFuCy1aWVcxD2VzbnHC9aNtW1ycVbx3++ZCoynuctApKHetiTPQY8qs4pUKd6R0ArPw7Pevd/oJlCnFQD/rZSmBlpO6a2EloXgKYWENAd0Dl6dG6kMkA6rMUYN/4oqn8mAby1NOuQOKFk3+eZOifuini7Yr8fGfCF+5qivU26PaCUzOTHGD6ImMKVb9EX7iuvVyQlLDWqL/zj2dvJCaKctwxf28Rp0XQNXAnyd60Qdy9lsmv5aC2P0jLB+1VcNArBi3ImdXjWAYt5cEz+jq67l3u8G8XaKycG+C4DijG/99NKxbhFLSg== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(46966006)(36840700001)(1076003)(47076005)(44832011)(6916009)(4326008)(36860700001)(2616005)(426003)(8676002)(83380400001)(107886003)(6266002)(8936002)(6666004)(70206006)(2906002)(70586007)(186003)(356005)(42186006)(336012)(5660300002)(26005)(316002)(36756003)(508600001)(7636003)(82310400003)(54906003)(36906005);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 22:26:07.2009 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe0d756e-820f-46dd-b607-08d9abab94be X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT021.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB3895 Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org The PCIE device driver which attaches to management function on Alveo devices. It instantiates one or more group drivers which, in turn, instantiate xrt drivers. The instantiation of group and xrt drivers is completely dtb driven. A test dtb is used for this patchset. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/fpga/Makefile | 1 + drivers/fpga/xrt/Kconfig | 1 + drivers/fpga/xrt/mgmt/Kconfig | 14 +++ drivers/fpga/xrt/mgmt/Makefile | 16 +++ drivers/fpga/xrt/mgmt/dt-test.dts | 13 +++ drivers/fpga/xrt/mgmt/dt-test.h | 15 +++ drivers/fpga/xrt/mgmt/xmgmt-drv.c | 166 ++++++++++++++++++++++++++++++ 7 files changed, 226 insertions(+) create mode 100644 drivers/fpga/xrt/mgmt/Kconfig create mode 100644 drivers/fpga/xrt/mgmt/Makefile create mode 100644 drivers/fpga/xrt/mgmt/dt-test.dts create mode 100644 drivers/fpga/xrt/mgmt/dt-test.h create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-drv.c diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile index 5bd41cf4c7ec..544e2144878f 100644 --- a/drivers/fpga/Makefile +++ b/drivers/fpga/Makefile @@ -52,3 +52,4 @@ obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o # XRT drivers for Alveo obj-$(CONFIG_FPGA_XRT_LIB) += xrt/lib/ +obj-$(CONFIG_FPGA_XRT_XMGMT) += xrt/mgmt/ diff --git a/drivers/fpga/xrt/Kconfig b/drivers/fpga/xrt/Kconfig index 04c3bb5aaf4f..50422f77c6df 100644 --- a/drivers/fpga/xrt/Kconfig +++ b/drivers/fpga/xrt/Kconfig @@ -4,3 +4,4 @@ # source "drivers/fpga/xrt/lib/Kconfig" +source "drivers/fpga/xrt/mgmt/Kconfig" diff --git a/drivers/fpga/xrt/mgmt/Kconfig b/drivers/fpga/xrt/mgmt/Kconfig new file mode 100644 index 000000000000..a978747482be --- /dev/null +++ b/drivers/fpga/xrt/mgmt/Kconfig @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Xilinx XRT FPGA device configuration +# + +config FPGA_XRT_XMGMT + tristate "Xilinx Alveo Management Driver" + depends on FPGA_XRT_LIB + select FPGA_BRIDGE + select FPGA_REGION + help + Select this option to enable XRT PCIe driver for Xilinx Alveo FPGA. + This driver provides interfaces for userspace application to access + Alveo FPGA device. diff --git a/drivers/fpga/xrt/mgmt/Makefile b/drivers/fpga/xrt/mgmt/Makefile new file mode 100644 index 000000000000..fd2d47fed0c5 --- /dev/null +++ b/drivers/fpga/xrt/mgmt/Makefile @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2020-2021 Xilinx, Inc. All rights reserved. +# +# Authors: Sonal.Santan@xilinx.com +# + +FULL_XRT_PATH=$(srctree)/$(src)/.. + +obj-$(CONFIG_FPGA_XRT_LIB) += xrt-mgmt.o + +xrt-mgmt-objs := \ + xmgmt-drv.o \ + dt-test.dtb.o + +ccflags-y := -I$(FULL_XRT_PATH)/include diff --git a/drivers/fpga/xrt/mgmt/dt-test.dts b/drivers/fpga/xrt/mgmt/dt-test.dts new file mode 100644 index 000000000000..e335fd61632c --- /dev/null +++ b/drivers/fpga/xrt/mgmt/dt-test.dts @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; + +/ { + compatible = "xlnx,xrt-group"; + #address-cells = <3>; + #size-cells = <2>; + ep_fpga_configuration_00@0,0,1e88000 { + reg = <0 0 0x1e88000 0 0x8000>; + compatible = "xilinx.com,reg_abs-axi_hwicap-1.0", + "axi_hwicap"; + }; +}; diff --git a/drivers/fpga/xrt/mgmt/dt-test.h b/drivers/fpga/xrt/mgmt/dt-test.h new file mode 100644 index 000000000000..25a8b86c381b --- /dev/null +++ b/drivers/fpga/xrt/mgmt/dt-test.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Lizhi Hou + */ + +#ifndef _DT_TEST_H_ +#define _DT_TEST_H_ + +extern u8 __dtb_dt_test_begin[]; +extern u8 __dtb_dt_test_end[]; + +#endif /* _DT_TEST_H_ */ diff --git a/drivers/fpga/xrt/mgmt/xmgmt-drv.c b/drivers/fpga/xrt/mgmt/xmgmt-drv.c new file mode 100644 index 000000000000..0782543cf39b --- /dev/null +++ b/drivers/fpga/xrt/mgmt/xmgmt-drv.c @@ -0,0 +1,166 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Xilinx Alveo Management Function Driver + * + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + * Lizhi Hou + */ + +#include +#include +#include +#include +#include +#include "xroot.h" +#include "dt-test.h" + +#define XMGMT_MODULE_NAME "xrt-mgmt" + +#define XMGMT_PDEV(xm) ((xm)->pdev) +#define XMGMT_DEV(xm) (&(XMGMT_PDEV(xm)->dev)) +#define xmgmt_err(xm, fmt, args...) \ + dev_err(XMGMT_DEV(xm), "%s: " fmt, __func__, ##args) +#define xmgmt_warn(xm, fmt, args...) \ + dev_warn(XMGMT_DEV(xm), "%s: " fmt, __func__, ##args) +#define xmgmt_info(xm, fmt, args...) \ + dev_info(XMGMT_DEV(xm), "%s: " fmt, __func__, ##args) +#define xmgmt_dbg(xm, fmt, args...) \ + dev_dbg(XMGMT_DEV(xm), "%s: " fmt, __func__, ##args) +#define XMGMT_DEV_ID(_pcidev) \ + ({ typeof(_pcidev) (pcidev) = (_pcidev); \ + ((pci_domain_nr((pcidev)->bus) << 16) | \ + PCI_DEVID((pcidev)->bus->number, (pcidev)->devfn)); }) + +#define XRT_MAX_READRQ 512 + +/* PCI Device IDs */ +#define PCI_DEVICE_ID_U50 0x5020 +static const struct pci_device_id xmgmt_pci_ids[] = { + { PCI_DEVICE(PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_U50), }, /* Alveo U50 */ + { 0, } +}; + +struct xmgmt { + struct pci_dev *pdev; + void *root; + + bool ready; +}; + +static int xmgmt_config_pci(struct xmgmt *xm) +{ + struct pci_dev *pdev = XMGMT_PDEV(xm); + int rc; + + rc = pcim_enable_device(pdev); + if (rc < 0) { + xmgmt_err(xm, "failed to enable device: %d", rc); + return rc; + } + + rc = pci_enable_pcie_error_reporting(pdev); + if (rc) + xmgmt_warn(xm, "failed to enable AER: %d", rc); + + pci_set_master(pdev); + + rc = pcie_get_readrq(pdev); + if (rc > XRT_MAX_READRQ) + pcie_set_readrq(pdev, XRT_MAX_READRQ); + return 0; +} + +static int xmgmt_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct xroot_range ranges[PCI_NUM_RESOURCES]; + struct xroot_info xr_info = { 0 }; + struct device *dev = &pdev->dev; + int ret, i, idx = 0; + struct xmgmt *xm; + __be64 tmp; + + xm = devm_kzalloc(dev, sizeof(*xm), GFP_KERNEL); + if (!xm) + return -ENOMEM; + xm->pdev = pdev; + pci_set_drvdata(pdev, xm); + + ret = xmgmt_config_pci(xm); + if (ret) + goto failed; + + for (i = 0; i < PCI_NUM_RESOURCES; i++) { + if (pci_resource_len(pdev, i) > 0) { + ranges[idx].child_addr[0] = cpu_to_be32(i); + tmp = cpu_to_be64(pci_resource_start(pdev, i)); + memcpy(ranges[idx].parent_addr, &tmp, sizeof(tmp)); + tmp = cpu_to_be64(pci_resource_len(pdev, i)); + memcpy(ranges[idx].child_size, &tmp, sizeof(tmp)); + idx++; + } + } + xr_info.num_range = idx; + xr_info.ranges = ranges; + xr_info.addr = XMGMT_DEV_ID(pdev); + ret = xroot_probe(&pdev->dev, &xr_info, &xm->root); + if (ret) + goto failed; + + ret = xroot_create_group(xm->root, __dtb_dt_test_begin); + if (ret) { + xmgmt_err(xm, "failed to create root group: %d", ret); + goto failed; + } + + xmgmt_info(xm, "%s started successfully", XMGMT_MODULE_NAME); + return 0; + +failed: + if (xm->root) + xroot_remove(xm->root); + pci_set_drvdata(pdev, NULL); + return ret; +} + +static void xmgmt_remove(struct pci_dev *pdev) +{ + struct xmgmt *xm = pci_get_drvdata(pdev); + + xroot_remove(xm->root); + pci_disable_pcie_error_reporting(xm->pdev); + xmgmt_info(xm, "%s cleaned up successfully", XMGMT_MODULE_NAME); +} + +static struct pci_driver xmgmt_driver = { + .name = XMGMT_MODULE_NAME, + .id_table = xmgmt_pci_ids, + .probe = xmgmt_probe, + .remove = xmgmt_remove, +}; + +static int __init xmgmt_init(void) +{ + int res = 0; + + res = pci_register_driver(&xmgmt_driver); + if (res) + return res; + + return 0; +} + +static __exit void xmgmt_exit(void) +{ + pci_unregister_driver(&xmgmt_driver); +} + +module_init(xmgmt_init); +module_exit(xmgmt_exit); + +MODULE_DEVICE_TABLE(pci, xmgmt_pci_ids); +MODULE_AUTHOR("XRT Team "); +MODULE_DESCRIPTION("Xilinx Alveo management function driver"); +MODULE_LICENSE("GPL v2");