| 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 <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 <print.h>
|
|---|
| 48 | #include <log.h>
|
|---|
| 49 |
|
|---|
| 50 | #define FFB_REG_24BPP 7
|
|---|
| 51 |
|
|---|
| 52 | scr_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 | */
|
|---|
| 61 | void scr_init(ofw_tree_node_t *node)
|
|---|
| 62 | {
|
|---|
| 63 | ofw_tree_property_t *prop;
|
|---|
| 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;
|
|---|
| 68 | const char *name;
|
|---|
| 69 |
|
|---|
| 70 | name = ofw_tree_node_name(node);
|
|---|
| 71 |
|
|---|
| 72 | if (str_cmp(name, "SUNW,m64B") == 0)
|
|---|
| 73 | scr_type = SCR_ATYFB;
|
|---|
| 74 | else if (str_cmp(name, "SUNW,XVR-100") == 0)
|
|---|
| 75 | scr_type = SCR_XVR;
|
|---|
| 76 | else if (str_cmp(name, "SUNW,ffb") == 0)
|
|---|
| 77 | scr_type = SCR_FFB;
|
|---|
| 78 | else if (str_cmp(name, "cgsix") == 0)
|
|---|
| 79 | scr_type = SCR_CGSIX;
|
|---|
| 80 | else if (str_cmp(name, "QEMU,VGA") == 0)
|
|---|
| 81 | scr_type = SCR_QEMU_VGA;
|
|---|
| 82 |
|
|---|
| 83 | if (scr_type == SCR_UNKNOWN) {
|
|---|
| 84 | log(LF_ARCH, LVL_ERROR, "Unknown screen device.");
|
|---|
| 85 | return;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | uintptr_t fb_addr;
|
|---|
| 89 | unsigned int fb_offset = 0;
|
|---|
| 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;
|
|---|
| 95 | unsigned int visual;
|
|---|
| 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)
|
|---|
| 115 | panic("Cannot find 'reg' property.");
|
|---|
| 116 |
|
|---|
| 117 | switch (scr_type) {
|
|---|
| 118 | case SCR_ATYFB:
|
|---|
| 119 | if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
|
|---|
| 120 | log(LF_ARCH, LVL_ERROR, "Too few screen registers.");
|
|---|
| 121 | return;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
|
|---|
| 125 |
|
|---|
| 126 | if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
|
|---|
| 127 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 128 | "Failed to absolutize fb register.");
|
|---|
| 129 | return;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
|
|---|
| 133 | &fb_addr)) {
|
|---|
| 134 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 135 | "Failed to determine screen address.");
|
|---|
| 136 | return;
|
|---|
| 137 | }
|
|---|
| 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);
|
|---|
| 146 | visual = VISUAL_RGB_5_6_5_BE;
|
|---|
| 147 | break;
|
|---|
| 148 | case 24:
|
|---|
| 149 | fb_scanline = fb_linebytes * 4;
|
|---|
| 150 | visual = VISUAL_BGR_8_8_8_0;
|
|---|
| 151 | break;
|
|---|
| 152 | case 32:
|
|---|
| 153 | fb_scanline = fb_linebytes * (fb_depth >> 3);
|
|---|
| 154 | visual = VISUAL_RGB_0_8_8_8;
|
|---|
| 155 | break;
|
|---|
| 156 | default:
|
|---|
| 157 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 158 | "Unsupported bits per pixel.");
|
|---|
| 159 | return;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | break;
|
|---|
| 163 | case SCR_XVR:
|
|---|
| 164 | if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
|
|---|
| 165 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 166 | "Too few screen registers.");
|
|---|
| 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)) {
|
|---|
| 173 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 174 | "Failed to absolutize fb register.");
|
|---|
| 175 | return;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
|
|---|
| 179 | &fb_addr)) {
|
|---|
| 180 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 181 | "Failed to determine screen address.");
|
|---|
| 182 | return;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | fb_offset = 4 * 0x2000;
|
|---|
| 186 |
|
|---|
| 187 | switch (fb_depth) {
|
|---|
| 188 | case 8:
|
|---|
| 189 | fb_scanline = fb_linebytes * (fb_depth >> 3);
|
|---|
| 190 | visual = VISUAL_INDIRECT_8;
|
|---|
| 191 | break;
|
|---|
| 192 | case 16:
|
|---|
| 193 | fb_scanline = fb_linebytes * (fb_depth >> 3);
|
|---|
| 194 | visual = VISUAL_RGB_5_6_5_BE;
|
|---|
| 195 | break;
|
|---|
| 196 | case 24:
|
|---|
| 197 | fb_scanline = fb_linebytes * 4;
|
|---|
| 198 | visual = VISUAL_BGR_8_8_8_0;
|
|---|
| 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:
|
|---|
| 205 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 206 | "Unsupported bits per pixel.");
|
|---|
| 207 | return;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | break;
|
|---|
| 211 | case SCR_FFB:
|
|---|
| 212 | fb_scanline = 8192;
|
|---|
| 213 | visual = VISUAL_BGR_0_8_8_8;
|
|---|
| 214 |
|
|---|
| 215 | upa_reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP];
|
|---|
| 216 | if (!ofw_upa_apply_ranges(node->parent, upa_reg, &fb_addr)) {
|
|---|
| 217 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 218 | "Failed to determine screen address.");
|
|---|
| 219 | return;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 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:
|
|---|
| 230 | log(LF_ARCH, LVL_WARN, "Not implemented.");
|
|---|
| 231 | return;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | sbus_reg = &((ofw_sbus_reg_t *) prop->value)[0];
|
|---|
| 235 | if (!ofw_sbus_apply_ranges(node->parent, sbus_reg, &fb_addr)) {
|
|---|
| 236 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 237 | "Failed to determine screen address.");
|
|---|
| 238 | return;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | break;
|
|---|
| 242 |
|
|---|
| 243 | case SCR_QEMU_VGA:
|
|---|
| 244 | if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
|
|---|
| 245 | log(LF_ARCH, LVL_ERROR, "Too few screen registers.");
|
|---|
| 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)) {
|
|---|
| 252 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 253 | "Failed to absolutize fb register.");
|
|---|
| 254 | return;
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
|
|---|
| 258 | &fb_addr)) {
|
|---|
| 259 | log(LF_ARCH, LVL_ERROR,
|
|---|
| 260 | "Failed to determine screen address.");
|
|---|
| 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:
|
|---|
| 282 | log(LF_ARCH, LVL_ERROR, "Unsupported bits per pixel.");
|
|---|
| 283 | return;
|
|---|
| 284 | }
|
|---|
| 285 | break;
|
|---|
| 286 |
|
|---|
| 287 | default:
|
|---|
| 288 | panic("Unexpected type.");
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | fb_properties_t props = {
|
|---|
| 292 | .addr = fb_addr,
|
|---|
| 293 | .offset = fb_offset,
|
|---|
| 294 | .x = fb_width,
|
|---|
| 295 | .y = fb_height,
|
|---|
| 296 | .scan = fb_scanline,
|
|---|
| 297 | .visual = visual,
|
|---|
| 298 | };
|
|---|
| 299 |
|
|---|
| 300 | outdev_t *fbdev = fb_init(&props);
|
|---|
| 301 | if (fbdev)
|
|---|
| 302 | stdout_wire(fbdev);
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | /** @}
|
|---|
| 306 | */
|
|---|