In many PCIe training material, there is details walkthrough on how the BAR is being programmed. I think I probably can understand some portion of that, but somehow there is a missing pieces that I couldn't digest well.
System software must first determine the size and type of the address space requested by a device
Above is true as the host has no idea what is the required address space from the device initially. So, since the size of the address space need to be determined by the endpoint and supposed this piece of info will be passed over to the host through the first time configuration space read?
If above is correct, how is this information is passed over to the host initially? The explanation stated about uninitialized state of the BAR which mean initially the top 20 bits of the BAR is X. So I couldn't think of through what operation the required address space information is being passed over to the host?
Next, why the host still need to write 1 in the upper 20 bits during configuration space based on earlier given information from the device and later read it back to determine the targeted range of the memory space?
I'm not sure where do I start to get confuse, but the PCIe book I read does not explain how the endpoint device pass the targeted address space information to the host and I assume this info is residing in the same 4 byte BAR field. Although I'm very sure I mis-interpret something wrongly, so I hope at least someone can enlighten me the specific process how the endpoint device to pass over / advertise the targeted address space to host so that I can appreciate why there is a need of step to writing 1'b1 in the top 20 bits of the BAR field.
Still my question is if in the first place there is already have way for endpoint device to pass over the targeted address space info to the host, why there is still need a step to write number of 1 to the top 20 bits and later readback. Why can't directly based on the first configuration read info to the host and the host simply append the address offset to it which is the last step of the BAR programming?