iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jim Quinlan <james.quinlan@broadcom.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>,
	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>,
	Bjorn Andersson <bjorn.andersson@linaro.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>,
	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: Thu, 2 Jul 2020 11:42:51 +0300	[thread overview]
Message-ID: <20200702084251.GF3703480@smile.fi.intel.com> (raw)
In-Reply-To: <20200701212155.37830-9-james.quinlan@broadcom.com>

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?

...


> +		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

  reply	other threads:[~2020-07-02  8:43 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 [this message]
2020-07-06 13:40     ` Jim Quinlan via iommu

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=20200702084251.GF3703480@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=airlied@linux.ie \
    --cc=arnd@arndb.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn.andersson@linaro.org \
    --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=iommu@lists.linux-foundation.org \
    --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).