From patchwork Wed Jul 25 09:50:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 949097 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41b9WW1hw2z9rxx for ; Wed, 25 Jul 2018 19:52:39 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41b9WW0465zDrTH for ; Wed, 25 Jul 2018 19:52:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=ozlabs.ru (client-ip=107.173.13.209; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from ozlabs.ru (unknown [107.173.13.209]) by lists.ozlabs.org (Postfix) with ESMTP id 41b9TP1NmnzDrHN for ; Wed, 25 Jul 2018 19:50:47 +1000 (AEST) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 054A8AE80037; Wed, 25 Jul 2018 05:49:23 -0400 (EDT) From: Alexey Kardashevskiy To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH kernel RFC 1/3] powerpc/pseries/iommu: Allow dynamic window to start from zero Date: Wed, 25 Jul 2018 19:50:30 +1000 Message-Id: <20180725095032.2196-2-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180725095032.2196-1-aik@ozlabs.ru> References: <20180725095032.2196-1-aik@ozlabs.ru> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , kvm-ppc@vger.kernel.org, David Gibson Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" At the moment the kernel does not expect dynamic windows to ever start at zero on a PCI bus as PAPR requires the hypervisor to create a 32bit default window which starts from zero and the pseries kernel only creates additional windows. However PAPR permits removing the default window and creating another one instead, starting from zero as well. In fact, the kernel used to remove the default window after sha1 25ebc45b934 but this has been reverted later. Since there are devices capable of more than 32 bits for DMA but less than 50, and currently available hardware allows the second window only at 1<<59, we will need to be able to create bigger windows starting from zero. This does the initial preparation and should not cause any behavioral changes. Signed-off-by: Alexey Kardashevskiy Reviewed-by: David Gibson --- arch/powerpc/platforms/pseries/iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index 06f0296..9ece42f 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -53,6 +53,8 @@ #include "pseries.h" +#define DDW_INVALID_OFFSET ((uint64_t)-1) + static struct iommu_table_group *iommu_pseries_alloc_group(int node) { struct iommu_table_group *table_group; @@ -844,7 +846,7 @@ static u64 find_existing_ddw(struct device_node *pdn) { struct direct_window *window; const struct dynamic_dma_window_prop *direct64; - u64 dma_addr = 0; + u64 dma_addr = DDW_INVALID_OFFSET; spin_lock(&direct_window_list_lock); /* check if we already created a window and dupe that config if so */ @@ -992,7 +994,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) mutex_lock(&direct_window_init_mutex); dma_addr = find_existing_ddw(pdn); - if (dma_addr != 0) + if (dma_addr != DDW_INVALID_OFFSET) goto out_unlock; /* @@ -1228,7 +1230,7 @@ static int dma_set_mask_pSeriesLP(struct device *dev, u64 dma_mask) } if (pdn && PCI_DN(pdn)) { dma_offset = enable_ddw(pdev, pdn); - if (dma_offset != 0) { + if (dma_offset != DDW_INVALID_OFFSET) { dev_info(dev, "Using 64-bit direct DMA at offset %llx\n", dma_offset); set_dma_offset(dev, dma_offset); set_dma_ops(dev, &dma_nommu_ops);