]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/boot/i386/libfirewire/dconsole.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / boot / i386 / libfirewire / dconsole.c
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$");
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
35 void fw_enable(void);
36 void fw_poll(void);
37
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);
43
44 static int      dcons_started = 0;
45
46 #define DCONS_BUF_SIZE (64*1024)
47 static struct dcons_softc sc[DCONS_NPORT];
48 uint32_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 sufficent
57  *      and we move it to high address as LOADER_SUPPORT_BZIP2.
58  *    - BSS is placed in conventional memory.
59  */
60 static char dcons_buffer[DCONS_BUF_SIZE + PAGE_SIZE];
61
62 struct 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
75 static void
76 dconsole_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
86 static int
87 dconsole_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
109 static void
110 dconsole_putchar(int c)
111 {
112     dcons_putc(&sc[0], c);
113 }
114
115 static int
116 dconsole_getchar(void)
117 {
118     fw_poll();
119     return (dcons_checkc(&sc[0]));
120 }
121
122 static int
123 dconsole_ischar(void)
124 {
125     fw_poll();
126     return (dcons_ischar(&sc[0]));
127 }