diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index 8b90e07c1b2a..83e6cc9dbd0d 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -105,6 +105,14 @@ config POWER_RESET_MSM help Power off and restart support for Qualcomm boards. +config POWER_RESET_QCOM_VM + tristate "Qualcomm Technologies, Inc. MSM VM power-off driver" + help + Power off and restart support for Qualcomm Technologies, Inc. virtual + machine. This driver supports virtual machine power down and restart. + Say Y here if you have a MSM virtual machine and wish to enable + restart driver. + config POWER_RESET_QCOM_DOWNLOAD_MODE tristate "MSM download mode driver" depends on ARCH_QCOM diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 5c68698f8920..84e6ad65fdbe 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o +obj-$(CONFIG_POWER_RESET_QCOM_VM) += msm-vm-poweroff.o obj-$(CONFIG_POWER_RESET_QCOM_DOWNLOAD_MODE) += qcom-dload-mode.o obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o obj-$(CONFIG_POWER_RESET_QCOM_REBOOT_REASON) += qcom-reboot-reason.o diff --git a/drivers/power/reset/msm-vm-poweroff.c b/drivers/power/reset/msm-vm-poweroff.c new file mode 100644 index 000000000000..3b29274bf608 --- /dev/null +++ b/drivers/power/reset/msm-vm-poweroff.c @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static int in_panic; +static struct notifier_block restart_nb; + +static int panic_prep_restart(struct notifier_block *this, + unsigned long event, void *ptr) +{ + in_panic = 1; + return NOTIFY_DONE; +} + +static struct notifier_block panic_blk = { + .notifier_call = panic_prep_restart, +}; + +static int do_vm_restart(struct notifier_block *unused, unsigned long action, + void *arg) +{ + pr_notice("Going down for vm restart now\n"); + + flush_cache_all(); + + /*outer_flush_all is not supported by 64bit kernel*/ +#ifndef CONFIG_ARM64 + outer_flush_all(); +#endif + + if (in_panic) + qcom_wdt_trigger_bite(); + + return NOTIFY_DONE; +} + +static int vm_restart_probe(struct platform_device *pdev) +{ + atomic_notifier_chain_register(&panic_notifier_list, &panic_blk); + + restart_nb.notifier_call = do_vm_restart; + restart_nb.priority = 200; + register_restart_handler(&restart_nb); + + return 0; +} + +static const struct of_device_id of_vm_restart_match[] = { + { .compatible = "qcom,vm-restart", }, + {}, +}; +MODULE_DEVICE_TABLE(of, of_vm_restart_match); + +static struct platform_driver vm_restart_driver = { + .probe = vm_restart_probe, + .driver = { + .name = "msm-vm-restart", + .of_match_table = of_match_ptr(of_vm_restart_match), + }, +}; + +static int __init vm_restart_init(void) +{ + return platform_driver_register(&vm_restart_driver); +} + +#if IS_MODULE(CONFIG_POWER_RESET_QCOM_VM) +module_init(vm_restart_init); +#else +pure_initcall(vm_restart_init); +#endif + +static __exit void vm_restart_exit(void) +{ + platform_driver_unregister(&vm_restart_driver); +} +module_exit(vm_restart_exit); + +MODULE_DESCRIPTION("MSM VM Poweroff Driver"); +MODULE_LICENSE("GPL v2");