ump_memory_backend.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <linux/module.h> /* kernel module definitions */
  11. #include <linux/ioport.h> /* request_mem_region */
  12. #include "arch/config.h" /* Configuration for current platform. The symlink for arch is set by Makefile */
  13. #include "ump_osk.h"
  14. #include "ump_kernel_common.h"
  15. #include "ump_kernel_memory_backend_os.h"
  16. #include "ump_kernel_memory_backend_dedicated.h"
  17. /* Configure which dynamic memory allocator to use */
  18. int ump_backend = ARCH_UMP_BACKEND_DEFAULT;
  19. module_param(ump_backend, int, S_IRUGO); /* r--r--r-- */
  20. MODULE_PARM_DESC(ump_backend, "0 = dedicated memory backend (default), 1 = OS memory backend");
  21. /* The base address of the memory block for the dedicated memory backend */
  22. unsigned int ump_memory_address = ARCH_UMP_MEMORY_ADDRESS_DEFAULT;
  23. module_param(ump_memory_address, uint, S_IRUGO); /* r--r--r-- */
  24. MODULE_PARM_DESC(ump_memory_address, "The physical address to map for the dedicated memory backend");
  25. /* The size of the memory block for the dedicated memory backend */
  26. unsigned int ump_memory_size = ARCH_UMP_MEMORY_SIZE_DEFAULT;
  27. module_param(ump_memory_size, uint, S_IRUGO); /* r--r--r-- */
  28. MODULE_PARM_DESC(ump_memory_size, "The size of fixed memory to map in the dedicated memory backend");
  29. ump_memory_backend* ump_memory_backend_create ( void )
  30. {
  31. ump_memory_backend * backend = NULL;
  32. /* Create the dynamic memory allocator backend */
  33. if (0 == ump_backend)
  34. {
  35. DBG_MSG(2, ("Using dedicated memory backend\n"));
  36. DBG_MSG(2, ("Requesting dedicated memory: 0x%08x, size: %u\n", ump_memory_address, ump_memory_size));
  37. /* Ask the OS if we can use the specified physical memory */
  38. if (NULL == request_mem_region(ump_memory_address, ump_memory_size, "UMP Memory"))
  39. {
  40. 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));
  41. return NULL;
  42. }
  43. backend = ump_block_allocator_create(ump_memory_address, ump_memory_size);
  44. }
  45. else if (1 == ump_backend)
  46. {
  47. DBG_MSG(2, ("Using OS memory backend, allocation limit: %d\n", ump_memory_size));
  48. backend = ump_os_memory_backend_create(ump_memory_size);
  49. }
  50. return backend;
  51. }
  52. void ump_memory_backend_destroy( void )
  53. {
  54. if (0 == ump_backend)
  55. {
  56. DBG_MSG(2, ("Releasing dedicated memory: 0x%08x\n", ump_memory_address));
  57. release_mem_region(ump_memory_address, ump_memory_size);
  58. }
  59. }