Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2085453pxj; Sat, 19 Jun 2021 02:28:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziGkmJnY3W/O/uOLTWHljd2D642hIu3QKVLfnyp8OcPBIekzxWKORmSQb+AUUaSfvL5HXp X-Received: by 2002:a92:c546:: with SMTP id a6mr9674505ilj.39.1624094892179; Sat, 19 Jun 2021 02:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624094892; cv=none; d=google.com; s=arc-20160816; b=J4b6CcaVCOkjyOmQTidfalYeH9m+NSUzaX/EoaXuF93QnGACiiElAAvPDHj/0RrWW2 91vLVqtv5PhzTwGyyn52jg0aWCUSBZg/1Xq0qpJzb39N5iru+YogTvcFvx7XlCABhjL9 FNUHJKyTecvL4xuAnR0l2AoKWoe4vR6a5n7fuoF4gOD5JK9s+YkysgFIdyfxXMYv44MO R4GkCnJ3V5ywlpAQpWirC1ByL9ncfGvg8lJa2gutfDCR5XVLql2rAdZDvl6RBpzQXh1n k7zMnIYCiYZGfT5gGttcJKlPG3qgQxUoZMi37ZGe/ZUPVvyUx5GAQIPL8zzqtBHVUDHF kdug== 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=omy6cCV/mqNeN2Sml+g2G3v+YRTOPwPuj3rsSOaGbf8=; b=MphJ0QWdGBryCpCMAMq8T9s5aAjcWXzLFOj6Qnr7xaBbSptqKgxklYsQrKw0NZLdSO 1t8gU17Kl66Jtc+LYTLcnrbEByvoQzFaBNdw6bd2O0qxkGfUCL31SH99uosllH3aq2or rzEGIHPlLFFkksD8ro+rkX8yvi6U6txbM8Jbu3J7b3uqyOdzrSqnWCELdqqbRZBQjNSL 2ZIhskB3VtN2UA7rwqiMir57yT7iLKeGJb5t9En2DCpS8gW4xC2JfcleV/RIIiikYzCy sWgVAmVGEyNCgWn1Uc25r3f7QUG3erk9yLO0PF7suvwV1AUILlazeSaSRo3KAjR1cO9e 9j8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=I5TZjmCg; 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 y18si13029537jat.52.2021.06.19.02.27.59; Sat, 19 Jun 2021 02:28:12 -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=I5TZjmCg; 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 S235728AbhFSDoa (ORCPT + 99 others); Fri, 18 Jun 2021 23:44:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234462AbhFSDoY (ORCPT ); Fri, 18 Jun 2021 23:44:24 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3484C061768 for ; Fri, 18 Jun 2021 20:41:03 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id bb10-20020a17090b008ab029016eef083425so8907986pjb.5 for ; Fri, 18 Jun 2021 20:41:03 -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=omy6cCV/mqNeN2Sml+g2G3v+YRTOPwPuj3rsSOaGbf8=; b=I5TZjmCgnGS7QCzs+GcKzND2zopF611oSqEk2ecm02oxJXrYZUgoQDr2D20q350b// QYtNYWxqxTTaqABZudTjO+NdWbPCAL6S986A1o51hT/KC6Y6jv56Aec5CbBEKD54AZvh ONSLv3o8P/DZRDHIEq/KTzFADPEWg4DUzfKuQ= 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=omy6cCV/mqNeN2Sml+g2G3v+YRTOPwPuj3rsSOaGbf8=; b=eg7xqxehZsk/Pi6f0oTiEZcb9+7Jc0WEJsVXucaNHoXraCVlo+8Uzw4zU9N/YB6yY+ AiOSF6ufciII1OG5jD+fUNh0FlADRCDPc0DQxbzEtj7unRjPkaXuDyaR64D1aRW43f7r o7YjgGu8CEWNolFWIzeuUQEAqLbecE4IJcAFcWPd8h4r9X4diBuhU1ZjI3owPqDyKjSE 3aaQ0KeIAZnzSMmYUio/mlLMr+DszrOSePBi67XpN5fTrhau7nLW3ZRyYQuM6fnf7Ugv 4kLeHdCGS7UA3nKC2bsjJCoum8ZXY/IV3z4XVCD5H5Ww3E7rE/+v5APUxyto5Xz4lHA3 3iLQ== X-Gm-Message-State: AOAM532so9WkyPV2TBFtmY9YiYOMLLFRb13LeEcrigc0ZYGANsvk/xy5 ueTqI1iZnDcl6QML+CKfy7VKng== X-Received: by 2002:a17:90a:3c8d:: with SMTP id g13mr7572126pjc.229.1624074063342; Fri, 18 Jun 2021 20:41:03 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:4a46:e208:29e8:e076]) by smtp.gmail.com with UTF8SMTPSA id v15sm10722584pgf.26.2021.06.18.20.40.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Jun 2021 20:41:02 -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, thomas.lendacky@amd.com Subject: [PATCH v14 01/12] swiotlb: Refactor swiotlb init functions Date: Sat, 19 Jun 2021 11:40:32 +0800 Message-Id: <20210619034043.199220-2-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210619034043.199220-1-tientzu@chromium.org> References: <20210619034043.199220-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..1f9b2b9e7490 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)); set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT); - memset(tlb, 0, bytes); + swiotlb_init_io_tlb_mem(mem, virt_to_phys(tlb), nslabs, true); io_tlb_default_mem = mem; swiotlb_print_info(); -- 2.32.0.288.g62a8d224e6-goog