From patchwork Wed May 7 13:24:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 29764 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 66667202E4 for ; Wed, 7 May 2014 13:25:10 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id i4sf4968870oah.1 for ; Wed, 07 May 2014 06:25:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-transfer-encoding; bh=7ylOZVMTD11/2M8b8u7Y2hbRAYR6/WGJV0QgYrdSqck=; b=cK5SDJ/i2x/N6Hl/yQhqxqtWd2j1nj5SIm++ACFBl8/YnkJ5QVziin88pce8ZoJv41 DWxuOiLgAt+2LOffmt7zgLfDIMEovNM++1wr/yl/VQjwU5Cdlgyc+xgASxQ7Xydz8c6D xM025tEnsjUc71YPlP7f6JrfjVEUSFQprhlT/X1PzMMFJow3gPN1WQDtmqzaNbTakaPv reff2umJn71qaoao7JbJ2dkzS7bNcTb10StOcrqPn+SKjMwHOWj6QvB5n+d4kRN/sMoy Lgc/lZBIJ7G7z/xi+ROqKaQcQU4VCfr6ZkX7ExWFUUnU3Y8cDq4lVzYu1GXoT49oZbe2 ZUFA== X-Gm-Message-State: ALoCoQkbil+ZefU1Qtlqqv1ljYkgylAMC22L9uuTPyVbkGhFBEwk6GR8UWpZruwunP06DeOZT1iU X-Received: by 10.182.153.68 with SMTP id ve4mr4412539obb.39.1399469110107; Wed, 07 May 2014 06:25:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.233 with SMTP id l96ls3410284qgl.90.gmail; Wed, 07 May 2014 06:25:10 -0700 (PDT) X-Received: by 10.52.244.194 with SMTP id xi2mr399122vdc.91.1399469109950; Wed, 07 May 2014 06:25:09 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id sr19si2906843vcb.71.2014.05.07.06.25.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 May 2014 06:25:09 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id il7so1250323vcb.18 for ; Wed, 07 May 2014 06:25:09 -0700 (PDT) X-Received: by 10.52.130.225 with SMTP id oh1mr32327605vdb.8.1399469109865; Wed, 07 May 2014 06:25:09 -0700 (PDT) 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.220.221.72 with SMTP id ib8csp308780vcb; Wed, 7 May 2014 06:25:09 -0700 (PDT) X-Received: by 10.66.147.130 with SMTP id tk2mr19117902pab.125.1399469107774; Wed, 07 May 2014 06:25:07 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hi3si13812311pac.205.2014.05.07.06.25.06; Wed, 07 May 2014 06:25:06 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933880AbaEGNY5 (ORCPT + 27 others); Wed, 7 May 2014 09:24:57 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:60742 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933211AbaEGNYy (ORCPT ); Wed, 7 May 2014 09:24:54 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s47DOBRV016905; Wed, 7 May 2014 08:24:11 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s47DOAkr012967; Wed, 7 May 2014 08:24:10 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Wed, 7 May 2014 08:24:10 -0500 Received: from [158.218.103.31] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s47DO91w010177; Wed, 7 May 2014 08:24:09 -0500 Message-ID: <536A33F9.3040406@ti.com> Date: Wed, 7 May 2014 09:24:09 -0400 From: Santosh Shilimkar User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Arnd Bergmann CC: Rob Herring , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "devicetree@vger.kernel.org" , Greg Kroah-Hartman , Russell King , Olof Johansson , Grant Likely , Rob Herring , Catalin Marinas , Linus Walleij , "Strashko, Grygorii" Subject: Re: [PATCH v3 4/7] of: configure the platform device dma parameters References: <1398353407-2345-1-git-send-email-santosh.shilimkar@ti.com> <536806F4.1090904@ti.com> <7182186.5Q53eQg77F@wuerfel> <536949B8.3030106@ti.com> In-Reply-To: <536949B8.3030106@ti.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: santosh.shilimkar@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On Tuesday 06 May 2014 04:44 PM, Santosh Shilimkar wrote: > On Tuesday 06 May 2014 05:40 AM, Arnd Bergmann wrote: >> On Monday 05 May 2014 17:47:32 Santosh Shilimkar wrote: >> >>> + dev->coherent_dma_mask = DMA_BIT_MASK(32); >>> + if (!dev->dma_mask) >>> + dev->dma_mask = &dev->coherent_dma_mask; >>> + >>> + /* >>> + * if dma-ranges property doesn't exist - just return else >>> + * setup the dma offset >>> + */ >>> + ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); >>> + if (ret < 0) { >>> + dev_dbg(dev, "no dma range information to setup\n"); >>> + return; >>> + } >>> + >>> + /* DMA ranges found. Calculate and set dma_pfn_offset */ >>> + dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr); >>> + dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset); >>> +} >> >> I think there should at least be a comment about why we are computing >> the correct DMA mask here and then ignore that and just use DMA_BIT_MASK(32) >> instead. I understand that Russell and Rob prefer it that way and I'm not >> going to argue, but I find it counterintuitive and I think it deserves >> an explanation in the source code for anybody who is trying to figure >> out how things fit together. >> > In this patch, the dma_mask related code is just moved. We are not calculating > dma_mask either. I was looking for the history of how DMA_BIT_MASK(32) > landed up but couldn't trace it down apart from the fact that the code was > carried from powerPC. May be Rob knows. > > How about below comment ? I didn't delibratly added point about bus > intercepting drivers dma_set_*mask() call etc. > > /* > * Set default dma-mask to 32 bit. Drivers are expected to setup > * the correct supported dma_mask. > */ > + dev->coherent_dma_mask = DMA_BIT_MASK(32); > + if (!dev->dma_mask) > + dev->dma_mask = &dev->coherent_dma_mask; > Updated patch below for records. >From 591c1ee465ce5372385dbc41e7d3e36cbb477bd8 Mon Sep 17 00:00:00 2001 From: Santosh Shilimkar Date: Thu, 24 Apr 2014 11:30:04 -0400 Subject: [PATCH v3 4/7] of: configure the platform device dma parameters Retrieve DMA configuration from DT and setup platform device's DMA parameters. The DMA configuration in DT has to be specified using "dma-ranges" and "dma-coherent" properties if supported. We setup dma_pfn_offset using "dma-ranges" and dma_coherent_ops using "dma-coherent" device tree properties. The set_arch_dma_coherent_ops macro has to be defined by arch if it supports coherent dma_ops. Otherwise, set_arch_dma_coherent_ops() is declared as nop. Cc: Greg Kroah-Hartman Cc: Russell King Cc: Arnd Bergmann Cc: Olof Johansson Cc: Grant Likely Cc: Catalin Marinas Cc: Linus Walleij Reviewed-by: Rob Herring Signed-off-by: Grygorii Strashko Signed-off-by: Santosh Shilimkar --- drivers/of/platform.c | 65 +++++++++++++++++++++++++++++++++++++++---- include/linux/dma-mapping.h | 7 +++++ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 404d1da..91fa983 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -187,6 +187,64 @@ struct platform_device *of_device_alloc(struct device_node *np, EXPORT_SYMBOL(of_device_alloc); /** + * of_dma_configure - Setup DMA configuration + * @dev: Device to apply DMA configuration + * + * Try to get devices's DMA configuration from DT and update it + * accordingly. + * + * In case if platform code need to use own special DMA configuration,it + * can use Platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE event + * to fix up DMA configuration. + */ +static void of_dma_configure(struct platform_device *pdev) +{ + u64 dma_addr, paddr, size; + int ret; + struct device *dev = &pdev->dev; + +#if defined(CONFIG_MICROBLAZE) + pdev->archdata.dma_mask = 0xffffffffUL; +#endif + + /* + * Set default dma-mask to 32 bit. Drivers are expected to setup + * the correct supported dma_mask. + */ + dev->coherent_dma_mask = DMA_BIT_MASK(32); + + /* + * Set it to coherent_dma_mask by default if the architecture + * code has not set it. + */ + if (!dev->dma_mask) + dev->dma_mask = &dev->coherent_dma_mask; + + /* + * if dma-coherent property exist, call arch hook to setup + * dma coherent operations. + */ + if (of_dma_is_coherent(dev->of_node)) { + set_arch_dma_coherent_ops(dev); + dev_dbg(dev, "device is dma coherent\n"); + } + + /* + * if dma-ranges property doesn't exist - just return else + * setup the dma offset + */ + ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); + if (ret < 0) { + dev_dbg(dev, "no dma range information to setup\n"); + return; + } + + /* DMA ranges found. Calculate and set dma_pfn_offset */ + dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr); + dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset); +} + +/** * of_platform_device_create_pdata - Alloc, initialize and register an of_device * @np: pointer to node to create device for * @bus_id: name to assign device @@ -211,12 +269,7 @@ static struct platform_device *of_platform_device_create_pdata( if (!dev) return NULL; -#if defined(CONFIG_MICROBLAZE) - dev->archdata.dma_mask = 0xffffffffUL; -#endif - dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); - if (!dev->dev.dma_mask) - dev->dev.dma_mask = &dev->dev.coherent_dma_mask; + of_dma_configure(dev); dev->dev.bus = &platform_bus_type; dev->dev.platform_data = platform_data; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index fd4aee2..c7d9b1b 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -123,6 +123,13 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask) extern u64 dma_get_required_mask(struct device *dev); +#ifndef set_arch_dma_coherent_ops +static inline int set_arch_dma_coherent_ops(struct device *dev) +{ + return 0; +} +#endif + static inline unsigned int dma_get_max_seg_size(struct device *dev) { return dev->dma_parms ? dev->dma_parms->max_segment_size : 65536;