From patchwork Mon May 10 14:17:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 433145 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2895213jao; Mon, 10 May 2021 07:25:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxoM3W6fAfV1KyrskhNtvNEg9YaqbF9/TkWzqorbiIGpiLFWmizyHtftuERnxUzRVEGWT+ X-Received: by 2002:a92:2a12:: with SMTP id r18mr21413006ile.170.1620656745456; Mon, 10 May 2021 07:25:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620656745; cv=none; d=google.com; s=arc-20160816; b=kTi1EUz23fQOjCuYzlnFt2usbK0X7FCCbGcv4SlNqLBIjN6zFaQPcv2sFtWkU+sJQb YtlvF46s4mzTays428legngn9Rx4oDFX3olUG9BsNRXA5/tNvWydQrD93iszUSkxIuLw /myjZhG5ZfhllQAY0qAwkpkd7a4/SFm4K/hCfWbNslb3Uj2NqMwwxORDEPK2MeuXKcVE LBkaYEHV/qnpTaLJd4G/bQ+XLP+QqUgOyBujgRcm4/YJYr/ABHhoMZ3NuiL2jN9330bV Wx/Ev7c2L8ghiGi4ZIJWVq7KfGNC+Z/iR5uRrhtv5x4Vwmz/ixZRIMyevSoGa0L+if+d EXZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=So/e+f3iqa0YCU0ukfuZrV7EnxP1XudXwqwF5ltFSOA=; b=VLzVrR6q2L1LpwQW+CHH6r1ztYRSuQLI7tk5T8pJnNPMxE2ntqjksDga8YQZWb6csN 36JqHX+54zgeH4NbATyuGJ1LOvzhnCQ1Vg+mVIt434Nrs0Mc+NQ6VMclzpHMrp+sJyyT 0AX0Z2bu4FLHLkeIWAjKBLC9yzvqArzgZT44M+Ifj+iY6fF8dx7YytojpIMzrHSrZBzj NjY4K/RX42Z8vbpfqFGc/juXcvA/k4Ni1lAwsbOgbYj1mxGKn8EEe73zzcER2LiptcoU mLffOmC8XFk9ZgvO3kFjzY3f6pXLPRRX1KPQzscQfvyNVog8k8zBSYFbveV3jMS7aqSF Ze+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k8si18487873jav.68.2021.05.10.07.25.45 for ; Mon, 10 May 2021 07:25:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232976AbhEJO0s (ORCPT ); Mon, 10 May 2021 10:26:48 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2678 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235417AbhEJOXq (ORCPT ); Mon, 10 May 2021 10:23:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ff39B55RDz1BKvf; Mon, 10 May 2021 22:19:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Mon, 10 May 2021 22:22:28 +0800 From: John Garry To: , , , , CC: , , , , , , John Garry Subject: [PATCH v2 13/15] dma-mapping: Add dma_set_max_opt_size() Date: Mon, 10 May 2021 22:17:27 +0800 Message-ID: <1620656249-68890-14-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1620656249-68890-1-git-send-email-john.garry@huawei.com> References: <1620656249-68890-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to allow the max size which we want to optimise DMA mappings for. Signed-off-by: John Garry --- include/linux/dma-map-ops.h | 1 + include/linux/dma-mapping.h | 8 ++++++++ kernel/dma/mapping.c | 11 +++++++++++ 3 files changed, 20 insertions(+) -- 2.26.2 diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 0d53a96a3d64..7f9857da87d8 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -69,6 +69,7 @@ struct dma_map_ops { u64 (*get_required_mask)(struct device *dev); size_t (*max_mapping_size)(struct device *dev); unsigned long (*get_merge_boundary)(struct device *dev); + int (*set_max_opt_size)(struct device *dev, size_t size); }; #ifdef CONFIG_DMA_OPS diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 183e7103a66d..41681db93580 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -153,6 +153,7 @@ void *dma_vmap_noncontiguous(struct device *dev, size_t size, void dma_vunmap_noncontiguous(struct device *dev, void *vaddr); int dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma, size_t size, struct sg_table *sgt); +int dma_set_max_opt_size(struct device *dev, size_t size); #else /* CONFIG_HAS_DMA */ static inline dma_addr_t dma_map_page_attrs(struct device *dev, struct page *page, size_t offset, size_t size, @@ -266,6 +267,7 @@ static inline unsigned long dma_get_merge_boundary(struct device *dev) { return 0; } + static inline struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size, enum dma_data_direction dir, gfp_t gfp, unsigned long attrs) @@ -289,6 +291,12 @@ static inline int dma_mmap_noncontiguous(struct device *dev, { return -EINVAL; } + +static inline int dma_set_max_opt_size(struct device *dev, size_t size) +{ + return -EINVAL; +} + #endif /* CONFIG_HAS_DMA */ struct page *dma_alloc_pages(struct device *dev, size_t size, diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 2b06a809d0b9..1e4820b08f7e 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -736,3 +736,14 @@ unsigned long dma_get_merge_boundary(struct device *dev) return ops->get_merge_boundary(dev); } EXPORT_SYMBOL_GPL(dma_get_merge_boundary); + +int dma_set_max_opt_size(struct device *dev, size_t size) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + + if (!ops || !ops->set_max_opt_size) + return 0; + + return ops->set_max_opt_size(dev, size); +} +EXPORT_SYMBOL_GPL(dma_set_max_opt_size);