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