/*
* 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
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This driver uses the QPAIR form of STREAMS Perimeters to serialize access
* to the read and write STREAMS queues.
*/
#include <sys/sysmacros.h>
#include <sys/prom_plat.h>
#include <sys/sgsbbc_iosram.h>
#include <sys/serengeti.h>
/*
* Here we define several macros for accessing console IOSRAM
*/
/* dev_ops and cb_ops for device driver */
/* interrupt handlers */
static void sgcn_data_in_handler(caddr_t);
static void sgcn_space_2_out_handler(caddr_t);
static void sgcn_break_handler(caddr_t);
/* other internal sgcn routines */
static void sgcn_reioctl(void *);
static void sgcn_start(void);
static void sgcn_flush(void);
static int sgcn_read_header(int, cnsram_header *);
static void sgcn_log_error(int, int);
/* circular buffer routines */
static int circular_buffer_write(int, int, int, int, caddr_t, int);
static int circular_buffer_read(int, int, int, int, caddr_t, int);
static void sg_abort_seq_handler(char *);
/* streams structures */
SGCN_MI_IDNUM, /* mi_idnum */
"sgcn", /* mi_idname */
0, /* mi_minpsz */
INFPSZ, /* mi_maxpsz */
SGCN_MI_HIWAT, /* mi_hiwat */
SGCN_MI_LOWAT /* mi_lowat */
};
putq, /* qi_putp */
sgcn_rsrv, /* qi_srvp */
sgcn_open, /* qi_qopen */
sgcn_close, /* qi_qclose */
NULL, /* qi_qadmin */
&minfo, /* qi_minfo */
NULL /* qi_mstat */
};
sgcn_wput, /* qi_putp */
sgcn_wsrv, /* qi_srvp */
sgcn_open, /* qi_qopen */
sgcn_close, /* qi_qclose */
NULL, /* qi_qadmin */
&minfo, /* qi_minfo */
NULL /* qi_mstat */
};
&rinit,
&winit,
NULL,
};
/* standard device driver structures */
nulldev, /* open() */
nulldev, /* close() */
nodev, /* strategy() */
nodev, /* print() */
nodev, /* dump() */
nodev, /* read() */
nodev, /* write() */
nodev, /* ioctl() */
nodev, /* devmap() */
nodev, /* mmap() */
nodev, /* segmap() */
nochpoll, /* poll() */
ddi_prop_op, /* prop_op() */
&sgcnstrinfo, /* cb_str */
};
0, /* refcnt */
sgcn_getinfo, /* getinfo() */
nulldev, /* identify() */
nulldev, /* probe() */
sgcn_attach, /* attach() */
sgcn_detach, /* detach() */
nodev, /* reset() */
&sgcn_cb_ops, /* cb_ops */
NULL, /* power() */
ddi_quiesce_not_supported, /* quiesce */
};
"Serengeti console driver",
};
(void*)&modldrv,
};
/* driver configuration routines */
int
_init(void)
{
int error;
if (error == 0) {
} else {
}
return (error);
}
int
_fini(void)
{
/* can't remove console driver */
return (EBUSY);
}
int
{
}
/*
* sgcn_attach is called at startup time.
* There is only once instance of this driver.
*/
static int
{
extern int ddi_create_internal_pathname(
dev_info_t *, char *, int, minor_t);
int rv;
if (cmd != DDI_ATTACH)
return (DDI_FAILURE);
!= DDI_SUCCESS)
return (DDI_FAILURE);
/* prepare some data structures in soft state */
/*
* We need to verify IOSRAM is intact at startup time. If by
* any chance IOSRAM is corrupted, that means SC is not ready.
* All we can do is stopping.
*/
sizeof (cnsram_header));
if (rv != 0)
/*
* XXX need to add extra check for version no.
*/
/* Allocate console input buffer */
#ifdef SGCN_DEBUG
prom_printf("Allocated %d(0x%X) bytes for console\n",
#endif
#ifdef SGCN_DEBUG
prom_printf("sgcn_attach(): SGCN driver attached\n");
#endif
return (DDI_SUCCESS);
}
/* ARGSUSED */
static int
{
if (cmd == DDI_DETACH)
return (DDI_FAILURE);
#ifdef SGCN_DEBUG
prom_printf("sgcn_detach(): SGCN driver detached\n");
#endif
return (DDI_SUCCESS);
}
/* ARGSUSED */
static int
{
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
if (sgcn_state) {
error = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
*result = (void *)0;
error = DDI_SUCCESS;
}
break;
}
return (error);
}
/* streams open & close */
/* ARGSUSED */
static int
{
if (unit != 0)
return (ENXIO);
/* stream already open */
if (q->q_ptr) {
return (DDI_SUCCESS);
}
if (!sgcn_state) {
autoconfig\n");
return (ENXIO);
}
/* Link the RD and WR Q's */
qprocson(q);
/* initialize interrupt handler */
(void) iosram_reg_intr(SBBC_CONSOLE_IN,
(void) iosram_reg_intr(SBBC_CONSOLE_BRK,
return (DDI_SUCCESS);
}
/* ARGSUSED */
static int
{
int ret;
if (sgcn_state->sgcn_wbufcid != 0) {
}
qprocsoff(q);
return (DDI_SUCCESS);
}
/*
* Put procedure for write queue.
* Respond to M_IOCTL, M_DATA and M_FLUSH messages here;
* It put's the data onto internal sgcn_output_q.
*/
static int
{
#ifdef SGCN_DEBUG
int i;
#endif
}
#ifdef SGCN_DEBUG
prom_printf("sgcn_wput(): SGCN wput q=%X mp=%X rd=%X wr=%X type=%X\n",
#endif
case M_IOCTL:
case M_CTL:
#ifdef SGCN_DEBUG
prom_printf("sgcn_wput(): M_IOCTL cmd=%X TIOC=%X\n",
#endif
case TCSETSW:
case TCSETSF:
case TCSETAW:
case TCSETAF:
case TCSBRK:
/*
* The change do not take effect until all
* output queued before them is drained.
* Put this message on the queue, so that
* "sgcn_start" will see it when it's done
* with the output before it. Poke the start
* routine, just in case.
*/
sgcn_start();
break;
default:
sgcn_ioctl(q, mp);
}
break;
case M_FLUSH:
}
} else {
}
break;
case M_STOP:
sgcn_stopped = TRUE;
break;
case M_START:
qenable(q); /* Start up delayed messages */
break;
case M_DATA:
/*
* Queue the message up to be transmitted,
* and poke the start routine.
*/
#ifdef SGCN_DEBUG
prom_printf("sgcn_wput(): DATA q=%X mp=%X rd=%X wr=%X\n",
prom_printf("sgcn_wput(): [[[[[");
}
prom_printf("]]]]]\n");
}
#endif /* SGCN_DEBUG */
sgcn_start();
break;
default:
}
return (0);
}
/*
* Process an "ioctl" message sent down to us.
*/
static void
{
int data_size;
int error = 0;
#ifdef SGCN_DEBUG
#endif
}
if (data_size != 0) {
if (sgcn_state->sgcn_wbufcid)
/* call sgcn_reioctl() */
return;
}
if (error < 0) {
/*
* "ttycommon_ioctl" didn't do anything; we process it here.
*/
error = 0;
case TCSBRK:
case TIOCSBRK:
case TIOCCBRK:
case TIOCMSET:
case TIOCMBIS:
case TIOCMBIC:
else
break;
case TIOCMGET:
break;
}
else
break;
default:
break;
}
}
if (error != 0) {
}
}
static void
{
queue_t *q;
if (!sgcnp->sgcn_wbufcid) {
return;
}
sgcnp->sgcn_wbufcid = 0;
return;
}
sgcn_ioctl(q, mp);
}
}
static void
{
queue_t *q;
int retval;
/*
* read stream queue and remove data from the queue and
* transmit them if possible
*/
q = sgcn_state->sgcn_writeq;
case M_IOCTL:
/*
* These are those IOCTLs queued up
* do it now
*/
sgcn_ioctl(q, mp);
continue;
default:
/*
* M_DATA
* Copy it from stream queue buffer to
* sgcn buffer
*/
/*
* Console output buffer is full for
* sgcn_timeout_period seconds, assume
* SC is dead, drop all console output
* data from stream queue.
*/
if (sgcn_state->sgcn_sc_active <
sgcn_flush();
return;
/*
* Console output just became full
* return
*/
return;
} else {
/* send more console output */
}
} /* switch */
}
}
static int
{
#ifdef SGCN_DEBUG
#endif
do {
if (len > 0)
(void) iosram_send_intr(SBBC_CONSOLE_OUT);
/* IOSRAM is full, we are not done with mp yet */
if (len)
return (EAGAIN);
else
return (EBUSY);
}
} while (mp);
return (0);
}
/*
* called when SC first establishes console connection
* drop all the data on the output queue
*/
static void
{
queue_t *q;
q = sgcn_state->sgcn_writeq;
prom_printf("sgcn_flush(): WARNING console output is dropped "
"time=%lX\n", gethrestime_sec());
}
}
/*
* Interrupt handlers
* All handlers register with SBBC driver and must follow SBBC interrupt
* delivery conventions.
*/
/*
* SC sends an interrupt when new data comes in
*/
/* ARGSUSED */
void
{
int i, len;
/*
* change interrupt state so that SBBC won't trigger
* another one.
*/
/* update sgcn_state for SC activity information */
/* enter our perimeter */
for (;;) {
/* read from console input IOSRAM */
if (len <= 0) {
if (len <= 0) {
/* leave our perimeter */
return;
} else {
}
}
(void) iosram_send_intr(SBBC_CONSOLE_SPACE_IN);
if (abort_enable == KIOCABORTALTERNATE) {
for (i = 0; i < len; i ++) {
if (abort_charseq_recognize(buf[i]))
abort_sequence_enter((char *)NULL);
}
}
/* put console input onto stream */
if (sgcn_state->sgcn_readq) {
"sgcn_data_in_handler(): allocb failed"
" (console input dropped.)");
} else {
}
}
}
}
/*
* SC sends an interrupt when it takes output data
* from a full IOSRAM
*/
/* ARGSUSED */
void
{
/*
* change interrupt state so that SBBC won't trigger
* another one.
*/
/* restore interrupt state */
}
/*
* SC sends an interrupt when it detects BREAK sequence
*/
/* ARGSUSED */
void
{
/*
* change interrupt state so that SBBC won't trigger
* another one.
*/
if (abort_enable != KIOCABORTALTERNATE)
abort_sequence_enter((char *)NULL);
/* restore interrupt state */
}
/*
* reporting errors in console driver sgcn.
* since we can not trust console driver at this time, we need to
* log errors in other system logs
* error codes:
* EIO - iosram interface failed
* EPROTO - IOSRAM is corrupted
* EINVAL - invalid argument
*/
static void
{
error_counter ++;
if (error_counter > SGCN_MAX_ERROR) {
error_counter = 0;
} else {
"console I/O");
}
}
static int
{
int rv;
/* check IOSRAM contents and read pointers */
sizeof (cnsram_header));
if (rv != 0) {
return (-1);
}
/*
* Since the header is read in a byte-by-byte fashion
* using ddi_rep_get8, we need to re-read the producer
* or consumer pointer as integer in case it has changed
* after part of the previous value has been read.
*/
if (rw == RW_CONSOLE_READ) {
sizeof (header->cnsram_in_wrptr));
} else if (rw == RW_CONSOLE_WRITE) {
sizeof (header->cnsram_out_rdptr));
} else
rv = -1;
return (rv);
}
static int
{
#ifdef SGCN_DEBUG
prom_printf("sgcn_rw() rw = %X buf = %p len = %d\n",
#endif /* SGCN_DEBUG */
if (len == 0)
return (0);
/* sanity check */
return (-1);
}
/* check IOSRAM contents and read pointers */
if (rv != 0) {
return (-1);
}
return (-1);
}
if (rw == RW_CONSOLE_READ)
else if (rw == RW_CONSOLE_WRITE)
if (size < 0) {
return (-1);
}
if (rw == RW_CONSOLE_READ)
else if (rw == RW_CONSOLE_WRITE)
/*
* error log was done in circular buffer routines,
* no need to call sgcn_log_error() here
*/
if (nbytes < 0)
return (-1);
if (nbytes == 0)
return (0);
if (rw == RW_CONSOLE_READ) {
+ nbytes)
sizeof (header.cnsram_in_rdptr));
} else if (rw == RW_CONSOLE_WRITE) {
+ nbytes)
sizeof (header.cnsram_out_wrptr));
}
if (rv != 0) {
return (-1);
}
return (nbytes);
}
/*
* Circular buffer interfaces
*
* See sgcn.h for circular buffer structure
*
* The circular buffer is empty when read ptr == write ptr
* and is full when read ptr is one ahead of write ptr
*/
/*
* Write to circular buffer in IOSRAM
* input:
* buf buffer in main memory, contains data to be written
* len length of data in bytes
* begin, end, rd, wr buffer pointers
* return value:
* actual bytes written.
*/
static int
{
int rv = 0;
if (size <= 0) {
goto out;
}
return (0); /* The buffer's full, so just return 0 now. */
/* write console data */
} else { /* break into two pieces because of circular buffer */
/* write console data */
if (space_at_end) {
}
if (len - space_at_end) {
}
}
return (len);
out:
return (-1);
}
/*
* Read from circular buffer in IOSRAM
* input:
* buf preallocated buffer in memory
* len size of buf
* begin, end, rd, wr buffer pointers
* return value:
* actual bytes read
*/
/* ARGSUSED */
static int
{
int rv = 0;
if (size <= 0) {
goto out;
}
} else { /* break into two pieces because of circular buffer */
/* read console data */
if (nbytes_at_end) {
}
if (nbytes-nbytes_at_end) {
}
}
return (nbytes);
out:
return (-1);
}
/*
* Check for abort character sequence, copied from zs_async.c
*/
static boolean_t
{
static int state = 0;
state = 0;
return (B_TRUE);
}
} else {
}
return (B_FALSE);
}
static void
{
char key_switch;
int rv;
/* read virtual keyswitch position from IOSRAM */
if (rv != 0) {
/* default to not secure if read failed */
key_switch = 0;
}
if (key_switch & SG_KEYSWITCH_POSN_SECURE) {
} else {
}
}
static int
{
if (sgcn_stopped == TRUE) {
return (0);
}
if (canputnext(q)) {
}
}
return (0);
}
/* ARGSUSED */
static int
{
if (sgcn_stopped == TRUE)
return (0);
sgcn_start();
return (0);
}