msm_migrate_pages.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2010, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/platform_device.h>
  14. #include <linux/memory.h>
  15. #include <linux/memory_hotplug.h>
  16. #include <linux/module.h>
  17. #include <mach/msm_migrate_pages.h>
  18. static unsigned long unstable_memory_state;
  19. unsigned long get_msm_migrate_pages_status(void)
  20. {
  21. return unstable_memory_state;
  22. }
  23. EXPORT_SYMBOL(get_msm_migrate_pages_status);
  24. #ifdef CONFIG_MEMORY_HOTPLUG
  25. static int migrate_pages_callback(struct notifier_block *self,
  26. unsigned long action, void *arg)
  27. {
  28. int ret = 0;
  29. switch (action) {
  30. case MEM_ONLINE:
  31. unstable_memory_state = action;
  32. break;
  33. case MEM_OFFLINE:
  34. unstable_memory_state = action;
  35. break;
  36. case MEM_GOING_OFFLINE:
  37. case MEM_GOING_ONLINE:
  38. case MEM_CANCEL_ONLINE:
  39. case MEM_CANCEL_OFFLINE:
  40. break;
  41. }
  42. return ret;
  43. }
  44. #endif
  45. static int __devinit msm_migrate_pages_probe(struct platform_device *pdev)
  46. {
  47. #ifdef CONFIG_MEMORY_HOTPLUG
  48. hotplug_memory_notifier(migrate_pages_callback, 0);
  49. #endif
  50. unstable_memory_state = 0;
  51. return 0;
  52. }
  53. static struct platform_driver msm_migrate_pages_driver = {
  54. .probe = msm_migrate_pages_probe,
  55. .driver = {
  56. .name = "msm_migrate_pages",
  57. },
  58. };
  59. static int __init msm_migrate_pages_init(void)
  60. {
  61. return platform_driver_register(&msm_migrate_pages_driver);
  62. }
  63. static void __exit msm_migrate_pages_exit(void)
  64. {
  65. platform_driver_unregister(&msm_migrate_pages_driver);
  66. }
  67. module_init(msm_migrate_pages_init);
  68. module_exit(msm_migrate_pages_exit);
  69. MODULE_LICENSE("GPL v2");
  70. MODULE_DESCRIPTION("Get Status of Unstable Memory Region");