Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754973AbbDJGd0 (ORCPT ); Fri, 10 Apr 2015 02:33:26 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:42047 "EHLO e23smtp03.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754625AbbDJGdL (ORCPT ); Fri, 10 Apr 2015 02:33:11 -0400 From: Alexey Kardashevskiy To: linuxppc-dev@lists.ozlabs.org Cc: Alexey Kardashevskiy , Benjamin Herrenschmidt , Paul Mackerras , Alex Williamson , linux-kernel@vger.kernel.org Subject: [PATCH kernel v8 27/31] powerpc/iommu/ioda2: Add get_table_size() to calculate the size of fiture table Date: Fri, 10 Apr 2015 16:31:09 +1000 Message-Id: <1428647473-11738-28-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1428647473-11738-1-git-send-email-aik@ozlabs.ru> References: <1428647473-11738-1-git-send-email-aik@ozlabs.ru> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15041006-0009-0000-0000-000001332E6B Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4072 Lines: 124 This adds a way for the IOMMU user to know how much a new table will use so it can be accounted in the locked_vm limit before allocation happens. This stores the allocated table size in pnv_pci_ioda2_create_table() so the locked_vm counter can be updated correctly when a table is being disposed. Signed-off-by: Alexey Kardashevskiy --- arch/powerpc/include/asm/iommu.h | 5 +++ arch/powerpc/platforms/powernv/pci-ioda.c | 54 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index a768a4d..9027b9e 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -94,6 +94,7 @@ struct iommu_table { unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_indirect_levels; unsigned long it_level_size; + unsigned long it_allocated_size; unsigned long it_offset; /* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ @@ -159,6 +160,10 @@ struct iommu_table_group_ops { void (*set_ownership)(struct iommu_table_group *table_group, bool enable); + unsigned long (*get_table_size)( + __u32 page_shift, + __u64 window_size, + __u32 levels); long (*create_table)(struct iommu_table_group *table_group, int num, __u32 page_shift, diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c index 3ac523d..1d2b1e4 100644 --- a/arch/powerpc/platforms/powernv/pci-ioda.c +++ b/arch/powerpc/platforms/powernv/pci-ioda.c @@ -1373,6 +1373,57 @@ static void pnv_free_tce_table(unsigned long addr, unsigned long size, free_pages(addr, get_order(size << 3)); } +static unsigned long pnv_get_tce_table_size(unsigned shift, unsigned levels, + unsigned long *left) +{ + unsigned long ret, chunk = 1UL << shift, i; + + ret = chunk; + + if (!*left) + return 0; + + --levels; + if (!levels) { + /* This is last level, actual TCEs */ + *left -= min(*left, chunk); + return chunk; + } + + for (i = 0; i < (chunk >> 3); ++i) { + ret += pnv_get_tce_table_size(shift, levels, left); + if (!*left) + break; + } + + return ret; +} + +static unsigned long pnv_ioda2_get_table_size(__u32 page_shift, + __u64 window_size, __u32 levels) +{ + unsigned long tce_table_size, shift, ret; + + if (!levels || (levels > POWERNV_IOMMU_MAX_LEVELS)) + return -EINVAL; + + if ((window_size > memory_hotplug_max()) || !is_power_of_2(window_size)) + return -EINVAL; + + tce_table_size = (window_size >> page_shift) * 8; + tce_table_size = max(0x1000UL, tce_table_size); + + /* Allocate TCE table */ + shift = ROUND_UP(ilog2(window_size) - page_shift, levels) / levels; + shift += 3; + shift = max_t(unsigned, shift, IOMMU_PAGE_SHIFT_4K); + + ret = tce_table_size; /* tbl->it_userspace */ + ret += pnv_get_tce_table_size(shift, levels, &tce_table_size); + + return ret; +} + static __be64 *pnv_alloc_tce_table(int nid, unsigned shift, unsigned levels, unsigned long *left) { @@ -1452,6 +1503,8 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group, return -ENOMEM; tbl->it_indirect_levels = levels - 1; + tbl->it_allocated_size = pnv_ioda2_get_table_size(page_shift, + window_size, levels); /* Setup linux iommu table */ pnv_pci_setup_iommu_table(tbl, addr, tce_table_size, @@ -1681,6 +1734,7 @@ static long pnv_pci_ioda2_create_table_with_uas( static struct iommu_table_group_ops pnv_pci_ioda2_ops = { .set_ownership = pnv_ioda2_set_ownership, + .get_table_size = pnv_ioda2_get_table_size, .create_table = pnv_pci_ioda2_create_table_with_uas, .set_window = pnv_pci_ioda2_set_window, .unset_window = pnv_pci_ioda2_unset_window, -- 2.0.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/