Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp181215pxj; Tue, 15 Jun 2021 23:23:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJwG5s2fE1CKY0fK/FFH87a6LjVcD/4Q2Rta1lVCFs7p2o9k7atyularpj8bmm/YNim9KQ X-Received: by 2002:aa7:d305:: with SMTP id p5mr2145766edq.167.1623824624826; Tue, 15 Jun 2021 23:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623824624; cv=none; d=google.com; s=arc-20160816; b=wgLZIsjCjBGuXTxHUrWOIABO6mmd17ELfilBWJGTj0fle9gisxYhb5QeeERWxtQ+2p TKBWkc1pWnPabzrX9l2gSxIlp2NQOZgBXz7m4KvN4qcDQ0zZfKkDDblN9ip+BFnX1P3s D2o+BxU1m7qocWkE/4Z1W4Yg539qGwjfky55Oxm/wnqZY5u22EIsa2HTAkGY3x03oC1J tG26oDZeQxRZE8aUYnSJj2xnIg1xu2vwAYzjHMOvjdqeLy/2QZC5m7i1hyhp4VZlZrZW ao1lwxvIB1jzQFrCOppod9nWVxCqrSyQ3ZKg4Cv+VCaxX/2pfU/nC73PpvOBwdA0tylI R0Vg== 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=w8jpaGfzoLiwzikPo4cNB/z3ajmfRt4xSbdunsHd/ZI=; b=UuPw7rO0zPkgjWEkKXH2dlpF7747/6HEoKJ0hmRYf1WPfvv+dlMzRiz5PV6y5GmSCc wUgPGzTxBcGthOZxUFNWakTns9+9u+rU2biwLNuSJjUGgqGo1eAZHxwkhcyBvSswJcex HzB1C65N/P6XTu70vt1+OFo8Sw40AHR12JGRy61n7FoE5mqQlUoMJ4CobvE9PDWz6v7x 3+5Oudq20WlDGrku/joe9WLdRCyxP5lAfqTUGaX23Ir5RihRZoDiWcWhAPdhq02rEH6w TeqGEpEKoxurQNpcE/BqBrzkKDO/Md6TWDYzT6cT3eT9j4wpN6ujgZcXplk9qnJruxq+ f3rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jTt9XUv4; 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 jg15si1331546ejc.143.2021.06.15.23.23.22; Tue, 15 Jun 2021 23:23:44 -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=jTt9XUv4; 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 S231354AbhFPGY0 (ORCPT + 99 others); Wed, 16 Jun 2021 02:24:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbhFPGYY (ORCPT ); Wed, 16 Jun 2021 02:24:24 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1910CC0617A6 for ; Tue, 15 Jun 2021 23:22:18 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id m2so1119671pgk.7 for ; Tue, 15 Jun 2021 23:22:18 -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=w8jpaGfzoLiwzikPo4cNB/z3ajmfRt4xSbdunsHd/ZI=; b=jTt9XUv4c1VjZCWjqcVf0OaKHSTM9qmeLPQt+E1mw44/Li4ZuKLF18RfGpTBv+Tid+ nNOVbaYyhWI150qfN2S9ojFKh1FavQDj6Z6EHE2L+OIk+zrqnwXrhwMp/ayMHUZgSc6S YgAnH6iJxwdJ6kj8kmg0G1HcyFcGfORXwT+L0= 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=w8jpaGfzoLiwzikPo4cNB/z3ajmfRt4xSbdunsHd/ZI=; b=J8FFmvlptY2C13iTOk0PPA0C3NBmPmXkQGrTHOjE+wVc8SYFBUA2Ao9zAf8V0Ib2gg hg2hg2d8R327sZljvfFOS/CPVVMeMgchPgRV23/zBQmNZyZWgFmGOCW+62MTSoNohwuJ nBUJ+ip6LadFAbnR3NTAy2Hyqu3HLNsBPEGIRkVk7+s+eAUcHjOCQ+Se204rbxdAXy3a h1Y3/gY+qGrj9NUnB5VLThYkqsVmlAQxzJgI3dtBPmnqnSFAIUTmzaj6eT68OV9p5l3E GEGXS6x0zQMvza3aHIkKSWdavOSmqjL39jPcbiQ3TpYd3iFsRVv0E/cIT8HLBWiurZ4r 4xlw== X-Gm-Message-State: AOAM533UXwEa04LUcc1n8H4XHll5Qh6nvtKnzCcwu2qgYp7uCmaEW4/d WT15qTZo4OzDx43HhbVSEZXrYw== X-Received: by 2002:a63:4c8:: with SMTP id 191mr3477163pge.217.1623824537639; Tue, 15 Jun 2021 23:22:17 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:3d52:f252:7393:1992]) by smtp.gmail.com with UTF8SMTPSA id b21sm1100157pgj.74.2021.06.15.23.22.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 23:22:17 -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 v12 01/12] swiotlb: Refactor swiotlb init functions Date: Wed, 16 Jun 2021 14:21:46 +0800 Message-Id: <20210616062157.953777-2-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog In-Reply-To: <20210616062157.953777-1-tientzu@chromium.org> References: <20210616062157.953777-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 --- kernel/dma/swiotlb.c | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 52e2ac526757..3ba0f08a39a1 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,8 @@ 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; - } - + 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.272.g935e593368-goog