/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* "Workstation console" multiplexor driver for Sun.
*
* Sends output to the primary frame buffer using the PROM monitor;
* gets input from a stream linked below us that is the "keyboard
* driver", below which is linked the primary keyboard.
*/
/*
* Locking Policy:
* This module has a D_MTPERMOD inner perimeter which means STREAMS
* only allows one thread to enter this module through STREAMS entry
* points each time -- open() close() put() srv() qtimeout().
* So for the most time we do not need locking in this module, but with
* the following exceptions:
*
* - wc shares three global variables (wc_dip, vc_active_console,
* vc_cons_user, vc_avl_root) with virtual console devname part
* (fs/dev/sdev_vtops.c) which get compiled into genunix.
*
* - wc_modechg_cb() is a callback function which will triggered when
* framebuffer display mode is changed.
*
* - vt_send_hotkeys() is triggered by timeout() which is not STREAMS MT
* safe.
*
* Based on the fact that virtual console devname part and wc_modechg_cb()
* only do read access to the above mentioned shared four global variables,
* It is safe to do locking this way:
* 1) all read access to the four global variables in THIS WC MODULE do not
* need locking;
* 2) all write access to the four global variables in THIS WC MODULE must
* hold vc_lock;
* 3) any access to the four global variables in either DEVNAME PART or the
* CALLBACK must hold vc_lock;
* 4) other global variables which are only shared in this wc module and only
* accessible through STREAMS entry points such as "vc_last_console",
* "vc_inuse_max_minor", "vc_target_console" and "vc_waitactive_list"
* do not need explict locking.
*
* wc_modechg_cb() does read access to vc_state_t::vc_flags,
* vc_state_t::vc_state_lock is used to protect concurrently accesses to
* vc_state_t::vc_flags which may happen from both through STREAMS entry
* points and wc_modechg_cb().
* Since wc_modechg_cb() only does read access to vc_state_t::vc_flags,
* The other parts of wc module (except wc_modechg_cb()) only has to hold
* vc_state_t::vc_flags when writing to vc_state_t::vc_flags.
*
* vt_send_hotkeys() could access vt_pending_vtno at the same time with
* the rest of wc module, vt_pending_vtno_lock is used to protect
* vt_pending_vtno.
*
* Lock order: vc_lock -> vc_state_t::vc_state_lock.
* No overlap between vc_lock and vt_pending_vtno_lock.
*/
#include <sys/sysmacros.h>
#include <sys/strredir.h>
#include <sys/polled_io.h>
#include <sys/ddi_impldefs.h>
/* streams stuff */
struct wscons_state {
#ifdef _HAVE_TEM_FIRMWARE
#endif /* _HAVE_TEM_FIRMWARE */
/* below us */
} wscons;
/*
* This module has a D_MTPERMOD inner perimeter, so we don't need to protect
* the variables only shared within this module
*/
#ifdef _HAVE_TEM_FIRMWARE
#endif /* _HAVE_TEM_FIRMWARE */
0,
"wc",
0,
2048,
128
};
putq,
NULL,
NULL,
&wcm_info,
};
NULL,
NULL,
&wcm_info,
};
NULL,
NULL,
NULL,
NULL,
&wcm_info,
};
/*
* We always putnext directly to the underlying queue.
*/
NULL,
NULL,
NULL,
NULL,
NULL,
&wcm_info,
};
&wcurinit,
&wcuwinit,
&wclrinit,
&wclwinit,
};
static void wcreioctl(void *);
#ifdef _HAVE_TEM_FIRMWARE
static void wcopoll(void *);
static void wconsout(void *);
#endif /* _HAVE_TEM_FIRMWARE */
static void wcrstrt(void *);
static void wcstart(void *);
unsigned char c);
/*
* Debug printing
*/
#ifndef DPRINTF
#ifdef DEBUG
/*PRINTFLIKE1*/
(((l) >= wc_errlevel) && ((m) & wc_errmask) ? \
wc_dprintf args : \
(void) 0)
/*
* Severity levels for printing
*/
/*
* Masks
*/
#else
#endif
#endif
/*
* Module linkage information for the kernel.
*/
&mod_driverops, /* Type of module. This one is a pseudo driver */
"Workstation multiplexer Driver 'wc'",
&wc_ops, /* driver ops */
};
&modldrv,
};
int
_init(void)
{
int rc;
vt_init();
return (rc);
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
{
}
/*ARGSUSED*/
static int
{
/* create minor node for workstation hard console */
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/* ARGSUSED */
static int
void **result)
{
int error;
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
error = DDI_FAILURE;
} else {
error = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
*result = (void *)0;
error = DDI_SUCCESS;
break;
default:
error = DDI_FAILURE;
}
return (error);
}
#ifdef _HAVE_TEM_FIRMWARE
/*
* Output buffer. Protected by the per-module inner perimeter.
*/
#endif /* _HAVE_TEM_FIRMWARE */
static void
wc_init_polledio(void)
{
if (polledio_inited)
return;
/*
* Initialize the parts of the polled I/O struct that
* are common to both input and output modes, but which
* don't flag to the upper layers, which if any of the
* two modes are available. We don't know at this point
* if system is configured CONS_KFB, but we will when
* consconfig_dacf asks us with CONSOPENPOLLED I/O.
*/
#ifdef _HAVE_TEM_FIRMWARE
/*
* If we're talking directly to a framebuffer, we assume
* that it's a "slow" device, so that rendering should
* be deferred to a timeout or softcall so that we write
* a bunch of characters at once.
*/
#endif /* _HAVE_TEM_FIRMWARE */
}
/*ARGSUSED*/
static int
{
int minor;
}
/*ARGSUSED*/
static int
{
qprocsoff(q);
/*
* If we are closing the VT node which
* /dev/vt/console_user points to, revert
*/
/*
* If we lose the system console,
* no any other active consoles.
*/
}
/*
* just clean for our primary console
* and active console
*/
return (0);
}
return (0);
}
/*
* Put procedure for upper write queue.
* Respond to M_STOP, M_START, M_IOCTL, and M_FLUSH messages here;
* queue up M_BREAK, M_DELAY, and M_DATA messages for processing by
* the start routine, and then call the start routine; discard
* everything else.
*/
static int
{
case M_STOP:
break;
case M_START:
break;
case M_IOCTL: {
case I_LINK: /* stupid, but permitted */
case I_PLINK:
/* somebody already linked */
return (0);
}
break;
case I_UNLINK: /* stupid, but permitted */
case I_PUNLINK:
/* not us */
return (0);
}
break;
case TCSETSW:
case TCSETSF:
case TCSETAW:
case TCSETAF:
case TCSBRK:
/*
* The changes do not take effect until all
* output queued before them is drained.
* Put this message on the queue, so that
* "wcstart" will see it when it's done
* with the output before it. Poke the
* start routine, just in case.
*/
break;
case CONSSETABORTENABLE:
case CONSGETABORTENABLE:
case KIOCSDIRECT:
wscons.wc_pending_wq = q;
break;
}
/* fall through */
default:
/*
* Do it now.
*/
break;
}
break;
}
case M_FLUSH:
/*
* Flush our write queue.
*/
}
} else
break;
case M_BREAK:
/*
* Ignore these, as they make no sense.
*/
break;
case M_DELAY:
case M_DATA:
/*
* Queue the message up to be transmitted,
* and poke the start routine.
*/
break;
case M_IOCDATA:
vt_miocdata(q, mp);
break;
default:
/*
* "No, I don't want a subscription to Chain Store Age,
* thank you anyway."
*/
break;
}
return (0);
}
/*
* Retry an "ioctl", now that "qbufcall" claims we may be able to allocate
* the buffer we need.
*/
/*ARGSUSED*/
static void
{
queue_t *q;
pvc->vc_bufcallid = 0;
/* not pending any more */
}
}
static int
{
char *term;
return (EFAULT);
}
/* PROM terminal emulator */
term = "sun";
} else {
/* Kernel terminal emulator */
term = "sun-color";
}
return (EOVERFLOW);
}
if (ddi_copyout(term,
return (EFAULT);
}
return (0);
}
/*
* Process an "ioctl" message sent down to us.
*/
static void
{
int error;
long len;
return;
}
case TIOCSWINSZ:
/*
* Ignore all attempts to set the screen size; the
* value in the EEPROM is guaranteed (modulo PROM bugs)
* to be the value used by the PROM monitor code, so it
* is by definition correct. Many programs (e.g.,
* "login" and "tset") will attempt to reset the size
* to (0, 0) or (34, 80), neither of which is
* necessarily correct.
* We just ACK the message, so as not to disturb
* programs that set the sizes.
*/
return;
case CONSOPENPOLLEDIO:
("wcioctl: CONSOPENPOLLEDIO\n"));
if (error != 0) {
return;
}
/*
* We are given an appropriate-sized data block,
* and return a pointer to our structure in it.
*/
break;
case CONS_GETTERM:
else
return;
case WC_OPEN_FB:
/*
* Start out pessimistic, so that we can just jump to
* the reply to bail out.
*/
/*
* First test: really, this should be done only from
* inside the kernel. Unfortunately, that information
* doesn't seem to be available in a streams ioctl,
* so restrict it to root only. (Perhaps we could check
* for ioc_cr == kcred.)
*/
goto open_fail;
/*
* Some miscellaneous checks...
*/
/*
* If we don't have exactly one continuation block, fail.
*/
goto open_fail;
/*
* If there's no null terminator in the string, fail.
*/
/* LINTED E_PTRDIFF_OVERFLOW */
goto open_fail;
/*
* NOTE: should eventually get default
* dimensions from a property, e.g. screen-#rows.
*/
/*
* Of course, if the terminal emulator initialization
* failed, fail.
*/
goto open_fail;
#ifdef _HAVE_TEM_FIRMWARE
if (prom_stdout_is_framebuffer()) {
/*
* Drivers in the console stream may emit additional
* messages before we are ready. This causes text
* overwrite on the screen. So we set the redirection
* here. It is safe because the ioctl in consconfig_dacf
* will succeed and consmode will be set to CONS_KFB.
*/
}
#endif /* _HAVE_TEM_FIRMWARE */
/*
* ... and succeed.
*/
break;
case WC_CLOSE_FB:
/*
* There's nothing that can call this, so it's not
* really implemented.
*/
/*
* However, if it were implemented, it would clearly
* be root-only.
*/
goto close_fail;
break;
default:
/*
* The only way in which "ttycommon_ioctl" can fail is
* if the "ioctl" requires a response containing data
* to be returned to the user, and no mblk could be
* allocated for the data. No such "ioctl" alters our
* state. Thus, we always go ahead and do any
* state-changes the "ioctl" calls for. If we couldn't
* allocate the data, "ttycommon_ioctl" has stashed the
* "ioctl" away safely, so we just call "qbufcall" to
* request that we be called back when we stand a
* better chance of allocating the data.
*/
if (datasize != 0) {
if (pvc->vc_bufcallid != 0)
return;
}
if (error < 0) {
error = 0;
else
}
if (error != 0) {
}
break;
}
}
/*
* This function gets the polled I/O structures from the lower
* keyboard driver. If any initialization or resource allocation
* needs to be done by the lower driver, it will be done when
* the lower driver services this message.
*/
static void
{
("wc_open_kb_polledio: sending CONSOPENPOLLEDIO\n"));
/*
* If we can't get an mblk, then wait for it.
*/
goto nomem;
}
/*
* If we can't get an mblk, then wait for it, and release
* the mblk that we have already allocated.
*/
goto nomem;
}
sizeof (struct cons_polledio *);
wscons->wc_pending_wq = q;
return;
}
/*
* This function releases the polled I/O structures from the lower
* keyboard driver. If any de-initialization needs to be done, or
* any resources need to be released, it will be done when the lower
* driver services this message.
*/
static void
{
("wc_close_kb_polledio: sending CONSCLOSEPOLLEDIO\n"));
/*
* If we can't get an mblk, then wait for it.
*/
goto nomem;
}
/*
* If we can't get an mblk, then wait for it, and release
* the mblk that we have already allocated.
*/
goto nomem;
}
wscons->wc_pending_wq = q;
return;
}
#ifdef _HAVE_TEM_FIRMWARE
/* ARGSUSED */
static void
{
queue_t *q;
pvc->vc_timeoutid = 0;
/* See if we can continue output */
} else
}
}
#endif /* _HAVE_TEM_FIRMWARE */
/*
* Restart output on the console after a timeout.
*/
/* ARGSUSED */
static void
{
}
/*
* get screen terminal for current output
*/
static tem_vt_state_t
{
return (NULL);
}
/*
* Start console output
*/
static void
{
#ifdef _HAVE_TEM_FIRMWARE
int c;
#endif /* _HAVE_TEM_FIRMWARE */
queue_t *q;
/*
* If we're waiting for something to happen (delay timeout to
* expire, current transmission to finish, output to be
* restarted, output to finish draining), don't grab anything
* new.
*/
return;
/*
* assumes that we have been called by whoever holds the
* exclusionary lock on the write-side queue (protects
* vc_flags and vc_pendc).
*/
for (;;) {
return; /* nothing to transmit */
/*
* We have a new message to work on.
* Check whether it's a delay or an ioctl (the latter
* occurs if the ioctl in question was waiting for the output
* to drain). If it's one of those, process it immediately.
*/
case M_DELAY:
/*
* Arrange for "wcrstrt" to be called when the
* delay expires; it will turn WCS_DELAY off,
* and call "wcstart" to grab the next message.
*/
if (pvc->vc_timeoutid != 0)
return; /* wait for this to finish */
case M_IOCTL:
/*
* This ioctl was waiting for the output ahead of
* it to drain; obviously, it has. Do it, and
* then grab the next message after it.
*/
continue;
}
#ifdef _HAVE_TEM_FIRMWARE
#endif /* _HAVE_TEM_FIRMWARE */
/* LINTED */
kcred);
}
}
}
#ifdef _HAVE_TEM_FIRMWARE
continue;
}
/* consmode = CONS_FW */
continue;
}
/* LINTED E_PTRDIFF_OVERFLOW */
continue;
}
/*
* Direct output to the frame buffer if this device
* is not the "hardware" console.
*/
if (wscons.wc_defer_output) {
/*
* Never do output here;
* it takes forever.
*/
} else { /* wait a bit */
if (pvc->vc_timeoutid != 0)
(void) quntimeout(q,
pvc->vc_timeoutid);
}
return;
}
for (;;) {
cc--;
if (prom_mayput((char)c) != 0) {
if (pvc->vc_timeoutid != 0)
(void) quntimeout(q,
pvc->vc_timeoutid);
pvc, 1);
/* not done with this message yet */
return;
}
while (cc <= 0) {
return;
/* LINTED E_PTRDIFF_OVERFLOW */
}
}
#endif /* _HAVE_TEM_FIRMWARE */
}
}
#ifdef _HAVE_TEM_FIRMWARE
/*
* Output to frame buffer console.
* It takes a long time to scroll.
*/
/* ARGSUSED */
static void
{
queue_t *q;
char *current_position;
return; /* not attached to a stream */
}
/*
* Set up to copy up to MAXHIWAT bytes.
*/
current_position = &obuf[0];
/*
* This ioctl was waiting for the output ahead of
* it to drain; obviously, it has. Put it back
* so that "wcstart" can handle it, and transmit
* what we've got.
*/
goto transmit;
}
do {
/* LINTED E_PTRDIFF_OVERFLOW */
while (cc != 0) {
if (bytes_left == 0) {
/*
* Out of buffer space; put this
* buffer back on the queue, and
* transmit what we have.
*/
goto transmit;
}
*current_position++ = *cp++;
cc--;
bytes_left--;
}
}
}
#endif /* _HAVE_TEM_FIRMWARE */
/*
* Put procedure for lower read queue.
* Pass everything up to queue above "upper half".
*/
static int
{
case M_FLUSH:
/*
* Flush our write queue.
*/
/* XXX doesn't flush M_DELAY */
}
} else
break;
case M_DATA:
break;
}
} else {
}
} else
break;
case M_IOCACK:
case M_IOCNAK:
case M_IOCACK:
case CONSOPENPOLLEDIO:
("wclrput: "
"ACK CONSOPENPOLLEDIO\n"));
*(struct cons_polledio **)
break;
case CONSCLOSEPOLLEDIO:
("wclrput: "
"ACK CONSCLOSEPOLLEDIO\n"));
break;
default:
("wclrput: "
"ACK UNKNOWN\n"));
}
break;
case M_IOCNAK:
/*
* Keyboard may or may not support polled I/O.
* This ioctl may have been rejected because
* we only have the wc->conskbd chain built,
* and the keyboard driver has not been linked
* underneath conskbd yet.
*/
("wclrput: NAK\n"));
case CONSCLOSEPOLLEDIO:
break;
}
break;
}
/*
* Discard the response, replace it with the
* pending response to the I_PLINK, then let it
* flow upward.
*/
}
/* FALLTHROUGH */
default: /* inc M_ERROR, M_HANGUP, M_IOCACK, M_IOCNAK, ... */
break;
}
} else {
("wclrput: Message DISCARDED\n"));
}
break;
}
return (0);
}
#ifdef _HAVE_TEM_FIRMWARE
/*
* This routine exists so that prom_write() can redirect writes
* to the framebuffer through the kernel terminal emulator, if
* that configuration is selected during consconfig.
* When the kernel terminal emulator is enabled, consconfig_dacf
* sets up the PROM output redirect vector to enter this function.
* During panic the console will already be powered up as part of
* calling into the prom_*() layer.
*/
/* ARGSUSED */
{
return (0);
if (panicstr)
polled_io_cons_write(s, n);
else
return (n);
}
#endif /* _HAVE_TEM_FIRMWARE */
/*
* These are for systems without OBP, and for devices that cannot be
* shared between Solaris and the OBP.
*/
static void
{
if (c == '\n')
/*
* We have no terminal emulator configured. We have no
* recourse but to drop the output on the floor.
*/
return;
}
}
/*
* These are for systems without OBP, and for devices that cannot be
* shared between Solaris and the OBP.
*/
static int
{
prom_printf("wscons: getchar with no keyboard support");
prom_printf("Halted...");
for (;;)
/* HANG FOREVER */;
}
}
static boolean_t
{
return (B_FALSE);
}
static void
{
return;
}
}
static void
{
return;
}
}
#ifdef DEBUG
static void
{
}
#endif
/*ARGSUSED*/
static void
{
}
/*
* Gets the number of text rows and columns and the
* width and height (in pixels) of the console.
*/
void
{
tem_get_size(&r, &c, &x, &y);
#ifdef _HAVE_TEM_FIRMWARE
else
console_get_size(&r, &c, &x, &y);
#endif /* _HAVE_TEM_FIRMWARE */
t->ws_col = c;
t->ws_row = r;
t->ws_xpixel = x;
t->ws_ypixel = y;
return;
/* only for the wscons:0 */
}
/*ARGSUSED*/
static void
{
}
}