From patchwork Tue Oct 9 14:01:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 148491 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp4941699lji; Tue, 9 Oct 2018 07:01:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV62/GAEmQgTX/P7yWFRvoULPhDg2HNQrYCQKKK313PtW6IxSuvKS+7asBC+Re5+0dk4/8Xj+ X-Received: by 2002:a62:8d16:: with SMTP id z22-v6mr30076012pfd.185.1539093704457; Tue, 09 Oct 2018 07:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539093704; cv=none; d=google.com; s=arc-20160816; b=yI+Kpr4r+5lvjP/Wzg8JL7Zz723ADV1GFaAEoGAQrym/Z74eFyq3gOCTkDBl/0MD+7 w/gIzPHNdS722UIb4mqqCTasAw41OBTLqP4IEL6YNIiZvvQxUZrNJyrOqvyI1PCeaFFF 1RL0RkqL1Gn6MaLbc9i1Kqf84H2W7zG7UeBIrbgw8v+6M6HLxsk2fNjQNIR6flHmsXDt U4ydSluBX5r7IwQwZLS1muueM2AA538DQUwLrKeFFWdoqnzqulanOZ0Uq9vDEsUjzU/T e3fFaoPEpQiVGEnAUsFni9PYcCJIQtB5T7jsjoM8MhkoKSor8MClm5BVju8Rx+c3SC8h 7QWw== 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=18HntNNi5Rnx33xZUNivLmtJVfcHTQ8v2YHFpEqlHzQ=; b=cjg9pl2qccy+EPoe/irkuuS2Bg8VvG0iJ6pLGc7Fb/9dGslwIfn1MERc+VkPxK52JH 9K/n+p9BXGeq4evKQAJIbKz9823BTJvayUt8MwWqvUdO9KQ2kw2kK7Wu4MRBafUvbQwR OX6Cp8m5eXimCfTL+cFMTEbJUBh3FXpsiE2qY7G3KIanE2af7UfUqmQKVdLqPcigwXsr 9zLImrhruT6zzaUkMF7/5rFUwc0XUPFB0MANGssh6zly2JhYTuatMGQQLFieitQmaksf z2IUu9cbIlGQiB96Qadjiawjsuzxrlf/OIrGQe+H/1edbLnxvh/3N7HyuUEWeImVubaN Uywg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="JjSWZ/kZ"; 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 k1-v6si22140574pld.424.2018.10.09.07.01.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 07:01:44 -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="JjSWZ/kZ"; 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 AB23221A07A92; Tue, 9 Oct 2018 07:01:43 -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::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-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 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: [edk2] [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: , Cc: ruiyu.ni@intel.com, 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 --- 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(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Tested-by: Marcin Wojtas Signed-off-by: Ard Biesheuvel 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; /**