1 /* $NetBSD: video_subr.c,v 1.11 2008/04/28 20:23:48 martin Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: video_subr.c,v 1.11 2008/04/28 20:23:48 martin Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/malloc.h>
39 #include <machine/bootinfo.h>
41 #include <dev/hpc/video_subr.h>
45 bitmap = *(volatile u_int8_t*)addr; \
46 *(volatile u_int8_t*)addr = \
47 (bitmap & ~(0x3 << ((3 - (x % 4)) * 2))); \
52 bitmap = *(volatile u_int8_t*)addr; \
53 *(volatile u_int8_t*)addr = \
54 (bitmap & ~(0xf << ((1 - (x % 2)) * 4))); \
58 *(volatile u_int8_t*)addr = 0xff; \
61 #define BRESENHAM(a, b, c, d, func) ({ \
62 u_int32_t fbaddr = vc->vc_fbvaddr; \
63 u_int32_t fbwidth = vc->vc_fbwidth; \
64 u_int32_t fbdepth = vc->vc_fbdepth; \
65 len = a, step = b -1; \
68 kstep = len == 0 ? 0 : 1; \
69 for (i = k = 0, j = step / 2; i <= step; i++) { \
72 addr = fbaddr + (((y * fbwidth + x) * fbdepth) >> 3); \
82 #define DRAWLINE(func) ({ \
86 BRESENHAM(_y, _x, -i, -k, func); \
88 BRESENHAM(_x, _y, -k, -i, func); \
92 BRESENHAM(_y, _x, -i, +k, func); \
94 BRESENHAM(_x, _y, -k, +i, func); \
100 BRESENHAM(_y, _x, +i, -k, func); \
102 BRESENHAM(_x, _y, +k, -i, func); \
106 BRESENHAM(_y, _x, +i, +k, func); \
108 BRESENHAM(_x, _y, +k, +i, func); \
114 #define LINEFUNC(b) \
115 static void linebpp##b (struct video_chip *, int, int, int, int); \
117 linebpp##b(vc, x0, y0, x1, y1) \
118 struct video_chip *vc; \
119 int x0, y0, x1, y1; \
122 int i, j, k, len, step, kstep; \
135 static void dotbpp##b (struct video_chip *, int, int); \
137 dotbpp##b(vc, x, y) \
138 struct video_chip *vc; \
142 addr = vc->vc_fbvaddr + (((y * vc->vc_fbwidth + x) * \
143 vc->vc_fbdepth) >> 3); \
153 static void linebpp_unimpl(struct video_chip
*, int, int, int, int);
154 static void dotbpp_unimpl(struct video_chip
*, int, int);
157 cmap_work_alloc(u_int8_t
**r
, u_int8_t
**g
, u_int8_t
**b
, u_int32_t
**rgb
,
160 KASSERT(LEGAL_CLUT_INDEX(cnt
- 1));
162 #define ALLOC_BUF(x, bit) \
164 *x = malloc(cnt * sizeof(u_int ## bit ## _t), \
165 M_DEVBUF, M_WAITOK); \
177 cmap_work_free(*r
, *g
, *b
, *rgb
);
183 cmap_work_free(u_int8_t
*r
, u_int8_t
*g
, u_int8_t
*b
, u_int32_t
*rgb
)
196 rgb24_compose(u_int32_t
*rgb24
, u_int8_t
*r
, u_int8_t
*g
, u_int8_t
*b
, int cnt
)
199 KASSERT(rgb24
&& r
&& g
&& b
&& LEGAL_CLUT_INDEX(cnt
- 1));
201 for (i
= 0; i
< cnt
; i
++) {
202 *rgb24
++ = RGB24(r
[i
], g
[i
], b
[i
]);
207 rgb24_decompose(u_int32_t
*rgb24
, u_int8_t
*r
, u_int8_t
*g
, u_int8_t
*b
,
211 KASSERT(rgb24
&& r
&& g
&& b
&& LEGAL_CLUT_INDEX(cnt
- 1));
213 for (i
= 0; i
< cnt
; i
++) {
214 u_int32_t rgb
= *rgb24
++;
215 *r
++ = (rgb
>> 16) & 0xff;
216 *g
++ = (rgb
>> 8) & 0xff;
225 video_calibration_pattern(struct video_chip
*vc
)
229 x
= vc
->vc_fbwidth
- 40;
230 y
= vc
->vc_fbheight
- 40;
231 video_line(vc
, 40, 40, x
, 40);
232 video_line(vc
, x
, 40, x
, y
);
233 video_line(vc
, x
, y
, 40, y
);
234 video_line(vc
, 40, y
, 40, 40);
235 video_line(vc
, 40, 40, x
, y
);
236 video_line(vc
, x
, 40, 40, y
);
240 linebpp_unimpl(struct video_chip
*vc
,
249 dotbpp_unimpl(struct video_chip
*vc
, int x
, int y
)
256 video_attach_drawfunc(struct video_chip
*vc
)
258 switch (vc
->vc_fbdepth
) {
260 vc
->vc_drawline
= linebpp_unimpl
;
261 vc
->vc_drawdot
= dotbpp_unimpl
;
264 vc
->vc_drawline
= linebpp8
;
265 vc
->vc_drawdot
= dotbpp8
;
268 vc
->vc_drawline
= linebpp4
;
269 vc
->vc_drawdot
= dotbpp4
;
272 vc
->vc_drawline
= linebpp2
;
273 vc
->vc_drawdot
= dotbpp2
;
279 video_line(struct video_chip
*vc
, int x0
, int y0
, int x1
, int y1
)
282 vc
->vc_drawline(vc
, x0
, y0
, x1
, y1
);
286 video_dot(struct video_chip
*vc
, int x
, int y
)
289 vc
->vc_drawdot(vc
, x
, y
);
293 video_reverse_color(void)
298 { BIFB_D2_M2L_3
, BIFB_D2_M2L_0
},
299 { BIFB_D2_M2L_3x2
, BIFB_D2_M2L_0x2
},
300 { BIFB_D8_FF
, BIFB_D8_00
},
301 { BIFB_D16_FFFF
, BIFB_D16_0000
, },
302 { -1, -1 } /* terminator */
306 /* check reverse color */
307 fbtype
= bootinfo
->fb_type
;
308 for (ctypep
= ctype
; ctypep
->normal
!= -1 ; ctypep
++) {
309 if (fbtype
== ctypep
->normal
) {
311 } else if (fbtype
== ctypep
->reverse
) {
315 printf(": WARNING unknown frame buffer type 0x%04x.\n", fbtype
);