⬢ DragonFlyBSD Kernel Audit
DF-5636 / df5636ctl.c
← back to finding ↓ download raw
/*
 * df5636ctl.c -- userland driver for the /dev/df5636 rig ioctls.
 * Runs ON THE GUEST.
 *
 *   df5636ctl f1|f2|f3|f3b      run an in-kernel test, print the summary
 *   df5636ctl park              parks the CALLING process in
 *                               smbus_poll() tsleep "smbreq" (DF-5638)
 *   df5636ctl unpark            release devA, waking the parker
 */
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <err.h>

#define DF5636_F1	_IOWR('d', 1, int)
#define DF5636_F2	_IOWR('d', 2, int)
#define DF5636_F3	_IOWR('d', 3, int)
#define DF5636_F3B	_IOWR('d', 4, int)
#define DF5636_PARK	_IOWR('d', 5, int)
#define DF5636_UNPARK	_IOWR('d', 6, int)

int
main(int argc, char **argv)
{
	unsigned long cmd;
	int fd, v = 0;

	if (argc != 2)
		errx(1, "usage: %s f1|f2|f3|f3b|park|unpark", argv[0]);

	if (!strcmp(argv[1], "f1"))         cmd = DF5636_F1;
	else if (!strcmp(argv[1], "f2"))    cmd = DF5636_F2;
	else if (!strcmp(argv[1], "f3"))    cmd = DF5636_F3;
	else if (!strcmp(argv[1], "f3b"))   cmd = DF5636_F3B;
	else if (!strcmp(argv[1], "park"))  cmd = DF5636_PARK;
	else if (!strcmp(argv[1], "unpark"))cmd = DF5636_UNPARK;
	else errx(1, "unknown test '%s'", argv[1]);

	fd = open("/dev/df5636", O_RDWR);
	if (fd < 0)
		err(1, "open /dev/df5636 (is the rig loaded?)");

	if (ioctl(fd, cmd, &v) < 0)
		err(1, "ioctl(%s)", argv[1]);
	printf("df5636ctl %s: ioctl ok, summary=0x%x, park status=%d\n",
	    argv[1], v, v);
	return (0);
}