Received: by 10.223.176.5 with SMTP id f5csp2644432wra; Mon, 29 Jan 2018 01:26:54 -0800 (PST) X-Google-Smtp-Source: AH8x224jIpsM8HFiHuVzYOq2Xp16e+nVpUOWh7q4XPrN/yGblEsFVO3z9Lvo4xUQTRQFjS5U58cQ X-Received: by 2002:a17:902:8d85:: with SMTP id v5-v6mr21199167plo.37.1517218014653; Mon, 29 Jan 2018 01:26:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517218014; cv=none; d=google.com; s=arc-20160816; b=g6m5ErUK4sFcg//evX9/weIY8ZBb9L7t0IWzUoGWslGE8a8RnaytK5JWzs9ZTQiu0+ y3+GyiJ0Zry31HG2bM86VAGKwOz+0sKs7j9ClCK3ruL/IIeDNiMetrPvuzqeKKkW7NgV 1Qssiy3hyJow7rcIvnbTYs5Kbec94c6mwL1dhNbQHt7Fnon4auvid8AUN7l40Bx2rhm/ obVeqMrZRk+I2GoVtn5pvuCNuGN/qM/25dddD6W6x1kyWEgVB/Wf7Bc3u2mja6eWLbyL 0Q/DCyw/v2YyasG2i2gnll1yB3dhbxsAIPZL5bf66ZXntgcqoapleD6ZZAr1Iu/47EOX RxOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=0IBzPcmBIQ4zRxSxR6HOjvXUI9V0GDDcgWMixQvWr8o=; b=AedF0M5Sp5QUOKdpnneFpORvXh6Qg2Ml3L0r5gXHm/MhJyM0aXzOrLOBHwDGoQhNXg hBlsYY1UfQiW1mfdoJvz/GLTOsSKd49sThkNu5fhpV56/PWtcj6Vmv0HM3U+dDezDQDe 2pMgUgsc4rJywGg3swqcHAl3iXIaCYuwDcsBMtjPeZheh8yedjOI7ZFOjX6yO02GAQSu 2Inu2VnHi0rECrKYh6m7hk6hSHXknfl0BpNO8gdJHU0PidUS/M5H+Ix8qHtAdL/L/fmJ x5wGm0GLr/slklt+KQXaaG19rB4ufqOIabHerhwo1cFKJmqSXsZJ8IhuMKoHaycDf6vN r+xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hT/jlRYX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j72si2956340pfk.24.2018.01.29.01.26.14; Mon, 29 Jan 2018 01:26:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hT/jlRYX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751412AbeA2JZM (ORCPT + 99 others); Mon, 29 Jan 2018 04:25:12 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:35928 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbeA2JZJ (ORCPT ); Mon, 29 Jan 2018 04:25:09 -0500 Received: by mail-it0-f68.google.com with SMTP id n206so6115705itg.1 for ; Mon, 29 Jan 2018 01:25:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=0IBzPcmBIQ4zRxSxR6HOjvXUI9V0GDDcgWMixQvWr8o=; b=hT/jlRYX42bdbQnR50PMMc5sEUd9dNnPq5qUSdXYIqsOp4gTOlJnITMlRF640K9Wo4 vq/m1qT18UJEdN0Pf12OAhWCO131cDrw+J5OUQ/DeseM14q0zzr4iuoaLw1dvfKNg41x jE/l4HnaBkKuaLYJ3jKX8wp/XaXKhLRrW25Zs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=0IBzPcmBIQ4zRxSxR6HOjvXUI9V0GDDcgWMixQvWr8o=; b=K1LC6AZr5x1HuoCDR7h1nJzCfAnFpMr2OlZ5/A7qsoY+EPwiVUXORX1HpOwELpPLeF dgbxmWRxzU1uPD0rAB+AlF5DarlylBCDdxfxG0vXumDBHJdpji0yDcHYtf0Dr5mVAw78 uraBvU/B1RtdxuDm/fn7MZVy8xD+3kW0jARYRIbd8ZHxqfjc9MjGtTAdgNfmNTloN7FS BkFgRlVKiBwtOXIby9BCVzt5Ynfkvd16qFnQ9uWf89dLcv/fwZ6GZ2hFgUwNv43GxTQy c2ABRGdCGUeGynNYqDIXPc0UYuL3Cn314Jfhei0D18kEZpStiKRCDbUhkm52WzEn3LBQ ep4Q== X-Gm-Message-State: AKwxytcZxfQGwRS1a97b5s6PT7ZhVkdVusfQveVXzaV3FBtwd0DacjuN QiybxY1S/hOty51klrkEBFN4s8dbiVlG+waeJlOvKA== X-Received: by 10.36.54.203 with SMTP id l194mr26968392itl.144.1517217908698; Mon, 29 Jan 2018 01:25:08 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.102.131 with HTTP; Mon, 29 Jan 2018 01:25:07 -0800 (PST) In-Reply-To: <20180129082533.6edmqgbauo6q5dgz@flea.lan> References: <1516695531-23349-1-git-send-email-yong.deng@magewell.com> <20180129082533.6edmqgbauo6q5dgz@flea.lan> From: Linus Walleij Date: Mon, 29 Jan 2018 10:25:07 +0100 Message-ID: Subject: Re: [PATCH v6 2/2] media: V3s: Add support for Allwinner CSI. To: Maxime Ripard , Arnd Bergmann Cc: Yong Deng , Mauro Carvalho Chehab , Rob Herring , Mark Rutland , Chen-Yu Tsai , "David S. Miller" , Greg Kroah-Hartman , Hans Verkuil , Randy Dunlap , Stanimir Varbanov , Hugues Fruchet , Yannick Fertre , Philipp Zabel , Benjamin Gaignard , Ramesh Shanmugasundaram , Sakari Ailus , Rick Chang , linux-media@vger.kernel.org, "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Linux ARM , "linux-kernel@vger.kernel.org" , linux-sunxi , megous@megous.com, Thomas Petazzoni Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 29, 2018 at 9:25 AM, Maxime Ripard wrote: > On Sat, Jan 27, 2018 at 05:14:26PM +0100, Linus Walleij wrote: >> > +void sun6i_csi_update_buf_addr(struct sun6i_csi *csi, dma_addr_t addr) >> > +{ >> > + struct sun6i_csi_dev *sdev = sun6i_csi_to_dev(csi); >> > + /* transform physical address to bus address */ >> > + dma_addr_t bus_addr = addr - PHYS_OFFSET; >> >> I am sorry if this is an unjustified drive-by comment. Maybe you >> have already investigate other ways to do this. > > It's definitely not unjustified :) > >> Accessing PHYS_OFFSET directly seems unintuitive and not good >> practice. >> >> But normally an dma_addr_t only comes from some function inside >> such as: dma_alloc_coherent() for a contigous >> buffer which is coherent in physical memory, or from some buffer <= >> 64KB that is switching ownership between device and CPU explicitly >> with dma_map* or so. Did you check with Documentation/DMA-API.txt? > > So, I've discussed this with Arnd a month ago or so, because I'm not > really fond of the current approach but we haven't found better way to > do it yet. > > The issue is that all the DMA accesses are done not through the main > AXI bus, but through a separate bus dedicated for memory accesses, > where the RAM is mapped at the address 0. So the CPU and DMA devices > have a different mapping for the RAM. Aha, I see the problem ... but since the dma_addr_t is supposed to actually be the address the DMA controller sees, something is apparently broken. > I guess we could address this by using the field dma_pfn_offset that > seems to be used in similar situations. That does seem like the right thing to do (to me). > However, in DT systems, that > field is filled only with the parent's node dma-ranges property. In > our case, and since the DT parenthood is based on the "control" bus, > and not the "data" bus, our parent node would be the AXI bus, and not > the memory bus that enforce those constraints. > > And other devices doing DMA through regular DMA accesses won't have > that mapping, so we definitely shouldn't enforce it for all the > devices there, but only the one connected to the separate memory bus. > > tl; dr: the DT is not really an option to store that info. > > I suggested setting dma_pfn_offset at probe, but Arnd didn't seem too > fond of that approach either at the time. > > So, well, I guess we could do better. We just have no idea how :) Usually of Arnd cannot suggest something smart, neither can I :( If some aspect of the memory layout of the system *really* doesn't fit into DT because of the assumptions that DT is doing about how systems work, we have a problem. Is the problem that DT's model assumes that devices have one and only one data port to the system memory, and that is how it populates the Linux devices? I guess, if nothing else works, I would use auxdata in the board file. It is our definitive last resort when DT doesn't hold. I.e. I would go into struct of_dev_auxdata (from ) and add a dma_pfn_offset field that gets set into the device's dma_pfn_offset in drivers/of/platform.c overriding anything else and use that to hammer it down in the boardfile. But I bet some DT people are going to have other ideas. Yours, Linus Walleij