From: Jim Quinlan via iommu <iommu@lists.linux-foundation.org> To: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Ulf Hansson <ulf.hansson@linaro.org>, Rich Felker <dalias@libc.org>, "open list:SUPERH" <linux-sh@vger.kernel.org>, David Airlie <airlied@linux.ie>, "open list:PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS" <linux-pci@vger.kernel.org>, Hanjun Guo <guohanjun@huawei.com>, "open list:REMOTE PROCESSOR \(REMOTEPROC\) SUBSYSTEM" <linux-remoteproc@vger.kernel.org>, "open list:DRM DRIVERS FOR ALLWINNER A10" <dri-devel@lists.freedesktop.org>, Julien Grall <julien.grall@arm.com>, Heikki Krogerus <heikki.krogerus@linux.intel.com>, "H. Peter Anvin" <hpa@zytor.com>, Will Deacon <will@kernel.org>, Christoph Hellwig <hch@lst.de>, "open list:STAGING SUBSYSTEM" <devel@driverdev.osuosl.org>, Yoshinori Sato <ysato@users.sourceforge.jp>, Frank Rowand <frowand.list@gmail.com>, "maintainer:X86 ARCHITECTURE \(32-BIT AND 64-BIT\)" <x86@kernel.org>, Russell King <linux@armlinux.org.uk>, "open list:ACPI FOR ARM64 \(ACPI/arm64\)" <linux-acpi@vger.kernel.org>, Chen-Yu Tsai <wens@csie.org>, Ingo Molnar <mingo@redhat.com>, "maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE" <bcm-kernel-feedback-list@broadcom.com>, Alan Stern <stern@rowland.harvard.edu>, Len Brown <lenb@kernel.org>, Ohad Ben-Cohen <ohad@wizery.com>, "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" <devicetree@vger.kernel.org>, Arnd Bergmann <arnd@arndb.de>, Suzuki K Poulose <suzuki.poulose@arm.com>, Maxime Ripard <mripard@kernel.org>, Rob Herring <robh+dt@kernel.org>, Borislav Petkov <bp@alien8.de>, Yong Deng <yong.deng@magewell.com>, Santosh Shilimkar <ssantosh@kernel.org>, Bjorn Helgaas <bhelgaas@google.com>, Thomas Gleixner <tglx@linutronix.de>, Mauro Carvalho Chehab <mchehab@kernel.org>, "moderated list:ARM PORT" <linux-arm-kernel@lists.infradead.org>, Saravana Kannan <saravanak@google.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Oliver Neukum <oneukum@suse.com>, "Rafael J. Wysocki" <rjw@rjwysocki.net>, open list <linux-kernel@vger.kernel.org>, Paul Kocialkowski <paul.kocialkowski@bootlin.com>, "open list:IOMMU DRIVERS" <iommu@lists.linux-foundation.org>, "open list:USB SUBSYSTEM" <linux-usb@vger.kernel.org>, Stefano Stabellini <sstabellini@kernel.org>, Daniel Vetter <daniel@ffwll.ch>, Sudeep Holla <sudeep.holla@arm.com>, "open list:ALLWINNER A10 CSI DRIVER" <linux-media@vger.kernel.org>, Robin Murphy <robin.murphy@arm.com>, Nicolas Saenz Julienne <nsaenzjulienne@suse.de> Subject: Re: [PATCH v6 08/12] device core: Introduce DMA range map, supplanting dma_pfn_offset Date: Mon, 6 Jul 2020 09:40:40 -0400 [thread overview] Message-ID: <CA+-6iNwu-jHTb7VFpmkYoyipWK9rtTEOq2dW7K=nYXpUrOTwCQ@mail.gmail.com> (raw) In-Reply-To: <20200702084251.GF3703480@smile.fi.intel.com> Hi Andy, Sorry for the delay in response. I will do what you suggest in your email. I do have one response to one of your comments below. On Thu, Jul 2, 2020 at 4:43 AM Andy Shevchenko <andriy.shevchenko@linux.intePHYSl.com> wrote: > > On Wed, Jul 01, 2020 at 05:21:38PM -0400, Jim Quinlan wrote: > > The new field 'dma_range_map' in struct device is used to facilitate the > > use of single or multiple offsets between mapping regions of cpu addrs and > > dma addrs. It subsumes the role of "dev->dma_pfn_offset" which was only > > capable of holding a single uniform offset and had no region bounds > > checking. > > > > The function of_dma_get_range() has been modified so that it takes a single > > argument -- the device node -- and returns a map, NULL, or an error code. > > The map is an array that holds the information regarding the DMA regions. > > Each range entry contains the address offset, the cpu_start address, the > > dma_start address, and the size of the region. > > > > of_dma_configure() is the typical manner to set range offsets but there are > > a number of ad hoc assignments to "dev->dma_pfn_offset" in the kernel > > driver code. These cases now invoke the function > > dma_attach_offset_range(dev, cpu_addr, dma_addr, size). > > ... > > > + if (dev && dev->dma_range_map) > > + pfn -= (unsigned long)PFN_DOWN(dma_offset_from_phys_addr(dev, PFN_PHYS(pfn))); > > Instead of casting use PHYS_PFN() and it will be consistent with latter in the same line. > > > + if (dev && dev->dma_range_map) > > + pfn += (unsigned long)PFN_DOWN(dma_offset_from_dma_addr(dev, addr)); > > Ditto. > > ... > > > + dev_err(dev, "set dma_offset%08llx%s\n", KEYSTONE_HIGH_PHYS_START > > + - KEYSTONE_LOW_PHYS_START, ret ? " failed" : ""); > > Please, avoid such indentation. > Better split it to the three lines, argument per line (expect dev which will go > on the first one). > > This applies to all similar places. > > ... > > > unsigned long pfn = (dma_handle >> PAGE_SHIFT); > > PHYS_PFN() / PFN_DOWN() ? > > > + if (!WARN_ON(!dev) && dev->dma_range_map) > > + pfn += (unsigned long)PFN_DOWN(dma_offset_from_dma_addr(dev, dma_handle)); > > PHYS_PFN() ? > > ... > > > + r = kcalloc(num_ranges + 1, sizeof(struct bus_dma_region), GFP_KERNEL); > > sizeof(*r) ? > > > + if (!r) > > + return ERR_PTR(-ENOMEM); > > ... > > > + ret = IS_ERR(map) ? PTR_ERR(map) : 0; > > PTR_ERR_OR_ZERO() > > ... > > > + /* We want the offset map to be device-managed, so alloc & copy */ > > + dev->dma_range_map = devm_kcalloc(dev, num_ranges + 1, sizeof(*r), > > + GFP_KERNEL); > > The question is how many times per device lifetime this can be called? Someone else questioned this. There are two cases that come to mind: our overnight test which load/unloads the RC driver over and over, and a customer that does an unbind/bind of the RC driver when their EP is hung and wants to restart. Both cases are atypical and are weak arguments to justify the second copy. I will drop the copy. Thanks, Jim Quinlan Broadcom STB > > ... > > > > + if (!dev->dma_range_map) > > + return -ENOMEM; > > + memcpy((void *)dev->dma_range_map, map, sizeof(*r) * num_ranges + 1); > > If it's continuous, perhaps kmemdup() ? > > ... > > > + rc = IS_ERR(map) ? PTR_ERR(map) : 0; > > PTR_ERR_OR_ZERO() > > ... > > > + = dma_offset_from_phys_addr(dev, PFN_PHYS(mem->pfn_base)); > > + > > + return (dma_addr_t)PFN_PHYS(mem->pfn_base) - dma_offset; > > Looking at this more, I think you need to introduce in the same header (pfn.h) > something like: > > #define PFN_DMA_ADDR() > #define DMA_ADDR_PFN() > > -- > With Best Regards, > Andy Shevchenko > > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
prev parent reply other threads:[~2020-07-06 13:40 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-01 21:21 [PATCH v6 00/12] PCI: brcmstb: enable PCIe for STB chips Jim Quinlan via iommu 2020-07-01 21:21 ` [PATCH v6 08/12] device core: Introduce DMA range map, supplanting dma_pfn_offset Jim Quinlan via iommu 2020-07-02 8:42 ` Andy Shevchenko 2020-07-06 13:40 ` Jim Quinlan via iommu [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CA+-6iNwu-jHTb7VFpmkYoyipWK9rtTEOq2dW7K=nYXpUrOTwCQ@mail.gmail.com' \ --to=iommu@lists.linux-foundation.org \ --cc=airlied@linux.ie \ --cc=andriy.shevchenko@linux.intel.com \ --cc=arnd@arndb.de \ --cc=bcm-kernel-feedback-list@broadcom.com \ --cc=bhelgaas@google.com \ --cc=bp@alien8.de \ --cc=dalias@libc.org \ --cc=daniel@ffwll.ch \ --cc=devel@driverdev.osuosl.org \ --cc=devicetree@vger.kernel.org \ --cc=dri-devel@lists.freedesktop.org \ --cc=frowand.list@gmail.com \ --cc=gregkh@linuxfoundation.org \ --cc=guohanjun@huawei.com \ --cc=hch@lst.de \ --cc=heikki.krogerus@linux.intel.com \ --cc=hpa@zytor.com \ --cc=james.quinlan@broadcom.com \ --cc=julien.grall@arm.com \ --cc=lenb@kernel.org \ --cc=linux-acpi@vger.kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-media@vger.kernel.org \ --cc=linux-pci@vger.kernel.org \ --cc=linux-remoteproc@vger.kernel.org \ --cc=linux-sh@vger.kernel.org \ --cc=linux-usb@vger.kernel.org \ --cc=linux@armlinux.org.uk \ --cc=mchehab@kernel.org \ --cc=mingo@redhat.com \ --cc=mripard@kernel.org \ --cc=nsaenzjulienne@suse.de \ --cc=ohad@wizery.com \ --cc=oneukum@suse.com \ --cc=paul.kocialkowski@bootlin.com \ --cc=rjw@rjwysocki.net \ --cc=robh+dt@kernel.org \ --cc=robin.murphy@arm.com \ --cc=saravanak@google.com \ --cc=ssantosh@kernel.org \ --cc=sstabellini@kernel.org \ --cc=stern@rowland.harvard.edu \ --cc=sudeep.holla@arm.com \ --cc=suzuki.poulose@arm.com \ --cc=tglx@linutronix.de \ --cc=ulf.hansson@linaro.org \ --cc=wens@csie.org \ --cc=will@kernel.org \ --cc=x86@kernel.org \ --cc=yong.deng@magewell.com \ --cc=ysato@users.sourceforge.jp \ --subject='Re: [PATCH v6 08/12] device core: Introduce DMA range map, supplanting dma_pfn_offset' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).