linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: eric.auger@redhat.com (Eric Auger)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v14 05/16] iommu/dma: Introduce iommu_calc_msi_resv
Date: Wed, 12 Oct 2016 13:22:13 +0000	[thread overview]
Message-ID: <1476278544-3397-6-git-send-email-eric.auger@redhat.com> (raw)
In-Reply-To: <1476278544-3397-1-git-send-email-eric.auger@redhat.com>

iommu_calc_msi_resv() sum up the number of iommu pages of the lowest
order supported by the iommu domain requested to map all the registered
doorbells. This function will allow to dimension the intermediate
physical address (IPA) aperture requested to map the MSI doorbells.

Signed-off-by: Eric Auger <eric.auger@redhat.com>

---

v13 -> v14
- name and proto changed, moved to dma-iommu
---
 drivers/iommu/dma-iommu.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/dma-iommu.h | 11 +++++++-
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index d8a7d86..3a4b73b 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -830,3 +830,73 @@ bool iommu_msi_doorbell_safe(void)
 	return !nb_unsafe_doorbells;
 }
 EXPORT_SYMBOL_GPL(iommu_msi_doorbell_safe);
+
+/**
+ * calc_region_reqs - compute the number of pages requested to map a region
+ *
+ * @addr: physical base address of the region
+ * @size: size of the region
+ * @order: the page order
+ *
+ * Return: the number of requested pages to map this region
+ */
+static int calc_region_reqs(phys_addr_t addr, size_t size, unsigned int order)
+{
+	phys_addr_t offset, granule;
+	unsigned int nb_pages;
+
+	granule = (uint64_t)(1 << order);
+	offset = addr & (granule - 1);
+	size = ALIGN(size + offset, granule);
+	nb_pages = size >> order;
+
+	return nb_pages;
+}
+
+/**
+ * calc_dbinfo_reqs - compute the number of pages requested to map a given
+ * MSI doorbell
+ *
+ * @dbi: doorbell info descriptor
+ * @order: page order
+ *
+ * Return: the number of requested pages to map this doorbell
+ */
+static int calc_dbinfo_reqs(struct iommu_msi_doorbell_info *dbi,
+			    unsigned int order)
+{
+	int ret = 0;
+
+	if (!dbi->doorbell_is_percpu) {
+		ret = calc_region_reqs(dbi->global_doorbell, dbi->size, order);
+	} else {
+		phys_addr_t __percpu *pbase;
+		int cpu;
+
+		for_each_possible_cpu(cpu) {
+			pbase = per_cpu_ptr(dbi->percpu_doorbells, cpu);
+			ret += calc_region_reqs(*pbase, dbi->size, order);
+		}
+	}
+	return ret;
+}
+
+int iommu_calc_msi_resv(struct iommu_domain *domain)
+{
+	unsigned long order = __ffs(domain->pgsize_bitmap);
+	struct iommu_msi_doorbell *db;
+	phys_addr_t granule;
+	int size = 0;
+
+	mutex_lock(&iommu_msi_doorbell_mutex);
+	list_for_each_entry(db, &iommu_msi_doorbell_list, next)
+		size += calc_dbinfo_reqs(&db->info, order);
+
+	mutex_unlock(&iommu_msi_doorbell_mutex);
+
+	granule = (uint64_t)(1 << order);
+	domain->msi_resv.size = size * granule;
+	domain->msi_resv.alignment = granule;
+
+	return 0;
+}
diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h
index 9640a27..95875c8 100644
--- a/include/linux/dma-iommu.h
+++ b/include/linux/dma-iommu.h
@@ -97,6 +97,16 @@ void iommu_msi_doorbell_free(struct iommu_msi_doorbell_info *db);
  */
 bool iommu_msi_doorbell_safe(void);
 
+/**
+ * iommu_calc_msi_resv - compute the number of pages of the lowest order
+ * supported by @domain, requested to map all the registered doorbells.
+ *
+ * @domain: iommu_domain
+ * @msi_resv: MSI reserved window requirements
+ *
+ */
+int iommu_calc_msi_resv(struct iommu_domain *domain);
+
 #else
 
 struct iommu_domain;
@@ -139,7 +149,6 @@ static inline bool iommu_msi_doorbell_safe(void)
 {
 	return false;
 }
-
 #endif	/* CONFIG_IOMMU_DMA */
 #endif	/* __KERNEL__ */
 #endif	/* __DMA_IOMMU_H */
-- 
1.9.1

  parent reply	other threads:[~2016-10-12 13:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-12 13:22 [PATCH v14 00/16] KVM PCIe/MSI passthrough on ARM/ARM64 Eric Auger
2016-10-12 13:22 ` [PATCH v14 01/16] iommu/iova: fix __alloc_and_insert_iova_range Eric Auger
2016-10-12 13:22 ` [PATCH v14 02/16] iommu: Introduce DOMAIN_ATTR_MSI_RESV Eric Auger
2016-10-12 13:22 ` [PATCH v14 03/16] iommu/dma: Allow MSI-only cookies Eric Auger
2016-10-12 13:22 ` [PATCH v14 04/16] iommu/dma: MSI doorbell alloc/free Eric Auger
2016-10-14 11:25   ` Punit Agrawal
2016-10-17 14:25     ` Auger Eric
2016-10-12 13:22 ` Eric Auger [this message]
2016-10-12 13:22 ` [PATCH v14 06/16] iommu/arm-smmu: Implement domain_get_attr for DOMAIN_ATTR_MSI_RESV Eric Auger
2016-10-12 13:22 ` [PATCH v14 07/16] irqchip/gic-v2m: Register the MSI doorbell Eric Auger
2016-10-12 13:22 ` [PATCH v14 08/16] irqchip/gicv3-its: " Eric Auger
2016-10-12 13:22 ` [PATCH v14 09/16] vfio: Introduce a vfio_dma type field Eric Auger
2016-10-12 13:22 ` [PATCH v14 10/16] vfio/type1: vfio_find_dma accepting a type argument Eric Auger
2016-10-12 13:22 ` [PATCH v14 11/16] vfio/type1: Implement recursive vfio_find_dma_from_node Eric Auger
2016-10-12 13:22 ` [PATCH v14 12/16] vfio/type1: Handle unmap/unpin and replay for VFIO_IOVA_RESERVED slots Eric Auger
2016-10-12 13:22 ` [PATCH v14 13/16] vfio: Allow reserved msi iova registration Eric Auger
2016-10-12 13:22 ` [PATCH v14 14/16] vfio/type1: Check doorbell safety Eric Auger
2016-11-03 13:45   ` Diana Madalina Craciun
2016-11-03 14:14     ` Auger Eric
2016-10-12 13:22 ` [PATCH v14 15/16] iommu/arm-smmu: Do not advertise IOMMU_CAP_INTR_REMAP Eric Auger
2016-10-12 13:22 ` [PATCH v14 16/16] vfio/type1: Introduce MSI_RESV capability Eric Auger
2016-10-14 11:24 ` [PATCH v14 00/16] KVM PCIe/MSI passthrough on ARM/ARM64 Punit Agrawal
2016-10-17 14:19   ` Auger Eric
2016-10-17 15:08     ` Punit Agrawal
2016-10-20 17:32 ` Will Deacon
2016-10-21  9:26   ` Auger Eric
2016-10-24 19:39     ` Robin Murphy
2016-11-02 16:15       ` Auger Eric

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476278544-3397-6-git-send-email-eric.auger@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).