upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / media / video / samsung / ump / linux / ump_memory_backend.c
1 /*
2  * Copyright (C) 2010 ARM Limited. All rights reserved.
3  * 
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  * 
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 #include <linux/module.h>            /* kernel module definitions */
12 #include <linux/ioport.h>            /* request_mem_region */
13
14 #include "arch/config.h"             /* Configuration for current platform. The symlink for arch is set by Makefile */
15
16 #include "ump_osk.h"
17 #include "ump_kernel_common.h"
18 #include "ump_kernel_memory_backend_os.h"
19 #include "ump_kernel_memory_backend_dedicated.h"
20
21 #ifdef CONFIG_UMP_VCM_ALLOC
22 #include "ump_kernel_memory_backend_vcm.h"
23 #endif
24
25 /* Configure which dynamic memory allocator to use */
26 int ump_backend = ARCH_UMP_BACKEND_DEFAULT;
27 module_param(ump_backend, int, S_IRUGO); /* r--r--r-- */
28 MODULE_PARM_DESC(ump_backend, "0 = dedicated memory backend (default), 1 = OS memory backend");
29
30 /* The base address of the memory block for the dedicated memory backend */
31 unsigned int ump_memory_address = ARCH_UMP_MEMORY_ADDRESS_DEFAULT;
32 module_param(ump_memory_address, uint, S_IRUGO); /* r--r--r-- */
33 MODULE_PARM_DESC(ump_memory_address, "The physical address to map for the dedicated memory backend");
34
35 /* The size of the memory block for the dedicated memory backend */
36 unsigned int ump_memory_size = ARCH_UMP_MEMORY_SIZE_DEFAULT;
37 module_param(ump_memory_size, uint, S_IRUGO); /* r--r--r-- */
38 MODULE_PARM_DESC(ump_memory_size, "The size of fixed memory to map in the dedicated memory backend");
39
40 ump_memory_backend* ump_memory_backend_create ( void )
41 {
42         ump_memory_backend * backend = NULL;
43
44         /* Create the dynamic memory allocator backend */
45         if (0 == ump_backend)
46         {
47                 DBG_MSG(2, ("Using dedicated memory backend\n"));
48
49                 DBG_MSG(2, ("Requesting dedicated memory: 0x%08x, size: %u\n", ump_memory_address, ump_memory_size));
50                 /* Ask the OS if we can use the specified physical memory */
51                 if (NULL == request_mem_region(ump_memory_address, ump_memory_size, "UMP Memory"))
52                 {
53                         MSG_ERR(("Failed to request memory region (0x%08X - 0x%08X). Is Mali DD already loaded?\n", ump_memory_address, ump_memory_address + ump_memory_size - 1));
54                         return NULL;
55                 }
56                 backend = ump_block_allocator_create(ump_memory_address, ump_memory_size);
57         }
58         else if (1 == ump_backend)
59         {
60                 DBG_MSG(2, ("Using OS memory backend, allocation limit: %d\n", ump_memory_size));
61                 backend = ump_os_memory_backend_create(ump_memory_size);
62         }
63 #ifdef CONFIG_UMP_VCM_ALLOC
64         else if (2 == ump_backend)
65         {
66                 DBG_MSG(2, ("Using VCM memory backend, allocation limit: %d\n", ump_memory_size));
67                 backend = ump_vcm_memory_backend_create(ump_memory_size);
68         }
69 #endif
70
71         return backend;
72 }
73
74 void ump_memory_backend_destroy( void )
75 {
76         if (0 == ump_backend)
77         {
78                 DBG_MSG(2, ("Releasing dedicated memory: 0x%08x\n", ump_memory_address));
79                 release_mem_region(ump_memory_address, ump_memory_size);
80         }
81 }