Subversion Repositories Kolibri OS

Rev

Rev 4080 | 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 <drm/drmP.h>
  32. #include <drm/ttm/ttm_bo_driver.h>
  33. #include "vmwgfx_drv.h"
  34.  
  35.  
  36. #define VMW_PPN_SIZE sizeof(unsigned long)
  37.  
  38. static int vmw_gmr2_bind(struct vmw_private *dev_priv,
  39.                          struct page *pages[],
  40.                          unsigned long num_pages,
  41.                          int gmr_id)
  42. {
  43.         SVGAFifoCmdDefineGMR2 define_cmd;
  44.         SVGAFifoCmdRemapGMR2 remap_cmd;
  45.         uint32_t define_size = sizeof(define_cmd) + 4;
  46.         uint32_t remap_size = VMW_PPN_SIZE * num_pages + sizeof(remap_cmd) + 4;
  47.         uint32_t *cmd;
  48.         uint32_t *cmd_orig;
  49.         uint32_t i;
  50.  
  51.         cmd_orig = cmd = vmw_fifo_reserve(dev_priv, define_size + remap_size);
  52.         if (unlikely(cmd == NULL))
  53.                 return -ENOMEM;
  54.  
  55.         define_cmd.gmrId = gmr_id;
  56.         define_cmd.numPages = num_pages;
  57.  
  58.         remap_cmd.gmrId = gmr_id;
  59.         remap_cmd.flags = (VMW_PPN_SIZE > sizeof(*cmd)) ?
  60.                 SVGA_REMAP_GMR2_PPN64 : SVGA_REMAP_GMR2_PPN32;
  61.         remap_cmd.offsetPages = 0;
  62.         remap_cmd.numPages = num_pages;
  63.  
  64.         *cmd++ = SVGA_CMD_DEFINE_GMR2;
  65.         memcpy(cmd, &define_cmd, sizeof(define_cmd));
  66.         cmd += sizeof(define_cmd) / sizeof(uint32);
  67.  
  68.         *cmd++ = SVGA_CMD_REMAP_GMR2;
  69.         memcpy(cmd, &remap_cmd, sizeof(remap_cmd));
  70.         cmd += sizeof(remap_cmd) / sizeof(uint32);
  71.  
  72.         for (i = 0; i < num_pages; ++i) {
  73.                 if (VMW_PPN_SIZE <= 4)
  74.                         *cmd = page_to_pfn(*pages++);
  75.                 else
  76.                         *((uint64_t *)cmd) = page_to_pfn(*pages++);
  77.  
  78.                 cmd += VMW_PPN_SIZE / sizeof(*cmd);
  79.         }
  80.  
  81.         vmw_fifo_commit(dev_priv, define_size + remap_size);
  82.  
  83.         return 0;
  84. }
  85.  
  86. static void vmw_gmr2_unbind(struct vmw_private *dev_priv,
  87.                             int gmr_id)
  88. {
  89.         SVGAFifoCmdDefineGMR2 define_cmd;
  90.         uint32_t define_size = sizeof(define_cmd) + 4;
  91.         uint32_t *cmd;
  92.  
  93.         cmd = vmw_fifo_reserve(dev_priv, define_size);
  94.         if (unlikely(cmd == NULL)) {
  95.                 DRM_ERROR("GMR2 unbind failed.\n");
  96.                 return;
  97.         }
  98.         define_cmd.gmrId = gmr_id;
  99.         define_cmd.numPages = 0;
  100.  
  101.         *cmd++ = SVGA_CMD_DEFINE_GMR2;
  102.         memcpy(cmd, &define_cmd, sizeof(define_cmd));
  103.  
  104.         vmw_fifo_commit(dev_priv, define_size);
  105. }
  106.  
  107.  
  108. int vmw_gmr_bind(struct vmw_private *dev_priv,
  109.                  struct page *pages[],
  110.                  unsigned long num_pages,
  111.                  int gmr_id)
  112. {
  113.         struct list_head desc_pages;
  114.         int ret;
  115.  
  116.         if (likely(dev_priv->capabilities & SVGA_CAP_GMR2))
  117.                 return vmw_gmr2_bind(dev_priv, pages, num_pages, gmr_id);
  118.  
  119.     printf("%s epic fail\n",__FUNCTION__);
  120.     return -EINVAL;
  121. }
  122.  
  123.  
  124. void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id)
  125. {
  126.         if (likely(dev_priv->capabilities & SVGA_CAP_GMR2)) {
  127.                 vmw_gmr2_unbind(dev_priv, gmr_id);
  128.                 return;
  129.         }
  130.  
  131.         mutex_lock(&dev_priv->hw_mutex);
  132.         vmw_write(dev_priv, SVGA_REG_GMR_ID, gmr_id);
  133.         wmb();
  134.         vmw_write(dev_priv, SVGA_REG_GMR_DESCRIPTOR, 0);
  135.         mb();
  136.         mutex_unlock(&dev_priv->hw_mutex);
  137. }
  138.