fpga: Clarify how write_init works streaming modes
authorJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Tue, 22 Nov 2016 18:22:09 +0000 (18:22 +0000)
committerAlan Tull <atull@opensource.altera.com>
Tue, 29 Nov 2016 21:51:49 +0000 (15:51 -0600)
This interface was designed for streaming, but write_init's buf
argument has an unclear purpose. Define it to be the first bytes
of the bitstream. Each driver gets to set how many bytes (at most)
it wants to see. Short bitstreams will be passed through as-is, while
long ones will be truncated.

The intent is to allow drivers to peek at the header before the transfer
actually starts.

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Acked-by: Alan Tull <atull@opensource.altera.com>
Documentation/fpga/fpga-mgr.txt
drivers/fpga/fpga-mgr.c
drivers/fpga/socfpga-a10.c
include/linux/fpga/fpga-mgr.h

index 087924f2b20c886d38333fb8b2717416ec0544a3..86ee5078fd034ff0247828fa6a3e01c8800da50f 100644 (file)
@@ -169,7 +169,10 @@ The programming sequence is:
  2. .write (may be called once or multiple times)
  3. .write_complete
 
-The .write_init function will prepare the FPGA to receive the image data.
+The .write_init function will prepare the FPGA to receive the image data.  The
+buffer passed into .write_init will be atmost .initial_header_size bytes long,
+if the whole bitstream is not immediately available then the core code will
+buffer up at least this much before starting.
 
 The .write function writes a buffer to the FPGA. The buffer may be contain the
 whole FPGA image or may be a smaller chunk of an FPGA image.  In the latter
index 79ce2eea44dbb8267f587552722fbad16cc82b40..f0a69d3e60a584d4565459b6e845cb205dc93946 100644 (file)
@@ -53,10 +53,12 @@ int fpga_mgr_buf_load(struct fpga_manager *mgr, struct fpga_image_info *info,
        /*
         * Call the low level driver's write_init function.  This will do the
         * device-specific things to get the FPGA into the state where it is
-        * ready to receive an FPGA image.
+        * ready to receive an FPGA image. The low level driver only gets to
+        * see the first initial_header_size bytes in the buffer.
         */
        mgr->state = FPGA_MGR_STATE_WRITE_INIT;
-       ret = mgr->mops->write_init(mgr, info, buf, count);
+       ret = mgr->mops->write_init(mgr, info, buf,
+                                   min(mgr->mops->initial_header_size, count));
        if (ret) {
                dev_err(dev, "Error preparing FPGA for writing\n");
                mgr->state = FPGA_MGR_STATE_WRITE_INIT_ERR;
index ccd9fb23bd5281657c284201959fe28bf4115b93..f8770af0f6b51975be92060292f8d5e1d7591d8d 100644 (file)
@@ -470,6 +470,7 @@ static enum fpga_mgr_states socfpga_a10_fpga_state(struct fpga_manager *mgr)
 }
 
 static const struct fpga_manager_ops socfpga_a10_fpga_mgr_ops = {
+       .initial_header_size = (RBF_DECOMPRESS_OFFSET + 1) * 4,
        .state = socfpga_a10_fpga_state,
        .write_init = socfpga_a10_fpga_write_init,
        .write = socfpga_a10_fpga_write,
index 96a1a33116495e2e8a17270d53922932167e061f..16551d5eac36a70a1fefd1a0ee4d997df18d15c1 100644 (file)
@@ -84,6 +84,7 @@ struct fpga_image_info {
 
 /**
  * struct fpga_manager_ops - ops for low level fpga manager drivers
+ * @initial_header_size: Maximum number of bytes that should be passed into write_init
  * @state: returns an enum value of the FPGA's state
  * @write_init: prepare the FPGA to receive confuration data
  * @write: write count bytes of configuration data to the FPGA
@@ -95,6 +96,7 @@ struct fpga_image_info {
  * called, so leaving them out is fine.
  */
 struct fpga_manager_ops {
+       size_t initial_header_size;
        enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
        int (*write_init)(struct fpga_manager *mgr,
                          struct fpga_image_info *info,