Subversion Repositories Kolibri OS

Rev

Rev 4560 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright © 2008-2012 Intel Corporation
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21.  * IN THE SOFTWARE.
  22.  *
  23.  * Authors:
  24.  *    Eric Anholt <eric@anholt.net>
  25.  *    Chris Wilson <chris@chris-wilson.co.uk>
  26.  *
  27.  */
  28.  
  29. #include <drm/drmP.h>
  30. #include <drm/i915_drm.h>
  31. #include "i915_drv.h"
  32.  
  33. static struct sg_table *
  34. i915_pages_create_for_fb(struct drm_device *dev,
  35.                  u32 offset, u32 size)
  36. {
  37.     struct drm_i915_private *dev_priv = dev->dev_private;
  38.     struct sg_table *st;
  39.     struct scatterlist *sg;
  40.     addr_t fb_pages;
  41.  
  42.     DRM_DEBUG_DRIVER("offset=0x%x, size=%d\n", offset, size);
  43. //    BUG_ON(offset > dev_priv->gtt.stolen_size - size);
  44.  
  45.     /* We hide that we have no struct page backing our stolen object
  46.      * by wrapping the contiguous physical allocation with a fake
  47.      * dma mapping in a single scatterlist.
  48.      */
  49.  
  50.     st = kmalloc(sizeof(*st), GFP_KERNEL);
  51.     if (st == NULL)
  52.         return NULL;
  53.  
  54.     if (sg_alloc_table(st, 1, GFP_KERNEL)) {
  55.         kfree(st);
  56.         return NULL;
  57.     }
  58.  
  59.     fb_pages = AllocPages(size/PAGE_SIZE);
  60.     if(fb_pages == 0)
  61.     {
  62.         kfree(st);
  63.         return NULL;
  64.     };
  65.  
  66.     sg = st->sgl;
  67.     sg->offset = offset;
  68.     sg->length = size;
  69.  
  70.     sg_dma_address(sg) = (dma_addr_t)fb_pages;
  71.     sg_dma_len(sg) = size;
  72.  
  73.     return st;
  74. }
  75.  
  76.  
  77. static int kos_fb_object_get_pages(struct drm_i915_gem_object *obj)
  78. {
  79.     BUG();
  80.     return -EINVAL;
  81. }
  82.  
  83. static void kos_fb_object_put_pages(struct drm_i915_gem_object *obj)
  84. {
  85.     /* Should only be called during free */
  86.     sg_free_table(obj->pages);
  87.     kfree(obj->pages);
  88. }
  89.  
  90. static const struct drm_i915_gem_object_ops kos_fb_object_ops = {
  91.     .get_pages = kos_fb_object_get_pages,
  92.     .put_pages = kos_fb_object_put_pages,
  93. };
  94.  
  95. static struct drm_i915_gem_object *
  96. _kos_fb_object_create(struct drm_device *dev,
  97.                    struct drm_mm_node *fb_node)
  98. {
  99.     struct drm_i915_gem_object *obj;
  100.  
  101.     obj = i915_gem_object_alloc(dev);
  102.     if (obj == NULL)
  103.         return NULL;
  104.  
  105.     drm_gem_private_object_init(dev, &obj->base, fb_node->size);
  106.     i915_gem_object_init(obj, &kos_fb_object_ops);
  107.  
  108.     obj->pages = i915_pages_create_for_fb(dev,
  109.                           fb_node->start, fb_node->size);
  110.     if (obj->pages == NULL)
  111.         goto cleanup;
  112.  
  113.     obj->has_dma_mapping = true;
  114.     i915_gem_object_pin_pages(obj);
  115.     obj->stolen = fb_node;
  116.  
  117.     obj->base.read_domains = I915_GEM_DOMAIN_GTT;
  118.     obj->cache_level = I915_CACHE_NONE;
  119.     obj->tiling_mode = I915_TILING_X;
  120.  
  121.     return obj;
  122.  
  123. cleanup:
  124.     i915_gem_object_free(obj);
  125.     return NULL;
  126. }
  127.  
  128.  
  129.  
  130.