VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
97870c34b4532 (Alex Dewar     2019-08-25 10:49:18 +0100  1) // SPDX-License-Identifier: GPL-2.0
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800  2) /*
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800  3)  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700  4)  */
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700  5) 
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700  6) #include <stdlib.h>
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800  7) #include <unistd.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700  8) #include <errno.h>
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800  9) #include <fcntl.h>
37185b3324087 (Al Viro        2012-10-08 03:27:32 +0100 10) #include <kern_util.h>
37185b3324087 (Al Viro        2012-10-08 03:27:32 +0100 11) #include <os.h>
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 12) 
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13) struct grantpt_info {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 14) 	int fd;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 15) 	int res;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 16) 	int err;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 17) };
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 18) 
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19) static void grantpt_cb(void *arg)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 20) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 21) 	struct grantpt_info *info = arg;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 22) 
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 23) 	info->res = grantpt(info->fd);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 24) 	info->err = errno;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 25) }
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 26) 
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 27) int get_pty(void)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 28) {
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 29) 	struct grantpt_info info;
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 30) 	int fd, err;
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 31) 
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 32) 	fd = open("/dev/ptmx", O_RDWR);
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 33) 	if (fd < 0) {
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 34) 		err = -errno;
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 35) 		printk(UM_KERN_ERR "get_pty : Couldn't open /dev/ptmx - "
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 36) 		       "err = %d\n", errno);
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 37) 		return err;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 38) 	}
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 39) 
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 40) 	info.fd = fd;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 41) 	initial_thread_cb(grantpt_cb, &info);
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 42) 
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 43) 	if (info.res < 0) {
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 44) 		err = -info.err;
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 45) 		printk(UM_KERN_ERR "get_pty : Couldn't grant pty - "
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 46) 		       "errno = %d\n", -info.err);
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 47) 		goto out;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 48) 	}
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 49) 
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 50) 	if (unlockpt(fd) < 0) {
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 51) 		err = -errno;
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 52) 		printk(UM_KERN_ERR "get_pty : Couldn't unlock pty - "
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 53) 		       "errno = %d\n", errno);
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 54) 		goto out;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 55) 	}
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 56) 	return fd;
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 57) out:
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 58) 	close(fd);
edea138584d75 (Jeff Dike      2008-02-04 22:30:46 -0800 59) 	return err;
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 60) }