Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the CPU know the PCI adress-space

I understand that PCI and PCIe devices can be configured by the CPU (via code in the BIOS or OS) to respond to certain physical memory addresses by writing to specific areas of the device's configuration space.
In fact the Linux kernel has quite the complicated algorithm for doing this taking into account a lot of requirements of the device (memory alignment, DMA capabilities etc).

Seeing that software seems to be in control of if, when and where this memory is mapped, my question is: How can a piece of software control mapping of physical memory?

After this configuration, the PCI device will know to respond to the given address range, but how does the CPU know that it should go on the PCI bus for those specific addresses that were just dynamically decided?

like image 937
Lifesworder Avatar asked Oct 27 '13 03:10

Lifesworder


2 Answers

The northbridge is programmed with the address range(s) that are to be routed to the memory controller(s). All other addresses go to the external bus.

like image 174
CL. Avatar answered Oct 12 '22 04:10

CL.


It is based on address mapping info that CPU had. normally you have 2^64 -1 address lines with CPU if it is 64 bit processor. Now memory is now around 16 GB which is 2^34 is around 16 GB. So all the devices which CPU has (even legacy PCI and PCIe devices) and their config space can be mapped to address line above this RAM physical address space. Any IO to this space can be forwarded to respective device. In our case CPU finds out that the config space which it wants to access to is a PCI or PCIe device then it forwards the instruction to host bridge of CPU (00:00:00 Do lspci in a box you will see the host bridge with this BDF)

Once it finds out the target device is within host bridge the instruction (Can be IO or Memory) will be converted to appropriate TLP request.

like image 27
Venfah Nazir Avatar answered Oct 12 '22 04:10

Venfah Nazir