Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010, Code Aurora Forum. 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 | |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/memory.h> |
| 16 | #include <linux/memory_hotplug.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | #include <mach/msm_migrate_pages.h> |
| 19 | |
| 20 | static unsigned long unstable_memory_state; |
| 21 | |
| 22 | unsigned long get_msm_migrate_pages_status(void) |
| 23 | { |
| 24 | return unstable_memory_state; |
| 25 | } |
| 26 | EXPORT_SYMBOL(get_msm_migrate_pages_status); |
| 27 | |
| 28 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 29 | static int migrate_pages_callback(struct notifier_block *self, |
| 30 | unsigned long action, void *arg) |
| 31 | { |
| 32 | int ret = 0; |
| 33 | |
| 34 | switch (action) { |
| 35 | case MEM_ONLINE: |
| 36 | unstable_memory_state = action; |
| 37 | break; |
| 38 | case MEM_OFFLINE: |
| 39 | unstable_memory_state = action; |
| 40 | break; |
| 41 | case MEM_GOING_OFFLINE: |
| 42 | case MEM_GOING_ONLINE: |
| 43 | case MEM_CANCEL_ONLINE: |
| 44 | case MEM_CANCEL_OFFLINE: |
| 45 | break; |
| 46 | } |
| 47 | return ret; |
| 48 | } |
| 49 | #endif |
| 50 | |
| 51 | static int __devinit msm_migrate_pages_probe(struct platform_device *pdev) |
| 52 | { |
| 53 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 54 | hotplug_memory_notifier(migrate_pages_callback, 0); |
| 55 | #endif |
| 56 | unstable_memory_state = 0; |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static struct platform_driver msm_migrate_pages_driver = { |
| 61 | .probe = msm_migrate_pages_probe, |
| 62 | .driver = { |
| 63 | .name = "msm_migrate_pages", |
| 64 | }, |
| 65 | }; |
| 66 | |
| 67 | static int __init msm_migrate_pages_init(void) |
| 68 | { |
| 69 | return platform_driver_register(&msm_migrate_pages_driver); |
| 70 | } |
| 71 | |
| 72 | static void __exit msm_migrate_pages_exit(void) |
| 73 | { |
| 74 | platform_driver_unregister(&msm_migrate_pages_driver); |
| 75 | } |
| 76 | |
| 77 | module_init(msm_migrate_pages_init); |
| 78 | module_exit(msm_migrate_pages_exit); |
| 79 | |
| 80 | MODULE_LICENSE("GPL v2"); |
| 81 | MODULE_DESCRIPTION("Get Status of Unstable Memory Region"); |