169 lines · plain
1FPGA Manager2============3 4Overview5--------6 7The FPGA manager core exports a set of functions for programming an FPGA with8an image. The API is manufacturer agnostic. All manufacturer specifics are9hidden away in a low level driver which registers a set of ops with the core.10The FPGA image data itself is very manufacturer specific, but for our purposes11it's just binary data. The FPGA manager core won't parse it.12 13The FPGA image to be programmed can be in a scatter gather list, a single14contiguous buffer, or a firmware file. Because allocating contiguous kernel15memory for the buffer should be avoided, users are encouraged to use a scatter16gather list instead if possible.17 18The particulars for programming the image are presented in a structure (struct19fpga_image_info). This struct contains parameters such as pointers to the20FPGA image as well as image-specific particulars such as whether the image was21built for full or partial reconfiguration.22 23How to support a new FPGA device24--------------------------------25 26To add another FPGA manager, write a driver that implements a set of ops. The27probe function calls ``fpga_mgr_register()`` or ``fpga_mgr_register_full()``,28such as::29 30 static const struct fpga_manager_ops socfpga_fpga_ops = {31 .write_init = socfpga_fpga_ops_configure_init,32 .write = socfpga_fpga_ops_configure_write,33 .write_complete = socfpga_fpga_ops_configure_complete,34 .state = socfpga_fpga_ops_state,35 };36 37 static int socfpga_fpga_probe(struct platform_device *pdev)38 {39 struct device *dev = &pdev->dev;40 struct socfpga_fpga_priv *priv;41 struct fpga_manager *mgr;42 int ret;43 44 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);45 if (!priv)46 return -ENOMEM;47 48 /*49 * do ioremaps, get interrupts, etc. and save50 * them in priv51 */52 53 mgr = fpga_mgr_register(dev, "Altera SOCFPGA FPGA Manager",54 &socfpga_fpga_ops, priv);55 if (IS_ERR(mgr))56 return PTR_ERR(mgr);57 58 platform_set_drvdata(pdev, mgr);59 60 return 0;61 }62 63 static int socfpga_fpga_remove(struct platform_device *pdev)64 {65 struct fpga_manager *mgr = platform_get_drvdata(pdev);66 67 fpga_mgr_unregister(mgr);68 69 return 0;70 }71 72Alternatively, the probe function could call one of the resource managed73register functions, ``devm_fpga_mgr_register()`` or74``devm_fpga_mgr_register_full()``. When these functions are used, the75parameter syntax is the same, but the call to ``fpga_mgr_unregister()`` should be76removed. In the above example, the ``socfpga_fpga_remove()`` function would not be77required.78 79The ops will implement whatever device specific register writes are needed to80do the programming sequence for this particular FPGA. These ops return 0 for81success or negative error codes otherwise.82 83The programming sequence is::84 1. .parse_header (optional, may be called once or multiple times)85 2. .write_init86 3. .write or .write_sg (may be called once or multiple times)87 4. .write_complete88 89The .parse_header function will set header_size and data_size to90struct fpga_image_info. Before parse_header call, header_size is initialized91with initial_header_size. If flag skip_header of fpga_manager_ops is true,92.write function will get image buffer starting at header_size offset from the93beginning. If data_size is set, .write function will get data_size bytes of94the image buffer, otherwise .write will get data up to the end of image buffer.95This will not affect .write_sg, .write_sg will still get whole image in96sg_table form. If FPGA image is already mapped as a single contiguous buffer,97whole buffer will be passed into .parse_header. If image is in scatter-gather98form, core code will buffer up at least .initial_header_size before the first99call of .parse_header, if it is not enough, .parse_header should set desired100size into info->header_size and return -EAGAIN, then it will be called again101with greater part of image buffer on the input.102 103The .write_init function will prepare the FPGA to receive the image data. The104buffer passed into .write_init will be at least info->header_size bytes long;105if the whole bitstream is not immediately available then the core code will106buffer up at least this much before starting.107 108The .write function writes a buffer to the FPGA. The buffer may be contain the109whole FPGA image or may be a smaller chunk of an FPGA image. In the latter110case, this function is called multiple times for successive chunks. This interface111is suitable for drivers which use PIO.112 113The .write_sg version behaves the same as .write except the input is a sg_table114scatter list. This interface is suitable for drivers which use DMA.115 116The .write_complete function is called after all the image has been written117to put the FPGA into operating mode.118 119The ops include a .state function which will determine the state the FPGA is in120and return a code of type enum fpga_mgr_states. It doesn't result in a change121in state.122 123API for implementing a new FPGA Manager driver124----------------------------------------------125 126* ``fpga_mgr_states`` - Values for :c:expr:`fpga_manager->state`.127* struct fpga_manager - the FPGA manager struct128* struct fpga_manager_ops - Low level FPGA manager driver ops129* struct fpga_manager_info - Parameter structure for fpga_mgr_register_full()130* __fpga_mgr_register_full() - Create and register an FPGA manager using the131 fpga_mgr_info structure to provide the full flexibility of options132* __fpga_mgr_register() - Create and register an FPGA manager using standard133 arguments134* __devm_fpga_mgr_register_full() - Resource managed version of135 __fpga_mgr_register_full()136* __devm_fpga_mgr_register() - Resource managed version of __fpga_mgr_register()137* fpga_mgr_unregister() - Unregister an FPGA manager138 139Helper macros ``fpga_mgr_register_full()``, ``fpga_mgr_register()``,140``devm_fpga_mgr_register_full()``, and ``devm_fpga_mgr_register()`` are available141to ease the registration.142 143.. kernel-doc:: include/linux/fpga/fpga-mgr.h144 :functions: fpga_mgr_states145 146.. kernel-doc:: include/linux/fpga/fpga-mgr.h147 :functions: fpga_manager148 149.. kernel-doc:: include/linux/fpga/fpga-mgr.h150 :functions: fpga_manager_ops151 152.. kernel-doc:: include/linux/fpga/fpga-mgr.h153 :functions: fpga_manager_info154 155.. kernel-doc:: drivers/fpga/fpga-mgr.c156 :functions: __fpga_mgr_register_full157 158.. kernel-doc:: drivers/fpga/fpga-mgr.c159 :functions: __fpga_mgr_register160 161.. kernel-doc:: drivers/fpga/fpga-mgr.c162 :functions: __devm_fpga_mgr_register_full163 164.. kernel-doc:: drivers/fpga/fpga-mgr.c165 :functions: __devm_fpga_mgr_register166 167.. kernel-doc:: drivers/fpga/fpga-mgr.c168 :functions: fpga_mgr_unregister169