1 /*- 2 * Copyright (c) 2011 Google, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #include <sys/cdefs.h> 28 #include <stand.h> 29 #include <sys/font.h> 30 #include "bootstrap.h" 31 #include "libuserboot.h" 32 33 int console; 34 35 static struct console *userboot_comconsp; 36 37 static void userboot_cons_probe(struct console *cp); 38 static int userboot_cons_init(int); 39 static void userboot_comcons_probe(struct console *cp); 40 static int userboot_comcons_init(int); 41 static void userboot_cons_putchar(int); 42 static int userboot_cons_getchar(void); 43 static int userboot_cons_poll(void); 44 45 struct console userboot_console = { 46 "userboot", 47 "userboot", 48 0, 49 userboot_cons_probe, 50 userboot_cons_init, 51 userboot_cons_putchar, 52 userboot_cons_getchar, 53 userboot_cons_poll, 54 }; 55 56 /* 57 * Provide a simple alias to allow loader scripts to set the 58 * console to comconsole without resulting in an error 59 */ 60 struct console userboot_comconsole = { 61 "comconsole", 62 "comconsole", 63 0, 64 userboot_comcons_probe, 65 userboot_comcons_init, 66 userboot_cons_putchar, 67 userboot_cons_getchar, 68 userboot_cons_poll, 69 }; 70 71 static void 72 userboot_cons_probe(struct console *cp) 73 { 74 75 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT); 76 } 77 78 static int 79 userboot_cons_init(int arg) 80 { 81 82 return (0); 83 } 84 85 static void 86 userboot_comcons_probe(struct console *cp) 87 { 88 89 /* 90 * Save the console pointer so the comcons_init routine 91 * can set the C_PRESENT* flags. They are not set 92 * here to allow the existing userboot console to 93 * be elected the default. 94 */ 95 userboot_comconsp = cp; 96 } 97 98 static int 99 userboot_comcons_init(int arg) 100 { 101 102 /* 103 * Set the C_PRESENT* flags to allow the comconsole 104 * to be selected as the active console 105 */ 106 userboot_comconsp->c_flags |= (C_PRESENTIN | C_PRESENTOUT); 107 return (0); 108 } 109 110 static void 111 userboot_cons_putchar(int c) 112 { 113 114 CALLBACK(putc, c); 115 } 116 117 static int 118 userboot_cons_getchar() 119 { 120 121 return (CALLBACK(getc)); 122 } 123 124 static int 125 userboot_cons_poll() 126 { 127 128 return (CALLBACK(poll)); 129 } 130