reserve system memory, ioremap()?

5.1k views Asked by At

Is it bad to call ioremap() on system DRAM. I would like to reserve a space in system DRAM that will not be used by any other process. Would this be the way to do it? I know that DRAM is not actually IO memory so I wasn't sure if this was considered bad practice.

2

There are 2 answers

0
sawdust On

Is it bad to call ioremap() on system DRAM.

System memory that is managed by the kernel should not also be remapped using ioremap(). These multiple mappings can cause data corruption on some architectures/processors. Refer to this article on this issue for ARM.

You could try to ensure a single mapping (using ioremap()) by excluding the memory region in question at boot time from the kernel's management.
On ARM specify the reduced physical memory using ATAGs (the ATAG_MEM tag(s)) or the Device Tree (the memory property).
Otherwise use the memmap= kernel parameter in the kernel command line:

1835         memmap=nn[KMG]$ss[KMG]
1836                         [KNL,ACPI] Mark specific memory as reserved.
1837                         Region of memory to be reserved is from ss to ss+nn.
1838                         Example: Exclude memory from 0x18690000-0x1869ffff
1839                                  memmap=64K$0x18690000
1840                                  or
1841                                  memmap=0x10000$0x18690000

The memory region should also be declared through request_mem_region() to prevent multiple requests and for completeness/accuracy of /proc/iomem.

0
Manx On

Memory can be reserved during system boot time by using "mem" in the kernel command line argument.

LDD3 Ch-15 Pg 443

For example, if you have 256 MB, the argument mem=255M keeps the kernel from using the top megabyte. Your module could later use the following code to gain access to such memory:

dmabuf = ioremap (0xFF00000 /* 255M /, 0x100000 / 1M */);

However this is not efficient way of doing it since the kernel cannot use this reserved memory. On the SoC I'm currently working, memory is reserved using Contiguous Memory Allocator(CMA) which allows memory to be reused by other processes when the SoC drivers are not using this memory.