2007-05-10 08:27:22

by Mahesh

[permalink] [raw]
Subject: [HOWTO] accessing the DMA mapped data

Hi list,

I have a small question regarding the accessing the data in the DMA
mapped region (in the driver). In my driver I only have the
'dma_addr_t addr' variable which is result after the 'dma_map_single'.
I don't have access to the virtual address of the data region.

Is there helper routine which we will give me the virtual address back
from the DMA mapped address???

After some searching in the net about it found 'dma_sync_single' which
will help to synchronize it after 'modifying' the contents of the DMA mapped
region. But to 'modify' the contents of DMA mapped region I require the virtual
address, which is not available in my case.

Regards,
Mahesh.



2007-05-10 08:47:57

by David Miller

[permalink] [raw]
Subject: Re: [HOWTO] accessing the DMA mapped data

From: Mahesh <[email protected]>
Date: Thu, 10 May 2007 13:28:13 +0530

> I have a small question regarding the accessing the data in the DMA
> mapped region (in the driver). In my driver I only have the
> 'dma_addr_t addr' variable which is result after the 'dma_map_single'.
> I don't have access to the virtual address of the data region.
>
> Is there helper routine which we will give me the virtual address back
> from the DMA mapped address???

You can eithe keep track of this yourself, or (depending upon
your usage) you might be able to use DMA pools, see
dma_pool_create() and friends.

2007-05-10 11:17:18

by Mahesh

[permalink] [raw]
Subject: Re: [HOWTO] accessing the DMA mapped data

Hi Miller,

Thanks for replying.
> You can eithe keep track of this yourself, or (depending upon
> your usage) you might be able to use DMA pools, see
> dma_pool_create() and friends.
>
I think you have not understood my question properly. My problem is, the
layer above the driver will do
dma_map_single on a kmalloc'ed buffer and passes the result (bus
address) to the device driver. Now
the driver has to modify the contents of the the original buffer.
Is it possible to do that ??

-regards,
Mahesh

2007-05-10 11:32:37

by David Miller

[permalink] [raw]
Subject: Re: [HOWTO] accessing the DMA mapped data

From: Mahesh <[email protected]>
Date: Thu, 10 May 2007 16:49:03 +0530

> I think you have not understood my question properly. My problem is, the
> layer above the driver will do
> dma_map_single on a kmalloc'ed buffer and passes the result (bus
> address) to the device driver. Now
> the driver has to modify the contents of the the original buffer.
> Is it possible to do that ??

You haven't given an example of where this might actually happen.

The driver is where the DMA mappings almost always occur because
that is the layer that knows the bus technology and therefore
the correct DMA interfaces to call.

What kind of driver do you have and what is this upper layer
doing the mappings for you but not giving you a pointer to
the kernel buffer as well?

2007-05-10 11:39:46

by Mahesh

[permalink] [raw]
Subject: Re: [HOWTO] accessing the DMA mapped data

Hi,
> You haven't given an example of where this might actually happen.
>
> The driver is where the DMA mappings almost always occur because
> that is the layer that knows the bus technology and therefore
> the correct DMA interfaces to call.
>
> What kind of driver do you have and what is this upper layer
> doing the mappings for you but not giving you a pointer to
> the kernel buffer as well?
>
Here I am dealing with a infiniband (see http://www.openfabrics.org) network
device driver. The layer above the
driver is the standard infiniband core interface. Now I have a situation
where I need to peek into the packets
and do some modifications(some hacking). So I just want know whether I
can access the original data region
using the bus address generated by the dma_map_single.

FYI, architecture I am working on is x86_64.

-Mahesh


2007-05-10 11:47:37

by David Miller

[permalink] [raw]
Subject: Re: [HOWTO] accessing the DMA mapped data

From: Mahesh <[email protected]>
Date: Thu, 10 May 2007 17:11:17 +0530

> Hi, > You haven't given an example of where this might actually
> happen. > > The driver is where the DMA mappings almost always
> occur because > that is the layer that knows the bus technology and
> therefore > the correct DMA interfaces to call. > > What kind of
> driver do you have and what is this upper layer > doing the mappings
> for you but not giving you a pointer to > the kernel buffer as well?
> > Here I am dealing with a infiniband (see http://www.openfabrics.org)
> network device driver. The layer above the driver is the standard
> infiniband core interface. Now I have a situation where I need to
> peek into the packets and do some modifications(some hacking). So I
> just want know whether I can access the original data region using
> the bus address generated by the dma_map_single.

You can't, therefore you need to ask the Inifiniband guys to perhaps
tweak the infiniband driver interfaces so that you can get at the
buffer or provide some other mechanism by which you can accomplish
what you're trying to do.

2007-05-10 18:28:12

by Roland Dreier

[permalink] [raw]
Subject: Re: [HOWTO] accessing the DMA mapped data

> Here I am dealing with a infiniband (see http://www.openfabrics.org)
> network device driver. The layer above the driver is the standard
> infiniband core interface. Now I have a situation where I need to
> peek into the packets and do some modifications(some hacking). So I
> just want know whether I can access the original data region using
> the bus address generated by the dma_map_single.

If you give more details about what you're trying to do, maybe I can
suggest a good way to accomplish it.

Also for IB-related stuff you may want to at least CC
<[email protected]> to get the best info.

2007-05-11 15:43:03

by Muli Ben-Yehuda

[permalink] [raw]
Subject: Re: [HOWTO] accessing the DMA mapped data

On Thu, May 10, 2007 at 04:47:32AM -0700, David Miller wrote:
> From: Mahesh <[email protected]>
> Date: Thu, 10 May 2007 17:11:17 +0530
>
> > Hi, > You haven't given an example of where this might actually
> > happen. > > The driver is where the DMA mappings almost always
> > occur because > that is the layer that knows the bus technology and
> > therefore > the correct DMA interfaces to call. > > What kind of
> > driver do you have and what is this upper layer > doing the mappings
> > for you but not giving you a pointer to > the kernel buffer as well?
> > > Here I am dealing with a infiniband (see http://www.openfabrics.org)
> > network device driver. The layer above the driver is the standard
> > infiniband core interface. Now I have a situation where I need to
> > peek into the packets and do some modifications(some hacking). So I
> > just want know whether I can access the original data region using
> > the bus address generated by the dma_map_single.
>
> You can't, therefore you need to ask the Inifiniband guys to perhaps
> tweak the infiniband driver interfaces so that you can get at the
> buffer or provide some other mechanism by which you can accomplish
> what you're trying to do.

AFAICR the ipath driver had the same problem, which resulted in the
addition of ib specific DMA-API wrappers. See usage of struct
ipath_dma_mapping_ops in ipath_dma.c.

Cheers,
Muli