Skip to contentSkip to conversation

Reading a physical memory location

DISCUSSION [email protected] 5 participants 11 messages Jul 9, 2007 – Jul 24, 2007

lore
Share & tools
lore
#0 lore raw

--
Hey all,

I know the physical address of a string which is loaded into flash memory. I want to read the string at the known physical memory location from within a kernel module. I initially tried reading the "/dev/mem" file using open(), lseek() and read(). But I guess its not possible to call these functions from a kernel module.

Is there some way of reading the contents of this physical memory location from within a kernel module?

Thank You
Veena

#1 lore raw

Hi,
If you know the physical address, then you get virtual address
from that physical adress by using ioremap().

Then you can use readl(virtualaddress) to read the string from there

Nobin Mathew

Quoted 22 lines · On 7/10/07, [email protected] <[email protected]> wrote:

--
Hey all,

I know the physical address of a string which is loaded into flash memory. I want to read the string at the known physical memory location from within a kernel module. I initially tried reading the "/dev/mem" file using open(), lseek() and read(). But I guess its not possible to call these functions from a kernel module.

Is there some way of reading the contents of this physical memory location from within a kernel module?

Thank You
Veena
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw

Thanks for the quick reply. But I was wondering as to why I would have to map the physical address to the virtual address when I know that the string is permanently in the physical memory because its loaded into flash. Is there a way to directly read from the physical memory location? Also, do the functions ioremap() and readl(va) work when called from within a kernel module?

-- Veena

Quoting Nobin Mathew <[email protected]>:

Quoted 34 lines

Hi,
If you know the physical address, then you get virtual address
from that physical adress by using ioremap().

Then you can use readl(virtualaddress) to read the string from there

Nobin Mathew

Quoted 6 lines · On 7/10/07, [email protected] <[email protected]> wrote:

--
Hey all,

I know the physical address of a string which is loaded into flash memory.

I

Quoted 3 lines

want to read the string at the known physical memory location from within a kernel module. I initially tried reading the "/dev/mem" file using open(), lseek() and read(). But I guess its not possible to call these functions

from a

Quoted 3 lines

kernel module.

Is there some way of reading the contents of this physical memory location

from

Quoted 10 lines

within a kernel module?

Thank You
Veena
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Quoted 6 lines

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

--

#3 lore raw
Quoted 7 lines · On 7/10/07, [email protected] <[email protected]> wrote:

Thanks for the quick reply. But I was wondering as to why I would have to map the physical address to the virtual address when I know that the string is permanently in the physical memory because its loaded into flash. Is there a way to directly read from the physical memory location? Also, do the functions ioremap() and readl(va) work when called from within a kernel module?

Of course, if you look at almost any of the memory mapped device drivers, you will find that ioremap/readl/writel is the backbone of your infrastructure.

Manu

#4 lore raw

Which is your platform ?

Which processor?

If you want to use physical address directly, then disable MMU. That is not possible in linux.

Nobin

Quoted 16 lines · Manu Abraham
Quoted 7 lines · On 7/10/07, [email protected] <[email protected]> wrote:

Thanks for the quick reply. But I was wondering as to why I would have to map the physical address to the virtual address when I know that the string is permanently in the physical memory because its loaded into flash. Is there a way to directly read from the physical memory location? Also, do the functions ioremap() and readl(va) work when called from within a kernel module?

Of course, if you look at almost any of the memory mapped device drivers, you will find that ioremap/readl/writel is the backbone of your infrastructure.

Manu

#5 lore raw
Quoted 6 lines · Nobin Mathew

Which is your platform ?

Which processor?

If you want to use physical address directly, then disable MMU. That is not possible in linux.

ioremap does map io memory using phys_to_virt
I thought phys_to_virt was enough to remap physical memory to virtual
http://mirror.linux.org.au/linux.conf.au/2005/cdrom-beta-1/linux-mandocs-2.6.12.6/phys_to_virt.html

Quoted 21 lines

Nobin

Quoted 16 lines · Manu Abraham
Quoted 7 lines · On 7/10/07, [email protected] <[email protected]> wrote:

Thanks for the quick reply. But I was wondering as to why I would have to map the physical address to the virtual address when I know that the string is permanently in the physical memory because its loaded into flash. Is there a way to directly read from the physical memory location? Also, do the functions ioremap() and readl(va) work when called from within a kernel module?

Of course, if you look at almost any of the memory mapped device drivers, you will find that ioremap/readl/writel is the backbone of your infrastructure.

Manu

#6 lore raw

See this in the documentation

The returned virtual address is a current CPU mapping for the memory address given. It is only valid to use this function on addresses that have a kernel mapping

This function does not handle bus mappings for DMA transfers. In almost all conceivable cases a device driver should not be using this function

Nobin

Quoted 36 lines · Manu Abraham
Quoted 6 lines · Nobin Mathew

Which is your platform ?

Which processor?

If you want to use physical address directly, then disable MMU. That is not possible in linux.

ioremap does map io memory using phys_to_virt
I thought phys_to_virt was enough to remap physical memory to virtual
http://mirror.linux.org.au/linux.conf.au/2005/cdrom-beta-1/linux-mandocs-2.6.12.6/phys_to_virt.html

Quoted 21 lines

Nobin

Quoted 16 lines · Manu Abraham
Quoted 7 lines · On 7/10/07, [email protected] <[email protected]> wrote:

Thanks for the quick reply. But I was wondering as to why I would have to map the physical address to the virtual address when I know that the string is permanently in the physical memory because its loaded into flash. Is there a way to directly read from the physical memory location? Also, do the functions ioremap() and readl(va) work when called from within a kernel module?

Of course, if you look at almost any of the memory mapped device drivers, you will find that ioremap/readl/writel is the backbone of your infrastructure.

Manu

#7 lore raw
Quoted 10 lines · Nobin Mathew

See this in the documentation

The returned virtual address is a current CPU mapping for the memory address given. It is only valid to use this function on addresses that have a kernel mapping

This function does not handle bus mappings for DMA transfers. In almost all conceivable cases a device driver should not be using this function

To get a better idea, look here
http://tldp.org/LDP/khg/HyperNews/get/devices/addrxlate.html

#8 lore raw

Thanks

Quoted 15 lines · Manu Abraham
Quoted 10 lines · Nobin Mathew

See this in the documentation

The returned virtual address is a current CPU mapping for the memory address given. It is only valid to use this function on addresses that have a kernel mapping

This function does not handle bus mappings for DMA transfers. In almost all conceivable cases a device driver should not be using this function

To get a better idea, look here
http://tldp.org/LDP/khg/HyperNews/get/devices/addrxlate.html

#9 lore raw
In reply to Manu Abraham
Quoted 7 lines · Manu Abraham
Quoted 6 lines · Nobin Mathew

See this in the documentation

The returned virtual address is a current CPU mapping for the memory address given. It is only valid to use this function on addresses that have a kernel mapping

Quoted 7 lines
Quoted 4 lines

This function does not handle bus mappings for DMA transfers. In almost all conceivable cases a device driver should not be using this function

To get a better idea, look here
http://tldp.org/LDP/khg/HyperNews/get/devices/addrxlate.html

Very nice! I have two more questions:

1. Is the document up to date?

2. Can anybody give an example how to "map" lots of pages (which got filled by i.e. a scatter gather DMA chain) from a driver (kernel space) to userspace?

Thanks

Signature · 10 lines
Clemens Koller
__________________________________
R&D Imaging Devices
Anagramm GmbH
Rupert-Mayer-Straße 45/1
Linhof Werksgelände
D-81379 München
Tel.089-741518-50
Fax 089-741518-19
http://www.anagramm-technology.com
#10 lore raw
In reply to [email protected]
Quoted 3 lines · [email protected] wrote:

Thanks for the quick reply. But I was wondering as to why I would have to map the physical address to the virtual address when I know that the string is permanently in the physical memory because its loaded into flash.

Because that is how any CPU with a MMU works.
All accesses to memory goes through page tables (virtual memory) - there is no alternative. But this is not a problem, as the kernel can map any physical address for you.

Quoted 2 lines

Is there a way
to directly read from the physical memory location?

The way is to map the page containing that address. You can then read whatever you want from that page. Nothing is ever accessed by physical address, physical addresses is only used indirectly to set up the page tables.

Helge Hafting