From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 328DA21E8796F for ; Sun, 10 Sep 2017 23:43:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2226C0AF794; Mon, 11 Sep 2017 06:46:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F2226C0AF794 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-112.phx2.redhat.com [10.3.116.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36EB35E24D; Mon, 11 Sep 2017 06:46:39 +0000 (UTC) To: Ruiyu Ni , edk2-devel@lists.01.org Cc: Ard Biesheuvel , Benjamin Herrenschmidt , Andrew Fish , Dong Wei , Bartosz Szczepanek References: <20170911050121.85708-1-ruiyu.ni@intel.com> From: Laszlo Ersek Message-ID: <7fbd6e6b-0577-f470-3e89-f785ddd5dee1@redhat.com> Date: Mon, 11 Sep 2017 08:46:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170911050121.85708-1-ruiyu.ni@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 11 Sep 2017 06:46:41 +0000 (UTC) Subject: Re: [PATCH] MdeModulePkg/PciBusDxe: GetBarAttributes() returns Host address X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 06:43:46 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 09/11/17 07:01, Ruiyu Ni wrote: > Per the UEFI Spec, GetBarAttributes() should return the Host address. > But current implementation returns the address read from the BAR, > which is the Device address. > Per the description of AddressTranslationOffset in ACPI spec: > "For bridges that translate addresses across the bridge, this is the > offset that must be added to the address on the secondary side to > obtain the address on the primary side." The ACPI spec also says: "Non-bridge devices must list 0 for all Address Translation offset bits." However, the UEFI spec (v2.7) says, under EFI_PCI_IO_PROTOCOL.GetBarAttributes(): "The ACPI Specification does not define how to the use the Address Translation Offset for non-bridge devices. The UEFI Specification is extending the definition of Address Translation Offset to support systems that have different mapping for HostAddress and DeviceAddress. [...] Address Translation Offset. Offset to apply to the Starting address of a BAR to convert it to a PCI address. This value is zero unless the HostAddress and DeviceAddress for the BAR are different." So, I think the patch is correct, but the commit message should not refer to the ACPI spec. It should refer to / quote the UEFI spec only. > HostAddress = DeviceAddress + AddressTranslationOffset. The sentences from the UEFI spec are "Address Translation Offset. Offset to apply to the Starting address of a BAR to convert it to a PCI address", and "Address Range Minimum. Starting address of BAR." To me this seems to imply that AddrRangeMin is already a host address, and DeviceAddress = AddrRangeMin + AddressTranslationOffset > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ruiyu Ni > Cc: Ard Biesheuvel > Cc: Benjamin Herrenschmidt > Cc: Andrew Fish > Cc: Dong Wei > Cc: Laszlo Ersek > Cc: Bartosz Szczepanek > --- > MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c > index cc7125e4fc..852d35d710 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c > @@ -1955,7 +1955,7 @@ PciIoGetBarAttributes ( > End->Checksum = 0; > > // > - // Get the Address Translation Offset > + // Get the Address Translation Offset and convert the Device address to Host address. > // > if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) { > Descriptor->AddrTranslationOffset = GetMmioAddressTranslationOffset ( > @@ -1967,6 +1967,7 @@ PciIoGetBarAttributes ( > FreePool (Descriptor); > return EFI_UNSUPPORTED; > } > + Descriptor->AddrRangeMin += Descriptor->AddrTranslationOffset; > } > } > > Actually, let me circle back to the initial problem here (apologies if it's too late for that) -- why are we adding the offset inside the GetBarAttributes() function? Isn't it the caller's responsibility to do the addition after GetBarAttributes() returns? I mean if a PCI driver author reads the UEFI 2.7 spec, the spec seems to give that impression. (I'm sorry if I should have raised these questions last week -- I don't wish to block this patch. Please go ahead if I'm wrong.) Thanks Laszlo