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 #include <stand.h>
28 #include <bootstrap.h>
29 #include <sys/param.h>
30 #include <btxv86.h>
31 #include <dev/dcons/dcons.h>
32
33 void fw_enable(void);
34 void fw_poll(void);
35
36 static void dconsole_probe(struct console *cp);
37 static int dconsole_init(int arg);
38 static void dconsole_putchar(int c);
39 static int dconsole_getchar(void);
40 static int dconsole_ischar(void);
41
42 static int dcons_started = 0;
43
44 #define DCONS_BUF_SIZE (64*1024)
45 static struct dcons_softc sc[DCONS_NPORT];
46 uint32_t dcons_paddr;
47
48 /* The buffer must be allocated in BSS because:
49 * - The dcons driver in the kernel is initialized before VM/pmap is
50 * initialized, so that the buffer must be allocate in the region
51 * that is mapped at the very early boot state.
52 * - We expect identiy map only for regions before KERNLOAD
53 * (i386:4MB amd64:1MB).
54 * - It seems that heap in conventional memory(640KB) is not sufficient
55 * and we move it to high address as LOADER_SUPPORT_BZIP2.
56 * - BSS is placed in conventional memory.
57 */
58 static char dcons_buffer[DCONS_BUF_SIZE + PAGE_SIZE];
59
60 struct console dconsole = {
61 "dcons",
62 "dumb console port",
63 0,
64 dconsole_probe,
65 dconsole_init,
66 dconsole_putchar,
67 dconsole_getchar,
68 dconsole_ischar
69 };
70
71 #define DCONSOLE_AS_MULTI_CONSOLE 1
72
73 static void
dconsole_probe(struct console * cp)74 dconsole_probe(struct console *cp)
75 {
76 /* XXX check the BIOS equipment list? */
77 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
78 #if DCONSOLE_AS_MULTI_CONSOLE
79 dconsole_init(0);
80 cp->c_flags |= (C_ACTIVEIN | C_ACTIVEOUT);
81 #endif
82 }
83
84 static int
dconsole_init(int arg)85 dconsole_init(int arg)
86 {
87 char buf[16], *dbuf;
88 int size;
89
90 if (dcons_started && arg == 0)
91 return 0;
92 dcons_started = 1;
93
94 size = DCONS_BUF_SIZE;
95 dbuf = (char *)round_page((vm_offset_t)&dcons_buffer[0]);
96 dcons_paddr = VTOP(dbuf);
97 sprintf(buf, "0x%08x", dcons_paddr);
98 setenv("dcons.addr", buf, 1);
99
100 dcons_init((struct dcons_buf *)dbuf, size, sc);
101 sprintf(buf, "%d", size);
102 setenv("dcons.size", buf, 1);
103 fw_enable();
104 return(0);
105 }
106
107 static void
dconsole_putchar(int c)108 dconsole_putchar(int c)
109 {
110 dcons_putc(&sc[0], c);
111 }
112
113 static int
dconsole_getchar(void)114 dconsole_getchar(void)
115 {
116 fw_poll();
117 return (dcons_checkc(&sc[0]));
118 }
119
120 static int
dconsole_ischar(void)121 dconsole_ischar(void)
122 {
123 fw_poll();
124 return (dcons_ischar(&sc[0]));
125 }
126