Home | History | Annotate | Line # | Download | only in dev
cninit.c revision 1.13
      1  1.13     uwe /*	$NetBSD: cninit.c,v 1.13 2020/07/17 02:16:57 uwe Exp $	*/
      2   1.1  mellon 
      3   1.1  mellon /*
      4  1.11   rmind  * Copyright (c) 1988 University of Utah.
      5   1.1  mellon  * Copyright (c) 1990, 1993
      6   1.1  mellon  *	The Regents of the University of California.  All rights reserved.
      7   1.1  mellon  *
      8   1.1  mellon  * This code is derived from software contributed to Berkeley by
      9   1.1  mellon  * the Systems Programming Group of the University of Utah Computer
     10   1.1  mellon  * Science Department.
     11   1.1  mellon  *
     12   1.1  mellon  * Redistribution and use in source and binary forms, with or without
     13   1.1  mellon  * modification, are permitted provided that the following conditions
     14   1.1  mellon  * are met:
     15   1.1  mellon  * 1. Redistributions of source code must retain the above copyright
     16   1.1  mellon  *    notice, this list of conditions and the following disclaimer.
     17   1.1  mellon  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.1  mellon  *    notice, this list of conditions and the following disclaimer in the
     19   1.1  mellon  *    documentation and/or other materials provided with the distribution.
     20   1.5     agc  * 3. Neither the name of the University nor the names of its contributors
     21   1.5     agc  *    may be used to endorse or promote products derived from this software
     22   1.5     agc  *    without specific prior written permission.
     23   1.5     agc  *
     24   1.5     agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25   1.5     agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26   1.5     agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27   1.5     agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28   1.5     agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29   1.5     agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30   1.5     agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31   1.5     agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32   1.5     agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33   1.5     agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34   1.5     agc  * SUCH DAMAGE.
     35   1.5     agc  *
     36   1.5     agc  * from: Utah $Hdr: cons.c 1.7 92/01/21$
     37   1.5     agc  *
     38   1.5     agc  *	@(#)cons.c	8.2 (Berkeley) 1/12/94
     39   1.5     agc  */
     40   1.5     agc 
     41   1.4   lukem #include <sys/cdefs.h>
     42  1.13     uwe __KERNEL_RCSID(0, "$NetBSD: cninit.c,v 1.13 2020/07/17 02:16:57 uwe Exp $");
     43   1.1  mellon 
     44   1.1  mellon #include <sys/param.h>
     45   1.1  mellon #include <sys/proc.h>
     46   1.1  mellon #include <sys/systm.h>
     47   1.1  mellon #include <sys/buf.h>
     48   1.1  mellon #include <sys/ioctl.h>
     49   1.1  mellon #include <sys/tty.h>
     50   1.1  mellon #include <sys/file.h>
     51   1.1  mellon #include <sys/conf.h>
     52   1.1  mellon #include <sys/vnode.h>
     53   1.1  mellon 
     54   1.1  mellon #include <dev/cons.h>
     55   1.1  mellon 
     56   1.1  mellon void
     57   1.9    matt cninit(void)
     58   1.1  mellon {
     59  1.13     uwe 	struct consdev *bestMatch;
     60   1.3      tv 	struct consdev *cp;
     61   1.7   perry 
     62  1.13     uwe 	cn_tab = NULL;
     63  1.13     uwe 
     64   1.1  mellon 	/*
     65   1.1  mellon 	 * Collect information about all possible consoles
     66   1.1  mellon 	 * and find the one with highest priority
     67   1.1  mellon 	 */
     68  1.13     uwe 	bestMatch = NULL;
     69   1.1  mellon 	for (cp = constab; cp->cn_probe; cp++) {
     70   1.1  mellon 		(*cp->cn_probe)(cp);
     71   1.1  mellon 		if (cp->cn_pri > CN_DEAD &&
     72   1.3      tv 		    (bestMatch == NULL || cp->cn_pri > bestMatch->cn_pri)) {
     73   1.3      tv 			bestMatch = cp;
     74   1.3      tv 		}
     75   1.1  mellon 	}
     76  1.12     uwe 
     77   1.1  mellon 	/*
     78   1.1  mellon 	 * No console, we can handle it
     79   1.1  mellon 	 */
     80  1.12     uwe 	if (bestMatch == NULL)
     81   1.1  mellon 		return;
     82  1.12     uwe 
     83   1.1  mellon 	/*
     84   1.1  mellon 	 * Turn on console
     85   1.1  mellon 	 */
     86   1.3      tv 	{
     87  1.13     uwe 		/* XXX: can this ever be non-NULL? */
     88   1.3      tv 		struct consdev *old_cn_tab = cn_tab;
     89   1.3      tv 
     90  1.13     uwe 		/* cn_init may set cn_tab to self */
     91  1.12     uwe  		(*bestMatch->cn_init)(bestMatch);
     92  1.13     uwe 
     93   1.3      tv 		/*
     94   1.3      tv 		 * Now let everyone know we have an active console they can
     95   1.3      tv 		 * use for diagnostics. If we use cn_tab in the search loop
     96   1.3      tv 		 * then interrupts from the ethernet at boot may cause system
     97   1.3      tv 		 * hang.
     98   1.3      tv 		 */
     99  1.13     uwe 		if (cn_tab == old_cn_tab) /* if cn_init didn't, set it */
    100   1.3      tv 			cn_tab = bestMatch;
    101   1.3      tv 	}
    102   1.1  mellon }
    103