Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp334547pxv; Thu, 24 Jun 2021 08:57:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1qIg7AS4MPRcrM9znyR9zTZOHEWpflHLqWsmmxi+LWTA+K+pxFHO/04q9nSe6q7U2WrmG X-Received: by 2002:a17:906:9bd5:: with SMTP id de21mr5871490ejc.554.1624550245997; Thu, 24 Jun 2021 08:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624550245; cv=none; d=google.com; s=arc-20160816; b=FRdghAeozZdNQ5IZH1dY9VLTZVGnYbdkigCDH0/6n4qvzxNfh69/fNA4PXwa4V4Knn j/ZPe8NULcnuldS74jKN/IjwqH2NVHfOkyy5OXNVvV7Kks3ND1phnVQZDxoyVCzQHGS/ GB4Cft34YqE4/Bqp4i5iSckvRtG0l6tbC5MdnADQQGcP94f/YK7oQqd7bvYPTnC4neZ9 SU8dPTD5XcZeHxz2mdMPxJRcXSA2S4gjL+bBGd1DarusNPXsRNq1hjz7YN01ibjcchfm Rkwb51me6EtsslzqDig7N7+HVeLjUZO6+UK1e/Yv51Tp2jULbQGXLGZGZMVvHyI9Le7U HEBQ== 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=YJFR7rMJgjSCjddzLV99+gcsv72cCY4rcuJfLx7ix2M=; b=t070dU7RLJqqu+FZ/x32KgQi+az+CJ5o6Zy1hfjBP8xidvLB7SD2ZEqjD1ySIqm8LH GxI42/qeA4F5p2YiPNZ9vJSPINkc3hfGS5BC4wta8sCZAESaISGnk9aGMr8C6bxcrp0Y Fxm3pl0S1u4R+fT/l71MK/ouguK4EpLPNPk+GNoIYg1ogoYgJJcM6qZLTfsdhNhvsy6w ClsgHpoYed2I9TTod/MS1ABVpeExeKzgsOhmtC8s72+cmOSKgtwRhoqI2beh6CzjWSQT UVdhb1I/lRbqcOflVBbB1PQoTNYvN1AlR+Zz54e1pfsK/e2rSTC+RIo/3WSVObveCPqg uQgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IZ8zEMil; 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 25si3025754ejd.711.2021.06.24.08.57.01; Thu, 24 Jun 2021 08:57:25 -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=IZ8zEMil; 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 S232399AbhFXP6I (ORCPT + 99 others); Thu, 24 Jun 2021 11:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbhFXP6H (ORCPT ); Thu, 24 Jun 2021 11:58:07 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F0A4C06175F for ; Thu, 24 Jun 2021 08:55:48 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id q192so5532977pfc.7 for ; Thu, 24 Jun 2021 08:55:48 -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=YJFR7rMJgjSCjddzLV99+gcsv72cCY4rcuJfLx7ix2M=; b=IZ8zEMilmar/QDVLgl1NDX/TTwxyjXxS5kA1fSnBE6n5IfzENsPcNaND27UjFp5jiN u8HH6B7JIXK5EX6f67y7l9dDoZ++rPB0nrtDbiVwhfF52n//6y1BzEqiBhQhAh+kBIK8 UMPl2mPih9xqS2jFSSaq+Fm8SSizc0d0wP3VY= 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=YJFR7rMJgjSCjddzLV99+gcsv72cCY4rcuJfLx7ix2M=; b=atkN5UpsYhGWAGw5i00WF06Gla3WxML3rc5Q5ECPhYmdlgt8jCATn0zchkmeD6/mn6 +2/4fFYi+BHVrws+v3uKXWzEZCm2IOqceTA/46AeYKfaSJDe7wF+JwBkhi3bvzk0jzx+ 3AxwqSKV1T7l/szQopgSqDgoFmnf/AdQX1eY1lKk1vLVNujrGqB/BmVNMXUurMQMjcHI Kn0tjoVVNuUkdjNrrvH8ATd6dWdMLoe/4i8C9Oz5Vv3sU9ZJY2eGa8U+CRufGfkpyhmW hoQtxnzzQGSBwP1S5hTpNCTkm+zGvNb72mkV0BRd9/k/GlaMomJRRB2wByKT0g5aPUYu DaQg== X-Gm-Message-State: AOAM532IPkPuBUueq3Vux3bk//pBBxMiAs786xBUk/1hYJsT0Fp13XUI YDpAigs9Dlr5kN9YhJVay76IuA== X-Received: by 2002:a63:d908:: with SMTP id r8mr5249237pgg.414.1624550147592; Thu, 24 Jun 2021 08:55:47 -0700 (PDT) Received: from localhost ([2401:fa00:95:205:165a:99ec:42d5:d8b]) by smtp.gmail.com with UTF8SMTPSA id f12sm3216544pfc.100.2021.06.24.08.55.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 08:55:47 -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, quic_qiancai@quicinc.com Subject: [PATCH v15 01/12] swiotlb: Refactor swiotlb init functions Date: Thu, 24 Jun 2021 23:55:15 +0800 Message-Id: <20210624155526.2775863-2-tientzu@chromium.org> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210624155526.2775863-1-tientzu@chromium.org> References: <20210624155526.2775863-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 Acked-by: Stefano Stabellini --- 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