4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1982, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /*
27 * Indirect console driver for Sun.
28 *
29 * Redirects all I/O to the device designated as the underlying "hardware"
30 * console, as given by the value of rconsvp. The implementation assumes that
31 * rconsvp denotes a STREAMS device; the assumption is justified since
32 * consoles must be capable of effecting tty semantics.
33 *
34 * rconsvp is set in autoconf.c:consconfig(), based on information obtained
35 * from the EEPROM.
36 *
37 * XXX: The driver still needs to be converted to use ANSI C consistently
38 * throughout.
39 */
40
41 #include <sys/types.h>
42 #include <sys/open.h>
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/signal.h>
46 #include <sys/cred.h>
47 #include <sys/user.h>
48 #include <sys/proc.h>
49 #include <sys/disp.h>
50 #include <sys/file.h>
51 #include <sys/taskq.h>
52 #include <sys/log.h>
53 #include <sys/vnode.h>
54 #include <sys/uio.h>
55 #include <sys/stat.h>
56
57 #include <sys/console.h>
58 #include <sys/consdev.h>
59
60 #include <sys/stream.h>
61 #include <sys/strsubr.h>
62 #include <sys/poll.h>
63
64 #include <sys/debug.h>
65
66 #include <sys/conf.h>
67 #include <sys/ddi.h>
68 #include <sys/sunddi.h>
69 #include <sys/vt.h>
70
71 static int cnopen(dev_t *, int, int, struct cred *);
72 static int cnclose(dev_t, int, int, struct cred *);
73 static int cnread(dev_t, struct uio *, struct cred *);
74 static int cnwrite(dev_t, struct uio *, struct cred *);
75 static int cnioctl(dev_t, int, intptr_t, int, struct cred *, int *);
397 if (rconsvp->v_stream != NULL)
398 return (strread(rconsvp, uio, cred));
399 else
400 return (cdev_read(rconsdev, uio, cred));
401 }
402
403 /* ARGSUSED */
404 static int
405 cnwrite(dev_t dev, struct uio *uio, struct cred *cred)
406 {
407 if (rconsvp == NULL) {
408 uio->uio_resid = 0;
409 return (0);
410 }
411
412 /*
413 * Output to virtual console for logging if enabled.
414 */
415 if (vsconsvp != NULL && vsconsvp->v_stream != NULL) {
416 struiod_t uiod;
417
418 /*
419 * strwrite modifies uio so need to make copy.
420 */
421 (void) uiodup(uio, &uiod.d_uio, uiod.d_iov,
422 sizeof (uiod.d_iov) / sizeof (*uiod.d_iov));
423
424 (void) strwrite(vsconsvp, &uiod.d_uio, cred);
425 }
426
427 if (rconsvp->v_stream != NULL)
428 return (strwrite(rconsvp, uio, cred));
429 else
430 return (cdev_write(rconsdev, uio, cred));
431 }
432
433 /* ARGSUSED */
434 static int
435 cnprivateioc(dev_t dev, int cmd, intptr_t arg, int flag, struct cred *cred,
436 int *rvalp)
437 {
438
439 /* currently we only support one ioctl */
440 if (cmd != CONS_GETTERM)
441 return (EINVAL);
442
443 /* Confirm iwscn is immediate target of cn redirection */
444 if (rconsvp != wsconsvp)
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1982, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2015, Joyent, Inc. All rights reserved.
25 */
26
27 /*
28 * Indirect console driver for Sun.
29 *
30 * Redirects all I/O to the device designated as the underlying "hardware"
31 * console, as given by the value of rconsvp. The implementation assumes that
32 * rconsvp denotes a STREAMS device; the assumption is justified since
33 * consoles must be capable of effecting tty semantics.
34 *
35 * rconsvp is set in autoconf.c:consconfig(), based on information obtained
36 * from the EEPROM.
37 *
38 * XXX: The driver still needs to be converted to use ANSI C consistently
39 * throughout.
40 */
41
42 #include <sys/types.h>
43 #include <sys/open.h>
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/signal.h>
47 #include <sys/cred.h>
48 #include <sys/user.h>
49 #include <sys/proc.h>
50 #include <sys/disp.h>
51 #include <sys/file.h>
52 #include <sys/taskq.h>
53 #include <sys/log.h>
54 #include <sys/vnode.h>
55 #include <sys/uio.h>
56 #include <sys/stat.h>
57 #include <sys/limits.h>
58
59 #include <sys/console.h>
60 #include <sys/consdev.h>
61
62 #include <sys/stream.h>
63 #include <sys/strsubr.h>
64 #include <sys/poll.h>
65
66 #include <sys/debug.h>
67
68 #include <sys/conf.h>
69 #include <sys/ddi.h>
70 #include <sys/sunddi.h>
71 #include <sys/vt.h>
72
73 static int cnopen(dev_t *, int, int, struct cred *);
74 static int cnclose(dev_t, int, int, struct cred *);
75 static int cnread(dev_t, struct uio *, struct cred *);
76 static int cnwrite(dev_t, struct uio *, struct cred *);
77 static int cnioctl(dev_t, int, intptr_t, int, struct cred *, int *);
399 if (rconsvp->v_stream != NULL)
400 return (strread(rconsvp, uio, cred));
401 else
402 return (cdev_read(rconsdev, uio, cred));
403 }
404
405 /* ARGSUSED */
406 static int
407 cnwrite(dev_t dev, struct uio *uio, struct cred *cred)
408 {
409 if (rconsvp == NULL) {
410 uio->uio_resid = 0;
411 return (0);
412 }
413
414 /*
415 * Output to virtual console for logging if enabled.
416 */
417 if (vsconsvp != NULL && vsconsvp->v_stream != NULL) {
418 struiod_t uiod;
419 struct iovec buf[IOV_MAX_STACK];
420 int iovlen = 0;
421
422 if (uio->uio_iovcnt > IOV_MAX_STACK) {
423 iovlen = uio->uio_iovcnt * sizeof (iovec_t);
424 uiod.d_iov = kmem_alloc(iovlen, KM_SLEEP);
425 } else {
426 uiod.d_iov = buf;
427 }
428
429 /*
430 * strwrite modifies uio so need to make copy.
431 */
432 (void) uiodup(uio, &uiod.d_uio, uiod.d_iov, uio->uio_iovcnt);
433
434 (void) strwrite(vsconsvp, &uiod.d_uio, cred);
435 if (iovlen != 0)
436 kmem_free(uiod.d_iov, iovlen);
437 }
438
439 if (rconsvp->v_stream != NULL)
440 return (strwrite(rconsvp, uio, cred));
441 else
442 return (cdev_write(rconsdev, uio, cred));
443 }
444
445 /* ARGSUSED */
446 static int
447 cnprivateioc(dev_t dev, int cmd, intptr_t arg, int flag, struct cred *cred,
448 int *rvalp)
449 {
450
451 /* currently we only support one ioctl */
452 if (cmd != CONS_GETTERM)
453 return (EINVAL);
454
455 /* Confirm iwscn is immediate target of cn redirection */
456 if (rconsvp != wsconsvp)
|