source: mainline/kernel/arch/sparc64/src/drivers/scr.c@ b3b7e14a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b3b7e14a was bdfd3cdd, checked in by Jakub Jermar <jakub@…>, 15 years ago

Support for QEMU,VGA frame buffer on sparc64.
(Contributed by Igor Kovalenko.)

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Copyright (c) 2006 Jakub Jermar
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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - 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 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup sparc64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch/drivers/scr.h>
36#include <genarch/ofw/ofw_tree.h>
37#include <genarch/ofw/pci.h>
38#include <genarch/ofw/sbus.h>
39#include <genarch/ofw/upa.h>
40#include <genarch/fb/fb.h>
41#include <genarch/fb/visuals.h>
42#include <console/chardev.h>
43#include <console/console.h>
44#include <typedefs.h>
45#include <str.h>
46#include <align.h>
47#include <print.h>
48
49#define FFB_REG_24BPP 7
50
51scr_type_t scr_type = SCR_UNKNOWN;
52
53/** Initialize screen.
54 *
55 * Traverse OpenFirmware device tree in order to find necessary
56 * info about the screen device.
57 *
58 * @param node Screen device node.
59 */
60void scr_init(ofw_tree_node_t *node)
61{
62 ofw_tree_property_t *prop;
63 ofw_pci_reg_t *pci_reg;
64 ofw_pci_reg_t pci_abs_reg;
65 ofw_upa_reg_t *upa_reg;
66 ofw_sbus_reg_t *sbus_reg;
67 const char *name;
68
69 name = ofw_tree_node_name(node);
70
71 if (str_cmp(name, "SUNW,m64B") == 0)
72 scr_type = SCR_ATYFB;
73 else if (str_cmp(name, "SUNW,XVR-100") == 0)
74 scr_type = SCR_XVR;
75 else if (str_cmp(name, "SUNW,ffb") == 0)
76 scr_type = SCR_FFB;
77 else if (str_cmp(name, "cgsix") == 0)
78 scr_type = SCR_CGSIX;
79 else if (str_cmp(name, "QEMU,VGA") == 0)
80 scr_type = SCR_QEMU_VGA;
81
82 if (scr_type == SCR_UNKNOWN) {
83 printf("Unknown screen device.\n");
84 return;
85 }
86
87 uintptr_t fb_addr;
88 unsigned int fb_offset = 0;
89 uint32_t fb_width = 0;
90 uint32_t fb_height = 0;
91 uint32_t fb_depth = 0;
92 uint32_t fb_linebytes = 0;
93 uint32_t fb_scanline = 0;
94 unsigned int visual;
95
96 prop = ofw_tree_getprop(node, "width");
97 if (prop && prop->value)
98 fb_width = *((uint32_t *) prop->value);
99
100 prop = ofw_tree_getprop(node, "height");
101 if (prop && prop->value)
102 fb_height = *((uint32_t *) prop->value);
103
104 prop = ofw_tree_getprop(node, "depth");
105 if (prop && prop->value)
106 fb_depth = *((uint32_t *) prop->value);
107
108 prop = ofw_tree_getprop(node, "linebytes");
109 if (prop && prop->value)
110 fb_linebytes = *((uint32_t *) prop->value);
111
112 prop = ofw_tree_getprop(node, "reg");
113 if (!prop)
114 panic("Cannot find 'reg' property.");
115
116 switch (scr_type) {
117 case SCR_ATYFB:
118 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
119 printf("Too few screen registers.\n");
120 return;
121 }
122
123 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
124
125 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
126 printf("Failed to absolutize fb register.\n");
127 return;
128 }
129
130 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
131 &fb_addr)) {
132 printf("Failed to determine screen address.\n");
133 return;
134 }
135
136 switch (fb_depth) {
137 case 8:
138 fb_scanline = fb_linebytes * (fb_depth >> 3);
139 visual = VISUAL_INDIRECT_8;
140 break;
141 case 16:
142 fb_scanline = fb_linebytes * (fb_depth >> 3);
143 visual = VISUAL_RGB_5_6_5_BE;
144 break;
145 case 24:
146 fb_scanline = fb_linebytes * 4;
147 visual = VISUAL_BGR_8_8_8_0;
148 break;
149 case 32:
150 fb_scanline = fb_linebytes * (fb_depth >> 3);
151 visual = VISUAL_RGB_0_8_8_8;
152 break;
153 default:
154 printf("Unsupported bits per pixel.\n");
155 return;
156 }
157
158 break;
159 case SCR_XVR:
160 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
161 printf("Too few screen registers.\n");
162 return;
163 }
164
165 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
166
167 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
168 printf("Failed to absolutize fb register.\n");
169 return;
170 }
171
172 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
173 &fb_addr)) {
174 printf("Failed to determine screen address.\n");
175 return;
176 }
177
178 fb_offset = 4 * 0x2000;
179
180 switch (fb_depth) {
181 case 8:
182 fb_scanline = fb_linebytes * (fb_depth >> 3);
183 visual = VISUAL_INDIRECT_8;
184 break;
185 case 16:
186 fb_scanline = fb_linebytes * (fb_depth >> 3);
187 visual = VISUAL_RGB_5_6_5_BE;
188 break;
189 case 24:
190 fb_scanline = fb_linebytes * 4;
191 visual = VISUAL_BGR_8_8_8_0;
192 break;
193 case 32:
194 fb_scanline = fb_linebytes * (fb_depth >> 3);
195 visual = VISUAL_RGB_0_8_8_8;
196 break;
197 default:
198 printf("Unsupported bits per pixel.\n");
199 return;
200 }
201
202 break;
203 case SCR_FFB:
204 fb_scanline = 8192;
205 visual = VISUAL_BGR_0_8_8_8;
206
207 upa_reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP];
208 if (!ofw_upa_apply_ranges(node->parent, upa_reg, &fb_addr)) {
209 printf("Failed to determine screen address.\n");
210 return;
211 }
212
213 break;
214 case SCR_CGSIX:
215 switch (fb_depth) {
216 case 8:
217 fb_scanline = fb_linebytes;
218 visual = VISUAL_INDIRECT_8;
219 break;
220 default:
221 printf("Not implemented.\n");
222 return;
223 }
224
225 sbus_reg = &((ofw_sbus_reg_t *) prop->value)[0];
226 if (!ofw_sbus_apply_ranges(node->parent, sbus_reg, &fb_addr)) {
227 printf("Failed to determine screen address.\n");
228 return;
229 }
230
231 break;
232
233 case SCR_QEMU_VGA:
234 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
235 printf("Too few screen registers.\n");
236 return;
237 }
238
239 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
240
241 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
242 printf("Failed to absolutize fb register.\n");
243 return;
244 }
245
246 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
247 &fb_addr)) {
248 printf("Failed to determine screen address.\n");
249 return;
250 }
251
252 switch (fb_depth) {
253 case 8:
254 fb_scanline = fb_linebytes * (fb_depth >> 3);
255 visual = VISUAL_INDIRECT_8;
256 break;
257 case 16:
258 fb_scanline = fb_linebytes * (fb_depth >> 3);
259 visual = VISUAL_RGB_5_6_5_BE;
260 break;
261 case 24:
262 fb_scanline = fb_linebytes * 4;
263 visual = VISUAL_BGR_8_8_8_0;
264 break;
265 case 32:
266 fb_scanline = fb_linebytes * (fb_depth >> 3);
267 visual = VISUAL_RGB_0_8_8_8;
268 break;
269 default:
270 printf("Unsupported bits per pixel.\n");
271 return;
272 }
273 break;
274
275 default:
276 panic("Unexpected type.");
277 }
278
279 fb_properties_t props = {
280 .addr = fb_addr,
281 .offset = fb_offset,
282 .x = fb_width,
283 .y = fb_height,
284 .scan = fb_scanline,
285 .visual = visual,
286 };
287
288 outdev_t *fbdev = fb_init(&props);
289 if (fbdev)
290 stdout_wire(fbdev);
291}
292
293/** @}
294 */
Note: See TracBrowser for help on using the repository browser.