XRT Alveo driver overview
Subsystems (2)
v7 cover XRT Alveo driver overview
Hello,
This is V7 of patch series which adds management physical function driver for Xilinx Alveo PCIe accelerator cards.
https://www.xilinx.com/products/boards-and-kits/alveo.html
This driver is part of Xilinx Runtime (XRT) open source stack.
XILINX ALVEO PLATFORM ARCHITECTURE
Alveo PCIe FPGA based platforms have a static *shell* partition and a partial re-configurable *user* partition. The shell partition is automatically loaded from flash when host is booted and PCIe is enumerated by BIOS. Shell cannot be changed till the next cold reboot. The shell exposes two PCIe physical functions:
1. management physical function
2. user physical function
The patch series includes Documentation/xrt.rst which describes Alveo platform, XRT driver architecture and deployment model in more detail.
Users compile their high level design in C/C++/OpenCL or RTL into FPGA image using Vitis tools.
https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html
The compiled image is packaged as xclbin which contains partial bitstream for the user partition and necessary metadata. Users can dynamically swap the image running on the user partition in order to switch between different workloads by loading different xclbins.
XRT DRIVERS FOR XILINX ALVEO
XRT Linux kernel driver *xrt-mgmt* binds to management physical function of Alveo platform. The modular driver framework is organized into several platform drivers which primarily handle the following functionality:
1. Loading firmware container also called xsabin at driver attach time 2. Loading of user compiled xclbin with FPGA Manager integration 3. Clock scaling of image running on user partition 4. In-band sensors: temp, voltage, power, etc. 5. Device reset and rescan
The platform drivers are packaged into *xrt-lib* helper module with well defined interfaces. The module provides a pseudo-bus implementation for the platform drivers. More details on the driver model can be found in Documentation/xrt.rst.
User physical function driver is not included in this patch series.
LIBFDT REQUIREMENT
XRT driver infrastructure uses Device Tree as a metadata format to discover HW subsystems in the Alveo PCIe device. The Device Tree schema used by XRT is documented in Documentation/xrt.rst.
TESTING AND VALIDATION
xrt-mgmt driver can be tested with full XRT open source stack which includes user space libraries, board utilities and (out of tree) first generation user physical function driver xocl. XRT open source runtime stack is available at https://github.com/Xilinx/XRT
Complete documentation for XRT open source stack including sections on Alveo/XRT security and platform architecture can be found here:
https://xilinx.github.io/XRT/master/html/index.html
https://xilinx.github.io/XRT/master/html/security.html
https://xilinx.github.io/XRT/master/html/platforms_partitions.html
Changes since v6:
- Resolved grammatical errors and cleaned up taxonomy in xrt.rst documentation.
- Fixed clang warnings.
- Updated code base to include v6 code review comments.
Changes since v5:
- Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
- Updated code base to include v5 code review comments. xrt.rst: address grammar and taxonomy subdev_id.h: defines XRT_SUBDEV_INVALID = 0 xclbin.c: change shift operation to be_to_cpu
- Resolved kernel test robot errors.
Changes since v4:
- Added xrt_bus_type and xrt_device. All sub devices were changed from platform_bus_type/platform_device to xrt_bus_type/xrt_device.
- Renamed xrt-mgmt driver to xrt-mgnt driver.
- Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file names
- Moved pci function calls from infrastructure to xrt-mgnt driver.
- Renamed files: mgmt/main.c -> mgnt/xmgnt-main.c
mgmt/main-region.c -> mgnt/xmgnt-main-region.c
include/xmgmt-main.h -> include/xmgnt-main.h
mgmt/fmgr-drv.c -> mgnt/xrt-mgr.c
mgmt/fmgr.h -> mgnt/xrt-mgr.h- Updated code base to include v4 code review comments.
Changes since v3:
- Leaf drivers use regmap-mmio to access hardware registers.
- Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
- Renamed files: calib.[c|h] -> ddr_calibration.[c|h], lib/main.[c|h] -> lib/lib-drv.[c|h], mgmt/main-impl.h - > mgmt/xmgnt.h
- Updated code base to include v3 code review comments.
Changes since v2:
- Streamlined the driver framework into *xleaf*, *group* and *xroot*
- Updated documentation to show the driver model with examples
- Addressed kernel test robot errors
- Added a selftest for basic driver framework
- Documented device tree schema
- Removed need to export libfdt symbols
Changes since v1:
- Updated the driver to use fpga_region and fpga_bridge for FPGA programming
- Dropped platform drivers not related to PR programming to focus on XRT core framework
- Updated Documentation/fpga/xrt.rst with information on XRT core framework
- Addressed checkpatch issues
- Dropped xrt- prefix from some header files
For reference V6 version of patch series can be found here:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
Lizhi Hou (20):
Documentation: fpga: Add a document describing XRT Alveo drivers
fpga: xrt: driver metadata helper functions
fpga: xrt: xclbin file helper functions
fpga: xrt: xrt-lib driver manager
fpga: xrt: group driver
fpga: xrt: char dev node helper functions
fpga: xrt: root driver infrastructure
fpga: xrt: driver infrastructure
fpga: xrt: management physical function driver (root)
fpga: xrt: main driver for management function device
fpga: xrt: fpga-mgr and region implementation for xclbin download
fpga: xrt: VSEC driver
fpga: xrt: User Clock Subsystem driver
fpga: xrt: ICAP driver
fpga: xrt: devctl xrt driver
fpga: xrt: clock driver
fpga: xrt: clock frequency counter driver
fpga: xrt: DDR calibration driver
fpga: xrt: partition isolation driver
fpga: xrt: Kconfig and Makefile updates for XRT drivers
Documentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 870 ++++++++++++++++++ MAINTAINERS | 11 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 2 + drivers/fpga/Makefile | 5 + drivers/fpga/xrt/Kconfig | 8 + drivers/fpga/xrt/include/events.h | 45 + drivers/fpga/xrt/include/group.h | 25 + drivers/fpga/xrt/include/metadata.h | 236 +++++ drivers/fpga/xrt/include/subdev_id.h | 39 + drivers/fpga/xrt/include/xclbin-helper.h | 48 + drivers/fpga/xrt/include/xdevice.h | 131 +++ drivers/fpga/xrt/include/xleaf.h | 205 +++++ drivers/fpga/xrt/include/xleaf/axigate.h | 23 + drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 + drivers/fpga/xrt/include/xleaf/clock.h | 29 + .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 + drivers/fpga/xrt/include/xleaf/devctl.h | 40 + drivers/fpga/xrt/include/xleaf/icap.h | 27 + drivers/fpga/xrt/include/xmgmt-main.h | 34 + drivers/fpga/xrt/include/xroot.h | 117 +++ drivers/fpga/xrt/lib/Kconfig | 17 + drivers/fpga/xrt/lib/Makefile | 30 + drivers/fpga/xrt/lib/cdev.c | 209 +++++ drivers/fpga/xrt/lib/group.c | 278 ++++++ drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++ drivers/fpga/xrt/lib/lib-drv.h | 21 + drivers/fpga/xrt/lib/subdev.c | 859 +++++++++++++++++ drivers/fpga/xrt/lib/subdev_pool.h | 53 ++ drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++ drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++ drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++ drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++ drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++ drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++ drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++ drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++ drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++ drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++ drivers/fpga/xrt/metadata/Kconfig | 12 + drivers/fpga/xrt/metadata/Makefile | 16 + drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++ drivers/fpga/xrt/mgmt/Kconfig | 15 + drivers/fpga/xrt/mgmt/Makefile | 19 + drivers/fpga/xrt/mgmt/root.c | 420 +++++++++ drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++ drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++ drivers/fpga/xrt/mgmt/xmgmt.h | 33 + drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++ drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + include/uapi/linux/xrt/xclbin.h | 409 ++++++++ include/uapi/linux/xrt/xmgmt-ioctl.h | 46 + 53 files changed, 9988 insertions(+) create mode 100644 Documentation/fpga/xrt.rst create mode 100644 drivers/fpga/xrt/Kconfig create mode 100644 drivers/fpga/xrt/include/events.h create mode 100644 drivers/fpga/xrt/include/group.h create mode 100644 drivers/fpga/xrt/include/metadata.h create mode 100644 drivers/fpga/xrt/include/subdev_id.h create mode 100644 drivers/fpga/xrt/include/xclbin-helper.h create mode 100644 drivers/fpga/xrt/include/xdevice.h create mode 100644 drivers/fpga/xrt/include/xleaf.h create mode 100644 drivers/fpga/xrt/include/xleaf/axigate.h create mode 100644 drivers/fpga/xrt/include/xleaf/clkfreq.h create mode 100644 drivers/fpga/xrt/include/xleaf/clock.h create mode 100644 drivers/fpga/xrt/include/xleaf/ddr_calibration.h create mode 100644 drivers/fpga/xrt/include/xleaf/devctl.h create mode 100644 drivers/fpga/xrt/include/xleaf/icap.h create mode 100644 drivers/fpga/xrt/include/xmgmt-main.h create mode 100644 drivers/fpga/xrt/include/xroot.h create mode 100644 drivers/fpga/xrt/lib/Kconfig create mode 100644 drivers/fpga/xrt/lib/Makefile create mode 100644 drivers/fpga/xrt/lib/cdev.c create mode 100644 drivers/fpga/xrt/lib/group.c 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/subdev.c create mode 100644 drivers/fpga/xrt/lib/subdev_pool.h create mode 100644 drivers/fpga/xrt/lib/xclbin.c create mode 100644 drivers/fpga/xrt/lib/xleaf/axigate.c create mode 100644 drivers/fpga/xrt/lib/xleaf/clkfreq.c create mode 100644 drivers/fpga/xrt/lib/xleaf/clock.c create mode 100644 drivers/fpga/xrt/lib/xleaf/ddr_calibration.c create mode 100644 drivers/fpga/xrt/lib/xleaf/devctl.c create mode 100644 drivers/fpga/xrt/lib/xleaf/icap.c create mode 100644 drivers/fpga/xrt/lib/xleaf/ucs.c create mode 100644 drivers/fpga/xrt/lib/xleaf/vsec.c create mode 100644 drivers/fpga/xrt/lib/xroot.c create mode 100644 drivers/fpga/xrt/metadata/Kconfig create mode 100644 drivers/fpga/xrt/metadata/Makefile create mode 100644 drivers/fpga/xrt/metadata/metadata.c create mode 100644 drivers/fpga/xrt/mgmt/Kconfig create mode 100644 drivers/fpga/xrt/mgmt/Makefile create mode 100644 drivers/fpga/xrt/mgmt/root.c create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-main-region.c create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-main.c create mode 100644 drivers/fpga/xrt/mgmt/xmgmt.h create mode 100644 drivers/fpga/xrt/mgmt/xrt-mgr.c create mode 100644 drivers/fpga/xrt/mgmt/xrt-mgr.h create mode 100644 include/uapi/linux/xrt/xclbin.h create mode 100644 include/uapi/linux/xrt/xmgmt-ioctl.h
Signature · 1 line
2.27.0
PATCH v7 1/20 Documentation: fpga: Add a document describing XRT Alveo drivers
Describe XRT driver architecture and provide basic overview of Xilinx Alveo platform.
--- Documentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 870 +++++++++++++++++++++++++++++++++++ MAINTAINERS | 11 + 3 files changed, 882 insertions(+) create mode 100644 Documentation/fpga/xrt.rst
Documentation/fpga/index.rst +1 -0
@@ -8,6 +8,7 @@ fpga :maxdepth: 1 dfl + xrt .. only:: subproject and html
Documentation/fpga/xrt.rst new file +870 -0
870 lines not on this page · raw message
MAINTAINERS +11 -0
@@ -7136,6 +7136,17 @@ F: Documentation/fpga/ F: drivers/fpga/ F: include/linux/fpga/ +FPGA XRT DRIVERS +M: Lizhi Hou <[email protected]> +R: Max Zhen <[email protected]> +R: Sonal Santan <[email protected]> +L: [email protected] +S: Supported +W: https://github.com/Xilinx/XRT +F: Documentation/fpga/xrt.rst +F: drivers/fpga/xrt/ +F: include/uapi/linux/xrt/ + FPU EMULATOR M: Bill Metzenthen <[email protected]> S: Maintained
Signature · 1 line
2.27.0
PATCH v7 2/20 fpga: xrt: driver metadata helper functions
In reply to Lizhi HouXRT drivers use device tree as metadata format to discover HW subsystems behind PCIe BAR. Thus libfdt functions are called for the driver to parse the device tree blob.
--- drivers/fpga/xrt/include/metadata.h | 236 +++++++++++ drivers/fpga/xrt/metadata/metadata.c | 578 +++++++++++++++++++++++++++ 2 files changed, 814 insertions(+) create mode 100644 drivers/fpga/xrt/include/metadata.h create mode 100644 drivers/fpga/xrt/metadata/metadata.c
drivers/fpga/xrt/include/metadata.h new file +236 -0
@@ -0,0 +1,236 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou <[email protected]> +*/ + +#ifndef _XRT_METADATA_H +#define _XRT_METADATA_H + +#include <linux/device.h> +#include <linux/vmalloc.h> +#include <linux/uuid.h> + +#define XRT_MD_INVALID_LENGTH (~0U) + +/* metadata properties */ +#define XRT_MD_PROP_BAR_IDX "pcie_bar_mapping" +#define XRT_MD_PROP_COMPATIBLE "compatible" +#define XRT_MD_PROP_HWICAP "axi_hwicap" +#define XRT_MD_PROP_INTERFACE_UUID "interface_uuid" +#define XRT_MD_PROP_INTERRUPTS "interrupts" +#define XRT_MD_PROP_IO_OFFSET "reg" +#define XRT_MD_PROP_LOGIC_UUID "logic_uuid" +#define XRT_MD_PROP_PDI_CONFIG "pdi_config_mem" +#define XRT_MD_PROP_PF_NUM "pcie_physical_function" +#define XRT_MD_PROP_VERSION_MAJOR "firmware_version_major" + +/* non IP nodes */ +#define XRT_MD_NODE_ENDPOINTS "addressable_endpoints" +#define XRT_MD_NODE_FIRMWARE "firmware" +#define XRT_MD_NODE_INTERFACES "interfaces" +#define XRT_MD_NODE_PARTITION_INFO "partition_info" + +/* +* IP nodes +* AF: AXI Firewall +* CMC: Card Management Controller +* ERT: Embedded Runtime +* EP: End Point +* PLP: Provider Reconfigurable Partition +* ULP: User Reconfigurable Partition +*/ +#define XRT_MD_NODE_ADDR_TRANSLATOR "ep_remap_data_c2h_00" +#define XRT_MD_NODE_AF_BLP_CTRL_MGMT "ep_firewall_blp_ctrl_mgmt_00" +#define XRT_MD_NODE_AF_BLP_CTRL_USER "ep_firewall_blp_ctrl_user_00" +#define XRT_MD_NODE_AF_CTRL_DEBUG "ep_firewall_ctrl_debug_00" +#define XRT_MD_NODE_AF_CTRL_MGMT "ep_firewall_ctrl_mgmt_00" +#define XRT_MD_NODE_AF_CTRL_USER "ep_firewall_ctrl_user_00" +#define XRT_MD_NODE_AF_DATA_C2H "ep_firewall_data_c2h_00"/* c2h: card to host */ +#define XRT_MD_NODE_AF_DATA_H2C "ep_firewall_data_h2c_00"/* h2c: host to card */ +#define XRT_MD_NODE_AF_DATA_M2M "ep_firewall_data_m2m_00" +#define XRT_MD_NODE_AF_DATA_P2P "ep_firewall_data_p2p_00" +#define XRT_MD_NODE_CLKFREQ_HBM "ep_freq_cnt_aclk_hbm_00"/* hbm: High Bandwidth Memory */ +#define XRT_MD_NODE_CLKFREQ_K1 "ep_freq_cnt_aclk_kernel_00" +#define XRT_MD_NODE_CLKFREQ_K2 "ep_freq_cnt_aclk_kernel_01" +#define XRT_MD_NODE_CLK_KERNEL1 "ep_aclk_kernel_00" +#define XRT_MD_NODE_CLK_KERNEL2 "ep_aclk_kernel_01" +#define XRT_MD_NODE_CLK_KERNEL3 "ep_aclk_hbm_00" +#define XRT_MD_NODE_CLK_SHUTDOWN "ep_aclk_shutdown_00" +#define XRT_MD_NODE_CMC_FW_MEM "ep_cmc_firmware_mem_00" +#define XRT_MD_NODE_CMC_MUTEX "ep_cmc_mutex_00" +#define XRT_MD_NODE_CMC_REG "ep_cmc_regmap_00" +#define XRT_MD_NODE_CMC_RESET "ep_cmc_reset_00" +#define XRT_MD_NODE_DDR_CALIB "ep_ddr_mem_calib_00" +#define XRT_MD_NODE_DDR4_RESET_GATE "ep_ddr_mem_srsr_gate_00" +#define XRT_MD_NODE_ERT_BASE "ep_ert_base_address_00" +#define XRT_MD_NODE_ERT_CQ_MGMT "ep_ert_command_queue_mgmt_00" +#define XRT_MD_NODE_ERT_CQ_USER "ep_ert_command_queue_user_00" +#define XRT_MD_NODE_ERT_FW_MEM "ep_ert_firmware_mem_00" +#define XRT_MD_NODE_ERT_RESET "ep_ert_reset_00" +#define XRT_MD_NODE_ERT_SCHED "ep_ert_sched_00" +#define XRT_MD_NODE_FLASH "ep_card_flash_program_00" +#define XRT_MD_NODE_FPGA_CONFIG "ep_fpga_configuration_00" +#define XRT_MD_NODE_GAPPING "ep_gapping_demand_00" +#define XRT_MD_NODE_GATE_PLP "ep_pr_isolate_plp_00" +#define XRT_MD_NODE_GATE_ULP "ep_pr_isolate_ulp_00" +#define XRT_MD_NODE_KDMA_CTRL "ep_kdma_ctrl_00" +#define XRT_MD_NODE_MAILBOX_MGMT "ep_mailbox_mgmt_00" +#define XRT_MD_NODE_MAILBOX_USER "ep_mailbox_user_00" +#define XRT_MD_NODE_MAILBOX_XRT "ep_mailbox_user_to_ert_00" +#define XRT_MD_NODE_MSIX "ep_msix_00" +#define XRT_MD_NODE_P2P "ep_p2p_00" +#define XRT_MD_NODE_PCIE_MON "ep_pcie_link_mon_00" +#define XRT_MD_NODE_PMC_INTR "ep_pmc_intr_00" +#define XRT_MD_NODE_PMC_MUX "ep_pmc_mux_00" +#define XRT_MD_NODE_QDMA "ep_qdma_00" +#define XRT_MD_NODE_QDMA4 "ep_qdma4_00" +#define XRT_MD_NODE_REMAP_P2P "ep_remap_p2p_00" +#define XRT_MD_NODE_STM "ep_stream_traffic_manager_00" +#define XRT_MD_NODE_STM4 "ep_stream_traffic_manager4_00" +#define XRT_MD_NODE_SYSMON "ep_cmp_sysmon_00" +#define XRT_MD_NODE_XDMA "ep_xdma_00" +#define XRT_MD_NODE_XVC_PUB "ep_debug_bscan_user_00" +#define XRT_MD_NODE_XVC_PRI "ep_debug_bscan_mgmt_00" +#define XRT_MD_NODE_UCS_CONTROL_STATUS "ep_ucs_control_status_00" + +/* endpoint compatible string */ +#define XRT_MD_COMPAT_DDR_SRSR "drv_ddr_srsr" +#define XRT_MD_COMPAT_CLKFREQ "freq_cnt" + +/* driver defined endpoints */ +#define XRT_MD_NODE_BLP_ROM "drv_ep_blp_rom_00" +#define XRT_MD_NODE_DDR_SRSR "drv_ep_ddr_srsr" +#define XRT_MD_NODE_FLASH_VSEC "drv_ep_card_flash_program_00" +#define XRT_MD_NODE_GOLDEN_VER "drv_ep_golden_ver_00" +#define XRT_MD_NODE_MAILBOX_VSEC "drv_ep_mailbox_vsec_00" +#define XRT_MD_NODE_MGMT_MAIN "drv_ep_mgmt_main_00" +#define XRT_MD_NODE_PLAT_INFO "drv_ep_platform_info_mgmt_00" +#define XRT_MD_NODE_PARTITION_INFO_BLP "partition_info_0" +#define XRT_MD_NODE_PARTITION_INFO_PLP "partition_info_1" +#define XRT_MD_NODE_TEST "drv_ep_test_00" +#define XRT_MD_NODE_VSEC "drv_ep_vsec_00" +#define XRT_MD_NODE_VSEC_GOLDEN "drv_ep_vsec_golden_00" + +/* driver defined properties */ +#define XRT_MD_PROP_OFFSET "drv_offset" +#define XRT_MD_PROP_CLK_FREQ "drv_clock_frequency" +#define XRT_MD_PROP_CLK_CNT "drv_clock_frequency_counter" +#define XRT_MD_PROP_VBNV "vbnv" +#define XRT_MD_PROP_VROM "vrom" +#define XRT_MD_PROP_PARTITION_LEVEL "partition_level" + +struct xrt_md_endpoint { +const char *ep_name; +u32 bar_index; +u64 bar_off; +u64 size; +char *compat; +char *compat_ver; +}; + +/* Note: res_id is defined by leaf driver and must start with 0. */ +struct xrt_iores_map { +char *res_name; +int res_id; +}; + +static inline int xrt_md_res_name2id (const struct xrt_iores_map *res_map, +int entry_num,const char *res_name) +{ +int i; + +for (i =0 ; i < entry_num; i++) { +if (!strncmp (res_name, res_map->res_name,strlen (res_map->res_name) +1 )) +return res_map->res_id; + res_map++; + } +return -1 ; +} + +static inline const char * +xrt_md_res_id2name (const struct xrt_iores_map *res_map,int entry_num,int id) +{ +int i; + +for (i =0 ; i < entry_num; i++) { +if (res_map->res_id == id) +return res_map->res_name; + res_map++; + } +return NULL ; +} + +u32 xrt_md_size (struct device *dev,const char *blob); +int xrt_md_create (struct device *dev,char **blob); +char *xrt_md_dup (struct device *dev,const char *blob); +int xrt_md_add_endpoint (struct device *dev,char *blob, +struct xrt_md_endpoint *ep); +int xrt_md_del_endpoint (struct device *dev,char *blob,const char *ep_name, +const char *compat); +int xrt_md_get_prop (struct device *dev,const char *blob,const char *ep_name, +const char *compat,const char *prop, +const void **val,int *size); +int xrt_md_set_prop (struct device *dev,char *blob,const char *ep_name, +const char *compat,const char *prop, +const void *val,int size); +int xrt_md_copy_endpoint (struct device *dev,char *blob,const char *src_blob, +const char *ep_name,const char *compat, +const char *new_ep_name); +int xrt_md_get_next_endpoint (struct device *dev,const char *blob, +const char *ep_name,const char *compat, +char **next_ep,char **next_compat); +int xrt_md_get_compatible_endpoint (struct device *dev,const char *blob, +const char *compat,const char **ep_name); +int xrt_md_find_endpoint (struct device *dev,const char *blob, +const char *ep_name,const char *compat, +const char **epname); +int xrt_md_pack (struct device *dev,char *blob); +int xrt_md_get_interface_uuids (struct device *dev,const char *blob, +u32 num_uuids,uuid_t *intf_uuids); + +/* +* The firmware provides a 128 bit hash string as a unique id to the +* partition/interface. +* Existing hw does not yet use the cononical form, so it is necessary to +* use a translation function. +*/ +static inline void xrt_md_trans_uuid2str (const uuid_t *uuid,char *uuidstr) +{ +int i, p; +u8 tmp[UUID_SIZE ]; + +BUILD_BUG_ON (UUID_SIZE !=16 ); +export_uuid (tmp, uuid); +for (p =0 , i =UUID_SIZE -1 ; i >=0 ; p++, i--) +snprintf (&uuidstr[p *2 ],3 ,"%02x" , tmp[i]); +} + +static inline int xrt_md_trans_str2uuid (struct device *dev,const char *uuidstr,uuid_t *p_uuid) +{ +u8 p[UUID_SIZE ]; +const char *str; +char tmp[3 ] = {0 }; +int i, ret; + +if (strlen (uuidstr) !=UUID_SIZE *2 ) +return -EINVAL ; + + str = uuidstr +strlen (uuidstr) -2 ; + +for (i =0 ; i <sizeof (*p_uuid) && str >= uuidstr; i++) { + tmp[0 ] = *str; + tmp[1 ] = *(str +1 ); + ret =kstrtou8 (tmp,16 , &p[i]); +if (ret) +return -EINVAL ; + str -=2 ; + } +import_uuid (p_uuid, p); + +return 0 ; +} + +#endif
drivers/fpga/xrt/metadata/metadata.c new file +578 -0
578 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 3/20 fpga: xrt: xclbin file helper functions
In reply to Lizhi HouAlveo FPGA firmware and partial reconfigure file are in xclbin format. This code enumerates and extracts sections from xclbin files. xclbin.h is cross platform and used across all platforms and OS.
--- drivers/fpga/xrt/include/xclbin-helper.h | 48 +++ drivers/fpga/xrt/lib/xclbin.c | 381 +++++++++++++++++++++ include/uapi/linux/xrt/xclbin.h | 409 +++++++++++++++++++++++ 3 files changed, 838 insertions(+) create mode 100644 drivers/fpga/xrt/include/xclbin-helper.h create mode 100644 drivers/fpga/xrt/lib/xclbin.c create mode 100644 include/uapi/linux/xrt/xclbin.h
drivers/fpga/xrt/include/xclbin-helper.h new file +48 -0
@@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* David Zhang <[email protected]> +* Sonal Santan <[email protected]> +*/ + +#ifndef _XCLBIN_HELPER_H_ +#define _XCLBIN_HELPER_H_ + +#include <linux/types.h> +#include <linux/device.h> +#include <linux/xrt/xclbin.h> + +#define XCLBIN_VERSION2 "xclbin2" +#define XCLBIN_HWICAP_BITFILE_BUF_SZ 1024 +#define XCLBIN_MAX_SZ_1G (1024 * 1024 * 1024)/* Assuming xclbin <= 1G, always */ + +enum axlf_section_kind ; +struct axlf ; + +/** +* Bitstream header information as defined by Xilinx tools. +* Please note that this struct definition is not owned by the driver. +*/ +struct xclbin_bit_head_info { +u32 header_length;/* Length of header in 32 bit words */ +u32 bitstream_length;/* Length of bitstream to read in bytes */ +const unchar *design_name;/* Design name get from bitstream */ +const unchar *part_name;/* Part name read from bitstream */ +const unchar *date;/* Date read from bitstream header */ +const unchar *time;/* Bitstream creation time */ +u32 magic_length;/* Length of the magic numbers */ +const unchar *version;/* Version string */ +}; + +/* caller must free the allocated memory for **data. len could be NULL. */ +int xrt_xclbin_get_section (struct device *dev,const struct axlf *xclbin, +enum axlf_section_kind kind,void **data, +uint64_t *len); +int xrt_xclbin_get_metadata (struct device *dev,const struct axlf *xclbin,char **dtb); +int xrt_xclbin_parse_bitstream_header (struct device *dev,const unchar *data, +u32 size,struct xclbin_bit_head_info *head_info); +const char *xrt_clock_type2epname (enum XCLBIN_CLOCK_TYPE type); + +#endif /* _XCLBIN_HELPER_H_ */
drivers/fpga/xrt/lib/xclbin.c new file +381 -0
381 lines not on this page · raw message
include/uapi/linux/xrt/xclbin.h new file +409 -0
409 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 4/20 fpga: xrt: xrt-lib driver manager
In reply to Lizhi Houxrt-lib kernel module infrastructure code to register and manage all leaf driver modules.
--- drivers/fpga/xrt/include/subdev_id.h | 39 ++++ drivers/fpga/xrt/include/xdevice.h | 131 +++++++++++ drivers/fpga/xrt/include/xleaf.h | 205 +++++++++++++++++ drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++++++++++++++++++++++ drivers/fpga/xrt/lib/lib-drv.h | 21 ++ 5 files changed, 724 insertions(+) create mode 100644 drivers/fpga/xrt/include/subdev_id.h create mode 100644 drivers/fpga/xrt/include/xdevice.h create mode 100644 drivers/fpga/xrt/include/xleaf.h create mode 100644 drivers/fpga/xrt/lib/lib-drv.c create mode 100644 drivers/fpga/xrt/lib/lib-drv.h
drivers/fpga/xrt/include/subdev_id.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#ifndef _XRT_SUBDEV_ID_H_ +#define _XRT_SUBDEV_ID_H_ + +/* +* Every subdev driver has an ID for others to refer to it. There can be multiple number of +* instances of a subdev driver. A <subdev_id, subdev_instance> tuple is a unique identification +* of a specific instance of a subdev driver. +*/ +enum xrt_subdev_id { +XRT_SUBDEV_INVALID =0 , +XRT_SUBDEV_GRP , +XRT_SUBDEV_VSEC , +XRT_SUBDEV_VSEC_GOLDEN , +XRT_SUBDEV_DEVCTL , +XRT_SUBDEV_AXIGATE , +XRT_SUBDEV_ICAP , +XRT_SUBDEV_TEST , +XRT_SUBDEV_MGMT_MAIN , +XRT_SUBDEV_QSPI , +XRT_SUBDEV_MAILBOX , +XRT_SUBDEV_CMC , +XRT_SUBDEV_CALIB , +XRT_SUBDEV_CLKFREQ , +XRT_SUBDEV_CLOCK , +XRT_SUBDEV_SRSR , +XRT_SUBDEV_UCS , +XRT_SUBDEV_NUM ,/* Total number of subdevs. */ +XRT_ROOT =-1 ,/* Special ID for root driver. */ +}; + +#endif /* _XRT_SUBDEV_ID_H_ */
drivers/fpga/xrt/include/xdevice.h new file +131 -0
131 lines not on this page · raw message
drivers/fpga/xrt/include/xleaf.h new file +205 -0
205 lines not on this page · raw message
drivers/fpga/xrt/lib/lib-drv.c new file +328 -0
328 lines not on this page · raw message
drivers/fpga/xrt/lib/lib-drv.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#ifndef _LIB_DRV_H_ +#define _LIB_DRV_H_ + +#include <linux/device/class.h> +#include <linux/device/bus.h> + +extern struct class *xrt_class; +extern struct bus_type xrt_bus_type; + +const char *xrt_drv_name (enum xrt_subdev_id id); +struct xrt_dev_endpoints *xrt_drv_get_endpoints (enum xrt_subdev_id id); + +#endif /* _LIB_DRV_H_ */
Signature · 1 line
2.27.0
PATCH v7 5/20 fpga: xrt: group driver
In reply to Lizhi Hougroup driver that manages life cycle of a bunch of leaf driver instances and bridges them with root.
--- drivers/fpga/xrt/include/group.h | 25 +++ drivers/fpga/xrt/lib/group.c | 278 +++++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 drivers/fpga/xrt/include/group.h create mode 100644 drivers/fpga/xrt/lib/group.c
drivers/fpga/xrt/include/group.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#ifndef _XRT_GROUP_H_ +#define _XRT_GROUP_H_ + +#include "xleaf.h" + +/* +* Group driver leaf calls. +*/ +enum xrt_group_leaf_cmd { +XRT_GROUP_GET_LEAF =XRT_XLEAF_CUSTOM_BASE ,/* See comments in xleaf.h */ +XRT_GROUP_PUT_LEAF , +XRT_GROUP_INIT_CHILDREN , +XRT_GROUP_FINI_CHILDREN , +XRT_GROUP_TRIGGER_EVENT , +}; + +#endif /* _XRT_GROUP_H_ */
drivers/fpga/xrt/lib/group.c new file +278 -0
278 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 6/20 fpga: xrt: char dev node helper functions
In reply to Lizhi HouHelper functions for char device node creation / removal for xrt drivers. This is part of xrt driver infrastructure.
--- drivers/fpga/xrt/lib/cdev.c | 209 ++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 drivers/fpga/xrt/lib/cdev.c
drivers/fpga/xrt/lib/cdev.c new file +209 -0
@@ -0,0 +1,209 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Xilinx Alveo FPGA device node helper functions. +* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#include "xleaf.h" +#include "lib-drv.h" + +#define XRT_CDEV_DIR "xrt" +#define INODE2PDATA (inode) \ + container_of((inode)->i_cdev, struct xrt_subdev_platdata, xsp_cdev) +#define INODE2PDEV (inode) \ + to_xrt_dev(kobj_to_dev((inode)->i_cdev->kobj.parent)) +#define CDEV_NAME (sysdev) (strchr((sysdev)->kobj.name, '!') + 1) + +/* Allow it to be accessed from cdev. */ +static void xleaf_devnode_allowed (struct xrt_device *xdev) +{ +struct xrt_subdev_platdata *pdata =DEV_PDATA (xdev); + +/* Allow new opens. */ +mutex_lock (&pdata->xsp_devnode_lock); + pdata->xsp_devnode_online = true; +mutex_unlock (&pdata->xsp_devnode_lock); +} + +/* Turn off access from cdev and wait for all existing user to go away. */ +static void xleaf_devnode_disallowed (struct xrt_device *xdev) +{ +struct xrt_subdev_platdata *pdata =DEV_PDATA (xdev); + +mutex_lock (&pdata->xsp_devnode_lock); + +/* Prevent new opens. */ + pdata->xsp_devnode_online = false; +/* Wait for existing user to close. */ +while (pdata->xsp_devnode_ref) { +mutex_unlock (&pdata->xsp_devnode_lock); +wait_for_completion (&pdata->xsp_devnode_comp); +mutex_lock (&pdata->xsp_devnode_lock); + } + +mutex_unlock (&pdata->xsp_devnode_lock); +} + +static struct xrt_device * +__xleaf_devnode_open (struct inode *inode,bool excl) +{ +struct xrt_subdev_platdata *pdata =INODE2PDATA (inode); +struct xrt_device *xdev =INODE2PDEV (inode); +bool opened = false; + +mutex_lock (&pdata->xsp_devnode_lock); + +if (pdata->xsp_devnode_online) { +if (excl && pdata->xsp_devnode_ref) { +xrt_err (xdev,"%s has already been opened exclusively" , +CDEV_NAME (pdata->xsp_sysdev)); + }else if (!excl && pdata->xsp_devnode_excl) { +xrt_err (xdev,"%s has been opened exclusively" , +CDEV_NAME (pdata->xsp_sysdev)); + }else { + pdata->xsp_devnode_ref++; + pdata->xsp_devnode_excl = excl; + opened = true; +xrt_info (xdev,"opened %s, ref=%d" , +CDEV_NAME (pdata->xsp_sysdev), + pdata->xsp_devnode_ref); + } + }else { +xrt_err (xdev,"%s is offline" ,CDEV_NAME (pdata->xsp_sysdev)); + } + +mutex_unlock (&pdata->xsp_devnode_lock); + + xdev = opened ? xdev :NULL ; +return xdev; +} + +struct xrt_device * +xleaf_devnode_open_excl (struct inode *inode) +{ +return __xleaf_devnode_open (inode, true); +} + +struct xrt_device * +xleaf_devnode_open (struct inode *inode) +{ +return __xleaf_devnode_open (inode, false); +} +EXPORT_SYMBOL_GPL (xleaf_devnode_open); + +void xleaf_devnode_close (struct inode *inode) +{ +struct xrt_subdev_platdata *pdata =INODE2PDATA (inode); +struct xrt_device *xdev =INODE2PDEV (inode); +bool notify = false; + +mutex_lock (&pdata->xsp_devnode_lock); + +WARN_ON (pdata->xsp_devnode_ref ==0 ); + pdata->xsp_devnode_ref--; +if (pdata->xsp_devnode_ref ==0 ) { + pdata->xsp_devnode_excl = false; + notify = true; + } +if (notify) +xrt_info (xdev,"closed %s" ,CDEV_NAME (pdata->xsp_sysdev)); +else +xrt_info (xdev,"closed %s, notifying waiter" ,CDEV_NAME (pdata->xsp_sysdev)); + +mutex_unlock (&pdata->xsp_devnode_lock); + +if (notify) +complete (&pdata->xsp_devnode_comp); +} +EXPORT_SYMBOL_GPL (xleaf_devnode_close); + +static inline enum xrt_dev_file_mode +devnode_mode (struct xrt_device *xdev) +{ +return DEV_FILE_OPS (xdev)->xsf_mode; +} + +int xleaf_devnode_create (struct xrt_device *xdev,const char *file_name, +const char *inst_name) +{ +struct xrt_subdev_platdata *pdata =DEV_PDATA (xdev); +struct xrt_dev_file_ops *fops =DEV_FILE_OPS (xdev); +struct cdev *cdevp; +struct device *sysdev; +int ret =0 ; +char fname[256 ]; + +mutex_init (&pdata->xsp_devnode_lock); +init_completion (&pdata->xsp_devnode_comp); + + cdevp = &DEV_PDATA (xdev)->xsp_cdev; +cdev_init (cdevp, &fops->xsf_ops); + cdevp->owner = fops->xsf_ops.owner; + cdevp->dev =MKDEV (MAJOR (fops->xsf_dev_t), xdev->instance); + +/* +* Set xdev as parent of cdev so that when xdev (and its platform +* data) will not be freed when cdev is not freed. +*/ +cdev_set_parent (cdevp, &DEV (xdev)->kobj); + + ret =cdev_add (cdevp, cdevp->dev,1 ); +if (ret) { +xrt_err (xdev,"failed to add cdev: %d" , ret); + goto failed; + } +if (!file_name) + file_name = xdev->name; +if (!inst_name) { +if (devnode_mode (xdev) ==XRT_DEV_FILE_MULTI_INST ) { +snprintf (fname,sizeof (fname),"%s/%s/%s.%u" , +XRT_CDEV_DIR ,DEV_PDATA (xdev)->xsp_root_name, + file_name, xdev->instance); + }else { +snprintf (fname,sizeof (fname),"%s/%s/%s" , +XRT_CDEV_DIR ,DEV_PDATA (xdev)->xsp_root_name, + file_name); + } + }else { +snprintf (fname,sizeof (fname),"%s/%s/%s.%s" ,XRT_CDEV_DIR , +DEV_PDATA (xdev)->xsp_root_name, file_name, inst_name); + } + sysdev =device_create (xrt_class,NULL , cdevp->dev,NULL ,"%s" , fname); +if (IS_ERR (sysdev)) { + ret =PTR_ERR (sysdev); +xrt_err (xdev,"failed to create device node: %d" , ret); + goto failed_cdev_add; + } + pdata->xsp_sysdev = sysdev; + +xleaf_devnode_allowed (xdev); + +xrt_info (xdev,"created (%d, %d): /dev/%s" , +MAJOR (cdevp->dev), xdev->instance, fname); +return 0 ; + +failed_cdev_add: +cdev_del (cdevp); +failed: + cdevp->owner =NULL ; +return ret; +} + +void xleaf_devnode_destroy (struct xrt_device *xdev) +{ +struct xrt_subdev_platdata *pdata =DEV_PDATA (xdev); +struct cdev *cdevp = &pdata->xsp_cdev; +dev_t dev = cdevp->dev; + +xleaf_devnode_disallowed (xdev); + +xrt_info (xdev,"removed (%d, %d): /dev/%s/%s" ,MAJOR (dev),MINOR (dev), +XRT_CDEV_DIR ,CDEV_NAME (pdata->xsp_sysdev)); +device_destroy (xrt_class, cdevp->dev); + pdata->xsp_sysdev =NULL ; +cdev_del (cdevp); +}
Signature · 1 line
2.27.0
PATCH v7 7/20 fpga: xrt: root driver infrastructure
In reply to Lizhi HouContains common code for all root drivers and handles root calls from xrt drivers. This is part of root driver infrastructure.
--- drivers/fpga/xrt/include/events.h | 45 +++ drivers/fpga/xrt/include/xroot.h | 117 +++++++ drivers/fpga/xrt/lib/subdev_pool.h | 53 +++ drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++++++++++++++++++++ 4 files changed, 751 insertions(+) create mode 100644 drivers/fpga/xrt/include/events.h create mode 100644 drivers/fpga/xrt/include/xroot.h create mode 100644 drivers/fpga/xrt/lib/subdev_pool.h create mode 100644 drivers/fpga/xrt/lib/xroot.c
drivers/fpga/xrt/include/events.h new file +45 -0
@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#ifndef _XRT_EVENTS_H_ +#define _XRT_EVENTS_H_ + +#include "subdev_id.h" + +/* +* Event notification. +*/ +enum xrt_events { +XRT_EVENT_TEST =0 ,/* for testing */ +/* +* Events related to specific subdev +* Callback arg: struct xrt_event_arg_subdev +*/ +XRT_EVENT_POST_CREATION , +XRT_EVENT_PRE_REMOVAL , +/* +* Events related to change of the whole board +* Callback arg: <none> +*/ +XRT_EVENT_PRE_HOT_RESET , +XRT_EVENT_POST_HOT_RESET , +XRT_EVENT_PRE_GATE_CLOSE , +XRT_EVENT_POST_GATE_OPEN , +}; + +struct xrt_event_arg_subdev { +enum xrt_subdev_id xevt_subdev_id; +int xevt_subdev_instance; +}; + +struct xrt_event { +enum xrt_events xe_evt; +struct xrt_event_arg_subdev xe_subdev; +}; + +#endif /* _XRT_EVENTS_H_ */
drivers/fpga/xrt/include/xroot.h new file +117 -0
117 lines not on this page · raw message
drivers/fpga/xrt/lib/subdev_pool.h new file +53 -0
53 lines not on this page · raw message
drivers/fpga/xrt/lib/xroot.c new file +536 -0
536 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 8/20 fpga: xrt: driver infrastructure
In reply to Lizhi HouInfrastructure code providing APIs for managing leaf driver instance groups, facilitating inter-leaf driver calls and root calls.
--- drivers/fpga/xrt/lib/subdev.c | 859 ++++++++++++++++++++++++++++++++++ 1 file changed, 859 insertions(+) create mode 100644 drivers/fpga/xrt/lib/subdev.c
drivers/fpga/xrt/lib/subdev.c new file +859 -0
@@ -0,0 +1,859 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#include <linux/vmalloc.h> +#include <linux/slab.h> +#include "xleaf.h" +#include "subdev_pool.h" +#include "lib-drv.h" +#include "metadata.h" + +extern struct bus_type xrt_bus_type; + +#define IS_ROOT_DEV (dev) ((dev)->bus != &xrt_bus_type) +#define XRT_HOLDER_BUF_SZ 1024 + +static inline struct device *find_root (struct xrt_device *xdev) +{ +struct device *d =DEV (xdev); + +while (!IS_ROOT_DEV (d)) + d = d->parent; +return d; +} + +/* +* It represents a holder of a subdev. One holder can repeatedly hold a subdev +* as long as there is a unhold corresponding to a hold. +*/ +struct xrt_subdev_holder { +struct list_head xsh_holder_list; +struct device *xsh_holder; +int xsh_count; +struct kref xsh_kref; +}; + +/* +* It represents a specific instance of platform driver for a subdev, which +* provides services to its clients (another subdev driver or root driver). +*/ +struct xrt_subdev { +struct list_head xs_dev_list; +struct list_head xs_holder_list; +enum xrt_subdev_id xs_id;/* type of subdev */ +struct xrt_device *xs_xdev; +struct completion xs_holder_comp; +}; + +static struct xrt_subdev *xrt_subdev_alloc (void ) +{ +struct xrt_subdev *sdev =kzalloc (sizeof (*sdev),GFP_KERNEL ); + +if (!sdev) +return NULL ; + +INIT_LIST_HEAD (&sdev->xs_dev_list); +INIT_LIST_HEAD (&sdev->xs_holder_list); +init_completion (&sdev->xs_holder_comp); +return sdev; +} + +int xrt_subdev_root_request (struct xrt_device *self,u32 cmd,void *arg) +{ +struct device *dev =DEV (self); +struct xrt_subdev_platdata *pdata =DEV_PDATA (self); + +if (!pdata->xsp_root_cb) { +dev_err (dev,"invalid root callback" ); +return -EINVAL ; + } +return (*pdata->xsp_root_cb)(dev->parent, pdata->xsp_root_cb_arg, cmd, arg); +} + +/* +* Subdev common sysfs nodes. +*/ +static ssize_t holders_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +ssize_t len; +struct xrt_device *xdev =to_xrt_dev (dev); +struct xrt_root_get_holders holders = { xdev, buf,XRT_HOLDER_BUF_SZ }; + + len =xrt_subdev_root_request (xdev,XRT_ROOT_GET_LEAF_HOLDERS , &holders); +if (len >= holders.xpigh_holder_buf_len) +return len; + buf[len] ='\n' ; +return len +1 ; +} +static DEVICE_ATTR_RO (holders); + +static struct attribute *xrt_subdev_attrs[] = { + &dev_attr_holders.attr, +NULL , +}; + +static ssize_t metadata_output (struct file *filp,struct kobject *kobj, +struct bin_attribute *attr,char *buf,loff_t off,size_t count) +{ +struct device *dev =kobj_to_dev (kobj); +struct xrt_device *xdev =to_xrt_dev (dev); +struct xrt_subdev_platdata *pdata =DEV_PDATA (xdev); +unsigned char *blob; +unsigned long size; +ssize_t ret =0 ; + + blob = pdata->xsp_dtb; + size =xrt_md_size (dev, blob); +if (size ==XRT_MD_INVALID_LENGTH ) { + ret = -EINVAL ; + goto failed; + } + +if (off >= size) { +dev_dbg (dev,"offset (%lld) beyond total size: %ld\n" , off, size); + goto failed; + } + +if (off + count > size) { +dev_dbg (dev,"count (%ld) beyond left bytes: %lld\n" , + (unsigned long )count, size - off); + count = size - off; + } +memcpy (buf, blob + off, count); + + ret = count; +failed: +return ret; +} + +static struct bin_attribute meta_data_attr = { + .attr = { + .name ="metadata" , + .mode =0400 + }, + .read = metadata_output, + .size =0 +}; + +static struct bin_attribute *xrt_subdev_bin_attrs[] = { + &meta_data_attr, +NULL , +}; + +static const struct attribute_group xrt_subdev_attrgroup = { + .attrs = xrt_subdev_attrs, + .bin_attrs = xrt_subdev_bin_attrs, +}; + +/* +* Given the device metadata, parse it to get IO ranges and construct +* resource array. +*/ +static int +xrt_subdev_getres (struct device *parent,enum xrt_subdev_id id, +char *dtb,struct resource **res,int *res_num) +{ +struct xrt_subdev_platdata *pdata; +struct resource *pci_res =NULL ; +const __be64 *bar_range; +const __be32 *bar_idx; +char *ep_name =NULL , *compat =NULL ; +uint bar; +int count1 =0 , count2 =0 , ret; + +if (!dtb) +return -EINVAL ; + + pdata =DEV_PDATA (to_xrt_dev (parent)); + +/* go through metadata and count endpoints in it */ +xrt_md_get_next_endpoint (parent, dtb,NULL ,NULL , &ep_name, &compat); +while (ep_name) { + ret =xrt_md_get_prop (parent, dtb, ep_name, compat, +XRT_MD_PROP_IO_OFFSET , (const void **)&bar_range,NULL ); +if (!ret) + count1++; +xrt_md_get_next_endpoint (parent, dtb, ep_name, compat, &ep_name, &compat); + } +if (!count1) +return 0 ; + +/* allocate resource array for all endpoints been found in metadata */ + *res =vzalloc (sizeof (**res) * count1); + +/* go through all endpoints again and get IO range for each endpoint */ + ep_name =NULL ; +xrt_md_get_next_endpoint (parent, dtb,NULL ,NULL , &ep_name, &compat); +while (ep_name) { + ret =xrt_md_get_prop (parent, dtb, ep_name, compat, +XRT_MD_PROP_IO_OFFSET , (const void **)&bar_range,NULL ); +if (ret) +continue ; +xrt_md_get_prop (parent, dtb, ep_name, compat, +XRT_MD_PROP_BAR_IDX , (const void **)&bar_idx,NULL ); + bar = bar_idx ?be32_to_cpu (*bar_idx) :0 ; +xleaf_get_root_res (to_xrt_dev (parent), bar, &pci_res); +if (!pci_res) { +dev_err (parent,"Invalid bar defined %d" , bar); + ret = -EINVAL ; + goto failed; + } + (*res)[count2].start = pci_res->start +be64_to_cpu (bar_range[0 ]); + (*res)[count2].end = pci_res->start +be64_to_cpu (bar_range[0 ]) + +be64_to_cpu (bar_range[1 ]) -1 ; + (*res)[count2].flags =IORESOURCE_MEM ; +/* check if there is conflicted resource */ + ret =request_resource (pci_res, *res + count2); +if (ret) { +dev_err (parent,"Conflict resource %pR\n" , *res + count2); + goto failed; + } +release_resource (*res + count2); + + (*res)[count2].parent = pci_res; + +xrt_md_find_endpoint (parent, pdata->xsp_dtb, ep_name, + compat, &(*res)[count2].name); + + count2++; +xrt_md_get_next_endpoint (parent, dtb, ep_name, compat, &ep_name, &compat); + } + +WARN_ON (count1 != count2); + *res_num = count2; + +return 0 ; + +failed: +vfree (*res); + *res_num =0 ; + *res =NULL ; +return ret; +} + +static inline enum xrt_dev_file_mode +xleaf_devnode_mode (struct xrt_device *xdev) +{ +return DEV_FILE_OPS (xdev)->xsf_mode; +} + +static bool xrt_subdev_cdev_auto_creation (struct xrt_device *xdev) +{ +enum xrt_dev_file_mode mode =xleaf_devnode_mode (xdev); + +if (!xleaf_devnode_enabled (xdev)) +return false; + +return (mode ==XRT_DEV_FILE_DEFAULT || mode ==XRT_DEV_FILE_MULTI_INST ); +} + +static struct xrt_subdev * +xrt_subdev_create (struct device *parent,enum xrt_subdev_id id, +xrt_subdev_root_cb_t pcb,void *pcb_arg,char *dtb) +{ +struct xrt_subdev_platdata *pdata =NULL ; +struct xrt_subdev *sdev =NULL ; +struct xrt_device *xdev =NULL ; +struct resource *res =NULL ; +unsigned long dtb_len =0 ; +bool dtb_alloced = false; +int res_num =0 ; +size_t pdata_sz; +int ret; + + sdev =xrt_subdev_alloc (); +if (!sdev) { +dev_err (parent,"failed to alloc subdev for ID %d" , id); +return NULL ; + } + sdev->xs_id = id; + +if (!dtb) { + ret =xrt_md_create (parent, &dtb); +if (ret) { +dev_err (parent,"can't create empty dtb: %d" , ret); + goto fail; + } + dtb_alloced = true; + } +xrt_md_pack (parent, dtb); + dtb_len =xrt_md_size (parent, dtb); +if (dtb_len ==XRT_MD_INVALID_LENGTH ) { +dev_err (parent,"invalid metadata len %ld" , dtb_len); + goto fail1; + } + pdata_sz =sizeof (struct xrt_subdev_platdata ) + dtb_len; + +/* Prepare platform data passed to subdev. */ + pdata =vzalloc (pdata_sz); +if (!pdata) + goto fail1; + + pdata->xsp_root_cb = pcb; + pdata->xsp_root_cb_arg = pcb_arg; +memcpy (pdata->xsp_dtb, dtb, dtb_len); +if (id ==XRT_SUBDEV_GRP ) { +/* Group can only be created by root driver. */ + pdata->xsp_root_name =dev_name (parent); + }else { +struct xrt_device *grp =to_xrt_dev (parent); + +/* Leaf can only be created by group driver. */ +WARN_ON (to_xrt_drv (parent->driver)->subdev_id !=XRT_SUBDEV_GRP ); + pdata->xsp_root_name =DEV_PDATA (grp)->xsp_root_name; + } + +/* Create subdev. */ +if (id !=XRT_SUBDEV_GRP ) { +int rc =xrt_subdev_getres (parent, id, dtb, &res, &res_num); + +if (rc) { +dev_err (parent,"failed to get resource for %s: %d" , +xrt_drv_name (id), rc); + goto fail2; + } + } + xdev =xrt_device_register (parent, id, res, res_num, pdata, pdata_sz); +vfree (res); +if (!xdev) { +dev_err (parent,"failed to create subdev for %s" ,xrt_drv_name (id)); + goto fail2; + } + sdev->xs_xdev = xdev; + +if (device_attach (DEV (xdev)) !=1 ) { +xrt_err (xdev,"failed to attach" ); + goto fail3; + } + +if (sysfs_create_group (&DEV (xdev)->kobj, &xrt_subdev_attrgroup)) +xrt_err (xdev,"failed to create sysfs group" ); + +/* +* Create sysfs sym link under root for leaves +* under random groups for easy access to them. +*/ +if (id !=XRT_SUBDEV_GRP ) { +if (sysfs_create_link (&find_root (xdev)->kobj, + &DEV (xdev)->kobj,dev_name (DEV (xdev)))) { +xrt_err (xdev,"failed to create sysfs link" ); + } + } + +/* All done, ready to handle req thru cdev. */ +if (xrt_subdev_cdev_auto_creation (xdev)) +xleaf_devnode_create (xdev,DEV_FILE_OPS (xdev)->xsf_dev_name,NULL ); + +vfree (pdata); +return sdev; + +fail3: +xrt_device_unregister (sdev->xs_xdev); +fail2: +vfree (pdata); +fail1: +if (dtb_alloced) +vfree (dtb); +fail: +kfree (sdev); +return NULL ; +} + +static void xrt_subdev_destroy (struct xrt_subdev *sdev) +{ +struct xrt_device *xdev = sdev->xs_xdev; +struct device *dev =DEV (xdev); + +/* Take down the device node */ +if (xrt_subdev_cdev_auto_creation (xdev)) +xleaf_devnode_destroy (xdev); +if (sdev->xs_id !=XRT_SUBDEV_GRP ) +sysfs_remove_link (&find_root (xdev)->kobj,dev_name (dev)); +sysfs_remove_group (&dev->kobj, &xrt_subdev_attrgroup); +xrt_device_unregister (xdev); +kfree (sdev); +} + +struct xrt_device * +xleaf_get_leaf (struct xrt_device *xdev,xrt_subdev_match_t match_cb,void *match_arg) +{ +int rc; +struct xrt_root_get_leaf get_leaf = { + xdev, match_cb, match_arg, }; + + rc =xrt_subdev_root_request (xdev,XRT_ROOT_GET_LEAF , &get_leaf); +if (rc) +return NULL ; +return get_leaf.xpigl_tgt_xdev; +} +EXPORT_SYMBOL_GPL (xleaf_get_leaf); + +bool xleaf_has_endpoint (struct xrt_device *xdev,const char *endpoint_name) +{ +struct resource *res; +int i =0 ; + +do { + res =xrt_get_resource (xdev,IORESOURCE_MEM , i); +if (res && !strncmp (res->name, endpoint_name,strlen (res->name) +1 )) +return true; + ++i; + }while (res); + +return false; +} +EXPORT_SYMBOL_GPL (xleaf_has_endpoint); + +int xleaf_put_leaf (struct xrt_device *xdev,struct xrt_device *leaf) +{ +struct xrt_root_put_leaf put_leaf = { xdev, leaf }; + +return xrt_subdev_root_request (xdev,XRT_ROOT_PUT_LEAF , &put_leaf); +} +EXPORT_SYMBOL_GPL (xleaf_put_leaf); + +int xleaf_create_group (struct xrt_device *xdev,char *dtb) +{ +return xrt_subdev_root_request (xdev,XRT_ROOT_CREATE_GROUP , dtb); +} +EXPORT_SYMBOL_GPL (xleaf_create_group); + +int xleaf_destroy_group (struct xrt_device *xdev,int instance) +{ +return xrt_subdev_root_request (xdev,XRT_ROOT_REMOVE_GROUP , (void *)(uintptr_t )instance); +} +EXPORT_SYMBOL_GPL (xleaf_destroy_group); + +int xleaf_wait_for_group_bringup (struct xrt_device *xdev) +{ +return xrt_subdev_root_request (xdev,XRT_ROOT_WAIT_GROUP_BRINGUP ,NULL ); +} +EXPORT_SYMBOL_GPL (xleaf_wait_for_group_bringup); + +static ssize_t +xrt_subdev_get_holders (struct xrt_subdev *sdev,char *buf,size_t len) +{ +const struct list_head *ptr; +struct xrt_subdev_holder *h; +ssize_t n =0 ; + +list_for_each (ptr, &sdev->xs_holder_list) { + h = list_entry(ptr, struct xrt_subdev_holder, xsh_holder_list); + n +=snprintf (buf + n, len - n,"%s:%d " , +dev_name (h->xsh_holder),kref_read (&h->xsh_kref)); +/* Truncation is fine here. Buffer content is only for debugging. */ +if (n >= (len -1 )) +break ; + } +return n; +} + +void xrt_subdev_pool_init (struct device *dev,struct xrt_subdev_pool *spool) +{ +INIT_LIST_HEAD (&spool->xsp_dev_list); + spool->xsp_owner = dev; +mutex_init (&spool->xsp_lock); + spool->xsp_closing = false; +} + +static void xrt_subdev_free_holder (struct xrt_subdev_holder *holder) +{ +list_del (&holder->xsh_holder_list); +vfree (holder); +} + +static void xrt_subdev_pool_wait_for_holders (struct xrt_subdev_pool *spool,struct xrt_subdev *sdev) +{ +const struct list_head *ptr, *next; +char holders[128 ]; +struct xrt_subdev_holder *holder; +struct mutex *lk = &spool->xsp_lock; + +while (!list_empty (&sdev->xs_holder_list)) { +int rc; + +/* It's most likely a bug if we ever enters this loop. */ +xrt_subdev_get_holders (sdev, holders,sizeof (holders)); +xrt_err (sdev->xs_xdev,"awaits holders: %s" , holders); +mutex_unlock (lk); + rc =wait_for_completion_killable (&sdev->xs_holder_comp); +mutex_lock (lk); +if (rc == -ERESTARTSYS ) { +xrt_err (sdev->xs_xdev,"give up on waiting for holders, clean up now" ); +list_for_each_safe (ptr, next, &sdev->xs_holder_list) { + holder = list_entry(ptr, struct xrt_subdev_holder, xsh_holder_list); +xrt_subdev_free_holder (holder); + } + } + } +} + +void xrt_subdev_pool_fini (struct xrt_subdev_pool *spool) +{ +struct list_head *dl = &spool->xsp_dev_list; +struct mutex *lk = &spool->xsp_lock; + +mutex_lock (lk); +if (spool->xsp_closing) { +mutex_unlock (lk); +return ; + } + spool->xsp_closing = true; +mutex_unlock (lk); + +/* Remove subdev in the reverse order of added. */ +while (!list_empty (dl)) { + struct xrt_subdev *sdev = list_first_entry(dl, struct xrt_subdev, xs_dev_list); + +xrt_subdev_pool_wait_for_holders (spool, sdev); +list_del (&sdev->xs_dev_list); +xrt_subdev_destroy (sdev); + } +} + +static struct xrt_subdev_holder *xrt_subdev_find_holder (struct xrt_subdev *sdev, +struct device *holder_dev) +{ +struct list_head *hl = &sdev->xs_holder_list; +struct xrt_subdev_holder *holder; +const struct list_head *ptr; + +list_for_each (ptr, hl) { + holder = list_entry(ptr, struct xrt_subdev_holder, xsh_holder_list); +if (holder->xsh_holder == holder_dev) +return holder; + } +return NULL ; +} + +static int xrt_subdev_hold (struct xrt_subdev *sdev,struct device *holder_dev) +{ +struct xrt_subdev_holder *holder =xrt_subdev_find_holder (sdev, holder_dev); +struct list_head *hl = &sdev->xs_holder_list; + +if (!holder) { + holder =vzalloc (sizeof (*holder)); +if (!holder) +return -ENOMEM ; + holder->xsh_holder = holder_dev; +kref_init (&holder->xsh_kref); +list_add_tail (&holder->xsh_holder_list, hl); + }else { +kref_get (&holder->xsh_kref); + } + +return 0 ; +} + +static void xrt_subdev_free_holder_kref (struct kref *kref) +{ + struct xrt_subdev_holder *holder = container_of(kref, struct xrt_subdev_holder, xsh_kref); + +xrt_subdev_free_holder (holder); +} + +static int +xrt_subdev_release (struct xrt_subdev *sdev,struct device *holder_dev) +{ +struct xrt_subdev_holder *holder =xrt_subdev_find_holder (sdev, holder_dev); +struct list_head *hl = &sdev->xs_holder_list; + +if (!holder) { +dev_err (holder_dev,"can't release, %s did not hold %s" , +dev_name (holder_dev),dev_name (DEV (sdev->xs_xdev))); +return -EINVAL ; + } +kref_put (&holder->xsh_kref, xrt_subdev_free_holder_kref); + +/* kref_put above may remove holder from list. */ +if (list_empty (hl)) +complete (&sdev->xs_holder_comp); +return 0 ; +} + +int xrt_subdev_pool_add (struct xrt_subdev_pool *spool,enum xrt_subdev_id id, +xrt_subdev_root_cb_t pcb,void *pcb_arg,char *dtb) +{ +struct mutex *lk = &spool->xsp_lock; +struct list_head *dl = &spool->xsp_dev_list; +struct xrt_subdev *sdev; +int ret =0 ; + + sdev =xrt_subdev_create (spool->xsp_owner, id, pcb, pcb_arg, dtb); +if (sdev) { +mutex_lock (lk); +if (spool->xsp_closing) { +/* No new subdev when pool is going away. */ +xrt_err (sdev->xs_xdev,"pool is closing" ); + ret = -ENODEV ; + }else { +list_add (&sdev->xs_dev_list, dl); + } +mutex_unlock (lk); +if (ret) +xrt_subdev_destroy (sdev); + }else { + ret = -EINVAL ; + } + + ret = ret ? ret : sdev->xs_xdev->instance; +return ret; +} + +int xrt_subdev_pool_del (struct xrt_subdev_pool *spool,enum xrt_subdev_id id,int instance) +{ +const struct list_head *ptr; +struct mutex *lk = &spool->xsp_lock; +struct list_head *dl = &spool->xsp_dev_list; +struct xrt_subdev *sdev; +int ret = -ENOENT ; + +mutex_lock (lk); +if (spool->xsp_closing) { +/* Pool is going away, all subdevs will be gone. */ +mutex_unlock (lk); +return 0 ; + } +list_for_each (ptr, dl) { + sdev = list_entry(ptr, struct xrt_subdev, xs_dev_list); +if (sdev->xs_id != id || sdev->xs_xdev->instance != instance) +continue ; +xrt_subdev_pool_wait_for_holders (spool, sdev); +list_del (&sdev->xs_dev_list); + ret =0 ; +break ; + } +mutex_unlock (lk); +if (ret) +return ret; + +xrt_subdev_destroy (sdev); +return 0 ; +} + +static int xrt_subdev_pool_get_impl (struct xrt_subdev_pool *spool,xrt_subdev_match_t match, +void *arg,struct device *holder_dev,struct xrt_subdev **sdevp) +{ +struct xrt_device *xdev = (struct xrt_device *)arg; +struct list_head *dl = &spool->xsp_dev_list; +struct mutex *lk = &spool->xsp_lock; +struct xrt_subdev *sdev =NULL ; +const struct list_head *ptr; +struct xrt_subdev *d =NULL ; +int ret = -ENOENT ; + +mutex_lock (lk); + +if (!xdev) { +if (match ==XRT_SUBDEV_MATCH_PREV ) { + sdev =list_empty (dl) ?NULL : + list_last_entry(dl, struct xrt_subdev, xs_dev_list); + }else if (match ==XRT_SUBDEV_MATCH_NEXT ) { + sdev = list_first_entry_or_null(dl, struct xrt_subdev, xs_dev_list); + } + } + +list_for_each (ptr, dl) { + d = list_entry(ptr, struct xrt_subdev, xs_dev_list); +if (match ==XRT_SUBDEV_MATCH_PREV || match ==XRT_SUBDEV_MATCH_NEXT ) { +if (d->xs_xdev != xdev) +continue ; + }else { +if (!match (d->xs_id, d->xs_xdev, arg)) +continue ; + } + +if (match ==XRT_SUBDEV_MATCH_PREV ) + sdev = !list_is_first (ptr, dl) ?list_prev_entry (d, xs_dev_list) :NULL ; +else if (match ==XRT_SUBDEV_MATCH_NEXT ) + sdev = !list_is_last (ptr, dl) ?list_next_entry (d, xs_dev_list) :NULL ; +else + sdev = d; + } + +if (sdev) + ret =xrt_subdev_hold (sdev, holder_dev); + +mutex_unlock (lk); + +if (!ret) + *sdevp = sdev; +return ret; +} + +int xrt_subdev_pool_get (struct xrt_subdev_pool *spool,xrt_subdev_match_t match,void *arg, +struct device *holder_dev,struct xrt_device **xdevp) +{ +int rc; +struct xrt_subdev *sdev; + + rc =xrt_subdev_pool_get_impl (spool, match, arg, holder_dev, &sdev); +if (rc) { +if (rc != -ENOENT ) +dev_err (holder_dev,"failed to hold device: %d" , rc); +return rc; + } + +if (!IS_ROOT_DEV (holder_dev)) { +xrt_dbg (to_xrt_dev (holder_dev),"%s <<==== %s" , +dev_name (holder_dev),dev_name (DEV (sdev->xs_xdev))); + } + + *xdevp = sdev->xs_xdev; +return 0 ; +} + +static int xrt_subdev_pool_put_impl (struct xrt_subdev_pool *spool,struct xrt_device *xdev, +struct device *holder_dev) +{ +const struct list_head *ptr; +struct mutex *lk = &spool->xsp_lock; +struct list_head *dl = &spool->xsp_dev_list; +struct xrt_subdev *sdev; +int ret = -ENOENT ; + +mutex_lock (lk); +list_for_each (ptr, dl) { + sdev = list_entry(ptr, struct xrt_subdev, xs_dev_list); +if (sdev->xs_xdev != xdev) +continue ; + ret =xrt_subdev_release (sdev, holder_dev); +break ; + } +mutex_unlock (lk); + +return ret; +} + +int xrt_subdev_pool_put (struct xrt_subdev_pool *spool,struct xrt_device *xdev, +struct device *holder_dev) +{ +int ret =xrt_subdev_pool_put_impl (spool, xdev, holder_dev); + +if (ret) +return ret; + +if (!IS_ROOT_DEV (holder_dev)) { +xrt_dbg (to_xrt_dev (holder_dev),"%s <<==X== %s" , +dev_name (holder_dev),dev_name (DEV (xdev))); + } +return 0 ; +} + +void xrt_subdev_pool_trigger_event (struct xrt_subdev_pool *spool,enum xrt_events e) +{ +struct xrt_device *tgt =NULL ; +struct xrt_subdev *sdev =NULL ; +struct xrt_event evt; + +while (!xrt_subdev_pool_get_impl (spool,XRT_SUBDEV_MATCH_NEXT , + tgt, spool->xsp_owner, &sdev)) { + tgt = sdev->xs_xdev; + evt.xe_evt = e; + evt.xe_subdev.xevt_subdev_id = sdev->xs_id; + evt.xe_subdev.xevt_subdev_instance = tgt->instance; +xrt_subdev_root_request (tgt,XRT_ROOT_EVENT_SYNC , &evt); +xrt_subdev_pool_put_impl (spool, tgt, spool->xsp_owner); + } +} + +void xrt_subdev_pool_handle_event (struct xrt_subdev_pool *spool,struct xrt_event *evt) +{ +struct xrt_device *tgt =NULL ; +struct xrt_subdev *sdev =NULL ; + +while (!xrt_subdev_pool_get_impl (spool,XRT_SUBDEV_MATCH_NEXT , + tgt, spool->xsp_owner, &sdev)) { + tgt = sdev->xs_xdev; +xleaf_call (tgt,XRT_XLEAF_EVENT , evt); +xrt_subdev_pool_put_impl (spool, tgt, spool->xsp_owner); + } +} + +ssize_t xrt_subdev_pool_get_holders (struct xrt_subdev_pool *spool, +struct xrt_device *xdev,char *buf,size_t len) +{ +const struct list_head *ptr; +struct mutex *lk = &spool->xsp_lock; +struct list_head *dl = &spool->xsp_dev_list; +struct xrt_subdev *sdev; +ssize_t ret =0 ; + +mutex_lock (lk); +list_for_each (ptr, dl) { + sdev = list_entry(ptr, struct xrt_subdev, xs_dev_list); +if (sdev->xs_xdev != xdev) +continue ; + ret =xrt_subdev_get_holders (sdev, buf, len); +break ; + } +mutex_unlock (lk); + +return ret; +} +EXPORT_SYMBOL_GPL (xrt_subdev_pool_get_holders); + +int xleaf_broadcast_event (struct xrt_device *xdev,enum xrt_events evt,bool async) +{ +struct xrt_event e = { evt, }; +enum xrt_root_cmd cmd = async ?XRT_ROOT_EVENT_ASYNC :XRT_ROOT_EVENT_SYNC ; + +WARN_ON (evt ==XRT_EVENT_POST_CREATION || evt ==XRT_EVENT_PRE_REMOVAL ); +return xrt_subdev_root_request (xdev, cmd, &e); +} +EXPORT_SYMBOL_GPL (xleaf_broadcast_event); + +void xleaf_hot_reset (struct xrt_device *xdev) +{ +xrt_subdev_root_request (xdev,XRT_ROOT_HOT_RESET ,NULL ); +} +EXPORT_SYMBOL_GPL (xleaf_hot_reset); + +void xleaf_get_root_res (struct xrt_device *xdev,u32 region_id,struct resource **res) +{ +struct xrt_root_get_res arg = {0 }; + + arg.xpigr_region_id = region_id; +xrt_subdev_root_request (xdev,XRT_ROOT_GET_RESOURCE , &arg); + *res = arg.xpigr_res; +} + +void xleaf_get_root_id (struct xrt_device *xdev,unsigned short *vendor,unsigned short *device, +unsigned short *subvendor,unsigned short *subdevice) +{ +struct xrt_root_get_id id = {0 }; + +WARN_ON (!vendor && !device && !subvendor && !subdevice); + +xrt_subdev_root_request (xdev,XRT_ROOT_GET_ID , (void *)&id); +if (vendor) + *vendor = id.xpigi_vendor_id; +if (device) + *device = id.xpigi_device_id; +if (subvendor) + *subvendor = id.xpigi_sub_vendor_id; +if (subdevice) + *subdevice = id.xpigi_sub_device_id; +} + +struct device *xleaf_register_hwmon (struct xrt_device *xdev,const char *name,void *drvdata, +const struct attribute_group **grps) +{ +struct xrt_root_hwmon hm = { true, name, drvdata, grps, }; + +xrt_subdev_root_request (xdev,XRT_ROOT_HWMON , (void *)&hm); +return hm.xpih_hwmon_dev; +} + +void xleaf_unregister_hwmon (struct xrt_device *xdev,struct device *hwmon) +{ +struct xrt_root_hwmon hm = { false, }; + + hm.xpih_hwmon_dev = hwmon; +xrt_subdev_root_request (xdev,XRT_ROOT_HWMON , (void *)&hm); +}
Signature · 1 line
2.27.0
PATCH v7 9/20 fpga: xrt: management physical function driver (root)
In reply to Lizhi HouThe 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.
--- drivers/fpga/xrt/mgmt/root.c | 420 +++++++++++++++++++++++++++++++++++ 1 file changed, 420 insertions(+) create mode 100644 drivers/fpga/xrt/mgmt/root.c
drivers/fpga/xrt/mgmt/root.c new file +420 -0
@@ -0,0 +1,420 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Xilinx Alveo Management Function Driver +* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/aer.h> +#include <linux/vmalloc.h> +#include <linux/delay.h> + +#include "xroot.h" +#include "xmgmt.h" +#include "metadata.h" + +#define XMGMT_MODULE_NAME "xrt-mgmt" +#define XMGMT_DRIVER_VERSION "4.0.0" + +#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, 0)); }) +#define XRT_VSEC_ID 0x20 +#define XRT_MAX_READRQ 512 + +static struct class *xmgmt_class; + +/* PCI Device IDs */ +/* +* Golden image is preloaded on the device when it is shipped to customer. +* Then, customer can load other shells (from Xilinx or some other vendor). +* If something goes wrong with the shell, customer can always go back to +* golden and start over again. +*/ +#define PCI_DEVICE_ID_U50_GOLDEN 0xD020 +#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_GOLDEN ), },/* Alveo U50 (golden) */ + {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_match_slot_and_save (struct device *dev,void *data) +{ +struct xmgmt *xm = data; +struct pci_dev *pdev =to_pci_dev (dev); + +if (XMGMT_DEV_ID (pdev) ==XMGMT_DEV_ID (xm->pdev)) { +pci_cfg_access_lock (pdev); +pci_save_state (pdev); + } + +return 0 ; +} + +static void xmgmt_pci_save_config_all (struct xmgmt *xm) +{ +bus_for_each_dev (&pci_bus_type,NULL , xm, xmgmt_match_slot_and_save); +} + +static int xmgmt_match_slot_and_restore (struct device *dev,void *data) +{ +struct xmgmt *xm = data; +struct pci_dev *pdev =to_pci_dev (dev); + +if (XMGMT_DEV_ID (pdev) ==XMGMT_DEV_ID (xm->pdev)) { +pci_restore_state (pdev); +pci_cfg_access_unlock (pdev); + } + +return 0 ; +} + +static void xmgmt_pci_restore_config_all (struct xmgmt *xm) +{ +bus_for_each_dev (&pci_bus_type,NULL , xm, xmgmt_match_slot_and_restore); +} + +static void xmgmt_root_hot_reset (struct device *dev) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct pci_bus *bus; +u16 pci_cmd, devctl; +struct xmgmt *xm; +u8 pci_bctl; +int i, ret; + + xm =pci_get_drvdata (pdev); +xmgmt_info (xm,"hot reset start" ); +xmgmt_pci_save_config_all (xm); +pci_disable_device (pdev); + bus = pdev->bus; + +/* +* When flipping the SBR bit, device can fall off the bus. This is +* usually no problem at all so long as drivers are working properly +* after SBR. However, some systems complain bitterly when the device +* falls off the bus. +* The quick solution is to temporarily disable the SERR reporting of +* switch port during SBR. +*/ + +pci_read_config_word (bus->self,PCI_COMMAND , &pci_cmd); +pci_write_config_word (bus->self,PCI_COMMAND , (pci_cmd & ~PCI_COMMAND_SERR )); +pcie_capability_read_word (bus->self,PCI_EXP_DEVCTL , &devctl); +pcie_capability_write_word (bus->self,PCI_EXP_DEVCTL , (devctl & ~PCI_EXP_DEVCTL_FERE )); +pci_read_config_byte (bus->self,PCI_BRIDGE_CONTROL , &pci_bctl); +pci_write_config_byte (bus->self,PCI_BRIDGE_CONTROL , pci_bctl |PCI_BRIDGE_CTL_BUS_RESET ); +msleep (100 ); +pci_write_config_byte (bus->self,PCI_BRIDGE_CONTROL , pci_bctl); +ssleep (1 ); + +pcie_capability_write_word (bus->self,PCI_EXP_DEVCTL , devctl); +pci_write_config_word (bus->self,PCI_COMMAND , pci_cmd); + + ret =pci_enable_device (pdev); +if (ret) +xmgmt_err (xm,"failed to enable device, ret %d" , ret); + +for (i =0 ; i <300 ; i++) { +pci_read_config_word (pdev,PCI_COMMAND , &pci_cmd); +if (pci_cmd !=0xffff ) +break ; +msleep (20 ); + } +if (i ==300 ) +xmgmt_err (xm,"timed out waiting for device to be online after reset" ); + +xmgmt_info (xm,"waiting for %d ms" , i *20 ); +xmgmt_pci_restore_config_all (xm); +xmgmt_config_pci (xm); +} + +static int xmgmt_add_vsec_node (struct xmgmt *xm,char *dtb) +{ +struct pci_dev *pdev =XMGMT_PDEV (xm); +struct xrt_md_endpoint ep = {0 }; +struct device *dev =DEV (pdev); +u32 off_low, off_high, header; +int cap =0 , ret =0 ; +__be32 vsec_bar; +__be64 vsec_off; + +while ((cap =pci_find_next_ext_capability (pdev, cap,PCI_EXT_CAP_ID_VNDR ))) { +pci_read_config_dword (pdev, cap +PCI_VNDR_HEADER , &header); +if (PCI_VNDR_HEADER_ID (header) ==XRT_VSEC_ID ) +break ; + } +if (!cap) { +xmgmt_info (xm,"No Vendor Specific Capability." ); +return -ENOENT ; + } + +if (pci_read_config_dword (pdev, cap +8 , &off_low) || +pci_read_config_dword (pdev, cap +12 , &off_high)) { +xmgmt_err (xm,"pci_read vendor specific failed." ); +return -EINVAL ; + } + + ep.ep_name =XRT_MD_NODE_VSEC ; + ret =xrt_md_add_endpoint (dev, dtb, &ep); +if (ret) { +xmgmt_err (xm,"add vsec metadata failed, ret %d" , ret); + goto failed; + } + + vsec_bar =cpu_to_be32 (off_low &0xf ); + ret =xrt_md_set_prop (dev, dtb,XRT_MD_NODE_VSEC ,NULL , +XRT_MD_PROP_BAR_IDX , &vsec_bar,sizeof (vsec_bar)); +if (ret) { +xmgmt_err (xm,"add vsec bar idx failed, ret %d" , ret); + goto failed; + } + + vsec_off =cpu_to_be64 (((u64 )off_high <<32 ) | (off_low & ~0xfU )); + ret =xrt_md_set_prop (dev, dtb,XRT_MD_NODE_VSEC ,NULL , +XRT_MD_PROP_OFFSET , &vsec_off,sizeof (vsec_off)); +if (ret) { +xmgmt_err (xm,"add vsec offset failed, ret %d" , ret); + goto failed; + } + +failed: +return ret; +} + +static int xmgmt_create_root_metadata (struct xmgmt *xm,char **root_dtb) +{ +char *dtb =NULL ; +int ret; + + ret =xrt_md_create (XMGMT_DEV (xm), &dtb); +if (ret) { +xmgmt_err (xm,"create metadata failed, ret %d" , ret); + goto failed; + } + + ret =xmgmt_add_vsec_node (xm, dtb); +if (ret == -ENOENT ) { +/* +* We may be dealing with a MFG board. +* Try vsec-golden which will bring up all hard-coded leaves +* at hard-coded offsets. +*/ + ret =xroot_add_simple_node (xm->root, dtb,XRT_MD_NODE_VSEC_GOLDEN ); + }else if (ret ==0 ) { + ret =xroot_add_simple_node (xm->root, dtb,XRT_MD_NODE_MGMT_MAIN ); + } +if (ret) + goto failed; + + *root_dtb = dtb; +return 0 ; + +failed: +vfree (dtb); +return ret; +} + +static ssize_t ready_show (struct device *dev, +struct device_attribute *da, +char *buf) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct xmgmt *xm =pci_get_drvdata (pdev); + +return sprintf (buf,"%d\n" , xm->ready); +} +static DEVICE_ATTR_RO (ready); + +static struct attribute *xmgmt_root_attrs[] = { + &dev_attr_ready.attr, +NULL +}; + +static struct attribute_group xmgmt_root_attr_group = { + .attrs = xmgmt_root_attrs, +}; + +static void xmgmt_root_get_id (struct device *dev,struct xrt_root_get_id *rid) +{ +struct pci_dev *pdev =to_pci_dev (dev); + + rid->xpigi_vendor_id = pdev->vendor; + rid->xpigi_device_id = pdev->device; + rid->xpigi_sub_vendor_id = pdev->subsystem_vendor; + rid->xpigi_sub_device_id = pdev->subsystem_device; +} + +static int xmgmt_root_get_resource (struct device *dev,struct xrt_root_get_res *res) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct xmgmt *xm; + + xm =pci_get_drvdata (pdev); +if (res->xpigr_region_id >PCI_STD_RESOURCE_END ) { +xmgmt_err (xm,"Invalid bar idx %d" , res->xpigr_region_id); +return -EINVAL ; + } + + res->xpigr_res = &pdev->resource[res->xpigr_region_id]; +return 0 ; +} + +static struct xroot_physical_function_callback xmgmt_xroot_pf_cb = { + .xpc_get_id = xmgmt_root_get_id, + .xpc_get_resource = xmgmt_root_get_resource, + .xpc_hot_reset = xmgmt_root_hot_reset, +}; + +static int xmgmt_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +int ret; +struct device *dev = &pdev->dev; +struct xmgmt *xm =devm_kzalloc (dev,sizeof (*xm),GFP_KERNEL ); +char *dtb =NULL ; + +if (!xm) +return -ENOMEM ; + xm->pdev = pdev; +pci_set_drvdata (pdev, xm); + + ret =xmgmt_config_pci (xm); +if (ret) + goto failed; + + ret =xroot_probe (&pdev->dev, &xmgmt_xroot_pf_cb, &xm->root); +if (ret) + goto failed; + + ret =xmgmt_create_root_metadata (xm, &dtb); +if (ret) + goto failed_metadata; + + ret =xroot_create_group (xm->root, dtb); +vfree (dtb); +if (ret) +xmgmt_err (xm,"failed to create root group: %d" , ret); + +if (!xroot_wait_for_bringup (xm->root)) +xmgmt_err (xm,"failed to bringup all groups" ); +else + xm->ready = true; + + ret =sysfs_create_group (&pdev->dev.kobj, &xmgmt_root_attr_group); +if (ret) { +/* Warning instead of failing the probe. */ +xmgmt_warn (xm,"create xmgmt root attrs failed: %d" , ret); + } + +xroot_broadcast (xm->root,XRT_EVENT_POST_CREATION ); +xmgmt_info (xm,"%s started successfully" ,XMGMT_MODULE_NAME ); +return 0 ; + +failed_metadata: +xroot_remove (xm->root); +failed: +pci_set_drvdata (pdev,NULL ); +return ret; +} + +static void xmgmt_remove (struct pci_dev *pdev) +{ +struct xmgmt *xm =pci_get_drvdata (pdev); + +xroot_broadcast (xm->root,XRT_EVENT_PRE_REMOVAL ); +sysfs_remove_group (&pdev->dev.kobj, &xmgmt_root_attr_group); +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 =xmgmt_register_leaf (); +if (res) +return res; + + xmgmt_class =class_create (THIS_MODULE ,XMGMT_MODULE_NAME ); +if (IS_ERR (xmgmt_class)) +return PTR_ERR (xmgmt_class); + + res =pci_register_driver (&xmgmt_driver); +if (res) { +class_destroy (xmgmt_class); +return res; + } + +return 0 ; +} + +static __exit void xmgmt_exit(void) +{ +pci_unregister_driver (&xmgmt_driver); +class_destroy (xmgmt_class); +xmgmt_unregister_leaf (); +} + +module_init (xmgmt_init); +module_exit (xmgmt_exit); + +MODULE_DEVICE_TABLE (pci, xmgmt_pci_ids); +MODULE_VERSION (XMGMT_DRIVER_VERSION ); +MODULE_AUTHOR ("XRT Team <[email protected]>" ); +MODULE_DESCRIPTION ("Xilinx Alveo management function driver" ); +MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.27.0
PATCH v7 10/20 fpga: xrt: main driver for management function device
In reply to Lizhi Houxrt driver that handles IOCTLs, such as hot reset and xclbin download.
--- drivers/fpga/xrt/include/xmgmt-main.h | 34 ++ drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 ++++++++++++++++++++++++++ drivers/fpga/xrt/mgmt/xmgmt.h | 33 ++ include/uapi/linux/xrt/xmgmt-ioctl.h | 46 ++ 4 files changed, 775 insertions(+) create mode 100644 drivers/fpga/xrt/include/xmgmt-main.h create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-main.c create mode 100644 drivers/fpga/xrt/mgmt/xmgmt.h create mode 100644 include/uapi/linux/xrt/xmgmt-ioctl.h
drivers/fpga/xrt/include/xmgmt-main.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#ifndef _XMGMT_MAIN_H_ +#define _XMGMT_MAIN_H_ + +#include <linux/xrt/xclbin.h> +#include "xleaf.h" + +enum xrt_mgmt_main_leaf_cmd { +XRT_MGMT_MAIN_GET_AXLF_SECTION =XRT_XLEAF_CUSTOM_BASE ,/* See comments in xleaf.h */ +XRT_MGMT_MAIN_GET_VBNV , +}; + +/* There are three kind of partitions. Each of them is programmed independently. */ +enum provider_kind { +XMGMT_BLP ,/* Base Logic Partition */ +XMGMT_PLP ,/* Provider Logic Partition */ +XMGMT_ULP ,/* User Logic Partition */ +}; + +struct xrt_mgmt_main_get_axlf_section { +enum provider_kind xmmigas_axlf_kind; +enum axlf_section_kind xmmigas_section_kind; +void *xmmigas_section; +u64 xmmigas_section_size; +}; + +#endif /* _XMGMT_MAIN_H_ */
drivers/fpga/xrt/mgmt/xmgmt-main.c new file +662 -0
662 lines not on this page · raw message
drivers/fpga/xrt/mgmt/xmgmt.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou <[email protected]> +* Cheng Zhen <[email protected]> +*/ + +#ifndef _XMGMT_H_ +#define _XMGMT_H_ + +#include "xmgmt-main.h" + +struct fpga_manager ; +int xmgmt_process_xclbin (struct xrt_device *xdev, +struct fpga_manager *fmgr, +const struct axlf *xclbin, +enum provider_kind kind); +void xmgmt_region_cleanup_all (struct xrt_device *xdev); + +int xmgmt_hot_reset (struct xrt_device *xdev); + +/* Getting dtb for specified group. Caller should vfree returned dtb. */ +char *xmgmt_get_dtb (struct xrt_device *xdev,enum provider_kind kind); +char *xmgmt_get_vbnv (struct xrt_device *xdev); +int xmgmt_get_provider_uuid (struct xrt_device *xdev, +enum provider_kind kind,uuid_t *uuid); + +int xmgmt_register_leaf (void ); +void xmgmt_unregister_leaf (void ); + +#endif /* _XMGMT_H_ */
include/uapi/linux/xrt/xmgmt-ioctl.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 11/20 fpga: xrt: fpga-mgr and region implementation for xclbin download
In reply to Lizhi Houfpga-mgr and region implementation for xclbin download which will be called from main xrt driver
--- drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++++++++++++++ drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 +++++++++ drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + 3 files changed, 689 insertions(+) create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-main-region.c create mode 100644 drivers/fpga/xrt/mgmt/xrt-mgr.c create mode 100644 drivers/fpga/xrt/mgmt/xrt-mgr.h
drivers/fpga/xrt/mgmt/xmgmt-main-region.c new file +483 -0
@@ -0,0 +1,483 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* FPGA Region Support for Xilinx Alveo +* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: [email protected] +*/ + +#include <linux/uuid.h> +#include <linux/fpga/fpga-bridge.h> +#include <linux/fpga/fpga-region.h> +#include <linux/slab.h> +#include "metadata.h" +#include "xleaf.h" +#include "xleaf/axigate.h" +#include "xclbin-helper.h" +#include "xmgmt.h" + +struct xmgmt_bridge { +struct xrt_device *xdev; +const char *bridge_name; +}; + +struct xmgmt_region { +struct xrt_device *xdev; +struct fpga_region *region; +struct fpga_compat_id compat_id; +uuid_t interface_uuid; +struct fpga_bridge *bridge; +int group_instance; +uuid_t depend_uuid; +struct list_head list; +}; + +struct xmgmt_region_match_arg { +struct xrt_device *xdev; +uuid_t *uuids; +u32 uuid_num; +}; + +static int xmgmt_br_enable_set (struct fpga_bridge *bridge,bool enable) +{ +struct xmgmt_bridge *br_data = (struct xmgmt_bridge *)bridge->priv; +struct xrt_device *axigate_leaf; +int rc; + + axigate_leaf =xleaf_get_leaf_by_epname (br_data->xdev, br_data->bridge_name); +if (!axigate_leaf) { +xrt_err (br_data->xdev,"failed to get leaf %s" , + br_data->bridge_name); +return -ENOENT ; + } + +if (enable) + rc =xleaf_call (axigate_leaf,XRT_AXIGATE_OPEN ,NULL ); +else + rc =xleaf_call (axigate_leaf,XRT_AXIGATE_CLOSE ,NULL ); + +if (rc) { +xrt_err (br_data->xdev,"failed to %s gate %s, rc %d" , + (enable ?"free" :"freeze" ), br_data->bridge_name, + rc); + } + +xleaf_put_leaf (br_data->xdev, axigate_leaf); + +return rc; +} + +static const struct fpga_bridge_ops xmgmt_bridge_ops = { + .enable_set = xmgmt_br_enable_set +}; + +static void xmgmt_destroy_bridge (struct fpga_bridge *br) +{ +struct xmgmt_bridge *br_data = br->priv; + +if (!br_data) +return ; + +xrt_info (br_data->xdev,"destroy fpga bridge %s" , br_data->bridge_name); +fpga_bridge_unregister (br); + +devm_kfree (DEV (br_data->xdev), br_data); + +fpga_bridge_free (br); +} + +static struct fpga_bridge *xmgmt_create_bridge (struct xrt_device *xdev, +char *dtb) +{ +struct fpga_bridge *br =NULL ; +struct xmgmt_bridge *br_data; +const char *gate; +int rc; + + br_data =devm_kzalloc (DEV (xdev),sizeof (*br_data),GFP_KERNEL ); +if (!br_data) +return NULL ; + br_data->xdev = xdev; + + br_data->bridge_name =XRT_MD_NODE_GATE_ULP ; + rc =xrt_md_find_endpoint (&xdev->dev, dtb,XRT_MD_NODE_GATE_ULP , +NULL , &gate); +if (rc) { + br_data->bridge_name =XRT_MD_NODE_GATE_PLP ; + rc =xrt_md_find_endpoint (&xdev->dev, dtb,XRT_MD_NODE_GATE_PLP , +NULL , &gate); + } +if (rc) { +xrt_err (xdev,"failed to get axigate, rc %d" , rc); + goto failed; + } + + br =fpga_bridge_create (DEV (xdev), br_data->bridge_name, + &xmgmt_bridge_ops, br_data); +if (!br) { +xrt_err (xdev,"failed to create bridge" ); + goto failed; + } + + rc =fpga_bridge_register (br); +if (rc) { +xrt_err (xdev,"failed to register bridge, rc %d" , rc); + goto failed; + } + +xrt_info (xdev,"created fpga bridge %s" , br_data->bridge_name); + +return br; + +failed: +if (br) +fpga_bridge_free (br); +if (br_data) +devm_kfree (DEV (xdev), br_data); + +return NULL ; +} + +static void xmgmt_destroy_region (struct fpga_region *region) +{ +struct xmgmt_region *r_data = region->priv; + +xrt_info (r_data->xdev,"destroy fpga region %llx.%llx" , + region->compat_id->id_h, region->compat_id->id_l); + +fpga_region_unregister (region); + +if (r_data->group_instance >0 ) +xleaf_destroy_group (r_data->xdev, r_data->group_instance); + +if (r_data->bridge) +xmgmt_destroy_bridge (r_data->bridge); + +if (r_data->region->info) { +fpga_image_info_free (r_data->region->info); + r_data->region->info =NULL ; + } + +fpga_region_free (region); + +devm_kfree (DEV (r_data->xdev), r_data); +} + +static int xmgmt_region_match (struct device *dev,const void *data) +{ +const struct xmgmt_region_match_arg *arg = data; +const struct fpga_region *match_region; +uuid_t compat_uuid; +int i; + +if (dev->parent != &arg->xdev->dev) +return false; + + match_region =to_fpga_region (dev); +/* +* The device tree provides both parent and child uuids for an +* xclbin in one array. Here we try both uuids to see if it matches +* with target region's compat_id. Strictly speaking we should +* only match xclbin's parent uuid with target region's compat_id +* but given the uuids by design are unique comparing with both +* does not hurt. +*/ +import_uuid (&compat_uuid, (const char *)match_region->compat_id); +for (i =0 ; i < arg->uuid_num; i++) { +if (uuid_equal (&compat_uuid, &arg->uuids[i])) +return true; + } + +return false; +} + +static int xmgmt_region_match_base (struct device *dev,const void *data) +{ +const struct xmgmt_region_match_arg *arg = data; +const struct fpga_region *match_region; +const struct xmgmt_region *r_data; + +if (dev->parent != &arg->xdev->dev) +return false; + + match_region =to_fpga_region (dev); + r_data = match_region->priv; +if (uuid_is_null (&r_data->depend_uuid)) +return true; + +return false; +} + +static int xmgmt_region_match_by_uuid (struct device *dev,const void *data) +{ +const struct xmgmt_region_match_arg *arg = data; +const struct fpga_region *match_region; +const struct xmgmt_region *r_data; + +if (dev->parent != &arg->xdev->dev) +return false; + +if (arg->uuid_num !=1 ) +return false; + + match_region =to_fpga_region (dev); + r_data = match_region->priv; +if (uuid_equal (&r_data->depend_uuid, arg->uuids)) +return true; + +return false; +} + +static void xmgmt_region_cleanup (struct fpga_region *region) +{ +struct xmgmt_region *r_data = region->priv, *pdata, *temp; +struct xrt_device *xdev = r_data->xdev; +struct xmgmt_region_match_arg arg = {0 }; +struct fpga_region *match_region =NULL ; +struct device *start_dev =NULL ; +LIST_HEAD (free_list); +uuid_t compat_uuid; + +list_add_tail (&r_data->list, &free_list); + arg.xdev = xdev; + arg.uuid_num =1 ; + arg.uuids = &compat_uuid; + +/* find all regions depending on this region */ +list_for_each_entry_safe (pdata, temp, &free_list, list) { +import_uuid (arg.uuids, (const char *)pdata->region->compat_id); + start_dev =NULL ; +while ((match_region =fpga_region_class_find (start_dev, &arg, + xmgmt_region_match_by_uuid))) { + pdata = match_region->priv; +list_add_tail (&pdata->list, &free_list); + start_dev = &match_region->dev; +put_device (&match_region->dev); + } + } + +list_del (&r_data->list); + +list_for_each_entry_safe_reverse (pdata, temp, &free_list, list) +xmgmt_destroy_region (pdata->region); + +if (r_data->group_instance >0 ) { +xleaf_destroy_group (xdev, r_data->group_instance); + r_data->group_instance =-1 ; + } +if (r_data->region->info) { +fpga_image_info_free (r_data->region->info); + r_data->region->info =NULL ; + } +} + +void xmgmt_region_cleanup_all (struct xrt_device *xdev) +{ +struct xmgmt_region_match_arg arg = {0 }; +struct fpga_region *base_region; + + arg.xdev = xdev; + +while ((base_region =fpga_region_class_find (NULL , &arg, xmgmt_region_match_base))) { +put_device (&base_region->dev); + +xmgmt_region_cleanup (base_region); +xmgmt_destroy_region (base_region); + } +} + +/* +* Program a region with a xclbin image. Bring up the subdevs and the +* group object to contain the subdevs. +*/ +static int xmgmt_region_program (struct fpga_region *region,const void *xclbin,char *dtb) +{ +const struct axlf *xclbin_obj = xclbin; +struct fpga_image_info *info; +struct xrt_device *xdev; +struct xmgmt_region *r_data; +int rc; + + r_data = region->priv; + xdev = r_data->xdev; + + info =fpga_image_info_alloc (&xdev->dev); +if (!info) +return -ENOMEM ; + + info->buf = xclbin; + info->count = xclbin_obj->header.length; + info->flags |=FPGA_MGR_PARTIAL_RECONFIG ; + region->info = info; + rc =fpga_region_program_fpga (region); +if (rc) { +xrt_err (xdev,"programming xclbin failed, rc %d" , rc); +return rc; + } + +/* free bridges to allow reprogram */ +if (region->get_bridges) +fpga_bridges_put (®ion->bridge_list); + +/* +* Next bringup the subdevs for this region which will be managed by +* its own group object. +*/ + r_data->group_instance =xleaf_create_group (xdev, dtb); +if (r_data->group_instance <0 ) { +xrt_err (xdev,"failed to create group, rc %d" , + r_data->group_instance); + rc = r_data->group_instance; +return rc; + } + + rc =xleaf_wait_for_group_bringup (xdev); +if (rc) +xrt_err (xdev,"group bringup failed, rc %d" , rc); +return rc; +} + +static int xmgmt_get_bridges (struct fpga_region *region) +{ +struct xmgmt_region *r_data = region->priv; +struct device *dev = &r_data->xdev->dev; + +return fpga_bridge_get_to_list (dev, region->info, ®ion->bridge_list); +} + +/* +* Program/create FPGA regions based on input xclbin file. +* 1. Identify a matching existing region for this xclbin +* 2. Tear down any previous objects for the found region +* 3. Program this region with input xclbin +* 4. Iterate over this region's interface uuids to determine if it defines any +* child region. Create fpga_region for the child region. +*/ +int xmgmt_process_xclbin (struct xrt_device *xdev, +struct fpga_manager *fmgr, +const struct axlf *xclbin, +enum provider_kind kind) +{ +struct fpga_region *region, *compat_region =NULL ; +struct xmgmt_region_match_arg arg = {0 }; +struct xmgmt_region *r_data; +uuid_t compat_uuid; +char *dtb =NULL ; +int rc, i; + + rc =xrt_xclbin_get_metadata (DEV (xdev), xclbin, &dtb); +if (rc) { +xrt_err (xdev,"failed to get dtb: %d" , rc); + goto failed; + } + + rc =xrt_md_get_interface_uuids (DEV (xdev), dtb,0 ,NULL ); +if (rc <0 ) { +xrt_err (xdev,"failed to get intf uuid" ); + rc = -EINVAL ; + goto failed; + } + arg.uuid_num = rc; + arg.uuids =kcalloc (arg.uuid_num,sizeof (uuid_t),GFP_KERNEL ); +if (!arg.uuids) { + rc = -ENOMEM ; + goto failed; + } + arg.xdev = xdev; + + rc =xrt_md_get_interface_uuids (DEV (xdev), dtb, arg.uuid_num, arg.uuids); +if (rc != arg.uuid_num) { +xrt_err (xdev,"only get %d uuids, expect %d" , rc, arg.uuid_num); + rc = -EINVAL ; + goto failed; + } + +/* if this is not base firmware, search for a compatible region */ +if (kind !=XMGMT_BLP ) { + compat_region =fpga_region_class_find (NULL , &arg, xmgmt_region_match); +if (!compat_region) { +xrt_err (xdev,"failed to get compatible region" ); + rc = -ENOENT ; + goto failed; + } + +xmgmt_region_cleanup (compat_region); + + rc =xmgmt_region_program (compat_region, xclbin, dtb); +if (rc) { +xrt_err (xdev,"failed to program region" ); + goto failed; + } + } + +if (compat_region) +import_uuid (&compat_uuid, (const char *)compat_region->compat_id); + +/* create all the new regions contained in this xclbin */ +for (i =0 ; i < arg.uuid_num; i++) { +if (compat_region &&uuid_equal (&compat_uuid, &arg.uuids[i])) { +/* region for this interface already exists */ +continue ; + } + + region =fpga_region_create (DEV (xdev), fmgr, xmgmt_get_bridges); +if (!region) { +xrt_err (xdev,"failed to create fpga region" ); + rc = -EFAULT ; + goto failed; + } + r_data =devm_kzalloc (DEV (xdev),sizeof (*r_data),GFP_KERNEL ); +if (!r_data) { + rc = -ENOMEM ; +fpga_region_free (region); + goto failed; + } + r_data->xdev = xdev; + r_data->region = region; + r_data->group_instance =-1 ; +uuid_copy (&r_data->interface_uuid, &arg.uuids[i]); +if (compat_region) +import_uuid (&r_data->depend_uuid, (const char *)compat_region->compat_id); + r_data->bridge =xmgmt_create_bridge (xdev, dtb); +if (!r_data->bridge) { +xrt_err (xdev,"failed to create fpga bridge" ); + rc = -EFAULT ; +devm_kfree (DEV (xdev), r_data); +fpga_region_free (region); + goto failed; + } + + region->compat_id = &r_data->compat_id; +export_uuid ((char *)region->compat_id, &r_data->interface_uuid); + region->priv = r_data; + + rc =fpga_region_register (region); +if (rc) { +xrt_err (xdev,"failed to register fpga region" ); +xmgmt_destroy_bridge (r_data->bridge); +fpga_region_free (region); +devm_kfree (DEV (xdev), r_data); + goto failed; + } + +xrt_info (xdev,"created fpga region %llx.%llx" , + region->compat_id->id_h, region->compat_id->id_l); + } + +if (compat_region) +put_device (&compat_region->dev); +vfree (dtb); +kfree (arg.uuids); +return 0 ; + +failed: +if (compat_region) { +put_device (&compat_region->dev); +xmgmt_region_cleanup (compat_region); + } + +vfree (dtb); +kfree (arg.uuids); +return rc; +}
drivers/fpga/xrt/mgmt/xrt-mgr.c new file +190 -0
190 lines not on this page · raw message
drivers/fpga/xrt/mgmt/xrt-mgr.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: [email protected] +*/ + +#ifndef _XRT_MGR_H_ +#define _XRT_MGR_H_ + +#include <linux/fpga/fpga-mgr.h> + +struct fpga_manager *xmgmt_fmgr_probe (struct xrt_device *xdev); +int xmgmt_fmgr_remove (struct fpga_manager *fmgr); + +#endif /* _XRT_MGR_H_ */
Signature · 1 line
2.27.0
PATCH v7 12/20 fpga: xrt: VSEC driver
In reply to Lizhi HouAdd VSEC driver. VSEC is a hardware function discovered by walking PCI Express configure space. A xrt device node will be created for it. VSEC provides board logic UUID and few offset of other hardware functions.
--- drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++++++++++++++++++++++++ 1 file changed, 372 insertions(+) create mode 100644 drivers/fpga/xrt/lib/xleaf/vsec.c
drivers/fpga/xrt/lib/xleaf/vsec.c new file +372 -0
@@ -0,0 +1,372 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Xilinx Alveo FPGA VSEC Driver +* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou<[email protected]> +*/ + +#include <linux/regmap.h> +#include "metadata.h" +#include "xdevice.h" +#include "xleaf.h" + +#define XRT_VSEC "xrt_vsec" + +#define VSEC_TYPE_UUID 0x50 +#define VSEC_TYPE_FLASH 0x51 +#define VSEC_TYPE_PLATINFO 0x52 +#define VSEC_TYPE_MAILBOX 0x53 +#define VSEC_TYPE_END 0xff + +#define VSEC_UUID_LEN 16 + +#define VSEC_REG_FORMAT 0x0 +#define VSEC_REG_LENGTH 0x4 +#define VSEC_REG_ENTRY 0x8 + +struct xrt_vsec_header { +u32 format; +u32 length; +u32 entry_sz; +u32 rsvd; +} __packed; + +struct xrt_vsec_entry { +u8 type; +u8 bar_rev; +u16 off_lo; +u32 off_hi; +u8 ver_type; +u8 minor; +u8 major; +u8 rsvd0; +u32 rsvd1; +} __packed; + +struct vsec_device { +u8 type; +char *ep_name; +ulong size; +char *compat; +}; + +static struct vsec_device vsec_devs[] = { + { + .type =VSEC_TYPE_UUID , + .ep_name =XRT_MD_NODE_BLP_ROM , + .size =VSEC_UUID_LEN , + .compat ="vsec-uuid" , + }, + { + .type =VSEC_TYPE_FLASH , + .ep_name =XRT_MD_NODE_FLASH_VSEC , + .size =4096 , + .compat ="vsec-flash" , + }, + { + .type =VSEC_TYPE_PLATINFO , + .ep_name =XRT_MD_NODE_PLAT_INFO , + .size =4 , + .compat ="vsec-platinfo" , + }, + { + .type =VSEC_TYPE_MAILBOX , + .ep_name =XRT_MD_NODE_MAILBOX_VSEC , + .size =48 , + .compat ="vsec-mbx" , + }, +}; + +XRT_DEFINE_REGMAP_CONFIG (vsec_regmap_config); + +struct xrt_vsec { +struct xrt_device *xdev; +struct regmap *regmap; +u32 length; + +char *metadata; +char uuid[VSEC_UUID_LEN ]; +int group; +}; + +static inline int vsec_read_entry (struct xrt_vsec *vsec,u32 index,struct xrt_vsec_entry *entry) +{ +int ret; + + ret =regmap_bulk_read (vsec->regmap,sizeof (struct xrt_vsec_header ) + + index *sizeof (struct xrt_vsec_entry ), entry, +sizeof (struct xrt_vsec_entry ) / + vsec_regmap_config.reg_stride); + +return ret; +} + +static inline u32 vsec_get_bar (struct xrt_vsec_entry *entry) +{ +return (entry->bar_rev >>4 ) &0xf ; +} + +static inline u64 vsec_get_bar_off (struct xrt_vsec_entry *entry) +{ +return entry->off_lo | ((u64 )entry->off_hi <<16 ); +} + +static inline u32 vsec_get_rev (struct xrt_vsec_entry *entry) +{ +return entry->bar_rev &0xf ; +} + +static char *type2epname (u32 type) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (vsec_devs); i++) { +if (vsec_devs[i].type == type) +return (vsec_devs[i].ep_name); + } + +return NULL ; +} + +static ulong type2size (u32 type) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (vsec_devs); i++) { +if (vsec_devs[i].type == type) +return (vsec_devs[i].size); + } + +return 0 ; +} + +static char *type2compat (u32 type) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (vsec_devs); i++) { +if (vsec_devs[i].type == type) +return (vsec_devs[i].compat); + } + +return NULL ; +} + +static int xrt_vsec_add_node (struct xrt_vsec *vsec, +void *md_blob,struct xrt_vsec_entry *p_entry) +{ +struct xrt_md_endpoint ep; +char compat_ver[64 ]; +int ret; + +if (!type2epname (p_entry->type)) +return -EINVAL ; + +/* +* VSEC may have more than 1 mailbox instance for the card +* which has more than 1 physical function. +* This is not supported for now. Assuming only one mailbox +*/ + +snprintf (compat_ver,sizeof (compat_ver) -1 ,"%d-%d.%d.%d" , + p_entry->ver_type, p_entry->major, p_entry->minor, +vsec_get_rev (p_entry)); + ep.ep_name =type2epname (p_entry->type); + ep.bar_index =vsec_get_bar (p_entry); + ep.bar_off =vsec_get_bar_off (p_entry); + ep.size =type2size (p_entry->type); + ep.compat =type2compat (p_entry->type); + ep.compat_ver = compat_ver; + ret =xrt_md_add_endpoint (DEV (vsec->xdev), vsec->metadata, &ep); +if (ret) +xrt_err (vsec->xdev,"add ep failed, ret %d" , ret); + +return ret; +} + +static int xrt_vsec_create_metadata (struct xrt_vsec *vsec) +{ +struct xrt_vsec_entry entry; +int i, ret; + + ret =xrt_md_create (&vsec->xdev->dev, &vsec->metadata); +if (ret) { +xrt_err (vsec->xdev,"create metadata failed" ); +return ret; + } + +for (i =0 ; i *sizeof (entry) < vsec->length - +sizeof (struct xrt_vsec_header ); i++) { + ret =vsec_read_entry (vsec, i, &entry); +if (ret) { +xrt_err (vsec->xdev,"failed read entry %d, ret %d" , i, ret); + goto fail; + } + +if (entry.type ==VSEC_TYPE_END ) +break ; + ret =xrt_vsec_add_node (vsec, vsec->metadata, &entry); +if (ret) + goto fail; + } + +return 0 ; + +fail: +vfree (vsec->metadata); + vsec->metadata =NULL ; +return ret; +} + +static int xrt_vsec_leaf_call (struct xrt_device *xdev,u32 cmd,void *arg) +{ +int ret =0 ; + +switch (cmd) { +case XRT_XLEAF_EVENT : +/* Does not handle any event. */ +break ; +default : + ret = -EINVAL ; +xrt_err (xdev,"should never been called" ); +break ; + } + +return ret; +} + +static int xrt_vsec_mapio (struct xrt_vsec *vsec) +{ +struct xrt_subdev_platdata *pdata =DEV_PDATA (vsec->xdev); +struct resource *res =NULL ; +void __iomem *base =NULL ; +const __be64 *bar_off; +const __be32 *bar; +u64 addr; +int ret; + +if (!pdata ||xrt_md_size (DEV (vsec->xdev), pdata->xsp_dtb) ==XRT_MD_INVALID_LENGTH ) { +xrt_err (vsec->xdev,"empty metadata" ); +return -EINVAL ; + } + + ret =xrt_md_get_prop (DEV (vsec->xdev), pdata->xsp_dtb,XRT_MD_NODE_VSEC , +NULL ,XRT_MD_PROP_BAR_IDX , (const void **)&bar,NULL ); +if (ret) { +xrt_err (vsec->xdev,"failed to get bar idx, ret %d" , ret); +return -EINVAL ; + } + + ret =xrt_md_get_prop (DEV (vsec->xdev), pdata->xsp_dtb,XRT_MD_NODE_VSEC , +NULL ,XRT_MD_PROP_OFFSET , (const void **)&bar_off,NULL ); +if (ret) { +xrt_err (vsec->xdev,"failed to get bar off, ret %d" , ret); +return -EINVAL ; + } + +xrt_info (vsec->xdev,"Map vsec at bar %d, offset 0x%llx" , +be32_to_cpu (*bar),be64_to_cpu (*bar_off)); + +xleaf_get_root_res (vsec->xdev,be32_to_cpu (*bar), &res); +if (!res) { +xrt_err (vsec->xdev,"failed to get bar addr" ); +return -EINVAL ; + } + + addr = res->start +be64_to_cpu (*bar_off); + + base =devm_ioremap (&vsec->xdev->dev, addr, vsec_regmap_config.max_register); +if (!base) { +xrt_err (vsec->xdev,"Map failed" ); +return -EIO ; + } + + vsec->regmap =devm_regmap_init_mmio (&vsec->xdev->dev, base, &vsec_regmap_config); +if (IS_ERR (vsec->regmap)) { +xrt_err (vsec->xdev,"regmap %pR failed" , res); +return PTR_ERR (vsec->regmap); + } + + ret =regmap_read (vsec->regmap,VSEC_REG_LENGTH , &vsec->length); +if (ret) { +xrt_err (vsec->xdev,"failed to read length %d" , ret); +return ret; + } + +return 0 ; +} + +static void xrt_vsec_remove (struct xrt_device *xdev) +{ +struct xrt_vsec *vsec; + + vsec =xrt_get_drvdata (xdev); + +if (vsec->group >=0 ) +xleaf_destroy_group (xdev, vsec->group); +vfree (vsec->metadata); +} + +static int xrt_vsec_probe (struct xrt_device *xdev) +{ +struct xrt_vsec *vsec; +int ret =0 ; + + vsec =devm_kzalloc (&xdev->dev,sizeof (*vsec),GFP_KERNEL ); +if (!vsec) +return -ENOMEM ; + + vsec->xdev = xdev; + vsec->group =-1 ; +xrt_set_drvdata (xdev, vsec); + + ret =xrt_vsec_mapio (vsec); +if (ret) + goto failed; + + ret =xrt_vsec_create_metadata (vsec); +if (ret) { +xrt_err (xdev,"create metadata failed, ret %d" , ret); + goto failed; + } + ret =xleaf_create_group (xdev, vsec->metadata); +if (ret <0 ) { +xrt_err (xdev,"create group failed, ret %d" , vsec->group); + goto failed; + } + vsec->group = ret; + +return 0 ; + +failed: +xrt_vsec_remove (xdev); + +return ret; +} + +static struct xrt_dev_endpoints xrt_vsec_endpoints[] = { + { + .xse_names = (struct xrt_dev_ep_names []){ + { .ep_name =XRT_MD_NODE_VSEC }, + {NULL }, + }, + .xse_min_ep =1 , + }, + {0 }, +}; + +static struct xrt_driver xrt_vsec_driver = { + .driver = { + .name =XRT_VSEC , + }, + .subdev_id =XRT_SUBDEV_VSEC , + .endpoints = xrt_vsec_endpoints, + .probe = xrt_vsec_probe, + .remove = xrt_vsec_remove, + .leaf_call = xrt_vsec_leaf_call, +}; + +XRT_LEAF_INIT_FINI_FUNC (vsec);
Signature · 1 line
2.27.0
PATCH v7 13/20 fpga: xrt: User Clock Subsystem driver
In reply to Lizhi HouAdd User Clock Subsystem (UCS) driver. UCS is a hardware function discovered by walking xclbin metadata. A xrt device node will be created for it. UCS enables/disables the dynamic region clocks.
--- drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 drivers/fpga/xrt/lib/xleaf/ucs.c
drivers/fpga/xrt/lib/xleaf/ucs.c new file +152 -0
@@ -0,0 +1,152 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Xilinx Alveo FPGA UCS Driver +* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou<[email protected]> +*/ + +#include <linux/mod_devicetable.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/regmap.h> +#include <linux/io.h> +#include "metadata.h" +#include "xleaf.h" +#include "xleaf/clock.h" + +#define UCS_ERR(ucs, fmt, arg...) \ + xrt_err((ucs)->xdev, fmt "\n", ##arg) +#define UCS_WARN(ucs, fmt, arg...) \ + xrt_warn((ucs)->xdev, fmt "\n", ##arg) +#define UCS_INFO(ucs, fmt, arg...) \ + xrt_info((ucs)->xdev, fmt "\n", ##arg) +#define UCS_DBG(ucs, fmt, arg...) \ + xrt_dbg((ucs)->xdev, fmt "\n", ##arg) + +#define XRT_UCS "xrt_ucs" + +#define XRT_UCS_CHANNEL1_REG 0 +#define XRT_UCS_CHANNEL2_REG 8 + +#define CLK_MAX_VALUE 6400 + +XRT_DEFINE_REGMAP_CONFIG (ucs_regmap_config); + +struct xrt_ucs { +struct xrt_device *xdev; +struct regmap *regmap; +struct mutex ucs_lock;/* ucs dev lock */ +}; + +static void xrt_ucs_event_cb (struct xrt_device *xdev,void *arg) +{ +struct xrt_event *evt = (struct xrt_event *)arg; +enum xrt_events e = evt->xe_evt; +struct xrt_device *leaf; +enum xrt_subdev_id id; +int instance; + + id = evt->xe_subdev.xevt_subdev_id; + instance = evt->xe_subdev.xevt_subdev_instance; + +if (e !=XRT_EVENT_POST_CREATION ) { +xrt_dbg (xdev,"ignored event %d" , e); +return ; + } + +if (id !=XRT_SUBDEV_CLOCK ) +return ; + + leaf =xleaf_get_leaf_by_id (xdev,XRT_SUBDEV_CLOCK , instance); +if (!leaf) { +xrt_err (xdev,"does not get clock subdev" ); +return ; + } + +xleaf_call (leaf,XRT_CLOCK_VERIFY ,NULL ); +xleaf_put_leaf (xdev, leaf); +} + +static int ucs_enable (struct xrt_ucs *ucs) +{ +int ret; + +mutex_lock (&ucs->ucs_lock); + ret =regmap_write (ucs->regmap,XRT_UCS_CHANNEL2_REG ,1 ); +mutex_unlock (&ucs->ucs_lock); + +return ret; +} + +static int +xrt_ucs_leaf_call (struct xrt_device *xdev,u32 cmd,void *arg) +{ +switch (cmd) { +case XRT_XLEAF_EVENT : +xrt_ucs_event_cb (xdev, arg); +break ; +default : +xrt_err (xdev,"unsupported cmd %d" , cmd); +return -EINVAL ; + } + +return 0 ; +} + +static int ucs_probe (struct xrt_device *xdev) +{ +struct xrt_ucs *ucs =NULL ; +void __iomem *base =NULL ; +struct resource *res; + + ucs =devm_kzalloc (&xdev->dev,sizeof (*ucs),GFP_KERNEL ); +if (!ucs) +return -ENOMEM ; + +xrt_set_drvdata (xdev, ucs); + ucs->xdev = xdev; +mutex_init (&ucs->ucs_lock); + + res =xrt_get_resource (xdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + + base =devm_ioremap_resource (&xdev->dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); + + ucs->regmap =devm_regmap_init_mmio (&xdev->dev, base, &ucs_regmap_config); +if (IS_ERR (ucs->regmap)) { +UCS_ERR (ucs,"map base %pR failed" , res); +return PTR_ERR (ucs->regmap); + } +ucs_enable (ucs); + +return 0 ; +} + +static struct xrt_dev_endpoints xrt_ucs_endpoints[] = { + { + .xse_names = (struct xrt_dev_ep_names []) { + { .ep_name =XRT_MD_NODE_UCS_CONTROL_STATUS }, + {NULL }, + }, + .xse_min_ep =1 , + }, + {0 }, +}; + +static struct xrt_driver xrt_ucs_driver = { + .driver = { + .name =XRT_UCS , + }, + .subdev_id =XRT_SUBDEV_UCS , + .endpoints = xrt_ucs_endpoints, + .probe = ucs_probe, + .leaf_call = xrt_ucs_leaf_call, +}; + +XRT_LEAF_INIT_FINI_FUNC (ucs);
Signature · 1 line
2.27.0
PATCH v7 14/20 fpga: xrt: ICAP driver
In reply to Lizhi HouICAP stands for Hardware Internal Configuration Access Port. ICAP is discovered by walking the firmware metadata. A xrt device node will be created for it. FPGA bitstream is written to hardware through ICAP.
--- drivers/fpga/xrt/include/xleaf/icap.h | 27 +++ drivers/fpga/xrt/lib/xleaf/icap.c | 328 ++++++++++++++++++++++++++ 2 files changed, 355 insertions(+) create mode 100644 drivers/fpga/xrt/include/xleaf/icap.h create mode 100644 drivers/fpga/xrt/lib/xleaf/icap.c
drivers/fpga/xrt/include/xleaf/icap.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou <[email protected]> +*/ + +#ifndef _XRT_ICAP_H_ +#define _XRT_ICAP_H_ + +#include "xleaf.h" + +/* +* ICAP driver leaf calls. +*/ +enum xrt_icap_leaf_cmd { +XRT_ICAP_WRITE =XRT_XLEAF_CUSTOM_BASE ,/* See comments in xleaf.h */ +XRT_ICAP_GET_IDCODE , +}; + +struct xrt_icap_wr { +void *xiiw_bit_data; +u32 xiiw_data_len; +}; + +#endif /* _XRT_ICAP_H_ */
drivers/fpga/xrt/lib/xleaf/icap.c new file +328 -0
328 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 15/20 fpga: xrt: devctl xrt driver
In reply to Lizhi HouAdd devctl driver. devctl is a type of hardware function which only has few registers to read or write. They are discovered by walking firmware metadata. A xrt device node will be created for them.
--- drivers/fpga/xrt/include/xleaf/devctl.h | 40 ++++++ drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++++++++++++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 drivers/fpga/xrt/include/xleaf/devctl.h create mode 100644 drivers/fpga/xrt/lib/xleaf/devctl.c
drivers/fpga/xrt/include/xleaf/devctl.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou <[email protected]> +*/ + +#ifndef _XRT_DEVCTL_H_ +#define _XRT_DEVCTL_H_ + +#include "xleaf.h" + +/* +* DEVCTL driver leaf calls. +*/ +enum xrt_devctl_leaf_cmd { +XRT_DEVCTL_READ =XRT_XLEAF_CUSTOM_BASE ,/* See comments in xleaf.h */ +}; + +enum xrt_devctl_id { +XRT_DEVCTL_ROM_UUID =0 , +XRT_DEVCTL_DDR_CALIB , +XRT_DEVCTL_GOLDEN_VER , +XRT_DEVCTL_MAX +}; + +struct xrt_devctl_rw { +u32 xdr_id; +void *xdr_buf; +u32 xdr_len; +u32 xdr_offset; +}; + +struct xrt_devctl_intf_uuid { +u32 uuid_num; +uuid_t *uuids; +}; + +#endif /* _XRT_DEVCTL_H_ */
drivers/fpga/xrt/lib/xleaf/devctl.c new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 16/20 fpga: xrt: clock driver
In reply to Lizhi HouAdd clock driver. Clock is a hardware function discovered by walking xclbin metadata. A xrt device node will be created for it. Other part of driver configures clock through clock driver.
--- drivers/fpga/xrt/include/xleaf/clock.h | 29 ++ drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++++++++++++++ 2 files changed, 681 insertions(+) create mode 100644 drivers/fpga/xrt/include/xleaf/clock.h create mode 100644 drivers/fpga/xrt/lib/xleaf/clock.c
drivers/fpga/xrt/include/xleaf/clock.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou <[email protected]> +*/ + +#ifndef _XRT_CLOCK_H_ +#define _XRT_CLOCK_H_ + +#include "xleaf.h" +#include <linux/xrt/xclbin.h> + +/* +* CLOCK driver leaf calls. +*/ +enum xrt_clock_leaf_cmd { +XRT_CLOCK_SET =XRT_XLEAF_CUSTOM_BASE ,/* See comments in xleaf.h */ +XRT_CLOCK_GET , +XRT_CLOCK_VERIFY , +}; + +struct xrt_clock_get { +u16 freq; +u32 freq_cnter; +}; + +#endif /* _XRT_CLOCK_H_ */
drivers/fpga/xrt/lib/xleaf/clock.c new file +652 -0
652 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 17/20 fpga: xrt: clock frequency counter driver
In reply to Lizhi HouAdd clock frequency counter driver. Clock frequency counter is a hardware function discovered by walking xclbin metadata. A xrt device node will be created for it. Other part of driver can read the actual clock frequency through clock frequency counter driver.
--- drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 +++ drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 drivers/fpga/xrt/include/xleaf/clkfreq.h create mode 100644 drivers/fpga/xrt/lib/xleaf/clkfreq.c
drivers/fpga/xrt/include/xleaf/clkfreq.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou <[email protected]> +*/ + +#ifndef _XRT_CLKFREQ_H_ +#define _XRT_CLKFREQ_H_ + +#include "xleaf.h" + +/* +* CLKFREQ driver leaf calls. +*/ +enum xrt_clkfreq_leaf_cmd { +XRT_CLKFREQ_READ =XRT_XLEAF_CUSTOM_BASE ,/* See comments in xleaf.h */ +}; + +#endif /* _XRT_CLKFREQ_H_ */
drivers/fpga/xrt/lib/xleaf/clkfreq.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 18/20 fpga: xrt: DDR calibration driver
In reply to Lizhi HouAdd DDR calibration driver. DDR calibration is a hardware function discovered by walking firmware metadata. A xrt device node will be created for it. Hardware provides DDR calibration status through this function.
--- .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 +++ drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 ++++++++++++++++++ 2 files changed, 238 insertions(+) create mode 100644 drivers/fpga/xrt/include/xleaf/ddr_calibration.h create mode 100644 drivers/fpga/xrt/lib/xleaf/ddr_calibration.c
drivers/fpga/xrt/include/xleaf/ddr_calibration.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Cheng Zhen <[email protected]> +*/ + +#ifndef _XRT_DDR_CALIBRATION_H_ +#define _XRT_DDR_CALIBRATION_H_ + +#include "xleaf.h" +#include <linux/xrt/xclbin.h> + +/* +* Memory calibration driver leaf calls. +*/ +enum xrt_calib_results { +XRT_CALIB_UNKNOWN =0 , +XRT_CALIB_SUCCEEDED , +XRT_CALIB_FAILED , +}; + +enum xrt_calib_leaf_cmd { +XRT_CALIB_RESULT =XRT_XLEAF_CUSTOM_BASE ,/* See comments in xleaf.h */ +}; + +#endif /* _XRT_DDR_CALIBRATION_H_ */
drivers/fpga/xrt/lib/xleaf/ddr_calibration.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 19/20 fpga: xrt: partition isolation driver
In reply to Lizhi HouAdd partition isolation xrt driver. partition isolation is a hardware function discovered by walking firmware metadata. A xrt device node will be created for it. Partition isolation function isolate the different fpga regions
--- drivers/fpga/xrt/include/xleaf/axigate.h | 23 ++ drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 drivers/fpga/xrt/include/xleaf/axigate.h create mode 100644 drivers/fpga/xrt/lib/xleaf/axigate.c
drivers/fpga/xrt/include/xleaf/axigate.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020-2021 Xilinx, Inc. +* +* Authors: +* Lizhi Hou <[email protected]> +*/ + +#ifndef _XRT_AXIGATE_H_ +#define _XRT_AXIGATE_H_ + +#include "xleaf.h" +#include "metadata.h" + +/* +* AXIGATE driver leaf calls. +*/ +enum xrt_axigate_leaf_cmd { +XRT_AXIGATE_CLOSE =XRT_XLEAF_CUSTOM_BASE ,/* See comments in xleaf.h */ +XRT_AXIGATE_OPEN , +}; + +#endif /* _XRT_AXIGATE_H_ */
drivers/fpga/xrt/lib/xleaf/axigate.c new file +325 -0
325 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v7 20/20 fpga: xrt: Kconfig and Makefile updates for XRT drivers
In reply to Lizhi HouUpdate fpga Kconfig/Makefile and add Kconfig/Makefile for new drivers.
--- drivers/Makefile | 1 + drivers/fpga/Kconfig | 2 ++ drivers/fpga/Makefile | 5 +++++ drivers/fpga/xrt/Kconfig | 8 ++++++++ drivers/fpga/xrt/lib/Kconfig | 17 +++++++++++++++++ drivers/fpga/xrt/lib/Makefile | 30 ++++++++++++++++++++++++++++++ drivers/fpga/xrt/metadata/Kconfig | 12 ++++++++++++ drivers/fpga/xrt/metadata/Makefile | 16 ++++++++++++++++ drivers/fpga/xrt/mgmt/Kconfig | 15 +++++++++++++++ drivers/fpga/xrt/mgmt/Makefile | 19 +++++++++++++++++++ 10 files changed, 125 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/metadata/Kconfig create mode 100644 drivers/fpga/xrt/metadata/Makefile create mode 100644 drivers/fpga/xrt/mgmt/Kconfig create mode 100644 drivers/fpga/xrt/mgmt/Makefile
drivers/Makefile +1 -0
@@ -181,6 +181,7 @@ obj-$(CONFIG_STM) += hwtracing/stm/ obj-$(CONFIG_ANDROID) += android/ obj-$(CONFIG_NVMEM) += nvmem/ obj-$(CONFIG_FPGA) += fpga/ +obj-$(CONFIG_FPGA_XRT_METADATA) += fpga/ obj-$(CONFIG_FSI) += fsi/ obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_MULTIPLEXER) += mux/
drivers/fpga/Kconfig +2 -0
@@ -234,4 +234,6 @@ config FPGA_MGR_ZYNQMP_FPGA to configure the programmable logic(PL) through PS on ZynqMP SoC. +source "drivers/fpga/xrt/Kconfig" + endif # FPGA
drivers/fpga/Makefile +5 -0
@@ -48,3 +48,8 @@ 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_METADATA) += xrt/metadata/ +obj-$(CONFIG_FPGA_XRT_LIB) += xrt/lib/ +obj-$(CONFIG_FPGA_XRT_XMGMT) += xrt/mgmt/
drivers/fpga/xrt/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Xilinx Alveo FPGA device configuration +# + +source "drivers/fpga/xrt/metadata/Kconfig" +source "drivers/fpga/xrt/lib/Kconfig" +source "drivers/fpga/xrt/mgmt/Kconfig"
drivers/fpga/xrt/lib/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# 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 + select FPGA_XRT_METADATA + 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.
drivers/fpga/xrt/lib/Makefile new file +30 -0
@@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2020-2021 Xilinx, Inc. All rights reserved. +# +# Authors: [email protected] +# + +FULL_XRT_PATH=$(srctree)/$(src)/.. +FULL_DTC_PATH=$(srctree)/scripts/dtc/libfdt + +obj-$(CONFIG_FPGA_XRT_LIB) += xrt-lib.o + +xrt-lib-objs := \ + lib-drv.o \ + xroot.o \ + xclbin.o \ + subdev.o \ + cdev.o \ + group.o \ + xleaf/vsec.o \ + xleaf/axigate.o \ + xleaf/devctl.o \ + xleaf/icap.o \ + xleaf/clock.o \ + xleaf/clkfreq.o \ + xleaf/ucs.o \ + xleaf/ddr_calibration.o + +ccflags-y := -I$(FULL_XRT_PATH)/include \ + -I$(FULL_DTC_PATH)
drivers/fpga/xrt/metadata/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# XRT Alveo FPGA device configuration +# + +config FPGA_XRT_METADATA + bool "XRT Alveo Driver Metadata Parser" + select LIBFDT + help + This option provides helper functions to parse Xilinx Alveo FPGA + firmware metadata. The metadata is in device tree format and the + XRT driver uses it to discover the HW subsystems behind PCIe BAR.
drivers/fpga/xrt/metadata/Makefile new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2020-2021 Xilinx, Inc. All rights reserved. +# +# Authors: [email protected] +# + +FULL_XRT_PATH=$(srctree)/$(src)/.. +FULL_DTC_PATH=$(srctree)/scripts/dtc/libfdt + +obj-$(CONFIG_FPGA_XRT_METADATA) += xrt-md.o + +xrt-md-objs := metadata.o + +ccflags-y := -I$(FULL_XRT_PATH)/include \ + -I$(FULL_DTC_PATH)
drivers/fpga/xrt/mgmt/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# 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_XRT_METADATA + 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.
drivers/fpga/xrt/mgmt/Makefile new file +19 -0
@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2020-2021 Xilinx, Inc. All rights reserved. +# +# Authors: [email protected] +# + +FULL_XRT_PATH=$(srctree)/$(src)/.. +FULL_DTC_PATH=$(srctree)/scripts/dtc/libfdt + +obj-$(CONFIG_FPGA_XRT_XMGMT) += xrt-mgmt.o + +xrt-mgmt-objs := root.o \ + xmgmt-main.o \ + xrt-mgr.o \ + xmgmt-main-region.o + +ccflags-y := -I$(FULL_XRT_PATH)/include \ + -I$(FULL_DTC_PATH)
Signature · 1 line
2.27.0
Hi Moritz and Tom,
Thanks a lot for reviewing the XRT patches. This v7 patches contains our latest fixes for all review comments. And it seems auto build robot is happy with it as well. Do you have more comment against v7? What will be the next step for XRT patches if it looks ok to you?
Thanks,
Lizhi
Quoted 271 lines · Lizhi Hou
Hello,
This is V7 of patch series which adds management physical function driver for Xilinx Alveo PCIe accelerator cards.
https://www.xilinx.com/products/boards-and-kits/alveo.htmlThis driver is part of Xilinx Runtime (XRT) open source stack.
XILINX ALVEO PLATFORM ARCHITECTURE
Alveo PCIe FPGA based platforms have a static *shell* partition and a partial re-configurable *user* partition. The shell partition is automatically loaded from flash when host is booted and PCIe is enumerated by BIOS. Shell cannot be changed till the next cold reboot. The shell exposes two PCIe physical functions:
1. management physical function
2. user physical functionThe patch series includes
Documentation/xrt.rstwhich describes Alveo platform, XRT driver architecture and deployment model in more detail.Users compile their high level design in C/C++/OpenCL or RTL into FPGA image using Vitis tools.
https://www.xilinx.com/products/design-tools/vitis/vitis-platform.htmlThe compiled image is packaged as xclbin which contains partial bitstream for the user partition and necessary metadata. Users can dynamically swap the image running on the user partition in order to switch between different workloads by loading different xclbins.
XRT DRIVERS FOR XILINX ALVEO
XRT Linux kernel driver *xrt-mgmt* binds to management physical function of Alveo platform. The modular driver framework is organized into several platform drivers which primarily handle the following functionality:
1. Loading firmware container also called xsabin at driver attach time 2. Loading of user compiled xclbin with FPGA Manager integration 3. Clock scaling of image running on user partition 4. In-band sensors: temp, voltage, power, etc. 5. Device reset and rescanThe platform drivers are packaged into *xrt-lib* helper module with well defined interfaces. The module provides a pseudo-bus implementation for the platform drivers. More details on the driver model can be found in
Documentation/xrt.rst.User physical function driver is not included in this patch series.
LIBFDT REQUIREMENT
XRT driver infrastructure uses Device Tree as a metadata format to discover HW subsystems in the Alveo PCIe device. The Device Tree schema used by XRT is documented in
Documentation/xrt.rst.TESTING AND VALIDATION
xrt-mgmt driver can be tested with full XRT open source stack which includes user space libraries, board utilities and (out of tree) first generation user physical function driver xocl. XRT open source runtime stack is available at https://github.com/Xilinx/XRT
Complete documentation for XRT open source stack including sections on Alveo/XRT security and platform architecture can be found here:
https://xilinx.github.io/XRT/master/html/index.html
https://xilinx.github.io/XRT/master/html/security.html
https://xilinx.github.io/XRT/master/html/platforms_partitions.htmlChanges since v6:
- Resolved grammatical errors and cleaned up taxonomy inxrt.rstdocumentation.
- Fixed clang warnings.
- Updated code base to include v6 code review comments.Changes since v5:
- Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
- Updated code base to include v5 code review comments.xrt.rst: address grammar and taxonomysubdev_id.h: definesXRT_SUBDEV_INVALID= 0xclbin.c: change shift operation tobe_to_cpu
- Resolved kernel test robot errors.Changes since v4:
- Addedxrt_bus_typeandxrt_device. All sub devices were changed from platform_bus_type/platform_device to xrt_bus_type/xrt_device.
- Renamed xrt-mgmt driver to xrt-mgnt driver.
- Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file names
- Moved pci function calls from infrastructure to xrt-mgnt driver.
- Renamed files:mgmt/main.c->mgnt/xmgnt-main.cmgmt/main-region.c -> mgnt/xmgnt-main-region.c include/xmgmt-main.h -> include/xmgnt-main.h mgmt/fmgr-drv.c -> mgnt/xrt-mgr.c mgmt/fmgr.h -> mgnt/xrt-mgr.h- Updated code base to include v4 code review comments.
Changes since v3:
- Leaf drivers use regmap-mmio to access hardware registers.
- Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
- Renamed files: calib.[c|h] -> ddr_calibration.[c|h], lib/main.[c|h] -> lib/lib-drv.[c|h],mgmt/main-impl.h- >mgmt/xmgnt.h
- Updated code base to include v3 code review comments.Changes since v2:
- Streamlined the driver framework into *xleaf*, *group* and *xroot*
- Updated documentation to show the driver model with examples
- Addressed kernel test robot errors
- Added a selftest for basic driver framework
- Documented device tree schema
- Removed need to export libfdt symbolsChanges since v1:
- Updated the driver to usefpga_regionandfpga_bridgefor FPGA programming
- Dropped platform drivers not related to PR programming to focus on XRT core framework
- UpdatedDocumentation/fpga/xrt.rstwith information on XRT core framework
- Addressed checkpatch issues
- Dropped xrt- prefix from some header filesFor reference V6 version of patch series can be found here:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/Lizhi Hou (20):
Documentation: fpga: Add a document describing XRT Alveo drivers
fpga: xrt: driver metadata helper functions
fpga: xrt: xclbin file helper functions
fpga: xrt: xrt-lib driver manager
fpga: xrt: group driver
fpga: xrt: char dev node helper functions
fpga: xrt: root driver infrastructure
fpga: xrt: driver infrastructure
fpga: xrt: management physical function driver (root)
fpga: xrt: main driver for management function device
fpga: xrt: fpga-mgr and region implementation for xclbin download
fpga: xrt: VSEC driver
fpga: xrt: User Clock Subsystem driver
fpga: xrt: ICAP driver
fpga: xrt: devctl xrt driver
fpga: xrt: clock driver
fpga: xrt: clock frequency counter driver
fpga: xrt: DDR calibration driver
fpga: xrt: partition isolation driver
fpga: xrt:KconfigandMakefileupdates for XRT driversDocumentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 870 ++++++++++++++++++ MAINTAINERS | 11 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 2 + drivers/fpga/Makefile | 5 + drivers/fpga/xrt/Kconfig | 8 + drivers/fpga/xrt/include/events.h | 45 + drivers/fpga/xrt/include/group.h | 25 + drivers/fpga/xrt/include/metadata.h | 236 +++++ drivers/fpga/xrt/include/subdev_id.h | 39 + drivers/fpga/xrt/include/xclbin-helper.h | 48 + drivers/fpga/xrt/include/xdevice.h | 131 +++ drivers/fpga/xrt/include/xleaf.h | 205 +++++ drivers/fpga/xrt/include/xleaf/axigate.h | 23 + drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 + drivers/fpga/xrt/include/xleaf/clock.h | 29 + .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 + drivers/fpga/xrt/include/xleaf/devctl.h | 40 + drivers/fpga/xrt/include/xleaf/icap.h | 27 + drivers/fpga/xrt/include/xmgmt-main.h | 34 + drivers/fpga/xrt/include/xroot.h | 117 +++ drivers/fpga/xrt/lib/Kconfig | 17 + drivers/fpga/xrt/lib/Makefile | 30 + drivers/fpga/xrt/lib/cdev.c | 209 +++++ drivers/fpga/xrt/lib/group.c | 278 ++++++ drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++ drivers/fpga/xrt/lib/lib-drv.h | 21 + drivers/fpga/xrt/lib/subdev.c | 859 +++++++++++++++++ drivers/fpga/xrt/lib/subdev_pool.h | 53 ++ drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++ drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++ drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++ drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++ drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++ drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++ drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++ drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++ drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++ drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++ drivers/fpga/xrt/metadata/Kconfig | 12 + drivers/fpga/xrt/metadata/Makefile | 16 + drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++ drivers/fpga/xrt/mgmt/Kconfig | 15 + drivers/fpga/xrt/mgmt/Makefile | 19 + drivers/fpga/xrt/mgmt/root.c | 420 +++++++++ drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++ drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++ drivers/fpga/xrt/mgmt/xmgmt.h | 33 + drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++ drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + include/uapi/linux/xrt/xclbin.h | 409 ++++++++ include/uapi/linux/xrt/xmgmt-ioctl.h | 46 + 53 files changed, 9988 insertions(+)create mode 100644
Documentation/fpga/xrt.rst
create mode 100644drivers/fpga/xrt/Kconfig
create mode 100644drivers/fpga/xrt/include/events.hcreate mode 100644drivers/fpga/xrt/include/group.hcreate mode 100644drivers/fpga/xrt/include/metadata.hcreate mode 100644drivers/fpga/xrt/include/subdev_id.hcreate mode 100644drivers/fpga/xrt/include/xclbin-helper.hcreate mode 100644drivers/fpga/xrt/include/xdevice.hcreate mode 100644drivers/fpga/xrt/include/xleaf.hcreate mode 100644drivers/fpga/xrt/include/xleaf/axigate.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clkfreq.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clock.hcreate mode 100644drivers/fpga/xrt/include/xleaf/ddr_calibration.hcreate mode 100644drivers/fpga/xrt/include/xleaf/devctl.hcreate mode 100644drivers/fpga/xrt/include/xleaf/icap.hcreate mode 100644drivers/fpga/xrt/include/xmgmt-main.hcreate mode 100644drivers/fpga/xrt/include/xroot.hcreate mode 100644drivers/fpga/xrt/lib/Kconfig
create mode 100644drivers/fpga/xrt/lib/Makefile
create mode 100644drivers/fpga/xrt/lib/cdev.c
create mode 100644drivers/fpga/xrt/lib/group.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.h
create mode 100644drivers/fpga/xrt/lib/subdev.c
create mode 100644drivers/fpga/xrt/lib/subdev_pool.hcreate mode 100644drivers/fpga/xrt/lib/xclbin.c
create mode 100644drivers/fpga/xrt/lib/xleaf/axigate.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clkfreq.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clock.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ddr_calibration.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/devctl.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/icap.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ucs.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/vsec.ccreate mode 100644drivers/fpga/xrt/lib/xroot.c
create mode 100644drivers/fpga/xrt/metadata/Kconfigcreate mode 100644drivers/fpga/xrt/metadata/Makefilecreate mode 100644drivers/fpga/xrt/metadata/metadata.ccreate mode 100644drivers/fpga/xrt/mgmt/Kconfig
create mode 100644drivers/fpga/xrt/mgmt/Makefile
create mode 100644drivers/fpga/xrt/mgmt/root.c
create mode 100644drivers/fpga/xrt/mgmt/xmgmt-main-region.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt-main.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt.h
create mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.ccreate mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.hcreate mode 100644include/uapi/linux/xrt/xclbin.hcreate mode 100644include/uapi/linux/xrt/xmgmt-ioctl.h
Tom Rix
reviewerRFC : [PATCH V7 XRT Alveo 00/20] XRT Alveo driver overview
Quoted 3 lines · Lizhi Hou
Hi Moritz and Tom,
Thanks a lot for reviewing the XRT patches. This v7 patches contains our latest fixes for all review comments. And it seems auto build robot is happy with it as well. Do you have more comment against v7? What will be the next step for XRT patches if it looks ok to you?
Please do not add any features to the patchset.
When you add a feature, that tends to reset the review process.
For little stuff.
I need to look at the documentation again, iirc that was the only issue in v6.
For big stuff.
At the beginning some possible refactor questions were raised, I don't know if they have been resolved.
ex/
some of the leaf drivers like clock should be moved the clock subsystem
the xrt/ dir vs existing flat, we don't want both.
is your xrt bus consistent with dfl bus, can it support adding devices outside of fpga/xrt
how clean are the public headers
Since flipflopping on refactoring is a painful, let's try to get a consensus before moving forward.
This may mean the patchset is committed by parts as it and the existing code changes.
Lets start with the directory structure.
Since there are a lot of files in xrt, the xrt/ makes sense.
For other fpga's with a lot of files, say > 3, we need to change ex/
dfl-foo.c to dfl/foo.c
to be consistent.
The Kconfig and Makefiles for xrt/ and dfl/ would only be in that top subdir.
Which i think is a change for xrt/
I'll whip up something for dfl/ to move things along.
Tom
Quoted 293 lines
Thanks,
Lizhi
Quoted 285 lines · Lizhi Hou
Hello,
This is V7 of patch series which adds management physical function driver for Xilinx Alveo PCIe accelerator cards.
https://www.xilinx.com/products/boards-and-kits/alveo.htmlThis driver is part of Xilinx Runtime (XRT) open source stack.
XILINX ALVEO PLATFORM ARCHITECTURE
Alveo PCIe FPGA based platforms have a static *shell* partition and a partial re-configurable *user* partition. The shell partition is automatically loaded from flash when host is booted and PCIe is enumerated by BIOS. Shell cannot be changed till the next cold reboot. The shell exposes two PCIe physical functions:
1. management physical function
2. user physical functionThe patch series includes
Documentation/xrt.rstwhich describes Alveo platform, XRT driver architecture and deployment model in more detail.Users compile their high level design in C/C++/OpenCL or RTL into FPGA image using Vitis tools.
https://www.xilinx.com/products/design-tools/vitis/vitis-platform.htmlThe compiled image is packaged as xclbin which contains partial bitstream for the user partition and necessary metadata. Users can dynamically swap the image running on the user partition in order to switch between different workloads by loading different xclbins.
XRT DRIVERS FOR XILINX ALVEO
XRT Linux kernel driver *xrt-mgmt* binds to management physical function of Alveo platform. The modular driver framework is organized into several platform drivers which primarily handle the following functionality:
1. Loading firmware container also called xsabin at driver attach time 2. Loading of user compiled xclbin with FPGA Manager integration 3. Clock scaling of image running on user partition
4. In-band sensors: temp, voltage, power, etc.
5. Device reset and rescanThe platform drivers are packaged into *xrt-lib* helper module with well defined interfaces. The module provides a pseudo-bus implementation for the platform drivers. More details on the driver model can be found in
Documentation/xrt.rst.User physical function driver is not included in this patch series.
LIBFDT REQUIREMENT
XRT driver infrastructure uses Device Tree as a metadata format to discover HW subsystems in the Alveo PCIe device. The Device Tree schema used by XRT is documented in
Documentation/xrt.rst.TESTING AND VALIDATION
xrt-mgmt driver can be tested with full XRT open source stack which includes user space libraries, board utilities and (out of tree) first generation user physical function driver xocl. XRT open source runtime stack is available at https://github.com/Xilinx/XRT
Complete documentation for XRT open source stack including sections on Alveo/XRT security and platform architecture can be found here:
https://xilinx.github.io/XRT/master/html/index.html
https://xilinx.github.io/XRT/master/html/security.html
https://xilinx.github.io/XRT/master/html/platforms_partitions.htmlChanges since v6:
- Resolved grammatical errors and cleaned up taxonomy inxrt.rstdocumentation.
- Fixed clang warnings.
- Updated code base to include v6 code review comments.Changes since v5:
- Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
- Updated code base to include v5 code review comments.xrt.rst: address grammar and taxonomysubdev_id.h: definesXRT_SUBDEV_INVALID= 0xclbin.c: change shift operation tobe_to_cpu
- Resolved kernel test robot errors.Changes since v4:
- Addedxrt_bus_typeandxrt_device. All sub devices were changed from platform_bus_type/platform_device to xrt_bus_type/xrt_device.
- Renamed xrt-mgmt driver to xrt-mgnt driver.
- Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file names
- Moved pci function calls from infrastructure to xrt-mgnt driver.
- Renamed files:mgmt/main.c->mgnt/xmgnt-main.cmgmt/main-region.c->mgnt/xmgnt-main-region.cinclude/xmgmt-main.h->include/xmgnt-main.hmgmt/fmgr-drv.c->mgnt/xrt-mgr.cmgmt/fmgr.h->mgnt/xrt-mgr.h
- Updated code base to include v4 code review comments.Changes since v3:
- Leaf drivers use regmap-mmio to access hardware registers.
- Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
- Renamed files: calib.[c|h] -> ddr_calibration.[c|h], lib/main.[c|h] -> lib/lib-drv.[c|h],mgmt/main-impl.h- >mgmt/xmgnt.h
- Updated code base to include v3 code review comments.Changes since v2:
- Streamlined the driver framework into *xleaf*, *group* and *xroot*
- Updated documentation to show the driver model with examples
- Addressed kernel test robot errors
- Added a selftest for basic driver framework
- Documented device tree schema
- Removed need to export libfdt symbolsChanges since v1:
- Updated the driver to usefpga_regionandfpga_bridgefor FPGA programming
- Dropped platform drivers not related to PR programming to focus on XRT core framework
- UpdatedDocumentation/fpga/xrt.rstwith information on XRT core framework
- Addressed checkpatch issues
- Dropped xrt- prefix from some header filesFor reference V6 version of patch series can be found here:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
Lizhi Hou (20):
Documentation: fpga: Add a document describing XRT Alveo drivers
fpga: xrt: driver metadata helper functions
fpga: xrt: xclbin file helper functions
fpga: xrt: xrt-lib driver manager
fpga: xrt: group driver
fpga: xrt: char dev node helper functions
fpga: xrt: root driver infrastructure
fpga: xrt: driver infrastructure
fpga: xrt: management physical function driver (root)
fpga: xrt: main driver for management function device
fpga: xrt: fpga-mgr and region implementation for xclbin download
fpga: xrt: VSEC driver
fpga: xrt: User Clock Subsystem driver
fpga: xrt: ICAP driver
fpga: xrt: devctl xrt driver
fpga: xrt: clock driver
fpga: xrt: clock frequency counter driver
fpga: xrt: DDR calibration driver
fpga: xrt: partition isolation driver
fpga: xrt:KconfigandMakefileupdates for XRT driversDocumentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 870 ++++++++++++++++++ MAINTAINERS | 11 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 2 + drivers/fpga/Makefile | 5 + drivers/fpga/xrt/Kconfig | 8 + drivers/fpga/xrt/include/events.h | 45 + drivers/fpga/xrt/include/group.h | 25 + drivers/fpga/xrt/include/metadata.h | 236 +++++ drivers/fpga/xrt/include/subdev_id.h | 39 + drivers/fpga/xrt/include/xclbin-helper.h | 48 + drivers/fpga/xrt/include/xdevice.h | 131 +++ drivers/fpga/xrt/include/xleaf.h | 205 +++++ drivers/fpga/xrt/include/xleaf/axigate.h | 23 + drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 + drivers/fpga/xrt/include/xleaf/clock.h | 29 + .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 + drivers/fpga/xrt/include/xleaf/devctl.h | 40 + drivers/fpga/xrt/include/xleaf/icap.h | 27 + drivers/fpga/xrt/include/xmgmt-main.h | 34 + drivers/fpga/xrt/include/xroot.h | 117 +++ drivers/fpga/xrt/lib/Kconfig | 17 + drivers/fpga/xrt/lib/Makefile | 30 + drivers/fpga/xrt/lib/cdev.c | 209 +++++ drivers/fpga/xrt/lib/group.c | 278 ++++++ drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++ drivers/fpga/xrt/lib/lib-drv.h | 21 + drivers/fpga/xrt/lib/subdev.c | 859 +++++++++++++++++ drivers/fpga/xrt/lib/subdev_pool.h | 53 ++ drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++ drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++ drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++ drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++ drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++ drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++ drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++ drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++ drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++ drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++ drivers/fpga/xrt/metadata/Kconfig | 12 + drivers/fpga/xrt/metadata/Makefile | 16 + drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++ drivers/fpga/xrt/mgmt/Kconfig | 15 + drivers/fpga/xrt/mgmt/Makefile | 19 + drivers/fpga/xrt/mgmt/root.c | 420 +++++++++ drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++ drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++ drivers/fpga/xrt/mgmt/xmgmt.h | 33 +
drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++ drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + include/uapi/linux/xrt/xclbin.h | 409 ++++++++ include/uapi/linux/xrt/xmgmt-ioctl.h | 46 + 53 files changed, 9988 insertions(+)create mode 100644
Documentation/fpga/xrt.rst
create mode 100644drivers/fpga/xrt/Kconfig
create mode 100644drivers/fpga/xrt/include/events.hcreate mode 100644drivers/fpga/xrt/include/group.hcreate mode 100644drivers/fpga/xrt/include/metadata.hcreate mode 100644drivers/fpga/xrt/include/subdev_id.hcreate mode 100644drivers/fpga/xrt/include/xclbin-helper.hcreate mode 100644drivers/fpga/xrt/include/xdevice.hcreate mode 100644drivers/fpga/xrt/include/xleaf.hcreate mode 100644drivers/fpga/xrt/include/xleaf/axigate.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clkfreq.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clock.hcreate mode 100644drivers/fpga/xrt/include/xleaf/ddr_calibration.hcreate mode 100644drivers/fpga/xrt/include/xleaf/devctl.hcreate mode 100644drivers/fpga/xrt/include/xleaf/icap.hcreate mode 100644drivers/fpga/xrt/include/xmgmt-main.hcreate mode 100644drivers/fpga/xrt/include/xroot.hcreate mode 100644drivers/fpga/xrt/lib/Kconfig
create mode 100644drivers/fpga/xrt/lib/Makefile
create mode 100644drivers/fpga/xrt/lib/cdev.c
create mode 100644drivers/fpga/xrt/lib/group.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.h
create mode 100644drivers/fpga/xrt/lib/subdev.c
create mode 100644drivers/fpga/xrt/lib/subdev_pool.hcreate mode 100644drivers/fpga/xrt/lib/xclbin.c
create mode 100644drivers/fpga/xrt/lib/xleaf/axigate.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clkfreq.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clock.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ddr_calibration.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/devctl.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/icap.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ucs.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/vsec.ccreate mode 100644drivers/fpga/xrt/lib/xroot.c
create mode 100644drivers/fpga/xrt/metadata/Kconfigcreate mode 100644drivers/fpga/xrt/metadata/Makefilecreate mode 100644drivers/fpga/xrt/metadata/metadata.ccreate mode 100644drivers/fpga/xrt/mgmt/Kconfig
create mode 100644drivers/fpga/xrt/mgmt/Makefile
create mode 100644drivers/fpga/xrt/mgmt/root.c
create mode 100644drivers/fpga/xrt/mgmt/xmgmt-main-region.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt-main.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt.h
create mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.ccreate mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.hcreate mode 100644include/uapi/linux/xrt/xclbin.hcreate mode 100644include/uapi/linux/xrt/xmgmt-ioctl.h
Re: RFC : [PATCH V7 XRT Alveo 00/20] XRT Alveo driver overview
Hi Tom,
Quoted 26 lines · Tom Rix
Quoted 6 lines · Lizhi Hou
Hi Moritz and Tom,
Thanks a lot for reviewing the XRT patches. This v7 patches contains our latest fixes for all review comments. And it seems auto build robot is happy with it as well. Do you have more comment against v7? What will be the next step for XRT patches if it looks ok to you?
Please do not add any features to the patchset.
When you add a feature, that tends to reset the review process.
For little stuff.
I need to look at the documentation again, iirc that was the only issue in v6.
For big stuff.
At the beginning some possible refactor questions were raised, I don't know if they have been resolved.
Quoted 8 lines
ex/
some of the leaf drivers like clock should be moved the clock subsystem
the xrt/ dir vs existing flat, we don't want both.
is your xrt bus consistent with dfl bus, can it support adding devices outside of fpga/xrt
It would be ideal if we make incremental changes to move xrt xleaf drivers to other subsystems. One question comes to mind if xleaf drivers move to different subsystems they would need to become independent ko. That would require load/unload dependency management complicating the design. Also if we go in that direction xdevice.h should move to linux/include?
Quoted 2 lines
how clean are the public headers
Is there anything in the public header we need to change?
Quoted 20 lines
Since flipflopping on refactoring is a painful, let's try to get a consensus before moving forward.
This may mean the patchset is committed by parts as it and the existing code changes.
Lets start with the directory structure.
Since there are a lot of files in xrt, the xrt/ makes sense.
For other fpga's with a lot of files, say > 3, we need to change ex/
dfl-foo.ctodfl/foo.cto be consistent.
Quoted 7 lines
The
Kconfigand Makefiles for xrt/ and dfl/ would only be in that top subdir.Which i think is a change for xrt/
I'll whip up something for dfl/ to move things along.
We will wait for the new structure of dfl/ and make necessary for xrt/ accordingly.
Thanks,
Lizhi
Quoted 329 lines
Tom
Quoted 324 lines
Thanks,
Lizhi
Quoted 316 lines · Lizhi Hou
Hello,
This is V7 of patch series which adds management physical function driver
for Xilinx Alveo PCIe accelerator cards.
https://www.xilinx.com/products/boards-and-kits/alveo.htmlThis driver is part of Xilinx Runtime (XRT) open source stack.
XILINX ALVEO PLATFORM ARCHITECTURE
Alveo PCIe FPGA based platforms have a static *shell* partition and a partial re-configurable *user* partition. The shell partition is automatically loaded from flash when host is booted and PCIe is enumerated
by BIOS. Shell cannot be changed till the next cold reboot. The shell exposes two PCIe physical functions:1. management physical function
2. user physical functionThe patch series includes
Documentation/xrt.rstwhich describes Alveo platform, XRT driver architecture and deployment model in more detail.Users compile their high level design in C/C++/OpenCL or RTL into FPGA image using Vitis tools.
https://www.xilinx.com/products/design-tools/vitis/vitis-platform.htmlThe compiled image is packaged as xclbin which contains partial bitstream
for the user partition and necessary metadata. Users can dynamically swap
the image running on the user partition in order to switch between different workloads by loading different xclbins.XRT DRIVERS FOR XILINX ALVEO
XRT Linux kernel driver *xrt-mgmt* binds to management physical function of
Alveo platform. The modular driver framework is organized into several platform drivers which primarily handle the following functionality:1. Loading firmware container also called xsabin at driver attach time 2. Loading of user compiled xclbin with FPGA Manager integration 3. Clock scaling of image running on user partition 4. In-band sensors: temp, voltage, power, etc. 5. Device reset and rescanThe platform drivers are packaged into *xrt-lib* helper module with well defined interfaces. The module provides a pseudo-bus implementation for the
platform drivers. More details on the driver model can be found inDocumentation/xrt.rst.User physical function driver is not included in this patch series.
LIBFDT REQUIREMENT
XRT driver infrastructure uses Device Tree as a metadata format to discover
HW subsystems in the Alveo PCIe device. The Device Tree schema used by XRT
is documented inDocumentation/xrt.rst.TESTING AND VALIDATION
xrt-mgmt driver can be tested with full XRT open source stack which includes user space libraries, board utilities and (out of tree) first generation user physical function driver xocl. XRT open source runtime stack is available at https://github.com/Xilinx/XRT
Complete documentation for XRT open source stack including sections on Alveo/XRT security and platform architecture can be found here:
https://xilinx.github.io/XRT/master/html/index.html
https://xilinx.github.io/XRT/master/html/security.html
https://xilinx.github.io/XRT/master/html/platforms_partitions.htmlChanges since v6:
- Resolved grammatical errors and cleaned up taxonomy inxrt.rstdocumentation.
- Fixed clang warnings.
- Updated code base to include v6 code review comments.Changes since v5:
- Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
- Updated code base to include v5 code review comments.xrt.rst: address grammar and taxonomysubdev_id.h: definesXRT_SUBDEV_INVALID= 0xclbin.c: change shift operation tobe_to_cpu
- Resolved kernel test robot errors.Changes since v4:
- Addedxrt_bus_typeandxrt_device. All sub devices were changed from platform_bus_type/platform_device to xrt_bus_type/xrt_device.
- Renamed xrt-mgmt driver to xrt-mgnt driver.
- Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file names
- Moved pci function calls from infrastructure to xrt-mgnt driver.
- Renamed files:mgmt/main.c->mgnt/xmgnt-main.cmgmt/main-region.c -> mgnt/xmgnt-main-region.c include/xmgmt-main.h -> include/xmgnt-main.h mgmt/fmgr-drv.c -> mgnt/xrt-mgr.c mgmt/fmgr.h -> mgnt/xrt-mgr.h- Updated code base to include v4 code review comments.
Changes since v3:
- Leaf drivers use regmap-mmio to access hardware registers.
- Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
- Renamed files: calib.[c|h] -> ddr_calibration.[c|h], lib/main.[c|h] -> lib/lib-drv.[c|h],mgmt/main-impl.h- >mgmt/xmgnt.h
- Updated code base to include v3 code review comments.Changes since v2:
- Streamlined the driver framework into *xleaf*, *group* and *xroot*
- Updated documentation to show the driver model with examples
- Addressed kernel test robot errors
- Added a selftest for basic driver framework
- Documented device tree schema
- Removed need to export libfdt symbolsChanges since v1:
- Updated the driver to usefpga_regionandfpga_bridgefor FPGA programming
- Dropped platform drivers not related to PR programming to focus on XRT
core framework
- UpdatedDocumentation/fpga/xrt.rstwith information on XRT core framework
- Addressed checkpatch issues
- Dropped xrt- prefix from some header filesFor reference V6 version of patch series can be found here:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
Lizhi Hou (20):
Documentation: fpga: Add a document describing XRT Alveo drivers
fpga: xrt: driver metadata helper functions
fpga: xrt: xclbin file helper functions
fpga: xrt: xrt-lib driver manager
fpga: xrt: group driver
fpga: xrt: char dev node helper functions
fpga: xrt: root driver infrastructure
fpga: xrt: driver infrastructure
fpga: xrt: management physical function driver (root)
fpga: xrt: main driver for management function device
fpga: xrt: fpga-mgr and region implementation for xclbin download
fpga: xrt: VSEC driver
fpga: xrt: User Clock Subsystem driver
fpga: xrt: ICAP driver
fpga: xrt: devctl xrt driver
fpga: xrt: clock driver
fpga: xrt: clock frequency counter driver
fpga: xrt: DDR calibration driver
fpga: xrt: partition isolation driver
fpga: xrt:KconfigandMakefileupdates for XRT driversDocumentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 870 ++++++++++++++++++ MAINTAINERS | 11 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 2 + drivers/fpga/Makefile | 5 + drivers/fpga/xrt/Kconfig | 8 + drivers/fpga/xrt/include/events.h | 45 + drivers/fpga/xrt/include/group.h | 25 + drivers/fpga/xrt/include/metadata.h | 236 +++++ drivers/fpga/xrt/include/subdev_id.h | 39 + drivers/fpga/xrt/include/xclbin-helper.h | 48 + drivers/fpga/xrt/include/xdevice.h | 131 +++ drivers/fpga/xrt/include/xleaf.h | 205 +++++ drivers/fpga/xrt/include/xleaf/axigate.h | 23 + drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 + drivers/fpga/xrt/include/xleaf/clock.h | 29 + .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 + drivers/fpga/xrt/include/xleaf/devctl.h | 40 + drivers/fpga/xrt/include/xleaf/icap.h | 27 + drivers/fpga/xrt/include/xmgmt-main.h | 34 + drivers/fpga/xrt/include/xroot.h | 117 +++ drivers/fpga/xrt/lib/Kconfig | 17 + drivers/fpga/xrt/lib/Makefile | 30 + drivers/fpga/xrt/lib/cdev.c | 209 +++++ drivers/fpga/xrt/lib/group.c | 278 ++++++ drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++ drivers/fpga/xrt/lib/lib-drv.h | 21 + drivers/fpga/xrt/lib/subdev.c | 859 +++++++++++++++++ drivers/fpga/xrt/lib/subdev_pool.h | 53 ++ drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++ drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++ drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++ drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++ drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++ drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++ drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++ drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++ drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++ drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++ drivers/fpga/xrt/metadata/Kconfig | 12 + drivers/fpga/xrt/metadata/Makefile | 16 + drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++ drivers/fpga/xrt/mgmt/Kconfig | 15 + drivers/fpga/xrt/mgmt/Makefile | 19 + drivers/fpga/xrt/mgmt/root.c | 420 +++++++++ drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++ drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++ drivers/fpga/xrt/mgmt/xmgmt.h | 33 + drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++ drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + include/uapi/linux/xrt/xclbin.h | 409 ++++++++ include/uapi/linux/xrt/xmgmt-ioctl.h | 46 + 53 files changed, 9988 insertions(+)create mode 100644
Documentation/fpga/xrt.rst
create mode 100644drivers/fpga/xrt/Kconfig
create mode 100644drivers/fpga/xrt/include/events.hcreate mode 100644drivers/fpga/xrt/include/group.hcreate mode 100644drivers/fpga/xrt/include/metadata.hcreate mode 100644drivers/fpga/xrt/include/subdev_id.hcreate mode 100644drivers/fpga/xrt/include/xclbin-helper.hcreate mode 100644drivers/fpga/xrt/include/xdevice.hcreate mode 100644drivers/fpga/xrt/include/xleaf.hcreate mode 100644drivers/fpga/xrt/include/xleaf/axigate.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clkfreq.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clock.hcreate mode 100644drivers/fpga/xrt/include/xleaf/ddr_calibration.hcreate mode 100644drivers/fpga/xrt/include/xleaf/devctl.hcreate mode 100644drivers/fpga/xrt/include/xleaf/icap.hcreate mode 100644drivers/fpga/xrt/include/xmgmt-main.hcreate mode 100644drivers/fpga/xrt/include/xroot.hcreate mode 100644drivers/fpga/xrt/lib/Kconfig
create mode 100644drivers/fpga/xrt/lib/Makefile
create mode 100644drivers/fpga/xrt/lib/cdev.c
create mode 100644drivers/fpga/xrt/lib/group.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.h
create mode 100644drivers/fpga/xrt/lib/subdev.c
create mode 100644drivers/fpga/xrt/lib/subdev_pool.hcreate mode 100644drivers/fpga/xrt/lib/xclbin.c
create mode 100644drivers/fpga/xrt/lib/xleaf/axigate.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clkfreq.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clock.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ddr_calibration.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/devctl.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/icap.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ucs.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/vsec.ccreate mode 100644drivers/fpga/xrt/lib/xroot.c
create mode 100644drivers/fpga/xrt/metadata/Kconfigcreate mode 100644drivers/fpga/xrt/metadata/Makefilecreate mode 100644drivers/fpga/xrt/metadata/metadata.ccreate mode 100644drivers/fpga/xrt/mgmt/Kconfig
create mode 100644drivers/fpga/xrt/mgmt/Makefile
create mode 100644drivers/fpga/xrt/mgmt/root.c
create mode 100644drivers/fpga/xrt/mgmt/xmgmt-main-region.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt-main.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt.h
create mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.ccreate mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.hcreate mode 100644include/uapi/linux/xrt/xclbin.hcreate mode 100644include/uapi/linux/xrt/xmgmt-ioctl.h
Tom Rix
reviewerRe: RFC : [PATCH V7 XRT Alveo 00/20] XRT Alveo driver overview
Quoted 32 lines · Lizhi Hou
Hi Tom,
Quoted 28 lines · Tom Rix
Quoted 6 lines · Lizhi Hou
Hi Moritz and Tom,
Thanks a lot for reviewing the XRT patches. This v7 patches contains our latest fixes for all review comments. And it seems auto build robot is happy with it as well. Do you have more comment against v7? What will be the next step for XRT patches if it looks ok to you?
Please do not add any features to the patchset.
When you add a feature, that tends to reset the review process.
For little stuff.
I need to look at the documentation again, iirc that was the only issue in v6.
For big stuff.
At the beginning some possible refactor questions were raised, I don't know if they have been resolved.
ex/
Quoted 7 lines
Quoted 6 lines
some of the leaf drivers like clock should be moved the clock subsystem
the xrt/ dir vs existing flat, we don't want both.
is your xrt bus consistent with dfl bus, can it support adding devices outside of fpga/xrt
It would be ideal if we make incremental changes to move xrt xleaf drivers to other subsystems. One question comes to mind if xleaf drivers move to different subsystems they would need to become independent ko. That would require load/unload dependency management complicating the design. Also if we go in that direction
xdevice.hshould move to linux/include?
At this point this just general advice, when I look into it more I will provide some more concrete suggestions.
Quoted 3 lines
Quoted 2 lines
how clean are the public headers
Is there anything in the public header we need to change?
In the other passes, I looked more for small problems within the file.
Since this the public interface, it needs more attention than an interior h
Quoted 20 lines
Quoted 20 lines
Since flipflopping on refactoring is a painful, let's try to get a consensus before moving forward.
This may mean the patchset is committed by parts as it and the existing code changes.
Lets start with the directory structure.
Since there are a lot of files in xrt, the xrt/ makes sense.
For other fpga's with a lot of files, say > 3, we need to change ex/
dfl-foo.ctodfl/foo.cto be consistent.
Quoted 9 lines
Quoted 7 lines
The
Kconfigand Makefiles for xrt/ and dfl/ would only be in that top subdir.Which i think is a change for xrt/
I'll whip up something for dfl/ to move things along.
We will wait for the new structure of dfl/ and make necessary for xrt/ accordingly.
The new structure is being worked out now.
I'll post v3 shortly.
Please take a look and comment.
Tom
Quoted 333 lines
Thanks,
LizhiQuoted 330 lines
Tom
Quoted 325 lines
Thanks,
Lizhi
Quoted 317 lines · Lizhi Hou
Hello,
This is V7 of patch series which adds management physical function driver
for Xilinx Alveo PCIe accelerator cards.
https://www.xilinx.com/products/boards-and-kits/alveo.htmlThis driver is part of Xilinx Runtime (XRT) open source stack.
XILINX ALVEO PLATFORM ARCHITECTURE
Alveo PCIe FPGA based platforms have a static *shell* partition and a partial re-configurable *user* partition. The shell partition is automatically loaded from flash when host is booted and PCIe is enumerated
by BIOS. Shell cannot be changed till the next cold reboot. The shell exposes two PCIe physical functions:1. management physical function
2. user physical functionThe patch series includes
Documentation/xrt.rstwhich describes Alveo platform, XRT driver architecture and deployment model in more detail.Users compile their high level design in C/C++/OpenCL or RTL into FPGA image using Vitis tools.
https://www.xilinx.com/products/design-tools/vitis/vitis-platform.htmlThe compiled image is packaged as xclbin which contains partial bitstream
for the user partition and necessary metadata. Users can dynamically swap
the image running on the user partition in order to switch between different workloads by loading different xclbins.XRT DRIVERS FOR XILINX ALVEO
XRT Linux kernel driver *xrt-mgmt* binds to management physical function of
Alveo platform. The modular driver framework is organized into several platform drivers which primarily handle the following functionality:1. Loading firmware container also called xsabin at driver attach time 2. Loading of user compiled xclbin with FPGA Manager integration 3. Clock scaling of image running on user partition
4. In-band sensors: temp, voltage, power, etc.
5. Device reset and rescanThe platform drivers are packaged into *xrt-lib* helper module with well defined interfaces. The module provides a pseudo-bus implementation for the
platform drivers. More details on the driver model can be found inDocumentation/xrt.rst.User physical function driver is not included in this patch series.
LIBFDT REQUIREMENT
XRT driver infrastructure uses Device Tree as a metadata format to discover
HW subsystems in the Alveo PCIe device. The Device Tree schema used by XRT
is documented inDocumentation/xrt.rst.TESTING AND VALIDATION
xrt-mgmt driver can be tested with full XRT open source stack which includes user space libraries, board utilities and (out of tree) first generation user physical function driver xocl. XRT open source runtime stack is available at https://github.com/Xilinx/XRT
Complete documentation for XRT open source stack including sections on Alveo/XRT security and platform architecture can be found here:
https://xilinx.github.io/XRT/master/html/index.html
https://xilinx.github.io/XRT/master/html/security.html
https://xilinx.github.io/XRT/master/html/platforms_partitions.htmlChanges since v6:
- Resolved grammatical errors and cleaned up taxonomy inxrt.rstdocumentation.
- Fixed clang warnings.
- Updated code base to include v6 code review comments.Changes since v5:
- Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
- Updated code base to include v5 code review comments.xrt.rst: address grammar and taxonomysubdev_id.h: definesXRT_SUBDEV_INVALID= 0xclbin.c: change shift operation tobe_to_cpu
- Resolved kernel test robot errors.Changes since v4:
- Addedxrt_bus_typeandxrt_device. All sub devices were changed from platform_bus_type/platform_device to xrt_bus_type/xrt_device.
- Renamed xrt-mgmt driver to xrt-mgnt driver.
- Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file names
- Moved pci function calls from infrastructure to xrt-mgnt driver.
- Renamed files:mgmt/main.c->mgnt/xmgnt-main.cmgmt/main-region.c->mgnt/xmgnt-main-region.cinclude/xmgmt-main.h->include/xmgnt-main.hmgmt/fmgr-drv.c->mgnt/xrt-mgr.cmgmt/fmgr.h->mgnt/xrt-mgr.h
- Updated code base to include v4 code review comments.Changes since v3:
- Leaf drivers use regmap-mmio to access hardware registers.
- Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
- Renamed files: calib.[c|h] -> ddr_calibration.[c|h], lib/main.[c|h] -> lib/lib-drv.[c|h],mgmt/main-impl.h- >mgmt/xmgnt.h
- Updated code base to include v3 code review comments.Changes since v2:
- Streamlined the driver framework into *xleaf*, *group* and *xroot*
- Updated documentation to show the driver model with examples
- Addressed kernel test robot errors
- Added a selftest for basic driver framework
- Documented device tree schema
- Removed need to export libfdt symbolsChanges since v1:
- Updated the driver to usefpga_regionandfpga_bridgefor FPGA programming
- Dropped platform drivers not related to PR programming to focus on XRT
core framework
- UpdatedDocumentation/fpga/xrt.rstwith information on XRT core framework
- Addressed checkpatch issues
- Dropped xrt- prefix from some header filesFor reference V6 version of patch series can be found here:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
Lizhi Hou (20):
Documentation: fpga: Add a document describing XRT Alveo drivers
fpga: xrt: driver metadata helper functions
fpga: xrt: xclbin file helper functions
fpga: xrt: xrt-lib driver manager
fpga: xrt: group driver
fpga: xrt: char dev node helper functions
fpga: xrt: root driver infrastructure
fpga: xrt: driver infrastructure
fpga: xrt: management physical function driver (root)
fpga: xrt: main driver for management function device
fpga: xrt: fpga-mgr and region implementation for xclbin download
fpga: xrt: VSEC driver
fpga: xrt: User Clock Subsystem driver
fpga: xrt: ICAP driver
fpga: xrt: devctl xrt driver
fpga: xrt: clock driver
fpga: xrt: clock frequency counter driver
fpga: xrt: DDR calibration driver
fpga: xrt: partition isolation driver
fpga: xrt:KconfigandMakefileupdates for XRT driversDocumentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 870
++++++++++++++++++
MAINTAINERS | 11 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 2 + drivers/fpga/Makefile | 5 + drivers/fpga/xrt/Kconfig | 8 + drivers/fpga/xrt/include/events.h | 45 + drivers/fpga/xrt/include/group.h | 25 + drivers/fpga/xrt/include/metadata.h | 236 +++++ drivers/fpga/xrt/include/subdev_id.h | 39 + drivers/fpga/xrt/include/xclbin-helper.h | 48 + drivers/fpga/xrt/include/xdevice.h | 131 +++ drivers/fpga/xrt/include/xleaf.h | 205 +++++ drivers/fpga/xrt/include/xleaf/axigate.h | 23 + drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 + drivers/fpga/xrt/include/xleaf/clock.h | 29 + .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 + drivers/fpga/xrt/include/xleaf/devctl.h | 40 + drivers/fpga/xrt/include/xleaf/icap.h | 27 + drivers/fpga/xrt/include/xmgmt-main.h | 34 + drivers/fpga/xrt/include/xroot.h | 117 +++ drivers/fpga/xrt/lib/Kconfig | 17 + drivers/fpga/xrt/lib/Makefile | 30 + drivers/fpga/xrt/lib/cdev.c | 209 +++++ drivers/fpga/xrt/lib/group.c | 278 ++++++ drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++ drivers/fpga/xrt/lib/lib-drv.h | 21 + drivers/fpga/xrt/lib/subdev.c | 859
+++++++++++++++++
drivers/fpga/xrt/lib/subdev_pool.h | 53 ++ drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++ drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++ drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++ drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++ drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++ drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++ drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++ drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++ drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++ drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++ drivers/fpga/xrt/metadata/Kconfig | 12 + drivers/fpga/xrt/metadata/Makefile | 16 + drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++ drivers/fpga/xrt/mgmt/Kconfig | 15 + drivers/fpga/xrt/mgmt/Makefile | 19 + drivers/fpga/xrt/mgmt/root.c | 420 +++++++++ drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++ drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++ drivers/fpga/xrt/mgmt/xmgmt.h | 33 +drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++ drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + include/uapi/linux/xrt/xclbin.h | 409 ++++++++ include/uapi/linux/xrt/xmgmt-ioctl.h | 46 + 53 files changed, 9988 insertions(+)create mode 100644
Documentation/fpga/xrt.rst
create mode 100644drivers/fpga/xrt/Kconfig
create mode 100644drivers/fpga/xrt/include/events.hcreate mode 100644drivers/fpga/xrt/include/group.hcreate mode 100644drivers/fpga/xrt/include/metadata.hcreate mode 100644drivers/fpga/xrt/include/subdev_id.hcreate mode 100644drivers/fpga/xrt/include/xclbin-helper.hcreate mode 100644drivers/fpga/xrt/include/xdevice.hcreate mode 100644drivers/fpga/xrt/include/xleaf.hcreate mode 100644drivers/fpga/xrt/include/xleaf/axigate.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clkfreq.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clock.hcreate mode 100644drivers/fpga/xrt/include/xleaf/ddr_calibration.hcreate mode 100644drivers/fpga/xrt/include/xleaf/devctl.hcreate mode 100644drivers/fpga/xrt/include/xleaf/icap.hcreate mode 100644drivers/fpga/xrt/include/xmgmt-main.hcreate mode 100644drivers/fpga/xrt/include/xroot.hcreate mode 100644drivers/fpga/xrt/lib/Kconfig
create mode 100644drivers/fpga/xrt/lib/Makefile
create mode 100644drivers/fpga/xrt/lib/cdev.c
create mode 100644drivers/fpga/xrt/lib/group.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.h
create mode 100644drivers/fpga/xrt/lib/subdev.c
create mode 100644drivers/fpga/xrt/lib/subdev_pool.hcreate mode 100644drivers/fpga/xrt/lib/xclbin.c
create mode 100644drivers/fpga/xrt/lib/xleaf/axigate.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clkfreq.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clock.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ddr_calibration.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/devctl.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/icap.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ucs.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/vsec.ccreate mode 100644drivers/fpga/xrt/lib/xroot.c
create mode 100644drivers/fpga/xrt/metadata/Kconfigcreate mode 100644drivers/fpga/xrt/metadata/Makefilecreate mode 100644drivers/fpga/xrt/metadata/metadata.ccreate mode 100644drivers/fpga/xrt/mgmt/Kconfig
create mode 100644drivers/fpga/xrt/mgmt/Makefile
create mode 100644drivers/fpga/xrt/mgmt/root.c
create mode 100644drivers/fpga/xrt/mgmt/xmgmt-main-region.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt-main.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt.h
create mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.ccreate mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.hcreate mode 100644include/uapi/linux/xrt/xclbin.hcreate mode 100644include/uapi/linux/xrt/xmgmt-ioctl.h
Tom Rix
reviewerLizhi,
Sorry for the delay in reviewing v7.
Is it too early to blame it on the July 4 holiday here ?!? :)
All the small stuff looks fine to me. In this pass I looked at issues that would need a refactoring. Since it would be a lot of work and I am not the final word on this, it would be good if some others to chime in. Also a couple of new spelling fixes at the end.
Tom
Having xrt/ dir
ok with it or it will follow the subdir reorg of fpga/, afaik not a blocker
Location of xrt_bus_type
ok, similar to dfl_bus_type
Non fpga subdevices should go to other subsystems. looking in drivers/fpga/xrt/lib/xleaf
clock clkfrq ucs these are clocks
should move to drivers/clk/xilinx/
axigate, for fpga partitioning
ok to stay
ddr_calibaration, a memory status checker
should move drivers/memory dfl-emif is similar
devctl, a general purpose misc driver
should move to drivers/mfd
icap, for fpga bitstream writing
ok to stay
vsec, misc small drivers discovered via pci config vsec should move to drivers/mfd
For include/uapi/linux
collapse include/uapi/linux/xrt/*.h into include/uapi/linux/fpga-xrt.h There are only 2 files, one really small. fpga-xrt.h follows fpga-dfl.h The comments are pretty messy, user should be able to scan them. Try cleaning them up.
Spelling mistakes
Documentation/fpga/xrt.rst +0 -0
@@ -275,7 +275,7 @@ fpga_bridge and fpga_region for the next region in the chain.
fpga_bridge
-----------
-Like the fpga_region, a fpga_bridge is created by walking the device tree +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.
@@ -416,7 +416,7 @@ xclbin is compiled by end user using
Vitis <https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html>_
tool set from Xilinx. The xclbin contains sections describing user compiled acceleration engines/kernels, memory subsystems, clocking information etc. It also -contains a FPGA bitstream for the user partition, UUIDs, platform name, etc. +contains an FPGA bitstream for the user partition, UUIDs, platform name, etc.
.. _xsabin_xclbin_container_format:
drivers/fpga/xrt/include/metadata.h +0 -0
@@ -194,7 +194,7 @@ int xrt_md_get_interface_uuids(struct device *dev, const char *blob,
/*
* The firmware provides a 128 bit hash string as a unique id to the
* partition/interface.
- * Existing hw does not yet use the cononical form, so it is necessary to
+ * Existing hw does not yet use the canonical form, so it is necessary to
* use a translation function.
*/
static inline void xrt_md_trans_uuid2str(const uuid_t *uuid, char *uuidstr)
drivers/fpga/xrt/lib/xroot.c +0 -0
@@ -427,7 +427,7 @@ static void xroot_bringup_group_work(struct work_struct *work)
r = xleaf_call(xdev, XRT_GROUP_INIT_CHILDREN, NULL); xroot_put_group(xr, xdev);
if (r == -EEXIST)
- continue; /* Already brough up, nothing to do. */ + continue; /* Already brought up, nothing to do. */ if (r) atomic_inc(&xr->groups.bringup_failed_cnt);
drivers/fpga/xrt/mgmt/xmgmt-main.c +0 -0
@@ -142,7 +142,7 @@ static ssize_t VBNV_show(struct device *dev, struct device_attribute *da, char *
}
static DEVICE_ATTR_RO(VBNV);
-/* logic uuid is the uuid uniquely identfy the partition */
+/* logic uuid is the uuid uniquely identify the partition */
static ssize_t logic_uuids_show(struct device *dev, struct device_attribute *da, char *buf) {
struct xrt_device *xdev = to_xrt_dev(dev);
drivers/fpga/xrt/mgmt/xrt-mgr.c +0 -0
@@ -115,7 +115,7 @@ static int xmgmt_pr_write_init(struct fpga_manager *mgr,
}
/*
- * The implementation requries full xclbin image before we can start
+ * The implementation requires full xclbin image before we can start
* programming the hardware via ICAP subsystem. The full image is required
* for checking the validity of xclbin and walking the sections to
* discover the bitstream.
Quoted 271 lines · Lizhi Hou
Hello,
This is V7 of patch series which adds management physical function driver for Xilinx Alveo PCIe accelerator cards.
https://www.xilinx.com/products/boards-and-kits/alveo.htmlThis driver is part of Xilinx Runtime (XRT) open source stack.
XILINX ALVEO PLATFORM ARCHITECTURE
Alveo PCIe FPGA based platforms have a static *shell* partition and a partial re-configurable *user* partition. The shell partition is automatically loaded from flash when host is booted and PCIe is enumerated by BIOS. Shell cannot be changed till the next cold reboot. The shell exposes two PCIe physical functions:
1. management physical function
2. user physical functionThe patch series includes
Documentation/xrt.rstwhich describes Alveo platform, XRT driver architecture and deployment model in more detail.Users compile their high level design in C/C++/OpenCL or RTL into FPGA image using Vitis tools.
https://www.xilinx.com/products/design-tools/vitis/vitis-platform.htmlThe compiled image is packaged as xclbin which contains partial bitstream for the user partition and necessary metadata. Users can dynamically swap the image running on the user partition in order to switch between different workloads by loading different xclbins.
XRT DRIVERS FOR XILINX ALVEO
XRT Linux kernel driver *xrt-mgmt* binds to management physical function of Alveo platform. The modular driver framework is organized into several platform drivers which primarily handle the following functionality:
1. Loading firmware container also called xsabin at driver attach time 2. Loading of user compiled xclbin with FPGA Manager integration 3. Clock scaling of image running on user partition 4. In-band sensors: temp, voltage, power, etc. 5. Device reset and rescanThe platform drivers are packaged into *xrt-lib* helper module with well defined interfaces. The module provides a pseudo-bus implementation for the platform drivers. More details on the driver model can be found in
Documentation/xrt.rst.User physical function driver is not included in this patch series.
LIBFDT REQUIREMENT
XRT driver infrastructure uses Device Tree as a metadata format to discover HW subsystems in the Alveo PCIe device. The Device Tree schema used by XRT is documented in
Documentation/xrt.rst.TESTING AND VALIDATION
xrt-mgmt driver can be tested with full XRT open source stack which includes user space libraries, board utilities and (out of tree) first generation user physical function driver xocl. XRT open source runtime stack is available at https://github.com/Xilinx/XRT
Complete documentation for XRT open source stack including sections on Alveo/XRT security and platform architecture can be found here:
https://xilinx.github.io/XRT/master/html/index.html
https://xilinx.github.io/XRT/master/html/security.html
https://xilinx.github.io/XRT/master/html/platforms_partitions.htmlChanges since v6:
- Resolved grammatical errors and cleaned up taxonomy inxrt.rstdocumentation.
- Fixed clang warnings.
- Updated code base to include v6 code review comments.Changes since v5:
- Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
- Updated code base to include v5 code review comments.xrt.rst: address grammar and taxonomysubdev_id.h: definesXRT_SUBDEV_INVALID= 0xclbin.c: change shift operation tobe_to_cpu
- Resolved kernel test robot errors.Changes since v4:
- Addedxrt_bus_typeandxrt_device. All sub devices were changed from platform_bus_type/platform_device to xrt_bus_type/xrt_device.
- Renamed xrt-mgmt driver to xrt-mgnt driver.
- Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file names
- Moved pci function calls from infrastructure to xrt-mgnt driver.
- Renamed files:mgmt/main.c->mgnt/xmgnt-main.cmgmt/main-region.c -> mgnt/xmgnt-main-region.c include/xmgmt-main.h -> include/xmgnt-main.h mgmt/fmgr-drv.c -> mgnt/xrt-mgr.c mgmt/fmgr.h -> mgnt/xrt-mgr.h- Updated code base to include v4 code review comments.
Changes since v3:
- Leaf drivers use regmap-mmio to access hardware registers.
- Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
- Renamed files: calib.[c|h] -> ddr_calibration.[c|h], lib/main.[c|h] -> lib/lib-drv.[c|h],mgmt/main-impl.h- >mgmt/xmgnt.h
- Updated code base to include v3 code review comments.Changes since v2:
- Streamlined the driver framework into *xleaf*, *group* and *xroot*
- Updated documentation to show the driver model with examples
- Addressed kernel test robot errors
- Added a selftest for basic driver framework
- Documented device tree schema
- Removed need to export libfdt symbolsChanges since v1:
- Updated the driver to usefpga_regionandfpga_bridgefor FPGA programming
- Dropped platform drivers not related to PR programming to focus on XRT core framework
- UpdatedDocumentation/fpga/xrt.rstwith information on XRT core framework
- Addressed checkpatch issues
- Dropped xrt- prefix from some header filesFor reference V6 version of patch series can be found here:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/Lizhi Hou (20):
Documentation: fpga: Add a document describing XRT Alveo drivers
fpga: xrt: driver metadata helper functions
fpga: xrt: xclbin file helper functions
fpga: xrt: xrt-lib driver manager
fpga: xrt: group driver
fpga: xrt: char dev node helper functions
fpga: xrt: root driver infrastructure
fpga: xrt: driver infrastructure
fpga: xrt: management physical function driver (root)
fpga: xrt: main driver for management function device
fpga: xrt: fpga-mgr and region implementation for xclbin download
fpga: xrt: VSEC driver
fpga: xrt: User Clock Subsystem driver
fpga: xrt: ICAP driver
fpga: xrt: devctl xrt driver
fpga: xrt: clock driver
fpga: xrt: clock frequency counter driver
fpga: xrt: DDR calibration driver
fpga: xrt: partition isolation driver
fpga: xrt:KconfigandMakefileupdates for XRT driversDocumentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 870 ++++++++++++++++++ MAINTAINERS | 11 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 2 + drivers/fpga/Makefile | 5 + drivers/fpga/xrt/Kconfig | 8 + drivers/fpga/xrt/include/events.h | 45 + drivers/fpga/xrt/include/group.h | 25 + drivers/fpga/xrt/include/metadata.h | 236 +++++ drivers/fpga/xrt/include/subdev_id.h | 39 + drivers/fpga/xrt/include/xclbin-helper.h | 48 + drivers/fpga/xrt/include/xdevice.h | 131 +++ drivers/fpga/xrt/include/xleaf.h | 205 +++++ drivers/fpga/xrt/include/xleaf/axigate.h | 23 + drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 + drivers/fpga/xrt/include/xleaf/clock.h | 29 + .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 + drivers/fpga/xrt/include/xleaf/devctl.h | 40 + drivers/fpga/xrt/include/xleaf/icap.h | 27 + drivers/fpga/xrt/include/xmgmt-main.h | 34 + drivers/fpga/xrt/include/xroot.h | 117 +++ drivers/fpga/xrt/lib/Kconfig | 17 + drivers/fpga/xrt/lib/Makefile | 30 + drivers/fpga/xrt/lib/cdev.c | 209 +++++ drivers/fpga/xrt/lib/group.c | 278 ++++++ drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++ drivers/fpga/xrt/lib/lib-drv.h | 21 + drivers/fpga/xrt/lib/subdev.c | 859 +++++++++++++++++ drivers/fpga/xrt/lib/subdev_pool.h | 53 ++ drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++ drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++ drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++ drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++ drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++ drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++ drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++ drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++ drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++ drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++ drivers/fpga/xrt/metadata/Kconfig | 12 + drivers/fpga/xrt/metadata/Makefile | 16 + drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++ drivers/fpga/xrt/mgmt/Kconfig | 15 + drivers/fpga/xrt/mgmt/Makefile | 19 + drivers/fpga/xrt/mgmt/root.c | 420 +++++++++ drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++ drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++ drivers/fpga/xrt/mgmt/xmgmt.h | 33 + drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++ drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + include/uapi/linux/xrt/xclbin.h | 409 ++++++++ include/uapi/linux/xrt/xmgmt-ioctl.h | 46 + 53 files changed, 9988 insertions(+)create mode 100644
Documentation/fpga/xrt.rst
create mode 100644drivers/fpga/xrt/Kconfig
create mode 100644drivers/fpga/xrt/include/events.hcreate mode 100644drivers/fpga/xrt/include/group.hcreate mode 100644drivers/fpga/xrt/include/metadata.hcreate mode 100644drivers/fpga/xrt/include/subdev_id.hcreate mode 100644drivers/fpga/xrt/include/xclbin-helper.hcreate mode 100644drivers/fpga/xrt/include/xdevice.hcreate mode 100644drivers/fpga/xrt/include/xleaf.hcreate mode 100644drivers/fpga/xrt/include/xleaf/axigate.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clkfreq.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clock.hcreate mode 100644drivers/fpga/xrt/include/xleaf/ddr_calibration.hcreate mode 100644drivers/fpga/xrt/include/xleaf/devctl.hcreate mode 100644drivers/fpga/xrt/include/xleaf/icap.hcreate mode 100644drivers/fpga/xrt/include/xmgmt-main.hcreate mode 100644drivers/fpga/xrt/include/xroot.hcreate mode 100644drivers/fpga/xrt/lib/Kconfig
create mode 100644drivers/fpga/xrt/lib/Makefile
create mode 100644drivers/fpga/xrt/lib/cdev.c
create mode 100644drivers/fpga/xrt/lib/group.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.h
create mode 100644drivers/fpga/xrt/lib/subdev.c
create mode 100644drivers/fpga/xrt/lib/subdev_pool.hcreate mode 100644drivers/fpga/xrt/lib/xclbin.c
create mode 100644drivers/fpga/xrt/lib/xleaf/axigate.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clkfreq.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clock.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ddr_calibration.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/devctl.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/icap.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ucs.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/vsec.ccreate mode 100644drivers/fpga/xrt/lib/xroot.c
create mode 100644drivers/fpga/xrt/metadata/Kconfigcreate mode 100644drivers/fpga/xrt/metadata/Makefilecreate mode 100644drivers/fpga/xrt/metadata/metadata.ccreate mode 100644drivers/fpga/xrt/mgmt/Kconfig
create mode 100644drivers/fpga/xrt/mgmt/Makefile
create mode 100644drivers/fpga/xrt/mgmt/root.c
create mode 100644drivers/fpga/xrt/mgmt/xmgmt-main-region.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt-main.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt.h
create mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.ccreate mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.hcreate mode 100644include/uapi/linux/xrt/xclbin.hcreate mode 100644include/uapi/linux/xrt/xmgmt-ioctl.h
Tom Rix
reviewerQuoted 8 lines · Tom Rix
Lizhi,
Sorry for the delay in reviewing v7.
Is it too early to blame it on the July 4 holiday here ?!? :)
All the small stuff looks fine to me. In this pass I looked at issues that would need a refactoring. Since it would be a lot of work and I am not the final word on this, it would be good if some others to chime in. Also a couple of new spelling fixes at the end.
Lizhi
This pathset has stalled.
The spelling changes should be fixed.
Some of xleafs may need to be moved and reworked.
The addition of building outside of fpga/xrt is a new feature, and I think is best considered when the first foundational change (this patchset) is in tree.
Could the xleafs' below be dropped from this set ?
Tom
Quoted 412 lines
Tom
Having xrt/ dir
ok with it or it will follow the subdir reorg of fpga/, afaik not a blockerLocation of
xrt_bus_type
ok, similar todfl_bus_typeNon fpga subdevices should go to other subsystems. looking in
drivers/fpga/xrt/lib/xleafclock clkfrq ucs these are clocks
should move todrivers/clk/xilinx/axigate, for fpga partitioning
ok to stay
ddr_calibaration, a memory status checker
should movedrivers/memorydfl-emif is similardevctl, a general purpose misc driver
should move todrivers/mfdicap, for fpga bitstream writing
ok to stayvsec, misc small drivers discovered via pci config vsec should move to
drivers/mfdFor
include/uapi/linux
collapseinclude/uapi/linux/xrt/*.hintoinclude/uapi/linux/fpga-xrt.hThere are only 2 files, one really small.fpga-xrt.hfollowsfpga-dfl.hThe comments are pretty messy, user should be able to scan them. Try cleaning them up.Spelling mistakes
Documentation/fpga/xrt.rst +0
-0@@ -275,7 +275,7 @@ fpga_bridge and fpga_region for the next region inthe chain.
fpga_bridge
------------Like the
fpga_region, afpga_bridgeis created by walking the device tree
+Like thefpga_region, anfpga_bridgeis created by walking the device tree
of the parent group. The bridge is used for isolation between a parent and its child.Documentation/fpga/xrt.rst +0
-0@@ -416,7 +416,7 @@ xclbin is compiled by end user using
Vitis <https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html>_
tool set from Xilinx. The xclbin contains sections describing user compiled acceleration engines/kernels, memory subsystems, clocking information etc. It also -contains a FPGA bitstream for the user partition, UUIDs, platform name, etc.
+contains an FPGA bitstream for the user partition, UUIDs, platform name, etc...
_xsabin_xclbin_container_format:drivers/fpga/xrt/include/metadata.h +0
-1@@ -194,7 +194,7 @@ int xrt_md_get_interface_uuids(struct device *dev, const char *blob, /** The firmware provides a 128 bit hash string as a unique id to the * partition/interface. -* Existing hw does not yet use the cononical form, so it is necessary to
+ * Existing hw does not yet use the canonical form, so it is necessary to
* use a translation function.
*/
static inline voidxrt_md_trans_uuid2str(const uuid_t *uuid, char *uuidstr)drivers/fpga/xrt/lib/xroot.c +1
-1@@ -427,7 +427,7 @@ static void xroot_bringup_group_work(struct work_struct *work) r = xleaf_call(xdev, XRT_GROUP_INIT_CHILDREN, NULL); xroot_put_group(xr, xdev); if (r == -EEXIST) - continue; /* Already brough up, nothing to do. */ + continue; /* Already brought up, nothing todo. */
if (r)atomic_inc(&xr->groups.bringup_failed_cnt);drivers/fpga/xrt/mgmt/xmgmt-main.c +0
-0@@ -142,7 +142,7 @@ static ssize_t VBNV_show(struct device *dev,struct
device_attribute*da, char *
}
staticDEVICE_ATTR_RO(VBNV);drivers/fpga/xrt/mgmt/xmgmt-main.c +1
-1-/* logic uuid is the uuid uniquely identfy the partition */ +/* logic uuid is the uuid uniquely identify the partition */ static
ssize_tlogic_uuids_show(struct device *dev, struct device_attribute *da, char *buf){
structxrt_device*xdev =to_xrt_dev(dev);drivers/fpga/xrt/mgmt/xrt-mgr.c +1
-1@@ -115,7 +115,7 @@ static int xmgmt_pr_write_init(struct fpga_manager *mgr, } /* -* The implementation requries full xclbin image before we can start +* The implementation requires full xclbin image before we can start * programming the hardware via ICAP subsystem. The full image is required * for checking the validity of xclbin and walking the sections to * discover the bitstream.
Quoted 285 lines · Lizhi Hou
Hello,
This is V7 of patch series which adds management physical function driver for Xilinx Alveo PCIe accelerator cards.
https://www.xilinx.com/products/boards-and-kits/alveo.htmlThis driver is part of Xilinx Runtime (XRT) open source stack.
XILINX ALVEO PLATFORM ARCHITECTURE
Alveo PCIe FPGA based platforms have a static *shell* partition and a partial re-configurable *user* partition. The shell partition is automatically loaded from flash when host is booted and PCIe is enumerated by BIOS. Shell cannot be changed till the next cold reboot. The shell exposes two PCIe physical functions:
1. management physical function
2. user physical functionThe patch series includes
Documentation/xrt.rstwhich describes Alveo platform, XRT driver architecture and deployment model in more detail.Users compile their high level design in C/C++/OpenCL or RTL into FPGA image using Vitis tools.
https://www.xilinx.com/products/design-tools/vitis/vitis-platform.htmlThe compiled image is packaged as xclbin which contains partial bitstream for the user partition and necessary metadata. Users can dynamically swap the image running on the user partition in order to switch between different workloads by loading different xclbins.
XRT DRIVERS FOR XILINX ALVEO
XRT Linux kernel driver *xrt-mgmt* binds to management physical function of Alveo platform. The modular driver framework is organized into several platform drivers which primarily handle the following functionality:
1. Loading firmware container also called xsabin at driver attach time 2. Loading of user compiled xclbin with FPGA Manager integration 3. Clock scaling of image running on user partition
4. In-band sensors: temp, voltage, power, etc.
5. Device reset and rescanThe platform drivers are packaged into *xrt-lib* helper module with well defined interfaces. The module provides a pseudo-bus implementation for the platform drivers. More details on the driver model can be found in
Documentation/xrt.rst.User physical function driver is not included in this patch series.
LIBFDT REQUIREMENT
XRT driver infrastructure uses Device Tree as a metadata format to discover HW subsystems in the Alveo PCIe device. The Device Tree schema used by XRT is documented in
Documentation/xrt.rst.TESTING AND VALIDATION
xrt-mgmt driver can be tested with full XRT open source stack which includes user space libraries, board utilities and (out of tree) first generation user physical function driver xocl. XRT open source runtime stack is available at https://github.com/Xilinx/XRT
Complete documentation for XRT open source stack including sections on Alveo/XRT security and platform architecture can be found here:
https://xilinx.github.io/XRT/master/html/index.html
https://xilinx.github.io/XRT/master/html/security.html
https://xilinx.github.io/XRT/master/html/platforms_partitions.htmlChanges since v6:
- Resolved grammatical errors and cleaned up taxonomy inxrt.rstdocumentation.
- Fixed clang warnings.
- Updated code base to include v6 code review comments.Changes since v5:
- Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
- Updated code base to include v5 code review comments.xrt.rst: address grammar and taxonomysubdev_id.h: definesXRT_SUBDEV_INVALID= 0xclbin.c: change shift operation tobe_to_cpu
- Resolved kernel test robot errors.Changes since v4:
- Addedxrt_bus_typeandxrt_device. All sub devices were changed from platform_bus_type/platform_device to xrt_bus_type/xrt_device.
- Renamed xrt-mgmt driver to xrt-mgnt driver.
- Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file names
- Moved pci function calls from infrastructure to xrt-mgnt driver.
- Renamed files:mgmt/main.c->mgnt/xmgnt-main.cmgmt/main-region.c->mgnt/xmgnt-main-region.cinclude/xmgmt-main.h->include/xmgnt-main.hmgmt/fmgr-drv.c->mgnt/xrt-mgr.cmgmt/fmgr.h->mgnt/xrt-mgr.h
- Updated code base to include v4 code review comments.Changes since v3:
- Leaf drivers use regmap-mmio to access hardware registers.
- Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
- Renamed files: calib.[c|h] -> ddr_calibration.[c|h], lib/main.[c|h] -> lib/lib-drv.[c|h],mgmt/main-impl.h- >mgmt/xmgnt.h
- Updated code base to include v3 code review comments.Changes since v2:
- Streamlined the driver framework into *xleaf*, *group* and *xroot*
- Updated documentation to show the driver model with examples
- Addressed kernel test robot errors
- Added a selftest for basic driver framework
- Documented device tree schema
- Removed need to export libfdt symbolsChanges since v1:
- Updated the driver to usefpga_regionandfpga_bridgefor FPGA programming
- Dropped platform drivers not related to PR programming to focus on XRT core framework
- UpdatedDocumentation/fpga/xrt.rstwith information on XRT core framework
- Addressed checkpatch issues
- Dropped xrt- prefix from some header filesFor reference V6 version of patch series can be found here:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
Lizhi Hou (20):
Documentation: fpga: Add a document describing XRT Alveo drivers
fpga: xrt: driver metadata helper functions
fpga: xrt: xclbin file helper functions
fpga: xrt: xrt-lib driver manager
fpga: xrt: group driver
fpga: xrt: char dev node helper functions
fpga: xrt: root driver infrastructure
fpga: xrt: driver infrastructure
fpga: xrt: management physical function driver (root)
fpga: xrt: main driver for management function device
fpga: xrt: fpga-mgr and region implementation for xclbin download
fpga: xrt: VSEC driver
fpga: xrt: User Clock Subsystem driver
fpga: xrt: ICAP driver
fpga: xrt: devctl xrt driver
fpga: xrt: clock driver
fpga: xrt: clock frequency counter driver
fpga: xrt: DDR calibration driver
fpga: xrt: partition isolation driver
fpga: xrt:KconfigandMakefileupdates for XRT driversDocumentation/fpga/index.rst | 1 + Documentation/fpga/xrt.rst | 870 ++++++++++++++++++ MAINTAINERS | 11 + drivers/Makefile | 1 + drivers/fpga/Kconfig | 2 + drivers/fpga/Makefile | 5 + drivers/fpga/xrt/Kconfig | 8 + drivers/fpga/xrt/include/events.h | 45 + drivers/fpga/xrt/include/group.h | 25 + drivers/fpga/xrt/include/metadata.h | 236 +++++ drivers/fpga/xrt/include/subdev_id.h | 39 + drivers/fpga/xrt/include/xclbin-helper.h | 48 + drivers/fpga/xrt/include/xdevice.h | 131 +++ drivers/fpga/xrt/include/xleaf.h | 205 +++++ drivers/fpga/xrt/include/xleaf/axigate.h | 23 + drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 + drivers/fpga/xrt/include/xleaf/clock.h | 29 + .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 + drivers/fpga/xrt/include/xleaf/devctl.h | 40 + drivers/fpga/xrt/include/xleaf/icap.h | 27 + drivers/fpga/xrt/include/xmgmt-main.h | 34 + drivers/fpga/xrt/include/xroot.h | 117 +++ drivers/fpga/xrt/lib/Kconfig | 17 + drivers/fpga/xrt/lib/Makefile | 30 + drivers/fpga/xrt/lib/cdev.c | 209 +++++ drivers/fpga/xrt/lib/group.c | 278 ++++++ drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++ drivers/fpga/xrt/lib/lib-drv.h | 21 + drivers/fpga/xrt/lib/subdev.c | 859 +++++++++++++++++ drivers/fpga/xrt/lib/subdev_pool.h | 53 ++ drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++ drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++ drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++ drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++ drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++ drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++ drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++ drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++ drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++ drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++ drivers/fpga/xrt/metadata/Kconfig | 12 + drivers/fpga/xrt/metadata/Makefile | 16 + drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++ drivers/fpga/xrt/mgmt/Kconfig | 15 + drivers/fpga/xrt/mgmt/Makefile | 19 + drivers/fpga/xrt/mgmt/root.c | 420 +++++++++ drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++ drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++ drivers/fpga/xrt/mgmt/xmgmt.h | 33 +
drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++ drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + include/uapi/linux/xrt/xclbin.h | 409 ++++++++ include/uapi/linux/xrt/xmgmt-ioctl.h | 46 + 53 files changed, 9988 insertions(+)create mode 100644
Documentation/fpga/xrt.rst
create mode 100644drivers/fpga/xrt/Kconfig
create mode 100644drivers/fpga/xrt/include/events.hcreate mode 100644drivers/fpga/xrt/include/group.hcreate mode 100644drivers/fpga/xrt/include/metadata.hcreate mode 100644drivers/fpga/xrt/include/subdev_id.hcreate mode 100644drivers/fpga/xrt/include/xclbin-helper.hcreate mode 100644drivers/fpga/xrt/include/xdevice.hcreate mode 100644drivers/fpga/xrt/include/xleaf.hcreate mode 100644drivers/fpga/xrt/include/xleaf/axigate.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clkfreq.hcreate mode 100644drivers/fpga/xrt/include/xleaf/clock.hcreate mode 100644drivers/fpga/xrt/include/xleaf/ddr_calibration.hcreate mode 100644drivers/fpga/xrt/include/xleaf/devctl.hcreate mode 100644drivers/fpga/xrt/include/xleaf/icap.hcreate mode 100644drivers/fpga/xrt/include/xmgmt-main.hcreate mode 100644drivers/fpga/xrt/include/xroot.hcreate mode 100644drivers/fpga/xrt/lib/Kconfig
create mode 100644drivers/fpga/xrt/lib/Makefile
create mode 100644drivers/fpga/xrt/lib/cdev.c
create mode 100644drivers/fpga/xrt/lib/group.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.c
create mode 100644drivers/fpga/xrt/lib/lib-drv.h
create mode 100644drivers/fpga/xrt/lib/subdev.c
create mode 100644drivers/fpga/xrt/lib/subdev_pool.hcreate mode 100644drivers/fpga/xrt/lib/xclbin.c
create mode 100644drivers/fpga/xrt/lib/xleaf/axigate.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clkfreq.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/clock.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ddr_calibration.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/devctl.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/icap.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/ucs.ccreate mode 100644drivers/fpga/xrt/lib/xleaf/vsec.ccreate mode 100644drivers/fpga/xrt/lib/xroot.c
create mode 100644drivers/fpga/xrt/metadata/Kconfigcreate mode 100644drivers/fpga/xrt/metadata/Makefilecreate mode 100644drivers/fpga/xrt/metadata/metadata.ccreate mode 100644drivers/fpga/xrt/mgmt/Kconfig
create mode 100644drivers/fpga/xrt/mgmt/Makefile
create mode 100644drivers/fpga/xrt/mgmt/root.c
create mode 100644drivers/fpga/xrt/mgmt/xmgmt-main-region.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt-main.ccreate mode 100644drivers/fpga/xrt/mgmt/xmgmt.h
create mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.ccreate mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.hcreate mode 100644include/uapi/linux/xrt/xclbin.hcreate mode 100644include/uapi/linux/xrt/xmgmt-ioctl.h
Hi Tom,
I am working on v8 patchset which I followed your guidance to move the listed xleaf to suggested subsystems. And the spelling error fixes, and fpga-xrt.h cleanup are all included. Does that make senses to you? If yes, I may send the V8 patchset early next week for you to review.
Thanks,
Lizhi
On 7/16/21, 11:27 AM, "Tom Rix" <[email protected]> wrote:
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
On 7/1/21 1:32 PM, Tom Rix wrote:
> Lizhi,
>
> Sorry for the delay in reviewing v7.
>
> Is it too early to blame it on the July 4 holiday here ?!? :) >
>
> All the small stuff looks fine to me. In this pass I looked at issues > that would need a refactoring. Since it would be a lot of work and I > am not the final word on this, it would be good if some others to > chime in. Also a couple of new spelling fixes at the end.
Lizhi
This pathset has stalled.
The spelling changes should be fixed.
Some of xleafs may need to be moved and reworked.
The addition of building outside of fpga/xrt is a new feature, and I think is best considered when the first foundational change (this patchset) is in tree.
Could the xleafs' below be dropped from this set ?
Tom
>
> Tom
>
>
> Having xrt/ dir
> ok with it or it will follow the subdir reorg of fpga/, afaik not a > blocker
>
> Location of xrt_bus_type
> ok, similar to dfl_bus_type
>
> Non fpga subdevices should go to other subsystems.
> looking in drivers/fpga/xrt/lib/xleaf
>
> clock clkfrq ucs these are clocks
> should move to drivers/clk/xilinx/
>
> axigate, for fpga partitioning
> ok to stay
>
> ddr_calibaration, a memory status checker
> should move drivers/memory dfl-emif is similar
>
> devctl, a general purpose misc driver
> should move to drivers/mfd
>
> icap, for fpga bitstream writing
> ok to stay
>
> vsec, misc small drivers discovered via pci config vsec
> should move to drivers/mfd
>
> For include/uapi/linux
> collapse include/uapi/linux/xrt/*.h into include/uapi/linux/fpga-xrt.h > There are only 2 files, one really small. fpga-xrt.h follows fpga-dfl.h > The comments are pretty messy, user should be able to scan them. > Try cleaning them up.
>
> Spelling mistakes
>
> diff --git a/Documentation/fpga/xrt.rst b/Documentation/fpga/xrt.rst > index 5a5b4d5a3bc6..84eb41be9ac1 100644
> --- a/Documentation/fpga/xrt.rst
> +++ b/Documentation/fpga/xrt.rst
> @@ -275,7 +275,7 @@ fpga_bridge and fpga_region for the next region in > the chain.
> fpga_bridge
> -----------
>
> -Like the fpga_region, a fpga_bridge is created by walking the device > tree
> +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.
>
> @@ -416,7 +416,7 @@ xclbin is compiled by end user using
> `Vitis
> <https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html>`_
> tool set from Xilinx. The xclbin contains sections describing user > compiled
> acceleration engines/kernels, memory subsystems, clocking information > etc. It also
> -contains a FPGA bitstream for the user partition, UUIDs, platform > name, etc.
> +contains an FPGA bitstream for the user partition, UUIDs, platform > name, etc.
>
>
> .. _xsabin_xclbin_container_format:
> diff --git a/drivers/fpga/xrt/include/metadata.h
> b/drivers/fpga/xrt/include/metadata.h
> index c4df88262f8a..f48d6d42f5ef 100644
> --- a/drivers/fpga/xrt/include/metadata.h
> +++ b/drivers/fpga/xrt/include/metadata.h
> @@ -194,7 +194,7 @@ int xrt_md_get_interface_uuids(struct device *dev, > const char *blob,
> /*
> * The firmware provides a 128 bit hash string as a unique id to the
> * partition/interface.
> - * Existing hw does not yet use the cononical form, so it is > necessary to
> + * Existing hw does not yet use the canonical form, so it is > necessary to
> * use a translation function.
> */
> static inline void xrt_md_trans_uuid2str(const uuid_t *uuid, char > *uuidstr)
> diff --git a/drivers/fpga/xrt/lib/xroot.c b/drivers/fpga/xrt/lib/xroot.c > index 7b3e540dd6c0..f324a25e1d4d 100644
> --- a/drivers/fpga/xrt/lib/xroot.c
> +++ b/drivers/fpga/xrt/lib/xroot.c
> @@ -427,7 +427,7 @@ static void xroot_bringup_group_work(struct > work_struct *work)
> r = xleaf_call(xdev, XRT_GROUP_INIT_CHILDREN, NULL);
> xroot_put_group(xr, xdev);
> if (r == -EEXIST)
> - continue; /* Already brough up, nothing to do. */
> + continue; /* Already brought up, nothing to
> do. */
> if (r)
> atomic_inc(&xr->groups.bringup_failed_cnt);
>
> diff --git a/drivers/fpga/xrt/mgmt/xmgmt-main.c
> b/drivers/fpga/xrt/mgmt/xmgmt-main.c
> index 820c888e7918..9077254e0f8a 100644
> --- a/drivers/fpga/xrt/mgmt/xmgmt-main.c
> +++ b/drivers/fpga/xrt/mgmt/xmgmt-main.c
> @@ -142,7 +142,7 @@ static ssize_t VBNV_show(struct device *dev, > struct device_attribute *da, char *
> }
> static DEVICE_ATTR_RO(VBNV);
>
> -/* logic uuid is the uuid uniquely identfy the partition */ > +/* logic uuid is the uuid uniquely identify the partition */ > static ssize_t logic_uuids_show(struct device *dev, struct
> device_attribute *da, char *buf)
> {
> struct xrt_device *xdev = to_xrt_dev(dev);
> diff --git a/drivers/fpga/xrt/mgmt/xrt-mgr.c
> b/drivers/fpga/xrt/mgmt/xrt-mgr.c
> index 41263a033d9d..ab253b516e8d 100644
> --- a/drivers/fpga/xrt/mgmt/xrt-mgr.c
> +++ b/drivers/fpga/xrt/mgmt/xrt-mgr.c
> @@ -115,7 +115,7 @@ static int xmgmt_pr_write_init(struct fpga_manager > *mgr,
> }
>
> /*
> - * The implementation requries full xclbin image before we can start > + * The implementation requires full xclbin image before we can start
> * programming the hardware via ICAP subsystem. The full image is
> required
> * for checking the validity of xclbin and walking the sections to
> * discover the bitstream.
>
> On 5/27/21 5:49 PM, Lizhi Hou wrote:
>> Hello,
>>
>> This is V7 of patch series which adds management physical function >> driver
>> for Xilinx Alveo PCIe accelerator cards.
>> https://www.xilinx.com/products/boards-and-kits/alveo.html
>>
>> This driver is part of Xilinx Runtime (XRT) open source stack. >>
>> XILINX ALVEO PLATFORM ARCHITECTURE
>>
>> Alveo PCIe FPGA based platforms have a static *shell* partition and a >> partial re-configurable *user* partition. The shell partition is >> automatically loaded from flash when host is booted and PCIe is >> enumerated
>> by BIOS. Shell cannot be changed till the next cold reboot. The shell >> exposes two PCIe physical functions:
>>
>> 1. management physical function
>> 2. user physical function
>>
>> The patch series includes Documentation/xrt.rst which describes Alveo >> platform, XRT driver architecture and deployment model in more detail. >>
>> Users compile their high level design in C/C++/OpenCL or RTL into FPGA >> image using Vitis tools.
>> https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html
>>
>> The compiled image is packaged as xclbin which contains partial >> bitstream
>> for the user partition and necessary metadata. Users can dynamically >> swap
>> the image running on the user partition in order to switch between >> different workloads by loading different xclbins.
>>
>> XRT DRIVERS FOR XILINX ALVEO
>>
>> XRT Linux kernel driver *xrt-mgmt* binds to management physical >> function of
>> Alveo platform. The modular driver framework is organized into several >> platform drivers which primarily handle the following functionality:
>>
>> 1. Loading firmware container also called xsabin at driver attach time >> 2. Loading of user compiled xclbin with FPGA Manager integration >> 3. Clock scaling of image running on user partition
>> 4. In-band sensors: temp, voltage, power, etc.
>> 5. Device reset and rescan
>>
>> The platform drivers are packaged into *xrt-lib* helper module with well >> defined interfaces. The module provides a pseudo-bus implementation >> for the
>> platform drivers. More details on the driver model can be found in >> Documentation/xrt.rst.
>>
>> User physical function driver is not included in this patch series. >>
>> LIBFDT REQUIREMENT
>>
>> XRT driver infrastructure uses Device Tree as a metadata format to >> discover
>> HW subsystems in the Alveo PCIe device. The Device Tree schema used >> by XRT
>> is documented in Documentation/xrt.rst.
>>
>> TESTING AND VALIDATION
>>
>> xrt-mgmt driver can be tested with full XRT open source stack which >> includes user space libraries, board utilities and (out of tree) first >> generation user physical function driver xocl. XRT open source runtime >> stack is available at https://github.com/Xilinx/XRT
>>
>> Complete documentation for XRT open source stack including sections on >> Alveo/XRT security and platform architecture can be found here:
>>
>> https://xilinx.github.io/XRT/master/html/index.html
>> https://xilinx.github.io/XRT/master/html/security.html
>> https://xilinx.github.io/XRT/master/html/platforms_partitions.html
>>
>> Changes since v6:
>> - Resolved grammatical errors and cleaned up taxonomy in xrt.rst
>> documentation.
>> - Fixed clang warnings.
>> - Updated code base to include v6 code review comments.
>>
>> Changes since v5:
>> - Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
>> - Updated code base to include v5 code review comments.
>> xrt.rst: address grammar and taxonomy
>> subdev_id.h: defines XRT_SUBDEV_INVALID = 0
>> xclbin.c: change shift operation to be_to_cpu
>> - Resolved kernel test robot errors.
>>
>> Changes since v4:
>> - Added xrt_bus_type and xrt_device. All sub devices were changed from
>> platform_bus_type/platform_device to xrt_bus_type/xrt_device.
>> - Renamed xrt-mgmt driver to xrt-mgnt driver.
>> - Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file >> names
>> - Moved pci function calls from infrastructure to xrt-mgnt driver. >> - Renamed files: mgmt/main.c -> mgnt/xmgnt-main.c
>> mgmt/main-region.c -> mgnt/xmgnt-main-region.c
>> include/xmgmt-main.h -> include/xmgnt-main.h
>> mgmt/fmgr-drv.c -> mgnt/xrt-mgr.c
>> mgmt/fmgr.h -> mgnt/xrt-mgr.h
>> - Updated code base to include v4 code review comments.
>>
>> Changes since v3:
>> - Leaf drivers use regmap-mmio to access hardware registers. >> - Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
>> - Renamed files: calib.[c|h] -> ddr_calibration.[c|h],
>> lib/main.[c|h] -> lib/lib-drv.[c|h],
>> mgmt/main-impl.h - > mgmt/xmgnt.h
>> - Updated code base to include v3 code review comments.
>>
>> Changes since v2:
>> - Streamlined the driver framework into *xleaf*, *group* and *xroot* >> - Updated documentation to show the driver model with examples >> - Addressed kernel test robot errors
>> - Added a selftest for basic driver framework
>> - Documented device tree schema
>> - Removed need to export libfdt symbols
>>
>> Changes since v1:
>> - Updated the driver to use fpga_region and fpga_bridge for FPGA
>> programming
>> - Dropped platform drivers not related to PR programming to focus on XRT
>> core framework
>> - Updated Documentation/fpga/xrt.rst with information on XRT core >> framework
>> - Addressed checkpatch issues
>> - Dropped xrt- prefix from some header files
>>
>> For reference V6 version of patch series can be found here:
>>
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>>
>> Lizhi Hou (20):
>> Documentation: fpga: Add a document describing XRT Alveo drivers
>> fpga: xrt: driver metadata helper functions
>> fpga: xrt: xclbin file helper functions
>> fpga: xrt: xrt-lib driver manager
>> fpga: xrt: group driver
>> fpga: xrt: char dev node helper functions
>> fpga: xrt: root driver infrastructure
>> fpga: xrt: driver infrastructure
>> fpga: xrt: management physical function driver (root)
>> fpga: xrt: main driver for management function device
>> fpga: xrt: fpga-mgr and region implementation for xclbin download
>> fpga: xrt: VSEC driver
>> fpga: xrt: User Clock Subsystem driver
>> fpga: xrt: ICAP driver
>> fpga: xrt: devctl xrt driver
>> fpga: xrt: clock driver
>> fpga: xrt: clock frequency counter driver
>> fpga: xrt: DDR calibration driver
>> fpga: xrt: partition isolation driver
>> fpga: xrt: Kconfig and Makefile updates for XRT drivers
>>
>> Documentation/fpga/index.rst | 1 +
>> Documentation/fpga/xrt.rst | 870 ++++++++++++++++++
>> MAINTAINERS | 11 +
>> drivers/Makefile | 1 +
>> drivers/fpga/Kconfig | 2 +
>> drivers/fpga/Makefile | 5 +
>> drivers/fpga/xrt/Kconfig | 8 +
>> drivers/fpga/xrt/include/events.h | 45 +
>> drivers/fpga/xrt/include/group.h | 25 +
>> drivers/fpga/xrt/include/metadata.h | 236 +++++
>> drivers/fpga/xrt/include/subdev_id.h | 39 +
>> drivers/fpga/xrt/include/xclbin-helper.h | 48 +
>> drivers/fpga/xrt/include/xdevice.h | 131 +++
>> drivers/fpga/xrt/include/xleaf.h | 205 +++++
>> drivers/fpga/xrt/include/xleaf/axigate.h | 23 +
>> drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 +
>> drivers/fpga/xrt/include/xleaf/clock.h | 29 +
>> .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 +
>> drivers/fpga/xrt/include/xleaf/devctl.h | 40 +
>> drivers/fpga/xrt/include/xleaf/icap.h | 27 +
>> drivers/fpga/xrt/include/xmgmt-main.h | 34 +
>> drivers/fpga/xrt/include/xroot.h | 117 +++
>> drivers/fpga/xrt/lib/Kconfig | 17 +
>> drivers/fpga/xrt/lib/Makefile | 30 +
>> drivers/fpga/xrt/lib/cdev.c | 209 +++++
>> drivers/fpga/xrt/lib/group.c | 278 ++++++
>> drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++
>> drivers/fpga/xrt/lib/lib-drv.h | 21 +
>> drivers/fpga/xrt/lib/subdev.c | 859 +++++++++++++++++
>> drivers/fpga/xrt/lib/subdev_pool.h | 53 ++
>> drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++
>> drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++
>> drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++
>> drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++
>> drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++
>> drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++
>> drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++
>> drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++
>> drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++
>> drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++
>> drivers/fpga/xrt/metadata/Kconfig | 12 +
>> drivers/fpga/xrt/metadata/Makefile | 16 +
>> drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++
>> drivers/fpga/xrt/mgmt/Kconfig | 15 +
>> drivers/fpga/xrt/mgmt/Makefile | 19 +
>> drivers/fpga/xrt/mgmt/root.c | 420 +++++++++
>> drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++
>> drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++
>> drivers/fpga/xrt/mgmt/xmgmt.h | 33 +
>> drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++
>> drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 +
>> include/uapi/linux/xrt/xclbin.h | 409 ++++++++
>> include/uapi/linux/xrt/xmgmt-ioctl.h | 46 +
>> 53 files changed, 9988 insertions(+)
>> create mode 100644 Documentation/fpga/xrt.rst
>> create mode 100644 drivers/fpga/xrt/Kconfig
>> create mode 100644 drivers/fpga/xrt/include/events.h
>> create mode 100644 drivers/fpga/xrt/include/group.h
>> create mode 100644 drivers/fpga/xrt/include/metadata.h
>> create mode 100644 drivers/fpga/xrt/include/subdev_id.h
>> create mode 100644 drivers/fpga/xrt/include/xclbin-helper.h
>> create mode 100644 drivers/fpga/xrt/include/xdevice.h
>> create mode 100644 drivers/fpga/xrt/include/xleaf.h
>> create mode 100644 drivers/fpga/xrt/include/xleaf/axigate.h
>> create mode 100644 drivers/fpga/xrt/include/xleaf/clkfreq.h
>> create mode 100644 drivers/fpga/xrt/include/xleaf/clock.h
>> create mode 100644 drivers/fpga/xrt/include/xleaf/ddr_calibration.h
>> create mode 100644 drivers/fpga/xrt/include/xleaf/devctl.h
>> create mode 100644 drivers/fpga/xrt/include/xleaf/icap.h
>> create mode 100644 drivers/fpga/xrt/include/xmgmt-main.h
>> create mode 100644 drivers/fpga/xrt/include/xroot.h
>> create mode 100644 drivers/fpga/xrt/lib/Kconfig
>> create mode 100644 drivers/fpga/xrt/lib/Makefile
>> create mode 100644 drivers/fpga/xrt/lib/cdev.c
>> create mode 100644 drivers/fpga/xrt/lib/group.c
>> 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/subdev.c
>> create mode 100644 drivers/fpga/xrt/lib/subdev_pool.h
>> create mode 100644 drivers/fpga/xrt/lib/xclbin.c
>> create mode 100644 drivers/fpga/xrt/lib/xleaf/axigate.c
>> create mode 100644 drivers/fpga/xrt/lib/xleaf/clkfreq.c
>> create mode 100644 drivers/fpga/xrt/lib/xleaf/clock.c
>> create mode 100644 drivers/fpga/xrt/lib/xleaf/ddr_calibration.c
>> create mode 100644 drivers/fpga/xrt/lib/xleaf/devctl.c
>> create mode 100644 drivers/fpga/xrt/lib/xleaf/icap.c
>> create mode 100644 drivers/fpga/xrt/lib/xleaf/ucs.c
>> create mode 100644 drivers/fpga/xrt/lib/xleaf/vsec.c
>> create mode 100644 drivers/fpga/xrt/lib/xroot.c
>> create mode 100644 drivers/fpga/xrt/metadata/Kconfig
>> create mode 100644 drivers/fpga/xrt/metadata/Makefile
>> create mode 100644 drivers/fpga/xrt/metadata/metadata.c
>> create mode 100644 drivers/fpga/xrt/mgmt/Kconfig
>> create mode 100644 drivers/fpga/xrt/mgmt/Makefile
>> create mode 100644 drivers/fpga/xrt/mgmt/root.c
>> create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-main-region.c
>> create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-main.c
>> create mode 100644 drivers/fpga/xrt/mgmt/xmgmt.h
>> create mode 100644 drivers/fpga/xrt/mgmt/xrt-mgr.c
>> create mode 100644 drivers/fpga/xrt/mgmt/xrt-mgr.h
>> create mode 100644 include/uapi/linux/xrt/xclbin.h
>> create mode 100644 include/uapi/linux/xrt/xmgmt-ioctl.h
>>
Tom Rix
reviewerQuoted 4 lines · Lizhi Hou
Hi Tom,
I am working on v8 patchset which I followed your guidance to move the listed xleaf to suggested subsystems. And the spelling error fixes, and
fpga-xrt.hcleanup are all included. Does that make senses to you? If yes, I may send the V8 patchset early next week for you to review.
Can handling the move be done in a followup ?
AFAIK, there are no other problems with v7 and I would rather see a smaller subset of v7 make it intree sooner.
This would mean dropping the (maybe) contentious xleafs from v8 just doing the cleanups.
Tom
Quoted 471 lines
Thanks,
LizhiOn 7/16/21, 11:27 AM, "Tom Rix" <[email protected]> wrote:
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
On 7/1/21 1:32 PM, Tom Rix wrote:
> Lizhi,
>
> Sorry for the delay in reviewing v7.
>
> Is it too early to blame it on the July 4 holiday here ?!? :) >
>
> All the small stuff looks fine to me. In this pass I looked at issues > that would need a refactoring. Since it would be a lot of work and I > am not the final word on this, it would be good if some others to > chime in. Also a couple of new spelling fixes at the end.Lizhi
This pathset has stalled.
The spelling changes should be fixed.
Some of xleafs may need to be moved and reworked.
The addition of building outside of fpga/xrt is a new feature, and I think is best considered when the first foundational change (this patchset) is in tree.
Could the xleafs' below be dropped from this set ?
Tom
>
> Tom
>
>
> Having xrt/ dir
> ok with it or it will follow the subdir reorg of fpga/, afaik not a > blocker
>
> Location ofxrt_bus_type
> ok, similar todfl_bus_type
>
> Non fpga subdevices should go to other subsystems.
> looking indrivers/fpga/xrt/lib/xleaf
>
> clock clkfrq ucs these are clocks
> should move todrivers/clk/xilinx/
>
> axigate, for fpga partitioning
> ok to stay
>
>ddr_calibaration, a memory status checker
> should movedrivers/memorydfl-emif is similar
>
> devctl, a general purpose misc driver
> should move todrivers/mfd
>
> icap, for fpga bitstream writing
> ok to stay
>
> vsec, misc small drivers discovered via pci config vsec
> should move todrivers/mfd
>
> Forinclude/uapi/linux
> collapseinclude/uapi/linux/xrt/*.hintoinclude/uapi/linux/fpga-xrt.h> There are only 2 files, one really small.fpga-xrt.hfollowsfpga-dfl.h> The comments are pretty messy, user should be able to scan them. > Try cleaning them up.
>
> Spelling mistakes
>
> diff --gita/Documentation/fpga/xrt.rstb/Documentation/fpga/xrt.rst> index5a5b4d5a3bc6..84eb41be9ac1100644
> ---a/Documentation/fpga/xrt.rst
> +++b/Documentation/fpga/xrt.rst
> @@ -275,7 +275,7 @@fpga_bridgeandfpga_regionfor the next region in > the chain.
>fpga_bridge
> -----------
>
> -Like thefpga_region, afpga_bridgeis created by walking the device > tree
> +Like thefpga_region, anfpga_bridgeis created by walking the device > tree
> of the parent group. The bridge is used for isolation between a > parent and
> its child.
>
> @@ -416,7 +416,7 @@ xclbin is compiled by end user using
> `Vitis
> <https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html>`_
> tool set from Xilinx. The xclbin contains sections describing user > compiled
> acceleration engines/kernels, memory subsystems, clocking information > etc. It also
> -contains a FPGA bitstream for the user partition, UUIDs, platform > name, etc.
> +contains an FPGA bitstream for the user partition, UUIDs, platform > name, etc.
>
>
> .._xsabin_xclbin_container_format:
> diff --gita/drivers/fpga/xrt/include/metadata.h
>b/drivers/fpga/xrt/include/metadata.h
> indexc4df88262f8a..f48d6d42f5ef100644
> ---a/drivers/fpga/xrt/include/metadata.h
> +++b/drivers/fpga/xrt/include/metadata.h
> @@ -194,7 +194,7 @@ int xrt_md_get_interface_uuids(struct device *dev, > const char *blob,
> /*
> * The firmware provides a 128 bit hash string as a unique id to the
> * partition/interface.
> - * Existing hw does not yet use the cononical form, so it is > necessary to
> + * Existing hw does not yet use the canonical form, so it is > necessary to
> * use a translation function.
> */
> static inline voidxrt_md_trans_uuid2str(const uuid_t *uuid, char > *uuidstr)
> diff --gita/drivers/fpga/xrt/lib/xroot.cb/drivers/fpga/xrt/lib/xroot.c> index7b3e540dd6c0..f324a25e1d4d100644
> ---a/drivers/fpga/xrt/lib/xroot.c
> +++b/drivers/fpga/xrt/lib/xroot.c
> @@ -427,7 +427,7 @@ static voidxroot_bringup_group_work(struct > work_struct *work)
> r =xleaf_call(xdev, XRT_GROUP_INIT_CHILDREN, NULL);
>xroot_put_group(xr, xdev);
> if (r ==-EEXIST)
> - continue; /* Already brough up, nothing to do. */
> + continue; /* Already brought up, nothing to
> do. */
> if (r)
>atomic_inc(&xr->groups.bringup_failed_cnt);
>
> diff --gita/drivers/fpga/xrt/mgmt/xmgmt-main.c
>b/drivers/fpga/xrt/mgmt/xmgmt-main.c
> index820c888e7918..9077254e0f8a100644
> ---a/drivers/fpga/xrt/mgmt/xmgmt-main.c
> +++b/drivers/fpga/xrt/mgmt/xmgmt-main.c
> @@ -142,7 +142,7 @@ staticssize_tVBNV_show(struct device *dev, > structdevice_attribute*da, char *
> }
> staticDEVICE_ATTR_RO(VBNV);
>
> -/* logic uuid is the uuid uniquely identfy the partition */ > +/* logic uuid is the uuid uniquely identify the partition */ > staticssize_tlogic_uuids_show(struct device *dev, struct
>device_attribute*da, char *buf)
> {
> structxrt_device*xdev =to_xrt_dev(dev);
> diff --gita/drivers/fpga/xrt/mgmt/xrt-mgr.c
>b/drivers/fpga/xrt/mgmt/xrt-mgr.c
> index41263a033d9d..ab253b516e8d100644
> ---a/drivers/fpga/xrt/mgmt/xrt-mgr.c
> +++b/drivers/fpga/xrt/mgmt/xrt-mgr.c
> @@ -115,7 +115,7 @@ static int xmgmt_pr_write_init(structfpga_manager> *mgr,
> }
>
> /*
> - * The implementation requries full xclbin image before we can start > + * The implementation requires full xclbin image before we can start
> * programming the hardware via ICAP subsystem. The full image is
> required
> * for checking the validity of xclbin and walking the sections to
> * discover the bitstream.
>
> On 5/27/21 5:49 PM, Lizhi Hou wrote:
>> Hello,
>>
>> This is V7 of patch series which adds management physical function >> driver
>> for Xilinx Alveo PCIe accelerator cards.
>> https://www.xilinx.com/products/boards-and-kits/alveo.html
>>
>> This driver is part of Xilinx Runtime (XRT) open source stack. >>
>> XILINX ALVEO PLATFORM ARCHITECTURE
>>
>> Alveo PCIe FPGA based platforms have a static *shell* partition and a >> partial re-configurable *user* partition. The shell partition is >> automatically loaded from flash when host is booted and PCIe is >> enumerated
>> by BIOS. Shell cannot be changed till the next cold reboot. The shell >> exposes two PCIe physical functions:
>>
>> 1. management physical function
>> 2. user physical function
>>
>> The patch series includesDocumentation/xrt.rstwhich describes Alveo >> platform, XRT driver architecture and deployment model in more detail. >>
>> Users compile their high level design in C/C++/OpenCL or RTL into FPGA >> image using Vitis tools.
>> https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html
>>
>> The compiled image is packaged as xclbin which contains partial >> bitstream
>> for the user partition and necessary metadata. Users can dynamically >> swap
>> the image running on the user partition in order to switch between >> different workloads by loading different xclbins.
>>
>> XRT DRIVERS FOR XILINX ALVEO
>>
>> XRT Linux kernel driver *xrt-mgmt* binds to management physical >> function of
>> Alveo platform. The modular driver framework is organized into several >> platform drivers which primarily handle the following functionality:
>>
>> 1. Loading firmware container also called xsabin at driver attach time >> 2. Loading of user compiled xclbin with FPGA Manager integration >> 3. Clock scaling of image running on user partition
>> 4. In-band sensors: temp, voltage, power, etc.
>> 5. Device reset and rescan
>>
>> The platform drivers are packaged into *xrt-lib* helper module with well >> defined interfaces. The module provides a pseudo-bus implementation >> for the
>> platform drivers. More details on the driver model can be found in >>Documentation/xrt.rst.
>>
>> User physical function driver is not included in this patch series. >>
>> LIBFDT REQUIREMENT
>>
>> XRT driver infrastructure uses Device Tree as a metadata format to >> discover
>> HW subsystems in the Alveo PCIe device. The Device Tree schema used >> by XRT
>> is documented inDocumentation/xrt.rst.
>>
>> TESTING AND VALIDATION
>>
>> xrt-mgmt driver can be tested with full XRT open source stack which >> includes user space libraries, board utilities and (out of tree) first >> generation user physical function driver xocl. XRT open source runtime >> stack is available at https://github.com/Xilinx/XRT
>>
>> Complete documentation for XRT open source stack including sections on >> Alveo/XRT security and platform architecture can be found here:
>>
>> https://xilinx.github.io/XRT/master/html/index.html
>> https://xilinx.github.io/XRT/master/html/security.html
>> https://xilinx.github.io/XRT/master/html/platforms_partitions.html
>>
>> Changes since v6:
>> - Resolved grammatical errors and cleaned up taxonomy inxrt.rst
>> documentation.
>> - Fixed clang warnings.
>> - Updated code base to include v6 code review comments.
>>
>> Changes since v5:
>> - Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT'
>> - Updated code base to include v5 code review comments.
>>xrt.rst: address grammar and taxonomy
>>subdev_id.h: definesXRT_SUBDEV_INVALID= 0
>>xclbin.c: change shift operation tobe_to_cpu
>> - Resolved kernel test robot errors.
>>
>> Changes since v4:
>> - Addedxrt_bus_typeandxrt_device. All sub devices were changed from
>> platform_bus_type/platform_device to xrt_bus_type/xrt_device.
>> - Renamed xrt-mgmt driver to xrt-mgnt driver.
>> - Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code and file >> names
>> - Moved pci function calls from infrastructure to xrt-mgnt driver. >> - Renamed files:mgmt/main.c->mgnt/xmgnt-main.c
>>mgmt/main-region.c->mgnt/xmgnt-main-region.c
>>include/xmgmt-main.h->include/xmgnt-main.h
>>mgmt/fmgr-drv.c->mgnt/xrt-mgr.c
>>mgmt/fmgr.h->mgnt/xrt-mgr.h
>> - Updated code base to include v4 code review comments.
>>
>> Changes since v3:
>> - Leaf drivers use regmap-mmio to access hardware registers. >> - Renamed driver module: xmgmt.ko -> xrt-mgmt.ko
>> - Renamed files: calib.[c|h] -> ddr_calibration.[c|h],
>> lib/main.[c|h] -> lib/lib-drv.[c|h],
>>mgmt/main-impl.h- >mgmt/xmgnt.h
>> - Updated code base to include v3 code review comments.
>>
>> Changes since v2:
>> - Streamlined the driver framework into *xleaf*, *group* and *xroot* >> - Updated documentation to show the driver model with examples >> - Addressed kernel test robot errors
>> - Added a selftest for basic driver framework
>> - Documented device tree schema
>> - Removed need to export libfdt symbols
>>
>> Changes since v1:
>> - Updated the driver to usefpga_regionandfpga_bridgefor FPGA
>> programming
>> - Dropped platform drivers not related to PR programming to focus on XRT
>> core framework
>> - UpdatedDocumentation/fpga/xrt.rstwith information on XRT core >> framework
>> - Addressed checkpatch issues
>> - Dropped xrt- prefix from some header files
>>
>> For reference V6 version of patch series can be found here:
>>
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>> https://lore.kernel.org/lkml/[email protected]/
>>
>>
>> Lizhi Hou (20):
>> Documentation: fpga: Add a document describing XRT Alveo drivers
>> fpga: xrt: driver metadata helper functions
>> fpga: xrt: xclbin file helper functions
>> fpga: xrt: xrt-lib driver manager
>> fpga: xrt: group driver
>> fpga: xrt: char dev node helper functions
>> fpga: xrt: root driver infrastructure
>> fpga: xrt: driver infrastructure
>> fpga: xrt: management physical function driver (root)
>> fpga: xrt: main driver for management function device
>> fpga: xrt: fpga-mgr and region implementation for xclbin download
>> fpga: xrt: VSEC driver
>> fpga: xrt: User Clock Subsystem driver
>> fpga: xrt: ICAP driver
>> fpga: xrt: devctl xrt driver
>> fpga: xrt: clock driver
>> fpga: xrt: clock frequency counter driver
>> fpga: xrt: DDR calibration driver
>> fpga: xrt: partition isolation driver
>> fpga: xrt:KconfigandMakefileupdates for XRT drivers
>>
>>Documentation/fpga/index.rst| 1 +
>>Documentation/fpga/xrt.rst| 870 ++++++++++++++++++
>>MAINTAINERS| 11 +
>>drivers/Makefile| 1 +
>>drivers/fpga/Kconfig| 2 +
>>drivers/fpga/Makefile| 5 +
>>drivers/fpga/xrt/Kconfig| 8 +
>>drivers/fpga/xrt/include/events.h| 45 +
>>drivers/fpga/xrt/include/group.h| 25 +
>>drivers/fpga/xrt/include/metadata.h| 236 +++++
>>drivers/fpga/xrt/include/subdev_id.h| 39 +
>>drivers/fpga/xrt/include/xclbin-helper.h| 48 +
>>drivers/fpga/xrt/include/xdevice.h| 131 +++
>>drivers/fpga/xrt/include/xleaf.h| 205 +++++
>>drivers/fpga/xrt/include/xleaf/axigate.h| 23 +
>>drivers/fpga/xrt/include/xleaf/clkfreq.h| 21 +
>>drivers/fpga/xrt/include/xleaf/clock.h| 29 +
>>.../fpga/xrt/include/xleaf/ddr_calibration.h| 28 +
>>drivers/fpga/xrt/include/xleaf/devctl.h| 40 +
>>drivers/fpga/xrt/include/xleaf/icap.h| 27 +
>>drivers/fpga/xrt/include/xmgmt-main.h| 34 +
>>drivers/fpga/xrt/include/xroot.h| 117 +++
>>drivers/fpga/xrt/lib/Kconfig| 17 +
>>drivers/fpga/xrt/lib/Makefile| 30 +
>>drivers/fpga/xrt/lib/cdev.c| 209 +++++
>>drivers/fpga/xrt/lib/group.c| 278 ++++++
>>drivers/fpga/xrt/lib/lib-drv.c| 328 +++++++
>>drivers/fpga/xrt/lib/lib-drv.h| 21 +
>>drivers/fpga/xrt/lib/subdev.c| 859 +++++++++++++++++
>>drivers/fpga/xrt/lib/subdev_pool.h| 53 ++
>>drivers/fpga/xrt/lib/xclbin.c| 381 ++++++++
>>drivers/fpga/xrt/lib/xleaf/axigate.c| 325 +++++++
>>drivers/fpga/xrt/lib/xleaf/clkfreq.c| 223 +++++
>>drivers/fpga/xrt/lib/xleaf/clock.c| 652 +++++++++++++
>>drivers/fpga/xrt/lib/xleaf/ddr_calibration.c| 210 +++++
>>drivers/fpga/xrt/lib/xleaf/devctl.c| 169 ++++
>>drivers/fpga/xrt/lib/xleaf/icap.c| 328 +++++++
>>drivers/fpga/xrt/lib/xleaf/ucs.c| 152 +++
>>drivers/fpga/xrt/lib/xleaf/vsec.c| 372 ++++++++
>>drivers/fpga/xrt/lib/xroot.c| 536 +++++++++++
>>drivers/fpga/xrt/metadata/Kconfig| 12 +
>>drivers/fpga/xrt/metadata/Makefile| 16 +
>>drivers/fpga/xrt/metadata/metadata.c| 578 ++++++++++++
>>drivers/fpga/xrt/mgmt/Kconfig| 15 +
>>drivers/fpga/xrt/mgmt/Makefile| 19 +
>>drivers/fpga/xrt/mgmt/root.c| 420 +++++++++
>>drivers/fpga/xrt/mgmt/xmgmt-main-region.c| 483 ++++++++++
>>drivers/fpga/xrt/mgmt/xmgmt-main.c| 662 +++++++++++++
>>drivers/fpga/xrt/mgmt/xmgmt.h| 33 +
>>drivers/fpga/xrt/mgmt/xrt-mgr.c| 190 ++++
>>drivers/fpga/xrt/mgmt/xrt-mgr.h| 16 +
>>include/uapi/linux/xrt/xclbin.h| 409 ++++++++
>>include/uapi/linux/xrt/xmgmt-ioctl.h| 46 +
>> 53 files changed, 9988 insertions(+)
>> create mode 100644Documentation/fpga/xrt.rst
>> create mode 100644drivers/fpga/xrt/Kconfig
>> create mode 100644drivers/fpga/xrt/include/events.h
>> create mode 100644drivers/fpga/xrt/include/group.h
>> create mode 100644drivers/fpga/xrt/include/metadata.h
>> create mode 100644drivers/fpga/xrt/include/subdev_id.h
>> create mode 100644drivers/fpga/xrt/include/xclbin-helper.h
>> create mode 100644drivers/fpga/xrt/include/xdevice.h
>> create mode 100644drivers/fpga/xrt/include/xleaf.h
>> create mode 100644drivers/fpga/xrt/include/xleaf/axigate.h
>> create mode 100644drivers/fpga/xrt/include/xleaf/clkfreq.h
>> create mode 100644drivers/fpga/xrt/include/xleaf/clock.h
>> create mode 100644drivers/fpga/xrt/include/xleaf/ddr_calibration.h
>> create mode 100644drivers/fpga/xrt/include/xleaf/devctl.h
>> create mode 100644drivers/fpga/xrt/include/xleaf/icap.h
>> create mode 100644drivers/fpga/xrt/include/xmgmt-main.h
>> create mode 100644drivers/fpga/xrt/include/xroot.h
>> create mode 100644drivers/fpga/xrt/lib/Kconfig
>> create mode 100644drivers/fpga/xrt/lib/Makefile
>> create mode 100644drivers/fpga/xrt/lib/cdev.c
>> create mode 100644drivers/fpga/xrt/lib/group.c
>> create mode 100644drivers/fpga/xrt/lib/lib-drv.c
>> create mode 100644drivers/fpga/xrt/lib/lib-drv.h
>> create mode 100644drivers/fpga/xrt/lib/subdev.c
>> create mode 100644drivers/fpga/xrt/lib/subdev_pool.h
>> create mode 100644drivers/fpga/xrt/lib/xclbin.c
>> create mode 100644drivers/fpga/xrt/lib/xleaf/axigate.c
>> create mode 100644drivers/fpga/xrt/lib/xleaf/clkfreq.c
>> create mode 100644drivers/fpga/xrt/lib/xleaf/clock.c
>> create mode 100644drivers/fpga/xrt/lib/xleaf/ddr_calibration.c
>> create mode 100644drivers/fpga/xrt/lib/xleaf/devctl.c
>> create mode 100644drivers/fpga/xrt/lib/xleaf/icap.c
>> create mode 100644drivers/fpga/xrt/lib/xleaf/ucs.c
>> create mode 100644drivers/fpga/xrt/lib/xleaf/vsec.c
>> create mode 100644drivers/fpga/xrt/lib/xroot.c
>> create mode 100644drivers/fpga/xrt/metadata/Kconfig
>> create mode 100644drivers/fpga/xrt/metadata/Makefile
>> create mode 100644drivers/fpga/xrt/metadata/metadata.c
>> create mode 100644drivers/fpga/xrt/mgmt/Kconfig
>> create mode 100644drivers/fpga/xrt/mgmt/Makefile
>> create mode 100644drivers/fpga/xrt/mgmt/root.c
>> create mode 100644drivers/fpga/xrt/mgmt/xmgmt-main-region.c
>> create mode 100644drivers/fpga/xrt/mgmt/xmgmt-main.c
>> create mode 100644drivers/fpga/xrt/mgmt/xmgmt.h
>> create mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.c
>> create mode 100644drivers/fpga/xrt/mgmt/xrt-mgr.h
>> create mode 100644include/uapi/linux/xrt/xclbin.h
>> create mode 100644include/uapi/linux/xrt/xmgmt-ioctl.h
>>
Hi Tom,
Sure. I will send out a V8 set just dropping listed xleafs and doing the cleanups.
Thanks,
Lizhi
Quoted 580 lines · Tom Rix
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
Quoted 4 lines · Lizhi Hou
Hi Tom,
I am working on v8 patchset which I followed your guidance to move the listed xleaf to suggested subsystems. And the spelling error fixes, and
fpga-xrt.hcleanup are all included. Does that make senses to you? If yes, I may send the V8 patchset early next week for you to review.Can handling the move be done in a followup ?
AFAIK, there are no other problems with v7 and I would rather see a smaller subset of v7 make it intree sooner.
This would mean dropping the (maybe) contentious xleafs from v8 just doing the cleanups.
Tom
Quoted 560 lines
Thanks,
LizhiOn 7/16/21, 11:27 AM, "Tom Rix" <[email protected]> wrote:
CAUTION: This message has originated from an External Source.
Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.On 7/1/21 1:32 PM, Tom Rix wrote: > Lizhi, > > Sorry for the delay in reviewing v7. > > Is it too early to blame it on the July 4 holiday here ?!? :) > > > All the small stuff looks fine to me. In this pass I lookedat issues
> that would need a refactoring. Since it would be a lot of
work and I
> am not the final word on this, it would be good if some others to > chime in. Also a couple of new spelling fixes at the end.Lizhi
This pathset has stalled.
The spelling changes should be fixed.
Some of xleafs may need to be moved and reworked.
The addition of building outside of fpga/xrt is a new feature,
and I
think is best considered when the first foundational change (this patchset) is in tree.Could the xleafs' below be dropped from this set ?
Tom
>
> Tom
>
>
> Having xrt/ dir
> ok with it or it will follow the subdir reorg of fpga/, afaik
not a
> blocker
>
> Location ofxrt_bus_type
> ok, similar todfl_bus_type
>
> Non fpga subdevices should go to other subsystems.
> looking indrivers/fpga/xrt/lib/xleaf
>
> clock clkfrq ucs these are clocks
> should move todrivers/clk/xilinx/
>
> axigate, for fpga partitioning
> ok to stay
>
>ddr_calibaration, a memory status checker
> should movedrivers/memorydfl-emif is similar
>
> devctl, a general purpose misc driver
> should move todrivers/mfd
>
> icap, for fpga bitstream writing
> ok to stay
>
> vsec, misc small drivers discovered via pci config vsec > should move todrivers/mfd
>
> Forinclude/uapi/linux
> collapseinclude/uapi/linux/xrt/*.hintoinclude/uapi/linux/fpga-xrt.h
> There are only 2 files, one really small.fpga-xrt.hfollowsfpga-dfl.h
> The comments are pretty messy, user should be able to scan them. > Try cleaning them up.
>
> Spelling mistakes
>
> diff --gita/Documentation/fpga/xrt.rstb/Documentation/fpga/xrt.rst
> index5a5b4d5a3bc6..84eb41be9ac1100644
> ---a/Documentation/fpga/xrt.rst
> +++b/Documentation/fpga/xrt.rst
> @@ -275,7 +275,7 @@fpga_bridgeandfpga_regionfor the next
region in
> the chain.
>fpga_bridge
> -----------
>
> -Like thefpga_region, afpga_bridgeis created by walking the
device
> tree
> +Like thefpga_region, anfpga_bridgeis created by walking
the device
> tree
> of the parent group. The bridge is used for isolation between a > parent and
> its child.
>
> @@ -416,7 +416,7 @@ xclbin is compiled by end user using > `Vitis
>
<https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html>`_
> tool set from Xilinx. The xclbin contains sections describing
user
> compiled
> acceleration engines/kernels, memory subsystems, clocking
information
> etc. It also
> -contains a FPGA bitstream for the user partition, UUIDs,
platform
> name, etc.
> +contains an FPGA bitstream for the user partition, UUIDs,
platform> name, etc. > > > .. _xsabin_xclbin_container_format: > diff --git a/drivers/fpga/xrt/include/metadata.h > b/drivers/fpga/xrt/include/metadata.h > index c4df88262f8a..f48d6d42f5ef 100644 > --- a/drivers/fpga/xrt/include/metadata.h > +++ b/drivers/fpga/xrt/include/metadata.h > @@ -194,7 +194,7 @@ int xrt_md_get_interface_uuids(structdevice *dev,
> const char *blob,
> /*
> * The firmware provides a 128 bit hash string as a unique id
to the
> * partition/interface.
> - * Existing hw does not yet use the cononical form, so it is > necessary to
> + * Existing hw does not yet use the canonical form, so it is > necessary to
> * use a translation function.
> */
> static inline void xrt_md_trans_uuid2str(constuuid_t*uuid,
char> *uuidstr) > diff --git a/drivers/fpga/xrt/lib/xroot.c b/drivers/fpga/xrt/lib/xroot.c > index 7b3e540dd6c0..f324a25e1d4d 100644 > --- a/drivers/fpga/xrt/lib/xroot.c > +++ b/drivers/fpga/xrt/lib/xroot.c > @@ -427,7 +427,7 @@ static void xroot_bringup_group_work(struct > work_struct *work) > r = xleaf_call(xdev, XRT_GROUP_INIT_CHILDREN, NULL); > xroot_put_group(xr, xdev); > if (r == -EEXIST) > - continue; /* Already brough up, nothing to do. */ > + continue; /* Already brought up, nothing to > do. */ > if (r) > atomic_inc(&xr->groups.bringup_failed_cnt); > > diff --git a/drivers/fpga/xrt/mgmt/xmgmt-main.c > b/drivers/fpga/xrt/mgmt/xmgmt-main.c > index 820c888e7918..9077254e0f8a 100644 > --- a/drivers/fpga/xrt/mgmt/xmgmt-main.c > +++ b/drivers/fpga/xrt/mgmt/xmgmt-main.c > @@ -142,7 +142,7 @@ static ssize_t VBNV_show(struct device *dev, > struct device_attribute *da, char * > } > static DEVICE_ATTR_RO(VBNV); > > -/* logic uuid is the uuid uniquely identfy the partition */ > +/* logic uuid is the uuid uniquely identify the partition */ > static ssize_t logic_uuids_show(struct device *dev, struct > device_attribute *da, char *buf) > { > struct xrt_device *xdev = to_xrt_dev(dev); > diff --git a/drivers/fpga/xrt/mgmt/xrt-mgr.c > b/drivers/fpga/xrt/mgmt/xrt-mgr.c > index 41263a033d9d..ab253b516e8d 100644 > --- a/drivers/fpga/xrt/mgmt/xrt-mgr.c > +++ b/drivers/fpga/xrt/mgmt/xrt-mgr.c > @@ -115,7 +115,7 @@ static int xmgmt_pr_write_init(struct fpga_manager > *mgr, > } > > /* > - * The implementation requries full xclbin image before wecan start
> + * The implementation requires full xclbin image before we
can start
> * programming the hardware via ICAP subsystem. The full
image is
> required
> * for checking the validity of xclbin and walking the
sections to> * discover the bitstream. > > On 5/27/21 5:49 PM, Lizhi Hou wrote: >> Hello, >> >> This is V7 of patch series which adds management physicalfunction
>> driver
>> for Xilinx Alveo PCIe accelerator cards.
>> https://www.xilinx.com/products/boards-and-kits/alveo.html
>>
>> This driver is part of Xilinx Runtime (XRT) open source stack. >>
>> XILINX ALVEO PLATFORM ARCHITECTURE
>>
>> Alveo PCIe FPGA based platforms have a static *shell*
partition and a
>> partial re-configurable *user* partition. The shell partition is >> automatically loaded from flash when host is booted and PCIe is >> enumerated
>> by BIOS. Shell cannot be changed till the next cold reboot.
The shell
>> exposes two PCIe physical functions:
>>
>> 1. management physical function
>> 2. user physical function
>>
>> The patch series includesDocumentation/xrt.rstwhich
describes Alveo
>> platform, XRT driver architecture and deployment model in
more detail.
>>
>> Users compile their high level design in C/C++/OpenCL or RTL
into FPGA
>> image using Vitis tools.
>>
https://www.xilinx.com/products/design-tools/vitis/vitis-platform.html
>>
>> The compiled image is packaged as xclbin which contains partial >> bitstream
>> for the user partition and necessary metadata. Users can
dynamically
>> swap
>> the image running on the user partition in order to switch
between
>> different workloads by loading different xclbins.
>>
>> XRT DRIVERS FOR XILINX ALVEO
>>
>> XRT Linux kernel driver *xrt-mgmt* binds to management physical >> function of
>> Alveo platform. The modular driver framework is organized
into several
>> platform drivers which primarily handle the following
functionality:
>>
>> 1. Loading firmware container also called xsabin at driver
attach time
>> 2. Loading of user compiled xclbin with FPGA Manager
integration>> 3. Clock scaling of image running on user partition >> 4. In-band sensors: temp, voltage, power, etc. >> 5. Device reset and rescan>>
>> The platform drivers are packaged into *xrt-lib* helper
module with well
>> defined interfaces. The module provides a pseudo-bus
implementation
>> for the
>> platform drivers. More details on the driver model can be
found in
>>Documentation/xrt.rst.
>>
>> User physical function driver is not included in this patch
series.
>>
>> LIBFDT REQUIREMENT
>>
>> XRT driver infrastructure uses Device Tree as a metadata
format to
>> discover
>> HW subsystems in the Alveo PCIe device. The Device Tree
schema used
>> by XRT
>> is documented inDocumentation/xrt.rst.
>>
>> TESTING AND VALIDATION
>>
>> xrt-mgmt driver can be tested with full XRT open source stack
which
>> includes user space libraries, board utilities and (out of
tree) first
>> generation user physical function driver xocl. XRT open
source runtime
>> stack is available at https://github.com/Xilinx/XRT
>>
>> Complete documentation for XRT open source stack including
sections on>> Alveo/XRT security and platform architecture can be found here: >> >> https://xilinx.github.io/XRT/master/html/index.html >> https://xilinx.github.io/XRT/master/html/security.html >>https://xilinx.github.io/XRT/master/html/platforms_partitions.html
>>
>> Changes since v6:
>> - Resolved grammatical errors and cleaned up taxonomy inxrt.rst
>> documentation.
>> - Fixed clang warnings.
>> - Updated code base to include v6 code review comments. >>
>> Changes since v5:
>> - Revert all changes 'mgnt/MGNT' back to 'mgmt/MGMT' >> - Updated code base to include v5 code review comments.
>>xrt.rst: address grammar and taxonomy
>>subdev_id.h: definesXRT_SUBDEV_INVALID= 0
>>xclbin.c: change shift operation tobe_to_cpu
>> - Resolved kernel test robot errors.
>>
>> Changes since v4:
>> - Addedxrt_bus_typeandxrt_device. All sub devices were
changed from
>> platform_bus_type/platform_device to xrt_bus_type/xrt_device.
>> - Renamed xrt-mgmt driver to xrt-mgnt driver.
>> - Replaced 'MGMT' with 'MGNT' and 'mgmt' with 'mgnt' in code
and file
>> names
>> - Moved pci function calls from infrastructure to xrt-mgnt
driver.>> - Renamed files: mgmt/main.c -> mgnt/xmgnt-main.c >> mgmt/main-region.c -> mgnt/xmgnt-main-region.c >> include/xmgmt-main.h -> include/xmgnt-main.h >> mgmt/fmgr-drv.c -> mgnt/xrt-mgr.c >> mgmt/fmgr.h -> mgnt/xrt-mgr.h >> - Updated code base to include v4 code review comments. >> >> Changes since v3: >> - Leaf drivers use regmap-mmio to access hardware registers. >> - Renamed driver module: xmgmt.ko -> xrt-mgmt.ko >> - Renamed files: calib.[c|h] -> ddr_calibration.[c|h], >> lib/main.[c|h] -> lib/lib-drv.[c|h], >> mgmt/main-impl.h - > mgmt/xmgnt.h >> - Updated code base to include v3 code review comments. >> >> Changes since v2: >> - Streamlined the driver framework into *xleaf*, *group* and*xroot*
>> - Updated documentation to show the driver model with examples >> - Addressed kernel test robot errors
>> - Added a selftest for basic driver framework
>> - Documented device tree schema
>> - Removed need to export libfdt symbols
>>
>> Changes since v1:
>> - Updated the driver to usefpga_regionandfpga_bridgefor FPGA
>> programming
>> - Dropped platform drivers not related to PR programming to
focus on XRT
>> core framework
>> - UpdatedDocumentation/fpga/xrt.rstwith information on XRT
core
>> framework
>> - Addressed checkpatch issues
>> - Dropped xrt- prefix from some header files
>>
>> For reference V6 version of patch series can be found here:
>>
>>
https://lore.kernel.org/lkml/[email protected]/>> https://lore.kernel.org/lkml/[email protected]/ >> https://lore.kernel.org/lkml/[email protected]/ >> https://lore.kernel.org/lkml/[email protected]/ >> https://lore.kernel.org/lkml/[email protected]/ >> https://lore.kernel.org/lkml/[email protected]/ >> https://lore.kernel.org/lkml/[email protected]/ >> https://lore.kernel.org/lkml/[email protected]/ >> https://lore.kernel.org/lkml/[email protected]/ >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> https://lore.kernel.org/lkml/[email protected]/ >> >> >> Lizhi Hou (20): >> Documentation: fpga: Add a document describing XRT Alveo drivers >> fpga: xrt: driver metadata helper functions >> fpga: xrt: xclbin file helper functions >> fpga: xrt: xrt-lib driver manager >> fpga: xrt: group driver >> fpga: xrt: char dev node helper functions >> fpga: xrt: root driver infrastructure >> fpga: xrt: driver infrastructure >> fpga: xrt: management physical function driver (root) >> fpga: xrt: main driver for management function device >> fpga: xrt: fpga-mgr and region implementation for xclbin download >> fpga: xrt: VSEC driver >> fpga: xrt: User Clock Subsystem driver >> fpga: xrt: ICAP driver >> fpga: xrt: devctl xrt driver >> fpga: xrt: clock driver >> fpga: xrt: clock frequency counter driver >> fpga: xrt: DDR calibration driver >> fpga: xrt: partition isolation driver >> fpga: xrt: Kconfig and Makefile updates for XRT drivers>>
>>Documentation/fpga/index.rst| 1 +
>>Documentation/fpga/xrt.rst| 870
++++++++++++++++++>> MAINTAINERS | 11 + >> drivers/Makefile | 1 + >> drivers/fpga/Kconfig | 2 + >> drivers/fpga/Makefile | 5 + >> drivers/fpga/xrt/Kconfig | 8 + >> drivers/fpga/xrt/include/events.h | 45 + >> drivers/fpga/xrt/include/group.h | 25 + >> drivers/fpga/xrt/include/metadata.h | 236 +++++ >> drivers/fpga/xrt/include/subdev_id.h | 39 + >> drivers/fpga/xrt/include/xclbin-helper.h | 48 + >> drivers/fpga/xrt/include/xdevice.h | 131 +++ >> drivers/fpga/xrt/include/xleaf.h | 205 +++++ >> drivers/fpga/xrt/include/xleaf/axigate.h | 23 + >> drivers/fpga/xrt/include/xleaf/clkfreq.h | 21 + >> drivers/fpga/xrt/include/xleaf/clock.h | 29 + >> .../fpga/xrt/include/xleaf/ddr_calibration.h | 28 + >> drivers/fpga/xrt/include/xleaf/devctl.h | 40 + >> drivers/fpga/xrt/include/xleaf/icap.h | 27 + >> drivers/fpga/xrt/include/xmgmt-main.h | 34 + >> drivers/fpga/xrt/include/xroot.h | 117 +++ >> drivers/fpga/xrt/lib/Kconfig | 17 + >> drivers/fpga/xrt/lib/Makefile | 30 + >> drivers/fpga/xrt/lib/cdev.c | 209 +++++ >> drivers/fpga/xrt/lib/group.c | 278 ++++++ >> drivers/fpga/xrt/lib/lib-drv.c | 328 +++++++ >> drivers/fpga/xrt/lib/lib-drv.h | 21 + >> drivers/fpga/xrt/lib/subdev.c | 859 +++++++++++++++++ >> drivers/fpga/xrt/lib/subdev_pool.h | 53 ++ >> drivers/fpga/xrt/lib/xclbin.c | 381 ++++++++ >> drivers/fpga/xrt/lib/xleaf/axigate.c | 325 +++++++ >> drivers/fpga/xrt/lib/xleaf/clkfreq.c | 223 +++++ >> drivers/fpga/xrt/lib/xleaf/clock.c | 652 +++++++++++++ >> drivers/fpga/xrt/lib/xleaf/ddr_calibration.c | 210 +++++ >> drivers/fpga/xrt/lib/xleaf/devctl.c | 169 ++++ >> drivers/fpga/xrt/lib/xleaf/icap.c | 328 +++++++ >> drivers/fpga/xrt/lib/xleaf/ucs.c | 152 +++ >> drivers/fpga/xrt/lib/xleaf/vsec.c | 372 ++++++++ >> drivers/fpga/xrt/lib/xroot.c | 536 +++++++++++ >> drivers/fpga/xrt/metadata/Kconfig | 12 + >> drivers/fpga/xrt/metadata/Makefile | 16 + >> drivers/fpga/xrt/metadata/metadata.c | 578 ++++++++++++ >> drivers/fpga/xrt/mgmt/Kconfig | 15 + >> drivers/fpga/xrt/mgmt/Makefile | 19 + >> drivers/fpga/xrt/mgmt/root.c | 420 +++++++++ >> drivers/fpga/xrt/mgmt/xmgmt-main-region.c | 483 ++++++++++ >> drivers/fpga/xrt/mgmt/xmgmt-main.c | 662 +++++++++++++ >> drivers/fpga/xrt/mgmt/xmgmt.h | 33 + >> drivers/fpga/xrt/mgmt/xrt-mgr.c | 190 ++++ >> drivers/fpga/xrt/mgmt/xrt-mgr.h | 16 + >> include/uapi/linux/xrt/xclbin.h | 409 ++++++++ >> include/uapi/linux/xrt/xmgmt-ioctl.h | 46 + >> 53 files changed, 9988 insertions(+) >> create mode 100644 Documentation/fpga/xrt.rst >> create mode 100644 drivers/fpga/xrt/Kconfig >> create mode 100644 drivers/fpga/xrt/include/events.h >> create mode 100644 drivers/fpga/xrt/include/group.h >> create mode 100644 drivers/fpga/xrt/include/metadata.h >> create mode 100644 drivers/fpga/xrt/include/subdev_id.h >> create mode 100644 drivers/fpga/xrt/include/xclbin-helper.h >> create mode 100644 drivers/fpga/xrt/include/xdevice.h >> create mode 100644 drivers/fpga/xrt/include/xleaf.h >> create mode 100644 drivers/fpga/xrt/include/xleaf/axigate.h >> create mode 100644 drivers/fpga/xrt/include/xleaf/clkfreq.h >> create mode 100644 drivers/fpga/xrt/include/xleaf/clock.h >> create mode 100644 drivers/fpga/xrt/include/xleaf/ddr_calibration.h >> create mode 100644 drivers/fpga/xrt/include/xleaf/devctl.h >> create mode 100644 drivers/fpga/xrt/include/xleaf/icap.h >> create mode 100644 drivers/fpga/xrt/include/xmgmt-main.h >> create mode 100644 drivers/fpga/xrt/include/xroot.h >> create mode 100644 drivers/fpga/xrt/lib/Kconfig >> create mode 100644 drivers/fpga/xrt/lib/Makefile >> create mode 100644 drivers/fpga/xrt/lib/cdev.c >> create mode 100644 drivers/fpga/xrt/lib/group.c >> 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/subdev.c >> create mode 100644 drivers/fpga/xrt/lib/subdev_pool.h >> create mode 100644 drivers/fpga/xrt/lib/xclbin.c >> create mode 100644 drivers/fpga/xrt/lib/xleaf/axigate.c >> create mode 100644 drivers/fpga/xrt/lib/xleaf/clkfreq.c >> create mode 100644 drivers/fpga/xrt/lib/xleaf/clock.c >> create mode 100644 drivers/fpga/xrt/lib/xleaf/ddr_calibration.c >> create mode 100644 drivers/fpga/xrt/lib/xleaf/devctl.c >> create mode 100644 drivers/fpga/xrt/lib/xleaf/icap.c >> create mode 100644 drivers/fpga/xrt/lib/xleaf/ucs.c >> create mode 100644 drivers/fpga/xrt/lib/xleaf/vsec.c >> create mode 100644 drivers/fpga/xrt/lib/xroot.c >> create mode 100644 drivers/fpga/xrt/metadata/Kconfig >> create mode 100644 drivers/fpga/xrt/metadata/Makefile >> create mode 100644 drivers/fpga/xrt/metadata/metadata.c >> create mode 100644 drivers/fpga/xrt/mgmt/Kconfig >> create mode 100644 drivers/fpga/xrt/mgmt/Makefile >> create mode 100644 drivers/fpga/xrt/mgmt/root.c >> create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-main-region.c >> create mode 100644 drivers/fpga/xrt/mgmt/xmgmt-main.c >> create mode 100644 drivers/fpga/xrt/mgmt/xmgmt.h >> create mode 100644 drivers/fpga/xrt/mgmt/xrt-mgr.c >> create mode 100644 drivers/fpga/xrt/mgmt/xrt-mgr.h >> create mode 100644 include/uapi/linux/xrt/xclbin.h >> create mode 100644 include/uapi/linux/xrt/xmgmt-ioctl.h >>