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
RevLine 
[5d684e4]1/*
[df4ed85]2 * Copyright (c) 2006 Jakub Jermar
[5d684e4]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
[c5429fe]29/** @addtogroup kernel_sparc64
[5d684e4]30 * @{
31 */
32/** @file
33 */
34
35#include <arch/drivers/scr.h>
36#include <genarch/ofw/ofw_tree.h>
[e731b0d]37#include <genarch/ofw/pci.h>
38#include <genarch/ofw/sbus.h>
39#include <genarch/ofw/upa.h>
[5d684e4]40#include <genarch/fb/fb.h>
[c0699467]41#include <abi/fb/visuals.h>
[a71c158]42#include <console/chardev.h>
43#include <console/console.h>
[83dab11]44#include <stdint.h>
[19f857a]45#include <str.h>
[5d684e4]46#include <align.h>
[9a5abb78]47#include <log.h>
[5d684e4]48
[6ff1f1e]49#define FFB_REG_24BPP 7
50
[5d684e4]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;
[965dc18]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;
[5d684e4]67 const char *name;
[a35b458]68
[5d684e4]69 name = ofw_tree_node_name(node);
[a35b458]70
[b60c582]71 if (str_cmp(name, "SUNW,m64B") == 0)
[5d684e4]72 scr_type = SCR_ATYFB;
[b60c582]73 else if (str_cmp(name, "SUNW,XVR-100") == 0)
[965dc18]74 scr_type = SCR_XVR;
[b60c582]75 else if (str_cmp(name, "SUNW,ffb") == 0)
[5d684e4]76 scr_type = SCR_FFB;
[b60c582]77 else if (str_cmp(name, "cgsix") == 0)
[9b35499]78 scr_type = SCR_CGSIX;
[bdfd3cdd]79 else if (str_cmp(name, "QEMU,VGA") == 0)
80 scr_type = SCR_QEMU_VGA;
[a35b458]81
[5d684e4]82 if (scr_type == SCR_UNKNOWN) {
[b2fa1204]83 log(LF_ARCH, LVL_ERROR, "Unknown screen device.");
[5d684e4]84 return;
85 }
[a35b458]86
[5d684e4]87 uintptr_t fb_addr;
[20eb5e4d]88 unsigned int fb_offset = 0;
[5d684e4]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;
[2bc137c2]94 unsigned int visual;
[5d684e4]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)
[f651e80]114 panic("Cannot find 'reg' property.");
[5d684e4]115
116 switch (scr_type) {
117 case SCR_ATYFB:
118 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
[b2fa1204]119 log(LF_ARCH, LVL_ERROR, "Too few screen registers.");
[5d684e4]120 return;
121 }
[a35b458]122
[965dc18]123 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
[a35b458]124
[965dc18]125 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
[b2fa1204]126 log(LF_ARCH, LVL_ERROR,
127 "Failed to absolutize fb register.");
[5d684e4]128 return;
129 }
[a35b458]130
[965dc18]131 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
132 &fb_addr)) {
[b2fa1204]133 log(LF_ARCH, LVL_ERROR,
134 "Failed to determine screen address.");
[5d684e4]135 return;
136 }
[a35b458]137
[2bc137c2]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);
[19490ce]145 visual = VISUAL_RGB_5_6_5_BE;
[2bc137c2]146 break;
147 case 24:
[5d684e4]148 fb_scanline = fb_linebytes * 4;
[30885b9]149 visual = VISUAL_BGR_8_8_8_0;
[2bc137c2]150 break;
151 case 32:
[5d684e4]152 fb_scanline = fb_linebytes * (fb_depth >> 3);
[2bc137c2]153 visual = VISUAL_RGB_0_8_8_8;
154 break;
155 default:
[b2fa1204]156 log(LF_ARCH, LVL_ERROR,
157 "Unsupported bits per pixel.");
[2bc137c2]158 return;
159 }
[a35b458]160
[965dc18]161 break;
162 case SCR_XVR:
163 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
[b2fa1204]164 log(LF_ARCH, LVL_ERROR,
165 "Too few screen registers.");
[965dc18]166 return;
167 }
[a35b458]168
[965dc18]169 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
[a35b458]170
[965dc18]171 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
[b2fa1204]172 log(LF_ARCH, LVL_ERROR,
173 "Failed to absolutize fb register.");
[965dc18]174 return;
175 }
[a35b458]176
[965dc18]177 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
178 &fb_addr)) {
[b2fa1204]179 log(LF_ARCH, LVL_ERROR,
180 "Failed to determine screen address.");
[965dc18]181 return;
182 }
183
[20eb5e4d]184 fb_offset = 4 * 0x2000;
185
[965dc18]186 switch (fb_depth) {
187 case 8:
188 fb_scanline = fb_linebytes * (fb_depth >> 3);
[20eb5e4d]189 visual = VISUAL_INDIRECT_8;
[965dc18]190 break;
191 case 16:
192 fb_scanline = fb_linebytes * (fb_depth >> 3);
[19490ce]193 visual = VISUAL_RGB_5_6_5_BE;
[965dc18]194 break;
195 case 24:
196 fb_scanline = fb_linebytes * 4;
[30885b9]197 visual = VISUAL_BGR_8_8_8_0;
[965dc18]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:
[b2fa1204]204 log(LF_ARCH, LVL_ERROR,
205 "Unsupported bits per pixel.");
[965dc18]206 return;
207 }
[a35b458]208
[5d684e4]209 break;
[1b20da0]210 case SCR_FFB:
[6ff1f1e]211 fb_scanline = 8192;
[ccb0cbc]212 visual = VISUAL_BGR_0_8_8_8;
[6ff1f1e]213
[965dc18]214 upa_reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP];
215 if (!ofw_upa_apply_ranges(node->parent, upa_reg, &fb_addr)) {
[b2fa1204]216 log(LF_ARCH, LVL_ERROR,
217 "Failed to determine screen address.");
[6ff1f1e]218 return;
219 }
220
[9b35499]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:
[b2fa1204]229 log(LF_ARCH, LVL_WARN, "Not implemented.");
[9b35499]230 return;
231 }
[a35b458]232
[965dc18]233 sbus_reg = &((ofw_sbus_reg_t *) prop->value)[0];
234 if (!ofw_sbus_apply_ranges(node->parent, sbus_reg, &fb_addr)) {
[b2fa1204]235 log(LF_ARCH, LVL_ERROR,
236 "Failed to determine screen address.");
[9b35499]237 return;
238 }
[a35b458]239
[6ff1f1e]240 break;
[bdfd3cdd]241
242 case SCR_QEMU_VGA:
243 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
[b2fa1204]244 log(LF_ARCH, LVL_ERROR, "Too few screen registers.");
[bdfd3cdd]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)) {
[b2fa1204]251 log(LF_ARCH, LVL_ERROR,
252 "Failed to absolutize fb register.");
[bdfd3cdd]253 return;
254 }
255
256 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
257 &fb_addr)) {
[b2fa1204]258 log(LF_ARCH, LVL_ERROR,
259 "Failed to determine screen address.");
[bdfd3cdd]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:
[b2fa1204]281 log(LF_ARCH, LVL_ERROR, "Unsupported bits per pixel.");
[bdfd3cdd]282 return;
283 }
284 break;
285
[5d684e4]286 default:
[f651e80]287 panic("Unexpected type.");
[5d684e4]288 }
289
[965dc18]290 fb_properties_t props = {
291 .addr = fb_addr,
[20eb5e4d]292 .offset = fb_offset,
[965dc18]293 .x = fb_width,
294 .y = fb_height,
295 .scan = fb_scanline,
296 .visual = visual,
297 };
[a35b458]298
[a71c158]299 outdev_t *fbdev = fb_init(&props);
300 if (fbdev)
301 stdout_wire(fbdev);
[b1a29bb]302}
303
[5d684e4]304/** @}
305 */
Note: See TracBrowser for help on using the repository browser.