title: mmap, axi and multiple reads from pcie
body: <p>I am trying to optimize the reading of data via pcie via mmap. We have some tools that allow for reading/writing one word from the PCIe communication at the time, but I would like to get/write as many words as require in one request.</p>
  <p>My project uses PCIe Gen3 with AXI bridges (2 PCIe bars).</p>
  <p>I can successfully read any word from the bus but I notice a pattern when requesting data:</p>
  <ul>
  <li>request data in address 0: AXI master requests 4 addresses of data, initial addr is 0</li>
  <li>request data in address 0 and 1: two AXI requests: first is similar to the one above, follow by a read requests of 3 addresses of data, initial addr is 1</li>
  <li>request data from address 0 to 2: 3  AXI requests: first two are similar to the previous one, follow by a read requests of 2 addresses of data, initial addr is 2</li>
  </ul>
  <p>The pattern continues until the addr is a multiple of 4. In seems that if I request the first address, the AXI sends the first 4 values.  Any hints? Could this be on the driver that I am using?</p>
  <p>Here's how I use mmap:</p>
  <pre><code>        length_offset = tmp_offset_rw &amp; ~(sysconf (_SC_PAGESIZE)-1);
      mmap_offset = (u_long)(tmp_barx_rw &lt;&lt; 12) + length_offset;
      mmap_len = (u_long)(tmp_size * sizeof(int));
      mmap_address = mmap(NULL, mmap_len + (int)(tmp_offset_rw) - length_offset,
              PROT_READ | PROT_WRITE, MAP_SHARED, fd, mmap_offset);
  
      close(fd);
      // tmp_reg_buf = new u_int[tmp_size];
      // memcpy(tmp_reg_buf, mmap_address , tmp_size*sizeof(int));
    
      // for(int i = 0; i &lt; 4; i++)
      //   printf(&quot;0x%08X\n&quot;, tmp_reg_buf[i]);
      
      for(int i = 0; i &lt; tmp_size; i++)
        printf(&quot;0x%08X\n&quot;, *((u_int*)mmap_address + (int)tmp_offset_rw - length_offset + i));
  
  </code></pre>