cregit-Linux how code gets into the kernel

Release 4.16 drivers/watchdog/xen_wdt.c

Directory: drivers/watchdog
/*
 *      Xen Watchdog Driver
 *
 *      (c) Copyright 2010 Novell, Inc.
 *
 *      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; either version
 *      2 of the License, or (at your option) any later version.
 */


#define DRV_NAME	"xen_wdt"

#include <linux/bug.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/hrtimer.h>
#include <linux/kernel.h>
#include <linux/ktime.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/platform_device.h>
#include <linux/watchdog.h>
#include <xen/xen.h>
#include <asm/xen/hypercall.h>
#include <xen/interface/sched.h>


static struct platform_device *platform_device;

static struct sched_watchdog wdt;

static time64_t wdt_expires;


#define WATCHDOG_TIMEOUT 60 
/* in seconds */

static unsigned int timeout;
module_param(timeout, uint, S_IRUGO);
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds "
	"(default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");


static bool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, S_IRUGO);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
	"(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");


static inline time64_t set_timeout(struct watchdog_device *wdd) { wdt.timeout = wdd->timeout; return ktime_get_seconds() + wdd->timeout; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich1864.29%133.33%
Radu Rendec828.57%133.33%
Arnd Bergmann27.14%133.33%
Total28100.00%3100.00%


static int xen_wdt_start(struct watchdog_device *wdd) { time64_t expires; int err; expires = set_timeout(wdd); if (!wdt.id) err = HYPERVISOR_sched_op(SCHEDOP_watchdog, &wdt); else err = -EBUSY; if (err > 0) { wdt.id = err; wdt_expires = expires; err = 0; } else BUG_ON(!err); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich7189.87%133.33%
Radu Rendec78.86%133.33%
Arnd Bergmann11.27%133.33%
Total79100.00%3100.00%


static int xen_wdt_stop(struct watchdog_device *wdd) { int err = 0; wdt.timeout = 0; if (wdt.id) err = HYPERVISOR_sched_op(SCHEDOP_watchdog, &wdt); if (!err) wdt.id = 0; return err; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich4892.31%150.00%
Radu Rendec47.69%150.00%
Total52100.00%2100.00%


static int xen_wdt_kick(struct watchdog_device *wdd) { time64_t expires; int err; expires = set_timeout(wdd); if (wdt.id) err = HYPERVISOR_sched_op(SCHEDOP_watchdog, &wdt); else err = -ENXIO; if (!err) wdt_expires = expires; return err; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich5086.21%133.33%
Radu Rendec712.07%133.33%
Arnd Bergmann11.72%133.33%
Total58100.00%3100.00%


static unsigned int xen_wdt_get_timeleft(struct watchdog_device *wdd) { return wdt_expires - ktime_get_seconds(); }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich1266.67%150.00%
Radu Rendec633.33%150.00%
Total18100.00%2100.00%

static struct watchdog_info xen_wdt_info = { .identity = DRV_NAME, .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, }; static const struct watchdog_ops xen_wdt_ops = { .owner = THIS_MODULE, .start = xen_wdt_start, .stop = xen_wdt_stop, .ping = xen_wdt_kick, .get_timeleft = xen_wdt_get_timeleft, }; static struct watchdog_device xen_wdt_dev = { .info = &xen_wdt_info, .ops = &xen_wdt_ops, .timeout = WATCHDOG_TIMEOUT, };
static int xen_wdt_probe(struct platform_device *pdev) { struct sched_watchdog wd = { .id = ~0 }; int ret = HYPERVISOR_sched_op(SCHEDOP_watchdog, &wd); if (ret == -ENOSYS) { dev_err(&pdev->dev, "watchdog not supported by hypervisor\n"); return -ENODEV; } if (ret != -EINVAL) { dev_err(&pdev->dev, "unexpected hypervisor error (%d)\n", ret); return -ENODEV; } if (watchdog_init_timeout(&xen_wdt_dev, timeout, NULL)) dev_info(&pdev->dev, "timeout value invalid, using %d\n", xen_wdt_dev.timeout); watchdog_set_nowayout(&xen_wdt_dev, nowayout); watchdog_stop_on_reboot(&xen_wdt_dev); watchdog_stop_on_unregister(&xen_wdt_dev); ret = devm_watchdog_register_device(&pdev->dev, &xen_wdt_dev); if (ret) { dev_err(&pdev->dev, "cannot register watchdog device (%d)\n", ret); return ret; } dev_info(&pdev->dev, "initialized (timeout=%ds, nowayout=%d)\n", xen_wdt_dev.timeout, nowayout); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Radu Rendec9753.59%133.33%
Jan Beulich7843.09%133.33%
Joe Perches63.31%133.33%
Total181100.00%3100.00%


static int xen_wdt_suspend(struct platform_device *dev, pm_message_t state) { typeof(wdt.id) id = wdt.id; int rc = xen_wdt_stop(&xen_wdt_dev); wdt.id = id; return rc; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich3890.48%266.67%
Radu Rendec49.52%133.33%
Total42100.00%3100.00%


static int xen_wdt_resume(struct platform_device *dev) { if (!wdt.id) return 0; wdt.id = 0; return xen_wdt_start(&xen_wdt_dev); }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich3088.24%266.67%
Radu Rendec411.76%133.33%
Total34100.00%3100.00%

static struct platform_driver xen_wdt_driver = { .probe = xen_wdt_probe, .suspend = xen_wdt_suspend, .resume = xen_wdt_resume, .driver = { .name = DRV_NAME, }, };
static int __init xen_wdt_init_module(void) { int err; if (!xen_domain()) return -ENODEV; err = platform_driver_register(&xen_wdt_driver); if (err) return err; platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0); if (IS_ERR(platform_device)) { err = PTR_ERR(platform_device); platform_driver_unregister(&xen_wdt_driver); } return err; }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich76100.00%1100.00%
Total76100.00%1100.00%


static void __exit xen_wdt_cleanup_module(void) { platform_device_unregister(platform_device); platform_driver_unregister(&xen_wdt_driver); }

Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich20100.00%1100.00%
Total20100.00%1100.00%

module_init(xen_wdt_init_module); module_exit(xen_wdt_cleanup_module); MODULE_AUTHOR("Jan Beulich <jbeulich@novell.com>"); MODULE_DESCRIPTION("Xen WatchDog Timer Driver"); MODULE_LICENSE("GPL");

Overall Contributors

PersonTokensPropCommitsCommitProp
Jan Beulich62774.20%350.00%
Radu Rendec20724.50%116.67%
Joe Perches60.71%116.67%
Arnd Bergmann50.59%116.67%
Total845100.00%6100.00%
Directory: drivers/watchdog
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.