| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: wsdisplay_vcons.c,v 1.34 2015/07/19 13:22:42 mlelstv Exp $ */ | | 1 | /* $NetBSD: wsdisplay_vcons.c,v 1.35 2015/11/08 16:49:20 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2005, 2006 Michael Lorenz | | 4 | * Copyright (c) 2005, 2006 Michael Lorenz |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. 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 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. 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. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.34 2015/07/19 13:22:42 mlelstv Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: wsdisplay_vcons.c,v 1.35 2015/11/08 16:49:20 christos Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/systm.h> | | 33 | #include <sys/systm.h> |
34 | #include <sys/kernel.h> | | 34 | #include <sys/kernel.h> |
35 | #include <sys/buf.h> | | 35 | #include <sys/buf.h> |
36 | #include <sys/device.h> | | 36 | #include <sys/device.h> |
37 | #include <sys/ioctl.h> | | 37 | #include <sys/ioctl.h> |
38 | #include <sys/malloc.h> | | 38 | #include <sys/malloc.h> |
39 | #include <sys/mman.h> | | 39 | #include <sys/mman.h> |
40 | #include <sys/tty.h> | | 40 | #include <sys/tty.h> |
41 | #include <sys/conf.h> | | 41 | #include <sys/conf.h> |
42 | #include <sys/proc.h> | | 42 | #include <sys/proc.h> |
43 | #include <sys/kthread.h> | | 43 | #include <sys/kthread.h> |
| @@ -275,35 +275,41 @@ vcons_init_screen(struct vcons_data *vd, | | | @@ -275,35 +275,41 @@ vcons_init_screen(struct vcons_data *vd, |
275 | * we allocate both chars and attributes in one chunk, attributes first | | 275 | * we allocate both chars and attributes in one chunk, attributes first |
276 | * because they have the (potentially) bigger alignment | | 276 | * because they have the (potentially) bigger alignment |
277 | */ | | 277 | */ |
278 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 278 | #ifdef WSDISPLAY_SCROLLSUPPORT |
279 | cnt = (ri->ri_rows + WSDISPLAY_SCROLLBACK_LINES) * ri->ri_cols; | | 279 | cnt = (ri->ri_rows + WSDISPLAY_SCROLLBACK_LINES) * ri->ri_cols; |
280 | scr->scr_lines_in_buffer = WSDISPLAY_SCROLLBACK_LINES; | | 280 | scr->scr_lines_in_buffer = WSDISPLAY_SCROLLBACK_LINES; |
281 | scr->scr_current_line = 0; | | 281 | scr->scr_current_line = 0; |
282 | scr->scr_line_wanted = 0; | | 282 | scr->scr_line_wanted = 0; |
283 | scr->scr_offset_to_zero = ri->ri_cols * WSDISPLAY_SCROLLBACK_LINES; | | 283 | scr->scr_offset_to_zero = ri->ri_cols * WSDISPLAY_SCROLLBACK_LINES; |
284 | scr->scr_current_offset = scr->scr_offset_to_zero; | | 284 | scr->scr_current_offset = scr->scr_offset_to_zero; |
285 | #else | | 285 | #else |
286 | cnt = ri->ri_rows * ri->ri_cols; | | 286 | cnt = ri->ri_rows * ri->ri_cols; |
287 | #endif | | 287 | #endif |
288 | scr->scr_attrs = (long *)malloc(cnt * (sizeof(long) + | | 288 | scr->scr_attrs = malloc(cnt * (sizeof(long) + |
289 | sizeof(uint32_t)), M_DEVBUF, M_WAITOK); | | 289 | sizeof(uint32_t)), M_DEVBUF, M_WAITOK); |
290 | if (scr->scr_attrs == NULL) | | 290 | if (scr->scr_attrs == NULL) |
291 | return ENOMEM; | | 291 | return ENOMEM; |
292 | | | 292 | |
293 | scr->scr_chars = (uint32_t *)&scr->scr_attrs[cnt]; | | 293 | scr->scr_chars = (uint32_t *)&scr->scr_attrs[cnt]; |
294 | | | 294 | |
295 | ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr); | | 295 | i = ri->ri_ops.allocattr(ri, WS_DEFAULT_FG, WS_DEFAULT_BG, 0, defattr); |
296 | scr->scr_defattr = *defattr; | | 296 | if (i != 0) { |
| | | 297 | #ifdef DIAGNOSTIC |
| | | 298 | printf("vcons: error allocating attribute %d\n", i); |
| | | 299 | #endif |
| | | 300 | scr->scr_defattr = 0; |
| | | 301 | } else |
| | | 302 | scr->scr_defattr = *defattr; |
297 | | | 303 | |
298 | /* | | 304 | /* |
299 | * fill the attribute buffer with *defattr, chars with 0x20 | | 305 | * fill the attribute buffer with *defattr, chars with 0x20 |
300 | * since we don't know if the driver tries to mimic firmware output or | | 306 | * since we don't know if the driver tries to mimic firmware output or |
301 | * reset everything we do nothing to VRAM here, any driver that feels | | 307 | * reset everything we do nothing to VRAM here, any driver that feels |
302 | * the need to clear screen or something will have to do it on its own | | 308 | * the need to clear screen or something will have to do it on its own |
303 | * Additional screens will start out in the background anyway so | | 309 | * Additional screens will start out in the background anyway so |
304 | * cleaning or not only really affects the initial console screen | | 310 | * cleaning or not only really affects the initial console screen |
305 | */ | | 311 | */ |
306 | for (i = 0; i < cnt; i++) { | | 312 | for (i = 0; i < cnt; i++) { |
307 | scr->scr_attrs[i] = *defattr; | | 313 | scr->scr_attrs[i] = *defattr; |
308 | scr->scr_chars[i] = 0x20; | | 314 | scr->scr_chars[i] = 0x20; |
309 | } | | 315 | } |
| @@ -1130,40 +1136,43 @@ vcons_cursor(void *cookie, int on, int r | | | @@ -1130,40 +1136,43 @@ vcons_cursor(void *cookie, int on, int r |
1130 | scr->scr_ri.ri_crow = row; | | 1136 | scr->scr_ri.ri_crow = row; |
1131 | scr->scr_ri.ri_ccol = col; | | 1137 | scr->scr_ri.ri_ccol = col; |
1132 | } | | 1138 | } |
1133 | vcons_unlock(scr); | | 1139 | vcons_unlock(scr); |
1134 | } | | 1140 | } |
1135 | | | 1141 | |
1136 | /* methods to read/write characters via ioctl() */ | | 1142 | /* methods to read/write characters via ioctl() */ |
1137 | | | 1143 | |
1138 | static int | | 1144 | static int |
1139 | vcons_putwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc) | | 1145 | vcons_putwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc) |
1140 | { | | 1146 | { |
1141 | long attr; | | 1147 | long attr; |
1142 | struct rasops_info *ri; | | 1148 | struct rasops_info *ri; |
| | | 1149 | int error; |
1143 | | | 1150 | |
1144 | KASSERT(scr != NULL && wsc != NULL); | | 1151 | KASSERT(scr != NULL && wsc != NULL); |
1145 | | | 1152 | |
1146 | ri = &scr->scr_ri; | | 1153 | ri = &scr->scr_ri; |
1147 | | | 1154 | |
1148 | if (__predict_false((unsigned int)wsc->col > ri->ri_cols || | | 1155 | if (__predict_false((unsigned int)wsc->col > ri->ri_cols || |
1149 | (unsigned int)wsc->row > ri->ri_rows)) | | 1156 | (unsigned int)wsc->row > ri->ri_rows)) |
1150 | return (EINVAL); | | 1157 | return (EINVAL); |
1151 | | | 1158 | |
1152 | if ((wsc->row >= 0) && (wsc->row < ri->ri_rows) && (wsc->col >= 0) && | | 1159 | if ((wsc->row >= 0) && (wsc->row < ri->ri_rows) && (wsc->col >= 0) && |
1153 | (wsc->col < ri->ri_cols)) { | | 1160 | (wsc->col < ri->ri_cols)) { |
1154 | | | 1161 | |
1155 | ri->ri_ops.allocattr(ri, wsc->foreground, wsc->background, | | 1162 | error = ri->ri_ops.allocattr(ri, wsc->foreground, |
1156 | wsc->flags, &attr); | | 1163 | wsc->background, wsc->flags, &attr); |
| | | 1164 | if (error) |
| | | 1165 | return error; |
1157 | vcons_putchar(ri, wsc->row, wsc->col, wsc->letter, attr); | | 1166 | vcons_putchar(ri, wsc->row, wsc->col, wsc->letter, attr); |
1158 | #ifdef VCONS_DEBUG | | 1167 | #ifdef VCONS_DEBUG |
1159 | printf("vcons_putwschar(%d, %d, %x, %lx\n", wsc->row, wsc->col, | | 1168 | printf("vcons_putwschar(%d, %d, %x, %lx\n", wsc->row, wsc->col, |
1160 | wsc->letter, attr); | | 1169 | wsc->letter, attr); |
1161 | #endif | | 1170 | #endif |
1162 | return 0; | | 1171 | return 0; |
1163 | } else | | 1172 | } else |
1164 | return EINVAL; | | 1173 | return EINVAL; |
1165 | } | | 1174 | } |
1166 | | | 1175 | |
1167 | static int | | 1176 | static int |
1168 | vcons_getwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc) | | 1177 | vcons_getwschar(struct vcons_screen *scr, struct wsdisplay_char *wsc) |
1169 | { | | 1178 | { |