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::442; helo=mail-wr1-x442.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (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 1C00F21162CD9 for ; Wed, 10 Oct 2018 01:34:58 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id a13-v6so4687371wrt.5 for ; Wed, 10 Oct 2018 01:34:58 -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=64RDxXjaE5+cRKi/x81cSfgBF+6hR+RJU8C8p8xQHwg=; b=diEac/Q1h389Ded2DHH8g61PJYX3aJQEVPVtd0kGFVmkJIQz31qcfH/GRdmogw0rY/ Aly7sCsommyB9bRVoheMPpB7kcYlaU3kERlN5Mcb1LFjFowBFO/TNNQhOQpJsalbeDbt MoMlyKOL6rK5B/TdRu8x5/G7lJpiPa9lIOvvQ= 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=64RDxXjaE5+cRKi/x81cSfgBF+6hR+RJU8C8p8xQHwg=; b=aljy6ex3rHsDyLBsmajfGT6z5hh8UY0zofiPKFvAfy0AJRSbcuYdghL3jyzw+Cid/o k1c24iRG/PbBDjUKMydlUc56zQrdgfo2tsvKymbVUToHxXI0YYu//f+4ldUgs+OSst/h AngvXsDywXn0lOFwWpZjoxXmjdZcRSmTpx8zlXu6hvo1YnISjuylYgatMK5ttzh9Ks7D rHxaQbBbkIQRDeVGOKluxCabyYlCLAWZkCz3QDw4FdjvKJ6oKXx4C98YeE24y/SzFaxI xgIqA0X9ABrJZ6Kq2aiYidt5YjRx7eyeiM3AfG1HJv/5MPAmXBfPp5N4aRui6d9Q9uke fh0w== X-Gm-Message-State: ABuFfohPWsqiT5urYeFRSv67pErgtRH85JV0dtRMtevIosKum6cf5ciE xadw+UcphyTbhS8DtR9VqmmbHRUOEFc= X-Google-Smtp-Source: ACcGV62sVU8LqqozXZYB18PfgFuvfId6ZaPu+mKYwfmoWQDReyt51qLIMRfcyLSHb2ECUCWk4LME3Q== X-Received: by 2002:adf:8065:: with SMTP id 92-v6mr22330678wrk.23.1539160495439; Wed, 10 Oct 2018 01:34:55 -0700 (PDT) Received: from localhost.localdomain ([2a01:cb1d:112:6f00:e0b5:37c2:198:2e90]) by smtp.gmail.com with ESMTPSA id t82-v6sm16310044wme.30.2018.10.10.01.34.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 01:34:54 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: star.zeng@intel.com, mw@semihalf.com, Ard Biesheuvel Date: Wed, 10 Oct 2018 10:34:50 +0200 Message-Id: <20181010083450.22298-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 Subject: [PATCH v2] 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: Wed, 10 Oct 2018 08:34:59 -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 Tested-by: Marcin Wojtas --- v2: add sanity check on id value so we don't exceed 256 buses initialize counter to 0 explicitly - this isn't strictly necessary but clarifies the code MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c | 10 ++++++++++ MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c | 10 +++++++--- MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.h | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c index 3e9ff6620d8d..2483c7296912 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c @@ -16,6 +16,9 @@ #include +#define MAX_NON_DISCOVERABLE_PCI_DEVICE_ID (32 * 256) + +STATIC UINTN mUniqueIdCounter = 0; EFI_CPU_ARCH_PROTOCOL *mCpu; // @@ -141,6 +144,11 @@ NonDiscoverablePciDeviceStart ( NON_DISCOVERABLE_PCI_DEVICE *Dev; EFI_STATUS Status; + ASSERT (mUniqueIdCounter < MAX_NON_DISCOVERABLE_PCI_DEVICE_ID); + if (mUniqueIdCounter >= MAX_NON_DISCOVERABLE_PCI_DEVICE_ID) { + return EFI_OUT_OF_RESOURCES; + } + Dev = AllocateZeroPool (sizeof *Dev); if (Dev == NULL) { return EFI_OUT_OF_RESOURCES; @@ -167,6 +175,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.19.1