Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp168406pxj; Wed, 16 Jun 2021 23:28:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWP5uEO44RzU2GgXTtQxX2zQxUlxoPyWK4LCC+Lp9TS4Jrbrg8Z4l3GLjZh2J4hrdeM+pZ X-Received: by 2002:a05:6e02:12a6:: with SMTP id f6mr2439594ilr.121.1623911317199; Wed, 16 Jun 2021 23:28:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623911317; cv=none; d=google.com; s=arc-20160816; b=a+E+oEKrvQUfb8Amhx7D1ZIQetV09bBx+OrGtR3j4lAQKgzlOfygKVVhYOccO0l3G2 RnKIooRShgFlhx6hOoIbf/UZbK7f9+LetCqdp+OJPDcEO7rm+bWBQPoN3742CFk8hfSX 4HJQjhvc998bG6m61dnZN34kMHpZfxfyuyIw0IeY72xSSiL5Jf27VMxidZ2tR2yi+0Uu LT2aoiRYyxCSaW8tjlydlKFe7H1kDdrPFjG0ixMMBuOWIVwPwQx+gWvQW8O9tnH7/e9F E+qeJRtOa5jXXTJRq8U+6dG4kHCrsqjPGg8/xbeV+9oKwuqSZtgk10shE7ZzTZcNF6Yq YueA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sOkzSft4/PekQY0R4flE8dZ9jaJgeD5vzcmemGtg3cs=; b=xKkZEIAy3bxfDN98yFxF85Wl+2WE5+nmu+MjUXKSFimWxYVgibQDBJkJd8XTQcPWv8 lxRO7VIntEZMBJn03ddgg8G+CeRtTaGvm/Ql+6yucW80JvAfn2apifNNwXoYrWsMKJPg AlkibxFftAf4glQQZheb5Zus57Xyp+RNIQKgtkspV7bBlb66szDci30hBhvNcdBR2BdP mhzgNARM+XMThYxJ9JYhrmyu0s26Mi4v6rC71Rot0jYJjxAnDPEw66PQRWjsWnDfOuQh I8YjWUkW3J4qw/0d40NpJsyXMw2u0BCSfgKRDa5FJ/Hi0EH3fmpyJerYQ8TSyW7lBpH1 Svyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PgkZf0dq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i15si4177518ila.101.2021.06.16.23.28.25; Wed, 16 Jun 2021 23:28:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PgkZf0dq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbhFQG3U (ORCPT + 99 others); Thu, 17 Jun 2021 02:29:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbhFQG3T (ORCPT ); Thu, 17 Jun 2021 02:29:19 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F7B7C061574 for ; Wed, 16 Jun 2021 23:27:12 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id t13so4075885pgu.11 for ; Wed, 16 Jun 2021 23:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sOkzSft4/PekQY0R4flE8dZ9jaJgeD5vzcmemGtg3cs=; b=PgkZf0dqtS9ToNJdUfOn4ouQrVj5xyDb0O2hfA2ZXQeoO+JV+cvuiqavT8vPvjQgKA uGeSMQI4OSn0CIUdv+4NKoUnDmfkrwa4J9Y2i2zrNHTx2K4IDo1nSWJLR1VqoLOEzqab AJGia54I/c58jg7PTAZHkzSODnw0UdhBZ9VbM= 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:mime-version:content-transfer-encoding; bh=sOkzSft4/PekQY0R4flE8dZ9jaJgeD5vzcmemGtg3cs=; b=mrcgZ3EWRoFhZzNM65+fyIR07Iop8jiSQfFoveI5jKId9mupWEuIhuIra8tfeGeNkk oFPJ2BSbM+im/BDeANYKF/cN0EoA4CoctF9ackPzR1ophQTmBXnOJqYeU89Wxb6Py1JM jatU93AftO363pbn/zE63UhrRaF0r/cNqz2rRt7fQ2cf8xgC6j7oTkLJwx9DoJqld6Aj oZ9Hsb/HmOtHueNzeuenrSP/PG7hLLzrhr/cHjTCVE3A7tnldqAWAyoztu8AP5jxjiNv ddbxfOt1hBSBsOcf6V69Hvptlf4Ndc1uVWVDkXO7Zgi6CqxuBIRQXBHgj4u78SHLr6lD UCCg== X-Gm-Message-State: AOAM530s4LC8x9Q/ADpT1yLToZJOU36mY9hanDRoJYPszzXXRf2Cam4w Czzi0pnmGmLJXoEEfbxRq88vjw== X-Received: by 2002:a63:4554:: with SMTP id u20mr3474032pgk.23.1623911231703; Wed, 16 Jun 2021 23:27:11 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:e349:a6ae:d3d0:1621]) by smtp.gmail.com with UTF8SMTPSA id g18sm3933417pfi.199.2021.06.16.23.27.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Jun 2021 23:27:11 -0700 (PDT) From: Claire Chang To: Rob Herring , mpe@ellerman.id.au, Joerg Roedel , Will Deacon , Frank Rowand , Konrad Rzeszutek Wilk , boris.ostrovsky@oracle.com, jgross@suse.com, Christoph Hellwig , Marek Szyprowski Cc: benh@kernel.crashing.org, paulus@samba.org, "list@263.net:IOMMU DRIVERS" , sstabellini@kernel.org, Robin Murphy , grant.likely@arm.com, xypron.glpk@gmx.de, Thierry Reding , mingo@kernel.org, bauerman@linux.ibm.com, peterz@infradead.org, Greg KH , Saravana Kannan , "Rafael J . Wysocki" , heikki.krogerus@linux.intel.com, Andy Shevchenko , Randy Dunlap , Dan Williams , Bartosz Golaszewski , linux-devicetree , lkml , linuxppc-dev@lists.ozlabs.org, xen-devel@lists.xenproject.org, Nicolas Boichat , Jim Quinlan , tfiga@chromium.org, bskeggs@redhat.com, bhelgaas@google.com, chris@chris-wilson.co.uk, tientzu@chromium.org, daniel@ffwll.ch, airlied@linux.ie, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, jani.nikula@linux.intel.com, jxgao@google.com, joonas.lahtinen@linux.intel.com, linux-pci@vger.kernel.org, maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, rodrigo.vivi@intel.com, thomas.hellstrom@linux.intel.com Subject: [PATCH v13 03/12] swiotlb: Set dev->dma_io_tlb_mem to the swiotlb pool used Date: Thu, 17 Jun 2021 14:26:26 +0800 Message-Id: <20210617062635.1660944-4-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210617062635.1660944-1-tientzu@chromium.org> References: <20210617062635.1660944-1-tientzu@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Always have the pointer to the swiotlb pool used in struct device. This could help simplify the code for other pools. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon --- drivers/base/core.c | 4 ++++ include/linux/device.h | 4 ++++ kernel/dma/swiotlb.c | 8 ++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index f29839382f81..cb3123e3954d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include /* for dma_default_coherent */ @@ -2736,6 +2737,9 @@ void device_initialize(struct device *dev) defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) dev->dma_coherent = dma_default_coherent; #endif +#ifdef CONFIG_SWIOTLB + dev->dma_io_tlb_mem = io_tlb_default_mem; +#endif } EXPORT_SYMBOL_GPL(device_initialize); diff --git a/include/linux/device.h b/include/linux/device.h index ba660731bd25..240d652a0696 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -416,6 +416,7 @@ struct dev_links_info { * @dma_pools: Dma pools (if dma'ble device). * @dma_mem: Internal for coherent mem override. * @cma_area: Contiguous memory area for dma allocations + * @dma_io_tlb_mem: Pointer to the swiotlb pool used. Not for driver use. * @archdata: For arch-specific additions. * @of_node: Associated device tree node. * @fwnode: Associated device node supplied by platform firmware. @@ -518,6 +519,9 @@ struct device { #ifdef CONFIG_DMA_CMA struct cma *cma_area; /* contiguous memory area for dma allocations */ +#endif +#ifdef CONFIG_SWIOTLB + struct io_tlb_mem *dma_io_tlb_mem; #endif /* arch specific additions */ struct dev_archdata archdata; diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 2dba659a1e73..de79e9437030 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -340,7 +340,7 @@ void __init swiotlb_exit(void) static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size, enum dma_data_direction dir) { - struct io_tlb_mem *mem = io_tlb_default_mem; + struct io_tlb_mem *mem = dev->dma_io_tlb_mem; int index = (tlb_addr - mem->start) >> IO_TLB_SHIFT; unsigned int offset = (tlb_addr - mem->start) & (IO_TLB_SIZE - 1); phys_addr_t orig_addr = mem->slots[index].orig_addr; @@ -431,7 +431,7 @@ static unsigned int wrap_index(struct io_tlb_mem *mem, unsigned int index) static int find_slots(struct device *dev, phys_addr_t orig_addr, size_t alloc_size) { - struct io_tlb_mem *mem = io_tlb_default_mem; + struct io_tlb_mem *mem = dev->dma_io_tlb_mem; unsigned long boundary_mask = dma_get_seg_boundary(dev); dma_addr_t tbl_dma_addr = phys_to_dma_unencrypted(dev, mem->start) & boundary_mask; @@ -508,7 +508,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr, size_t mapping_size, size_t alloc_size, enum dma_data_direction dir, unsigned long attrs) { - struct io_tlb_mem *mem = io_tlb_default_mem; + struct io_tlb_mem *mem = dev->dma_io_tlb_mem; unsigned int offset = swiotlb_align_offset(dev, orig_addr); unsigned int i; int index; @@ -559,7 +559,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, size_t mapping_size, enum dma_data_direction dir, unsigned long attrs) { - struct io_tlb_mem *mem = io_tlb_default_mem; + struct io_tlb_mem *mem = hwdev->dma_io_tlb_mem; unsigned long flags; unsigned int offset = swiotlb_align_offset(hwdev, tlb_addr); int index = (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT; -- 2.32.0.288.g62a8d224e6-goog