Exemplo n.º 1
0
static ssize_t watchdog_write(struct file *filp, const char *buf, size_t len, loff_t *off)
{
	/*  Refresh the timer. */
	if (len) {
		watchdog_keepalive();
	}
	return len;

}
Exemplo n.º 2
0
static int watchdog_ioctl(struct inode *inode, struct file *filp,
			  unsigned int cmd, unsigned long arg)
{
	void __user *argp = (void __user *)arg;
	int margin;

	switch(cmd)
	{
	case WDIOC_GETSUPPORT:
		return copy_to_user(argp, &sl351x_wdt_ident,
				    sizeof(sl351x_wdt_ident)) ? -EFAULT : 0;

	case WDIOC_GETSTATUS:
	case WDIOC_GETBOOTSTATUS:
		return put_user(0, (int __user*)argp);

	case WDIOC_KEEPALIVE:
		watchdog_keepalive();
		return 0;

	case WDIOC_SETTIMEOUT:
		if (get_user(margin, (int __user*)argp))
			return -EFAULT;

		/* Arbitrary, can't find the card's limits */
		if ((margin < 0) || (margin > 60))
			return -EINVAL;

		// watchdog_disable();
		wdt_margin = margin;
		watchdog_set_timeout(margin);
		watchdog_keepalive();
		// watchdog_enable();

		/* Fall through */

	case WDIOC_GETTIMEOUT:
		return put_user(wdt_margin, (int *)arg);

	default:
		return -ENOIOCTLCMD;
	}
}
/* Write */
static ssize_t intel_scu_write(struct file *file, char const *data, size_t len,
			      loff_t *ppos)
{
	pr_debug("watchdog %s\n", __func__);

	if (watchdog_device.shutdown_flag == true)
		/* do nothing if we are shutting down */
		return len;

	if (watchdog_device.started) {
		/* Watchdog already started, keep it alive */
		watchdog_keepalive();
	}

	return len;
}
/* Write */
static ssize_t intel_scu_write(struct file *file, char const *data, size_t len,
			      loff_t *ppos)
{
	pr_debug(PFX "watchdog %s\n", __func__);

	if (watchdog_device.shutdown_flag == true)
		/* do nothing if we are shutting down */
		return len;

	if (watchdog_device.started) {
		/* Watchdog already started, keep it alive */
		watchdog_keepalive();
		wake_unlock(&watchdog_wake_lock);
	} else {
		/* Start watchdog with timer value set by init */
		watchdog_config_and_start(timeout, pre_timeout);
	}

	return len;
}
/* Release */
static int intel_scu_release(struct inode *inode, struct file *file)
{
	/*
	 * This watchdog should not be closed, after the timer
	 * is started with the WDIPC_SETTIMEOUT ioctl
	 * If reset_on_release is set this  will cause an
	 * immediate reset. If reset_on_release is not set, the watchdog
	 * timer is refreshed for one more interval. At the end
	 * of that interval, the watchdog timer will reset the system.
	 */

	if (!test_bit(0, &watchdog_device.driver_open)) {
		pr_err("intel_scu_release, without open\n");
		return -ENOTTY;
	}

	if (!watchdog_device.started) {
		/* Just close, since timer has not been started */
		pr_err("Closed, without starting timer\n");
		return 0;
	}

	pr_crit("Unexpected close of /dev/watchdog!\n");

	/* Since the timer was started, prevent future reopens */
	watchdog_device.driver_closed = 1;

	/* Refresh the timer for one more interval */
	watchdog_keepalive();

	/* Reboot system if requested */
	if (reset_on_release) {
		pr_crit("Initiating system reboot.\n");
		emergency_restart();
	}

	pr_crit("Immediate Reboot Disabled\n");
	pr_crit("System will reset when watchdog timer expire!\n");

	return 0;
}
Exemplo n.º 6
0
int jiveL_update_screen(lua_State *L) {
	JiveSurface *screen;

	/* stack is:
	 * 1: framework
	 */

	/* ping watchdog */
	// FIXME 30 seconds
	watchdog_keepalive(ui_watchdog, 3);

	if (!update_screen) {
		return 0;
	}

	lua_pushcfunction(L, jive_traceback);  /* push traceback function */

	lua_pushcfunction(L, _draw_screen);
	lua_pushvalue(L, 1);

	lua_getfield(L, 1, "screen");
	lua_getfield(L, -1, "surface");
	lua_replace(L, -2);
	screen = tolua_tousertype(L, -1, 0);

	lua_pushboolean(L, 0);

	if (lua_pcall(L, 3, 1, 2) != 0) {
		LOG_WARN(log_ui_draw, "error in update_screen:\n\t%s\n", lua_tostring(L, -1));
		return 0;
	}

	/* flip screen */
	if (lua_toboolean(L, -1)) {
		jive_surface_flip(screen);
	}

	lua_pop(L, 2);

	return 0;
}
/* ioctl */
static long intel_scu_ioctl(struct file *file, unsigned int cmd,
			    unsigned long arg)
{
	void __user *argp = (void __user *)arg;
	u32 __user *p = argp;
	u32 val;
	int options;

	static const struct watchdog_info ident = {
		.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
		/* @todo Get from SCU via ipc_get_scu_fw_version()? */
		.firmware_version = 0,
		/* len < 32 */
		.identity = "Intel_SCU IOH Watchdog"
	};

	switch (cmd) {
	case WDIOC_GETSUPPORT:
		return copy_to_user(argp, &ident,
				    sizeof(ident)) ? -EFAULT : 0;
	case WDIOC_GETSTATUS:
	case WDIOC_GETBOOTSTATUS:
		return put_user(0, p);
	case WDIOC_KEEPALIVE:
		pr_warn("%s: KeepAlive ioctl\n", __func__);
		if (!watchdog_device.started)
			return -EINVAL;

		watchdog_keepalive();
		return 0;
	case WDIOC_SETPRETIMEOUT:
		pr_warn("%s: SetPreTimeout ioctl\n", __func__);

		if (watchdog_device.started)
			return -EBUSY;

		/* Timeout to warn */
		if (get_user(val, p))
			return -EFAULT;

		pre_timeout = val;
		return 0;
	case WDIOC_SETTIMEOUT:
		pr_warn("%s: SetTimeout ioctl\n", __func__);

		if (watchdog_device.started)
			return -EBUSY;

		if (get_user(val, p))
			return -EFAULT;

		timeout = val;
		return 0;
	case WDIOC_GETTIMEOUT:
		return put_user(timeout, p);
	case WDIOC_SETOPTIONS:
		if (get_user(options, p))
			return -EFAULT;

		if (options & WDIOS_DISABLECARD) {
			pr_warn("%s: Stopping the watchdog\n", __func__);
			watchdog_stop();
			return 0;
		}

		if (options & WDIOS_ENABLECARD) {
			pr_warn("%s: Starting the watchdog\n", __func__);

			if (watchdog_device.started)
				return -EBUSY;

			if (check_timeouts(pre_timeout, timeout)) {
				pr_warn("%s: Invalid thresholds\n",
					__func__);
				return -EINVAL;
			}
			if (watchdog_config_and_start(timeout, pre_timeout))
				return -EINVAL;
			return 0;
		}
		return 0;
	default:
		return -ENOTTY;
	}
}

static int watchdog_set_reset_type(int reset_type)
{
	int ret;
	struct ipc_wd_on_timeout {
		u32 reset_type;
	} ipc_wd_on_timeout = { reset_type };

	ret = rpmsg_send_command(watchdog_instance, IPC_WATCHDOG,
				 SCU_WATCHDOG_SET_ACTION_ON_TIMEOUT,
				 (u8 *)&ipc_wd_on_timeout, NULL,
				 sizeof(ipc_wd_on_timeout), 0);
	if (ret) {
		pr_crit("Error setting watchdog action: %d\n", ret);
		return -EIO;
	}

	watchdog_device.normal_wd_action = reset_type;

	return 0;
}
Exemplo n.º 8
0
static int jiveL_initSDL(lua_State *L) {
	const SDL_VideoInfo *video_info;
#ifndef JIVE_NO_DISPLAY
	JiveSurface *srf, *splash;
	Uint16 splash_w, splash_h;
	bool fullscreen = false;
	char splashfile[32] = "jive/splash.png";
#endif
	/* logging */
	log_ui_draw = LOG_CATEGORY_GET("squeezeplay.ui.draw");
	log_ui = LOG_CATEGORY_GET("squeezeplay.ui");

	/* linux fbcon does not need a mouse */
	SDL_putenv("SDL_NOMOUSE=1");

#ifdef JIVE_NO_DISPLAY
#   define JIVE_SDL_FEATURES (SDL_INIT_EVENTLOOP)
#else
#   define JIVE_SDL_FEATURES (SDL_INIT_VIDEO)
#endif
	/* initialise SDL */
	if (SDL_Init(JIVE_SDL_FEATURES) < 0) {
		LOG_ERROR(log_ui_draw, "SDL_Init(V|T|A): %s\n", SDL_GetError());
		SDL_Quit();
		exit(-1);
	}

	/* report video info */
	if ((video_info = SDL_GetVideoInfo())) {
		LOG_INFO(log_ui_draw, "%d,%d %d bits/pixel %d bytes/pixel [R<<%d G<<%d B<<%d]", video_info->current_w, video_info->current_h, video_info->vfmt->BitsPerPixel, video_info->vfmt->BytesPerPixel, video_info->vfmt->Rshift, video_info->vfmt->Gshift, video_info->vfmt->Bshift);
		LOG_INFO(log_ui_draw, "Hardware acceleration %s available", video_info->hw_available?"is":"is not");
		LOG_INFO(log_ui_draw, "Window Manager %s available", video_info->wm_available?"is":"is not");
	}

	/* Register callback for additional events (used for multimedia keys)*/
	SDL_EventState(SDL_SYSWMEVENT,SDL_ENABLE);
	SDL_SetEventFilter(filter_events);

	// Secific magic for windows|linux|macos
	platform_init(L);

#ifndef JIVE_NO_DISPLAY

	/* open window */
	SDL_WM_SetCaption("SqueezePlay", "SqueezePlay");
	SDL_ShowCursor(SDL_DISABLE);
	SDL_EnableKeyRepeat (100, 100);
	SDL_EnableUNICODE(1);


#ifdef SCREEN_ROTATION_ENABLED
	screen_w = video_info->current_h;
	screen_h = video_info->current_w;
#else
	screen_w = video_info->current_w;
	screen_h = video_info->current_h;
#endif
	screen_bpp = video_info->vfmt->BitsPerPixel;

	if (video_info->wm_available) {
		/* desktop build */
		JiveSurface *icon;

		/* load the icon */
		icon = jive_surface_load_image("jive/app.png");
		if (icon) {
			jive_surface_set_wm_icon(icon);
			jive_surface_free(icon);
		}

		splash = jive_surface_load_image(splashfile);
		if (splash) {
			jive_surface_get_size(splash, &splash_w, &splash_h);

			screen_w = splash_w;
			screen_h = splash_h;
		}
	} else {
		/* product build and full screen...*/

		sprintf(splashfile, "jive/splash%dx%d.png", screen_w, screen_h);

		splash = jive_surface_load_image(splashfile);
		if(!splash) {
			sprintf(splashfile,"jive/splash.png");
			splash = jive_surface_load_image(splashfile);
		}

		if (splash) {
			jive_surface_get_size(splash, &splash_w, &splash_h);
		}

		fullscreen = true;
	}

	srf = jive_surface_set_video_mode(screen_w, screen_h, screen_bpp, fullscreen);
	if (!srf) {
		LOG_ERROR(log_ui_draw, "Video mode not supported: %dx%d\n", screen_w, screen_h);

		SDL_Quit();
		exit(-1);
	}

	if (splash) {
		jive_surface_blit(splash, srf, (screen_w - splash_w) > 0 ?((screen_w - splash_w) / 2):0, (screen_w - splash_w) > 0 ?((screen_w - splash_w) / 2):0);
		jive_surface_flip(srf);
		LOG_INFO(log_ui_draw, "Splash %s %dx%d Screen %dx%d", splashfile,splash_w,splash_h,screen_w,screen_h);
	}

	lua_getfield(L, 1, "screen");
	if (lua_isnil(L, -1)) {
		LOG_ERROR(log_ui_draw, "no screen table");

		SDL_Quit();
		exit(-1);
	}

	/* store screen surface */
	tolua_pushusertype(L, srf, "Surface");
	lua_setfield(L, -2, "surface");

	lua_getfield(L, -1, "bounds");
	lua_pushinteger(L, screen_w);
	lua_rawseti(L, -2, 3);
	lua_pushinteger(L, screen_h);
	lua_rawseti(L, -2, 4);
	lua_pop(L, 2);

	/* background image */
	jive_background = jive_tile_fill_color(0x000000FF);

	/* jive.ui.style = {} */
	lua_getglobal(L, "jive");
	lua_getfield(L, -1, "ui");
	lua_newtable(L);
	lua_setfield(L, -2, "style");
	lua_pop(L, 2);

	ui_watchdog = watchdog_get();
	watchdog_keepalive(ui_watchdog, 6); /* 60 seconds to start */

#endif /* JIVE_NO_DISPLAY */

	return 0;
}