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

Last change on this file was bab75df6, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Let kernel code get printf via the standard stdio header. Clean up unused includes.

  • Property mode set to 100644
File size: 7.4 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 kernel_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 <abi/fb/visuals.h>
42#include <console/chardev.h>
43#include <console/console.h>
44#include <stdint.h>
45#include <str.h>
46#include <align.h>
47#include <log.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 log(LF_ARCH, LVL_ERROR, "Unknown screen device.");
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 log(LF_ARCH, LVL_ERROR, "Too few screen registers.");
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 log(LF_ARCH, LVL_ERROR,
127 "Failed to absolutize fb register.");
128 return;
129 }
130
131 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
132 &fb_addr)) {
133 log(LF_ARCH, LVL_ERROR,
134 "Failed to determine screen address.");
135 return;
136 }
137
138 switch (fb_depth) {
139 case 8:
140 fb_scanline = fb_linebytes * (fb_depth >> 3);
141 visual = VISUAL_INDIRECT_8;
142 break;
143 case 16:
144 fb_scanline = fb_linebytes * (fb_depth >> 3);
145 visual = VISUAL_RGB_5_6_5_BE;
146 break;
147 case 24:
148 fb_scanline = fb_linebytes * 4;
149 visual = VISUAL_BGR_8_8_8_0;
150 break;
151 case 32:
152 fb_scanline = fb_linebytes * (fb_depth >> 3);
153 visual = VISUAL_RGB_0_8_8_8;
154 break;
155 default:
156 log(LF_ARCH, LVL_ERROR,
157 "Unsupported bits per pixel.");
158 return;
159 }
160
161 break;
162 case SCR_XVR:
163 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
164 log(LF_ARCH, LVL_ERROR,
165 "Too few screen registers.");
166 return;
167 }
168
169 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
170
171 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
172 log(LF_ARCH, LVL_ERROR,
173 "Failed to absolutize fb register.");
174 return;
175 }
176
177 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
178 &fb_addr)) {
179 log(LF_ARCH, LVL_ERROR,
180 "Failed to determine screen address.");
181 return;
182 }
183
184 fb_offset = 4 * 0x2000;
185
186 switch (fb_depth) {
187 case 8:
188 fb_scanline = fb_linebytes * (fb_depth >> 3);
189 visual = VISUAL_INDIRECT_8;
190 break;
191 case 16:
192 fb_scanline = fb_linebytes * (fb_depth >> 3);
193 visual = VISUAL_RGB_5_6_5_BE;
194 break;
195 case 24:
196 fb_scanline = fb_linebytes * 4;
197 visual = VISUAL_BGR_8_8_8_0;
198 break;
199 case 32:
200 fb_scanline = fb_linebytes * (fb_depth >> 3);
201 visual = VISUAL_RGB_0_8_8_8;
202 break;
203 default:
204 log(LF_ARCH, LVL_ERROR,
205 "Unsupported bits per pixel.");
206 return;
207 }
208
209 break;
210 case SCR_FFB:
211 fb_scanline = 8192;
212 visual = VISUAL_BGR_0_8_8_8;
213
214 upa_reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP];
215 if (!ofw_upa_apply_ranges(node->parent, upa_reg, &fb_addr)) {
216 log(LF_ARCH, LVL_ERROR,
217 "Failed to determine screen address.");
218 return;
219 }
220
221 break;
222 case SCR_CGSIX:
223 switch (fb_depth) {
224 case 8:
225 fb_scanline = fb_linebytes;
226 visual = VISUAL_INDIRECT_8;
227 break;
228 default:
229 log(LF_ARCH, LVL_WARN, "Not implemented.");
230 return;
231 }
232
233 sbus_reg = &((ofw_sbus_reg_t *) prop->value)[0];
234 if (!ofw_sbus_apply_ranges(node->parent, sbus_reg, &fb_addr)) {
235 log(LF_ARCH, LVL_ERROR,
236 "Failed to determine screen address.");
237 return;
238 }
239
240 break;
241
242 case SCR_QEMU_VGA:
243 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
244 log(LF_ARCH, LVL_ERROR, "Too few screen registers.");
245 return;
246 }
247
248 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
249
250 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
251 log(LF_ARCH, LVL_ERROR,
252 "Failed to absolutize fb register.");
253 return;
254 }
255
256 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
257 &fb_addr)) {
258 log(LF_ARCH, LVL_ERROR,
259 "Failed to determine screen address.");
260 return;
261 }
262
263 switch (fb_depth) {
264 case 8:
265 fb_scanline = fb_linebytes * (fb_depth >> 3);
266 visual = VISUAL_INDIRECT_8;
267 break;
268 case 16:
269 fb_scanline = fb_linebytes * (fb_depth >> 3);
270 visual = VISUAL_RGB_5_6_5_BE;
271 break;
272 case 24:
273 fb_scanline = fb_linebytes * 4;
274 visual = VISUAL_BGR_8_8_8_0;
275 break;
276 case 32:
277 fb_scanline = fb_linebytes * (fb_depth >> 3);
278 visual = VISUAL_RGB_0_8_8_8;
279 break;
280 default:
281 log(LF_ARCH, LVL_ERROR, "Unsupported bits per pixel.");
282 return;
283 }
284 break;
285
286 default:
287 panic("Unexpected type.");
288 }
289
290 fb_properties_t props = {
291 .addr = fb_addr,
292 .offset = fb_offset,
293 .x = fb_width,
294 .y = fb_height,
295 .scan = fb_scanline,
296 .visual = visual,
297 };
298
299 outdev_t *fbdev = fb_init(&props);
300 if (fbdev)
301 stdout_wire(fbdev);
302}
303
304/** @}
305 */
Note: See TracBrowser for help on using the repository browser.