Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:39

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  * @ingroup zynq_devcfg
0006  * @brief Device configuration support.
0007  *
0008  * Provides support for the Zynq7000 series device configuration interface
0009  * controller. PCAP command sequences are written using the write interface,
0010  * and PCAP responses are retrieved with the read interface. The driver can be
0011  * used for reconfiguration of the FPGA, and also reading FPGA configuration
0012  * data for error checking.
0013  */
0014 
0015 /*
0016  * Copyright (c) 2016
0017  *  NSF Center for High-Performance Reconfigurable Computing (CHREC),
0018  *  University of Florida.  All rights reserved.
0019  * Copyright (c) 2017
0020  *  NSF Center for High-Performance Reconfigurable Computing (CHREC),
0021  *  University of Pittsburgh.  All rights reserved.
0022  *
0023  * Redistribution and use in source and binary forms, with or without
0024  * modification, are permitted provided that the following conditions are
0025  * met:
0026  * 1. Redistributions of source code must retain the above copyright
0027  *    notice, this list of conditions and the following disclaimer.
0028  * 2. Redistributions in binary form must reproduce the above copyright
0029  *    notice, this list of conditions and the following disclaimer in the
0030  *    documentation and/or other materials provided with the distribution.
0031  *
0032  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0033  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
0034  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
0035  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
0036  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0037  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0038  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0039  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0040  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0041  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0042  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0043  *
0044  * The views and conclusions contained in the software and documentation
0045  * are those of the authors and should not be interpreted as representing
0046  * official policies, either expressed or implied, of CHREC.
0047  *
0048  * Author: Patrick Gauvin <gauvin@hcs.ufl.edu>
0049  */
0050 
0051 /**
0052  * @defgroup zynq_devcfg Device Configuration Interface Support
0053  * @ingroup arm_zynq
0054  * @brief Device Configuration Interface Support
0055  */
0056 
0057 #ifndef LIBBSP_ARM_XILINX_ZYNQ_DEVCFG_H
0058 #define LIBBSP_ARM_XILINX_ZYNQ_DEVCFG_H
0059 
0060 #include <rtems/libio.h>
0061 
0062 #ifdef __cplusplus
0063 extern "C" {
0064 #endif /* __cplusplus */
0065 
0066 #define ZYNQ_DEVCFG_NAME "/dev/fpga"
0067 /*
0068  * Add to CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS
0069  */
0070 #define ZYNQ_DEVCFG_DRIVER_TABLE_ENTRY \
0071   { zynq_devcfg_init, zynq_devcfg_open, zynq_devcfg_close, zynq_devcfg_read, \
0072     zynq_devcfg_write, zynq_devcfg_control }
0073 
0074 /* PCAP DMA transfers must be 64-byte aligned.
0075    Use this to read or write an aligned buffer avoiding the
0076    use of the heap in the driver. */
0077 #define ZYNQ_DEVCFG_PCAP_DMA_ALIGN 64
0078 
0079 /* Configuration command words. */
0080 #define ZYNQ_DEVCFG_CFG_DUMMY ( 0xffffffff )
0081 #define ZYNQ_DEVCFG_CFG_BUS_WIDTH_SYNC ( 0x000000bb )
0082 #define ZYNQ_DEVCFG_CFG_BUS_WIDTH_DETECT ( 0x11220044 )
0083 #define ZYNQ_DEVCFG_CFG_SYNC ( 0xaa995566 )
0084 
0085 /** @brief Zynq configuration frame length in bytes */
0086 #define ZYNQ_DEVCFG_CONFIG_FRAME_LEN ( 101 * 4 )
0087 
0088 #define ZYNQ_DEVCFG_IOCTL_VERSION_MAX_LEN 16
0089 
0090 enum zynq_devcfg_ioctl {
0091   /** @brief Argument: Buffer for character string of at least
0092    * ZYNQ_DEVCFG_IOCTL_VERSION_MAX_LEN bytes.
0093    */
0094   ZYNQ_DEVCFG_IOCTL_VERSION,
0095   /** @brief Argument: None. */
0096   ZYNQ_DEVCFG_IOCTL_FPGA_PROGRAM_PRE,
0097   /** @brief Argument: None. */
0098   ZYNQ_DEVCFG_IOCTL_FPGA_PROGRAM_POST,
0099   /** @brief Argument: None. */
0100   ZYNQ_DEVCFG_IOCTL_FPGA_PROGRAM_WAIT_DONE,
0101   /** @brief Argument: bool. */
0102   ZYNQ_DEVCFG_IOCTL_SET_SECURE,
0103   /** @brief Argument: bool. */
0104   ZYNQ_DEVCFG_IOCTL_SET_WRITE_MODE_RESTRICTED
0105 };
0106 
0107 rtems_device_driver zynq_devcfg_init(
0108   rtems_device_major_number  major,
0109   rtems_device_minor_number  minor,
0110   void                      *args
0111 );
0112 
0113 rtems_device_driver zynq_devcfg_open(
0114   rtems_device_major_number  major,
0115   rtems_device_minor_number  minor,
0116   void                      *args
0117 );
0118 
0119 rtems_device_driver zynq_devcfg_close(
0120   rtems_device_major_number  major,
0121   rtems_device_minor_number  minor,
0122   void                      *args
0123 );
0124 
0125 /**
0126  * @brief Read from the PCAP controller.
0127  *
0128  * Readback reads cannot be split into multiple DMA reads, this may cause the
0129  * PCAP DMA to exhibit unexpected behavior. Therefore, the read length must
0130  * match the preceding command sequence's expected data output length.
0131  */
0132 rtems_device_driver zynq_devcfg_read(
0133   rtems_device_major_number  major,
0134   rtems_device_minor_number  minor,
0135   void                      *args
0136 );
0137 
0138 /**
0139  * @brief Write to the PCAP controller.
0140  *
0141  * Data format: dword aligned bistream data or PCAP commands. Bitstream data is
0142  * expected to be formatted as Vivado 2016.4 outputs BIN-format bitstreams by
0143  * default (not bit-swapped) BUT with the byte order within each dword changed
0144  * to little endian. See UG470 for information on data ordering.
0145  */
0146 rtems_device_driver zynq_devcfg_write(
0147   rtems_device_major_number  major,
0148   rtems_device_minor_number  minor,
0149   void                      *args
0150 );
0151 
0152 rtems_device_driver zynq_devcfg_control(
0153   rtems_device_major_number  major,
0154   rtems_device_minor_number  minor,
0155   void                      *args
0156 );
0157 
0158 #ifdef __cplusplus
0159 }
0160 #endif /* __cplusplus */
0161 
0162 #endif /* LIBBSP_ARM_XILINX_ZYNQ_DEVCFG_H */