Kmalloc returns which address

8 messages, 4 authors, 2007-07-24 · open the first message on its own page

Kmalloc returns which address

From: suresh suresh <hidden>
Date: 2007-07-16 14:00:00

Hi,

I am porting MPC8280 driver from vxWorks to Linux.

I want know the address return by kmalloc function? is it physical address
or kernel virtual address.

For Tx and Rx, hardware uses buffers, so I have to allocate buffers and pass
the pointer to hardware. Can I pass the pointer returned kmalloc?  or  I
should convert it into physical address?

If it returns kernel virtual address, then how to convert into physical?

Thanks & Regards-
Suresh

Re: Kmalloc returns which address

From: Scott Wood <hidden>
Date: 2007-07-16 15:46:43

suresh suresh wrote:
I want know the address return by kmalloc function? is it physical address
or kernel virtual address.
Kernel virtual.
For Tx and Rx, hardware uses buffers, so I have to allocate buffers and 
pass
the pointer to hardware. Can I pass the pointer returned kmalloc?  or  I
should convert it into physical address?
You need to convert it; read Documentation/DMA-mapping.txt.

-Scott

Re: Kmalloc returns which address

From: Misbah khan <hidden>
Date: 2007-07-20 10:52:23

hi Suresh

In linux kmelloc returns the pointer to virtual address not the physical
address, to return to the physical address there is different function
called ioremap 

for eg :-
char *buf_tx =kmalloc(100,GFP_KERNEL); // Tx buffer
char *buf_rx=kmalloc(100,GFP_KERNEL); // Rx buffer

ptr_tx=ioremap( buf_tx,100);
ptr_rx=ioremap(buf_rx,100);

To learn more about this go through Linux device driver by rubini 

I hope this will work for you 
regard 
Misbah

suresh suresh wrote:
Hi,

I am porting MPC8280 driver from vxWorks to Linux.

I want know the address return by kmalloc function? is it physical address
or kernel virtual address.

For Tx and Rx, hardware uses buffers, so I have to allocate buffers and
pass
the pointer to hardware. Can I pass the pointer returned kmalloc?  or  I
should convert it into physical address?

If it returns kernel virtual address, then how to convert into physical?

Thanks & Regards-
Suresh

_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-embedded
-- 
View this message in context: http://www.nabble.com/Kmalloc-returns-which-address-tf4086826.html#a11705981
Sent from the linuxppc-embedded mailing list archive at Nabble.com.

Re: Kmalloc returns which address

From: Alessandro Rubini <hidden>
Date: 2007-07-20 12:27:51

Hello.
In linux kmelloc returns the pointer to virtual address not the physical
address, to return to the physical address there is different function
called ioremap 
Not exactly. Both return virtual addresses. The kmalloc one is allocated
RAM memory, the ioremap is the virtual address built for you to
access a physical address you specified (i.e., a device memory area).
quoted
For Tx and Rx, hardware uses buffers, so I have to allocate buffers and
pass
the pointer to hardware. Can I pass the pointer returned kmalloc?  or  I
should convert it into physical address?
If you allocate with kmalloc, use __pa(addr) to turn the virtual
address addr into the physical address you need to pass to the device,
ad DMA access is outside of the virtual view of the address space.

However, please note that according to how your device is connected
and what bus it is using, the design can get more hairy, you may need
to study the consistent memory allocations.

Hope this helps
/alessandro

Re: Kmalloc returns which address

From: Scott Wood <hidden>
Date: 2007-07-20 16:58:49

Misbah khan wrote:
hi Suresh

In linux kmelloc returns the pointer to virtual address not the physical
address, to return to the physical address there is different function
called ioremap 

for eg :-
char *buf_tx =kmalloc(100,GFP_KERNEL); // Tx buffer
char *buf_rx=kmalloc(100,GFP_KERNEL); // Rx buffer

ptr_tx=ioremap( buf_tx,100);
ptr_rx=ioremap(buf_rx,100);
That's a really easy way to cause a machine check.

-Scott

Re: Kmalloc returns which address

From: Misbah khan <hidden>
Date: 2007-07-23 03:47:49

hi Scott

yes really it would really generate a machine check... but i guess if you
convert this virt address to physical address using __pa() then pass it to
the ioremap() i guess things will work .

Please correct me if i am wrong

regard 
misbah
 

Scott Wood-2 wrote:
suresh suresh wrote:
quoted
I want know the address return by kmalloc function? is it physical
address
or kernel virtual address.
Kernel virtual.
quoted
For Tx and Rx, hardware uses buffers, so I have to allocate buffers and 
pass
the pointer to hardware. Can I pass the pointer returned kmalloc?  or  I
should convert it into physical address?
You need to convert it; read Documentation/DMA-mapping.txt.

-Scott
_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-embedded
-- 
View this message in context: http://www.nabble.com/Kmalloc-returns-which-address-tf4086826.html#a11737504
Sent from the linuxppc-embedded mailing list archive at Nabble.com.

Re: Kmalloc returns which address

From: Scott Wood <hidden>
Date: 2007-07-23 18:39:17

On Sun, Jul 22, 2007 at 08:47:47PM -0700, Misbah khan wrote:
yes really it would really generate a machine check... but i guess if you
convert this virt address to physical address using __pa() then pass it to
the ioremap() i guess things will work .
What would be the point?  All you'd get is another virtual mapping.

Is the DMA mapping API that difficult?

-Scott

Re: Kmalloc returns which address

From: Misbah khan <hidden>
Date: 2007-07-24 07:03:37

Hi Scott

The while idea behind my logic was something this :-

 Conver the physical address into virtual address and every time you read or
write to that virtual you are reading or writing to the physical address.
For that i suggested for ioremap(), some may suggest for __pa() to translate
the physical address to logical address. The whole idea behind this is to
make the task much easy and less complicated as if you are working on memory
mapped address.

DMA operation will make the application process to access the device
directly this i guess is little more complicated in implimentation and
passing a pointer to the application is a serious security concern untill
and unless only one thread is accessing .

well i will try this with a test driver as soon as i get the free time and
let you know with the findings

Thanks 
Misbah  

Scott Wood-2 wrote:
suresh suresh wrote:
quoted
I want know the address return by kmalloc function? is it physical
address
or kernel virtual address.
Kernel virtual.
quoted
For Tx and Rx, hardware uses buffers, so I have to allocate buffers and 
pass
the pointer to hardware. Can I pass the pointer returned kmalloc?  or  I
should convert it into physical address?
You need to convert it; read Documentation/DMA-mapping.txt.

-Scott
_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-embedded
-- 
View this message in context: http://www.nabble.com/Kmalloc-returns-which-address-tf4086826.html#a11757911
Sent from the linuxppc-embedded mailing list archive at Nabble.com.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help