Path: blob/main/sys/powerpc/mambo/mambo_console.c
105541 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (C) 2008 by Nathan Whitehorn. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,18* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;20* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,21* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF23* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include <sys/param.h>27#include <sys/kdb.h>28#include <sys/kernel.h>29#include <sys/priv.h>30#include <sys/systm.h>31#include <sys/types.h>32#include <sys/conf.h>33#include <sys/cons.h>34#include <sys/consio.h>35#include <sys/tty.h>3637#include <dev/ofw/openfirm.h>3839#include <ddb/ddb.h>4041#include "mambocall.h"4243#define MAMBOBURSTLEN 128 /* max number of bytes to write in one chunk */4445#define MAMBO_CONSOLE_WRITE 046#define MAMBO_CONSOLE_READ 604748static tsw_outwakeup_t mambotty_outwakeup;4950static struct ttydevsw mambo_ttydevsw = {51.tsw_flags = TF_NOPREFIX,52.tsw_outwakeup = mambotty_outwakeup,53};5455static int polltime;56static struct callout mambo_callout;57static struct tty *tp = NULL;5859#if defined(KDB)60static int alt_break_state;61#endif6263static void mambo_timeout(void *);6465static cn_probe_t mambo_cnprobe;66static cn_init_t mambo_cninit;67static cn_term_t mambo_cnterm;68static cn_getc_t mambo_cngetc;69static cn_putc_t mambo_cnputc;70static cn_grab_t mambo_cngrab;71static cn_ungrab_t mambo_cnungrab;7273CONSOLE_DRIVER(mambo);7475static void76cn_drvinit(void *unused)77{7879if (mambo_consdev.cn_pri != CN_DEAD &&80mambo_consdev.cn_name[0] != '\0') {81if (OF_finddevice("/mambo") == -1)82return;8384tp = tty_alloc(&mambo_ttydevsw, NULL);85tty_init_console(tp, 0);86tty_makedev(tp, NULL, "%s", "mambocons");8788polltime = 1;8990callout_init(&mambo_callout, 1);91callout_reset(&mambo_callout, polltime, mambo_timeout, NULL);92}93}9495SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);9697static void98mambotty_outwakeup(struct tty *tp)99{100int len;101u_char buf[MAMBOBURSTLEN];102103for (;;) {104len = ttydisc_getc(tp, buf, sizeof buf);105if (len == 0)106break;107mambocall(MAMBO_CONSOLE_WRITE, buf, (register_t)len, 1UL);108}109}110111static void112mambo_timeout(void *v)113{114int c;115116tty_lock(tp);117while ((c = mambo_cngetc(NULL)) != -1)118ttydisc_rint(tp, c, 0);119ttydisc_rint_done(tp);120tty_unlock(tp);121122callout_reset(&mambo_callout, polltime, mambo_timeout, NULL);123}124125static void126mambo_cnprobe(struct consdev *cp)127{128if (OF_finddevice("/mambo") == -1) {129cp->cn_pri = CN_DEAD;130return;131}132133cp->cn_pri = CN_NORMAL;134}135136static void137mambo_cninit(struct consdev *cp)138{139140/* XXX: This is the alias, but that should be good enough */141strcpy(cp->cn_name, "mambocons");142}143144static void145mambo_cnterm(struct consdev *cp)146{147}148149static void150mambo_cngrab(struct consdev *cp)151{152}153154static void155mambo_cnungrab(struct consdev *cp)156{157}158159static int160mambo_cngetc(struct consdev *cp)161{162int ch;163164ch = mambocall(MAMBO_CONSOLE_READ);165166if (ch > 0 && ch < 0xff) {167#if defined(KDB)168kdb_alt_break(ch, &alt_break_state);169#endif170return (ch);171}172173return (-1);174}175176static void177mambo_cnputc(struct consdev *cp, int c)178{179char cbuf;180181cbuf = c;182mambocall(MAMBO_CONSOLE_WRITE, &cbuf, 1UL, 1UL);183}184185186