title: How to know or set a PCI/PCIe device address map?
body: <p>I'm trying to understand how to instruct the CPU to instruct a PCI device to map its memory to the physical address of the CPU.</p>
  
  <p>I've read <a href="https://wiki.osdev.org/PCI#Memory_Mapped_PCI_Configuration_Space_Access" rel="nofollow noreferrer">https://wiki.osdev.org/PCI#Memory_Mapped_PCI_Configuration_Space_Access</a> and I understand how to configure a PCI device through the IO ports of the CPU:</p>
  
  <blockquote>
    <p>Two 32-bit I/O locations are used, the first location (0xCF8) is named
    CONFIG_ADDRESS, and the second (0xCFC) is called CONFIG_DATA.
    CONFIG_ADDRESS specifies the configuration address that is required to
    be accesses, while accesses to CONFIG_DATA will actually generate the
    configuration access and will transfer the data to or from the
    CONFIG_DATA register.</p>
  </blockquote>
  
  <p>So in order to configure a PCI device I just need to put the configuration address that I want to configure and CONFIG_DATA is where I put the data. Both of these are I/O locations, so I ise I/O instructions in the CPU.</p>
  
  <p>These two I/O locations give me access to a 256byte "big register" that I can use to configure the PCI device. All the fields of this big register are described in the OSDEV page. These 2 bits are of interest:</p>
  
  <blockquote>
    <p>Memory Space - If set to 1 the device can respond to Memory Space
    accesses; otherwise, the device's response is disabled.</p>
    
    <p>I/O Space - If set to 1 the device can respond to I/O Space accesses;
    otherwise, the device's response is disabled.</p>
  </blockquote>
  
  <p>However apart from this, it's not clear on how to get or set the physical address space where each PCI device is going to respond </p>