Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2007  Luc Verhaegen <lverhaegen@novell.com>
  3.  * Copyright 2007  Matthias Hopf <mhopf@novell.com>
  4.  * Copyright 2007  Egbert Eich   <eich@novell.com>
  5.  * Copyright 2007  Advanced Micro Devices, Inc.
  6.  *
  7.  * Permission is hereby granted, free of charge, to any person obtaining a
  8.  * copy of this software and associated documentation files (the "Software"),
  9.  * to deal in the Software without restriction, including without limitation
  10.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11.  * and/or sell copies of the Software, and to permit persons to whom the
  12.  * Software is furnished to do so, subject to the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice shall be included in
  15.  * all copies or substantial portions of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  20.  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23.  * OTHER DEALINGS IN THE SOFTWARE.
  24.  */
  25.  
  26. #ifdef HAVE_CONFIG_H
  27. #include "config.h"
  28. #endif
  29.  
  30. #include "xf86.h"
  31. #if HAVE_XF86_ANSIC_H
  32. # include "xf86_ansic.h"
  33. #endif
  34.  
  35. #include "rhd.h"
  36. #include "rhd_vga.h"
  37. #include "rhd_regs.h"
  38. #include "rhd_mc.h"
  39.  
  40. /*
  41.  *
  42.  */
  43. void
  44. RHDVGAInit(RHDPtr rhdPtr)
  45. {
  46.   static struct rhdVGA VGA;
  47.  
  48.   /* Check whether one of our VGA bits is set */
  49.   if (!(_RHDRegRead(rhdPtr, VGA_RENDER_CONTROL) & 0x00030000) &&
  50.        (_RHDRegRead(rhdPtr, VGA_HDP_CONTROL) & 0x00000010) &&
  51.       !(_RHDRegRead(rhdPtr, D1VGA_CONTROL) & 0x00000001) &&
  52.       !(_RHDRegRead(rhdPtr, D2VGA_CONTROL) & 0x00000001))
  53.         return;
  54.  
  55.   DBG(dbgprintf("Detected VGA mode.\n"));
  56.  
  57.   VGA.Stored = FALSE;
  58.   rhdPtr->VGA = &VGA;
  59. }
  60.  
  61. #if 0
  62. /*
  63.  *
  64.  */
  65. void
  66. RHDVGASave(RHDPtr rhdPtr)
  67. {
  68.   struct rhdVGA *VGA = &rhdPtr->VGA;
  69.  
  70.   VGA->Render_Control = _RHDRegRead(rhdPtr, VGA_RENDER_CONTROL);
  71.   VGA->Mode_Control = _RHDRegRead(rhdPtr, VGA_MODE_CONTROL);
  72.   VGA->HDP_Control = _RHDRegRead(rhdPtr, VGA_HDP_CONTROL);
  73.   VGA->D1_Control = _RHDRegRead(rhdPtr, D1VGA_CONTROL);
  74.   VGA->D2_Control = _RHDRegRead(rhdPtr, D2VGA_CONTROL);
  75.  
  76.     /* Store our VGA FB */
  77.   VGA->FBOffset =
  78.     _RHDRegRead(rhdPtr, VGA_MEMORY_BASE_ADDRESS) - rhdPtr->FbIntAddress;
  79.  
  80.   /* Could be that the VGA internal address no longer is pointing to what
  81.      we know as our FB memory, in which case we should give up cleanly. */
  82.   if (VGA->FBOffset < (unsigned) (rhdPtr->videoRam * 1024)) {
  83.     VGA->FBSize = 256 * 1024;
  84.     VGA->FB = calloc(VGA->FBSize, 1);
  85.         if (VGA->FB)
  86.             memcpy(VGA->FB, ((CARD8 *) rhdPtr->FbBase) + VGA->FBOffset,
  87.                    VGA->FBSize);
  88.         else {
  89.       dbgprintf("%s: Failed to allocate"
  90.                 " space for storing the VGA framebuffer.\n", __func__);
  91.             VGA->FBSize = 0;
  92.             VGA->FB = NULL;
  93.         }
  94.     } else {
  95.   dbgprintf("%s: VGA FB Offset (0x%08X) is "
  96.             "out of range of the Cards Internal FB Address (0x%08X)\n",
  97.             __func__, (int) RHDRegRead(rhdPtr, VGA_MEMORY_BASE_ADDRESS),
  98.                    rhdPtr->FbIntAddress);
  99.         VGA->FBOffset = 0xFFFFFFFF;
  100.         VGA->FBSize = 0;
  101.         VGA->FB = NULL;
  102.     }
  103.  
  104.     VGA->Stored = TRUE;
  105. }
  106.  
  107. /*
  108.  *
  109.  */
  110. void
  111. RHDVGARestore(RHDPtr rhdPtr)
  112. {
  113.     struct rhdVGA *VGA = rhdPtr->VGA;
  114.  
  115.     RHDFUNC(rhdPtr);
  116.  
  117.     if (!VGA)
  118.         return; /* We don't need to warn , this is intended use */
  119.  
  120.     if (!VGA->Stored) {
  121.   dbgprintf("%s: trying to restore uninitialized values.\n", __func__);
  122.         return;
  123.     }
  124.  
  125.     if (VGA->FB)
  126.         memcpy(((CARD8 *) rhdPtr->FbBase) + VGA->FBOffset,
  127.                VGA->FB, VGA->FBSize);
  128.  
  129.     RHDRegWrite(rhdPtr, VGA_RENDER_CONTROL, VGA->Render_Control);
  130.     RHDRegWrite(rhdPtr, VGA_MODE_CONTROL, VGA->Mode_Control);
  131.     RHDRegWrite(rhdPtr, VGA_HDP_CONTROL, VGA->HDP_Control);
  132.     RHDRegWrite(rhdPtr, D1VGA_CONTROL, VGA->D1_Control);
  133.     RHDRegWrite(rhdPtr, D2VGA_CONTROL, VGA->D2_Control);
  134. }
  135. #endif
  136. /*
  137.  *
  138.  */
  139. void
  140. RHDVGADisable(RHDPtr rhdPtr)
  141. {
  142.     RHDFUNC(rhdPtr);
  143.  
  144.     _RHDRegMask(rhdPtr, VGA_RENDER_CONTROL, 0, 0x00030000);
  145.     _RHDRegMask(rhdPtr, VGA_MODE_CONTROL, 0, 0x00000030);
  146.     _RHDRegMask(rhdPtr, VGA_HDP_CONTROL, 0x00010010, 0x00010010);
  147.     _RHDRegMask(rhdPtr, D1VGA_CONTROL, 0, 0x00000001);
  148.     _RHDRegMask(rhdPtr, D2VGA_CONTROL, 0, 0x00000001);
  149. }
  150.  
  151. /*
  152.  *
  153.  */
  154. void
  155. RHDVGADestroy(RHDPtr rhdPtr)
  156. {
  157.     struct rhdVGA *VGA = rhdPtr->VGA;
  158.  
  159.     RHDFUNC(rhdPtr);
  160.  
  161.     if (!VGA)
  162.       return; /* We don't need to warn , this is intended use */
  163.  
  164.     if (VGA->FB)
  165.       free(VGA->FB);
  166.     rhdPtr->VGA=NULL;
  167. }
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.