0

example while writing a driver we do the following

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

We get the info about the memory allocated to the device.

So is it necessary that I use this memory using virtual address

virt_base = ioremap(res->start, resource_size(res));

Can't we use the physical address itself to address the memory?

If we can, so are there any specific advantages of using virtual memory or this is how kernel wants us to do...

Mallikarjuna Reddy
  • 1,212
  • 2
  • 20
  • 33

1 Answers1

1

Yes, it is absolutely necessary. (On x86) Once paging is enabled in the CPU, all addresses visible to the OS (so you, the driver developer) are virtual addresses. In other words, any address you read from or write to will be interpreted by the CPU as a virtual address. It will then go through the page table hierarchy to finally arrive at a physical address to put on the bus.

You can't use physical addresses - they will not be mapped, or mapped to something other than what you want. This is why ioremap must exist and be used.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328