title: PCIe Understanding
body: <p>As this domain is new for me, I have some confusions understanding PCIe.
  I was previously working on some protocols like I2c,spi,uart,can and most of these protocols have well defined docs(a max of 300 pages).
  In almost all these protocols mentioned, from a software perspective, the application had to just write to a data register and the rest will be taken care by the hardware.
  Like for example, in Uart, we just load data into the data register and the data is sent out with a start, parity and stop bit.</p>
  
  <p>I have read a few things about PCIe online and here is the understanding i have so far.</p>
  
  <p>During system boot, the BIOS firmware will figure out the memory space required by the PCIe device by a magic write and read procedure to the BAR in the PCIe device(endpoint).
  Once it figures out that, it will allocate an address space for the device in the system memory map(no actual RAM is used in the HOST, memory resides only in the endpoint.The enpoint is memory mapped into the Host).
  I see that the PCIe has a few header fields that the BIOS firmware figures out during the bus enumeration phase.</p>
  
  <p>Now,if the Host wants to set a bit in a configuration register located at address 0x10000004(address mapped for the enpoint), the host would do something like(assume just 1 enpoint exists with no branches):</p>
  
  <pre><code>*(volatile uint32 *)0x10000004 |= (1&lt;&lt;Bit_pos);
  </code></pre>
  
  <p>1.How does the Root complex know where to direct these messages because the BAR is in the enpoint.
  Does the RC broadcast to all enpoints and then the enpoints each compare the address to the address programmed in BAR to see if it must accept it or not?(like an acceptence filter in CAN).</p>
  
  <ol start="2">
  <li><p>Does the RC add all the PCIe header related info(the host just writes to the address)?</p></li>
  <li><p>If Host writes to 0x10000004, will it write to register at location 0x4 in the endpoint?</p></li>
  <li><p>How does the host know the enpoint is given an address space starting from  0x10000000?</p></li>
  <li><p>Is the RC like a router?</p></li>
  </ol>
  
  <p>The above queries were related to, only if a config reg in the enpoint was needed to be read or written to.
  The following queries below are related to data transfer from the host to the enpoint.</p>
  
  <p>1.Suppose the host asks the enpoint to save a particular data present in the dram to a SSD,and since the SSD is conneted to the PCIe slot, will PCIe also perform DMA transfers?
  Like, are the special BAR in the enpoint that the host writes with a start address in the Dram that has to be moved to ssd, which in turn triggers the PCIe to perform a DMA tranfer from host to enpoint?</p>
  
  <p>I am trying to understand PCIe relative any other protocols i have worked on so far. This seems a bit new to me.</p>