From nobody Sat Nov 30 00:46:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1623763682; cv=none; d=zohomail.com; s=zohoarc; b=XGx0eqzxjEw7RseJp2SQexCsoq1zcnkXNaDmUrvplQur2v6ti03hjF6G1r/gXYStVpuL10qd4uRo7DSv20XmcWxveNUK8lwF4WxbSx2t+zO9i/tjQ9RWguoi5uw90NQOrA6eDeBuRfFNqoKrCWYTKQ+RDEyKHUNmF7GhIn/ryp0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623763682; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tVRlHSBvojaNtd1pcEKRrz7NPHsOzWEMDgZ+1zbmGdU=; b=mPHbG7QNbFnkLvPmPg98+TY5LEJjHBkNBhDuSUEPORkcGqU+b3iYaBwN97vYko5/BwR9JKEkKK7ks2ShaAVgqWsAznxg2fWUeCgVYASYg8IReRQheWf9246Ucl68YIyRQ5ZItHxDYOQofnatWs3UkST4aQTqSmxRFnPMNEoccTQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1623763682971710.9507485883132; Tue, 15 Jun 2021 06:28:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.142031.262221 (Exim 4.92) (envelope-from ) id 1lt96d-0000Cj-Mg; Tue, 15 Jun 2021 13:27:51 +0000 Received: by outflank-mailman (output) from mailman id 142031.262221; Tue, 15 Jun 2021 13:27:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lt96d-0000Bg-JC; Tue, 15 Jun 2021 13:27:51 +0000 Received: by outflank-mailman (input) for mailman id 142031; Tue, 15 Jun 2021 13:27:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lt96c-00008I-0w for xen-devel@lists.xenproject.org; Tue, 15 Jun 2021 13:27:50 +0000 Received: from mail-pl1-x633.google.com (unknown [2607:f8b0:4864:20::633]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id eb5c12c0-b778-4d80-ad69-7c15a331c80b; Tue, 15 Jun 2021 13:27:49 +0000 (UTC) Received: by mail-pl1-x633.google.com with SMTP id e1so8454597pld.13 for ; Tue, 15 Jun 2021 06:27:49 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:1846:5274:e444:139e]) by smtp.gmail.com with UTF8SMTPSA id k18sm2754133pff.63.2021.06.15.06.27.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 06:27:48 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: eb5c12c0-b778-4d80-ad69-7c15a331c80b 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=tVRlHSBvojaNtd1pcEKRrz7NPHsOzWEMDgZ+1zbmGdU=; b=Cms1BF5oSGt10F2UP+9O24JLfXZ4Lgyb9VQETesDzBTKgGS2FhYMDpDInrIK+BxGXi O42ERCktMhFmjKYBGQo46u5TM2rojL1WmkdAsDK33i17jwJ2EqHwyU915h0pGnIwGy1f lh1qyRzNXBWb9F0PmNUmShWK2hwpwgmn4zTDg= 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=tVRlHSBvojaNtd1pcEKRrz7NPHsOzWEMDgZ+1zbmGdU=; b=aonaMKAV0EOW+7IrZHIgiUjnIlmPOkFfg468g0DO9Ctk/ceXs3TGjwLG5ho99AsGBB ObPlU/YtI8vLIHVU7YV3XcnYfD6YyhGGJ6YXeHc8SxvYb+0LinFZBk810w7c17W3aUqm m70vwpVThCK/xLPdEcCDjfQtkCUwFtyGXsUyRmllhnFj73kKefyXv5+1tKasu7Coefyv 2t/hXsvfCUGfsqM2BVYxC9nfuk/3HLCEGQwHh/Un91m87V11Cv+aVbFAXBf8x7Q4gyL0 UITd+7Zue0Kix/EVZv7bIPIi4XATm9+/S9wQlFKB43mvddtZCC87V1ZmVwm8yotZx5Qb I2mQ== X-Gm-Message-State: AOAM530m2fMuFy6BgFcJCeUqKpw338lTaxaRdlP3ORWnPXNpyOEtanTL MQx8p2mji8qR8OGXrAYNk00Omg== X-Google-Smtp-Source: ABdhPJwk8KMv/p2fIKu5kDhwGYYH+3Bkx30q2cCSNaBqyz4utMpWcyKvcqe+i2VzWvJcpDMj+Kp1ZA== X-Received: by 2002:a17:90b:3ecb:: with SMTP id rm11mr24584966pjb.95.1623763668526; Tue, 15 Jun 2021 06:27:48 -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 v10 03/12] swiotlb: Set dev->dma_io_tlb_mem to the swiotlb pool used Date: Tue, 15 Jun 2021 21:27:02 +0800 Message-Id: <20210615132711.553451-4-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210615132711.553451-1-tientzu@chromium.org> References: <20210615132711.553451-1-tientzu@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @chromium.org) Content-Type: text/plain; charset="utf-8" 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 --- 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 b8a8c96dca58..eeb2d49d3aa3 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 */ =20 @@ -2846,6 +2847,9 @@ void device_initialize(struct device *dev) defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) dev->dma_coherent =3D dma_default_coherent; #endif +#ifdef CONFIG_SWIOTLB + dev->dma_io_tlb_mem =3D io_tlb_default_mem; +#endif } EXPORT_SYMBOL_GPL(device_initialize); =20 diff --git a/include/linux/device.h b/include/linux/device.h index 4443e12238a0..2e9a378c9100 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -432,6 +432,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. @@ -540,6 +541,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 97c6ad50fdc2..949a6bb21343 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -339,7 +339,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 =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; int index =3D (tlb_addr - mem->start) >> IO_TLB_SHIFT; phys_addr_t orig_addr =3D mem->slots[index].orig_addr; size_t alloc_size =3D mem->slots[index].alloc_size; @@ -421,7 +421,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 =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; unsigned long boundary_mask =3D dma_get_seg_boundary(dev); dma_addr_t tbl_dma_addr =3D phys_to_dma_unencrypted(dev, mem->start) & boundary_mask; @@ -498,7 +498,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 =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D dev->dma_io_tlb_mem; unsigned int offset =3D swiotlb_align_offset(dev, orig_addr); unsigned int i; int index; @@ -549,7 +549,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phy= s_addr_t tlb_addr, size_t mapping_size, enum dma_data_direction dir, unsigned long attrs) { - struct io_tlb_mem *mem =3D io_tlb_default_mem; + struct io_tlb_mem *mem =3D hwdev->dma_io_tlb_mem; unsigned long flags; unsigned int offset =3D swiotlb_align_offset(hwdev, tlb_addr); int index =3D (tlb_addr - offset - mem->start) >> IO_TLB_SHIFT; --=20 2.32.0.272.g935e593368-goog