From patchwork Tue Jan 27 08:25:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 43815 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 017BE2409D for ; Tue, 27 Jan 2015 08:26:21 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id b6sf6786029lbj.0 for ; Tue, 27 Jan 2015 00:26:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:subject:date :message-id:cc:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=Ro3dxCzSZ72gjxm3HjpQUZjzTIPzmmixhF/EP/mGjGE=; b=a4JGq0t71MpzjITaL0+kK5zB70rU67QyIgbaVOm7Z/TTJJPDhmh1ZDFByzM4OGG9LY vMGI0nmGk+uXuOny0jAI7kPf50J59hPhgk6FTdC3y/ZIW4KB+4fkZO9hZVqCvyKP40wm mBMtzL6V/HQsdmdqkKRplcwY0h5ONC/lp63JXZtDhc9RObEambsunm66nngfOpFHrwEF 4UGMkZJfxFkXs7L6aYPBpmq+/5yCu656e5tmGnP+Yzohb69ZWYpmS5CmXgCV2utu2HV0 bfbuMS4AoxThVQAPbKIA46LcVjCudZV22MahAnbwY6R6kNJRlL0ZC2mTxA9GU1Lu9Un9 9jTA== X-Gm-Message-State: ALoCoQl3nSFWs/lZtfDirFM2xWx5Aa51Yi4AjUPEwTbq945Lxok414cHZ6YB/Isjz8GGB3dOnJ7E X-Received: by 10.194.204.201 with SMTP id la9mr22162wjc.6.1422347180003; Tue, 27 Jan 2015 00:26:20 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.67 with SMTP id g3ls4163lab.25.gmail; Tue, 27 Jan 2015 00:26:19 -0800 (PST) X-Received: by 10.112.167.68 with SMTP id zm4mr2601756lbb.93.1422347179847; Tue, 27 Jan 2015 00:26:19 -0800 (PST) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id s8si518658laj.69.2015.01.27.00.26.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:26:19 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id q1so12005078lam.2 for ; Tue, 27 Jan 2015 00:26:19 -0800 (PST) X-Received: by 10.112.98.99 with SMTP id eh3mr145167lbb.32.1422347179644; Tue, 27 Jan 2015 00:26:19 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1023136lbj; Tue, 27 Jan 2015 00:26:18 -0800 (PST) X-Received: by 10.70.43.8 with SMTP id s8mr95373pdl.114.1422347177748; Tue, 27 Jan 2015 00:26:17 -0800 (PST) Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id he4si586539pbc.187.2015.01.27.00.26.16; Tue, 27 Jan 2015 00:26:17 -0800 (PST) Received-SPF: none (google.com: dri-devel-bounces@lists.freedesktop.org does not designate permitted sender hosts) client-ip=131.252.210.177; Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 225036E30E; Tue, 27 Jan 2015 00:26:16 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by gabe.freedesktop.org (Postfix) with ESMTP id A83696E30E for ; Tue, 27 Jan 2015 00:26:15 -0800 (PST) Received: by mail-pa0-f43.google.com with SMTP id eu11so17136930pac.2 for ; Tue, 27 Jan 2015 00:26:15 -0800 (PST) X-Received: by 10.66.120.109 with SMTP id lb13mr160642pab.66.1422347175232; Tue, 27 Jan 2015 00:26:15 -0800 (PST) Received: from ss-ubuntu.lan ([106.51.225.38]) by mx.google.com with ESMTPSA id l4sm783884pdj.47.2015.01.27.00.26.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jan 2015 00:26:14 -0800 (PST) From: Sumit Semwal To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: [RFCv3 1/2] device: add dma_params->max_segment_count Date: Tue, 27 Jan 2015 13:55:53 +0530 Message-Id: <1422347154-15258-1-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 1.9.1 Cc: linaro-kernel@lists.linaro.org, stanislawski.tomasz@googlemail.com, robin.murphy@arm.com, m.szyprowski@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sumit.semwal@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Rob Clark For devices which have constraints about maximum number of segments in an sglist. For example, a device which could only deal with contiguous buffers would set max_segment_count to 1. The initial motivation is for devices sharing buffers via dma-buf, to allow the buffer exporter to know the constraints of other devices which have attached to the buffer. The dma_mask and fields in 'struct device_dma_parameters' tell the exporter everything else that is needed, except whether the importer has constraints about maximum number of segments. Signed-off-by: Rob Clark [sumits: Minor updates wrt comments] Signed-off-by: Sumit Semwal --- v3: include Robin Murphy's fix[1] for handling '0' as a value for max_segment_count v2: minor updates wrt comments on the first version [1]: http://article.gmane.org/gmane.linux.kernel.iommu/8175/ include/linux/device.h | 1 + include/linux/dma-mapping.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index fb506738f7b7..a32f9b67315c 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -647,6 +647,7 @@ struct device_dma_parameters { * sg limitations. */ unsigned int max_segment_size; + unsigned int max_segment_count; /* INT_MAX for unlimited */ unsigned long segment_boundary_mask; }; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index c3007cb4bfa6..d3351a36d5ec 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -154,6 +154,25 @@ static inline unsigned int dma_set_max_seg_size(struct device *dev, return -EIO; } +#define DMA_SEGMENTS_MAX_SEG_COUNT ((unsigned int) INT_MAX) + +static inline unsigned int dma_get_max_seg_count(struct device *dev) +{ + if (dev->dma_parms && dev->dma_parms->max_segment_count) + return dev->dma_parms->max_segment_count; + return DMA_SEGMENTS_MAX_SEG_COUNT; +} + +static inline int dma_set_max_seg_count(struct device *dev, + unsigned int count) +{ + if (dev->dma_parms) { + dev->dma_parms->max_segment_count = count; + return 0; + } + return -EIO; +} + static inline unsigned long dma_get_seg_boundary(struct device *dev) { return dev->dma_parms ?