1/*- 2 * Copyright (c) 2004 Hidetoshi Shimokawa 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h> 27__FBSDID("$FreeBSD: stable/11/stand/i386/libfirewire/dconsole.c 298826 2016-04-30 00:26:38Z pfg $"); 28 29#include <stand.h> 30#include <bootstrap.h> 31#include <sys/param.h> 32#include <btxv86.h> 33#include <dev/dcons/dcons.h> 34 35void fw_enable(void); 36void fw_poll(void); 37 38static void dconsole_probe(struct console *cp); 39static int dconsole_init(int arg); 40static void dconsole_putchar(int c); 41static int dconsole_getchar(void); 42static int dconsole_ischar(void); 43 44static int dcons_started = 0; 45 46#define DCONS_BUF_SIZE (64*1024) 47static struct dcons_softc sc[DCONS_NPORT]; 48uint32_t dcons_paddr; 49 50/* The buffer must be allocated in BSS becase: 51 * - The dcons driver in the kernel is initialized before VM/pmap is 52 * initialized, so that the buffer must be allocate in the region 53 * that is mapped at the very early boot state. 54 * - We expect identiy map only for regions before KERNLOAD 55 * (i386:4MB amd64:1MB). 56 * - It seems that heap in conventional memory(640KB) is not sufficient 57 * and we move it to high address as LOADER_SUPPORT_BZIP2. 58 * - BSS is placed in conventional memory. 59 */ 60static char dcons_buffer[DCONS_BUF_SIZE + PAGE_SIZE]; 61 62struct console dconsole = { 63 "dcons", 64 "dumb console port", 65 0, 66 dconsole_probe, 67 dconsole_init, 68 dconsole_putchar, 69 dconsole_getchar, 70 dconsole_ischar 71}; 72 73#define DCONSOLE_AS_MULTI_CONSOLE 1 74 75static void 76dconsole_probe(struct console *cp) 77{ 78 /* XXX check the BIOS equipment list? */ 79 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT); 80#if DCONSOLE_AS_MULTI_CONSOLE 81 dconsole_init(0); 82 cp->c_flags |= (C_ACTIVEIN | C_ACTIVEOUT); 83#endif 84} 85 86static int 87dconsole_init(int arg) 88{ 89 char buf[16], *dbuf; 90 int size; 91 92 if (dcons_started && arg == 0) 93 return 0; 94 dcons_started = 1; 95 96 size = DCONS_BUF_SIZE; 97 dbuf = (char *)round_page((vm_offset_t)&dcons_buffer[0]); 98 dcons_paddr = VTOP(dbuf); 99 sprintf(buf, "0x%08x", dcons_paddr); 100 setenv("dcons.addr", buf, 1); 101 102 dcons_init((struct dcons_buf *)dbuf, size, sc); 103 sprintf(buf, "%d", size); 104 setenv("dcons.size", buf, 1); 105 fw_enable(); 106 return(0); 107} 108 109static void 110dconsole_putchar(int c) 111{ 112 dcons_putc(&sc[0], c); 113} 114 115static int 116dconsole_getchar(void) 117{ 118 fw_poll(); 119 return (dcons_checkc(&sc[0])); 120} 121 122static int 123dconsole_ischar(void) 124{ 125 fw_poll(); 126 return (dcons_ischar(&sc[0])); 127} 128