From patchwork Wed Oct 10 08:34:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 148541 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp570699lji; Wed, 10 Oct 2018 01:35:02 -0700 (PDT) X-Google-Smtp-Source: ACcGV637MQUMtc5Xn4dHlrDud7n+RkVMESuXgE9YRqfBDh/qUJsoEAM9pWlOvOtsAYLLGgodf2PQ X-Received: by 2002:a17:902:b696:: with SMTP id c22-v6mr16805412pls.37.1539160502093; Wed, 10 Oct 2018 01:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539160502; cv=none; d=google.com; s=arc-20160816; b=vRsD3GLEIos1AYmJugqbwDgGl1COscp0MGxUuPEipu7iihIazK8Qcaa+bfnyRG8a2T RsAbddJnQBPnvR+yYB7jMwD3ZBB+QGSstfOH7vgW0zrUU9lPgNedBGS3LHQb3d1bINY4 o/UmFm8eJx/iasFKlT3Qv7/1uqP8fAqAkhX5/8X/n54bvWqbVN0FQglA7JO3CJltTyLH VufzhQxLdmqnknwvrAQ6Vy0apj6Or8mOq3tZJnnEcom6wCwV4X+BtPkhoLnaQu7FgvC4 b2Hip6HV9JdeosvfcywsRmJ+wsgd4XmI9QD33hruQOJ2+H8uLZl/DMB69+qwpLxz4W+I Egag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=TboQ598l8xpn6xfN1xSgbwHFwLebkWQYHWHenI+pypI=; b=KOLieLmqhrrKpODxqdOb1SSfgqUeL0fdDShMaNR3RVzclQbw4Oy6EzO1zwIGREk5KR F38D4zp5R1QX1vrAEbEjBUUnnHHxMnpH4YSjJE964Bn2bwBsjXL8TJQnA/eo/NnvA/Ar ypt+6uqIGfhIt0GDg960sKzU8ZdbMsbw9LBApSoiqnddFTuzOdFGiwZfJ2aTFoCYu5oI L3JAUcPUdzLwoULBaq2OcgOSCmb1YB+rYdryROJxRRYtGj4MxPBMvJ2MCwu6DiaNzlGU S3e7FP1qXJaJxZMyC9C/8TMrZaNUpEay+d0X/4XdjUXebG5O62SWP8ULv8sNiZG8gQS7 4u6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="diEac/Q1"; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id g7-v6si25059675plb.167.2018.10.10.01.35.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 01:35:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="diEac/Q1"; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 140E721A09130; Wed, 10 Oct 2018 01:35:01 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org 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-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 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: [edk2] [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: , Cc: star.zeng@intel.com MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 2.19.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Star Zeng Signed-off-by: Ard Biesheuvel Tested-by: Marcin Wojtas 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; /**