1

I am using "ioremap" to map the address of a GPIO port in the datasheet of Ti AM3359 . The code is running fine.

Problem:

1> The problem is , why do we need to map the virtual address to physical address? Is it because physical address is the real address of the hardware that we want to access?

2> If above is true then, why don't the datasheets directly give the physical address .

3> Is the physical address returned by "ioremap" would be different in different Boards with different amount of RAM?

Virendra Kumar
  • 947
  • 2
  • 13
  • 31

2 Answers2

1

As for your first question, the reason you use ioremap is because the kernel's address space does not correspond to the physical address space. You need to map the physical pages into the virtual address space to be able to address them at all. This is what ioremap does.

As for your second and third questions, I wouldn't know what your datasheets give or do not give. :)

Normally, I would expect hardware datasheets to give physical addresses, unless it is that the physical address must be either found out or configured via bus-specific mechanisms. What is it that yours actually specify, if not that?

You may want to read this for further information.

Dolda2000
  • 25,216
  • 4
  • 51
  • 92
  • We use the address given in the datasheet as input in ioremap, so it must be virtual address only?(actually the address given in the data sheet are always offsets) – Virendra Kumar Feb 07 '14 at 09:24
  • No, that means it is, in fact, a physical address. `ioremap` gives you a virtual address. What made you think it wasn't? – Dolda2000 Feb 07 '14 at 09:25
  • Ya you are right, i also verified this, But the thing is that why would we need virtual address to access any hardware? – Virendra Kumar Feb 07 '14 at 09:29
  • 1
    Because all code that you write will run on the virtual side of the MMU. The addresses your code handles are only virtual addresses, by virtue of the basic execution model of any MMU-equipped CPU. If you don't map your physical pages through the MMU, you wouldn't have any means to access them. That's what an MMU does. – Dolda2000 Feb 07 '14 at 09:30
1
  1. because kernel operates on virtual addresses not on physical ones
  2. in my datasheets there are only physical addresses
  3. afaik ioremap returns virtual address mapping your physical address
user2699113
  • 4,262
  • 3
  • 25
  • 43