Re: Copying user space data to PCI memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Mon, May 18, 2009 at 6:50 AM, Grant Grundler
<grundler@xxxxxxxxxxxxxxxx> wrote:
> Hi Arun, Sandeep,
>
> On Sat, May 16, 2009 at 06:33:44PM +0530, SandeepKsinha wrote:
>> Hi Arun,
>>
>> On Sat, May 16, 2009 at 5:48 PM, arun c <arun.edarath@xxxxxxxxx> wrote:
>> > Hi all,
>> >
>> > I want to copy data from user space to PCI memory.
>> >
>> > I mapped the PCI memory of the card by,
>> >
>> > 1)pci_request_regions(pci_dev, DEVICE_NAME);
>> > 2)buffer_addr = pci_iomap(pci_dev, 1, 1024);
>> >
>> > Now I want to write data supplied by the
>> > user to buffer_addr(BAR1 pre-fetch-able memory
>> > of the device)
>> >
>> > I did like this:
>> >
>> > copy_from_user(buffer_addr, usr_addr, 1024)
>> >
>> > This method is working fine on an X86 running
>> > linux 2.6.27 kernel. I can see the data clearly copied.
>> >
>> > I want to know is this legal for all the platforms? and for
>> > older kernels starting from 2.6.16?
>> >
>> > If the above method is totally legal then can I use
>> > copy_to_user(usr_addr, buffer_addr, 1024) also?
>>
>> AFAIK, yes.
>
> Sorry, I don't think so.
>
> Copying stuff to non-cacheable addresses can have other side effects.

My destination memory is a PCI pre-fetchable memory. I am not sure
this is cacheable or not.

> So the optimizations available when copying TO cacheable address space
> are generally not available (or have risks).
>
> That's why we have copy_from_user_toio()

I greped for  copy_from_user_toio, only some files in the sound/pci
folder seems to be using it.

I make my scenario more clear here.

I want to transfer data in and out from user space to PCI memory.
I know I can do a copy_from_user to get data to kernel and do any
iowrite* flavours to eventually write to PCI memory, and do the exact
reverse to transfer data to user.

I just wanted to eliminate the unnecessary buffering of data in kernel
for which kernel has no interest. copy_from_user_toio and
copy_to_user_fromio are designed for this purpose?

I can test my driver on PPC and X86 machines, rest of the
platforms are not available with me. That is why I wanted a
bullet proof implementation.

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

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux