From patchwork Thu Nov 18 21:03:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627733 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58690C433EF for ; Thu, 18 Nov 2021 21:04:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 360E76139F for ; Thu, 18 Nov 2021 21:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232932AbhKRVHE (ORCPT ); Thu, 18 Nov 2021 16:07:04 -0500 Received: from mail-mw2nam08on2043.outbound.protection.outlook.com ([40.107.101.43]:6190 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231787AbhKRVHE (ORCPT ); Thu, 18 Nov 2021 16:07:04 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ed9e+xqr8ILEdb0vs+5SH2Mx6bEUvVPCZTcx/QC/vbgfp2NZ5917yF9WMEtBlKYUrfha+bIBvLsAe+f8LsGNvi+6jpFaGJrrUbx6VwhldQcbZ5SSQ/o1uJ7KSZ1wvHUtxahwvTgftPfwGw63sD5R4YlyDqMN0mx1y6x9jD+YcSfhUQgLCsJ/Tbb1Q3QXK2B1unZzDxzOmYBIyAJOLTe5Lzw5TCPW5g4tYViDwalz8uwfCXtfjsQ6zraID6sN0EHIBIgyDTgSXpbErC2j2mlHPR2p2W7EBv2IO9oasXy1DwTd+Udt5HRqpkXX/D7DikE1c126dncRBANBjT7/q7XkLQ== 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=dl7Sd7yKV6bMFpqjEc6NAa6ONv+eAwp+b+yGab/SacCQP2xHEaeWR5N8J6A/JyaybfHFC1GjEhMkA0+p/tyThEiSVjAPdKri1Qc/RdcK5CcbLPHnhVZ9xVbjtdus/lvwSOXwntpAt/dP+Kw5BPKmw85FV2s8WgM4D1XSkOnWrNSB0xM3EhlFBzfhiz8d8onpNnu7C3QYJh+EH8UF3R6McRZuUFlj9jZ4bVmPq9612lIElRMO9kJJ7Ln5ql4hVVY59hrfJLw33A4pde3c5FY/moCqm9U+izTrtoSsUjussI29cE9cEIAMUB2Km87lqSt5Y/pqME0fOmV8DYlSHPRg9g== 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=BrbaDExPo++1lmK7qdpGD3mKTW82m3hUs/r/r3SCWOmS4hIkZsM5SF8OUeqvN2lQ3Ya1Lw8CrIFcaagllepwqkTDr7630Fc5Ai9jeW6xMk/Pijo9H/r410stwQUGBbmZ9YSCZw7ft4gr9oIlblGzhpeK3I6oPHg3mXiKbS56O3c= Received: from SN4PR0501CA0100.namprd05.prod.outlook.com (2603:10b6:803:42::17) by SN4PR0201MB8774.namprd02.prod.outlook.com (2603:10b6:806:201::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.18; Thu, 18 Nov 2021 21:04:01 +0000 Received: from SN1NAM02FT0048.eop-nam02.prod.protection.outlook.com (2603:10b6:803:42:cafe::20) by SN4PR0501CA0100.outlook.office365.com (2603:10b6:803:42::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.10 via Frontend Transport; Thu, 18 Nov 2021 21:04:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; infradead.org; dkim=none (message not signed) header.d=none;infradead.org; 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 SN1NAM02FT0048.mail.protection.outlook.com (10.97.4.223) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:04:01 +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; Thu, 18 Nov 2021 13:03:48 -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; Thu, 18 Nov 2021 13:03:48 -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=37750 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoZQ-0007Ct-CP; Thu, 18 Nov 2021 13:03:48 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 9D40F60003F; Thu, 18 Nov 2021 13:03:36 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 1/9] Documentation: fpga: Add a document describing XRT Alveo driver infrastructure Date: Thu, 18 Nov 2021 13:03:15 -0800 Message-ID: <20211118210323.1070283-2-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d605610c-764f-4604-0156-08d9aad6f228 X-MS-TrafficTypeDiagnostic: SN4PR0201MB8774: 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: 4Y2QH5KxEhebPEkt+ANYliTm+9sOyIlTiaBCD42HkLFLVLI09meXzIkxnt0ZNeGLQB+RIzgq3hBLZaX5x/DlgwSaEpESl/uyUFcxzzFkgkZ3xmzmTeVoaAJ3RmBTzkvRqg90rL22AQ9CSCgVgoR5rhtzQDVyDo5cF2jYj1EJZ6vv2l8XiI/qabTYNh0sWZZdMpfedhSKBvOR7n5m6fJFRoVq+giLTXyE4kPI4sGW29l7qxOCXcFCSdcISeab1dNfkYQV9RcK5rCi9jUF7HrNJIme379bz2rmzDEPsOgNm+7pAe9X5e2VURSIbin3gAQo9Y/g1McCJ13gLY7CszgOJDqx3w5x3D/2DG/wWTX0TJN+OMd2m8XckApnndTzdauzX5brlMpPM7ce3w/ZGDGYfJ7diPoPTqfhjQCSggvsHszJsQcmTyoDWjsayzrPoI/1ve5mEJHZ1owtb6jw16sbQISPQ4VjKo49gMzlcVLHdkk8JdDo1SbFjD5ixJyr8jLAW+aTnyosFNIVeH4aaBzbXKk3amwmcOYiKh41ahXNYohZvK/ESUF7mpg7I2ITTrc3n4Rr1a+9pni4AazDaTldvse4gNk+XypNz/h6vCHKzDIApRIZd+DNtnb3+KYA9Afcfw6tUi2RmA6pyLVb95VYDQW9SD9lQnAjJ6WDZlrQg41JMJCcH+pucGhLMW4lRGkJY1ji3k4Qzu166zBwYg+bNYPVdsqkM8FT3P04ds3aRQP70zRxbzt/AXzd3KHreuTnawZdKeop4ROm5BJ4ceKrJQFVaXlklXYYD0RFX9j/NN/6buf/Fv0hmCl8QY0Wvu1BAYefhLfd8lnY02QmrIAN2g== 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)(44832011)(30864003)(2906002)(186003)(336012)(5660300002)(36756003)(2616005)(356005)(6916009)(42186006)(508600001)(7636003)(83380400001)(4326008)(70206006)(6266002)(6666004)(70586007)(107886003)(26005)(82310400003)(36860700001)(1076003)(8936002)(966005)(8676002)(54906003)(426003)(36906005)(316002)(47076005);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:04:01.1267 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d605610c-764f-4604-0156-08d9aad6f228 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: SN1NAM02FT0048.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR0201MB8774 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 Thu Nov 18 21:03:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627735 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAA6BC433EF for ; Thu, 18 Nov 2021 21:04:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB42561401 for ; Thu, 18 Nov 2021 21:04:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbhKRVHa (ORCPT ); Thu, 18 Nov 2021 16:07:30 -0500 Received: from mail-bn8nam11on2059.outbound.protection.outlook.com ([40.107.236.59]:2721 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229830AbhKRVHa (ORCPT ); Thu, 18 Nov 2021 16:07:30 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aRCBM6oSMY202Up9TjiJJ7prk9wZ5Hv+1zK/GihyvzN/DFdIEGIf71akxZlE7ANkMKOJqv2b2vpNOivVQt8ukquqdJi5cVwbenzx5QRWZqYLPQtMlgMtoPDMS2F+u1lKY8W7ojDtsiVXYdKFLUvuB4OiT5fT062Dfs3fePfMKQNSiB4Rhhd9T56WpxmhsxogtihfgXuP1iyVnm88wlMPhViMP/pzz9B3R6W8JBYO2zfak9RiZlT760lYhYN/ea+HgOCSeS82tP9ZIAfvqkT1VxrFWEALjIEfEYWqMYHjGO4E33/SMp8EYf7Dunwe0IhQ/ce3PuRwilCIM2YgvRqAxg== 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=QECNB7kmHRaIsQ7iC4f8bVPstXJH1ZGOxqBSelutlXM=; b=JhQHtUCc4dp8+YHzdduHJIze0rJmT3SefyRwdxPo0B0M4FeTDhXzs5thLF2T+Vu0kFSWHCS0XWAySsWnW6FGmKDHoGwCFZFMtt2AYFs7Tg/hiVX2H7UMwzdtPf11ZbYBgpjaIefq9DwhQrujrJQyhBmk5jLFQ2lhGmlA+LR7UGqFkiDo7ECYUvqX0wFwD4y2f0NiS20QKfQYTePV2Eownb5ix8h5lA1fL9Nqlc8CuECMUNQbw6/OWO+5XX+YQzPXU9b+1MUEcsRCEC/bqVpWksUiGT0vWQfCvpk2CXlw5u/ld64kBEjp17P5d4gFnVD9ZFQdjbLqD+My3yCnAvZb+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=QECNB7kmHRaIsQ7iC4f8bVPstXJH1ZGOxqBSelutlXM=; b=ituJR5vt9IdHxnWvg5VGa7UwmLNpnVcfgrRnB3QfTRVniZDyzd9C7pDI2tP5663ntxl0yoAFcEW39j1eEtdJz33GMKCmHl86W3UNdmDSJ7OBd2JRdQhcI+awlquZ2m4k1x9S8SDFjWW3sxDh/i8tboKhclq4P0NxR1+eIWahyis= Received: from SN6PR05CA0015.namprd05.prod.outlook.com (2603:10b6:805:de::28) by BN7PR02MB4004.namprd02.prod.outlook.com (2603:10b6:406:fe::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Thu, 18 Nov 2021 21:04:26 +0000 Received: from SN1NAM02FT0058.eop-nam02.prod.protection.outlook.com (2603:10b6:805:de:cafe::8f) by SN6PR05CA0015.outlook.office365.com (2603:10b6:805:de::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.7 via Frontend Transport; Thu, 18 Nov 2021 21:04:26 +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 SN1NAM02FT0058.mail.protection.outlook.com (10.97.5.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:04:26 +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; Thu, 18 Nov 2021 13:04:00 -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; Thu, 18 Nov 2021 13:04:00 -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=37752 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoZc-0007Dk-DU; Thu, 18 Nov 2021 13:04:00 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id B406B600061; Thu, 18 Nov 2021 13:03:36 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 2/9] Documentation: devicetree: bindings: add xrt group binding Date: Thu, 18 Nov 2021 13:03:16 -0800 Message-ID: <20211118210323.1070283-3-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a78db70a-b157-4e3e-141b-08d9aad70150 X-MS-TrafficTypeDiagnostic: BN7PR02MB4004: 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: mH7XRKyYbjiQe13MYtGXD2W8o23tNW0JD2ndlSdJYPN7ljcHCIMKY57Dv2XIp5HRBbaqAGOot03CCXYvy+i7qe54ZCbjHLfrnjdBur9DsdputAuwzgaU3XosPEQcZlFjrQpLYsQdHPMWFt2RIf6Q96mEq6FJHqkJCT+B7icSnUiYz5NnaNTSQ9kYSv1Lbg0BHMxBnQq4XMpGa4zj9MSZ7a4/xzor3kGkBJU7SxquY5RChwyVAHFyVAIwseauqYDnhTCV5fJhRrk4G3U+Kyjl6Fm1jBNok6zI/6wdWbIK35ek3Zj2+4JKXrcBy+1tETwRwow/3uOlkzmQCmNiCBc1jhfC68hkXu60tRISNwxFDhM1bFeF3/fYkrtq2QX4tDOYOZuWwK58wQZb74/wmWH1+OIgFt+5PFsvtGy2GvT6L61lm2Vpu1BYZkfG9VRBga1EBkaw6Xm57XGjDFcvZIYGf8DYUYVehY4da0c2RACT9/lBBRaAJvSOUPMQykE+KYokb+MomTtlJpRIQX1MY5ZKHGKZ8O/vVjhWGQwFnyr8bATP7ijDSPDEG/UXHRCc6BaRJixEhb45X35CXBu+5NdMaTw5Cn24SYQLZIIXhBu/T8gTPCR9MzJ1dGx1k8kpspNk5UaFbY6HMl7vPJO4OV6+JxZaDLFwOSWd0TcmRS/F7DVrEtqtfhhEtKCNm1KOfomt7ecSpL82dQv3Tm5lU0tL2w7DK+eL0E5SSARF4Rxhz8NggVUrq3pKOT/8fsSTwZvBpSmQ0bJGKupXGX5GR1NjpOe7aFCUWgKqA2wgzsd75oNbl1DpO9z33FRm8hwApNlv+7uPsTaL9kaGPT5jI3JrXw== 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)(5660300002)(44832011)(70586007)(2906002)(4326008)(54906003)(36756003)(6666004)(8676002)(426003)(36860700001)(6266002)(336012)(7636003)(26005)(966005)(47076005)(356005)(1076003)(2616005)(8936002)(82310400003)(42186006)(186003)(70206006)(508600001)(36906005)(316002)(107886003)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:04:26.5541 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a78db70a-b157-4e3e-141b-08d9aad70150 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: SN1NAM02FT0058.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB4004 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 | 59 +++++++++++++++++++ 1 file changed, 59 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..112c493eb2d2 --- /dev/null +++ b/Documentation/devicetree/bindings/xrt/xlnx,xrt-group.yaml @@ -0,0 +1,59 @@ +# 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>; + compatible = "xilinx.com,reg_abs-axi_hwicap-1.0", + "axi_hwicap"; + }; + }; + }; From patchwork Thu Nov 18 21:03:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627737 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE18AC433EF for ; Thu, 18 Nov 2021 21:04:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 916D660F0F for ; Thu, 18 Nov 2021 21:04:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231841AbhKRVHg (ORCPT ); Thu, 18 Nov 2021 16:07:36 -0500 Received: from mail-bn7nam10on2050.outbound.protection.outlook.com ([40.107.92.50]:20926 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233954AbhKRVHf (ORCPT ); Thu, 18 Nov 2021 16:07:35 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U4ScFZpWm+FEu5/aGc6jmLvWbBIR+MxQZFx40sJIKWIKhaOOXxKXVVhgHV6Jxvv5brvxM7Wty3DzY+lvK2ePQTy/TnW95pvnf+Ff8XES4pob8QCvctZB1rEvriYIfo2n/Wngzvti67q0xW9IVRVbClwNSHeVR4J//Zh8KUlBTALni2Am4wt3lg82iXTRk95SajuB3t8515dWZLVQPnZKJMDohjqbzNy6o7kKuRI0lNug5kLG/YTt3eYW+/TTAqeHc2WwhauCO0Cdx9TuK0rOTLTseN35UBMNF9JAt3IADxFJCLBX9e/L9nxqjeHprIgXOvfKcFoqKhZ2Y9/zYhaVRQ== 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=UkZg+qyEx7EW0aNJIfSEHpDdrm8Oi3ZkotWDwX3VsGR3g1nBUvd1mUhSLx/D+0GEeHRkL01bxA7gFzIOYy84Q5KHRqtawxEiZqDg8z2BuaOV0TwX47Glzs6qLV/w4gJrposSO9rfH3wha62QLfmR/ES64Ytw/Wc+mOpKR1VpkKeW8ns/od3XjHUi8YeuHgy8u6KPkfjDzY5nedwkO7g9RPtEZ2qg0EzkZGieOrfx08Ctdg7GWUzrfswJ+atzQIO7Tp1dm228Q7Zj/19VvTuGFLl3FZ/YISwWRMOsHK6ksWJ5cjx9Fymqd73qeH3kqjRH68q+PiTcH8ocjMWm2xPb8g== 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=oYos8GYKsDSXpBZZjbXDJHqGk+/nHuPzONKdvlSmlOsAKV5IluvBrcAZhBFNXT/s15Zi5WwMEsVrAJ2EAHuWnInZ/eE7d0BuchZHtPAEUHmBA91CV5ZimuKuxI7D+S5ZwywSYnI6YkT+06mZBeY4J8HlpvGf2RfWIFWBaDmJMRI= Received: from BN0PR04CA0021.namprd04.prod.outlook.com (2603:10b6:408:ee::26) by CH2PR02MB6679.namprd02.prod.outlook.com (2603:10b6:610:7a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.20; Thu, 18 Nov 2021 21:04:32 +0000 Received: from BN1NAM02FT039.eop-nam02.prod.protection.outlook.com (2603:10b6:408:ee:cafe::27) by BN0PR04CA0021.outlook.office365.com (2603:10b6:408:ee::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27 via Frontend Transport; Thu, 18 Nov 2021 21:04:32 +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 BN1NAM02FT039.mail.protection.outlook.com (10.13.2.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:04:30 +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; Thu, 18 Nov 2021 13:04:12 -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; Thu, 18 Nov 2021 13:04:12 -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=37754 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoZo-0001YV-FB; Thu, 18 Nov 2021 13:04:12 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id CE081600143; Thu, 18 Nov 2021 13:03:36 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 3/9] of: handle fdt buffer alignment inside unflatten function Date: Thu, 18 Nov 2021 13:03:17 -0800 Message-ID: <20211118210323.1070283-4-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e48aca60-c825-4824-bd79-08d9aad70393 X-MS-TrafficTypeDiagnostic: CH2PR02MB6679: 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: O/ThyLr+AzL586F9ZtGtSBHu4bxlFDMJp+K4T6EBOZYnOje/BNg28jivBVlaDKrfZo+/cg77czQtUQCzYLr+YSg8oWnQB9HJ76p4X94ySTQ2GsfFjbVS3GPRKeXuF0uEZLs+CUk35SvE0kgCPdtwf5SJAiZq/FzNXkW8Amf0NDg6QSfT1XJ4Bni4Ku5jYV5k9MerI1uMvzgiACV4YZP7FVM9BotwTfFPhPjyVCBSuLcqBa7UKKm6xCOtYURGcDiUpfBIyIBDo8Kb5xruU/0bvkfngN4lnzzFNC3zPeagZA8AgJqfvDyJh6minPDSAUH+8Q8yQDens6E2pmqPJzZAkhCwv7oa6R7VXmUhwe66SQCkOBno5I+vHVABkgLjCILXcz5dAswEQ2Uqh/Rf3cry1HvhPjjEKQK+d74tRCyqSR+E4M4+JaVHz3iF6BJSrXXNLDNfUv7cl+u4JcnYmSX9JMjmBeTO65vlq1pP99qL3u/356kqBVGjbidPl9Xbtph9dMilqhfQFpk3YzfNq5wDhX5Or+Db+gKztSKGwBEu6Cx/FRxtVTzTgYWo4cyTBdH8eSYGIXA3UPrS1TTNcgaqry3ajVTD1pAZxWSBtSLF34R+yApvvNUHHF337VaNtXRCuZ0tUICBKRQbCwk++plyfIgBdgsMjKk/TX1L0y2eIvWoH025eqc+43s42deiUKtY7JAqfJzs2U+ixReZxd+1cg== 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)(36860700001)(8676002)(107886003)(6666004)(5660300002)(83380400001)(2906002)(508600001)(47076005)(26005)(356005)(70206006)(70586007)(36756003)(186003)(54906003)(426003)(82310400003)(336012)(7636003)(42186006)(4326008)(6916009)(1076003)(6266002)(36906005)(8936002)(44832011)(2616005)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:04:30.2930 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e48aca60-c825-4824-bd79-08d9aad70393 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: BN1NAM02FT039.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR02MB6679 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 Thu Nov 18 21:03:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627741 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFCE0C433EF for ; Thu, 18 Nov 2021 21:05:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A26E461401 for ; Thu, 18 Nov 2021 21:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbhKRVID (ORCPT ); Thu, 18 Nov 2021 16:08:03 -0500 Received: from mail-dm6nam11on2041.outbound.protection.outlook.com ([40.107.223.41]:62177 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231667AbhKRVIC (ORCPT ); Thu, 18 Nov 2021 16:08:02 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MTP6CoD+RI5Ow2UmAvUopslPM21i96auIlx8qHPUyUmlvTNWxeOr6a6JB7QCXALCpicqTCWDEMz3zhPSIGJLGhDGzBqZwyQrGNns/jOPtuCUhpx2XBJEjUh1nkaHqYWBnvd/3jXig41A8hIf3qjA81Csu2QEOLyKfD0sH9iLwAf1crspp8D6OgR+qlKPULpIu7ofhyO1PS/CpiQnb1ELwdI5siubXc3aVGWCbbSo/RZAY+5W3HFmrDFb3+yTuFkw8Zg6NsSmVK3wiaTkBLydUixfS7S3CHvPeSK0vrQuSwkou+llLk8yr6Pc6XwFSuLZi2A61ODy9J2/Cni0DT0VIA== 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=JqhVpVGT/XpAuNcnShlly3n75QkclBdPtHAx3JvAQOB8fr+qScj/cC9krAgoc8HtRRjKbMDoFf0pmBibF/xjRi71nqTcl+SKKr9TZ+oRWZ15hv7WQ5ws/wVcqBLZAEuL87nXsyuSybAkMutJcc0+JXdCDR4dr3vlsRlti+NZ2xW0eZ5WawsgASvvd6n8FU7QN8OEyFogYWCXRli+NmLpmSpdSU8YBVSlbi7H5eVAUdZLZQ37RA4millr6+JBE2i2nPI7l4bT6klOSgZ/I1sV29vp5RaZZTv/gPA/LvnG26Jwni3FroM25TW3gQmYed7KFnrRK3tFiC3+TB0AOhm+zg== 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=d3BFhpGStij0tb8qcHE3BB2bTbRGx6mD8nuSvlpd2R4ur8YHIT8e1RVlox2Onmehn1w+ZwX8bdSu1Itp+O6ayID3S6tfZY+k1UyiSzGJHgRbA9Hz7xiM9HrQ7C6GMhyUs003OTpSxhOC2Sgk21vwf75URz8q32+jLsiWoXOCxew= Received: from SN6PR16CA0070.namprd16.prod.outlook.com (2603:10b6:805:ca::47) by SA1PR02MB8400.namprd02.prod.outlook.com (2603:10b6:806:1f4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Thu, 18 Nov 2021 21:04:59 +0000 Received: from SN1NAM02FT0018.eop-nam02.prod.protection.outlook.com (2603:10b6:805:ca:cafe::59) by SN6PR16CA0070.outlook.office365.com (2603:10b6:805:ca::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:04:59 +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 SN1NAM02FT0018.mail.protection.outlook.com (10.97.5.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:04:59 +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; Thu, 18 Nov 2021 13:04:48 -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; Thu, 18 Nov 2021 13:04:48 -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=37760 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoaO-0007HC-KA; Thu, 18 Nov 2021 13:04:48 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 105C9600147; Thu, 18 Nov 2021 13:03:36 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 4/9] of: create empty of root Date: Thu, 18 Nov 2021 13:03:18 -0800 Message-ID: <20211118210323.1070283-5-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3cb75961-2ea5-4cd1-8a60-08d9aad714bf X-MS-TrafficTypeDiagnostic: SA1PR02MB8400: 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: zyYZQlkZUxh7piK10PdqPbAg1G5Md5CNCQL8A5NWHlM6O5EyBw26G03oMsoVSgaDXYD5N8YDsjYXz39N9UL8RxZJv3ARODeqZULvUv2puuhUpeKRqZ6zyiQOsWirv1h8f1Kb+fA6rUnfX8PAqn5sZ5TRdMjQsbtD9N+DL+nkxMxfmjOd8CVd5kTdY7sQIQg/FZR/TLDown2Q4mdCzEXsK72eu0X0u1EtAfVKfCvgI9HsjOOq1ZWZs3ibjE0ZaRL69geSjDTRTcBDUZ2MdHxSCF02csJH6vJwXDx8JUO1epB4ZBlNv8fQBcWLLE1z4PEI5BA8waiqkcaZez7100XiJbfKv7JgI2QlC42SMC+NrG6eOye27u+tNUgXCzD62I8jjskzm7i3edpaIoJtxoNifLP9blIUJSlPpGtR+Czz3QbKwRHrLcByG5fpDjFsjXzWFHX6vOzVsZMZWqo7aY3Snxssa3FUjgveO1yguT+ERewD3LhIlQpvCBrtxBkaBWUnCT7TUPc8aJgB1wnEFF9wGC+pWVk3GVHiIJM5jIFuFSJT+DVm5DlxEncZq61kxmDGzlT658Dnsp+zUh4k+FgztTGqLUgB+ANvJYHS4zTqzKNrSbD9F7nbWa8e4Ca5K3rZ9rgnwCRrvnU/PWQFUZCBruI0tTJs8S4tuCIQyKgez1bV4KzG8srEbP6n4vr0lgW25m/+Z8CLWv+a99npyzqL0w== 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)(6916009)(5660300002)(1076003)(186003)(82310400003)(36906005)(26005)(6666004)(70206006)(70586007)(8936002)(8676002)(508600001)(336012)(36860700001)(42186006)(4326008)(6266002)(44832011)(107886003)(2616005)(356005)(47076005)(426003)(2906002)(7636003)(83380400001)(316002)(36756003)(54906003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:04:59.1613 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3cb75961-2ea5-4cd1-8a60-08d9aad714bf 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: SN1NAM02FT0018.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR02MB8400 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 Thu Nov 18 21:03:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627739 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DEC7C433EF for ; Thu, 18 Nov 2021 21:04:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0576E61401 for ; Thu, 18 Nov 2021 21:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233859AbhKRVHs (ORCPT ); Thu, 18 Nov 2021 16:07:48 -0500 Received: from mail-sn1anam02on2063.outbound.protection.outlook.com ([40.107.96.63]:6213 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232359AbhKRVHs (ORCPT ); Thu, 18 Nov 2021 16:07:48 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fG5IJjeekj/m+SunIe6a95X0y31jQb0XhJKawubiZzZgsp7N6+QeBLxUTggZgnoNOI/m84LPAncMIN0PGNL9L/YTNui9YQJVRNFpVz64waqgQFAeUrrEq0bK1PV9q8SkH5tIXuXcUWNSwV823lhFahsSu7RnrSCCnlA83L7/RJ4eJcG+vF92I+zV06RtDdIAp0BonQKPbs5/YS2Staq3wOtQaB3KxDYzA6bkp/lHzP0p8GFTV1kk/S5Wy6W3A1bactZR56umPD+rbpRvmBKfeR+SanrAKDzwu8LgvxvCIyUwdqiONnX+yB66ajPka63x6FPZxEkFY4srvWIirfrmFA== 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=IoAi6X3JdbcG+J9TVmqWROSprEyiav6NuWbqwDvI/pyJtd3kcj9EAzAobFv0YX0Kb9bSjMDG4w5bXljiMtXdVW6+U//8ptb54aofRb2MEyoSppQKKJumXNxW14BzQtQ8wUjSZT0yBhbtBgAC4VHGVusW7HDNERjJzD67AzyIDVtlDcm3NHqcGbalgPXfVp3+MVxujTu6nY4Ie+cJOY1OQMnjdP+LkeaM1WzwamAJbZP7yxy3OCzyGqzsf+h/XMjxvOpNdsxzY56tJPDqdI+pOGMuCDmJCf5vOYJtOet+eY7i73O/Afa+yJ/VLg+huFEomKKoKOyaHqgDtUOVKrdzaQ== 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=VZTnbdTt1ttzf8pLrDzcYTdlxJdE7FJRwa0CCLc4Rke4W6P7GwmSB4GZMWf3Rgtb24xdgLCLVEDqT3rvmgIKysW22asc1frgOfVx1We7QWn2tKAOjqaXMh1wYibz6ZLK9cPn5oTWwzKYNzs59ZAqUpg0OImQyHWdEd4g9J8Ci0g= Received: from BN0PR04CA0043.namprd04.prod.outlook.com (2603:10b6:408:e8::18) by DM5PR02MB3372.namprd02.prod.outlook.com (2603:10b6:4:63::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Thu, 18 Nov 2021 21:04:45 +0000 Received: from BN1NAM02FT053.eop-nam02.prod.protection.outlook.com (2603:10b6:408:e8:cafe::bf) by BN0PR04CA0043.outlook.office365.com (2603:10b6:408:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22 via Frontend Transport; Thu, 18 Nov 2021 21:04:45 +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 BN1NAM02FT053.mail.protection.outlook.com (10.13.2.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:04:45 +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; Thu, 18 Nov 2021 13:04:24 -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; Thu, 18 Nov 2021 13:04:24 -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=37756 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoa0-0001Z6-H0; Thu, 18 Nov 2021 13:04:24 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id E0D8A600144; Thu, 18 Nov 2021 13:03:36 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 5/9] fpga: xrt: xrt-lib initialization Date: Thu, 18 Nov 2021 13:03:19 -0800 Message-ID: <20211118210323.1070283-6-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 053d4301-b160-42bc-f6bd-08d9aad70c6b X-MS-TrafficTypeDiagnostic: DM5PR02MB3372: 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: qRTZ58YOmeT2e87a23OUoiP8Gb2WB+8VwLNCs1pO+xDk2A2ytqYJmqgwRk6xGMej6bX33f9PHA4QRJwOBlVpC+2koh+w5/hwo/yJbFTqICFpvqiVbVG68RktU5b8j8X1wU1LutdVbHs1wug7OHnnG63SBILgWRwNtVbVaI1pcBBrd6hjrlfHqWG9Pw2FHrTiz9iygUopR9rxVPuVIVnrwvJlJD+WiVs+WuWJeR7syAtFroFJ/t8TyV0ayzV9UiibYklU6lKTVcbd8s73AUwY9CPA6VT69yVEvjnY2ieK4fE/3yd3NjGfuZQn1a4JeTLsSmnxSNNZ7zb71FW3QofKqIkKCcVaMcDTCaEjR4EdZErHnTULBUu1/IYbosyHF7suTkL88llwxUKzD3w0P3Pe7gnarjDSPo2yAu2OcEBFkIyM977+Ap2CKiyRcgn63XfgtP9RIo+w/CKd34xENM/RxTRQ9HYZ5/gvyec2N0B0foLxt7Z4MQB9T9VMB8IPpXy4YGuA6u87fySRD7ZUEqwNIdWVzinY/QzuBAgL8uzq4xmfuxVh5cjFaVsE0xEuhGwQigoKEs+J64GXXlx2dVhX2Sg92kT1qW/kGxuJq6Fyh2SB5Lj53Zfx7B9+LpfQUN+CV3Pny/50V2PtOPRzRmL1VICBbc+vJNEYqtvUPS6nWyWrZgtM55LxFLVuSDUFhbfKn48tpbpCB6w7j/dosHhRSg== 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)(7636003)(26005)(6266002)(82310400003)(44832011)(70586007)(5660300002)(6916009)(6666004)(2616005)(8676002)(186003)(356005)(70206006)(4326008)(316002)(54906003)(508600001)(47076005)(107886003)(426003)(8936002)(42186006)(36756003)(336012)(36860700001)(1076003)(36906005)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:04:45.1289 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 053d4301-b160-42bc-f6bd-08d9aad70c6b 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: BN1NAM02FT053.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB3372 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 Thu Nov 18 21:03:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627745 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B467C433FE for ; Thu, 18 Nov 2021 21:05:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E107461A02 for ; Thu, 18 Nov 2021 21:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234073AbhKRVIR (ORCPT ); Thu, 18 Nov 2021 16:08:17 -0500 Received: from mail-bn8nam12on2055.outbound.protection.outlook.com ([40.107.237.55]:51559 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234232AbhKRVIQ (ORCPT ); Thu, 18 Nov 2021 16:08:16 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a1/fLLMSwqs0CN/cq3erwgav8CrHfHMhvwlvDbBBStGE8JHZEEFs3NST6ctSyXqNOYW/UqfI1+0rry0MixUtkW+CzH/FUyChf9JkxawifqBnhipCOl3L7klxtvCz+zFO29BMHPHHaU2AGlcjKYLTgsiBMGWiHgnXU3iz2tq6EQ0QhjyEnKIpBqIszsEezzQEmG6CCAn0Q8NsDyvls2a16HC5ioaSTlbLQ9BpbcyunqeYkA9DU5mQaWMcIXYApDCX8KmXKFMD5vXHpN8Rj1haAo+mwukuN8I/wK3WioMzVJDow77o0cRARJP4v5P1DwnuGcN+OuPJd6HgASdMu2UckQ== 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=htdhM01s/HePOTmwmwfXsZy1W6gEqgJoHBCWDWkkEwZRI/f3jhaIA69eL2SmGH/tZgSX4aEApSv1Ied7tY05DW5eS0lvkaO/Ij5AmpuNko4Ov84EdMe29trrNOBjGqu6akHM68Nr22fUwR2aTlj2YG28v2FNWD5xd9oxjMAMBAVohhy2GRSG3IvmmuV8+MSHL3RKb7Q8LzL49oLktzJ61ahlmVrQXqBFrY8cirbLayzNp/9ExlOPQ8WrYDu6VEQwe0g4BFmgIbMd/3s+KJ/F+Wuc/d6lRNO18ijH+MU6wa6AxmiH1PLJktj+tTDGl7GDSS5NH+lLpNA6Py5N6HoGaw== 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=Nxd7u9nA5dPmoikHaRMwUkqiy5j38lq62mY0I2ldp2GWF2Ko9ux0XWAfoOebbC1GrBmpgYvz/m77NjKEjpbCgg1kH5F/nutJHy+Ynr/WYlbSUaGbw/yc8u2DjJnfrmfeXo37bvalSpAXwXekkx0UsaprkhhLNhZXFbLlSPwro2s= Received: from BN6PR1401CA0016.namprd14.prod.outlook.com (2603:10b6:405:4b::26) by BN0PR02MB7920.namprd02.prod.outlook.com (2603:10b6:408:165::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Thu, 18 Nov 2021 21:05:13 +0000 Received: from BN1NAM02FT038.eop-nam02.prod.protection.outlook.com (2603:10b6:405:4b:cafe::df) by BN6PR1401CA0016.outlook.office365.com (2603:10b6:405:4b::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21 via Frontend Transport; Thu, 18 Nov 2021 21:05:13 +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 BN1NAM02FT038.mail.protection.outlook.com (10.13.2.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:05:12 +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; Thu, 18 Nov 2021 13:04:36 -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; Thu, 18 Nov 2021 13:04:36 -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=37758 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoaC-0001Zp-IX; Thu, 18 Nov 2021 13:04:36 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 01C0A600093; Thu, 18 Nov 2021 13:03:36 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 6/9] fpga: xrt: xrt bus and device Date: Thu, 18 Nov 2021 13:03:20 -0800 Message-ID: <20211118210323.1070283-7-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3c8df76e-fff1-483f-9f81-08d9aad71d06 X-MS-TrafficTypeDiagnostic: BN0PR02MB7920: 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: zt8aIsFJeVqsEtmopqseU5K/5O5IPdqypPyjs2xUX60R0BPPU0U5yQXyMzx0/QKW64GNnHjk0qjqiANfkSObI9fB/JRubOej/wcQWn1ATsFT0rDiis5DyVpMNtGZDbJEni53ZUoZBw9tPktCAjgAHZzZ0C7FhjfWn2uOWfdYecBvaLRFiJngYYOmXzYdxl1+1gMiauE5VY1Lbpai5K1TF0PyPvOPC0odki8lcdeCjYv2YsNTr3zTli2mkcUIj4jRwqov2xSrtGNNuGgdtrmLAa499l7Ni+5umYXem+wy8DpMs1eW04+6RyU7iXP+e8puOWwFUznpHMB0y2Qnr7vDyYFiBJamdG0wh6P+CODucX0QydyKOnXDz9fdRdRFdBpLwmntfCxgvgkfHAkF5Va6LgbiouUmHlKEJ6CCqCmhUz99Aoj96bjrbXbOBcO0e4WhNN/ZsrlRtWkufLX45slVtfCQOSWdQqIqF8l3mbj0NBg8cj47OFrDPhRcp3qTu022fEZNG4SK15GIoXnyjCGzZksREE6FCCK0+t/7QGNSNxOmmgOMd2j2MnNcGDHLOZps3N3knGutCJ+ATgxuxwEeOqJqClOzC0Pp6mdguzT4k4vhpZJuR4XCOlxL+OM+6TL7TtOBszJogvgZPC6JLuk0AvFG5pu20luGhUude21AG5/o5V7OkYn/hsg3+8fLKKcsn3BaZJ51Mt6hXUs2ZUlvmw== 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)(336012)(426003)(82310400003)(36756003)(70586007)(8676002)(5660300002)(26005)(508600001)(2906002)(316002)(42186006)(186003)(1076003)(6266002)(107886003)(47076005)(70206006)(36906005)(54906003)(6916009)(4326008)(356005)(8936002)(44832011)(36860700001)(7636003)(6666004)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:05:12.9890 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c8df76e-fff1-483f-9f81-08d9aad71d06 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: BN1NAM02FT038.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR02MB7920 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 Thu Nov 18 21:03:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627743 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F293C433F5 for ; Thu, 18 Nov 2021 21:05:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27ED460F0F for ; Thu, 18 Nov 2021 21:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231338AbhKRVIQ (ORCPT ); Thu, 18 Nov 2021 16:08:16 -0500 Received: from mail-bn8nam11on2048.outbound.protection.outlook.com ([40.107.236.48]:50326 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234082AbhKRVIN (ORCPT ); Thu, 18 Nov 2021 16:08:13 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YWCfRg6CjCO7Hgypm+2zbmTNqI4HaxSjNG8OF5Q5jy4WdL25M5je70cThj0NOd/pELX93kLIeiK2DSnmpWptgmE59Crz6POc8Fx92KGxIAzYwzxsqthATExl7KbDHTKeDWOZw9aJCzBRS4+T6Y5Hiz5U8TI37mQOjJhbGxceVq1tK9Ct/9HToT6hVtsHYeNxyz1GznOI56WFU86crf0JGN7x3n9lgPjaAZvYFbPzn9xFdkcizbQbR4p9zKBDZUe6E/DcBDsmBfIfr3fPcGZGBRKVneutMHfH+13dUHhgjTD5M/n8lVHPBrOvvdg9tKA4aW4o6g0c8HCUKvDB8V5ggg== 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=hu0o34cTF1G7sXflK93ufZJBJVmmluXVQ+gufHhkU+gf2AsIXua4URcZAn+PWiQuGbQdE+Q+OjCTIyyLHpzXzWWeo4/yVn5/VT9TRwCwu5taOd9DM0bKjtaqGpsnNnSXS+JQqCdTCn68JkwsqUvq/ez7wg+Zea/iPlf7c2r3LxclRoYL8buuyTSYvSSXYNqkXENGtJo2bReTyuo/CHYofHhDtqIu5klH5wi+tYoXaasqFEdiV2y7+tuNGUcmlW4kJJ7dh7vl5/9lbwcRDVkljq+q7Fiosc/VcD7GUb5ob+QfFrFm0MXy4A9rKHRSTNltWrr8SgvVl4u0PvlfPX0dYw== 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=O6lEM2xqOaX/05mpvX7dc23J8UTLADM2uXG27z0MXWC0z0OhRvAEfjc5tMFYg3WT5kossZxhYqhGpWT+08vwUJ4MZb0XQE4OCBeXtNmed9V6JaGF7Wf1V1CIwSqyF7anyGA3vKemx/VYtcR2Hdf5iqDImIUJA8Ri6fUbJSFig1M= Received: from SN4PR0701CA0033.namprd07.prod.outlook.com (2603:10b6:803:2d::27) 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; Thu, 18 Nov 2021 21:05:10 +0000 Received: from SN1NAM02FT0050.eop-nam02.prod.protection.outlook.com (2603:10b6:803:2d:cafe::bb) by SN4PR0701CA0033.outlook.office365.com (2603:10b6:803:2d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:05:10 +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 SN1NAM02FT0050.mail.protection.outlook.com (10.97.5.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4713.19 via Frontend Transport; Thu, 18 Nov 2021 21:05:10 +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; Thu, 18 Nov 2021 13:05:00 -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; Thu, 18 Nov 2021 13:05:00 -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=37762 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoaa-0001bD-LX; Thu, 18 Nov 2021 13:05:00 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 29315600146; Thu, 18 Nov 2021 13:03:36 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 7/9] fpga: xrt: lib-xrt xroot APIs Date: Thu, 18 Nov 2021 13:03:21 -0800 Message-ID: <20211118210323.1070283-8-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9f7afaac-20bc-4921-04b9-08d9aad71b54 X-MS-TrafficTypeDiagnostic: CO6PR02MB7537: 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: s4duEB2XUMgCckN/k9SqwNphLy0k3GIVLzkoKevYTmZG+DE4gVWaiJiOzBLEw7cm7aPlrY1MIAKI/wJqgEIajLTLM03MnCEtJa2uCwxC4iKF2hVBVRzpxEyzFzbtxguzNhuLmqeK02okGjTqz0SuAIxgQ2VH2+BeqyBoJbB46jTJAf+kAgiUEVz7Ndyh3JR3UKsoYHDqu4+ynD00aJv5IhQfTqgFrdSuuUj3XDnrYc0soL0roIqU11fW5u7X5JjKGhpCR6JLKDwJVhQ3zG3vFpAre4BQZRDYfOcAp5/ImuAUvBSOxonNRjqblg6ke+Qt++6g0bgOkSj20+gGgIk7okbC2+wDxV8GG+G5nTsAw2PAUUI+XjzsyUT/OpGG5O3B50q7TFuEXpIL8dPx2if5plw+JVTbn+HrFRQHEads+nOrQR+the7/Cw/absM+1I6AMpuAqQL32RTEy4zHosSUyZAMxgmKivczK4YdMq9+fVNJBDIkr/p/BIuo/giPzZ4KY+2qUiiTyETYyheAvkKWy10+63XwlowSu9YWm6fPfq4j8OJe+Ajj9iMIF4OSGlBZlnp9aI+/WTdT3DTL2incdRLaqAIL7GsctZXLJvK0IZQtMtAD3g6pAlnHMkmID20SEFxYCwHTo3A4G0ZGqMStqcS40g5xa5Flngyhv5dXEhJcl9zMTcqObN1mNKte1RTjdp1NePutvLjT7cBMwj5ICQ== 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)(356005)(7636003)(6266002)(508600001)(426003)(6916009)(2906002)(47076005)(36756003)(54906003)(1076003)(186003)(70586007)(70206006)(42186006)(44832011)(82310400003)(8936002)(2616005)(316002)(336012)(107886003)(36906005)(5660300002)(8676002)(26005)(6666004)(4326008)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:05:10.2017 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f7afaac-20bc-4921-04b9-08d9aad71b54 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: SN1NAM02FT0050.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 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 Thu Nov 18 21:03:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627747 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F207AC433F5 for ; Thu, 18 Nov 2021 21:05:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8CFF60F0F for ; Thu, 18 Nov 2021 21:05:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232944AbhKRVIg (ORCPT ); Thu, 18 Nov 2021 16:08:36 -0500 Received: from mail-co1nam11on2049.outbound.protection.outlook.com ([40.107.220.49]:52321 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232591AbhKRVIg (ORCPT ); Thu, 18 Nov 2021 16:08:36 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vp161UpHygB9QbN9zG1+qgK/o39PUgC9UfLrLwZOe0zNrxTHynn0MdZklTrGYJ6rGFIwIZcNNeBDv15uHZWONQfqPyIQk9X8s/aTA9nAHQCyIOnr22alnTHRjxJsGq9MNH6vOmAX7nBAWB6Q60XauyQYqY9SKM/ieCtVhw/6VFXcEDXgd4ayfTcLnySUpE9AvvxQCvUo4BP/knSBzV3NuN9XdIxwJqdB5zMl/thqWAmquvwzHyD3mGnv+7PLFJtrWkx/+dy3jcWxwly7cPPIS7Ej3NwDTjZGYdV7VGrBiJMpBcIPIHZj2MFvC0Z567swvGvo9plnFZNAj6CI8IjLZA== 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=NvgIrd8owY50IBk0eQ9SCTszcpujxviu0wytc8R7ZqX/ZWKCfCS3lyY4FN22guLoNqzvMDrjc3sPLJA0bSMDibVW2PdC56R1pmLHtL8m/B43clGTYzfR7Hzc9pdMK9n0sZK7IoYz97On5RhHNz31bzF1ZSFIs1E7JUBrLKML+cybIhsmSCy8bw95wXxtLAPlRFsotRKyeMNj4lYg/26a1yxnOjH29RCB541WQevWBs3xgVQqjU0zqhfgnwSjOGVq2G1BWbCbBictcpmn06Y7/nEAXRNETvrIMWkXVWn9StAMtG9b7J5KgK4+V9JVTdvIJthAe/44jjCC+NsNwqO0VQ== 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=DmBhSGcCPw1irZEzUI28ak4qIg3mGGowN/BcqnGZTPv3NVsq6GnHnqHbCpJ/EkH26Exen+3GaqtyQWZkvBa45FI+7TDrvco9LVgiUT9KQ0j9Fg53ZbuavrolQf0vuGZ9LoYO2kHhIY+b72FtIA9keHdikjBqRAms3jmOpg+ak5E= Received: from BN6PR2001CA0041.namprd20.prod.outlook.com (2603:10b6:405:16::27) by CH2PR02MB7063.namprd02.prod.outlook.com (2603:10b6:610:83::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Thu, 18 Nov 2021 21:05:32 +0000 Received: from BN1NAM02FT006.eop-nam02.prod.protection.outlook.com (2603:10b6:405:16:cafe::e0) by BN6PR2001CA0041.outlook.office365.com (2603:10b6:405:16::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22 via Frontend Transport; Thu, 18 Nov 2021 21:05:32 +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 BN1NAM02FT006.mail.protection.outlook.com (10.13.2.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.19 via Frontend Transport; Thu, 18 Nov 2021 21:05:32 +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; Thu, 18 Nov 2021 13:05:12 -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; Thu, 18 Nov 2021 13:05:12 -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=37764 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoam-0001ij-Ne; Thu, 18 Nov 2021 13:05:12 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 4418560014A; Thu, 18 Nov 2021 13:03:37 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 8/9] fpga: xrt: xrt group device driver Date: Thu, 18 Nov 2021 13:03:22 -0800 Message-ID: <20211118210323.1070283-9-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dc3d58ae-36a9-4628-fd4e-08d9aad7287b X-MS-TrafficTypeDiagnostic: CH2PR02MB7063: 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: ca5ppYfpbX9Cqw4Vh4fQMdhBXGgjUpc5KWTqLxlLFJPI/B8MIpe3qMa/4Ss0rKJP/lNRjMAygjgP8bPMHfZttzLz+m+Q3mV4z8wLb15ty6s5eGHHkE9RqD30ce0mArftjMAyyQ00/S0+/rtOex0YGhEmlESH7n7Mx+IMXAS4SzHeqo/E+syIGvVQ86icRIb5e2XZsBI+SCC9ur3mW+ET3hB7bB0RwHCJnsVtO8HXgHRCvzVqj376xXzZnM43js6//QLoIS1DsRac1yWVFLWwodKBFOHke+PUcQG/d1fkyp09M4xsFWtg6BkCQmixHszTZxJ0D6PRivqxWZ31o745eCz7fi3NDBLXnHr0L2Yq4Eus6A2aEEQagKQ0l6bc3EZOtBQxaRrws2r88O54OWhwt7peoWozZYZlWJwlKfQJ7RcbI92wWVzJXIhChScfx7d80dY07z/2ixEnjmzLVolMJ3ENewTCGXvRbxmepGdNEbqRO6zdzjCgjYjeG/aX8kDHsVjn6tWgnfxFPp4AktlYlLWE+Kw/5k26fEymBqbYHAWtTUgGFBNwDUUxwYewl+leQzJekoe++H+/0O+OSTY6rVEjvhOPG0FOhiq6zy/9T3jjXhdnF37DcqlbgkqIXaT3QiqQNVmW2dyLIa3uziUF0HPE7bBKznpCq/UEw2KE6hL6PPBYpPKE9rE6WthG+Hjm/NtLMux2VeE7OMVO/5qMZw== 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)(47076005)(6666004)(54906003)(42186006)(4326008)(356005)(5660300002)(2906002)(83380400001)(36756003)(8676002)(7636003)(1076003)(70206006)(36906005)(70586007)(316002)(8936002)(6916009)(508600001)(26005)(426003)(44832011)(107886003)(6266002)(186003)(336012)(36860700001)(82310400003)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:05:32.2131 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dc3d58ae-36a9-4628-fd4e-08d9aad7287b 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: BN1NAM02FT006.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR02MB7063 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 Thu Nov 18 21:03:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 12627749 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 136B7C433F5 for ; Thu, 18 Nov 2021 21:05:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDFCB619E1 for ; Thu, 18 Nov 2021 21:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233007AbhKRVIu (ORCPT ); Thu, 18 Nov 2021 16:08:50 -0500 Received: from mail-dm6nam11on2059.outbound.protection.outlook.com ([40.107.223.59]:16449 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229879AbhKRVIt (ORCPT ); Thu, 18 Nov 2021 16:08:49 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m1vlbzUv8cR/y1Eu8Agormfh3ZQ3TtsxVvmQnTyDsmi3qlPJPvOtAti1Qf8Fk1+A4PepmruqzWJPGh/XGmaFK8WQxNaLHefo31o/e9wD7CBOXFcAxAZtQcrW7ubmeZp+yOtj15H4BNLAfQ1bMwy5V/YuLuyXGehrE/whcOkQ06Ye1GV0fgfcbSAEVP2BNK6HBCr5ehT3QYvaoxXyFYz7PkV8UmqCMiRUjmIaVD7F0EZH1KuAFM47x0Rgd3hKbWua6UHcSuPYbSVMHZag1DwMzemo/ZLk3CG2bzVqSUDEa2h/OvHZabprEtmq/VvnDDptyYkJ891aRE3N3QScsXMl/A== 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=iB119gmn3FtD0xrSQzMIFPhXav7MgMJCFLsLpjUvjcHcbcPU/GkWzyd/Er2+jj2IuwV9GxT7K+qEf64UjUeDfaVDX1ATAhn9HtI7rswc3vfJGe+dTkx/Nj58+5WsWvP5B26n8n6i4JuIuDwTBA0PHXFmV6a/kUn9M9T17mGLHLXg1ZkV7UlS64RAKJBQiiZibKs3hZywCYdIBvFqT8NZ/n9OJfwCnJ61ORVq2b3RTt8IOWNTk9a9H2IYu6f8QEL3H26B/gxuCuu8oWZ+KLo5QDBryiqRWqaJFH7S8/PUTeyjprthVeshfe7Nys4WCtRWlaJ2JLeXZ0tQD7Q3E+cryw== 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=GGU7FSVJFJ7w07cg7BISxyrZtrmpwjHeK6eSs87sFS8s/M7UdFuedyenMfjmTflYMrwuN7WLw1SGYbtjBsITMA8M/sPUw7XscIFjznUTLMDZ3JQzMvT3qE2Hijyw+Tuc86v3KuyXmQqcs49Njnhz0QZX/5OQOBzRU9L5oXWb/yw= Received: from BN0PR07CA0005.namprd07.prod.outlook.com (2603:10b6:408:141::20) by PH0PR02MB7173.namprd02.prod.outlook.com (2603:10b6:510:d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19; Thu, 18 Nov 2021 21:05:46 +0000 Received: from BN1NAM02FT016.eop-nam02.prod.protection.outlook.com (2603:10b6:408:141:cafe::18) by BN0PR07CA0005.outlook.office365.com (2603:10b6:408:141::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27 via Frontend Transport; Thu, 18 Nov 2021 21:05:46 +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 BN1NAM02FT016.mail.protection.outlook.com (10.13.2.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.19 via Frontend Transport; Thu, 18 Nov 2021 21:05:46 +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; Thu, 18 Nov 2021 13:05:29 -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; Thu, 18 Nov 2021 13:05:29 -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=37766 helo=xsj-xw9400.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mnoay-0001ra-P1; Thu, 18 Nov 2021 13:05:24 -0800 Received: by xsj-xw9400.xilinx.com (Postfix, from userid 21952) id 4E90E60014B; Thu, 18 Nov 2021 13:03:37 -0800 (PST) From: Lizhi Hou To: CC: Lizhi Hou , , , , , , , , , , , , Max Zhen Subject: [PATCH V1 XRT Alveo Infrastructure 9/9] fpga: xrt: management physical function driver Date: Thu, 18 Nov 2021 13:03:23 -0800 Message-ID: <20211118210323.1070283-10-lizhi.hou@xilinx.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118210323.1070283-1-lizhi.hou@xilinx.com> References: <20211118210323.1070283-1-lizhi.hou@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3bf3219b-f3fa-48dd-8058-08d9aad730b8 X-MS-TrafficTypeDiagnostic: PH0PR02MB7173: 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: r+weUslaDX37W2V0r24GMe0ND3TlL74FfzE5AwpxdkHsqS5OmQq/dCkRVynA4Uw6Tz6fNlVPqTEA8VAxd0iM4BA3GiWjMWYPCSepjXcyNPCtekZYLNrpJdvYHvwuLWX75LQIYwCHu0nyqearvMVL8s7K2l1vYy84bevQQc+3WexbQtW6a27P9SciiKJbbXYFP6oAA+oVV+xqD7HkK3SHgxMbh99f+NGcp/oku7htEHpOwaGL7Bc5BjkaubExK8wmNrN49XBzue4h8UmUzyJqFrC0jGO52uZEKO4qlKLEw5g1iyiRoOAYzUFy/u5aRGzJjlORhR2hte5xEZaC4sIqwgdYoZUVnvC8xnDQviYGQtOpch8dv8fy4y3kGcUKuFhqoZPu/jl/9eysdQQGbFjqHY9HKlhdRalIYWogSbjqPwNR5WT9ww964Gdp0+haCEY3smX184a35fgV6riZeKXZ4CaLqosGEXRWDDql58KcWYY2jQ63gmZuiQtVgmgyLXuFKBEr3lDeUbH2FkN3Bc+Zhx4vo8uIgKG1GrTvSfifCv++p9D3SD4oXUP3ePvtXH4TaBrM7P1xvo5F+irhsc4Df9SOobJvbmSLicbyDgEclpX4AzCL1lAv5tc1Y2jISskKRbHQa8w3Dd+dSvyN0PiO9alee1auuUYaqEsftQx1LVTVRwwHqYtjCy/xgJLiwfr7EDxIyZx2deomUXeUiJoywQ== 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)(8936002)(8676002)(36860700001)(42186006)(426003)(36906005)(2906002)(54906003)(186003)(1076003)(82310400003)(26005)(83380400001)(316002)(70206006)(356005)(508600001)(107886003)(47076005)(4326008)(6666004)(336012)(7636003)(5660300002)(36756003)(2616005)(6916009)(70586007)(44832011)(6266002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2021 21:05:46.0314 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3bf3219b-f3fa-48dd-8058-08d9aad730b8 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: BN1NAM02FT016.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR02MB7173 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");