2009-06-16 07:29:33

by Malcom Blaney

[permalink] [raw]
Subject: is_device_dma_capable

Hello,

I'm using the parport_pc driver with a dma buffer, which is provided
by calling dma_alloc_coherent in arch/x86/include/asm/dma-mapping.h.

This is no longer working for me in 2.6.29.2, the previous version I
was using is 2.6.25.10, which was fine with the same hardware.

The problem is that the call to is_device_dma_capable returns false,
so dma_alloc_coherent returns NULL. Do I need to set the dma_mask in
the driver for this to work correctly?

thanks,
Malcolm.


2009-06-16 08:12:32

by FUJITA Tomonori

[permalink] [raw]
Subject: Re: is_device_dma_capable

On Tue, 16 Jun 2009 16:54:24 +0930
Malcom Blaney <[email protected]> wrote:

> I'm using the parport_pc driver with a dma buffer, which is provided
> by calling dma_alloc_coherent in arch/x86/include/asm/dma-mapping.h.
>
> This is no longer working for me in 2.6.29.2, the previous version I
> was using is 2.6.25.10, which was fine with the same hardware.
>
> The problem is that the call to is_device_dma_capable returns false,
> so dma_alloc_coherent returns NULL. Do I need to set the dma_mask in
> the driver for this to work correctly?

You use X86_32, right?

In 2.6.25, X86_32 and X86_64 had the own dma_alloc_coherent
implementations; X86_32 accepted a device having dma_mask that is not
initialized however X86_64 didn't, I think.

When we merged them, we chose to prohibit a device having dma_mask
that is not initialized. I'm not sure the DMA docs say this but IMO
it's good to require drivers to set up dma_mask (and
coherent_dma_mask) properly if the drivers want DMA.

2009-06-16 08:23:20

by Malcom Blaney

[permalink] [raw]
Subject: Re: is_device_dma_capable

Hi Fujita,

2009/6/16 FUJITA Tomonori <[email protected]>:
> You use X86_32, right?

I have CONFIG_X86_32=y in my config file.

>
> In 2.6.25, X86_32 and X86_64 had the own dma_alloc_coherent
> implementations; X86_32 accepted a device having dma_mask that is not
> initialized however X86_64 didn't, I think.
>
> When we merged them, we chose to prohibit a device having dma_mask
> that is not initialized. I'm not sure the DMA docs say this but IMO
> it's good to require drivers to set up dma_mask (and
> coherent_dma_mask) properly if the drivers want DMA.
>

If you could point me in the direction of how to set these values
correctly, I would appreciate it.

thanks,
Malcolm.

2009-06-16 08:56:25

by FUJITA Tomonori

[permalink] [raw]
Subject: Re: is_device_dma_capable

On Tue, 16 Jun 2009 17:53:03 +0930
Malcom Blaney <[email protected]> wrote:

> Hi Fujita,
>
> 2009/6/16 FUJITA Tomonori <[email protected]>:
> > You use X86_32, right?
>
> I have CONFIG_X86_32=y in my config file.
>
> >
> > In 2.6.25, X86_32 and X86_64 had the own dma_alloc_coherent
> > implementations; X86_32 accepted a device having dma_mask that is not
> > initialized however X86_64 didn't, I think.
> >
> > When we merged them, we chose to prohibit a device having dma_mask
> > that is not initialized. I'm not sure the DMA docs say this but IMO
> > it's good to require drivers to set up dma_mask (and
> > coherent_dma_mask) properly if the drivers want DMA.
> >
>
> If you could point me in the direction of how to set these values
> correctly, I would appreciate it.

You hit the problem that a device that parport_pc_probe_port creates
but doesn't set up the dma_mask properly, right (I'm not familiar with
the driver at all so I might misunderstand something)?

If so, I guess that the following patch works (only compile tested).


diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index 151bf5b..1af57b7 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -2271,6 +2271,9 @@ struct parport *parport_pc_probe_port(unsigned long int base,
if (IS_ERR(pdev))
return NULL;
dev = &pdev->dev;
+
+ dev->coherent_dma_mask = DMA_BIT_MASK(24);
+ dev->dma_mask = &dev->coherent_dma_mask;
}

ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);

2009-06-17 01:10:42

by Malcom Blaney

[permalink] [raw]
Subject: Re: is_device_dma_capable

Thanks Fujita, your patch worked a treat!

2009/6/16 FUJITA Tomonori <[email protected]>:
> On Tue, 16 Jun 2009 17:53:03 +0930
> Malcom Blaney <[email protected]> wrote:
>
>> Hi Fujita,
>>
>> 2009/6/16 FUJITA Tomonori <[email protected]>:
>> > You use X86_32, right?
>>
>> I have CONFIG_X86_32=y in my config file.
>>
>> >
>> > In 2.6.25, X86_32 and X86_64 had the own dma_alloc_coherent
>> > implementations; X86_32 accepted a device having dma_mask that is not
>> > initialized however X86_64 didn't, I think.
>> >
>> > When we merged them, we chose to prohibit a device having dma_mask
>> > that is not initialized. I'm not sure the DMA docs say this but IMO
>> > it's good to require drivers to set up dma_mask (and
>> > coherent_dma_mask) properly if the drivers want DMA.
>> >
>>
>> If you could point me in the direction of how to set these values
>> correctly, I would appreciate it.
>
> You hit the problem that a device that parport_pc_probe_port creates
> but doesn't set up the dma_mask properly, right (I'm not familiar with
> the driver at all so I might misunderstand something)?
>
> If so, I guess that the following patch works (only compile tested).
>
>
> diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
> index 151bf5b..1af57b7 100644
> --- a/drivers/parport/parport_pc.c
> +++ b/drivers/parport/parport_pc.c
> @@ -2271,6 +2271,9 @@ struct parport *parport_pc_probe_port(unsigned long int base,
> ? ? ? ? ? ? ? ?if (IS_ERR(pdev))
> ? ? ? ? ? ? ? ? ? ? ? ?return NULL;
> ? ? ? ? ? ? ? ?dev = &pdev->dev;
> +
> + ? ? ? ? ? ? ? dev->coherent_dma_mask = DMA_BIT_MASK(24);
> + ? ? ? ? ? ? ? dev->dma_mask = &dev->coherent_dma_mask;
> ? ? ? ?}
>
> ? ? ? ?ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);
>