From patchwork Thu Mar 15 06:03:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 131746 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp703105ljb; Wed, 14 Mar 2018 23:05:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELukhPoZuKgkZ+Ox8n+3WPa6TRDWjpTaxBAQn9Vs/ICBS2vYFWIr5JRJ6/85wdjzZkOEsq82 X-Received: by 10.98.36.25 with SMTP id r25mr6775375pfj.106.1521093915847; Wed, 14 Mar 2018 23:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521093915; cv=none; d=google.com; s=arc-20160816; b=e/WVp/9ziTfp8M8tIlk+1dd2ljzUdSx/ll+Uay1ujQJ5xtrSQXMYukMp9nfu5fXZGw oz2qoKyHY4cmCey+Pa5NFCM2Q+kACpTXoBhv/Ze3MHA8NsImOYE75Q/xR2/S95r/AGk9 BPmHgodQtshOfE6R7Ub9Z5CqRUkv20Om8pnlpQLAxFBVswUq12ce3abXu+EQlKanTBHI nv9Hn1Uk9qUDemAtMUQ/YGFM8qc0kD5iGMjFgOqGj70uBsPvHWPKP1tCW+J7DPLRnhrZ TWXNUG8ex+8UzP2zVk0tYzmp2bwKJ9DcxBnrlcUkeTh21wFVQodN4EKLje5pteMiiCmv xofA== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=L9cLuPJEGb34CT4P3wsULrF8TK677eba4LerW3bgot4=; b=KS2nTe5xC/n60Nkg8KcvHWvcwNkIdfNlQa90e625F+bQlpsmOWMOyUf+oMEYKyNX1k LOkd2Bwtie7sjqHu2bS42JqKC3yUjM0+eyw1A0nml4oEs1Znw8xZ9lYfiOsOArWRQdyL at2hjOge2Bn6Hk5KxPdki/+k6VrWj9sOfjBJLcT2MuKFmh+hocWMvF6WfqpOO6L+Y20O 1PJaJNegFiVa/ODQ/g326oawxKqZuGZoPVaIUrfFSh1ldXBh0TrFcMiwu19UCNtl3ADc sCjQrWpcMSNmqG7twNaJMQMp2MvRIjbN/2FVOCdv2ehZM3qYQNKTYpsi6859ibx99DGQ JezQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=elqpovMX; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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. [198.145.21.10]) by mx.google.com with ESMTPS id e10si3025944pgf.45.2018.03.14.23.05.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 23:05:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=elqpovMX; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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 6B3E52202E4A6; Wed, 14 Mar 2018 22:58:50 -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=2607:f8b0:400e:c01::22d; helo=mail-pl0-x22d.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl0-x22d.google.com (mail-pl0-x22d.google.com [IPv6:2607:f8b0:400e:c01::22d]) (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 B41F321E08283 for ; Wed, 14 Mar 2018 22:58:49 -0700 (PDT) Received: by mail-pl0-x22d.google.com with SMTP id f5-v6so3142062plj.13 for ; Wed, 14 Mar 2018 23:05:13 -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:in-reply-to:references; bh=OPK4RhszyeDXlSWyJKEN5VmhDTYCS7ksK+BmbF4IegM=; b=elqpovMXRk3it3d88haNHNAnUPu6vxLsy1Xap/EUClVVppSB43BR0nlu3iO46HsaHA zpakXP2ITcZLyIm2vA+PbCS2JYkQ1FCIQ2EJHgm+JII9VjufOQrYr0AjzDQGgHMr/Rwz 7f2daSxkzE+/7UdxzvpKcL0ve6g95+9qmuD2I= 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:in-reply-to :references; bh=OPK4RhszyeDXlSWyJKEN5VmhDTYCS7ksK+BmbF4IegM=; b=HYr9dPQHK/tIKo04NGdLnTRwRUeoKFPg9N/BMSoCvc+OQzird2V/UUWbLp3WmZLf50 9lmzHE7Vd+c9LQfUxQRMHaNqJ7vK4SiML0a5wPmD1LRLiK3dJWx0aeSAOnyhvm3p5Sso hPqy9O3cIgJtPGu8omJNqr7USJdHX5JZVmS/1l9DpXYu3o5/jHGegCMatz90VZFKAgsv exiNgUrzsuY2nzvqkWWq0BOg21wLKdVjDkGR+FU3xad2EWD7qw1uiapxpLpwNcnvl1Hv 4QYuWOS0uG8+IvuJpmSorj+4esA6EIap/ETgw8D55yNKZym8k0DgWKQY2thDWlwc13Sj coAg== X-Gm-Message-State: AElRT7Hein0tw0tEpxIJOPS5BnDmGLLST38BDjT08sI/mMH7ppnrHnww t5d8QxQLb7aTOlIPF9btFu+zz/Dz13M= X-Received: by 2002:a17:902:4025:: with SMTP id b34-v6mr6861453pld.359.1521093913002; Wed, 14 Mar 2018 23:05:13 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.100]) by smtp.gmail.com with ESMTPSA id 70sm7436192pgb.86.2018.03.14.23.05.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 23:05:12 -0700 (PDT) From: Heyi Guo To: edk2-devel@lists.01.org Date: Thu, 15 Mar 2018 14:03:58 +0800 Message-Id: <1521093843-48615-2-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> References: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> Subject: [edk2] [PATCH v7 1/6] CorebootPayloadPkg/PciHostBridgeLib: clear aperture vars for (re)init X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Yi Li , Ard Biesheuvel , Heyi Guo , Laszlo Ersek , Prince Agyeman MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Use ZeroMem() to initialize (or re-initialize) all fields in temporary PCI_ROOT_BRIDGE_APERTURE variables to zero. This is not mandatory but helpful for future extension: when we add new fields to PCI_ROOT_BRIDGE_APERTURE and the default value of these fields can safely be zero, this code will not suffer from an additional change. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Signed-off-by: Yi Li Reviewed-by: Ni Ruiyu Cc: Maurice Ma Cc: Prince Agyeman Cc: Benjamin You Cc: Ruiyu Ni Cc: Laszlo Ersek Cc: Ard Biesheuvel --- Notes: v6: - Move ZeroMem() into the loop just as Laszlo commented on OvmfPkg [Laszlo] - Minor changes in commit message CorebootPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Benjamin You diff --git a/CorebootPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c b/CorebootPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c index 6d94ff72c956..18dcbafdf0c6 100644 --- a/CorebootPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c +++ b/CorebootPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c @@ -328,8 +328,13 @@ ScanForRootBridges ( for (PrimaryBus = 0; PrimaryBus <= PCI_MAX_BUS; PrimaryBus = SubBus + 1) { SubBus = PrimaryBus; Attributes = 0; + + ZeroMem (&Io, sizeof (Io)); + ZeroMem (&Mem, sizeof (Mem)); + ZeroMem (&MemAbove4G, sizeof (MemAbove4G)); + ZeroMem (&PMem, sizeof (PMem)); + ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G)); Io.Base = Mem.Base = MemAbove4G.Base = PMem.Base = PMemAbove4G.Base = MAX_UINT64; - Io.Limit = Mem.Limit = MemAbove4G.Limit = PMem.Limit = PMemAbove4G.Limit = 0; // // Scan all the PCI devices on the primary bus of the PCI root bridge // From patchwork Thu Mar 15 06:03:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 131747 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp703142ljb; Wed, 14 Mar 2018 23:05:18 -0700 (PDT) X-Google-Smtp-Source: AG47ELsc4DcPtTbcg7Bup+mNBqLgov5UjCnVbZDaLvUhJhtEBomwO1lq4n3y12DqNKVMzLTEbPlr X-Received: by 2002:a17:902:8ec4:: with SMTP id x4-v6mr6733869plo.402.1521093918115; Wed, 14 Mar 2018 23:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521093918; cv=none; d=google.com; s=arc-20160816; b=N98/udRtPl7rAaHveagqEDPrrA3MzsHOHJtPb1n04Wut0voFGDPuMHzgO9K1b1kzfa XH1zEsjt6XtWw23jUQaCyQmAVJRu77+yE2B5GGMaEKkKNnQfHL0GPCMX1gCjZImRWYbj knQtyiny2Z2oXdkYjH89JO2kSxITeefOhpuuEWTjtFRIELpn5xCXQy1bzsKVtOUo8DNn aLiEklsWYrOtVX5NV+WCHw/m6YgFi5iORaSX3WDg6KU4dBaxzSz5v5bgMMbnZ/SYQb2t cC+aP7sOF46r6HAU/bP4Fd95cC5cQ9Sq3uW1UPtFwliu1MdoSZn3xh4IfuhTBYtI7jR6 uqDQ== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=IvWQ8NuAWIDlBskc5gYTVcUIUE39wrsy1XKeDQWg/9U=; b=asG5BrP2BDvr/J0YfVKfR10za7Fw75LZqqFX4hoX3VztE1m0vx9LObz66eAvSW1qyN NLdI6P8d2ENuvx0Ix2IIv9SeyMRCPRR1CH23nfbfroHRwkHcUUXEnI76hEQu9dkhk0iv 6A2Uv/y0s/LpRpHNmWlM9IGMYsH/KqasKG+vz0cNBmYQre974Mqk7OcNEr0kiVkQXcgt 9U9DtOjHub2LfTuz0uEBQSjC+NyPYrNgFb2hC1W7IVqVn+R2JNYo9vDr8y0wVitn+EfH wp6WQneR9yGCAJmQHO16z5p7R2MypxhQMUIwNqsJNmxrKogS5F6K6mI5uqw4YFC+ZfAZ l27w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Q0yEyNqB; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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. [198.145.21.10]) by mx.google.com with ESMTPS id k4-v6si3348916plt.255.2018.03.14.23.05.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 23:05:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Q0yEyNqB; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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 D0FF12202E49E; Wed, 14 Mar 2018 22:58:53 -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=2607:f8b0:400e:c01::22a; helo=mail-pl0-x22a.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl0-x22a.google.com (mail-pl0-x22a.google.com [IPv6:2607:f8b0:400e:c01::22a]) (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 4E54821E08283 for ; Wed, 14 Mar 2018 22:58:52 -0700 (PDT) Received: by mail-pl0-x22a.google.com with SMTP id u13-v6so3171868plq.1 for ; Wed, 14 Mar 2018 23:05:16 -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:in-reply-to:references; bh=x1PIFmRa9L5EHuOxCczQBXiPyyouN19MpWKAKHjHilA=; b=Q0yEyNqBduANfhEtu1BqHtsLCEjilMsAmggfNsmwL+mGhFtaKS2n1DiemKDKsHYPXr diac/5KtX54g1ddUEm/3Rtru/CF86JnTAMyRuUsQObtagBC7o9+fuEQEPHm/eRy9jgom f422QbLTnMNMk1Z9cPg5S32Q1UISWfl5nYx2g= 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:in-reply-to :references; bh=x1PIFmRa9L5EHuOxCczQBXiPyyouN19MpWKAKHjHilA=; b=dN+diy5StJPuN7feHfZpHyJn3aKxmcFq7lzxCnFqIvb6HaLl9WuzOKB7PhH4VLiZxz /K9xLh2FjqUB0yd8WKnKc7TtEBhrdWNRkmG6Qv/eifRqm8r73CpB6HS1GR6KNqGZ2+ph Fycj0r1r3/2zi+f6i2dvbn5r6cU3aQ6IIufjMys3mPC8qIZyyVGiuTdqRZtNXH3duQ9d VMicmqhd9rzhB6DjzmtIPLk5GE4xSFCyokdCqCOVEPuXjuEgFMSmJUlzr8CyPeBFpwEW lnb5/nfSdIbu8/L7JMdqyA76KVL2sH1nmqC/MFv890FBL3iEB2e2iwwuYuJT/wtXTQJD J+vQ== X-Gm-Message-State: AElRT7EjO+lXg6dkqvAXxf0fRFgpUD/HVDayAXBVnMvur87gFcKU9+Uj 5q5dy07bk5hNlVwasKTPBavaVFx03YQ= X-Received: by 2002:a17:902:9307:: with SMTP id bc7-v6mr6725937plb.29.1521093915557; Wed, 14 Mar 2018 23:05:15 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.100]) by smtp.gmail.com with ESMTPSA id 70sm7436192pgb.86.2018.03.14.23.05.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 23:05:15 -0700 (PDT) From: Heyi Guo To: edk2-devel@lists.01.org Date: Thu, 15 Mar 2018 14:03:59 +0800 Message-Id: <1521093843-48615-3-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> References: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> Subject: [edk2] [PATCH v7 2/6] OvmfPkg/PciHostBridgeLib: clear PCI aperture vars for (re)init X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Yi Li , Ard Biesheuvel , Jordan Justen , Heyi Guo , Anthony Perard , Laszlo Ersek MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Use ZeroMem() to initialize (or re-initialize) all fields in temporary PCI_ROOT_BRIDGE_APERTURE variables to zero. This is not mandatory but is helpful for future extension: when we add new fields to PCI_ROOT_BRIDGE_APERTURE and the default value of these fields can safely be zero, this code will not suffer from an additional change. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Signed-off-by: Yi Li Reviewed-by: Ni Ruiyu Cc: Jordan Justen Cc: Anthony Perard Cc: Julien Grall Cc: Ruiyu Ni Cc: Laszlo Ersek Cc: Ard Biesheuvel --- Notes: v6: - Move ZeroMem() into the loop [Laszlo] - Move ZeroMem() after checking PcdPciDisableBusEnumeration [Laszlo] - Commit title change (However 74 characters will cause PatchCheck warning, so I tried to reduce the length to eliminate the warning) [laszlo] - Minor changes in commit message OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 4 ++++ OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c index ff837035caff..65d0ef9252c5 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c +++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -221,6 +221,10 @@ PciHostBridgeGetRootBridges ( return ScanForRootBridges (Count); } + ZeroMem (&Io, sizeof (Io)); + ZeroMem (&Mem, sizeof (Mem)); + ZeroMem (&MemAbove4G, sizeof (MemAbove4G)); + Attributes = EFI_PCI_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_ATTRIBUTE_ISA_IO_16 | diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c index 31c63ae19e0a..920417950ad9 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c @@ -202,8 +202,13 @@ ScanForRootBridges ( for (PrimaryBus = 0; PrimaryBus <= PCI_MAX_BUS; PrimaryBus = SubBus + 1) { SubBus = PrimaryBus; Attributes = 0; + + ZeroMem (&Io, sizeof (Io)); + ZeroMem (&Mem, sizeof (Mem)); + ZeroMem (&MemAbove4G, sizeof (MemAbove4G)); + ZeroMem (&PMem, sizeof (PMem)); + ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G)); Io.Base = Mem.Base = MemAbove4G.Base = PMem.Base = PMemAbove4G.Base = MAX_UINT64; - Io.Limit = Mem.Limit = MemAbove4G.Limit = PMem.Limit = PMemAbove4G.Limit = 0; // // Scan all the PCI devices on the primary bus of the PCI root bridge // From patchwork Thu Mar 15 06:04:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 131748 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp703179ljb; Wed, 14 Mar 2018 23:05:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELvw68V4M9saL3bXk7NGYwgwxfMxDmDY1F3HfA568uHoFnCHRmqRKr3QxTkho9yu0BNn/jM8 X-Received: by 10.101.96.141 with SMTP id t13mr5940842pgu.427.1521093920518; Wed, 14 Mar 2018 23:05:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521093920; cv=none; d=google.com; s=arc-20160816; b=JeEvU68el++fDJd1GvTcFkiD1AMSSy+8zVX+yLp5nAnIVQzaXETDL36qQY90DDTDgH DSpZzQ8q9jKRAyJjQHr7NX5r7M1gTIRUqw6oDNZrX4DMJu9xtaUHwlFNK74C3xnLPYew 4PcLXtC1IcF5cARn4nhoQDuCwwRyo7ogLNstNFJhh8VHN+jplR532NjVOubjECkUeD8E uLYa/pXAEb0c9N22jcNgPBxte8ajeQxxsT3ReHIazIpsn2f1zmf6n2GQWhFI5aTOdBh3 /sUs264mM3+J+iI+CNRPPO8Xa8pe8HdY2HRTDU5PegFhpQuPu5GDNvxcjmocJMUGVKv2 GpJw== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=BZjB6yxIXxaf5mnPnYKlA2dXf6iMhuD69nU3aA4Rtl8=; b=yArSCaOplwpkZtfuSrmoaU0f2oxhJW2GJQa/AKmH+4j7t4NboVROpL16WffB7k2NCN tiku0nsyKNOdUGJz5irgRDgkBfXJeL+vUzFxk0JGjPV2rmC8RIM/INo1ojMZhsWnEjEO 1XVkFDFXdRMQwZJhbxJYy7+lxgt71hRuOwDe5y/Znu6wPxHmIDB8lV4oHx2Jo35EGeGU b+K50idCKuBS8R8CfpzZwe/W1UDe8gQThAKah7bDRwhyA2epUlsdBkLfvpggmV/lxCBx E8xR6/IOp2D1lK4QbHlgANOigpkwM018Djrr1M17OmZLXLw4+eBY8RATngWXZwyo3uRa by6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=S6zV2R5g; 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 g9si3271906pfi.310.2018.03.14.23.05.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 23:05:20 -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=S6zV2R5g; 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 40C402202E4B1; Wed, 14 Mar 2018 22:58:56 -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=2607:f8b0:400e:c01::241; helo=mail-pl0-x241.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::241]) (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 AEDBF21E08283 for ; Wed, 14 Mar 2018 22:58:54 -0700 (PDT) Received: by mail-pl0-x241.google.com with SMTP id u13-v6so3171904plq.1 for ; Wed, 14 Mar 2018 23:05:18 -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:in-reply-to:references; bh=33f0/vbuAnA/bRbJS0DhfcvbaWajDYS11I220APWgI0=; b=S6zV2R5gDFkt83eTLw1EsMca0e3h2uqkOAqQ4g9Y2xscYKk8hFKnqckDcmJJPqNXg5 VT7zUPtKwrOqVdcVevdkV0rFGcdNEpPTMwX23NOf/w4hlXjtFcJrARVycWncsI2y0o7g LBYE7+qwr94gH2Ha6w/uLNDZ7NwkGKqkCd+hM= 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:in-reply-to :references; bh=33f0/vbuAnA/bRbJS0DhfcvbaWajDYS11I220APWgI0=; b=HJDPtCp4FBKqCTXZCdd5cVTBwneZdTgztxXx9mbiaOB9r5dd+W1bZRGjs8I9XZ2PZT sbWHOIi0PfszUfHAcay0Ct5rUlaF3Gr++5gUJyeW0uCED7R6VUvAxAWkhcLVwT2JuHd5 oh/1yxl9ecflYx+QFxOm1J2OLt2G1zhlcqP9yXmc3QzqdLHllW6oSdLq8yxbJSv8l/kN NP+l2VRrPElEhT5EXDVXgP1HkXN9FfCa7ttSqQ2WadO9gx2/PzwTrkhszwiKoOe7Qod1 l6B8HaBbvxL+doR485pg8AyAiyix2Nzm0bcI1wHTROnU+oTDiYrIxNANCI0SRJS0aGub HffQ== X-Gm-Message-State: AElRT7HuHEp2JuXR5Mit9t3HOUakE6Cv/9C8kWw8x98/Tec7XUS5ulVX 4LQQ+SuuAYSDwOFX2k9T8Vpsz0udmy8= X-Received: by 2002:a17:902:5a0b:: with SMTP id q11-v6mr6929070pli.199.1521093918048; Wed, 14 Mar 2018 23:05:18 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.100]) by smtp.gmail.com with ESMTPSA id 70sm7436192pgb.86.2018.03.14.23.05.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 23:05:17 -0700 (PDT) From: Heyi Guo To: edk2-devel@lists.01.org Date: Thu, 15 Mar 2018 14:04:00 +0800 Message-Id: <1521093843-48615-4-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> References: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> Subject: [edk2] [PATCH v7 3/6] MdeModulePkg/PciHostBridgeLib.h: add address Translation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Yi Li , Eric Dong , Ard Biesheuvel , Heyi Guo , Michael D Kinney , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Add Translation field to PCI_ROOT_BRIDGE_APERTURE. Translation is used to represent the difference between device address and host address, if they are not the same on some platforms. In UEFI 2.7, "Address Translation Offset" is "Offset to apply to the Starting address to convert it to a PCI address". This means: Translation = device address - host address So we also use the above calculation for this Translation field to keep consistent. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Signed-off-by: Yi Li Reviewed-by: Ni Ruiyu Cc: Ruiyu Ni Cc: Ard Biesheuvel Cc: Star Zeng Cc: Eric Dong Cc: Laszlo Ersek Cc: Michael D Kinney --- MdeModulePkg/Include/Library/PciHostBridgeLib.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Include/Library/PciHostBridgeLib.h b/MdeModulePkg/Include/Library/PciHostBridgeLib.h index d42e9ecdd763..18963a0d3821 100644 --- a/MdeModulePkg/Include/Library/PciHostBridgeLib.h +++ b/MdeModulePkg/Include/Library/PciHostBridgeLib.h @@ -20,8 +20,27 @@ // (Base > Limit) indicates an aperture is not available. // typedef struct { + // + // Base and Limit are the device address instead of host address when + // Translation is not zero + // UINT64 Base; UINT64 Limit; + // + // According to UEFI 2.7, Device Address = Host Address + Translation, + // so Translation = Device Address - Host Address. + // On platforms where Translation is not zero, the subtraction is probably to + // be performed with UINT64 wrap-around semantics, for we may translate an + // above-4G host address into a below-4G device address for legacy PCIe device + // compatibility. + // + // NOTE: The alignment of Translation is required to be larger than any BAR + // alignment in the same root bridge, so that the same alignment can be + // applied to both device address and host address, which simplifies the + // situation and makes the current resource allocation code in generic PCI + // host bridge driver still work. + // + UINT64 Translation; } PCI_ROOT_BRIDGE_APERTURE; typedef struct { From patchwork Thu Mar 15 06:04:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 131749 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp703219ljb; Wed, 14 Mar 2018 23:05:24 -0700 (PDT) X-Google-Smtp-Source: AG47ELsD9QIXn36XcipboQX2hD6svZaML5vpdcr5baKd+3XCOmHqNvgnb3aXH6xqmOB9UNbc+/ea X-Received: by 10.98.76.155 with SMTP id e27mr5172357pfj.45.1521093923987; Wed, 14 Mar 2018 23:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521093923; cv=none; d=google.com; s=arc-20160816; b=c8wtL9WOwIH0uveD5cgw/q8aWAMPlthncE7LfoZue4gri3WPY05JwFdK+DoRf7c97q CxfSx7MRjM5u7f+G566uMlC/u/6O9ae34KqbJd+1CVhYKCJtAsolnbycr9eGH3YmwNhw Qvw//AiABVSx/gUIXXOSMJWfFfn66hAzF+lf6Q2Tya+CIpkC1iZ/GGH5HyuPIPxtAH80 0kEWAVRfjlpmrhTP20Cx+D0nZx2BokIFptiICnGCum8KRWQEN/C8QCMnXNUcYe8KgDou RcK+beegVpqkdYwcvjqMcbFvowwDOHTM9p0VRT+MHgLxJ7yq3Xe63cqiv3cT5udJDM4U qHZw== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=LcXpeZdUTqyZcfYgcQqPmEoQl7W+njMteJI1MMa/DA0=; b=TlUFVqe2AxjmasOiCE2qw0FvzrhBodeL9EhFZlmHxA2uJnoLWKF5rZ/1nxhGz02V9x jibzebH1x9g3NButq6a6BoGAXauenayikfBBs/9imO3/A3eqqTVzWxamHri40AtiG81l DHRcbqTA0W9eDX7n2AEAHBbJr3h8eyuL77g6fhT0mJGm25tDeZrjm881dYBJ9pDRJjzg wUNxiW6LbZwBNikcoNReq+5zjfDEXtZLBlYzqwPz57u4V1sNufdiTEC29Aktj9I4GXQq kPiZSVdXTG3qnhjIcgAw+ttDMjlzOCCwxRy5mNfsTCiqYH5+7eNcE4J++j2DdXxmfyrD 6YWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=b+TBjDvD; 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 m9si2946213pgp.542.2018.03.14.23.05.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 23:05:23 -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=b+TBjDvD; 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 AADB22202E4B6; Wed, 14 Mar 2018 22:58:59 -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=2607:f8b0:400e:c01::244; helo=mail-pl0-x244.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl0-x244.google.com (mail-pl0-x244.google.com [IPv6:2607:f8b0:400e:c01::244]) (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 56BF021E08283 for ; Wed, 14 Mar 2018 22:58:58 -0700 (PDT) Received: by mail-pl0-x244.google.com with SMTP id k22-v6so2322416pls.6 for ; Wed, 14 Mar 2018 23:05:22 -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:in-reply-to:references; bh=aeDWfjhvPRFBoi3DiVHNaBwWQF4oeTRH2TxGpwJFDZA=; b=b+TBjDvDLcdLzsWd98yQPiECxGqQxP4OYEjOhCzsZ5gBsZFEjySDzGsbikBG10P9jM Lj1gO4oy+UXvgOW/srqA/sbgXI4d3zVYMYjaQmkl7PYmCUamuEKU9Y56bksQg8NftV/t +XgkVbYfvTDlwHTwTQ4wjOTF2mYNxMdTYdD2o= 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:in-reply-to :references; bh=aeDWfjhvPRFBoi3DiVHNaBwWQF4oeTRH2TxGpwJFDZA=; b=CELggg7914LRnilfkROLYLBvvpAJ6M5Mf5IkOtJ7pjBnDvzPZfrw3iwNjpNlI7CAIS 7NdbAEST3GQ63HCciqn/qgZZUc5eI/b0HllhVHFi9nsTrKgMR+Tlq4l3Oob/FK3qL3Bi wBKjh/QDh6X385TvTVFbCoqzkfyld3T5MSUvKh64YsQJ5GT3NeCeM+xeXMofvaTCQKyc sNyh63m6wGyJA0HCoT0hJTkX8papNQOh0pIcj3Pvxane5uIRjDEQuRpk3XP1UkenEbLN KHR7RAo674+eujQdob+q93tUz75IrbIp+2UBGiT3TiSOrh1JovNXLB3u2xj/TqoZg1mE sgqA== X-Gm-Message-State: AElRT7HM2Izn7ZN9dEsssL6aonHYa50SitG/GTmpJ4rm3UX41yiXqX1Y Y1in0cCWg+L9Kdh86Y/ofCMVkPyqlsE= X-Received: by 2002:a17:902:9897:: with SMTP id s23-v6mr6716547plp.105.1521093921459; Wed, 14 Mar 2018 23:05:21 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.100]) by smtp.gmail.com with ESMTPSA id 70sm7436192pgb.86.2018.03.14.23.05.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 23:05:20 -0700 (PDT) From: Heyi Guo To: edk2-devel@lists.01.org Date: Thu, 15 Mar 2018 14:04:01 +0800 Message-Id: <1521093843-48615-5-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> References: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> Subject: [edk2] [PATCH v7 4/6] MdeModulePkg/PciHostBridgeDxe: Add support for address translation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Yi Li , Eric Dong , Ard Biesheuvel , Heyi Guo , Michael D Kinney , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" PCI address translation is necessary for some non-x86 platforms. On such platforms, address value (denoted as "device address" or "address in PCI view") set to PCI BAR registers in configuration space might be different from the address which is used by CPU to access the registers in memory BAR or IO BAR spaces (denoted as "host address" or "address in CPU view"). The difference between the two addresses is called "Address Translation Offset" or simply "translation", and can be represented by "Address Translation Offset" in ACPI QWORD Address Space Descriptor (Offset 0x1E). However UEFI and ACPI differs on the definitions of QWORD Address Space Descriptor, and we will follow UEFI definition on UEFI protocols, such as PCI root bridge IO protocol and PCI IO protocol. In UEFI 2.7, "Address Translation Offset" is "Offset to apply to the Starting address to convert it to a PCI address". This means: 1. Translation = device address - host address. 2. PciRootBridgeIo->Configuration should return CPU view address, as well as PciIo->GetBarAttributes. Summary of addresses used in protocol interfaces and internal implementations: 1. *Only* the following protocol interfaces assume Address is Device Address: (1). PciHostBridgeResourceAllocation.GetProposedResources() Otherwise PCI bus driver cannot set correct address into PCI BARs. (2). PciRootBridgeIo.Mem.Read() and PciRootBridgeIo.Mem.Write() (3). PciRootBridgeIo.CopyMem() UEFI and PI spec have clear statements for all other protocol interfaces about the address type. 2. Library interfaces and internal implementation: (1). Base and Limit in PCI_ROOT_BRIDGE_APERTURE are device address. It is easy to check whether the address is below 4G or above 4G. (2). Addresses in PCI_ROOT_BRIDGE_INSTANCE.ResAllocNode are host address, for they are allocated from GCD. (3). Address passed to PciHostBridgeResourceConflict is host address, for it comes from PCI_ROOT_BRIDGE_INSTANCE.ResAllocNode. RESTRICTION: to simplify the situation, we require the alignment of Translation must be larger than any BAR alignment in the same root bridge, so that resource allocation alignment can be applied to both device address and host address. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Signed-off-by: Yi Li Reviewed-by: Ni Ruiyu Cc: Ruiyu Ni Cc: Ard Biesheuvel Cc: Star Zeng Cc: Eric Dong Cc: Laszlo Ersek Cc: Michael D Kinney --- Notes: v7: - Move ASSERT into if-check to print error details before assertion [Ray] v6: - Change ASSERT(FALSE) to ASSERT ((Translation & Alignment) == 0) and move ASSERT before if-check [Ray] - Print translation of bus and then assert [Ray] - Add function header for RootBridgeIoGetMemTranslationByAddress() [Ray] v5: - Add check for the alignment of Translation against the BAR alignment [Ray] - Keep coding style of comments consistent with the context [Ray] - Comment change for Base in PCI_RES_NODE [Ray] - Add macros of TO_HOST_ADDRESS and TO_DEVICE_ADDRESS for address type conversion (After that we can also simply the comments about the calculation [Ray] - Add check for bus translation offset in CreateRootBridge(), making sure it is zero, and unify code logic for all types of resource after that [Ray] - Use GetTranslationByResourceType() to simplify the code in RootBridgeIoConfiguration() (also fix a bug in previous patch version of missing a break after case TypePMem64) [Ray] - Commit message refinement [Ray] v4: - Add ASSERT (FALSE) to default branch in GetTranslationByResourceType [Laszlo] - Fix bug when passing BaseAddress to gDS->AllocateIoSpace and gDS->AllocateMemorySpace [Laszlo] - Add comment for applying alignment to both device address and host address, and add NOTE for the alignment requirement of Translation, as well as in commit message [Laszlo][Ray] - Improve indention for the code in CreateRootBridge [Laszlo] - Improve comment for Translation in PCI_ROOT_BRIDGE_APERTURE definition [Laszlo] - Ignore translation of bus in CreateRootBridge v4: - Add ASSERT (FALSE) to default branch in GetTranslationByResourceType [Laszlo] - Fix bug when passing BaseAddress to gDS->AllocateIoSpace and gDS->AllocateMemorySpace [Laszlo] - Add comment for applying alignment to both device address and host address, and add NOTE for the alignment requirement of Translation, as well as in commit message [Laszlo][Ray] - Improve indention for the code in CreateRootBridge [Laszlo] - Improve comment for Translation in PCI_ROOT_BRIDGE_APERTURE definition [Laszlo] - Ignore translation of bus in CreateRootBridge MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.h | 21 +++ MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostResource.h | 3 + MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c | 129 ++++++++++++++++--- MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 135 ++++++++++++++++++-- 4 files changed, 261 insertions(+), 27 deletions(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.h b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.h index 9a8ca21f4819..c2791ea5c2a4 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.h +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.h @@ -38,6 +38,13 @@ typedef struct { #define PCI_HOST_BRIDGE_FROM_THIS(a) CR (a, PCI_HOST_BRIDGE_INSTANCE, ResAlloc, PCI_HOST_BRIDGE_SIGNATURE) // +// Macros to translate device address to host address and vice versa. According +// to UEFI 2.7, device address = host address + translation offset. +// +#define TO_HOST_ADDRESS(DeviceAddress,TranslationOffset) ((DeviceAddress) - (TranslationOffset)) +#define TO_DEVICE_ADDRESS(HostAddress,TranslationOffset) ((HostAddress) + (TranslationOffset)) + +// // Driver Entry Point // /** @@ -247,6 +254,20 @@ ResourceConflict ( IN PCI_HOST_BRIDGE_INSTANCE *HostBridge ); +/** + This routine gets translation offset from a root bridge instance by resource type. + + @param RootBridge The Root Bridge Instance for the resources. + @param ResourceType The Resource Type of the translation offset. + + @retval The Translation Offset of the specified resource. +**/ +UINT64 +GetTranslationByResourceType ( + IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge, + IN PCI_RESOURCE_TYPE ResourceType + ); + extern EFI_METRONOME_ARCH_PROTOCOL *mMetronome; extern EFI_CPU_IO2_PROTOCOL *mCpuIo; #endif diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostResource.h b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostResource.h index 8612c0c3251b..a6c3739db368 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostResource.h +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostResource.h @@ -38,6 +38,9 @@ typedef enum { typedef struct { PCI_RESOURCE_TYPE Type; + // + // Base is a host address + // UINT64 Base; UINT64 Length; UINT64 Alignment; diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c index 1494848c3e8c..8b71363ea4e5 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c @@ -33,6 +33,39 @@ EFI_EVENT mIoMmuEvent; VOID *mIoMmuRegistration; /** + This routine gets translation offset from a root bridge instance by resource type. + + @param RootBridge The Root Bridge Instance for the resources. + @param ResourceType The Resource Type of the translation offset. + + @retval The Translation Offset of the specified resource. +**/ +UINT64 +GetTranslationByResourceType ( + IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge, + IN PCI_RESOURCE_TYPE ResourceType + ) +{ + switch (ResourceType) { + case TypeIo: + return RootBridge->Io.Translation; + case TypeMem32: + return RootBridge->Mem.Translation; + case TypePMem32: + return RootBridge->PMem.Translation; + case TypeMem64: + return RootBridge->MemAbove4G.Translation; + case TypePMem64: + return RootBridge->PMemAbove4G.Translation; + case TypeBus: + return RootBridge->Bus.Translation; + default: + ASSERT (FALSE); + return 0; + } +} + +/** Ensure the compatibility of an IO space descriptor with the IO aperture. The IO space descriptor can come from the GCD IO space map, or it can @@ -366,6 +399,7 @@ InitializePciHostBridge ( UINTN MemApertureIndex; BOOLEAN ResourceAssigned; LIST_ENTRY *Link; + UINT64 HostAddress; RootBridges = PciHostBridgeGetRootBridges (&RootBridgeCount); if ((RootBridges == NULL) || (RootBridgeCount == 0)) { @@ -411,8 +445,15 @@ InitializePciHostBridge ( } if (RootBridges[Index].Io.Base <= RootBridges[Index].Io.Limit) { + // + // Base and Limit in PCI_ROOT_BRIDGE_APERTURE are device address. + // For GCD resource manipulation, we need to use host address. + // + HostAddress = TO_HOST_ADDRESS (RootBridges[Index].Io.Base, + RootBridges[Index].Io.Translation); + Status = AddIoSpace ( - RootBridges[Index].Io.Base, + HostAddress, RootBridges[Index].Io.Limit - RootBridges[Index].Io.Base + 1 ); ASSERT_EFI_ERROR (Status); @@ -422,7 +463,7 @@ InitializePciHostBridge ( EfiGcdIoTypeIo, 0, RootBridges[Index].Io.Limit - RootBridges[Index].Io.Base + 1, - &RootBridges[Index].Io.Base, + &HostAddress, gImageHandle, NULL ); @@ -443,14 +484,20 @@ InitializePciHostBridge ( for (MemApertureIndex = 0; MemApertureIndex < ARRAY_SIZE (MemApertures); MemApertureIndex++) { if (MemApertures[MemApertureIndex]->Base <= MemApertures[MemApertureIndex]->Limit) { + // + // Base and Limit in PCI_ROOT_BRIDGE_APERTURE are device address. + // For GCD resource manipulation, we need to use host address. + // + HostAddress = TO_HOST_ADDRESS (MemApertures[MemApertureIndex]->Base, + MemApertures[MemApertureIndex]->Translation); Status = AddMemoryMappedIoSpace ( - MemApertures[MemApertureIndex]->Base, + HostAddress, MemApertures[MemApertureIndex]->Limit - MemApertures[MemApertureIndex]->Base + 1, EFI_MEMORY_UC ); ASSERT_EFI_ERROR (Status); Status = gDS->SetMemorySpaceAttributes ( - MemApertures[MemApertureIndex]->Base, + HostAddress, MemApertures[MemApertureIndex]->Limit - MemApertures[MemApertureIndex]->Base + 1, EFI_MEMORY_UC ); @@ -463,7 +510,7 @@ InitializePciHostBridge ( EfiGcdMemoryTypeMemoryMappedIo, 0, MemApertures[MemApertureIndex]->Limit - MemApertures[MemApertureIndex]->Base + 1, - &MemApertures[MemApertureIndex]->Base, + &HostAddress, gImageHandle, NULL ); @@ -654,6 +701,11 @@ AllocateResource ( if (BaseAddress < Limit) { // // Have to make sure Aligment is handled since we are doing direct address allocation + // Strictly speaking, alignment requirement should be applied to device + // address instead of host address which is used in GCD manipulation below, + // but as we restrict the alignment of Translation to be larger than any BAR + // alignment in the root bridge, we can simplify the situation and consider + // the same alignment requirement is also applied to host address. // BaseAddress = ALIGN_VALUE (BaseAddress, LShiftU64 (1, BitsOfAlignment)); @@ -721,6 +773,7 @@ NotifyPhase ( PCI_RESOURCE_TYPE Index2; BOOLEAN ResNodeHandled[TypeMax]; UINT64 MaxAlignment; + UINT64 Translation; HostBridge = PCI_HOST_BRIDGE_FROM_THIS (This); @@ -822,14 +875,43 @@ NotifyPhase ( BitsOfAlignment = LowBitSet64 (Alignment + 1); BaseAddress = MAX_UINT64; + // + // RESTRICTION: To simplify the situation, we require the alignment of + // Translation must be larger than any BAR alignment in the same root + // bridge, so that resource allocation alignment can be applied to + // both device address and host address. + // + Translation = GetTranslationByResourceType (RootBridge, Index); + if ((Translation & Alignment) != 0) { + DEBUG ((DEBUG_ERROR, "[%a:%d] Translation %lx is not aligned to %lx!\n", + __FUNCTION__, __LINE__, Translation, Alignment + )); + ASSERT ((Translation & Alignment) == 0); + // + // This may be caused by too large alignment or too small + // Translation; pick the 1st possibility and return out of resource, + // which can also go thru the same process for out of resource + // outside the loop. + // + ReturnStatus = EFI_OUT_OF_RESOURCES; + continue; + } + switch (Index) { case TypeIo: + // + // Base and Limit in PCI_ROOT_BRIDGE_APERTURE are device address. + // For AllocateResource is manipulating GCD resource, we need to use + // host address here. + // BaseAddress = AllocateResource ( FALSE, RootBridge->ResAllocNode[Index].Length, MIN (15, BitsOfAlignment), - ALIGN_VALUE (RootBridge->Io.Base, Alignment + 1), - RootBridge->Io.Limit + TO_HOST_ADDRESS (ALIGN_VALUE (RootBridge->Io.Base, Alignment + 1), + RootBridge->Io.Translation), + TO_HOST_ADDRESS (RootBridge->Io.Limit, + RootBridge->Io.Translation) ); break; @@ -838,8 +920,10 @@ NotifyPhase ( TRUE, RootBridge->ResAllocNode[Index].Length, MIN (63, BitsOfAlignment), - ALIGN_VALUE (RootBridge->MemAbove4G.Base, Alignment + 1), - RootBridge->MemAbove4G.Limit + TO_HOST_ADDRESS (ALIGN_VALUE (RootBridge->MemAbove4G.Base, Alignment + 1), + RootBridge->MemAbove4G.Translation), + TO_HOST_ADDRESS (RootBridge->MemAbove4G.Limit, + RootBridge->MemAbove4G.Translation) ); if (BaseAddress != MAX_UINT64) { break; @@ -853,8 +937,10 @@ NotifyPhase ( TRUE, RootBridge->ResAllocNode[Index].Length, MIN (31, BitsOfAlignment), - ALIGN_VALUE (RootBridge->Mem.Base, Alignment + 1), - RootBridge->Mem.Limit + TO_HOST_ADDRESS (ALIGN_VALUE (RootBridge->Mem.Base, Alignment + 1), + RootBridge->Mem.Translation), + TO_HOST_ADDRESS (RootBridge->Mem.Limit, + RootBridge->Mem.Translation) ); break; @@ -863,8 +949,10 @@ NotifyPhase ( TRUE, RootBridge->ResAllocNode[Index].Length, MIN (63, BitsOfAlignment), - ALIGN_VALUE (RootBridge->PMemAbove4G.Base, Alignment + 1), - RootBridge->PMemAbove4G.Limit + TO_HOST_ADDRESS (ALIGN_VALUE (RootBridge->PMemAbove4G.Base, Alignment + 1), + RootBridge->PMemAbove4G.Translation), + TO_HOST_ADDRESS (RootBridge->PMemAbove4G.Limit, + RootBridge->PMemAbove4G.Translation) ); if (BaseAddress != MAX_UINT64) { break; @@ -877,8 +965,10 @@ NotifyPhase ( TRUE, RootBridge->ResAllocNode[Index].Length, MIN (31, BitsOfAlignment), - ALIGN_VALUE (RootBridge->PMem.Base, Alignment + 1), - RootBridge->PMem.Limit + TO_HOST_ADDRESS (ALIGN_VALUE (RootBridge->PMem.Base, Alignment + 1), + RootBridge->PMem.Translation), + TO_HOST_ADDRESS (RootBridge->PMem.Limit, + RootBridge->PMem.Translation) ); break; @@ -1421,7 +1511,14 @@ GetProposedResources ( Descriptor->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3;; Descriptor->GenFlag = 0; - Descriptor->AddrRangeMin = RootBridge->ResAllocNode[Index].Base; + // + // AddrRangeMin in Resource Descriptor here should be device address + // instead of host address, or else PCI bus driver cannot set correct + // address into PCI BAR registers. + // Base in ResAllocNode is a host address, so conversion is needed. + // + Descriptor->AddrRangeMin = TO_DEVICE_ADDRESS (RootBridge->ResAllocNode[Index].Base, + GetTranslationByResourceType (RootBridge, Index)); Descriptor->AddrRangeMax = 0; Descriptor->AddrTranslationOffset = (ResStatus == ResAllocated) ? EFI_RESOURCE_SATISFIED : PCI_RESOURCE_LESS; Descriptor->AddrLen = RootBridge->ResAllocNode[Index].Length; diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c index dc06c16dc038..5764c2f49f92 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c @@ -86,12 +86,38 @@ CreateRootBridge ( (Bridge->AllocationAttributes & EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM) != 0 ? L"CombineMemPMem " : L"", (Bridge->AllocationAttributes & EFI_PCI_HOST_BRIDGE_MEM64_DECODE) != 0 ? L"Mem64Decode" : L"" )); - DEBUG ((EFI_D_INFO, " Bus: %lx - %lx\n", Bridge->Bus.Base, Bridge->Bus.Limit)); - DEBUG ((EFI_D_INFO, " Io: %lx - %lx\n", Bridge->Io.Base, Bridge->Io.Limit)); - DEBUG ((EFI_D_INFO, " Mem: %lx - %lx\n", Bridge->Mem.Base, Bridge->Mem.Limit)); - DEBUG ((EFI_D_INFO, " MemAbove4G: %lx - %lx\n", Bridge->MemAbove4G.Base, Bridge->MemAbove4G.Limit)); - DEBUG ((EFI_D_INFO, " PMem: %lx - %lx\n", Bridge->PMem.Base, Bridge->PMem.Limit)); - DEBUG ((EFI_D_INFO, " PMemAbove4G: %lx - %lx\n", Bridge->PMemAbove4G.Base, Bridge->PMemAbove4G.Limit)); + DEBUG (( + EFI_D_INFO, " Bus: %lx - %lx Translation=%lx\n", + Bridge->Bus.Base, Bridge->Bus.Limit, Bridge->Bus.Translation + )); + // + // Translation for bus is not supported. + // + ASSERT (Bridge->Bus.Translation == 0); + if (Bridge->Bus.Translation != 0) { + return NULL; + } + + DEBUG (( + DEBUG_INFO, " Io: %lx - %lx Translation=%lx\n", + Bridge->Io.Base, Bridge->Io.Limit, Bridge->Io.Translation + )); + DEBUG (( + DEBUG_INFO, " Mem: %lx - %lx Translation=%lx\n", + Bridge->Mem.Base, Bridge->Mem.Limit, Bridge->Mem.Translation + )); + DEBUG (( + DEBUG_INFO, " MemAbove4G: %lx - %lx Translation=%lx\n", + Bridge->MemAbove4G.Base, Bridge->MemAbove4G.Limit, Bridge->MemAbove4G.Translation + )); + DEBUG (( + DEBUG_INFO, " PMem: %lx - %lx Translation=%lx\n", + Bridge->PMem.Base, Bridge->PMem.Limit, Bridge->PMem.Translation + )); + DEBUG (( + DEBUG_INFO, " PMemAbove4G: %lx - %lx Translation=%lx\n", + Bridge->PMemAbove4G.Base, Bridge->PMemAbove4G.Limit, Bridge->PMemAbove4G.Translation + )); // // Make sure Mem and MemAbove4G apertures are valid @@ -206,7 +232,12 @@ CreateRootBridge ( } RootBridge->ResAllocNode[Index].Type = Index; if (Bridge->ResourceAssigned && (Aperture->Limit >= Aperture->Base)) { - RootBridge->ResAllocNode[Index].Base = Aperture->Base; + // + // Base in ResAllocNode is a host address, while Base in Aperture is a + // device address. + // + RootBridge->ResAllocNode[Index].Base = TO_HOST_ADDRESS (Aperture->Base, + Aperture->Translation); RootBridge->ResAllocNode[Index].Length = Aperture->Limit - Aperture->Base + 1; RootBridge->ResAllocNode[Index].Status = ResAllocated; } else { @@ -404,6 +435,40 @@ RootBridgeIoCheckParameter ( } /** + Use address to match apertures of memory type and then get the corresponding + translation. + + @param RootBridge The root bridge instance. + @param Address The address used to match aperture. + @param Translation Pointer containing the output translation. + + @return EFI_SUCCESS Get translation successfully. + @return EFI_INVALID_PARAMETER No matched memory aperture; the input Address + must be invalid. +**/ +EFI_STATUS +RootBridgeIoGetMemTranslationByAddress ( + IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge, + IN UINT64 Address, + IN OUT UINT64 *Translation + ) +{ + if (Address >= RootBridge->Mem.Base && Address <= RootBridge->Mem.Limit) { + *Translation = RootBridge->Mem.Translation; + } else if (Address >= RootBridge->PMem.Base && Address <= RootBridge->PMem.Limit) { + *Translation = RootBridge->PMem.Translation; + } else if (Address >= RootBridge->MemAbove4G.Base && Address <= RootBridge->MemAbove4G.Limit) { + *Translation = RootBridge->MemAbove4G.Translation; + } else if (Address >= RootBridge->PMemAbove4G.Base && Address <= RootBridge->PMemAbove4G.Limit) { + *Translation = RootBridge->PMemAbove4G.Translation; + } else { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + +/** Polls an address in memory mapped I/O space until an exit condition is met, or a timeout occurs. @@ -658,13 +723,25 @@ RootBridgeIoMemRead ( ) { EFI_STATUS Status; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + UINT64 Translation; Status = RootBridgeIoCheckParameter (This, MemOperation, Width, Address, Count, Buffer); if (EFI_ERROR (Status)) { return Status; } - return mCpuIo->Mem.Read (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Address, Count, Buffer); + + RootBridge = ROOT_BRIDGE_FROM_THIS (This); + Status = RootBridgeIoGetMemTranslationByAddress (RootBridge, Address, &Translation); + if (EFI_ERROR (Status)) { + return Status; + } + + // Address passed to CpuIo->Mem.Read needs to be a host address instead of + // device address. + return mCpuIo->Mem.Read (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, + TO_HOST_ADDRESS (Address, Translation), Count, Buffer); } /** @@ -705,13 +782,25 @@ RootBridgeIoMemWrite ( ) { EFI_STATUS Status; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + UINT64 Translation; Status = RootBridgeIoCheckParameter (This, MemOperation, Width, Address, Count, Buffer); if (EFI_ERROR (Status)) { return Status; } - return mCpuIo->Mem.Write (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Address, Count, Buffer); + + RootBridge = ROOT_BRIDGE_FROM_THIS (This); + Status = RootBridgeIoGetMemTranslationByAddress (RootBridge, Address, &Translation); + if (EFI_ERROR (Status)) { + return Status; + } + + // Address passed to CpuIo->Mem.Write needs to be a host address instead of + // device address. + return mCpuIo->Mem.Write (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, + TO_HOST_ADDRESS (Address, Translation), Count, Buffer); } /** @@ -746,6 +835,8 @@ RootBridgeIoIoRead ( ) { EFI_STATUS Status; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + Status = RootBridgeIoCheckParameter ( This, IoOperation, Width, Address, Count, Buffer @@ -753,7 +844,13 @@ RootBridgeIoIoRead ( if (EFI_ERROR (Status)) { return Status; } - return mCpuIo->Io.Read (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Address, Count, Buffer); + + RootBridge = ROOT_BRIDGE_FROM_THIS (This); + + // Address passed to CpuIo->Io.Read needs to be a host address instead of + // device address. + return mCpuIo->Io.Read (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, + TO_HOST_ADDRESS (Address, RootBridge->Io.Translation), Count, Buffer); } /** @@ -788,6 +885,8 @@ RootBridgeIoIoWrite ( ) { EFI_STATUS Status; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + Status = RootBridgeIoCheckParameter ( This, IoOperation, Width, Address, Count, Buffer @@ -795,7 +894,13 @@ RootBridgeIoIoWrite ( if (EFI_ERROR (Status)) { return Status; } - return mCpuIo->Io.Write (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Address, Count, Buffer); + + RootBridge = ROOT_BRIDGE_FROM_THIS (This); + + // Address passed to CpuIo->Io.Write needs to be a host address instead of + // device address. + return mCpuIo->Io.Write (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, + TO_HOST_ADDRESS (Address, RootBridge->Io.Translation), Count, Buffer); } /** @@ -1615,9 +1720,17 @@ RootBridgeIoConfiguration ( Descriptor->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3; + // According to UEFI 2.7, RootBridgeIo->Configuration should return address + // range in CPU view (host address), and ResAllocNode->Base is already a CPU + // view address (host address). Descriptor->AddrRangeMin = ResAllocNode->Base; Descriptor->AddrRangeMax = ResAllocNode->Base + ResAllocNode->Length - 1; Descriptor->AddrLen = ResAllocNode->Length; + Descriptor->AddrTranslationOffset = GetTranslationByResourceType ( + RootBridge, + ResAllocNode->Type + ); + switch (ResAllocNode->Type) { case TypeIo: From patchwork Thu Mar 15 06:04:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 131750 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp703247ljb; Wed, 14 Mar 2018 23:05:26 -0700 (PDT) X-Google-Smtp-Source: AG47ELudTgMAhhR9rhzcAzSB5CcXjmOLYsoLHtLLPMGEG2euBBJLfNzZF+O5g3DBCIOVpyUE0Xyn X-Received: by 2002:a17:902:209:: with SMTP id 9-v6mr6612259plc.403.1521093926410; Wed, 14 Mar 2018 23:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521093926; cv=none; d=google.com; s=arc-20160816; b=PMebNv//Q0AqjAwIpblafvPmbsVR66LB/6MA98CXpEu0a2jAOJHQGiioBr+YNoDAvg pJ7NzIRznRORkngBHSF+OuMQCcqutQG7TT5GjqD8kaKGM95W8GYnKcUFQAiU3LW6FNei e/VlMdufyUilpfVk0cpFcL2loleyXOYgPQ5gcxiW45e5cdtsR8xawjzzLNJOtRT9mhs7 pKVnq4nfGhtSpqxEGWyjYM/21XQ8EIjqcRZSdnMH1QNEW0nVfHi4PYRhwrPB5iq80cRI SppXKbCec5jRtsE/SoMR7uLVJqR/Kgmmarr0fG2ra5mCZUv3GVbQb4VBXMavIouan6Gb Fw1w== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=Y3ZpS3Kem3JBAAGMCeUNrb29FF7KHwhqR+av7wJZXXY=; b=DSY5F626h1LLYuwjPQ2X6KSvW2Zym98XcyVYr+zcaQHqozhidfvOtIohXfpR1rf3L7 0buHO0Np37ZaQ5IguE+vBjp9EmhaSdlgQKwd3n3mvKmUxCX4wv2mIjn8G9c+isHIVnFW QbS4gRY5skeyW+iU2hhGFkO0l9UZjB7TJJ6coTL0T1T9hgJ0XiG+zfh6yWEzb9pQg8QZ Zuq92BVGJNi1KQE/+eCzNu9OtMPI1BEwwo65BVq9qT/2Ou9kCbshFupf2bv1m1A6ktMg Rq/XOtzIUCBVa9ZfADxCi2QF6WzifeaNscRXJJdjGht7xyS5ylDedUPB+FcnLPFVZg68 Nn/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=N7p27n2S; 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 7-v6si3308273ple.604.2018.03.14.23.05.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 23:05:26 -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=N7p27n2S; 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 1C20A2202E4B9; Wed, 14 Mar 2018 22:59:02 -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=2607:f8b0:400e:c01::241; helo=mail-pl0-x241.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::241]) (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 AD33F21E08283 for ; Wed, 14 Mar 2018 22:59:00 -0700 (PDT) Received: by mail-pl0-x241.google.com with SMTP id u13-v6so3172030plq.1 for ; Wed, 14 Mar 2018 23:05:24 -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:in-reply-to:references; bh=/ILEGYndAnBI9hVnKCAq12KVLmeyy+j6gCOqjTVR60A=; b=N7p27n2Se5X/Vd4slGB6or2+szxfmCRXLLNnLcRcdNIIwBHqm/OOocE5VbWGVpdVEz bJz1H0jUvgxbvg5Ag9/9lpX26x2XFRmLLRezuh+esQq99Q5xBByWU5y6P9kRRZpuhg9O hIHiN5UPK4AlBFtytpLE9u/Gm84/ehxDoRoqk= 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:in-reply-to :references; bh=/ILEGYndAnBI9hVnKCAq12KVLmeyy+j6gCOqjTVR60A=; b=aOzjSV3a7cdpfDKRJNf927Ymo9o2+TsWUBWYOz0f/Eq1DMQcFgrvYeNhqxMKVCfHu2 nZJ1/+rLMd0mcjj5VJgB7q2YXAXihryaz+/bOHLnYPKSpJULUhciOJ46NHri4qDM/npV 2iMjlsE2wO606c9J36G5T38T0mXjDA3D6BqjsqytqxeFkcyFz3PvBW3k/vuzsYTdUk3D 7f9+OakDOP1CjCsG9Hls+9xgs6IW0eKuDCpBwTXSYIBoWU8wFS+/l2rrjIPdQGlDbB2b fKU6wA7efb/W/aeGIM5sDb0yxj0ChcsR5uFOZa9CD94vVmM5oNFoWIJMvJWVDMqjB5Jn fMMg== X-Gm-Message-State: AElRT7GQLEbRb2CsmPm+LnslVe69kGqZKI6GC87Y91LuDDmx9AKn9BmQ 9UerJSghR/aVVaMdGkBRHuZ+cPrPXEg= X-Received: by 2002:a17:902:8:: with SMTP id 8-v6mr6618374pla.291.1521093923966; Wed, 14 Mar 2018 23:05:23 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.100]) by smtp.gmail.com with ESMTPSA id 70sm7436192pgb.86.2018.03.14.23.05.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 23:05:23 -0700 (PDT) From: Heyi Guo To: edk2-devel@lists.01.org Date: Thu, 15 Mar 2018 14:04:02 +0800 Message-Id: <1521093843-48615-6-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> References: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> Subject: [edk2] [PATCH v7 5/6] MdeModulePkg/PciBus: convert host address to device address X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Yi Li , Eric Dong , Ard Biesheuvel , Heyi Guo , Michael D Kinney , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" According to UEFI spec 2.7, PciRootBridgeIo->Configuration() should return host address (CPU view ddress) rather than device address (PCI view address), so in function GetMmioAddressTranslationOffset we need to convert the range to device address before comparing. And device address = host address + translation offset. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Signed-off-by: Yi Li Reviewed-by: Ni Ruiyu Cc: Ruiyu Ni Cc: Ard Biesheuvel Cc: Star Zeng Cc: Eric Dong Cc: Laszlo Ersek Cc: Michael D Kinney --- MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c index 190f4b0dc7ed..fef3eceb7f62 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c @@ -1812,10 +1812,14 @@ GetMmioAddressTranslationOffset ( return (UINT64) -1; } + // According to UEFI 2.7, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL::Configuration() + // returns host address instead of device address, while AddrTranslationOffset + // is not zero, and device address = host address + AddrTranslationOffset, so + // we convert host address to device address for range compare. while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) { if ((Configuration->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) && - (Configuration->AddrRangeMin <= AddrRangeMin) && - (Configuration->AddrRangeMin + Configuration->AddrLen >= AddrRangeMin + AddrLen) + (Configuration->AddrRangeMin + Configuration->AddrTranslationOffset <= AddrRangeMin) && + (Configuration->AddrRangeMin + Configuration->AddrLen + Configuration->AddrTranslationOffset >= AddrRangeMin + AddrLen) ) { return Configuration->AddrTranslationOffset; } From patchwork Thu Mar 15 06:04:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 131751 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp703276ljb; Wed, 14 Mar 2018 23:05:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELvg62saGignSrmo/OSA+lJtXBCBriEZxGLSCm+267CkcPu0cX/o90hSsiYBiuXP+FrvAAj3 X-Received: by 2002:a17:902:32a2:: with SMTP id z31-v6mr6607461plb.32.1521093928740; Wed, 14 Mar 2018 23:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521093928; cv=none; d=google.com; s=arc-20160816; b=LRLygRAMkpLvgJ5mJN8Qlxm4xwqY3O7mu25ABOm8K9MAlY1Dgz2KHYTC4YXLKSSyqY ANa5gcPB7mglal0A+SIbSxO/pd7dAzSWyH4i9fteDc16p3zCcmJ+Xl/q0Y8lgTqe6mjK iNTr+PBIJA1u2rnipVlflq1RN3pVEZKgO/G0qJIPIgS1kyowjyQ8z5/fPdABXVDw54+D CzmV6ZXYbBpkJCP4WiFomOCkEsoaMAoG/8TRyRR29WUTRQFOekvYaj9tubMhznIR+r1k 87EBvkBK2OT0WtJ2LP3i6oUrs/4KWMZG0GhrEHicQXFm1hIgnC30OooV5IafwDvw4XEE cWiA== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=msdU6aRJW79twBqfT+diDOEdQcLquhaRcHFeky+oETQ=; b=WMqBr04qqbm977v1Xlb2jMcJYekTuzg+QVeYPwNuc39x7hUzf3jIudxtQs0rqJjRD3 /fHxUFUwQpcib7PWfJ1IDmmSAZArktteSJFVrQ780yqULU5/uf+zLvehaXGBatLt6Gf/ /PKM/XueVFb4ZQePCMFrBNYJ6AAhdscGdP1YAaCPKiF4SYh2j1flbEjY1tp/dWuYafLy NEh0g1VLtqrVc2LSHNWgIwS0rVOK8Miq31/YtLLRXuQmcFpM7kfZLFhke/xSxn8oqvBT pwFGTVGIZONbukPUnRH4J/u3/GddWzpIpaa0NkUdhZH64ZkDHum0tBQ7fDdzWM7Lnm2y v3yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Jril/SOa; 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 u21si3376605pfl.176.2018.03.14.23.05.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 23:05:28 -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=Jril/SOa; 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 79F032202E4BA; Wed, 14 Mar 2018 22:59:04 -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=2607:f8b0:400e:c00::244; helo=mail-pf0-x244.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (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 3616C21E08283 for ; Wed, 14 Mar 2018 22:59:03 -0700 (PDT) Received: by mail-pf0-x244.google.com with SMTP id q13so2465507pff.0 for ; Wed, 14 Mar 2018 23:05:26 -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:in-reply-to:references; bh=iYcOSp5Oiml897XHxDqe3TJg8iUlUm8UnBiyS9ZiZ4Y=; b=Jril/SOaGN/OGTpSZU4sIEceRce+60NFA45H0HiajbPMvspc0Pnf3z9CQzXymROkJt FVNHtk3kx2Q3llB8t+qWqmboXWPnzqDZWnWxB6iE7aMpZmyPx9kMSWuXu7/23YFe6w+q jertah/9Tk4+yxwuRUcIDzsvHfRamjYD0iCUo= 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:in-reply-to :references; bh=iYcOSp5Oiml897XHxDqe3TJg8iUlUm8UnBiyS9ZiZ4Y=; b=jwoSy8VdCfj+bajbSvx5jzSpxChmGedz5YppmUIbhr4ZI6fmgkAcl0b6xeRE4L/zqd eRY9OdlC6s7AKz/izPGsPg8XdBeL2p643YUzpj+6KxPE8YuyV9vf0n9Wq70h5CA4R5rn oSa0cenu/UAcRWdUrPVB1hBddiMRef1fQxNDKd6pvxHSFgd96fPTxeAz/EOJAlGemwn9 dATKagui6ryPiVkIG2VsM6PV8f0pxSSZZDQQl17vtPcOQJvTltyrtMNRZiyDjfQqu+WI ZaAo7EfP7DRWi0+jv/0bQPz+iI0MecvnLbjSbeA92uM7HyOWlEl4S6OcS0T3Q/tAktNi uYOg== X-Gm-Message-State: AElRT7E25Rt5Ud+c7/Kq/11GYDKLRjs1lJGR8FVfpssrq9/u9Yz4iHUz WpnGHoqF8SGVhOty3zARXQHujptI+2k= X-Received: by 10.99.96.79 with SMTP id u76mr520462pgb.199.1521093926487; Wed, 14 Mar 2018 23:05:26 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.100]) by smtp.gmail.com with ESMTPSA id 70sm7436192pgb.86.2018.03.14.23.05.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 23:05:26 -0700 (PDT) From: Heyi Guo To: edk2-devel@lists.01.org Date: Thu, 15 Mar 2018 14:04:03 +0800 Message-Id: <1521093843-48615-7-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> References: <1521093843-48615-1-git-send-email-heyi.guo@linaro.org> Subject: [edk2] [PATCH v7 6/6] MdeModulePkg/PciBus: return CPU address for GetBarAttributes X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Yi Li , Eric Dong , Ard Biesheuvel , Heyi Guo , Michael D Kinney , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" According to UEFI spec 2.7, PciIo->GetBarAttributes should return host address (CPU view ddress) rather than device address (PCI view address), and device address = host address + address translation offset, so we subtract translation from device address before returning. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Signed-off-by: Yi Li Reviewed-by: Ni Ruiyu Cc: Ruiyu Ni Cc: Ard Biesheuvel Cc: Star Zeng Cc: Eric Dong Cc: Laszlo Ersek Cc: Michael D Kinney --- MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c index fef3eceb7f62..62179eb44bbd 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c @@ -1972,6 +1972,10 @@ PciIoGetBarAttributes ( return EFI_UNSUPPORTED; } } + + // According to UEFI spec 2.7, we need return host address for + // PciIo->GetBarAttributes, and host address = device address - translation. + Descriptor->AddrRangeMin -= Descriptor->AddrTranslationOffset; } return EFI_SUCCESS;