Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp168533pxj; Wed, 16 Jun 2021 23:28:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG0wlUMFIKIi01hhw77FjX/mcr87hiZunpoxqY09eLrRx0WEugLBheiA1fzJPuDr5ocbjY X-Received: by 2002:a17:907:9688:: with SMTP id hd8mr3506667ejc.314.1623911331023; Wed, 16 Jun 2021 23:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623911331; cv=none; d=google.com; s=arc-20160816; b=qHYIsDLui2UGuy0eI0DDzi/UR39Eiyx4MOfOE6XVOoeoUvuXJ5QTTOuo+5INKsJ2Wj Zng6q1YsHcekq0783r+8U8fiL0L57VwEufAZLqb5mSMSdsUeqga/xfiwEf3GeAiKDGrb 7WCcftQQfJq+e6GCFolceIYJXTBVSd3M7CPC3P8MLi+9nNnXm+21KWOD0uFt1phxhf7U rRWWArF4Hng6hkCZozXx0D3lOktsDPfQanFWG8CrRezwWiIo3oGkjihE8di4kK/LFsX2 40AIIfFGqHJz3r33pWvkOpoTXshFKAbdVXVce947l6fTcfFHL7e2nZ4fGxJqEIbapUMS 0Jgg== 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=E+MUWhkl+Ru8Pk+7S8K4jPmnJS5eOQrmgvdL6fMLJbw=; b=dv/JUebT8Sy1nAxeiPBzMQHAQbJo4Amy0r3N3X1M+L2tk+M0G1Bqc44q7lh2IfQLvH aiAX7NOMlxoNE2YzjMDOVHyLW5YZzy/6Y9JIMc1DSTgBkmBXuUK6bFltaUi3ZnF5euLw ZqLDbaCp7rC3qFtNOLIYES324wOj5U4djmnJlnSm0r7ux7Nd+9G1JSN3u6X5etROMr7X uTHTX9AcpI123CVqtMg37zkAdj7OtcZSzy+WmqgJ73tI+W7VaCpUrB72S1FQ9T/7QZ8x TKD9BRkrwOFdCovBUYKSEdibPKjLUy9ffwUmLhxf5kM0ESSOykRfi3taugjIJ9/S5pYJ dAXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mma1FOIP; 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 1si4518243eje.566.2021.06.16.23.28.28; Wed, 16 Jun 2021 23:28:51 -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=mma1FOIP; 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 S230028AbhFQG3C (ORCPT + 99 others); Thu, 17 Jun 2021 02:29:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbhFQG3C (ORCPT ); Thu, 17 Jun 2021 02:29:02 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0115AC061760 for ; Wed, 16 Jun 2021 23:26:55 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id s14so4152973pfd.9 for ; Wed, 16 Jun 2021 23:26:54 -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=E+MUWhkl+Ru8Pk+7S8K4jPmnJS5eOQrmgvdL6fMLJbw=; b=mma1FOIPi3/YlNrFdBEt4nYURzXDczrPJ/dWyP51Gnu6yNJuHJmCKUAbOFtFw9T1s0 CqnKQSlxkrNsSEoLmZQrTGgCcmovuvFMg3qeWbXVsey51cG7JnPh89ZNVCtuZcsYBGLu s0zPcptkHlVax9UTbEnKIF01g9/TavWHQPZhU= 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=E+MUWhkl+Ru8Pk+7S8K4jPmnJS5eOQrmgvdL6fMLJbw=; b=YLMD/ovfQc5wC5kKW0NXsvrVtr71LOqADSWZqsVv6Y8Ya/shjiEhY6NiKWgVMdZdZX H6pA0HnP67R7ICYPkLm/Nh73ttV3cmYJ6uHk8BDR5p5cjxlskQsNmfgEyJv80d0+Lgnf 0Je9a3oHcJSr4ieJ5P/7vCjrptM0hRhXcxCaHE1f55zXkOpDC/elXwO50s00whmGJFAK lb3J9UdHlGT+vCvvcfm1PN8pa4/OC8+ox5IcPgi8BtIAnkrUBHOBP06JX9gIATLfn0I9 nJXr52v0LcV1EtNDJHHzdZPVEFCQ3/vsJMlmyMp4MKwGHh/WGkRhy6eF2g1ZmM/j3/S8 cZRg== X-Gm-Message-State: AOAM531RTHw61paKTFO6knsGl4CzHBHAQwjJ5aEt9yhNn3ZDQM8oUqR0 suDCCJzarZWKeYbt6OaFDFQG9Q== X-Received: by 2002:a63:4915:: with SMTP id w21mr3470580pga.363.1623911214530; Wed, 16 Jun 2021 23:26:54 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:e349:a6ae:d3d0:1621]) by smtp.gmail.com with UTF8SMTPSA id v4sm4315866pgr.65.2021.06.16.23.26.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Jun 2021 23:26:54 -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 01/12] swiotlb: Refactor swiotlb init functions Date: Thu, 17 Jun 2021 14:26:24 +0800 Message-Id: <20210617062635.1660944-2-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 Add a new function, swiotlb_init_io_tlb_mem, for the io_tlb_mem struct initialization to make the code reusable. Signed-off-by: Claire Chang Reviewed-by: Christoph Hellwig Tested-by: Stefano Stabellini Tested-by: Will Deacon --- kernel/dma/swiotlb.c | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 52e2ac526757..47bb2a766798 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -168,9 +168,28 @@ void __init swiotlb_update_mem_attributes(void) memset(vaddr, 0, bytes); } -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) +static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, + unsigned long nslabs, bool late_alloc) { + void *vaddr = phys_to_virt(start); unsigned long bytes = nslabs << IO_TLB_SHIFT, i; + + mem->nslabs = nslabs; + mem->start = start; + mem->end = mem->start + bytes; + mem->index = 0; + mem->late_alloc = late_alloc; + spin_lock_init(&mem->lock); + for (i = 0; i < mem->nslabs; i++) { + mem->slots[i].list = IO_TLB_SEGSIZE - io_tlb_offset(i); + mem->slots[i].orig_addr = INVALID_PHYS_ADDR; + mem->slots[i].alloc_size = 0; + } + memset(vaddr, 0, bytes); +} + +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) +{ struct io_tlb_mem *mem; size_t alloc_size; @@ -186,16 +205,8 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) if (!mem) panic("%s: Failed to allocate %zu bytes align=0x%lx\n", __func__, alloc_size, PAGE_SIZE); - mem->nslabs = nslabs; - mem->start = __pa(tlb); - mem->end = mem->start + bytes; - mem->index = 0; - spin_lock_init(&mem->lock); - for (i = 0; i < mem->nslabs; i++) { - mem->slots[i].list = IO_TLB_SEGSIZE - io_tlb_offset(i); - mem->slots[i].orig_addr = INVALID_PHYS_ADDR; - mem->slots[i].alloc_size = 0; - } + + swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, false); io_tlb_default_mem = mem; if (verbose) @@ -282,8 +293,8 @@ swiotlb_late_init_with_default_size(size_t default_size) int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) { - unsigned long bytes = nslabs << IO_TLB_SHIFT, i; struct io_tlb_mem *mem; + unsigned long bytes = nslabs << IO_TLB_SHIFT; if (swiotlb_force == SWIOTLB_NO_FORCE) return 0; @@ -297,20 +308,9 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) if (!mem) return -ENOMEM; - mem->nslabs = nslabs; - mem->start = virt_to_phys(tlb); - mem->end = mem->start + bytes; - mem->index = 0; - mem->late_alloc = 1; - spin_lock_init(&mem->lock); - for (i = 0; i < mem->nslabs; i++) { - mem->slots[i].list = IO_TLB_SEGSIZE - io_tlb_offset(i); - mem->slots[i].orig_addr = INVALID_PHYS_ADDR; - mem->slots[i].alloc_size = 0; - } - + memset(mem, 0, sizeof(*mem)); + swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true); set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT); - memset(tlb, 0, bytes); io_tlb_default_mem = mem; swiotlb_print_info(); -- 2.32.0.288.g62a8d224e6-goog