Subversion Repositories Kolibri OS

Rev

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

  1. /**************************************************************************
  2.  *
  3.  * Copyright © 2009-2011 VMware, Inc., Palo Alto, CA., USA
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21.  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24.  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27. #define mb()    asm volatile("mfence" : : : "memory")
  28. #define rmb()   asm volatile("lfence" : : : "memory")
  29. #define wmb()   asm volatile("sfence" : : : "memory")
  30.  
  31. #include "vmwgfx_drv.h"
  32. #include <drm/drmP.h>
  33. #include <drm/ttm/ttm_bo_driver.h>
  34.  
  35. #define VMW_PPN_SIZE sizeof(unsigned long)
  36.  
  37. static int vmw_gmr2_bind(struct vmw_private *dev_priv,
  38.                          struct page *pages[],
  39.                          unsigned long num_pages,
  40.                          int gmr_id)
  41. {
  42.         SVGAFifoCmdDefineGMR2 define_cmd;
  43.         SVGAFifoCmdRemapGMR2 remap_cmd;
  44.         uint32_t define_size = sizeof(define_cmd) + 4;
  45.         uint32_t remap_size = VMW_PPN_SIZE * num_pages + sizeof(remap_cmd) + 4;
  46.         uint32_t *cmd;
  47.         uint32_t *cmd_orig;
  48.         uint32_t i;
  49.  
  50.         cmd_orig = cmd = vmw_fifo_reserve(dev_priv, define_size + remap_size);
  51.         if (unlikely(cmd == NULL))
  52.                 return -ENOMEM;
  53.  
  54.         define_cmd.gmrId = gmr_id;
  55.         define_cmd.numPages = num_pages;
  56.  
  57.         remap_cmd.gmrId = gmr_id;
  58.         remap_cmd.flags = (VMW_PPN_SIZE > sizeof(*cmd)) ?
  59.                 SVGA_REMAP_GMR2_PPN64 : SVGA_REMAP_GMR2_PPN32;
  60.         remap_cmd.offsetPages = 0;
  61.         remap_cmd.numPages = num_pages;
  62.  
  63.         *cmd++ = SVGA_CMD_DEFINE_GMR2;
  64.         memcpy(cmd, &define_cmd, sizeof(define_cmd));
  65.         cmd += sizeof(define_cmd) / sizeof(uint32);
  66.  
  67.         *cmd++ = SVGA_CMD_REMAP_GMR2;
  68.         memcpy(cmd, &remap_cmd, sizeof(remap_cmd));
  69.         cmd += sizeof(remap_cmd) / sizeof(uint32);
  70.  
  71.         for (i = 0; i < num_pages; ++i) {
  72.                 if (VMW_PPN_SIZE <= 4)
  73.                         *cmd = page_to_pfn(*pages++);
  74.                 else
  75.                         *((uint64_t *)cmd) = page_to_pfn(*pages++);
  76.  
  77.                 cmd += VMW_PPN_SIZE / sizeof(*cmd);
  78.         }
  79.  
  80.         vmw_fifo_commit(dev_priv, define_size + remap_size);
  81.  
  82.         return 0;
  83. }
  84.  
  85. static void vmw_gmr2_unbind(struct vmw_private *dev_priv,
  86.                             int gmr_id)
  87. {
  88.         SVGAFifoCmdDefineGMR2 define_cmd;
  89.         uint32_t define_size = sizeof(define_cmd) + 4;
  90.         uint32_t *cmd;
  91.  
  92.         cmd = vmw_fifo_reserve(dev_priv, define_size);
  93.         if (unlikely(cmd == NULL)) {
  94.                 DRM_ERROR("GMR2 unbind failed.\n");
  95.                 return;
  96.         }
  97.         define_cmd.gmrId = gmr_id;
  98.         define_cmd.numPages = 0;
  99.  
  100.         *cmd++ = SVGA_CMD_DEFINE_GMR2;
  101.         memcpy(cmd, &define_cmd, sizeof(define_cmd));
  102.  
  103.         vmw_fifo_commit(dev_priv, define_size);
  104. }
  105.  
  106.  
  107. int vmw_gmr_bind(struct vmw_private *dev_priv,
  108.                  struct page *pages[],
  109.                  unsigned long num_pages,
  110.                  int gmr_id)
  111. {
  112.         struct list_head desc_pages;
  113.         int ret;
  114.  
  115.         if (likely(dev_priv->capabilities & SVGA_CAP_GMR2))
  116.                 return vmw_gmr2_bind(dev_priv, pages, num_pages, gmr_id);
  117.  
  118.     printf("%s epic fail\n",__FUNCTION__);
  119.     return -EINVAL;
  120. }
  121.  
  122.  
  123. void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id)
  124. {
  125.         if (likely(dev_priv->capabilities & SVGA_CAP_GMR2)) {
  126.                 vmw_gmr2_unbind(dev_priv, gmr_id);
  127.                 return;
  128.         }
  129.  
  130.         mutex_lock(&dev_priv->hw_mutex);
  131.         vmw_write(dev_priv, SVGA_REG_GMR_ID, gmr_id);
  132.         wmb();
  133.         vmw_write(dev_priv, SVGA_REG_GMR_DESCRIPTOR, 0);
  134.         mb();
  135.         mutex_unlock(&dev_priv->hw_mutex);
  136. }
  137.