Rev 3343 | Rev 3664 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1897 | jermar | 1 | /* |
| 2071 | jermar | 2 | * Copyright (c) 2006 Jakub Jermar |
| 1897 | 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/fb/fb.h> |
||
| 1993 | decky | 38 | #include <genarch/fb/visuals.h> |
| 1897 | jermar | 39 | #include <arch/types.h> |
| 40 | #include <func.h> |
||
| 41 | #include <align.h> |
||
| 42 | #include <print.h> |
||
| 43 | |||
| 1898 | jermar | 44 | #define FFB_REG_24BPP 7 |
| 45 | |||
| 1897 | jermar | 46 | scr_type_t scr_type = SCR_UNKNOWN; |
| 47 | |||
| 48 | /** Initialize screen. |
||
| 49 | * |
||
| 50 | * Traverse OpenFirmware device tree in order to find necessary |
||
| 51 | * info about the screen device. |
||
| 52 | * |
||
| 53 | * @param node Screen device node. |
||
| 54 | */ |
||
| 55 | void scr_init(ofw_tree_node_t *node) |
||
| 56 | { |
||
| 57 | ofw_tree_property_t *prop; |
||
| 58 | const char *name; |
||
| 59 | |||
| 60 | name = ofw_tree_node_name(node); |
||
| 61 | |||
| 62 | if (strcmp(name, "SUNW,m64B") == 0) |
||
| 63 | scr_type = SCR_ATYFB; |
||
| 64 | else if (strcmp(name, "SUNW,ffb") == 0) |
||
| 65 | scr_type = SCR_FFB; |
||
| 2510 | jermar | 66 | else if (strcmp(name, "cgsix") == 0) |
| 67 | scr_type = SCR_CGSIX; |
||
| 1897 | jermar | 68 | |
| 69 | if (scr_type == SCR_UNKNOWN) { |
||
| 70 | printf("Unknown keyboard device.\n"); |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | |||
| 74 | uintptr_t fb_addr; |
||
| 75 | uint32_t fb_width = 0; |
||
| 76 | uint32_t fb_height = 0; |
||
| 77 | uint32_t fb_depth = 0; |
||
| 78 | uint32_t fb_linebytes = 0; |
||
| 79 | uint32_t fb_scanline = 0; |
||
| 1993 | decky | 80 | unsigned int visual; |
| 1897 | jermar | 81 | |
| 82 | prop = ofw_tree_getprop(node, "width"); |
||
| 83 | if (prop && prop->value) |
||
| 84 | fb_width = *((uint32_t *) prop->value); |
||
| 85 | |||
| 86 | prop = ofw_tree_getprop(node, "height"); |
||
| 87 | if (prop && prop->value) |
||
| 88 | fb_height = *((uint32_t *) prop->value); |
||
| 89 | |||
| 90 | prop = ofw_tree_getprop(node, "depth"); |
||
| 91 | if (prop && prop->value) |
||
| 92 | fb_depth = *((uint32_t *) prop->value); |
||
| 93 | |||
| 94 | prop = ofw_tree_getprop(node, "linebytes"); |
||
| 95 | if (prop && prop->value) |
||
| 96 | fb_linebytes = *((uint32_t *) prop->value); |
||
| 97 | |||
| 98 | prop = ofw_tree_getprop(node, "reg"); |
||
| 99 | if (!prop) |
||
| 100 | panic("Can't find \"reg\" property.\n"); |
||
| 101 | |||
| 102 | switch (scr_type) { |
||
| 103 | case SCR_ATYFB: |
||
| 104 | if (prop->size / sizeof(ofw_pci_reg_t) < 2) { |
||
| 105 | printf("Too few screen registers.\n"); |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | |||
| 109 | ofw_pci_reg_t *fb_reg = &((ofw_pci_reg_t *) prop->value)[1]; |
||
| 110 | ofw_pci_reg_t abs_reg; |
||
| 111 | |||
| 112 | if (!ofw_pci_reg_absolutize(node, fb_reg, &abs_reg)) { |
||
| 113 | printf("Failed to absolutize fb register.\n"); |
||
| 114 | return; |
||
| 115 | } |
||
| 116 | |||
| 117 | if (!ofw_pci_apply_ranges(node->parent, &abs_reg , &fb_addr)) { |
||
| 118 | printf("Failed to determine screen address.\n"); |
||
| 119 | return; |
||
| 120 | } |
||
| 1993 | decky | 121 | |
| 122 | switch (fb_depth) { |
||
| 123 | case 8: |
||
| 124 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
||
| 125 | visual = VISUAL_INDIRECT_8; |
||
| 126 | break; |
||
| 127 | case 16: |
||
| 128 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
||
| 129 | visual = VISUAL_RGB_5_6_5; |
||
| 130 | break; |
||
| 131 | case 24: |
||
| 1897 | jermar | 132 | fb_scanline = fb_linebytes * 4; |
| 1993 | decky | 133 | visual = VISUAL_RGB_8_8_8_0; |
| 134 | break; |
||
| 135 | case 32: |
||
| 1897 | jermar | 136 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
| 1993 | decky | 137 | visual = VISUAL_RGB_0_8_8_8; |
| 138 | break; |
||
| 139 | default: |
||
| 140 | printf("Unsupported bits per pixel.\n"); |
||
| 141 | return; |
||
| 142 | } |
||
| 1897 | jermar | 143 | |
| 144 | break; |
||
| 1898 | jermar | 145 | case SCR_FFB: |
| 146 | fb_scanline = 8192; |
||
| 1994 | decky | 147 | visual = VISUAL_BGR_0_8_8_8; |
| 1898 | jermar | 148 | |
| 149 | ofw_upa_reg_t *reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP]; |
||
| 150 | if (!ofw_upa_apply_ranges(node->parent, reg, &fb_addr)) { |
||
| 151 | printf("Failed to determine screen address.\n"); |
||
| 152 | return; |
||
| 153 | } |
||
| 154 | |||
| 155 | break; |
||
| 2510 | jermar | 156 | case SCR_CGSIX: |
| 157 | switch (fb_depth) { |
||
| 158 | case 8: |
||
| 159 | fb_scanline = fb_linebytes; |
||
| 160 | visual = VISUAL_INDIRECT_8; |
||
| 161 | break; |
||
| 162 | default: |
||
| 163 | printf("Not implemented.\n"); |
||
| 164 | return; |
||
| 165 | } |
||
| 166 | |||
| 167 | ofw_sbus_reg_t *cg6_reg = &((ofw_sbus_reg_t *) prop->value)[0]; |
||
| 168 | if (!ofw_sbus_apply_ranges(node->parent, cg6_reg, &fb_addr)) { |
||
| 169 | printf("Failed to determine screen address.\n"); |
||
| 170 | return; |
||
| 171 | } |
||
| 172 | |||
| 173 | break; |
||
| 1897 | jermar | 174 | default: |
| 175 | panic("Unexpected type.\n"); |
||
| 176 | } |
||
| 177 | |||
| 3618 | rimsky | 178 | fb_properties_t props; |
| 179 | props.addr = fb_addr; |
||
| 180 | props.fb_start = 0; |
||
| 181 | props.x = fb_width; |
||
| 182 | props.y = fb_height; |
||
| 183 | props.scan = fb_scanline; |
||
| 184 | props.visual = visual; |
||
| 185 | fb_init(&props); |
||
| 1897 | jermar | 186 | } |
| 187 | |||
| 188 | /** @} |
||
| 189 | */ |