Android pmem has two main functions (from Android mail list ):
1. GPU or VPU buffers shared with CPU Core
2. Android Service heap.
Among them, 1 cannot be cached, 2 can be cached, and cached = x in platform device registration controls whether the data can be cached.
========================================================== ========================================================== ========
The pmem driver has the following content:
Pmem_init () driver Loading
|
Pmem_probe () platform Loading
|
Pmem_setup ()
Initialize pmem [ID]
Output Information at startup, in the format of [name] [can be cached] eg: pmem_adsp: 0 init
Misc_register ()
Initialize all bitmaps
Obtain all pmem [ID]. vbase through ioremap
Pmem_map () provides the MMAP Interface
Pmem_ioctl ()
# Define pmem_get_phys obtain the physical address
# Define pmem_map pmem_remap ()
# Define pmem_get_size pmem_getsize ()
# Define pmem_unmap pmem_remap (ion, file, pmem_unmap );
# Define pmem_allocate allocates pmem space. Len is a parameter. If the file has been allocated, it fails.
# Define pmem_connect connect a pmem file to other devices
# Define pmem_get_total_size returns the full size of pmem Region
Android uses the pmem driver in Linux for memory allocation.
Through reading the code, I made a simple diagram of the relationship between the allocation.
CTRL + mouse wheel to zoom in/out "width =" 896 ">
Note:
1. pmem_probe
A. Obtain the memory space of the device, including the physical address and size.
B. initialize the space management module by region
C. ioremap2. pmem_open
A. Create a New pmem_data Structure
B. Create a linked list with pmem [].
3. pmem_mmap
A. Adjust the space management module based on MMAP size requirements. And obtain the required space from the device.
B. Create a page table for the obtained Region
C. If the page is in connected state, you need to create a new page table for each subarea.
4. IOCTL: pmem_map
A. ensure the feasibility of MAP and obtain the region of the map request.
B. Create a New region_node and save the obtained region information to region_node.
C. Establish a linked list relationship with region_list
5. IOCTL: pmem_unmap
A. Remove the requested region from region_list
B. Release the page table
6. IOCTL: pmem_connect
A. link the file to be connected to the current file. It is equivalent to ing two files to the same region.
7. IOCTL: pmem_allocate
A. Adjust the space management module based on the allocate size requirement. And obtain the required space from the device.
For example, pmem defines 8 m space, while Android needs to obtain 1 m space.
There is an article worth referring to http://linux.chinaunix.net/techdoc/net/2009/04/21/1108452.shtml
========================================================== ========================================================== ========
Pmem is used in applications, which requires further research.
# Include "android_pmem.h"
Int pmem_fd;
Void * pmem_base;
Unsigned int size;
Struct pmem_region region;
Pmem_fd = open ("/dev/pmem_adsp", o_rdwr, 0); // open the device. To operate the hardware engine
If (pmem_fd> = 0)
{
If (IOCTL (pmem_fd, pmem_get_total_size, ion) <0) // obtain all space
{
Printf ("pmem_get_total_size failed ");
Size = 4 <20; // 4 MIB
}
Else
{
Size = region. Len;
}
Pmem_base = MMAP (0, size, prot_read | prot_write, map_shared, pmem_fd, 0); // MMAP operation
If (pmem_base = map_failed)
{
Pmem_base = 0;
Close (pmem_fd );
Pmem_fd =-1;
Printf ("MMAP pmem error! ");
}
If (IOCTL (pmem_fd, pmem_get_phys, ion) <0) // obtain the physical address
{
Printf ("pmem_get_phys failed ");
}
}
In fact, the first IOCTL is useless, just to get the length, you can also specify the length.
After the preceding operations, Region. offset is the physical address, and its space corresponds to the virtual address pmem_base.
Fill in pmem_base data in the program, and use region. offset to configure the physical address for VPU and GPU.
========================================================== ========================================================== ========
Finally, let's take a look at the driver call process.
1) Open Operation
[Drivers/MISC/pmem. C: pmem_open: 336] current 55 file c7355c80 (1)
2) MMAP will automatically call allocate
[Drivers/MISC/pmem. C: pmem_allocate: 398] Order 0
[Drivers/MISC/pmem. C: pmem_map_pfn_range: 511] map offset 0 Len 10000
3) IOCTL pmem_get_phys: the physical address is determined by the PID.
[Drivers/MISC/pmem. C: pmem_ioctl: 1081] get_phys
Pmem: Request for physical address of pmem region from process 55.
4) munmap
[Drivers/MISC/pmem. C: pmem_vma_close: 555] current 55 ppid 47 file c7355c80 count 2