From patchwork Wed Apr 19 10:03:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 85298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp264908vqo; Wed, 19 Apr 2023 03:06:27 -0700 (PDT) X-Google-Smtp-Source: AKy350bkyX2ovOa6OmESr58zDbA76ByWUloyFWT830j9GnKfnDJ4vec7azIsUch5RKpX9glJ72Zz X-Received: by 2002:a05:6a20:d398:b0:ee:aa9e:945a with SMTP id iq24-20020a056a20d39800b000eeaa9e945amr2954630pzb.26.1681898786826; Wed, 19 Apr 2023 03:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681898786; cv=none; d=google.com; s=arc-20160816; b=tf4pJJ7UTf/TmR0qqreBK5ztYrOdJaTur3sL+v02DWbjvplqdUXCdfYLWIWH9H89Gs hCqQTuWEkg6oqj5bSNj8S6VQ9QeUDKk+gpccrf0U9qcz81GsmthbL2eq+PRCfz7zLXME XM3Bii04JqhG5JzZU28HyQNQhsiXv7ntDOIHA7gwWVmT7+qxw00iYs0hWQztJ6jN1SJX z0qZKoQyJEPcnJIOso2Cn1rG0xQxzeoj5ue0fekFRZ2wL3786jzepc2mVt6/5HtwwobQ mz2d45opKSUukDRlfv2H6kEH4k3raxVWdFra2Uz3nGdX2O54EWY3rW9uTVkj5cIw4rbh bqpA== 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; bh=Qn5lJU0GLFbJx5/ZN6QSf8mW1JOyc3paXyHmDcFcAuA=; b=Fr7gIN8HHXO6aku6u+hzmozACQ2R/Tmq2JJnrMg4ksm35tm2C8MgPtKYFs5IwvnRx+ 98+fP/+NApbIkyReQsYFotu1OdzBnWFh/h23tclTzsYpi9vkiWYx9R8Yw/sPCkft5FiP adDOvSHMgva882SUWminqS+bXstWgeQszh/m3UOIWHk+1sE3aVdVg1lV7NRxCracAQ7C lJoHDT3xnXHBYAyugxcQgvOkGS3Y77RiVW1kfAothDT4dhkASj+1oVN5Hln3XPrdSnxv pRtVryeuGwg5/KrbdHrEUpkCX5jAO9axsGFO44bNjUmZheL5zBiFYw4cOgc9+Z0rYTo0 +4iA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t25-20020aa79479000000b0063d27f81f05si5983880pfq.247.2023.04.19.03.06.13; Wed, 19 Apr 2023 03:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232518AbjDSKFi (ORCPT + 99 others); Wed, 19 Apr 2023 06:05:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232513AbjDSKFf (ORCPT ); Wed, 19 Apr 2023 06:05:35 -0400 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65DA0106; Wed, 19 Apr 2023 03:05:33 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4Q1blL1yGHz9xqwr; Wed, 19 Apr 2023 17:55:58 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.45.152.239]) by APP1 (Coremail) with SMTP id LxC2BwAXi_aYvD9k7TY6Ag--.1944S3; Wed, 19 Apr 2023 11:04:48 +0100 (CET) From: Petr Tesarik To: Jonathan Corbet , Greg Kroah-Hartman , "Rafael J. Wysocki" , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Borislav Petkov , "Paul E. McKenney" , Catalin Marinas , Will Deacon , Zhen Lei , Randy Dunlap , Damien Le Moal , Kim Phillips , "Steven Rostedt (Google)" , Muchun Song , Ondrej Zary , "Jason A. Donenfeld" , Petr Tesarik , Hans de Goede , Dan Williams , Andy Shevchenko , Kees Cook , Thomas Gleixner , Won Chung , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list), dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), iommu@lists.linux.dev (open list:DMA MAPPING HELPERS) Cc: Roberto Sassu , Kefeng Wang , petr@tesarici.cz Subject: [PATCH v2 1/7] swiotlb: Use a helper to initialize swiotlb fields in struct device Date: Wed, 19 Apr 2023 12:03:53 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: LxC2BwAXi_aYvD9k7TY6Ag--.1944S3 X-Coremail-Antispam: 1UD129KBjvJXoW7Ww4DuF1Utry5Cry7Jw1xuFg_yoW8ZrWUpF 97Aay5KFW2gFZ7CrW7C3s7JF1fKan7Ca4xCrya9wn5CFnxJF9xJFyDJrW5Arn5Jr409F4f JFySvry5CF17Aw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmmb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV WxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ew Av7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY 6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxkF7I0En4kS14 v26r1q6r43MxkF7I0Ew4C26cxK6c8Ij28IcwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE 7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI 8E67AF67kF1VAFwI0_Wrv_Gr1UMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_ JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr 0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1U YxBIdaVFxhVjvjDU0xZFpf9x07j50eQUUUUU= X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763598702276962335?= X-GMAIL-MSGID: =?utf-8?q?1763598702276962335?= From: Petr Tesarik Move swiotlb initialization code to swiotlb.h. This change also allows to provide a stub implementation if swiotlb is not configured, getting rid of an #ifdef in driver core. Signed-off-by: Petr Tesarik --- drivers/base/core.c | 4 +--- include/linux/swiotlb.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 6878dfcbf0d6..a5dc7c673102 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3060,9 +3060,7 @@ void device_initialize(struct device *dev) defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) dev->dma_coherent = dma_default_coherent; #endif -#ifdef CONFIG_SWIOTLB - dev->dma_io_tlb_mem = &io_tlb_default_mem; -#endif + swiotlb_dev_init(dev); } EXPORT_SYMBOL_GPL(device_initialize); diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index bcef10e20ea4..b65b7330f7e5 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -119,6 +119,15 @@ static inline bool is_swiotlb_force_bounce(struct device *dev) return mem && mem->force_bounce; } +/** + * swiotlb_dev_init() - initialize swiotlb fields in &struct device + * @dev: device to be initialized + */ +static inline void swiotlb_dev_init(struct device *dev) +{ + dev->dma_io_tlb_mem = &io_tlb_default_mem; +} + void swiotlb_init(bool addressing_limited, unsigned int flags); void __init swiotlb_exit(void); size_t swiotlb_max_mapping_size(struct device *dev); @@ -128,6 +137,9 @@ void __init swiotlb_adjust_size(unsigned long size); static inline void swiotlb_init(bool addressing_limited, unsigned int flags) { } +static inline void swiotlb_dev_init(struct device *dev) +{ +} static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr) { return false;