From patchwork Mon May 5 21:47:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 29681 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2790F202E6 for ; Mon, 5 May 2014 21:48:22 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id wp4sf45348137obc.0 for ; Mon, 05 May 2014 14:48:21 -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=rDWA+5WVS24KaJSZmGLNQl70lustaFHGuIh4cQWtz5s=; b=SRYQae5bwJJ4D9gOi22LGDXhMQeyaXkBpO6cLuIYTySmH1OwjYiqslAOVPC9aqTM0c HHYjKFAGBi5ik6Z36pI5UxP5ibPNXo/Pe8nnVjF2qrIlWDKelG+sXh312YwJXA7yfLNh 2XqXkJzhbCZGwEQXwff3t0VPcdYJxnu0u18ZfqMSktM6+QpVSiuq+QJ9HzcTPvL6iCUo 6UlYZW12rIiMUYqne1edfz9K2rO7gnZyfypR612W9CLcQyAci1BpGtB7Zh1dY/qdcxxo g6JqvWeQFfihp48waPBncAMsvEvGci6agCLRYXY49t7HQluUpkpuWLzFU8xqywb+l2A0 MiLg== X-Gm-Message-State: ALoCoQnwHunvLphApeY6ZGPLi3gUtOeX70bcG14+woWq3EABzKaD3gcaVtxmNDq161tKslyJHer0 X-Received: by 10.182.60.37 with SMTP id e5mr18516219obr.30.1399326501675; Mon, 05 May 2014 14:48:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.112 with SMTP id n103ls2645334qga.86.gmail; Mon, 05 May 2014 14:48:21 -0700 (PDT) X-Received: by 10.52.53.101 with SMTP id a5mr25247082vdp.14.1399326501517; Mon, 05 May 2014 14:48:21 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id ud8si1887026vdc.51.2014.05.05.14.48.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 May 2014 14:48:21 -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.128.178; Received: by mail-ve0-f178.google.com with SMTP id sa20so3353526veb.9 for ; Mon, 05 May 2014 14:48:21 -0700 (PDT) X-Received: by 10.220.105.130 with SMTP id t2mr29629789vco.18.1399326501435; Mon, 05 May 2014 14:48:21 -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 ib8csp174337vcb; Mon, 5 May 2014 14:48:20 -0700 (PDT) X-Received: by 10.66.119.136 with SMTP id ku8mr77420468pab.121.1399326500393; Mon, 05 May 2014 14:48:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fn10si9836766pad.238.2014.05.05.14.48.19; Mon, 05 May 2014 14:48:19 -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 S932135AbaEEVsK (ORCPT + 27 others); Mon, 5 May 2014 17:48:10 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:52325 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756763AbaEEVsG (ORCPT ); Mon, 5 May 2014 17:48:06 -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 s45LlXD0005697; Mon, 5 May 2014 16:47:33 -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 s45LlXFR032547; Mon, 5 May 2014 16:47:33 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Mon, 5 May 2014 16:47:33 -0500 Received: from [158.218.103.31] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s45LlWb7009322; Mon, 5 May 2014 16:47:32 -0500 Message-ID: <536806F4.1090904@ti.com> Date: Mon, 5 May 2014 17:47:32 -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: Rob Herring CC: "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "devicetree@vger.kernel.org" , Greg Kroah-Hartman , Russell King , Arnd Bergmann , Olof Johansson , Grant Likely , Rob Herring , Catalin Marinas , Linus Walleij , Grygorii Strashko Subject: Re: [PATCH v3 4/7] of: configure the platform device dma parameters References: <1398353407-2345-1-git-send-email-santosh.shilimkar@ti.com> <1398353407-2345-5-git-send-email-santosh.shilimkar@ti.com> In-Reply-To: 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 Thursday 01 May 2014 08:49 PM, Rob Herring wrote: > On Thu, Apr 24, 2014 at 10:30 AM, Santosh Shilimkar > wrote: >> 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. >> > > [...] > >> + /* >> + * 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 == -ENODEV) || (ret < 0)) { > > The 1st condition is redundant. > >> + 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 >> @@ -214,9 +258,7 @@ static struct platform_device *of_platform_device_create_pdata( >> #if defined(CONFIG_MICROBLAZE) >> dev->archdata.dma_mask = 0xffffffffUL; >> #endif > > This is also dma related setup. Please move *all* dma setup into the function. > Updated patch with above minor updates. >From 80a9f06a09a90801d8ee337d9b2d155c43da8f23 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: Rob Herring Cc: Catalin Marinas Cc: Linus Walleij Signed-off-by: Grygorii Strashko Signed-off-by: Santosh Shilimkar Reviewed-by: Rob Herring --- drivers/of/platform.c | 55 ++++++++++++++++++++++++++++++++++++++----- include/linux/dma-mapping.h | 7 ++++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 404d1da..b71e089 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -187,6 +187,54 @@ 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 + dev->coherent_dma_mask = DMA_BIT_MASK(32); + 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 +259,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;