Exemplo n.º 1
0
static int __init buff_ovrflw_init(void){
  char c_array[16];
  module_param_array(c_array, char, &arr_argc, 0000);
  MODULE_PARM_DESC(myintArray, "An array of chars");
  for(int i=0; i < 17; i++){
    printk(KERN_INFO "char %d: %c", i, c_array[i]);
  }
  
  return 0;
}
Exemplo n.º 2
0
static long pc87413_ioctl(struct file *file, unsigned int cmd,
						unsigned long arg)
{
	int new_timeout;

	union {
		struct watchdog_info __user *ident;
		int __user *i;
	} uarg;

	static struct watchdog_info ident = {
		.options          = WDIOF_KEEPALIVEPING |
				    WDIOF_SETTIMEOUT |
				    WDIOF_MAGICCLOSE,
		.firmware_version = 1,
		.identity         = "PC87413(HF/F) watchdog",
	};

	uarg.i = (int __user *)arg;

	switch (cmd) {
	case WDIOC_GETSUPPORT:
		return copy_to_user(uarg.ident, &ident,
					sizeof(ident)) ? -EFAULT : 0;
	case WDIOC_GETSTATUS:
		return put_user(pc87413_status(), uarg.i);
	case WDIOC_GETBOOTSTATUS:
		return put_user(0, uarg.i);
	case WDIOC_SETOPTIONS:
	{
		int options, retval = -EINVAL;
		if (get_user(options, uarg.i))
			return -EFAULT;
		if (options & WDIOS_DISABLECARD) {
			pc87413_disable();
			retval = 0;
		}
		if (options & WDIOS_ENABLECARD) {
			pc87413_enable();
			retval = 0;
		}
		return retval;
	}
	case WDIOC_KEEPALIVE:
		pc87413_refresh();
#ifdef DEBUG
		printk(KERN_INFO DPFX "keepalive\n");
#endif
		return 0;
	case WDIOC_SETTIMEOUT:
		if (get_user(new_timeout, uarg.i))
			return -EFAULT;
		/* the API states this is given in secs */
		new_timeout /= 60;
		if (new_timeout < 0 || new_timeout > MAX_TIMEOUT)
			return -EINVAL;
		timeout = new_timeout;
		pc87413_refresh();
		/* fall through and return the new timeout... */
	case WDIOC_GETTIMEOUT:
		new_timeout = timeout * 60;
		return put_user(new_timeout, uarg.i);
	default:
		return -ENOTTY;
	}
}

/* -- Notifier funtions -----------------------------------------*/

/**
 *	notify_sys:
 *	@this: our notifier block
 *	@code: the event being reported
 *	@unused: unused
 *
 *	Our notifier is called on system shutdowns. We want to turn the card
 *	off at reboot otherwise the machine will reboot again during memory
 *	test or worse yet during the following fsck. This would suck, in fact
 *	trust me - if it happens it does suck.
 */

static int pc87413_notify_sys(struct notifier_block *this,
			      unsigned long code,
			      void *unused)
{
	if (code == SYS_DOWN || code == SYS_HALT)
		/* Turn the card off */
		pc87413_disable();
	return NOTIFY_DONE;
}

/* -- Module's structures ---------------------------------------*/

static const struct file_operations pc87413_fops = {
	.owner		= THIS_MODULE,
	.llseek		= no_llseek,
	.write		= pc87413_write,
	.unlocked_ioctl	= pc87413_ioctl,
	.open		= pc87413_open,
	.release	= pc87413_release,
};

static struct notifier_block pc87413_notifier = {
	.notifier_call  = pc87413_notify_sys,
};

static struct miscdevice pc87413_miscdev = {
	.minor          = WATCHDOG_MINOR,
	.name           = "watchdog",
	.fops           = &pc87413_fops,
};

/* -- Module init functions -------------------------------------*/

/**
 * 	pc87413_init: module's "constructor"
 *
 *	Set up the WDT watchdog board. All we have to do is grab the
 *	resources we require and bitch if anyone beat us to them.
 *	The open() function will actually kick the board off.
 */

static int __init pc87413_init(void)
{
	int ret;

	printk(KERN_INFO PFX "Version " VERSION " at io 0x%X\n",
							WDT_INDEX_IO_PORT);

	/* request_region(io, 2, "pc87413"); */

	ret = register_reboot_notifier(&pc87413_notifier);
	if (ret != 0) {
		printk(KERN_ERR PFX
			"cannot register reboot notifier (err=%d)\n", ret);
	}

	ret = misc_register(&pc87413_miscdev);
	if (ret != 0) {
		printk(KERN_ERR PFX
			"cannot register miscdev on minor=%d (err=%d)\n",
			WATCHDOG_MINOR, ret);
		unregister_reboot_notifier(&pc87413_notifier);
		return ret;
	}
	printk(KERN_INFO PFX "initialized. timeout=%d min \n", timeout);
	pc87413_enable();
	return 0;
}

/**
 *	pc87413_exit: module's "destructor"
 *
 *	Unload the watchdog. You cannot do this with any file handles open.
 *	If your watchdog is set to continue ticking on close and you unload
 *	it, well it keeps ticking. We won't get the interrupt but the board
 *	will not touch PC memory so all is fine. You just have to load a new
 *	module in 60 seconds or reboot.
 */

static void __exit pc87413_exit(void)
{
	/* Stop the timer before we leave */
	if (!nowayout) {
		pc87413_disable();
		printk(KERN_INFO MODNAME "Watchdog disabled.\n");
	}

	misc_deregister(&pc87413_miscdev);
	unregister_reboot_notifier(&pc87413_notifier);
	/* release_region(io, 2); */

	printk(KERN_INFO MODNAME " watchdog component driver removed.\n");
}

module_init(pc87413_init);
module_exit(pc87413_exit);

MODULE_AUTHOR("Sven Anders <*****@*****.**>, "
		"Marcus Junker <*****@*****.**>,");
MODULE_DESCRIPTION("PC87413 WDT driver");
MODULE_LICENSE("GPL");

MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);

module_param(io, int, 0);
MODULE_PARM_DESC(io, MODNAME " I/O port (default: " __MODULE_STRING(io) ").");

module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout,
		"Watchdog timeout in minutes (default="
				__MODULE_STRING(timeout) ").");

module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout,
		"Watchdog cannot be stopped once started (default="
				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
static long wb_smsc_wdt_ioctl(struct file *file,
					unsigned int cmd, unsigned long arg)
{
	int new_timeout;

	union {
		struct watchdog_info __user *ident;
		int __user *i;
	} uarg;

	static const struct watchdog_info ident = {
		.options =		WDIOF_KEEPALIVEPING |
					WDIOF_SETTIMEOUT |
					WDIOF_MAGICCLOSE,
		.firmware_version =	0,
		.identity =		"SMsC 37B787 Watchdog",
	};

	uarg.i = (int __user *)arg;

	switch (cmd) {
	case WDIOC_GETSUPPORT:
		return copy_to_user(uarg.ident, &ident, sizeof(ident))
								? -EFAULT : 0;
	case WDIOC_GETSTATUS:
		return put_user(wb_smsc_wdt_status(), uarg.i);
	case WDIOC_GETBOOTSTATUS:
		return put_user(0, uarg.i);
	case WDIOC_SETOPTIONS:
	{
		int options, retval = -EINVAL;

		if (get_user(options, uarg.i))
			return -EFAULT;

		if (options & WDIOS_DISABLECARD) {
			wb_smsc_wdt_disable();
			retval = 0;
		}
		if (options & WDIOS_ENABLECARD) {
			wb_smsc_wdt_enable();
			retval = 0;
		}
		return retval;
	}
	case WDIOC_KEEPALIVE:
		wb_smsc_wdt_reset_timer();
		return 0;
	case WDIOC_SETTIMEOUT:
		if (get_user(new_timeout, uarg.i))
			return -EFAULT;
		
		if (unit == UNIT_MINUTE)
			new_timeout /= 60;
		if (new_timeout < 0 || new_timeout > MAX_TIMEOUT)
			return -EINVAL;
		timeout = new_timeout;
		wb_smsc_wdt_set_timeout(timeout);
		
	case WDIOC_GETTIMEOUT:
		new_timeout = timeout;
		if (unit == UNIT_MINUTE)
			new_timeout *= 60;
		return put_user(new_timeout, uarg.i);
	default:
		return -ENOTTY;
	}
}


static int wb_smsc_wdt_notify_sys(struct notifier_block *this,
					unsigned long code, void *unused)
{
	if (code == SYS_DOWN || code == SYS_HALT) {
		
		timeout = 0;
		wb_smsc_wdt_disable();
	}
	return NOTIFY_DONE;
}


static const struct file_operations wb_smsc_wdt_fops = {
	.owner	  = THIS_MODULE,
	.llseek		= no_llseek,
	.write		= wb_smsc_wdt_write,
	.unlocked_ioctl	= wb_smsc_wdt_ioctl,
	.open		= wb_smsc_wdt_open,
	.release	= wb_smsc_wdt_release,
};

static struct notifier_block wb_smsc_wdt_notifier = {
	.notifier_call  = wb_smsc_wdt_notify_sys,
};

static struct miscdevice wb_smsc_wdt_miscdev = {
	.minor		= WATCHDOG_MINOR,
	.name		= "watchdog",
	.fops		= &wb_smsc_wdt_fops,
};



static int __init wb_smsc_wdt_init(void)
{
	int ret;

	pr_info("SMsC 37B787 watchdog component driver "
		VERSION " initialising...\n");

	if (!request_region(IOPORT, IOPORT_SIZE, "SMsC 37B787 watchdog")) {
		pr_err("Unable to register IO port %#x\n", IOPORT);
		ret = -EBUSY;
		goto out_pnp;
	}

	
	if (timeout > MAX_TIMEOUT)
		timeout = MAX_TIMEOUT;

	
	wb_smsc_wdt_initialize();

	ret = register_reboot_notifier(&wb_smsc_wdt_notifier);
	if (ret) {
		pr_err("Unable to register reboot notifier err = %d\n", ret);
		goto out_io;
	}

	ret = misc_register(&wb_smsc_wdt_miscdev);
	if (ret) {
		pr_err("Unable to register miscdev on minor %d\n",
		       WATCHDOG_MINOR);
		goto out_rbt;
	}

	
	pr_info("Timeout set to %d %s\n",
		timeout, (unit == UNIT_SECOND) ? "second(s)" : "minute(s)");
	pr_info("Watchdog initialized and sleeping (nowayout=%d)...\n",
		nowayout);
out_clean:
	return ret;

out_rbt:
	unregister_reboot_notifier(&wb_smsc_wdt_notifier);

out_io:
	release_region(IOPORT, IOPORT_SIZE);

out_pnp:
	goto out_clean;
}


static void __exit wb_smsc_wdt_exit(void)
{
	
	if (!nowayout) {
		wb_smsc_wdt_shutdown();
		pr_info("Watchdog disabled\n");
	}

	misc_deregister(&wb_smsc_wdt_miscdev);
	unregister_reboot_notifier(&wb_smsc_wdt_notifier);
	release_region(IOPORT, IOPORT_SIZE);

	pr_info("SMsC 37B787 watchdog component driver removed\n");
}

module_init(wb_smsc_wdt_init);
module_exit(wb_smsc_wdt_exit);

MODULE_AUTHOR("Sven Anders <*****@*****.**>");
MODULE_DESCRIPTION("Driver for SMsC 37B787 watchdog component (Version "
								VERSION ")");
MODULE_LICENSE("GPL");

MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);

#ifdef SMSC_SUPPORT_MINUTES
module_param(unit, int, 0);
MODULE_PARM_DESC(unit,
		"set unit to use, 0=seconds or 1=minutes, default is 0");
#endif

module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "range is 1-255 units, default is 60");

module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout,
		"Watchdog cannot be stopped once started (default="
				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Exemplo n.º 4
0
static int create_pipe(int nr)
{
	int minor_in, minor_out , ret;
		
	if (dev_offset == -1) {
		if (inminor == -1) {
		    minor_in  = -1;
		} else {
		    minor_in  = inminor+nr;
		}
		if (outminor == -1) {
		    minor_out = -1;
		} else {
		    minor_out = outminor+nr;
		}
	} else {
		minor_in  = 2*nr   + dev_offset;
		minor_out = 2*nr+1 + dev_offset;
	}

	/* allocate space for this pipe */
	loops[nr]= kmalloc(sizeof(struct vloopback_pipe), GFP_KERNEL);
	if (!loops[nr])
		return -ENOMEM;
	/* set up a new video device plus our private area */
	loops[nr]->vloopin= video_device_alloc();
	if (loops[nr]->vloopin == NULL)
		return -ENOMEM;
	*loops[nr]->vloopin = vloopback_template;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
	video_set_drvdata(loops[nr]->vloopin,kmalloc(sizeof(struct vloopback_private),GFP_KERNEL));
#else
	loops[nr]->vloopin->priv= kmalloc(sizeof(struct vloopback_private),GFP_KERNEL);
#endif	
	
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
	if ((priv_ptr)video_get_drvdata(loops[nr]->vloopin) == NULL) {
#else
	if (loops[nr]->vloopin->priv == NULL) {
#endif	
		kfree(loops[nr]->vloopin);
		return -ENOMEM;
	}
	/* repeat for the output device */
	loops[nr]->vloopout= video_device_alloc();
	if (loops[nr]->vloopout == NULL) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
		kfree((priv_ptr)video_get_drvdata(loops[nr]->vloopin));
#else
		kfree(loops[nr]->vloopin->priv);
#endif	
		kfree(loops[nr]->vloopin);
		return -ENOMEM;
	}
	*loops[nr]->vloopout = vloopback_template;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
	video_set_drvdata(loops[nr]->vloopout,kmalloc(sizeof(struct vloopback_private),GFP_KERNEL));
#else
	loops[nr]->vloopout->priv= kmalloc(sizeof(struct vloopback_private),GFP_KERNEL);
#endif	

	if ((priv_ptr)video_get_drvdata(loops[nr]->vloopout) == NULL) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
		kfree((priv_ptr)video_get_drvdata(loops[nr]->vloopin));
#else
		kfree(loops[nr]->vloopin->priv);
#endif	
		kfree(loops[nr]->vloopin);
		kfree(loops[nr]->vloopout);
		return -ENOMEM;
	}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
	((priv_ptr)video_get_drvdata(loops[nr]->vloopin))->pipenr=nr;
	((priv_ptr)video_get_drvdata(loops[nr]->vloopout))->pipenr=nr;
#else
	((priv_ptr)loops[nr]->vloopin->priv)->pipenr=nr;
	((priv_ptr)loops[nr]->vloopout->priv)->pipenr=nr;
#endif	

	loops[nr]->invalid_ioctl = 0; /* tibit */
	loops[nr]->buffer=NULL;
	loops[nr]->width=0;
	loops[nr]->height=0;
	loops[nr]->palette=0;
	loops[nr]->frameswrite=0;
	loops[nr]->framesread=0;
	loops[nr]->framesdumped=0;
	loops[nr]->wopen=0;
	loops[nr]->ropen=0;
	loops[nr]->frame=0;
	loops[nr]->pendingread=0;
	
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
	((priv_ptr)video_get_drvdata(loops[nr]->vloopin))->in=1;
	((priv_ptr)video_get_drvdata(loops[nr]->vloopout))->in=0;
#else
	((priv_ptr)loops[nr]->vloopin->priv)->in=1;
	((priv_ptr)loops[nr]->vloopout->priv)->in=0;
#endif	
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
	loops[nr]->vloopin->type=0;
#endif
	sprintf(loops[nr]->vloopin->name, "Video loopback %d input", nr);
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
	loops[nr]->vloopout->type=VID_TYPE_CAPTURE;
#endif
	sprintf(loops[nr]->vloopout->name, "Video loopback %d output", nr);
	init_waitqueue_head(&loops[nr]->wait);
	init_MUTEX(&loops[nr]->lock);
	
	ret = video_register_device(loops[nr]->vloopout, VFL_TYPE_GRABBER, minor_out);
	
	if ((ret ==-1) || (ret == -23)) {
		info("error registering device %s", loops[nr]->vloopout->name);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
		kfree(((priv_ptr)video_get_drvdata(loops[nr]->vloopin)));
		video_unregister_device(loops[nr]->vloopin);
		kfree(((priv_ptr)video_get_drvdata(loops[nr]->vloopout)));
#else
		kfree(loops[nr]->vloopin->priv);
		video_unregister_device(loops[nr]->vloopin);
		kfree(loops[nr]->vloopout->priv);
#endif	
		kfree(loops[nr]->vloopout);
		kfree(loops[nr]);
		loops[nr]=NULL;
		return ret;
	}
	
	ret = video_register_device(loops[nr]->vloopin, VFL_TYPE_GRABBER, minor_in);

	if ((ret == -1 ) || ( ret == -23 )) {
		info("error registering device %s",loops[nr]->vloopin->name);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
		kfree(((priv_ptr)video_get_drvdata(loops[nr]->vloopin)));
		kfree(((priv_ptr)video_get_drvdata(loops[nr]->vloopout)));
#else
		kfree(loops[nr]->vloopin->priv);
		kfree(loops[nr]->vloopout->priv);
#endif	

		kfree(loops[nr]->vloopin);
		kfree(loops[nr]->vloopout);
		kfree(loops[nr]);
		loops[nr]=NULL;
		return ret;
	}
	
	loops[nr]->ioctldata=kmalloc(1024, GFP_KERNEL);
	loops[nr]->ioctlretdata=kmalloc(1024, GFP_KERNEL);
	return 0;
}


/****************************************************************************
 *	init stuff
 ****************************************************************************/


MODULE_AUTHOR("J.B. Vreeken ([email protected])");
MODULE_DESCRIPTION("Video4linux loopback device.");

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(pipes, int, 000);
#else
MODULE_PARM(pipes, "i");
#endif

MODULE_PARM_DESC(pipes, "Nr of pipes to create (each pipe uses two video devices)");

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(spares, int, 000);
#else
MODULE_PARM(spares, "i");
#endif

MODULE_PARM_DESC(spares, "Nr of spare pipes that should be created");

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(dev_offset, int, 000);
#else
MODULE_PARM(dev_offset_param, "i");
#endif

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(inminor, int, 000);
#else
MODULE_PARM(inminor, "i");
#endif

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(outminor, int, 000);
#else
MODULE_PARM(outminor, "i");
#endif

MODULE_PARM_DESC(dev_offset, "Prefered offset for video device numbers");
MODULE_LICENSE("GPL");
MODULE_VERSION( VLOOPBACK_VERSION );

static int __init vloopback_init(void)
{
	int i,ret;

	info("Video4linux loopback driver v"VLOOPBACK_VERSION);

	if (pipes==-1) pipes=1;
	if (pipes > MAX_PIPES) {
		pipes=MAX_PIPES;
		info("Nr of pipes is limited to: %d", MAX_PIPES);
	}

	for (i=0; i<pipes; i++) {
		
		ret = create_pipe(i);

		if (ret == 0) {
			info("Loopback %d registered, input: video%d, output: video%d",
			     i, loops[i]->vloopin->minor,
			     loops[i]->vloopout->minor);
			nr_o_pipes=i+1;
		}else{
			return ret;
		}
	}
	return 0;
}
Exemplo n.º 5
0
static long asr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	static const struct watchdog_info ident = {
		.options =	WDIOF_KEEPALIVEPING |
				WDIOF_MAGICCLOSE,
		.identity =	"IBM ASR",
	};
	void __user *argp = (void __user *)arg;
	int __user *p = argp;
	int heartbeat;

	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_SETOPTIONS:
	{
		int new_options, retval = -EINVAL;
		if (get_user(new_options, p))
			return -EFAULT;
		if (new_options & WDIOS_DISABLECARD) {
			asr_disable();
			retval = 0;
		}
		if (new_options & WDIOS_ENABLECARD) {
			asr_enable();
			asr_toggle();
			retval = 0;
		}
		return retval;
	}
	case WDIOC_KEEPALIVE:
		asr_toggle();
		return 0;
	/*
	 * The hardware has a fixed timeout value, so no WDIOC_SETTIMEOUT
	 * and WDIOC_GETTIMEOUT always returns 256.
	 */
	case WDIOC_GETTIMEOUT:
		heartbeat = 256;
		return put_user(heartbeat, p);
	default:
		return -ENOTTY;
	}
}

static int asr_open(struct inode *inode, struct file *file)
{
	if (test_and_set_bit(0, &asr_is_open))
		return -EBUSY;

	asr_toggle();
	asr_enable();

	return nonseekable_open(inode, file);
}

static int asr_release(struct inode *inode, struct file *file)
{
	if (asr_expect_close == 42)
		asr_disable();
	else {
		pr_crit("unexpected close, not stopping watchdog!\n");
		asr_toggle();
	}
	clear_bit(0, &asr_is_open);
	asr_expect_close = 0;
	return 0;
}

static const struct file_operations asr_fops = {
	.owner =		THIS_MODULE,
	.llseek =		no_llseek,
	.write =		asr_write,
	.unlocked_ioctl =	asr_ioctl,
	.open =			asr_open,
	.release =		asr_release,
};

static struct miscdevice asr_miscdev = {
	.minor =	WATCHDOG_MINOR,
	.name =		"watchdog",
	.fops =		&asr_fops,
};


struct ibmasr_id {
	const char *desc;
	int type;
};

static struct ibmasr_id __initdata ibmasr_id_table[] = {
	{ "IBM Automatic Server Restart - eserver xSeries 220", ASMTYPE_TOPAZ },
	{ "IBM Automatic Server Restart - Machine Type 8673", ASMTYPE_PEARL },
	{ "IBM Automatic Server Restart - Machine Type 8480", ASMTYPE_JASPER },
	{ "IBM Automatic Server Restart - Machine Type 8482", ASMTYPE_JUNIPER },
	{ "IBM Automatic Server Restart - Machine Type 8648", ASMTYPE_SPRUCE },
	{ NULL }
};

static int __init ibmasr_init(void)
{
	struct ibmasr_id *id;
	int rc;

	for (id = ibmasr_id_table; id->desc; id++) {
		if (dmi_find_device(DMI_DEV_TYPE_OTHER, id->desc, NULL)) {
			asr_type = id->type;
			break;
		}
	}

	if (!asr_type)
		return -ENODEV;

	rc = asr_get_base_address();
	if (rc)
		return rc;

	rc = misc_register(&asr_miscdev);
	if (rc < 0) {
		release_region(asr_base, asr_length);
		pr_err("failed to register misc device\n");
		return rc;
	}

	return 0;
}

static void __exit ibmasr_exit(void)
{
	if (!nowayout)
		asr_disable();

	misc_deregister(&asr_miscdev);

	release_region(asr_base, asr_length);
}

module_init(ibmasr_init);
module_exit(ibmasr_exit);

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

MODULE_DESCRIPTION("IBM Automatic Server Restart driver");
MODULE_AUTHOR("Andrey Panin");
MODULE_LICENSE("GPL");
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
Exemplo n.º 6
0
static int create_pipe(int nr)
{
    int minor_in, minor_out , ret;

    if (debug > LOG_NODEBUG)
        info("Video loopback %d", nr);

    if (dev_offset == -1) {
        minor_in  = minor_out = -1; /* autoassign */
    } else {
        minor_in  = 2 * nr + dev_offset;
        minor_out = 2 * nr + 1 + dev_offset;
    }
    /* allocate space for this pipe */
    loops[nr]= kmalloc(sizeof(struct vloopback_pipe), GFP_KERNEL);

    if (!loops[nr])
        return -ENOMEM;
    /* set up a new video device plus our private area */
    loops[nr]->vloopin = video_device_alloc();

    if (loops[nr]->vloopin == NULL)
        return -ENOMEM;
    *loops[nr]->vloopin = vloopback_template;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)    
    priv_ptr ptr_in = kmalloc(sizeof(struct vloopback_private), 
                                                  GFP_KERNEL);
    if (ptr_in == NULL) {
        kfree(ptr_in);
#else
    loops[nr]->vloopin->vd_private_data = kmalloc(sizeof(struct vloopback_private),
                                                  GFP_KERNEL);
    if (loops[nr]->vloopin->vd_private_data == NULL) {
        kfree(loops[nr]->vloopin);
#endif    
        return -ENOMEM;
    }
    /* repeat for the output device */
    loops[nr]->vloopout = video_device_alloc();

    if (loops[nr]->vloopout == NULL) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
        kfree(ptr_in);
#else        
        kfree(loops[nr]->vloopin->vd_private_data);
#endif        
        kfree(loops[nr]->vloopin);
        return -ENOMEM;
    }
    *loops[nr]->vloopout = vloopback_template;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)    
    priv_ptr ptr_out = kmalloc(sizeof(struct vloopback_private),
                                                   GFP_KERNEL);
    if (ptr_out == NULL) {
        kfree(ptr_in);
        kfree(ptr_out);
#else
    loops[nr]->vloopout->vd_private_data = kmalloc(sizeof(struct vloopback_private),
                                                   GFP_KERNEL);
    if (loops[nr]->vloopout->vd_private_data == NULL) {
        kfree(loops[nr]->vloopin->vd_private_data);
#endif    
        kfree(loops[nr]->vloopin);
        kfree(loops[nr]->vloopout);
        return -ENOMEM;
    }

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
    ptr_in->pipenr = nr;
    ptr_out->pipenr = nr;
#else
    ((priv_ptr)loops[nr]->vloopin->vd_private_data)->pipenr = nr;
    ((priv_ptr)loops[nr]->vloopout->vd_private_data)->pipenr = nr;
#endif    
    loops[nr]->invalid_ioctl = 0; /* tibit */
    loops[nr]->buffer = NULL;
    loops[nr]->width = 0;
    loops[nr]->height = 0;
    loops[nr]->palette = 0;
    loops[nr]->frameswrite = 0;
    loops[nr]->framesread = 0;
    loops[nr]->framesdumped = 0;
    loops[nr]->wopen = 0;
    loops[nr]->ropen = 0;
    loops[nr]->frame = 0;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)    
    ptr_in->in = 1;
    ptr_out->in = 0;
    dev_set_drvdata(&loops[nr]->vloopin->dev, ptr_in);
    dev_set_drvdata(&loops[nr]->vloopout->dev, ptr_out);
#else
    ((priv_ptr)loops[nr]->vloopin->vd_private_data)->in = 1;
    ((priv_ptr)loops[nr]->vloopout->vd_private_data)->in = 0;
#endif

    sprintf(loops[nr]->vloopin->name, "Video loopback %d input", nr);
    sprintf(loops[nr]->vloopout->name, "Video loopback %d output", nr);

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
    loops[nr]->vloopin->type = 0;
    loops[nr]->vloopout->type = VID_TYPE_CAPTURE;
#endif
    loops[nr]->vloopout->minor = minor_out;
    loops[nr]->vloopin->minor = minor_in;

    init_waitqueue_head(&loops[nr]->wait);

    init_MUTEX(&loops[nr]->lock);

    ret = video_register_device(loops[nr]->vloopin, VFL_TYPE_GRABBER, minor_in);
    
    if ((ret == -1 ) || ( ret == -23 )) {
        info("error registering device %s", loops[nr]->vloopin->name);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)        
        kfree(ptr_in);
        dev_set_drvdata(&loops[nr]->vloopin->dev, NULL);
#else
        kfree(loops[nr]->vloopin->vd_private_data);
#endif        
        kfree(loops[nr]->vloopin);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)        
        kfree(ptr_out);
        dev_set_drvdata(&loops[nr]->vloopout->dev, NULL);
#else   
        kfree(loops[nr]->vloopout->vd_private_data);
#endif
        kfree(loops[nr]->vloopout);
        kfree(loops[nr]);
        loops[nr] = NULL;
        return ret;
    }
    
    ret = video_register_device(loops[nr]->vloopout, VFL_TYPE_GRABBER, minor_out);
    
    if ((ret ==-1) || (ret == -23)) {
        info("error registering device %s", loops[nr]->vloopout->name);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)        
        kfree(ptr_in);
        dev_set_drvdata(&loops[nr]->vloopin->dev, NULL);
#else
        kfree(loops[nr]->vloopin->vd_private_data);
#endif        
        video_unregister_device(loops[nr]->vloopin);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)        
        kfree(ptr_out);
        dev_set_drvdata(&loops[nr]->vloopout->dev, NULL);
#else   
        kfree(loops[nr]->vloopout->vd_private_data);
#endif        
        kfree(loops[nr]->vloopout);
        kfree(loops[nr]);
        loops[nr] = NULL;
        return ret;
    }
    
    loops[nr]->ioctldata = kmalloc(1024, GFP_KERNEL);
    loops[nr]->ioctlretdata = kmalloc(1024, GFP_KERNEL);
    return 0;
}


/****************************************************************************
 *    init stuff
 ****************************************************************************/


MODULE_AUTHOR("J.B. Vreeken ([email protected])");
MODULE_DESCRIPTION("Video4linux loopback device.");

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(pipes, int, 000);
#else
MODULE_PARM(pipes, "i");
#endif

MODULE_PARM_DESC(pipes, " Nr of pipes to create (each pipe uses two video devices)");

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(spares, int, 000);
#else
MODULE_PARM(spares, "i");
#endif

MODULE_PARM_DESC(spares, " Nr of spare pipes that should be created");

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(num_buffers, int, 000);
#else
MODULE_PARM(num_buffers, "i");
#endif

MODULE_PARM_DESC(num_buffers, " Prefered numbers of internal buffers to map (default 2)");


#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(dev_offset, int, 000);
#else
MODULE_PARM(dev_offset_param, "i");
#endif

MODULE_PARM_DESC(dev_offset, " Prefered offset for video device numbers");


#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
module_param(debug, int, 000);
#else
MODULE_PARM(debug_param, "i");
#endif

MODULE_PARM_DESC(debug, " Enable module debug level 0-3 (by default 0)");

MODULE_LICENSE("GPL");
MODULE_VERSION( VLOOPBACK_VERSION );

static int __init vloopback_init(void)
{
    int i, ret;

    info("video4linux loopback driver v"VLOOPBACK_VERSION);

    if (pipes == -1) 
        pipes = 1;

    if (pipes > MAX_PIPES) {
        pipes = MAX_PIPES;
        info("Nr of pipes is limited to: %d", MAX_PIPES);
    }

    if (num_buffers < N_BUFFS) {
        num_buffers = N_BUFFS;
        info("Nr of buffer set to default value %d", N_BUFFS);
    }

    for (i = 0; i < pipes; i++) {
        
        ret = create_pipe(i);

        if (ret == 0) {
            info("Loopback %d registered, input: video%d,"
                 " output: video%d",
                 i, loops[i]->vloopin->minor,
                 loops[i]->vloopout->minor);
            info("Loopback %d , Using %d buffers", i, num_buffers);
            nr_o_pipes = i + 1;
        } else {
            return ret;
        }
    }
    return 0;
}