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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1b20da0 was 1b20da0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on non-empty lines, in certain file types.

Command used: tools/srepl '\([^[:space:]]\)\s\+$' '\1' -- *.c *.h *.py *.sh *.s *.S *.ag

  • 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
[1b20da0]29/** @addtogroup 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>
47#include <print.h>
[9a5abb78]48#include <log.h>
[5d684e4]49
[6ff1f1e]50#define FFB_REG_24BPP 7
51
[5d684e4]52scr_type_t scr_type = SCR_UNKNOWN;
53
54/** Initialize screen.
55 *
56 * Traverse OpenFirmware device tree in order to find necessary
57 * info about the screen device.
58 *
59 * @param node Screen device node.
60 */
61void scr_init(ofw_tree_node_t *node)
62{
63 ofw_tree_property_t *prop;
[965dc18]64 ofw_pci_reg_t *pci_reg;
65 ofw_pci_reg_t pci_abs_reg;
66 ofw_upa_reg_t *upa_reg;
67 ofw_sbus_reg_t *sbus_reg;
[5d684e4]68 const char *name;
69
70 name = ofw_tree_node_name(node);
71
[b60c582]72 if (str_cmp(name, "SUNW,m64B") == 0)
[5d684e4]73 scr_type = SCR_ATYFB;
[b60c582]74 else if (str_cmp(name, "SUNW,XVR-100") == 0)
[965dc18]75 scr_type = SCR_XVR;
[b60c582]76 else if (str_cmp(name, "SUNW,ffb") == 0)
[5d684e4]77 scr_type = SCR_FFB;
[b60c582]78 else if (str_cmp(name, "cgsix") == 0)
[9b35499]79 scr_type = SCR_CGSIX;
[bdfd3cdd]80 else if (str_cmp(name, "QEMU,VGA") == 0)
81 scr_type = SCR_QEMU_VGA;
[5d684e4]82
83 if (scr_type == SCR_UNKNOWN) {
[b2fa1204]84 log(LF_ARCH, LVL_ERROR, "Unknown screen device.");
[5d684e4]85 return;
86 }
87
88 uintptr_t fb_addr;
[20eb5e4d]89 unsigned int fb_offset = 0;
[5d684e4]90 uint32_t fb_width = 0;
91 uint32_t fb_height = 0;
92 uint32_t fb_depth = 0;
93 uint32_t fb_linebytes = 0;
94 uint32_t fb_scanline = 0;
[2bc137c2]95 unsigned int visual;
[5d684e4]96
97 prop = ofw_tree_getprop(node, "width");
98 if (prop && prop->value)
99 fb_width = *((uint32_t *) prop->value);
100
101 prop = ofw_tree_getprop(node, "height");
102 if (prop && prop->value)
103 fb_height = *((uint32_t *) prop->value);
104
105 prop = ofw_tree_getprop(node, "depth");
106 if (prop && prop->value)
107 fb_depth = *((uint32_t *) prop->value);
108
109 prop = ofw_tree_getprop(node, "linebytes");
110 if (prop && prop->value)
111 fb_linebytes = *((uint32_t *) prop->value);
112
113 prop = ofw_tree_getprop(node, "reg");
114 if (!prop)
[f651e80]115 panic("Cannot find 'reg' property.");
[5d684e4]116
117 switch (scr_type) {
118 case SCR_ATYFB:
119 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
[b2fa1204]120 log(LF_ARCH, LVL_ERROR, "Too few screen registers.");
[5d684e4]121 return;
122 }
123
[965dc18]124 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
[5d684e4]125
[965dc18]126 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
[b2fa1204]127 log(LF_ARCH, LVL_ERROR,
128 "Failed to absolutize fb register.");
[5d684e4]129 return;
130 }
131
[965dc18]132 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
133 &fb_addr)) {
[b2fa1204]134 log(LF_ARCH, LVL_ERROR,
135 "Failed to determine screen address.");
[5d684e4]136 return;
137 }
[2bc137c2]138
139 switch (fb_depth) {
140 case 8:
141 fb_scanline = fb_linebytes * (fb_depth >> 3);
142 visual = VISUAL_INDIRECT_8;
143 break;
144 case 16:
145 fb_scanline = fb_linebytes * (fb_depth >> 3);
[19490ce]146 visual = VISUAL_RGB_5_6_5_BE;
[2bc137c2]147 break;
148 case 24:
[5d684e4]149 fb_scanline = fb_linebytes * 4;
[30885b9]150 visual = VISUAL_BGR_8_8_8_0;
[2bc137c2]151 break;
152 case 32:
[5d684e4]153 fb_scanline = fb_linebytes * (fb_depth >> 3);
[2bc137c2]154 visual = VISUAL_RGB_0_8_8_8;
155 break;
156 default:
[b2fa1204]157 log(LF_ARCH, LVL_ERROR,
158 "Unsupported bits per pixel.");
[2bc137c2]159 return;
160 }
[5d684e4]161
[965dc18]162 break;
163 case SCR_XVR:
164 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
[b2fa1204]165 log(LF_ARCH, LVL_ERROR,
166 "Too few screen registers.");
[965dc18]167 return;
168 }
169
170 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
171
172 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
[b2fa1204]173 log(LF_ARCH, LVL_ERROR,
174 "Failed to absolutize fb register.");
[965dc18]175 return;
176 }
177
178 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
179 &fb_addr)) {
[b2fa1204]180 log(LF_ARCH, LVL_ERROR,
181 "Failed to determine screen address.");
[965dc18]182 return;
183 }
184
[20eb5e4d]185 fb_offset = 4 * 0x2000;
186
[965dc18]187 switch (fb_depth) {
188 case 8:
189 fb_scanline = fb_linebytes * (fb_depth >> 3);
[20eb5e4d]190 visual = VISUAL_INDIRECT_8;
[965dc18]191 break;
192 case 16:
193 fb_scanline = fb_linebytes * (fb_depth >> 3);
[19490ce]194 visual = VISUAL_RGB_5_6_5_BE;
[965dc18]195 break;
196 case 24:
197 fb_scanline = fb_linebytes * 4;
[30885b9]198 visual = VISUAL_BGR_8_8_8_0;
[965dc18]199 break;
200 case 32:
201 fb_scanline = fb_linebytes * (fb_depth >> 3);
202 visual = VISUAL_RGB_0_8_8_8;
203 break;
204 default:
[b2fa1204]205 log(LF_ARCH, LVL_ERROR,
206 "Unsupported bits per pixel.");
[965dc18]207 return;
208 }
209
[5d684e4]210 break;
[1b20da0]211 case SCR_FFB:
[6ff1f1e]212 fb_scanline = 8192;
[ccb0cbc]213 visual = VISUAL_BGR_0_8_8_8;
[6ff1f1e]214
[965dc18]215 upa_reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP];
216 if (!ofw_upa_apply_ranges(node->parent, upa_reg, &fb_addr)) {
[b2fa1204]217 log(LF_ARCH, LVL_ERROR,
218 "Failed to determine screen address.");
[6ff1f1e]219 return;
220 }
221
[9b35499]222 break;
223 case SCR_CGSIX:
224 switch (fb_depth) {
225 case 8:
226 fb_scanline = fb_linebytes;
227 visual = VISUAL_INDIRECT_8;
228 break;
229 default:
[b2fa1204]230 log(LF_ARCH, LVL_WARN, "Not implemented.");
[9b35499]231 return;
232 }
233
[965dc18]234 sbus_reg = &((ofw_sbus_reg_t *) prop->value)[0];
235 if (!ofw_sbus_apply_ranges(node->parent, sbus_reg, &fb_addr)) {
[b2fa1204]236 log(LF_ARCH, LVL_ERROR,
237 "Failed to determine screen address.");
[9b35499]238 return;
239 }
240
[6ff1f1e]241 break;
[bdfd3cdd]242
243 case SCR_QEMU_VGA:
244 if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
[b2fa1204]245 log(LF_ARCH, LVL_ERROR, "Too few screen registers.");
[bdfd3cdd]246 return;
247 }
248
249 pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
250
251 if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
[b2fa1204]252 log(LF_ARCH, LVL_ERROR,
253 "Failed to absolutize fb register.");
[bdfd3cdd]254 return;
255 }
256
257 if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
258 &fb_addr)) {
[b2fa1204]259 log(LF_ARCH, LVL_ERROR,
260 "Failed to determine screen address.");
[bdfd3cdd]261 return;
262 }
263
264 switch (fb_depth) {
265 case 8:
266 fb_scanline = fb_linebytes * (fb_depth >> 3);
267 visual = VISUAL_INDIRECT_8;
268 break;
269 case 16:
270 fb_scanline = fb_linebytes * (fb_depth >> 3);
271 visual = VISUAL_RGB_5_6_5_BE;
272 break;
273 case 24:
274 fb_scanline = fb_linebytes * 4;
275 visual = VISUAL_BGR_8_8_8_0;
276 break;
277 case 32:
278 fb_scanline = fb_linebytes * (fb_depth >> 3);
279 visual = VISUAL_RGB_0_8_8_8;
280 break;
281 default:
[b2fa1204]282 log(LF_ARCH, LVL_ERROR, "Unsupported bits per pixel.");
[bdfd3cdd]283 return;
284 }
285 break;
286
[5d684e4]287 default:
[f651e80]288 panic("Unexpected type.");
[5d684e4]289 }
290
[965dc18]291 fb_properties_t props = {
292 .addr = fb_addr,
[20eb5e4d]293 .offset = fb_offset,
[965dc18]294 .x = fb_width,
295 .y = fb_height,
296 .scan = fb_scanline,
297 .visual = visual,
298 };
[a71c158]299
300 outdev_t *fbdev = fb_init(&props);
301 if (fbdev)
302 stdout_wire(fbdev);
[b1a29bb]303}
304
[5d684e4]305/** @}
306 */
Note: See TracBrowser for help on using the repository browser.