2 * Copyright (c) 2004 Hidetoshi Shimokawa
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
30 #include <bootstrap.h>
31 #include <sys/param.h>
33 #include <dev/dcons/dcons.h>
38 static void dconsole_probe(struct console *cp);
39 static int dconsole_init(int arg);
40 static void dconsole_putchar(int c);
41 static int dconsole_getchar(void);
42 static int dconsole_ischar(void);
44 static int dcons_started = 0;
46 #define DCONS_BUF_SIZE (64*1024)
47 static struct dcons_softc sc[DCONS_NPORT];
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 sufficent
57 * and we move it to high address as LOADER_SUPPORT_BZIP2.
58 * - BSS is placed in conventional memory.
60 static char dcons_buffer[DCONS_BUF_SIZE + PAGE_SIZE];
62 struct console dconsole = {
73 #define DCONSOLE_AS_MULTI_CONSOLE 1
76 dconsole_probe(struct console *cp)
78 /* XXX check the BIOS equipment list? */
79 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
80 #if DCONSOLE_AS_MULTI_CONSOLE
82 cp->c_flags |= (C_ACTIVEIN | C_ACTIVEOUT);
87 dconsole_init(int arg)
92 if (dcons_started && arg == 0)
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);
102 dcons_init((struct dcons_buf *)dbuf, size, sc);
103 sprintf(buf, "%d", size);
104 setenv("dcons.size", buf, 1);
110 dconsole_putchar(int c)
112 dcons_putc(&sc[0], c);
116 dconsole_getchar(void)
119 return (dcons_checkc(&sc[0]));
123 dconsole_ischar(void)
126 return (dcons_ischar(&sc[0]));