From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::342; helo=mail-wm1-x342.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E9E6121164898 for ; Tue, 9 Oct 2018 07:01:41 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id a8-v6so2121055wmf.1 for ; Tue, 09 Oct 2018 07:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=pFhBWk5fDrnnCsNT4Kzs5eF8uaU+ZBaKyhvFYIWAZ8w=; b=JjSWZ/kZu9gZf2VeoJoVi+7HEdl94VPb7TMxSMqFGCTsb3LFK9KcnyGItJXikl96VJ RYENGXGOaAXwwijFx3/m7XZ7aRbUw7bHrmlzsPSusO6U7KMRIC8bjRxhcF3EZs8iXPHr q6ebjgfDwJcxhTZQ7k3IFv+gWuvF8b17+7fw4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pFhBWk5fDrnnCsNT4Kzs5eF8uaU+ZBaKyhvFYIWAZ8w=; b=Y6rVQdsPIP7pnauKTZs6UTbAXRRs3e1BLm+pHklZMGNnIwdgyPokebDwfI3TccPKWP SX7cUMusBCsuq5rDdozwjsk4gIqCKiTwlZNBBwaxUHAzTuG3H+MgyJAmSdatTec1/QxC SZ6XvAeqwU1BvI4Wzhg+KIdW91iI8EjARcqBc4JWhpirQq9iHddgjsRdC6yQeFe46tVo CTs47CV3WRrJMfYA6UZWWRM3FgX9XHCG4woJTyb6+EwtPTCOTw1NUu8CTXV8kcMAMQ1t yjqmbo3+Rs27o+h2GtPoxCEH9+dfKFlkhp/I/fd+593/XVfisW5Ccrxn0uUaHdC+W1JW BgIg== X-Gm-Message-State: ABuFfog5jzWNxqWVtVcL/9SesydOXQDxLsJDjf7E5LTL1UngD3bEuXpo lAAgfNO6lnj5R1KMNH7VreJs1lAoD0A= X-Google-Smtp-Source: ACcGV63l8oztW6nI5lkbAQzmN3UP7SGGbSWx7xa29jAarjJrMI/WHj6uog+u0iVu5HmhaiZjBe3kqg== X-Received: by 2002:a1c:4406:: with SMTP id r6-v6mr2195483wma.4.1539093699117; Tue, 09 Oct 2018 07:01:39 -0700 (PDT) Received: from localhost.localdomain ([92.154.90.120]) by smtp.gmail.com with ESMTPSA id s132-v6sm7123596wme.14.2018.10.09.07.01.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 07:01:38 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, mw@semihalf.com, star.zeng@intel.com, ruiyu.ni@intel.com, Ard Biesheuvel Date: Tue, 9 Oct 2018 16:01:28 +0200 Message-Id: <20181009140128.21378-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Subject: [PATCH] MdeModulePkg/NonDiscoverablePciDeviceDxe: expose unique B/D/F identifiers X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2018 14:01:42 -0000 Currently, the implementation of EFI_PCI_IO_PROTOCOL::GetLocation() in NonDiscoverablePciDeviceDxe returns the same set of dummy values for each instance of the NON_DISCOVERABLE_DEVICE protocol that it attaches itself to. However, this turns out to be causing problems in cases where software (such as the ARM Compliance Test Suite [ACS]) attempts to use these values to uniquely identify controllers, since the collisions create ambiguity in this regard. So let's modify GetLocation() to return an arbitrary bus/device tuple on segment 0xff instead. This is guaranteed not to clash with other non-discoverable PCI devices, and highly unlikely to clash with real PCIe devices. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c | 4 ++++ MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c | 10 +++++++--- MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c index 3e9ff6620d8d..ed5256f3c7ea 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c @@ -18,6 +18,8 @@ EFI_CPU_ARCH_PROTOCOL *mCpu; +STATIC UINTN mUniqueIdCounter; + // // We only support the following device types // @@ -167,6 +169,8 @@ NonDiscoverablePciDeviceStart ( goto CloseProtocol; } + Dev->UniqueId = mUniqueIdCounter++; + return EFI_SUCCESS; CloseProtocol: diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c index 0e42ae4bf6ec..58cb5d8b1fc5 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c @@ -1181,6 +1181,8 @@ PciIoGetLocation ( OUT UINTN *FunctionNumber ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + if (SegmentNumber == NULL || BusNumber == NULL || DeviceNumber == NULL || @@ -1188,9 +1190,11 @@ PciIoGetLocation ( return EFI_INVALID_PARAMETER; } - *SegmentNumber = 0; - *BusNumber = 0xff; - *DeviceNumber = 0; + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + *SegmentNumber = 0xff; + *BusNumber = Dev->UniqueId >> 5; + *DeviceNumber = Dev->UniqueId & 0x1f; *FunctionNumber = 0; return EFI_SUCCESS; diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h index e641189267ee..5b4c57fa2a8e 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h @@ -100,6 +100,12 @@ typedef struct { // on behalf of this device // LIST_ENTRY UncachedAllocationList; + // + // Unique ID for this device instance: needed so that we can report unique + // segment/bus/device number for each device instance. Note that this number + // may change when disconnecting/reconnecting the driver. + // + UINTN UniqueId; } NON_DISCOVERABLE_PCI_DEVICE; /** -- 2.17.1