diff mbox

[v3,3/4] sh/PCI: Pass GAPSPCI_DMA_BASE CPU & bus address to dma_declare_coherent_memory()

Message ID 20140508204907.17877.4848.stgit@bhelgaas-glaptop.roam.corp.google.com (mailing list archive)
State Awaiting Upstream
Delegated to: Paul Mundt
Headers show

Commit Message

Bjorn Helgaas May 8, 2014, 8:49 p.m. UTC
dma_declare_coherent_memory() needs both the CPU physical address and the
bus address of the device memory.  They are the same on this platform, but
in general we should use pcibios_resource_to_bus() to account for any
address translation done by the PCI host bridge.

This makes no difference on Dreamcast, but is safer if the usage is copied
to future drivers.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
CC: Magnus Damm <damm@opensource.se>
CC: linux-sh@vger.kernel.org
---
 arch/sh/drivers/pci/fixups-dreamcast.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Geert Uytterhoeven May 26, 2014, 2:46 p.m. UTC | #1
On Thu, May 8, 2014 at 10:49 PM, Bjorn Helgaas <bhelgaas@google.com> wrote:
> --- a/arch/sh/drivers/pci/fixups-dreamcast.c
> +++ b/arch/sh/drivers/pci/fixups-dreamcast.c
> @@ -31,6 +31,8 @@
>  static void gapspci_fixup_resources(struct pci_dev *dev)
>  {
>         struct pci_channel *p = dev->sysdata;
> +       struct resource res;
> +       struct pci_bus_region region;
>
>         printk(KERN_NOTICE "PCI: Fixing up device %s\n", pci_name(dev));
>
> @@ -50,11 +52,21 @@ static void gapspci_fixup_resources(struct pci_dev *dev)
>
>                 /*
>                  * Redirect dma memory allocations to special memory window.
> +                *
> +                * If this GAPSPCI region were mapped by a BAR, the CPU
> +                * phys_addr_t would be pci_resource_start(), and the bus
> +                * address would be pci_bus_address(pci_resource_start()).
> +                * But apparently there's no BAR mapping it, so we just
> +                * "know" its CPU address is GAPSPCI_DMA_BASE.
>                  */
> +               res.start = GAPSPCI_DMA_BASE;
> +               res.end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1;
> +               res.flags = IORESOURCE_MEM;
> +               pcibios_resource_to_bus(dev, &region, &resource);

In response to http://kisskb.ellerman.id.au/kisskb/buildresult/11212250/

| /scratch/kisskb/src/arch/sh/drivers/pci/fixups-dreamcast.c: In
function 'gapspci_fixup_resources':
| /scratch/kisskb/src/arch/sh/drivers/pci/fixups-dreamcast.c:65:42:
error: 'resource' undeclared (first use in this function)
| /scratch/kisskb/src/arch/sh/drivers/pci/fixups-dreamcast.c:65:42:
note: each undeclared identifier is reported only once for each
function it appears in

"resource" seem to have been replaced by "res", but this warning still happens:

| /scratch/kisskb/src/arch/sh/drivers/pci/fixups-dreamcast.c:65:3:
warning: passing argument 1 of 'pcibios_resource_to_bus' from
incompatible pointer type [enabled by default]
| /scratch/kisskb/src/include/linux/pci.h:737:6: note: expected
'struct pci_bus *' but argument is of type 'struct pci_dev *'

>                 BUG_ON(!dma_declare_coherent_memory(&dev->dev,
> -                                               GAPSPCI_DMA_BASE,
> -                                               GAPSPCI_DMA_BASE,
> -                                               GAPSPCI_DMA_SIZE,
> +                                               res.start,
> +                                               region.start,
> +                                               resource_size(&res),
>                                                 DMA_MEMORY_MAP |
>                                                 DMA_MEMORY_EXCLUSIVE));
>                 break;

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas May 26, 2014, 11:33 p.m. UTC | #2
On Mon, May 26, 2014 at 8:46 AM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> On Thu, May 8, 2014 at 10:49 PM, Bjorn Helgaas <bhelgaas@google.com> wrote:
>> --- a/arch/sh/drivers/pci/fixups-dreamcast.c
>> +++ b/arch/sh/drivers/pci/fixups-dreamcast.c
>> @@ -31,6 +31,8 @@
>>  static void gapspci_fixup_resources(struct pci_dev *dev)
>>  {
>>         struct pci_channel *p = dev->sysdata;
>> +       struct resource res;
>> +       struct pci_bus_region region;
>>
>>         printk(KERN_NOTICE "PCI: Fixing up device %s\n", pci_name(dev));
>>
>> @@ -50,11 +52,21 @@ static void gapspci_fixup_resources(struct pci_dev *dev)
>>
>>                 /*
>>                  * Redirect dma memory allocations to special memory window.
>> +                *
>> +                * If this GAPSPCI region were mapped by a BAR, the CPU
>> +                * phys_addr_t would be pci_resource_start(), and the bus
>> +                * address would be pci_bus_address(pci_resource_start()).
>> +                * But apparently there's no BAR mapping it, so we just
>> +                * "know" its CPU address is GAPSPCI_DMA_BASE.
>>                  */
>> +               res.start = GAPSPCI_DMA_BASE;
>> +               res.end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1;
>> +               res.flags = IORESOURCE_MEM;
>> +               pcibios_resource_to_bus(dev, &region, &resource);
>
> In response to http://kisskb.ellerman.id.au/kisskb/buildresult/11212250/
>
> | /scratch/kisskb/src/arch/sh/drivers/pci/fixups-dreamcast.c: In
> function 'gapspci_fixup_resources':
> | /scratch/kisskb/src/arch/sh/drivers/pci/fixups-dreamcast.c:65:42:
> error: 'resource' undeclared (first use in this function)
> | /scratch/kisskb/src/arch/sh/drivers/pci/fixups-dreamcast.c:65:42:
> note: each undeclared identifier is reported only once for each
> function it appears in
>
> "resource" seem to have been replaced by "res", but this warning still happens:
>
> | /scratch/kisskb/src/arch/sh/drivers/pci/fixups-dreamcast.c:65:3:
> warning: passing argument 1 of 'pcibios_resource_to_bus' from
> incompatible pointer type [enabled by default]
> | /scratch/kisskb/src/include/linux/pci.h:737:6: note: expected
> 'struct pci_bus *' but argument is of type 'struct pci_dev *'

Sheesh, this really has not been my day.  Fixed, thanks.

>>                 BUG_ON(!dma_declare_coherent_memory(&dev->dev,
>> -                                               GAPSPCI_DMA_BASE,
>> -                                               GAPSPCI_DMA_BASE,
>> -                                               GAPSPCI_DMA_SIZE,
>> +                                               res.start,
>> +                                               region.start,
>> +                                               resource_size(&res),
>>                                                 DMA_MEMORY_MAP |
>>                                                 DMA_MEMORY_EXCLUSIVE));
>>                 break;
>
> Gr{oetje,eeting}s,
>
>                         Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/sh/drivers/pci/fixups-dreamcast.c b/arch/sh/drivers/pci/fixups-dreamcast.c
index d6cde700e316..f22127f966ce 100644
--- a/arch/sh/drivers/pci/fixups-dreamcast.c
+++ b/arch/sh/drivers/pci/fixups-dreamcast.c
@@ -31,6 +31,8 @@ 
 static void gapspci_fixup_resources(struct pci_dev *dev)
 {
 	struct pci_channel *p = dev->sysdata;
+	struct resource res;
+	struct pci_bus_region region;
 
 	printk(KERN_NOTICE "PCI: Fixing up device %s\n", pci_name(dev));
 
@@ -50,11 +52,21 @@  static void gapspci_fixup_resources(struct pci_dev *dev)
 
 		/*
 		 * Redirect dma memory allocations to special memory window.
+		 *
+		 * If this GAPSPCI region were mapped by a BAR, the CPU
+		 * phys_addr_t would be pci_resource_start(), and the bus
+		 * address would be pci_bus_address(pci_resource_start()).
+		 * But apparently there's no BAR mapping it, so we just
+		 * "know" its CPU address is GAPSPCI_DMA_BASE.
 		 */
+		res.start = GAPSPCI_DMA_BASE;
+		res.end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1;
+		res.flags = IORESOURCE_MEM;
+		pcibios_resource_to_bus(dev, &region, &resource);
 		BUG_ON(!dma_declare_coherent_memory(&dev->dev,
-						GAPSPCI_DMA_BASE,
-						GAPSPCI_DMA_BASE,
-						GAPSPCI_DMA_SIZE,
+						res.start,
+						region.start,
+						resource_size(&res),
 						DMA_MEMORY_MAP |
 						DMA_MEMORY_EXCLUSIVE));
 		break;