mali mess
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / mt8127 / mali / ump / linux / ump_memory_backend.c
CommitLineData
6fa3eb70
S
1/*
2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
02af6beb 4 * (C) COPYRIGHT 2009-2010, 2013-2015 ARM Limited
6fa3eb70
S
5 * ALL RIGHTS RESERVED
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
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/* Configure which dynamic memory allocator to use */
22int ump_backend = ARCH_UMP_BACKEND_DEFAULT;
23module_param(ump_backend, int, S_IRUGO); /* r--r--r-- */
24MODULE_PARM_DESC(ump_backend, "0 = dedicated memory backend (default), 1 = OS memory backend");
25
26/* The base address of the memory block for the dedicated memory backend */
27unsigned int ump_memory_address = ARCH_UMP_MEMORY_ADDRESS_DEFAULT;
28module_param(ump_memory_address, uint, S_IRUGO); /* r--r--r-- */
29MODULE_PARM_DESC(ump_memory_address, "The physical address to map for the dedicated memory backend");
30
31/* The size of the memory block for the dedicated memory backend */
32unsigned int ump_memory_size = ARCH_UMP_MEMORY_SIZE_DEFAULT;
33module_param(ump_memory_size, uint, S_IRUGO); /* r--r--r-- */
34MODULE_PARM_DESC(ump_memory_size, "The size of fixed memory to map in the dedicated memory backend");
35
02af6beb 36ump_memory_backend *ump_memory_backend_create(void)
6fa3eb70 37{
02af6beb 38 ump_memory_backend *backend = NULL;
6fa3eb70
S
39
40 /* Create the dynamic memory allocator backend */
41 if (0 == ump_backend) {
42 DBG_MSG(2, ("Using dedicated memory backend\n"));
43
44 DBG_MSG(2, ("Requesting dedicated memory: 0x%08x, size: %u\n", ump_memory_address, ump_memory_size));
45 /* Ask the OS if we can use the specified physical memory */
46 if (NULL == request_mem_region(ump_memory_address, ump_memory_size, "UMP Memory")) {
47 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));
48 return NULL;
49 }
50 backend = ump_block_allocator_create(ump_memory_address, ump_memory_size);
51 } else if (1 == ump_backend) {
52 DBG_MSG(2, ("Using OS memory backend, allocation limit: %d\n", ump_memory_size));
53 backend = ump_os_memory_backend_create(ump_memory_size);
54 }
55
56 return backend;
57}
58
02af6beb 59void ump_memory_backend_destroy(void)
6fa3eb70
S
60{
61 if (0 == ump_backend) {
62 DBG_MSG(2, ("Releasing dedicated memory: 0x%08x\n", ump_memory_address));
63 release_mem_region(ump_memory_address, ump_memory_size);
64 }
65}