Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3172006yba; Sun, 28 Apr 2019 19:17:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwadangBfUBjn+vXfkcMyuiMaRzKK3QKrLUzZjwCNPMPIJVA4MD3T1Jo3DIf8kRl+6cYtUC X-Received: by 2002:a62:b40b:: with SMTP id h11mr58649349pfn.133.1556504244233; Sun, 28 Apr 2019 19:17:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556504244; cv=none; d=google.com; s=arc-20160816; b=deNzXiyqhnzK0SsqlgZqNxER5Qx8Oy9fOyFkznE0waGLbhn2c88WokRff3cjwVNeVT joTWE2kp6LqZKldumZJkHr90tX0NttQs4UUmQ4tIqOZex3DXSdbFBGTheimW5Mu+Pj6D iKAipmXX/qHTco8AcLp+FidW+9o0IwtZOrSK8QusewX5nQl0X5cG5zqPinvW5X6pVlVL nmTcgFLjI3LEwmghXJ8U58rYCpo1LA88BRnTGMAlRtG47NBwosrQ8+XGX0rCjlNAE7CX 8ZzPIES/F8p3TBFcqovX4rHv2B+DrHHYQnV8+dvBkIM/VLw0np0nsZzFxEw3xz/Z6NTd 4gfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=DfMLgyCQxpDU9JpOzq6EUXUo9Ux788g/kev+Hkb8SaM=; b=pAUzSzB1mUEUeBwhPZlntDxOiY3SsKerCYmgrrd6xlpSWuu8YpGWsxcGWgs/jSakxa vsAKEJ0tlR+ATDee66boXpt+pFDtPFzJwcTjXouMGgnywXR9irdCxXADIwi+3qQv5bGZ PBwCt30P7+LWn3s+n1vC7WlKG5rnEApKBPYLCZOWmQ8hAw7lo+84JpN2I8/TAs9puhpU 8UTRN4jy7pZkW2Roq9RqLyLsZADFXo/OEid0ZZp/IEgcP7OVF6I5cOktcWPCErEIGfK/ A0TfiDH9ju9QgJarypSSXkOnerplmqXJChAboYVrZn/gaQ0zrf3SBguQCkEhYe9i+Ic7 b90A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si6980775pgs.402.2019.04.28.19.17.09; Sun, 28 Apr 2019 19:17:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727242AbfD2CQL (ORCPT + 99 others); Sun, 28 Apr 2019 22:16:11 -0400 Received: from mga03.intel.com ([134.134.136.65]:46364 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727185AbfD2CQF (ORCPT ); Sun, 28 Apr 2019 22:16:05 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 19:16:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="146537849" Received: from allen-box.sh.intel.com ([10.239.159.136]) by orsmga003.jf.intel.com with ESMTP; 28 Apr 2019 19:16:03 -0700 From: Lu Baolu To: David Woodhouse , Joerg Roedel Cc: ashok.raj@intel.com, jacob.jun.pan@intel.com, kevin.tian@intel.com, jamessewart@arista.com, tmurphy@arista.com, dima@arista.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/8] iommu/vt-d: Expose ISA direct mapping region via iommu_get_resv_regions Date: Mon, 29 Apr 2019 10:09:20 +0800 Message-Id: <20190429020925.18136-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190429020925.18136-1-baolu.lu@linux.intel.com> References: <20190429020925.18136-1-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Sewart To support mapping ISA region via iommu_group_create_direct_mappings, make sure its exposed by iommu_get_resv_regions. This allows deduplication of reserved region mappings. Signed-off-by: James Sewart --- drivers/iommu/intel-iommu.c | 43 +++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index af025955f1bc..e9f31b062305 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -339,6 +339,8 @@ static LIST_HEAD(dmar_rmrr_units); #define for_each_rmrr_units(rmrr) \ list_for_each_entry(rmrr, &dmar_rmrr_units, list) +static struct iommu_resv_region *isa_resv_region; + /* bitmap for indexing intel_iommus */ static int g_num_of_iommus; @@ -2785,26 +2787,33 @@ static inline int iommu_prepare_rmrr_dev(struct dmar_rmrr_unit *rmrr, rmrr->end_address); } +static inline struct iommu_resv_region *iommu_get_isa_resv_region(void) +{ + if (!isa_resv_region) + isa_resv_region = iommu_alloc_resv_region(0, 1UL << 24, 0, + IOMMU_RESV_DIRECT); + + return isa_resv_region; +} + #ifdef CONFIG_INTEL_IOMMU_FLOPPY_WA -static inline void iommu_prepare_isa(void) +static inline void iommu_prepare_isa(struct pci_dev *pdev) { - struct pci_dev *pdev; int ret; + struct iommu_resv_region *reg = iommu_get_isa_resv_region(); - pdev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); - if (!pdev) + if (!reg) return; pr_info("Prepare 0-16MiB unity mapping for LPC\n"); - ret = iommu_prepare_identity_map(&pdev->dev, 0, 16*1024*1024 - 1); + ret = iommu_prepare_identity_map(&pdev->dev, reg->start, + reg->start + reg->length - 1); if (ret) pr_err("Failed to create 0-16MiB identity map - floppy might not work\n"); - - pci_dev_put(pdev); } #else -static inline void iommu_prepare_isa(void) +static inline void iommu_prepare_isa(struct pci_dev *pdev) { return; } @@ -3293,6 +3302,7 @@ static int __init init_dmars(void) struct dmar_rmrr_unit *rmrr; bool copied_tables = false; struct device *dev; + struct pci_dev *pdev; struct intel_iommu *iommu; int i, ret; @@ -3473,7 +3483,11 @@ static int __init init_dmars(void) } } - iommu_prepare_isa(); + pdev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); + if (pdev) { + iommu_prepare_isa(pdev); + pci_dev_put(pdev); + } domains_done: @@ -5498,6 +5512,17 @@ static void intel_iommu_get_resv_regions(struct device *device, } rcu_read_unlock(); +#ifdef CONFIG_INTEL_IOMMU_FLOPPY_WA + if (dev_is_pci(device)) { + struct pci_dev *pdev = to_pci_dev(device); + + if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA) { + reg = iommu_get_isa_resv_region(); + list_add_tail(®->list, head); + } + } +#endif /* CONFIG_INTEL_IOMMU_FLOPPY_WA */ + reg = iommu_alloc_resv_region(IOAPIC_RANGE_START, IOAPIC_RANGE_END - IOAPIC_RANGE_START + 1, 0, IOMMU_RESV_MSI); -- 2.17.1