<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">void pciauto_region_align(struct pci_region *res, unsigned long size)</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">{</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman"><span> </span>res->bus_lower = ((res->bus_lower - 1) | (size - 1)) + 1;</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">}</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman"> </font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">The above function is to do address align with size.</font></span></p>
<div style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman"> </font></span></div>
<div style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">Belows is my explanation with example:</font></span></div>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">According to PCI specification, size must be the power of 2, </font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">assume Size is 0x100, then size-1 = 0xFF;</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">(res->bus_lower - 1) | (size - 1) = 0x??????FF;</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">((res->bus_lower - 1) | (size - 1)) + 1=0x??????00;</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">So, the result is aligned with size of 0x100.</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman"> </font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">Now let analyse "res->bus_lower", we must divide it into two aspects:</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt"><font face="Times New Roman"><span lang="EN-US"><span>1.<span><font size="3"> </font></span></span></span><span lang="EN-US">res->bus_lower = 0x??????0?</span>
</font></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">because or operate with 0x??????FF, substracting 1 is not important.</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt"><font face="Times New Roman"><span lang="EN-US"><span>2.<span><font size="3"> </font></span></span></span><span lang="EN-US">res->bus_lower = 0x??????00</span>
</font></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">Obviously, the address is aligned with size of 0x100, so doing substract 1 is necessary,</font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman">then the result of ((res->bus_lower - 1) | (size - 1)) + 1<span> </span>is the same with the original value of res->bus_lower. </font>
</span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman"> </font></span></p>
<p style="MARGIN: 0cm 0cm 0pt"><span lang="EN-US"><font face="Times New Roman"> </font></span></p>