|
1 /* |
|
2 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 * |
|
4 * Permission is hereby granted, free of charge, to any person obtaining a |
|
5 * copy of this software and associated documentation files (the "Software"), |
|
6 * to deal in the Software without restriction, including without limitation |
|
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
8 * and/or sell copies of the Software, and to permit persons to whom the |
|
9 * Software is furnished to do so, subject to the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice (including the next |
|
12 * paragraph) shall be included in all copies or substantial portions of the |
|
13 * Software. |
|
14 * |
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
21 * DEALINGS IN THE SOFTWARE. |
|
22 */ |
|
23 |
|
24 #include "libvtsSUNWmga.h" /* Common VTS library definitions */ |
|
25 |
|
26 |
|
27 return_packet * |
|
28 mga_test_dma( |
|
29 register int const fd) |
|
30 { |
|
31 static return_packet rp; |
|
32 |
|
33 memset(&rp, 0, sizeof (return_packet)); |
|
34 |
|
35 TraceMessage(VTS_DEBUG, "mga_test_dma", |
|
36 "mga_test_dma running\n"); |
|
37 |
|
38 mga_block_signals(); |
|
39 |
|
40 mga_lock_display(); |
|
41 |
|
42 dma_test(&rp, fd); |
|
43 |
|
44 TraceMessage(VTS_DEBUG, "mga_test_dma", |
|
45 "mga_dma_memory completed\n"); |
|
46 |
|
47 mga_unlock_display(); |
|
48 |
|
49 mga_restore_signals(); |
|
50 |
|
51 return (&rp); |
|
52 } |
|
53 |
|
54 |
|
55 int |
|
56 dma_test( |
|
57 register return_packet *const rp, |
|
58 register int const fd) |
|
59 { |
|
60 register int y; |
|
61 register int height; |
|
62 register int maxwidth; |
|
63 register int maxheight; |
|
64 register uint32_t fg; |
|
65 register uint32_t bg; |
|
66 |
|
67 memset(&mga_info, 0, sizeof (mga_info)); |
|
68 mga_info.mga_fd = fd; |
|
69 |
|
70 if (mga_map_mem(rp, GRAPHICS_ERR_DMA) != 0) { |
|
71 close(fd); |
|
72 return (-1); |
|
73 } |
|
74 |
|
75 if (mga_init_info(rp, GRAPHICS_ERR_DMA) != 0) { |
|
76 mga_unmap_mem(NULL, GRAPHICS_ERR_CHIP); |
|
77 close(fd); |
|
78 return (-1); |
|
79 } |
|
80 |
|
81 /* We need to be in mga mode. */ |
|
82 |
|
83 if (!mga_mgamode()) { |
|
84 mga_unmap_mem(NULL, GRAPHICS_ERR_DMA); |
|
85 close(fd); |
|
86 return (0); |
|
87 } |
|
88 |
|
89 if (!mga_init_graphics()) { |
|
90 mga_unmap_mem(NULL, GRAPHICS_ERR_DMA); |
|
91 close(fd); |
|
92 return (0); |
|
93 } |
|
94 |
|
95 mga_save_palet(); |
|
96 mga_set_palet(); |
|
97 |
|
98 fg = mga_color(0xff, 0x00, 0x00); |
|
99 bg = mga_color(0xff, 0xff, 0xff); |
|
100 |
|
101 /* Do pattern fill */ |
|
102 |
|
103 /* |
|
104 * Can only transfer 0x40000 (262144) pixels, probably due |
|
105 * to limit of the ar0 register. |
|
106 */ |
|
107 |
|
108 maxwidth = (mga_info.mga_width + 31) / 32 * 32; |
|
109 if (maxwidth == 0) |
|
110 maxheight = MGA_AR0_MASK + 1; |
|
111 else |
|
112 maxheight = (MGA_AR0_MASK + 1) / maxwidth; |
|
113 |
|
114 for (y = 0; y < mga_info.mga_height; y += height) { |
|
115 if (y + maxheight > mga_info.mga_height) |
|
116 height = mga_info.mga_height - y; |
|
117 else |
|
118 height = maxheight; |
|
119 |
|
120 if (!mga_fill_pattern_rect(0, y, |
|
121 mga_info.mga_width, y + height, |
|
122 fg, bg, 0x77ddbbee77ddbbee)) { |
|
123 mga_restore_palet(); |
|
124 mga_finish_graphics(); |
|
125 mga_unmap_mem(NULL, GRAPHICS_ERR_DMA); |
|
126 close(fd); |
|
127 return (-1); |
|
128 } |
|
129 |
|
130 } |
|
131 |
|
132 mga_sleep(2); |
|
133 |
|
134 mga_restore_palet(); |
|
135 mga_finish_graphics(); |
|
136 |
|
137 if (mga_unmap_mem(rp, GRAPHICS_ERR_DMA) != 0) { |
|
138 close(fd); |
|
139 return (-1); |
|
140 } |
|
141 |
|
142 if (close(fd) != 0) { |
|
143 gfx_vts_set_message(rp, 1, GRAPHICS_ERR_DMA, |
|
144 "error closing device\n"); |
|
145 return (-1); |
|
146 } |
|
147 |
|
148 return (0); |
|
149 } |