1 /* $OpenBSD: wscons_machdep.c,v 1.19 2016/03/07 05:32:47 naddy Exp $ */ 2 3 /* 4 * Copyright (c) 2001 Aaron Campbell 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 * THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/param.h> 30 #include <sys/systm.h> 31 #include <sys/kernel.h> 32 #include <sys/conf.h> 33 #include <sys/device.h> 34 #include <sys/extent.h> 35 36 #include <machine/bus.h> 37 38 #include <dev/cons.h> 39 40 #include "vga.h" 41 #include "pcdisplay.h" 42 #if (NVGA > 0) || (NPCDISPLAY > 0) 43 #include <dev/ic/mc6845reg.h> 44 #include <dev/ic/pcdisplayvar.h> 45 #if (NVGA > 0) 46 #include <dev/ic/vgareg.h> 47 #include <dev/ic/vgavar.h> 48 #endif 49 #if (NPCDISPLAY > 0) 50 #include <dev/isa/pcdisplayvar.h> 51 #endif 52 #endif 53 54 #include "wsdisplay.h" 55 #if NWSDISPLAY > 0 56 #include <dev/wscons/wsdisplayvar.h> 57 #endif 58 59 #include "pckbc.h" 60 #if (NPCKBC > 0) 61 #include <dev/isa/isareg.h> 62 #include <dev/ic/i8042reg.h> 63 #include <dev/ic/pckbcvar.h> 64 #endif 65 #include "pckbd.h" 66 #include "ukbd.h" 67 #if (NUKBD > 0) 68 #include <dev/usb/ukbdvar.h> 69 #endif 70 #include "wskbd.h" 71 #if NWSKBD > 0 72 #include <dev/wscons/wskbdvar.h> 73 #endif 74 75 void wscn_video_init(void); 76 void wscn_input_init(int); 77 78 cons_decl(ws); 79 80 void 81 wscnprobe(struct consdev *cp) 82 { 83 int maj; 84 85 /* locate the major number */ 86 for (maj = 0; maj < nchrdev; maj++) { 87 if (cdevsw[maj].d_open == wsdisplayopen) 88 break; 89 } 90 91 if (maj == nchrdev) { 92 /* we are not in cdevsw[], give up */ 93 panic("wsdisplay is not in cdevsw[]"); 94 } 95 96 cp->cn_dev = makedev(maj, 0); 97 cp->cn_pri = CN_MIDPRI; 98 } 99 100 void 101 wscninit(struct consdev *cp) 102 { 103 static int initted = 0; 104 105 if (initted) 106 return; 107 initted = 1; 108 109 wscn_video_init(); 110 wscn_input_init(0); 111 } 112 113 void 114 wscnputc(dev_t dev, int i) 115 { 116 wsdisplay_cnputc(dev, i); 117 } 118 119 int 120 wscngetc(dev_t dev) 121 { 122 return (wskbd_cngetc(dev)); 123 } 124 125 void 126 wscnpollc(dev_t dev, int on) 127 { 128 wskbd_cnpollc(dev, on); 129 } 130 131 /* 132 * Configure the display part of the console. 133 */ 134 void 135 wscn_video_init(void) 136 { 137 #if (NVGA > 0) 138 if (vga_cnattach(I386_BUS_SPACE_IO, I386_BUS_SPACE_MEM, -1, 1) == 0) 139 return; 140 #endif 141 #if (NPCDISPLAY > 0) 142 if (pcdisplay_cnattach(I386_BUS_SPACE_IO, I386_BUS_SPACE_MEM) == 0) 143 return; 144 #endif 145 } 146 147 /* 148 * Configure the keyboard part of the console. 149 * This is tricky, because of the games USB controllers play. 150 * 151 * On a truly legacy-free design, no PS/2 keyboard controller will be 152 * found, so we'll settle for the first USB keyboard as the console 153 * input device. 154 * 155 * Otherwise, the PS/2 controller will claim console, even if no PS/2 156 * keyboard is plugged into it. This is intentional, so that a PS/2 157 * keyboard can be plugged late (even though this is theoretically not 158 * allowed, most PS/2 controllers survive this). 159 * 160 * However, if there isn't any PS/2 keyboard connector, but an USB 161 * controller in Legacy mode, the kernel will detect a PS/2 keyboard 162 * connected (while there really isn't any), until the USB controller 163 * driver attaches. At that point the ghost of the legacy keyboard 164 * flees away. 165 * 166 * The pckbc(4) driver will, however, detect that the keyboard is gone 167 * missing, and will invoke this function again, allowing a new console 168 * input device choice. 169 */ 170 void 171 wscn_input_init(int pass) 172 { 173 if (pass != 0) { 174 #if NWSKBD > 0 175 wskbd_cndetach(); 176 #endif 177 } 178 179 #if (NPCKBC > 0) 180 if (pass == 0 && 181 pckbc_cnattach(I386_BUS_SPACE_IO, IO_KBD, KBCMDP, 0) == 0) 182 return; 183 #endif 184 #if (NUKBD > 0) 185 if (ukbd_cnattach() == 0) 186 return; 187 #endif 188 } 189