Home | History | Annotate | Line # | Download | only in sgimips
      1 /*	$NetBSD: console.c,v 1.46 2026/04/30 02:56:26 adrian Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: console.c,v 1.46 2026/04/30 02:56:26 adrian Exp $");
     32 
     33 #include "opt_kgdb.h"
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/termios.h>
     38 #include <sys/device.h>
     39 
     40 #include <sys/bus.h>
     41 #include <machine/machtype.h>
     42 
     43 #include <dev/cons.h>
     44 #include <dev/arcbios/arcbios.h>
     45 #include <dev/arcbios/arcbiosvar.h>
     46 #include <dev/ic/comreg.h>
     47 #include <dev/ic/comvar.h>
     48 #include <dev/ic/i8042reg.h>
     49 #include <dev/ic/pckbcvar.h>
     50 
     51 #include <sgimips/gio/giovar.h>
     52 #include <sgimips/hpc/hpcreg.h>
     53 #include <sgimips/ioc/iocreg.h>
     54 #include <sgimips/mace/macereg.h>
     55 
     56 #include "com.h"
     57 #include "scn.h"
     58 #include "zsc.h"
     59 #include "gio.h"
     60 #include "pckbc.h"
     61 #include "zskbd.h"
     62 #include "crmfb.h"
     63 
     64 #ifndef CONMODE
     65 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
     66 #endif
     67 int comcnmode = CONMODE;
     68 
     69 extern struct consdev scn_cn;
     70 extern struct consdev zs_cn;
     71 
     72 extern void	zs_kgdb_init(void);
     73 extern void	zskbd_cnattach(int, int);
     74 #if (NCRMFB > 0)
     75 extern int	crmfb_probe(void);
     76 #endif
     77 
     78 void		kgdb_port_init(void);
     79 static int	scn_serial_init(const char *);
     80 static int	zs_serial_init(const char *);
     81 static int	gio_video_init(const char *);
     82 static int	mace_serial_init(const char *);
     83 
     84 void
     85 consinit(void)
     86 {
     87 	const char *consdev;
     88 
     89 	/* Ask ARCS what it is using for console output. */
     90 	consdev = arcbios_GetEnvironmentVariable("ConsoleOut");
     91 
     92 	if (consdev == NULL) {
     93 		printf("WARNING: ConsoleOut environment variable not set\n");
     94 		return;
     95 	}
     96 
     97 	switch (mach_type) {
     98 	case MACH_SGI_IP6 | MACH_SGI_IP10:
     99 		if (scn_serial_init(consdev))
    100 			return;
    101 		break;
    102 
    103 	case MACH_SGI_IP12:
    104 	case MACH_SGI_IP20:
    105 	case MACH_SGI_IP22:
    106 		if (gio_video_init(consdev) || zs_serial_init(consdev))
    107 			return;
    108 		break;
    109 
    110 	case MACH_SGI_IP32:
    111 		if (mace_serial_init(consdev))
    112 			return;
    113 #if (NCRMFB > 0)
    114 		if (crmfb_probe()) {
    115 			return;
    116 		}
    117 #else
    118 		panic("this ip32 kernel does not contain framebuffer support.");
    119 #endif
    120 		break;
    121 
    122 	default:
    123 		panic("consinit(): unknown machine type IP%d\n", mach_type);
    124 		break;
    125 	}
    126 
    127 	printf("Using ARCS for console I/O.\n");
    128 }
    129 
    130 static int
    131 scn_serial_init(const char *consdev)
    132 {
    133 #if (NSCN > 0)
    134 	if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
    135 	    (consdev[7] == '0' || consdev[7] == '1')) {
    136 		cn_tab = &scn_cn;
    137 		(*cn_tab->cn_init)(cn_tab);
    138 
    139 		return (1);
    140 	}
    141 #endif
    142 
    143 	return (0);
    144 }
    145 
    146 static int
    147 zs_serial_init(const char *consdev)
    148 {
    149 #if (NZSC > 0)
    150 	if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
    151 	    (consdev[7] == '0' || consdev[7] == '1')) {
    152 		cn_tab = &zs_cn;
    153 		(*cn_tab->cn_init)(cn_tab);
    154 
    155 		return (1);
    156 	}
    157 #endif
    158 
    159 	return (0);
    160 }
    161 
    162 static int
    163 gio_video_init(const char *consdev)
    164 {
    165 #if (NGIO > 0)
    166 	if (strcmp(consdev, "video()") == 0) {
    167 		/*
    168 		 * XXX Assumes that if output is video()
    169 		 * input must be keyboard().
    170 		 */
    171 		if (gio_cnattach() != 0)
    172 			return (0);
    173 
    174 		switch(mach_type) {
    175 		case MACH_SGI_IP12:
    176 		case MACH_SGI_IP20:
    177 #if (NZSKBD > 0)
    178 			/* XXX Hardcoded unit, channel */
    179 			zskbd_cnattach(0, 0);
    180 #endif
    181 			break;
    182 
    183 		case MACH_SGI_IP22:
    184 #if (NPCKBC > 0)
    185 			/* XXX Hardcoded iotag, HPC address XXX */
    186 			pckbc_cnattach(normal_memt,
    187 			    HPC_BASE_ADDRESS_0 +
    188 			    HPC3_PBUS_CH6_DEVREGS + IOC_KB_REGS, KBCMDP,
    189 			    PCKBC_KBD_SLOT, 0);
    190 #endif
    191 			break;
    192 		}
    193 
    194 		return (1);
    195 	}
    196 #endif
    197 
    198 	return (0);
    199 }
    200 
    201 static int
    202 mace_serial_init(const char *consdev)
    203 {
    204 #if (NCOM > 0)
    205 	const char     *dbaud;
    206 	int       speed;
    207 	u_int32_t base;
    208 
    209 	if ((strlen(consdev) == 9) && (!strncmp(consdev, "serial", 6)) &&
    210 	    (consdev[7] == '0' || consdev[7] == '1')) {
    211 		/* Get comm speed from ARCS */
    212 		dbaud = arcbios_GetEnvironmentVariable("dbaud");
    213 		speed = strtoul(dbaud, NULL, 10);
    214 		base = (consdev[7] == '0') ? MACE_ISA_SER1_BASE :
    215 		    MACE_ISA_SER2_BASE;
    216 
    217 		delay(10000);
    218 
    219 		/* XXX: hardcoded MACE iotag */
    220 		mace_init_bus();
    221 		if (comcnattach(mace_isa_memt, MACE_BASE + base,
    222 		    speed, COM_FREQ, COM_TYPE_NORMAL, comcnmode) == 0)
    223 			return (1);
    224 	}
    225 #endif
    226 
    227 	return (0);
    228 }
    229 
    230 #if defined(KGDB)
    231 void
    232 kgdb_port_init(void)
    233 {
    234 # if (NCOM > 0)
    235 #  define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
    236 	if (mach_type == MACH_SGI_IP32) {
    237 		mace_init_bus();
    238 		com_kgdb_attach(mace_isa_memt, 0xbf398000, 9600, COM_FREQ, COM_TYPE_NORMAL,
    239 		    KGDB_DEVMODE);
    240 	}
    241 # endif	/* (NCOM > 0) */
    242 
    243 # if (NZSC > 0)
    244 	switch(mach_type) {
    245 	case MACH_SGI_IP12:
    246 	case MACH_SGI_IP20:
    247 	case MACH_SGI_IP22:
    248 		zs_kgdb_init();			/* XXX */
    249 	}
    250 # endif
    251 }
    252 #endif	/* KGDB */
    253