From: Laszlo Ersek <lersek@redhat.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
"Ni, Ruiyu" <ruiyu.ni@intel.com>
Cc: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
Dong Wei <Dong.Wei@arm.com>,
Benjamin Herrenschmidt <benh@au1.ibm.com>,
Andrew Fish <afish@apple.com>
Subject: Re: [PATCH] MdeModulePkg/PciBusDxe: GetBarAttributes() returns Host address
Date: Tue, 12 Sep 2017 10:40:32 +0200 [thread overview]
Message-ID: <5f8f5a1b-a170-c20b-91e0-6e813faf0527@redhat.com> (raw)
In-Reply-To: <CAKv+Gu_N6pMNV2_mCB7BnmXPwbE2ce4ORyJseqZwGqmRuGq=6A@mail.gmail.com>
On 09/12/17 08:44, Ard Biesheuvel wrote:
> On 12 September 2017 at 06:01, Ni, Ruiyu <ruiyu.ni@intel.com> wrote:
>> Laszlo,
>> Your understanding is: DeviceAddress = HostAddress + AddressTranslationOffset
>> But my patch assumes: HostAddress = DeviceAddress + AddressTranslationOffset
>>
>> They are totally different. If I follow your understanding, the patch is wrong!
>> Since UEFI spec doesn't describe "apply to" in sentence " Offset to apply to the
>> Starting address of a BAR to convert it to a PCI address" very clearly, I quoted
>> the statement from ACPI spec.
>> Your understanding to "apply to" is "add", my understanding is "minus".
>>
>
> Even though we are stretching the ACPI definition of a QWord
> descriptor beyond its original meaning, I don't think there is a lot
> of ambiguity here, to be honest. The AddrRangeMin field contains the
> address on the secondary side of a bridge, and the primary value can
> be obtained by 'applying' the ATO. In my opinion, applying a (positive
> or negative) offset implies addition, not subtraction, as subtraction
> involves negating the second addend before applying it. And the
> secondary side of the host bridge is clearly the PCI side.
Wait, now I'm even more confused.
(1) Up-thread you wrote, "AddrRangeMin is indeed already defined to be a
host address [...]".
(2) Here you write, "the secondary side of the host bridge is clearly
the PCI side [...] The AddrRangeMin field contains the address on the
secondary side of a bridge". --> This means that AddrRangeMin is a PCI
address.
Thus, to me these statements appear to conflict.
> It does mean the offset field is signed, though.
>
> So I don't agree with the conclusion that no clarification is
> required. We need to make sure the spec is crystal clear in this
> regard. But I do agree with the change, I think it is the only
> solution that makes sense.
My understanding of "Table 121. QWORD Address Space Descriptor" is:
- AddrRangeMin --> host address.
- ATO --> the UINT64 value that the *caller* of GetBarAttributes() has
to add, in UINT64 modular arithmetic, to AddrRangeMin, to calculate
the PCI address, after GetBarAttributes() returns.
Now, if I understand the *patch* correctly,
- the current (pre-patch) code returns a PCI address in
"Descriptor->AddrRangeMin", which is wrong,
- in addition, we already have the ATO, in
"Descriptor->AddrTranslationOffset", that we have to add to the PCI
address, to end up with a host address.
If that's the case, then I think the patch is good, but it is
incomplete. Namely,
- To return a host address to the caller in "Descriptor->AddrRangeMin",
we add the ATO to it, fetched from the Root Bridge IO protocol. Great.
- However, think of what happens when the caller wants to recompute the
PCI address! According to the UEFI spec, the ATO that the caller gets
in the QWORD descriptor has to be *added* to AddrRangeMin. This means
that, the client code would ultimately result in:
ClientSidePciAddress == (OriginalPciAddress + OriginalATO) + OriginalATO
This makes no sense. In order to end up with the original PCI address,
the client side ATO must be the modular UINT64 *negative* of the
original ATO, so that they ultimately cancel out on the client side,
like this:
ClientSidePciAddress == (OriginalPciAddress + OriginalATO) + ClientSideATO
== (OriginalPciAddress + OriginalATO) + (-OriginalATO)
== OriginalPciAddress
Therefore, I think that the patch must, *in addition*, negate the ATO
before returning, like this:
+ Descriptor->AddrRangeMin += Descriptor->AddrTranslationOffset;
+ Descriptor->AddrTranslationOffset = (-Descriptor->AddrTranslationOffset);
Thanks
Laszlo
next prev parent reply other threads:[~2017-09-12 8:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-11 5:01 [PATCH] MdeModulePkg/PciBusDxe: GetBarAttributes() returns Host address Ruiyu Ni
2017-09-11 6:46 ` Laszlo Ersek
2017-09-12 4:32 ` Ard Biesheuvel
2017-09-12 5:01 ` Ni, Ruiyu
2017-09-12 6:44 ` Ard Biesheuvel
2017-09-12 8:40 ` Laszlo Ersek [this message]
2017-09-12 15:49 ` Ard Biesheuvel
2017-09-12 16:15 ` Laszlo Ersek
[not found] ` <1505259457.12628.157.camel@au1.ibm.com>
2017-09-13 3:07 ` Ni, Ruiyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5f8f5a1b-a170-c20b-91e0-6e813faf0527@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox