From 4c6901d0a6b19541d3bfa9201ccafff10f978a77 Mon Sep 17 00:00:00 2001 From: Ryan Lattrel Date: Thu, 4 Jan 2018 10:12:05 -0600 Subject: [PATCH] watchdogtest: add module to test watchdog Convert the watchdog test to a lkm. Change-Id: Ifa83ce4790a52865ed82d67f1a304b8804c9bf64 Signed-off-by: Ryan Lattrel Reviewed-on: https://gerrit.mot.com/1111988 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Kenneth Kessler Reviewed-by: Dong-Hua Yan Submit-Approved: Jira Key --- drivers/watchdogtest/Android.mk | 8 +++ drivers/watchdogtest/Kbuild | 5 ++ drivers/watchdogtest/Makefile | 10 ++++ drivers/watchdogtest/watchdogtest.c | 85 +++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 drivers/watchdogtest/Android.mk create mode 100644 drivers/watchdogtest/Kbuild create mode 100644 drivers/watchdogtest/Makefile create mode 100644 drivers/watchdogtest/watchdogtest.c diff --git a/drivers/watchdogtest/Android.mk b/drivers/watchdogtest/Android.mk new file mode 100644 index 000000000000..f3e91f92216e --- /dev/null +++ b/drivers/watchdogtest/Android.mk @@ -0,0 +1,8 @@ +DLKM_DIR := motorola/kernel/modules +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := watchdogtest.ko +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT) +include $(DLKM_DIR)/AndroidKernelModule.mk diff --git a/drivers/watchdogtest/Kbuild b/drivers/watchdogtest/Kbuild new file mode 100644 index 000000000000..d8eee6e505d0 --- /dev/null +++ b/drivers/watchdogtest/Kbuild @@ -0,0 +1,5 @@ +# add -Wall to try to catch everything we can. +EXTRA_CFLAGS += -Wall +EXTRA_CFLAGS += -I$(TOP)/motorola/kernel/modules/include + +obj-m += watchdogtest.o \ No newline at end of file diff --git a/drivers/watchdogtest/Makefile b/drivers/watchdogtest/Makefile new file mode 100644 index 000000000000..34b09dd815a7 --- /dev/null +++ b/drivers/watchdogtest/Makefile @@ -0,0 +1,10 @@ +KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build + +all: + $(MAKE) -C $(KERNEL_SRC) M=$(shell pwd) modules $(KBUILD_OPTIONS) + +modules_install: + $(MAKE) INSTALL_MOD_STRIP=1 -C $(KERNEL_SRC) M=$(shell pwd) modules_install + +clean: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean \ No newline at end of file diff --git a/drivers/watchdogtest/watchdogtest.c b/drivers/watchdogtest/watchdogtest.c new file mode 100644 index 000000000000..6d85154eafa0 --- /dev/null +++ b/drivers/watchdogtest/watchdogtest.c @@ -0,0 +1,85 @@ +/* + * Simple softlockup watchdog regression test module + * + * Copyright (C) 2012 Motorola Mobility LLC. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +static struct dentry *dbgfs_fire_softlockup; +static struct dentry *dbgfs_fire_watchdog; + +#ifndef CONFIG_QCOM_WATCHDOG_V2 +struct completion wdt_timeout_complete; +static void wdt_timeout_work(struct work_struct *work) +{ + local_irq_disable(); + while (1) + ; + local_irq_enable(); + complete(&wdt_timeout_complete); +} +static DECLARE_WORK(wdt_timeout_work_struct, wdt_timeout_work); +#endif + +static int fire_watchdog_reset_set(void *data, u64 val) +{ + + printk(KERN_WARNING "Fire hardware watchdog reset.\n"); + printk(KERN_WARNING "Please wait ...\n"); +#ifdef CONFIG_QCOM_WATCHDOG_V2 + msm_trigger_wdog_bite(); +#else + init_completion(&wdt_timeout_complete); + schedule_work_on(0, &wdt_timeout_work_struct); + wait_for_completion(&wdt_timeout_complete); +#endif + return 0; +} +DEFINE_SIMPLE_ATTRIBUTE(fire_watchdog_reset_fops, + NULL, fire_watchdog_reset_set, "%llu\n"); + +static int fire_softlockup_reset_set(void *data, u64 val) +{ + printk(KERN_WARNING "Fire softlockup watchdog reset.\n"); + printk(KERN_WARNING "Please wait ...\n"); + preempt_disable(); + while (1) + ; + + return 0; +} +DEFINE_SIMPLE_ATTRIBUTE(fire_softlockup_reset_fops, + NULL, fire_softlockup_reset_set, "%llu\n"); + +static int watchdog_test_init(void) +{ + dbgfs_fire_softlockup = debugfs_create_file("fire_softlockup_reset", + 0200, NULL, NULL, &fire_softlockup_reset_fops); + dbgfs_fire_watchdog = debugfs_create_file("fire_watchdog_reset", + 0200, NULL, NULL, &fire_watchdog_reset_fops); + return 0; +} + +static void watchdog_test_exit(void) +{ + if(dbgfs_fire_softlockup) + debugfs_remove(dbgfs_fire_softlockup); + if(dbgfs_fire_watchdog) + debugfs_remove(dbgfs_fire_watchdog); +} + +module_init(watchdog_test_init); +module_exit(watchdog_test_exit); +MODULE_LICENSE("GPL");