Gu.
Gu.

Reputation: 123

How to choose static IO memory map for virtual memory on ARM

I am investigating how to port the Linux kernel to a new ARM platform. I noticed that some platform implementations have static mapping from a physical IO address to a virtual address in map_io function.

My question is how should I decide the "virtual" address in structure map_desc? Can I map a physical IO to arbitrary virtual memory? or are there some rules or good practice about it? I checked http://lxr.free-electrons.com/source/Documentation/arm/memory.txt , but did not find any answers.

Here are some examples of map_desc and map_io:

http://lxr.free-electrons.com/source/arch/arm/mach-versatile/versatile_dt.c#L45

 44 DT_MACHINE_START(VERSATILE_PB, "ARM-Versatile (Device Tree Support)")
 45         .map_io         = versatile_map_io,
 46         .init_early     = versatile_init_early,
 47         .init_machine   = versatile_dt_init,
 48         .dt_compat      = versatile_dt_match,
 49         .restart        = versatile_restart,
 50 MACHINE_END

http://lxr.free-electrons.com/source/arch/arm/mach-versatile/core.c#L189

189 void __init versatile_map_io(void)
190 {
191         iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
192 }

131 static struct map_desc versatile_io_desc[] __initdata __maybe_unused = {
132         {
133                 .virtual        =  IO_ADDRESS(VERSATILE_SYS_BASE),
134                 .pfn            = __phys_to_pfn(VERSATILE_SYS_BASE),
135                 .length         = SZ_4K,
136                 .type           = MT_DEVICE
137         }, {

Upvotes: 1

Views: 1291

Answers (1)

auselen
auselen

Reputation: 28087

too long for a comment...

Not an expert but, since map_desc is for static mappings. It should be from system manuals. virtual is how the peripheral can be accessed from kernel virtual space, pfn (page frame number) is physical address by page units.

Thing is if you are in kernel space, you are using kernel virtual space mappings so even you want to access a certain physical address you need to have a mapping for that which can be one-to-one which I believe what you get out of map_desc.

Static mapping is map_desc, dynamic mapping is ioremap. So if you want to play with physical IO, ioremap is first thing if that doesn't work then for special cases map_desc.

DMA-API-HOWTO provides a good entry point to different kind of addresses mappings in Linux.

Upvotes: 1

Related Questions