Deleted Added
sdiff udiff text old ( 50477 ) new ( 56043 )
full compact
1/*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
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 as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/syscons/scvtb.c 56043 2000-01-15 15:25:43Z yokota $
27 */
28
29#include "sc.h"
30#include "opt_syscons.h"
31
32#if NSC > 0
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/malloc.h>
37
38#include <machine/console.h>
39#include <machine/md_var.h>
40
41#include <dev/fb/fbreg.h>
42#include <dev/syscons/syscons.h>
43
44#define vtb_wrap(vtb, at, offset) \
45 (((at) + (offset) + (vtb)->vtb_size)%(vtb)->vtb_size)
46
47void
48sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows, void *buf, int wait)
49{
50 vtb->vtb_flags = 0;
51 vtb->vtb_type = type;
52 vtb->vtb_cols = cols;
53 vtb->vtb_rows = rows;
54 vtb->vtb_size = cols*rows;
55 vtb->vtb_buffer = NULL;
56 vtb->vtb_tail = 0;
57
58 switch (type) {
59 case VTB_MEMORY:
60 case VTB_RINGBUFFER:
61 if ((buf == NULL) && (cols*rows != 0)) {
62 vtb->vtb_buffer =
63 (vm_offset_t)malloc(cols*rows*sizeof(u_int16_t),
64 M_DEVBUF,
65 (wait) ? M_WAITOK : M_NOWAIT);
66 if (vtb->vtb_buffer != NULL)
67 bzero((void *)sc_vtb_pointer(vtb, 0),
68 cols*rows*sizeof(u_int16_t));
69 } else {
70 vtb->vtb_buffer = (vm_offset_t)buf;
71 }
72 vtb->vtb_flags |= VTB_VALID;
73 break;
74 case VTB_FRAMEBUFFER:
75 vtb->vtb_buffer = (vm_offset_t)buf;
76 vtb->vtb_flags |= VTB_VALID;
77 break;
78 default:
79 break;
80 }
81}
82
83void
84sc_vtb_destroy(sc_vtb_t *vtb)
85{
86 vm_offset_t p;
87
88 vtb->vtb_flags = 0;
89 vtb->vtb_cols = 0;
90 vtb->vtb_rows = 0;
91 vtb->vtb_size = 0;
92 vtb->vtb_tail = 0;
93
94 p = vtb->vtb_buffer;
95 vtb->vtb_buffer = NULL;
96 switch (vtb->vtb_type) {
97 case VTB_MEMORY:
98 case VTB_RINGBUFFER:
99 if (p != NULL)
100 free((void *)p, M_DEVBUF);
101 break;
102 default:
103 break;
104 }
105 vtb->vtb_type = VTB_INVALID;
106}
107
108size_t
109sc_vtb_size(int cols, int rows)
110{
111 return (size_t)(cols*rows*sizeof(u_int16_t));
112}
113
114int
115sc_vtb_getc(sc_vtb_t *vtb, int at)
116{
117 if (vtb->vtb_type == VTB_FRAMEBUFFER)
118 return (readw(sc_vtb_pointer(vtb, at)) & 0x00ff);
119 else
120 return (*(u_int16_t *)sc_vtb_pointer(vtb, at) & 0x00ff);
121}
122
123int
124sc_vtb_geta(sc_vtb_t *vtb, int at)
125{
126 if (vtb->vtb_type == VTB_FRAMEBUFFER)
127 return (readw(sc_vtb_pointer(vtb, at)) & 0xff00);
128 else
129 return (*(u_int16_t *)sc_vtb_pointer(vtb, at) & 0xff00);
130}
131
132void
133sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a)
134{
135 if (vtb->vtb_type == VTB_FRAMEBUFFER)
136 writew(sc_vtb_pointer(vtb, at), a | c);
137 else
138 *(u_int16_t *)sc_vtb_pointer(vtb, at) = a | c;
139}
140
141vm_offset_t
142sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a)
143{
144 if (vtb->vtb_type == VTB_FRAMEBUFFER)
145 writew(p, a | c);
146 else
147 *(u_int16_t *)p = a | c;
148 return (p + sizeof(u_int16_t));
149}
150
151vm_offset_t
152sc_vtb_pointer(sc_vtb_t *vtb, int at)
153{
154 return (vtb->vtb_buffer + sizeof(u_int16_t)*(at));
155}
156
157int
158sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset)
159{
160 return ((pos + offset + vtb->vtb_size)%vtb->vtb_size);
161}
162
163void
164sc_vtb_clear(sc_vtb_t *vtb, int c, int attr)
165{
166 if (vtb->vtb_type == VTB_FRAMEBUFFER)
167 fillw_io(attr | c, sc_vtb_pointer(vtb, 0), vtb->vtb_size);
168 else
169 fillw(attr | c, (void *)sc_vtb_pointer(vtb, 0), vtb->vtb_size);
170}
171
172void
173sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to, int count)
174{
175 /* XXX if both are VTB_VRAMEBUFFER... */
176 if (vtb2->vtb_type == VTB_FRAMEBUFFER) {
177 bcopy_toio(sc_vtb_pointer(vtb1, from),
178 sc_vtb_pointer(vtb2, to),
179 count*sizeof(u_int16_t));
180 } else if (vtb1->vtb_type == VTB_FRAMEBUFFER) {
181 bcopy_fromio(sc_vtb_pointer(vtb1, from),
182 sc_vtb_pointer(vtb2, to),
183 count*sizeof(u_int16_t));
184 } else {
185 bcopy((void *)sc_vtb_pointer(vtb1, from),
186 (void *)sc_vtb_pointer(vtb2, to),
187 count*sizeof(u_int16_t));
188 }
189}
190
191void
192sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int count)
193{
194 int len;
195
196 if (vtb2->vtb_type != VTB_RINGBUFFER)
197 return;
198
199 while (count > 0) {
200 len = imin(count, vtb2->vtb_size - vtb2->vtb_tail);
201 if (vtb1->vtb_type == VTB_FRAMEBUFFER) {
202 bcopy_fromio(sc_vtb_pointer(vtb1, from),
203 sc_vtb_pointer(vtb2, vtb2->vtb_tail),
204 len*sizeof(u_int16_t));
205 } else {
206 bcopy((void *)sc_vtb_pointer(vtb1, from),
207 (void *)sc_vtb_pointer(vtb2, vtb2->vtb_tail),
208 len*sizeof(u_int16_t));
209 }
210 from += len;
211 count -= len;
212 vtb2->vtb_tail = vtb_wrap(vtb2, vtb2->vtb_tail, len);
213 }
214}
215
216void
217sc_vtb_seek(sc_vtb_t *vtb, int pos)
218{
219 vtb->vtb_tail = pos%vtb->vtb_size;
220}
221
222void
223sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr)
224{
225 if (at + count > vtb->vtb_size)
226 count = vtb->vtb_size - at;
227 if (vtb->vtb_type == VTB_FRAMEBUFFER)
228 fillw_io(attr | c, sc_vtb_pointer(vtb, at), count);
229 else
230 fillw(attr | c, (void *)sc_vtb_pointer(vtb, at), count);
231}
232
233void
234sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count)
235{
236 if (from + count > vtb->vtb_size)
237 count = vtb->vtb_size - from;
238 if (to + count > vtb->vtb_size)
239 count = vtb->vtb_size - to;
240 if (count <= 0)
241 return;
242 if (vtb->vtb_type == VTB_FRAMEBUFFER) {
243 bcopy_io(sc_vtb_pointer(vtb, from),
244 sc_vtb_pointer(vtb, to), count*sizeof(u_int16_t));
245 } else {
246 bcopy((void *)sc_vtb_pointer(vtb, from),
247 (void *)sc_vtb_pointer(vtb, to), count*sizeof(u_int16_t));
248 }
249}
250
251void
252sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr)
253{
254 int len;
255
256 if (at + count > vtb->vtb_size)
257 count = vtb->vtb_size - at;
258 len = vtb->vtb_size - at - count;
259 if (len > 0) {
260 if (vtb->vtb_type == VTB_FRAMEBUFFER) {
261 bcopy_io(sc_vtb_pointer(vtb, at + count),
262 sc_vtb_pointer(vtb, at),
263 len*sizeof(u_int16_t));
264 } else {
265 bcopy((void *)sc_vtb_pointer(vtb, at + count),
266 (void *)sc_vtb_pointer(vtb, at),
267 len*sizeof(u_int16_t));
268 }
269 }
270 if (vtb->vtb_type == VTB_FRAMEBUFFER)
271 fillw_io(attr | c, sc_vtb_pointer(vtb, at + len),
272 vtb->vtb_size - at - len);
273 else
274 fillw(attr | c, (void *)sc_vtb_pointer(vtb, at + len),
275 vtb->vtb_size - at - len);
276}
277
278void
279sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr)
280{
281 if (at + count > vtb->vtb_size) {
282 count = vtb->vtb_size - at;
283 } else {
284 if (vtb->vtb_type == VTB_FRAMEBUFFER) {
285 bcopy_io(sc_vtb_pointer(vtb, at),
286 sc_vtb_pointer(vtb, at + count),
287 (vtb->vtb_size - at - count)*sizeof(u_int16_t));
288 } else {
289 bcopy((void *)sc_vtb_pointer(vtb, at),
290 (void *)sc_vtb_pointer(vtb, at + count),
291 (vtb->vtb_size - at - count)*sizeof(u_int16_t));
292 }
293 }
294 if (vtb->vtb_type == VTB_FRAMEBUFFER)
295 fillw_io(attr | c, sc_vtb_pointer(vtb, at), count);
296 else
297 fillw(attr | c, (void *)sc_vtb_pointer(vtb, at), count);
298}
299
300#endif /* NSC */