Rev 3710 | Rev 3741 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3710 | Rev 3733 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Martin Decky |
2 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2006 Ondrej Palkovsky |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup genarch |
30 | /** @addtogroup genarch |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** @file |
33 | /** @file |
34 | */ |
34 | */ |
35 | 35 | ||
36 | #include <genarch/fb/font-8x16.h> |
36 | #include <genarch/fb/font-8x16.h> |
37 | #include <genarch/fb/logo-196x66.h> |
37 | #include <genarch/fb/logo-196x66.h> |
38 | #include <genarch/fb/visuals.h> |
38 | #include <genarch/fb/visuals.h> |
39 | #include <genarch/fb/fb.h> |
39 | #include <genarch/fb/fb.h> |
40 | #include <console/chardev.h> |
40 | #include <console/chardev.h> |
41 | #include <console/console.h> |
41 | #include <console/console.h> |
42 | #include <sysinfo/sysinfo.h> |
42 | #include <sysinfo/sysinfo.h> |
43 | #include <mm/slab.h> |
43 | #include <mm/slab.h> |
44 | #include <align.h> |
44 | #include <align.h> |
45 | #include <panic.h> |
45 | #include <panic.h> |
46 | #include <memstr.h> |
46 | #include <memstr.h> |
47 | #include <config.h> |
47 | #include <config.h> |
48 | #include <bitops.h> |
48 | #include <bitops.h> |
49 | #include <print.h> |
49 | #include <print.h> |
50 | #include <ddi/ddi.h> |
50 | #include <ddi/ddi.h> |
51 | #include <arch/types.h> |
51 | #include <arch/types.h> |
52 | 52 | ||
53 | SPINLOCK_INITIALIZE(fb_lock); |
53 | SPINLOCK_INITIALIZE(fb_lock); |
54 | 54 | ||
55 | /**< Physical memory area for fb. */ |
55 | /**< Physical memory area for fb. */ |
56 | static parea_t fb_parea; |
56 | static parea_t fb_parea; |
57 | 57 | ||
58 | static uint8_t *fb_addr; |
58 | static uint8_t *fb_addr; |
59 | static uint8_t *backbuf; |
59 | static uint8_t *backbuf; |
60 | static uint8_t *glyphs; |
60 | static uint8_t *glyphs; |
61 | static uint8_t *bgscan; |
61 | static uint8_t *bgscan; |
62 | 62 | ||
63 | static unsigned int xres; |
63 | static unsigned int xres; |
64 | static unsigned int yres; |
64 | static unsigned int yres; |
65 | 65 | ||
66 | static unsigned int ylogo; |
66 | static unsigned int ylogo; |
67 | static unsigned int ytrim; |
67 | static unsigned int ytrim; |
68 | static unsigned int rowtrim; |
68 | static unsigned int rowtrim; |
69 | 69 | ||
70 | static unsigned int scanline; |
70 | static unsigned int scanline; |
71 | static unsigned int glyphscanline; |
71 | static unsigned int glyphscanline; |
72 | 72 | ||
73 | static unsigned int pixelbytes; |
73 | static unsigned int pixelbytes; |
74 | static unsigned int glyphbytes; |
74 | static unsigned int glyphbytes; |
75 | static unsigned int bgscanbytes; |
75 | static unsigned int bgscanbytes; |
76 | 76 | ||
77 | static unsigned int cols; |
77 | static unsigned int cols; |
78 | static unsigned int rows; |
78 | static unsigned int rows; |
79 | static unsigned int position = 0; |
79 | static unsigned int position = 0; |
80 | 80 | ||
81 | #define BG_COLOR 0x000080 |
81 | #define BG_COLOR 0x000080 |
82 | #define FG_COLOR 0xffff00 |
82 | #define FG_COLOR 0xffff00 |
83 | 83 | ||
84 | #define CURSOR 219 |
84 | #define CURSOR 219 |
85 | 85 | ||
86 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
86 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
87 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
87 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
88 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
88 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
89 | 89 | ||
90 | #define COL2X(col) ((col) * FONT_WIDTH) |
90 | #define COL2X(col) ((col) * FONT_WIDTH) |
91 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
91 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
92 | 92 | ||
93 | #define X2COL(x) ((x) / FONT_WIDTH) |
93 | #define X2COL(x) ((x) / FONT_WIDTH) |
94 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
94 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
95 | 95 | ||
96 | #define FB_POS(x, y) ((y) * scanline + (x) * pixelbytes) |
96 | #define FB_POS(x, y) ((y) * scanline + (x) * pixelbytes) |
97 | #define BB_POS(col, row) ((row) * cols + (col)) |
97 | #define BB_POS(col, row) ((row) * cols + (col)) |
98 | #define GLYPH_POS(glyph, y) ((glyph) * glyphbytes + (y) * glyphscanline) |
98 | #define GLYPH_POS(glyph, y) ((glyph) * glyphbytes + (y) * glyphscanline) |
99 | 99 | ||
100 | 100 | ||
101 | static void (*rgb_conv)(void *, uint32_t); |
101 | static void (*rgb_conv)(void *, uint32_t); |
102 | 102 | ||
103 | 103 | ||
104 | /** ARGB 8:8:8:8 conversion |
104 | /** ARGB 8:8:8:8 conversion |
105 | * |
105 | * |
106 | */ |
106 | */ |
107 | static void rgb_0888(void *dst, uint32_t rgb) |
107 | static void rgb_0888(void *dst, uint32_t rgb) |
108 | { |
108 | { |
109 | *((uint32_t *) dst) = rgb & 0xffffff; |
109 | *((uint32_t *) dst) = rgb & 0xffffff; |
110 | } |
110 | } |
111 | 111 | ||
112 | 112 | ||
113 | /** ABGR 8:8:8:8 conversion |
113 | /** ABGR 8:8:8:8 conversion |
114 | * |
114 | * |
115 | */ |
115 | */ |
116 | static void bgr_0888(void *dst, uint32_t rgb) |
116 | static void bgr_0888(void *dst, uint32_t rgb) |
117 | { |
117 | { |
118 | *((uint32_t *) dst) |
118 | *((uint32_t *) dst) |
119 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
119 | = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8); |
120 | } |
120 | } |
121 | 121 | ||
122 | 122 | ||
123 | /** BGR 8:8:8 conversion |
123 | /** BGR 8:8:8 conversion |
124 | * |
124 | * |
125 | */ |
125 | */ |
126 | static void rgb_888(void *dst, uint32_t rgb) |
126 | static void rgb_888(void *dst, uint32_t rgb) |
127 | { |
127 | { |
128 | #if defined(FB_INVERT_ENDIAN) |
128 | #if defined(FB_INVERT_ENDIAN) |
129 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
129 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
130 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
130 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
131 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
131 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
132 | #else |
132 | #else |
133 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
133 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
134 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
134 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
135 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
135 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
136 | #endif |
136 | #endif |
137 | } |
137 | } |
138 | 138 | ||
139 | 139 | ||
140 | /** RGB 5:5:5 conversion |
140 | /** RGB 5:5:5 conversion |
141 | * |
141 | * |
142 | */ |
142 | */ |
143 | static void rgb_555(void *dst, uint32_t rgb) |
143 | static void rgb_555(void *dst, uint32_t rgb) |
144 | { |
144 | { |
145 | *((uint16_t *) dst) |
145 | *((uint16_t *) dst) |
146 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
146 | = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5); |
147 | } |
147 | } |
148 | 148 | ||
149 | 149 | ||
150 | /** RGB 5:6:5 conversion |
150 | /** RGB 5:6:5 conversion |
151 | * |
151 | * |
152 | */ |
152 | */ |
153 | static void rgb_565(void *dst, uint32_t rgb) |
153 | static void rgb_565(void *dst, uint32_t rgb) |
154 | { |
154 | { |
155 | *((uint16_t *) dst) |
155 | *((uint16_t *) dst) |
156 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
156 | = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5); |
157 | } |
157 | } |
158 | 158 | ||
159 | 159 | ||
160 | /** RGB 3:2:3 |
160 | /** RGB 3:2:3 |
161 | * |
161 | * |
162 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
162 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
163 | * will most likely use a color palette. The color appearance |
163 | * will most likely use a color palette. The color appearance |
164 | * will be pretty random and depend on the default installed |
164 | * will be pretty random and depend on the default installed |
165 | * palette. This could be fixed by supporting custom palette |
165 | * palette. This could be fixed by supporting custom palette |
166 | * and setting it to simulate the 8-bit truecolor. |
166 | * and setting it to simulate the 8-bit truecolor. |
167 | * |
167 | * |
168 | * Currently we set the palette on the ia32, amd64 and sparc64 port. |
168 | * Currently we set the palette on the ia32, amd64 and sparc64 port. |
169 | * |
169 | * |
170 | * Note that the byte is being inverted by this function. The reason is |
170 | * Note that the byte is being inverted by this function. The reason is |
171 | * that we would like to use a color palette where the white color code |
171 | * that we would like to use a color palette where the white color code |
172 | * is 0 and the black color code is 255, as some machines (Sun Blade 1500) |
172 | * is 0 and the black color code is 255, as some machines (Sun Blade 1500) |
173 | * use these codes for black and white and prevent to set codes |
173 | * use these codes for black and white and prevent to set codes |
174 | * 0 and 255 to other colors. |
174 | * 0 and 255 to other colors. |
175 | * |
175 | * |
176 | */ |
176 | */ |
177 | static void rgb_323(void *dst, uint32_t rgb) |
177 | static void rgb_323(void *dst, uint32_t rgb) |
178 | { |
178 | { |
179 | *((uint8_t *) dst) |
179 | *((uint8_t *) dst) |
180 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
180 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
181 | } |
181 | } |
182 | 182 | ||
183 | 183 | ||
184 | /** Hide logo and refresh screen |
184 | /** Hide logo and refresh screen |
185 | * |
185 | * |
186 | */ |
186 | */ |
187 | static void logo_hide(void) |
187 | static void logo_hide(void) |
188 | { |
188 | { |
189 | ylogo = 0; |
189 | ylogo = 0; |
190 | ytrim = yres; |
190 | ytrim = yres; |
191 | rowtrim = rows; |
191 | rowtrim = rows; |
192 | fb_redraw(); |
192 | fb_redraw(); |
193 | } |
193 | } |
194 | 194 | ||
195 | 195 | ||
196 | /** Draw character at given position |
196 | /** Draw character at given position |
197 | * |
197 | * |
198 | */ |
198 | */ |
199 | static void glyph_draw(uint8_t glyph, unsigned int col, unsigned int row) |
199 | static void glyph_draw(uint8_t glyph, unsigned int col, unsigned int row) |
200 | { |
200 | { |
201 | unsigned int x = COL2X(col); |
201 | unsigned int x = COL2X(col); |
202 | unsigned int y = ROW2Y(row); |
202 | unsigned int y = ROW2Y(row); |
203 | unsigned int yd; |
203 | unsigned int yd; |
204 | 204 | ||
205 | if (y >= ytrim) |
205 | if (y >= ytrim) |
206 | logo_hide(); |
206 | logo_hide(); |
207 | 207 | ||
208 | backbuf[BB_POS(col, row)] = glyph; |
208 | backbuf[BB_POS(col, row)] = glyph; |
209 | 209 | ||
210 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
210 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
211 | memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)], |
211 | memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)], |
212 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
212 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
213 | } |
213 | } |
214 | 214 | ||
215 | 215 | ||
216 | /** Scroll screen down by one row |
216 | /** Scroll screen down by one row |
217 | * |
217 | * |
218 | * |
218 | * |
219 | */ |
219 | */ |
220 | static void screen_scroll(void) |
220 | static void screen_scroll(void) |
221 | { |
221 | { |
222 | if (ylogo > 0) |
222 | if (ylogo > 0) { |
223 | logo_hide(); |
223 | logo_hide(); |
- | 224 | return; |
|
- | 225 | } |
|
224 | 226 | ||
225 | unsigned int row; |
227 | unsigned int row; |
226 | 228 | ||
227 | for (row = 0; row < rows; row++) { |
229 | for (row = 0; row < rows; row++) { |
228 | unsigned int y = ROW2Y(row); |
230 | unsigned int y = ROW2Y(row); |
229 | unsigned int yd; |
231 | unsigned int yd; |
230 | 232 | ||
231 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
233 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
232 | unsigned int x; |
234 | unsigned int x; |
233 | unsigned int col; |
235 | unsigned int col; |
234 | 236 | ||
235 | for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) { |
237 | for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) { |
236 | uint8_t glyph; |
238 | uint8_t glyph; |
237 | 239 | ||
238 | if (row < rows - 1) { |
240 | if (row < rows - 1) { |
239 | if (backbuf[BB_POS(col, row)] == backbuf[BB_POS(col, row + 1)]) |
241 | if (backbuf[BB_POS(col, row)] == backbuf[BB_POS(col, row + 1)]) |
240 | continue; |
242 | continue; |
241 | 243 | ||
242 | glyph = backbuf[BB_POS(col, row + 1)]; |
244 | glyph = backbuf[BB_POS(col, row + 1)]; |
243 | } else |
245 | } else |
244 | glyph = 0; |
246 | glyph = 0; |
245 | 247 | ||
246 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
248 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
247 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
249 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
248 | } |
250 | } |
249 | } |
251 | } |
250 | } |
252 | } |
251 | 253 | ||
252 | memcpy(backbuf, backbuf + cols, cols * (rows - 1)); |
254 | memcpy(backbuf, backbuf + cols, cols * (rows - 1)); |
253 | memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0); |
255 | memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0); |
254 | } |
256 | } |
255 | 257 | ||
256 | 258 | ||
257 | static void cursor_put(void) |
259 | static void cursor_put(void) |
258 | { |
260 | { |
259 | glyph_draw(CURSOR, position % cols, position / cols); |
261 | glyph_draw(CURSOR, position % cols, position / cols); |
260 | } |
262 | } |
261 | 263 | ||
262 | 264 | ||
263 | static void cursor_remove(void) |
265 | static void cursor_remove(void) |
264 | { |
266 | { |
265 | glyph_draw(0, position % cols, position / cols); |
267 | glyph_draw(0, position % cols, position / cols); |
266 | } |
268 | } |
267 | 269 | ||
268 | 270 | ||
269 | /** Print character to screen |
271 | /** Print character to screen |
270 | * |
272 | * |
271 | * Emulate basic terminal commands. |
273 | * Emulate basic terminal commands. |
272 | * |
274 | * |
273 | */ |
275 | */ |
274 | static void fb_putchar(chardev_t *dev, char ch) |
276 | static void fb_putchar(chardev_t *dev, char ch) |
275 | { |
277 | { |
276 | spinlock_lock(&fb_lock); |
278 | spinlock_lock(&fb_lock); |
277 | 279 | ||
278 | switch (ch) { |
280 | switch (ch) { |
279 | case '\n': |
281 | case '\n': |
280 | cursor_remove(); |
282 | cursor_remove(); |
281 | position += cols; |
283 | position += cols; |
282 | position -= position % cols; |
284 | position -= position % cols; |
283 | break; |
285 | break; |
284 | case '\r': |
286 | case '\r': |
285 | cursor_remove(); |
287 | cursor_remove(); |
286 | position -= position % cols; |
288 | position -= position % cols; |
287 | break; |
289 | break; |
288 | case '\b': |
290 | case '\b': |
289 | cursor_remove(); |
291 | cursor_remove(); |
290 | if (position % cols) |
292 | if (position % cols) |
291 | position--; |
293 | position--; |
292 | break; |
294 | break; |
293 | case '\t': |
295 | case '\t': |
294 | cursor_remove(); |
296 | cursor_remove(); |
295 | do { |
297 | do { |
296 | glyph_draw((uint8_t) ' ', position % cols, position / cols); |
298 | glyph_draw((uint8_t) ' ', position % cols, position / cols); |
297 | position++; |
299 | position++; |
298 | } while ((position % 8) && (position < cols * rows)); |
300 | } while ((position % 8) && (position < cols * rows)); |
299 | break; |
301 | break; |
300 | default: |
302 | default: |
301 | glyph_draw((uint8_t) ch, position % cols, position / cols); |
303 | glyph_draw((uint8_t) ch, position % cols, position / cols); |
302 | position++; |
304 | position++; |
303 | } |
305 | } |
304 | 306 | ||
305 | if (position >= cols * rows) { |
307 | if (position >= cols * rows) { |
306 | position -= cols; |
308 | position -= cols; |
307 | screen_scroll(); |
309 | screen_scroll(); |
308 | } |
310 | } |
309 | 311 | ||
310 | cursor_put(); |
312 | cursor_put(); |
311 | 313 | ||
312 | spinlock_unlock(&fb_lock); |
314 | spinlock_unlock(&fb_lock); |
313 | } |
315 | } |
314 | 316 | ||
315 | static chardev_t framebuffer; |
317 | static chardev_t framebuffer; |
316 | static chardev_operations_t fb_ops = { |
318 | static chardev_operations_t fb_ops = { |
317 | .write = fb_putchar, |
319 | .write = fb_putchar, |
318 | }; |
320 | }; |
319 | 321 | ||
320 | 322 | ||
321 | /** Render glyphs |
323 | /** Render glyphs |
322 | * |
324 | * |
323 | * Convert glyphs from device independent font |
325 | * Convert glyphs from device independent font |
324 | * description to current visual representation. |
326 | * description to current visual representation. |
325 | * |
327 | * |
326 | */ |
328 | */ |
327 | static void glyphs_render(void) |
329 | static void glyphs_render(void) |
328 | { |
330 | { |
329 | /* Prerender glyphs */ |
331 | /* Prerender glyphs */ |
330 | unsigned int glyph; |
332 | unsigned int glyph; |
331 | 333 | ||
332 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
334 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
333 | unsigned int y; |
335 | unsigned int y; |
334 | 336 | ||
335 | for (y = 0; y < FONT_SCANLINES; y++) { |
337 | for (y = 0; y < FONT_SCANLINES; y++) { |
336 | unsigned int x; |
338 | unsigned int x; |
337 | 339 | ||
338 | for (x = 0; x < FONT_WIDTH; x++) |
340 | for (x = 0; x < FONT_WIDTH; x++) |
339 | rgb_conv(&glyphs[GLYPH_POS(glyph, y) + x * pixelbytes], |
341 | rgb_conv(&glyphs[GLYPH_POS(glyph, y) + x * pixelbytes], |
340 | (fb_font[ROW2Y(glyph) + y] & (1 << (7 - x))) ? FG_COLOR : BG_COLOR); |
342 | (fb_font[ROW2Y(glyph) + y] & (1 << (7 - x))) ? FG_COLOR : BG_COLOR); |
341 | } |
343 | } |
342 | } |
344 | } |
343 | 345 | ||
344 | /* Prerender background scanline */ |
346 | /* Prerender background scanline */ |
345 | unsigned int x; |
347 | unsigned int x; |
346 | 348 | ||
347 | for (x = 0; x < xres; x++) |
349 | for (x = 0; x < xres; x++) |
348 | rgb_conv(&bgscan[x * pixelbytes], BG_COLOR); |
350 | rgb_conv(&bgscan[x * pixelbytes], BG_COLOR); |
349 | } |
351 | } |
350 | 352 | ||
351 | 353 | ||
352 | /** Refresh the screen |
354 | /** Refresh the screen |
353 | * |
355 | * |
354 | */ |
356 | */ |
355 | void fb_redraw(void) |
357 | void fb_redraw(void) |
356 | { |
358 | { |
357 | if (ylogo > 0) { |
359 | if (ylogo > 0) { |
358 | unsigned int y; |
360 | unsigned int y; |
359 | 361 | ||
360 | for (y = 0; y < LOGO_HEIGHT; y++) { |
362 | for (y = 0; y < LOGO_HEIGHT; y++) { |
361 | unsigned int x; |
363 | unsigned int x; |
362 | 364 | ||
363 | for (x = 0; x < xres; x++) |
365 | for (x = 0; x < xres; x++) |
364 | rgb_conv(&fb_addr[FB_POS(x, y)], |
366 | rgb_conv(&fb_addr[FB_POS(x, y)], |
365 | (x < LOGO_WIDTH) ? fb_logo[y * LOGO_WIDTH + x] : LOGO_COLOR); |
367 | (x < LOGO_WIDTH) ? fb_logo[y * LOGO_WIDTH + x] : LOGO_COLOR); |
366 | } |
368 | } |
367 | } |
369 | } |
368 | 370 | ||
369 | unsigned int row; |
371 | unsigned int row; |
370 | 372 | ||
371 | for (row = 0; row < rowtrim; row++) { |
373 | for (row = 0; row < rowtrim; row++) { |
372 | unsigned int y = ylogo + ROW2Y(row); |
374 | unsigned int y = ylogo + ROW2Y(row); |
373 | unsigned int yd; |
375 | unsigned int yd; |
374 | 376 | ||
375 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
377 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
376 | unsigned int x; |
378 | unsigned int x; |
377 | unsigned int col; |
379 | unsigned int col; |
378 | 380 | ||
379 | for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) |
381 | for (col = 0, x = 0; col < cols; col++, x += FONT_WIDTH) |
380 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
382 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
381 | &glyphs[GLYPH_POS(backbuf[BB_POS(col, row)], yd)], |
383 | &glyphs[GLYPH_POS(backbuf[BB_POS(col, row)], yd)], |
382 | glyphscanline); |
384 | glyphscanline); |
383 | } |
385 | } |
384 | } |
386 | } |
385 | 387 | ||
386 | if (COL2X(cols) < xres) { |
388 | if (COL2X(cols) < xres) { |
387 | unsigned int y; |
389 | unsigned int y; |
388 | unsigned int size = (xres - COL2X(cols)) * pixelbytes; |
390 | unsigned int size = (xres - COL2X(cols)) * pixelbytes; |
389 | 391 | ||
390 | for (y = ylogo; y < yres; y++) |
392 | for (y = ylogo; y < yres; y++) |
391 | memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size); |
393 | memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size); |
392 | } |
394 | } |
393 | 395 | ||
394 | if (ROW2Y(rowtrim) < yres) { |
396 | if (ROW2Y(rowtrim) + ylogo < yres) { |
395 | unsigned int y; |
397 | unsigned int y; |
396 | 398 | ||
397 | for (y = ROW2Y(rowtrim); y < yres; y++) |
399 | for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++) |
398 | memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes); |
400 | memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes); |
399 | } |
401 | } |
400 | } |
402 | } |
401 | 403 | ||
402 | 404 | ||
403 | /** Initialize framebuffer as a chardev output device |
405 | /** Initialize framebuffer as a chardev output device |
404 | * |
406 | * |
405 | * @param addr Physical address of the framebuffer |
407 | * @param addr Physical address of the framebuffer |
406 | * @param x Screen width in pixels |
408 | * @param x Screen width in pixels |
407 | * @param y Screen height in pixels |
409 | * @param y Screen height in pixels |
408 | * @param scan Bytes per one scanline |
410 | * @param scan Bytes per one scanline |
409 | * @param visual Color model |
411 | * @param visual Color model |
410 | * |
412 | * |
411 | */ |
413 | */ |
412 | void fb_init(fb_properties_t *props) |
414 | void fb_init(fb_properties_t *props) |
413 | { |
415 | { |
414 | switch (props->visual) { |
416 | switch (props->visual) { |
415 | case VISUAL_INDIRECT_8: |
417 | case VISUAL_INDIRECT_8: |
416 | rgb_conv = rgb_323; |
418 | rgb_conv = rgb_323; |
417 | pixelbytes = 1; |
419 | pixelbytes = 1; |
418 | break; |
420 | break; |
419 | case VISUAL_RGB_5_5_5: |
421 | case VISUAL_RGB_5_5_5: |
420 | rgb_conv = rgb_555; |
422 | rgb_conv = rgb_555; |
421 | pixelbytes = 2; |
423 | pixelbytes = 2; |
422 | break; |
424 | break; |
423 | case VISUAL_RGB_5_6_5: |
425 | case VISUAL_RGB_5_6_5: |
424 | rgb_conv = rgb_565; |
426 | rgb_conv = rgb_565; |
425 | pixelbytes = 2; |
427 | pixelbytes = 2; |
426 | break; |
428 | break; |
427 | case VISUAL_RGB_8_8_8: |
429 | case VISUAL_RGB_8_8_8: |
428 | rgb_conv = rgb_888; |
430 | rgb_conv = rgb_888; |
429 | pixelbytes = 3; |
431 | pixelbytes = 3; |
430 | break; |
432 | break; |
431 | case VISUAL_RGB_8_8_8_0: |
433 | case VISUAL_RGB_8_8_8_0: |
432 | rgb_conv = rgb_888; |
434 | rgb_conv = rgb_888; |
433 | pixelbytes = 4; |
435 | pixelbytes = 4; |
434 | break; |
436 | break; |
435 | case VISUAL_RGB_0_8_8_8: |
437 | case VISUAL_RGB_0_8_8_8: |
436 | rgb_conv = rgb_0888; |
438 | rgb_conv = rgb_0888; |
437 | pixelbytes = 4; |
439 | pixelbytes = 4; |
438 | break; |
440 | break; |
439 | case VISUAL_BGR_0_8_8_8: |
441 | case VISUAL_BGR_0_8_8_8: |
440 | rgb_conv = bgr_0888; |
442 | rgb_conv = bgr_0888; |
441 | pixelbytes = 4; |
443 | pixelbytes = 4; |
442 | break; |
444 | break; |
443 | default: |
445 | default: |
444 | panic("Unsupported visual.\n"); |
446 | panic("Unsupported visual.\n"); |
445 | } |
447 | } |
446 | 448 | ||
447 | xres = props->x; |
449 | xres = props->x; |
448 | yres = props->y; |
450 | yres = props->y; |
449 | scanline = props->scan; |
451 | scanline = props->scan; |
450 | 452 | ||
451 | cols = X2COL(xres); |
453 | cols = X2COL(xres); |
452 | rows = Y2ROW(yres); |
454 | rows = Y2ROW(yres); |
453 | 455 | ||
454 | if (yres > ylogo) { |
456 | if (yres > ylogo) { |
455 | ylogo = LOGO_HEIGHT; |
457 | ylogo = LOGO_HEIGHT; |
456 | rowtrim = rows - Y2ROW(ylogo); |
458 | rowtrim = rows - Y2ROW(ylogo); |
457 | if (ylogo % FONT_SCANLINES > 0) |
459 | if (ylogo % FONT_SCANLINES > 0) |
458 | rowtrim--; |
460 | rowtrim--; |
459 | ytrim = ROW2Y(rowtrim); |
461 | ytrim = ROW2Y(rowtrim); |
460 | } else { |
462 | } else { |
461 | ylogo = 0; |
463 | ylogo = 0; |
462 | ytrim = yres; |
464 | ytrim = yres; |
463 | rowtrim = rows; |
465 | rowtrim = rows; |
464 | } |
466 | } |
465 | 467 | ||
466 | glyphscanline = FONT_WIDTH * pixelbytes; |
468 | glyphscanline = FONT_WIDTH * pixelbytes; |
467 | glyphbytes = ROW2Y(glyphscanline); |
469 | glyphbytes = ROW2Y(glyphscanline); |
468 | bgscanbytes = xres * pixelbytes; |
470 | bgscanbytes = xres * pixelbytes; |
469 | 471 | ||
470 | unsigned int fbsize = scanline * yres; |
472 | unsigned int fbsize = scanline * yres; |
471 | unsigned int bbsize = cols * rows; |
473 | unsigned int bbsize = cols * rows; |
472 | unsigned int glyphsize = FONT_GLYPHS * glyphbytes; |
474 | unsigned int glyphsize = FONT_GLYPHS * glyphbytes; |
473 | 475 | ||
474 | backbuf = (uint8_t *) malloc(bbsize, 0); |
476 | backbuf = (uint8_t *) malloc(bbsize, 0); |
475 | if (!backbuf) |
477 | if (!backbuf) |
476 | panic("Unable to allocate backbuffer.\n"); |
478 | panic("Unable to allocate backbuffer.\n"); |
477 | 479 | ||
478 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
480 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
479 | if (!glyphs) |
481 | if (!glyphs) |
480 | panic("Unable to allocate glyphs.\n"); |
482 | panic("Unable to allocate glyphs.\n"); |
481 | 483 | ||
482 | bgscan = malloc(bgscanbytes, 0); |
484 | bgscan = malloc(bgscanbytes, 0); |
483 | if (!bgscan) |
485 | if (!bgscan) |
484 | panic("Unable to allocate background pixel.\n"); |
486 | panic("Unable to allocate background pixel.\n"); |
485 | 487 | ||
486 | memsetb(backbuf, bbsize, 0); |
488 | memsetb(backbuf, bbsize, 0); |
487 | 489 | ||
488 | glyphs_render(); |
490 | glyphs_render(); |
489 | 491 | ||
490 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
492 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
491 | 493 | ||
492 | fb_parea.pbase = (uintptr_t) props->addr + props->offset; |
494 | fb_parea.pbase = (uintptr_t) props->addr + props->offset; |
493 | fb_parea.vbase = (uintptr_t) fb_addr; |
495 | fb_parea.vbase = (uintptr_t) fb_addr; |
494 | fb_parea.frames = SIZE2FRAMES(fbsize); |
496 | fb_parea.frames = SIZE2FRAMES(fbsize); |
495 | fb_parea.cacheable = false; |
497 | fb_parea.cacheable = false; |
496 | ddi_parea_register(&fb_parea); |
498 | ddi_parea_register(&fb_parea); |
497 | 499 | ||
498 | sysinfo_set_item_val("fb", NULL, true); |
500 | sysinfo_set_item_val("fb", NULL, true); |
499 | sysinfo_set_item_val("fb.kind", NULL, 1); |
501 | sysinfo_set_item_val("fb.kind", NULL, 1); |
500 | sysinfo_set_item_val("fb.width", NULL, xres); |
502 | sysinfo_set_item_val("fb.width", NULL, xres); |
501 | sysinfo_set_item_val("fb.height", NULL, yres); |
503 | sysinfo_set_item_val("fb.height", NULL, yres); |
502 | sysinfo_set_item_val("fb.scanline", NULL, scanline); |
504 | sysinfo_set_item_val("fb.scanline", NULL, scanline); |
503 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
505 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
504 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
506 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
505 | 507 | ||
506 | fb_redraw(); |
508 | fb_redraw(); |
507 | 509 | ||
508 | chardev_initialize("fb", &framebuffer, &fb_ops); |
510 | chardev_initialize("fb", &framebuffer, &fb_ops); |
509 | stdout = &framebuffer; |
511 | stdout = &framebuffer; |
510 | } |
512 | } |
511 | 513 | ||
512 | /** @} |
514 | /** @} |
513 | */ |
515 | */ |
514 | 516 |