Subversion Repositories HelenOS

Rev

Rev 3618 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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/fb/fb.h>
  38. #include <genarch/fb/visuals.h>
  39. #include <arch/types.h>
  40. #include <func.h>
  41. #include <align.h>
  42. #include <print.h>
  43.  
  44. #define FFB_REG_24BPP   7
  45.  
  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,XVR-100") == 0)
  65.         scr_type = SCR_XVR;
  66.     else if (strcmp(name, "SUNW,ffb") == 0)
  67.         scr_type = SCR_FFB;
  68.     else if (strcmp(name, "cgsix") == 0)
  69.         scr_type = SCR_CGSIX;
  70.    
  71.     if (scr_type == SCR_UNKNOWN) {
  72.         printf("Unknown screen device.\n");
  73.         return;
  74.     }
  75.    
  76.     uintptr_t fb_addr;
  77.     uint32_t fb_width = 0;
  78.     uint32_t fb_height = 0;
  79.     uint32_t fb_depth = 0;
  80.     uint32_t fb_linebytes = 0;
  81.     uint32_t fb_scanline = 0;
  82.     unsigned int visual;
  83.  
  84.     prop = ofw_tree_getprop(node, "width");
  85.     if (prop && prop->value)
  86.         fb_width = *((uint32_t *) prop->value);
  87.  
  88.     prop = ofw_tree_getprop(node, "height");
  89.     if (prop && prop->value)
  90.         fb_height = *((uint32_t *) prop->value);
  91.  
  92.     prop = ofw_tree_getprop(node, "depth");
  93.     if (prop && prop->value)
  94.         fb_depth = *((uint32_t *) prop->value);
  95.  
  96.     prop = ofw_tree_getprop(node, "linebytes");
  97.     if (prop && prop->value)
  98.         fb_linebytes = *((uint32_t *) prop->value);
  99.  
  100.     prop = ofw_tree_getprop(node, "reg");
  101.     if (!prop)
  102.         panic("Can't find \"reg\" property.\n");
  103.  
  104.     switch (scr_type) {
  105.     case SCR_ATYFB:
  106.         if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
  107.             printf("Too few screen registers.\n");
  108.             return;
  109.         }
  110.    
  111.         ofw_pci_reg_t *fb_reg = &((ofw_pci_reg_t *) prop->value)[1];
  112.         ofw_pci_reg_t abs_reg;
  113.        
  114.         if (!ofw_pci_reg_absolutize(node, fb_reg, &abs_reg)) {
  115.             printf("Failed to absolutize fb register.\n");
  116.             return;
  117.         }
  118.    
  119.         if (!ofw_pci_apply_ranges(node->parent, &abs_reg , &fb_addr)) {
  120.             printf("Failed to determine screen address.\n");
  121.             return;
  122.         }
  123.        
  124.         switch (fb_depth) {
  125.         case 8:
  126.             fb_scanline = fb_linebytes * (fb_depth >> 3);
  127.             visual = VISUAL_INDIRECT_8;
  128.             break;
  129.         case 16:
  130.             fb_scanline = fb_linebytes * (fb_depth >> 3);
  131.             visual = VISUAL_RGB_5_6_5;
  132.             break;
  133.         case 24:
  134.             fb_scanline = fb_linebytes * 4;
  135.             visual = VISUAL_RGB_8_8_8_0;
  136.             break;
  137.         case 32:
  138.             fb_scanline = fb_linebytes * (fb_depth >> 3);
  139.             visual = VISUAL_RGB_0_8_8_8;
  140.             break;
  141.         default:
  142.             printf("Unsupported bits per pixel.\n");
  143.             return;
  144.         }
  145.        
  146.         break;
  147.     case SCR_XVR:
  148.     {
  149.         if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
  150.             printf("Too few screen registers.\n");
  151.             return;
  152.         }
  153.    
  154.         ofw_pci_reg_t *fb_reg = &((ofw_pci_reg_t *) prop->value)[1];
  155.         ofw_pci_reg_t abs_reg;
  156.        
  157.         if (!ofw_pci_reg_absolutize(node, fb_reg, &abs_reg)) {
  158.             printf("Failed to absolutize fb register.\n");
  159.             return;
  160.         }
  161.    
  162.         if (!ofw_pci_apply_ranges(node->parent, &abs_reg , &fb_addr)) {
  163.             printf("Failed to determine screen address.\n");
  164.             return;
  165.         }
  166.  
  167.         switch (fb_depth) {
  168.         case 8:
  169.             fb_scanline = fb_linebytes * (fb_depth >> 3);
  170.             visual = VISUAL_SB1500_PALETTE;
  171.             break;
  172.         case 16:
  173.             fb_scanline = fb_linebytes * (fb_depth >> 3);
  174.             visual = VISUAL_RGB_5_6_5;
  175.             break;
  176.         case 24:
  177.             fb_scanline = fb_linebytes * 4;
  178.             visual = VISUAL_RGB_8_8_8_0;
  179.             break;
  180.         case 32:
  181.             fb_scanline = fb_linebytes * (fb_depth >> 3);
  182.             visual = VISUAL_RGB_0_8_8_8;
  183.             break;
  184.         default:
  185.             printf("Unsupported bits per pixel.\n");
  186.             return;
  187.         }
  188.        
  189.         break;
  190.     }
  191.     case SCR_FFB:  
  192.         fb_scanline = 8192;
  193.         visual = VISUAL_BGR_0_8_8_8;
  194.  
  195.         ofw_upa_reg_t *reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP];
  196.         if (!ofw_upa_apply_ranges(node->parent, reg, &fb_addr)) {
  197.             printf("Failed to determine screen address.\n");
  198.             return;
  199.         }
  200.  
  201.         break;
  202.     case SCR_CGSIX:
  203.         switch (fb_depth) {
  204.         case 8:
  205.             fb_scanline = fb_linebytes;
  206.             visual = VISUAL_INDIRECT_8;
  207.             break;
  208.         default:
  209.             printf("Not implemented.\n");
  210.             return;
  211.         }
  212.        
  213.         ofw_sbus_reg_t *cg6_reg = &((ofw_sbus_reg_t *) prop->value)[0];
  214.         if (!ofw_sbus_apply_ranges(node->parent, cg6_reg, &fb_addr)) {
  215.             printf("Failed to determine screen address.\n");
  216.             return;
  217.         }
  218.    
  219.         break;
  220.     default:
  221.         panic("Unexpected type.\n");
  222.     }
  223.  
  224.     fb_properties_t props;
  225.     props.addr = fb_addr;
  226.     props.fb_start = 0;
  227.     props.x = fb_width;
  228.     props.y = fb_height;
  229.     props.scan = fb_scanline;
  230.     props.visual = visual;
  231.     fb_init(&props);
  232. }
  233.  
  234. /** @}
  235.  */
  236.