Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Copyright © 2007 David Airlie
  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
  21.  * DEALINGS IN THE SOFTWARE.
  22.  *
  23.  * Authors:
  24.  *     David Airlie
  25.  */
  26.  
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/errno.h>
  30. #include <linux/string.h>
  31. //#include <linux/mm.h>
  32. //#include <linux/tty.h>
  33. #include <linux/sysrq.h>
  34. //#include <linux/delay.h>
  35. #include <linux/fb.h>
  36. //#include <linux/init.h>
  37. //#include <linux/vga_switcheroo.h>
  38.  
  39. #include <drm/drmP.h>
  40. #include <drm/drm_crtc.h>
  41. #include <drm/drm_fb_helper.h>
  42. #include "intel_drv.h"
  43. #include <drm/i915_drm.h>
  44. #include "i915_drv.h"
  45.  
  46. static struct drm_i915_gem_object *fb_obj;
  47.  
  48. struct drm_i915_gem_object *get_fb_obj()
  49. {
  50.     return fb_obj;
  51. };
  52.  
  53. struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
  54. {
  55. #define BYTES_PER_LONG (BITS_PER_LONG/8)
  56. #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
  57.     int fb_info_size = sizeof(struct fb_info);
  58.     struct fb_info *info;
  59.     char *p;
  60.  
  61.     if (size)
  62.         fb_info_size += PADDING;
  63.  
  64.     p = kzalloc(fb_info_size + size, GFP_KERNEL);
  65.  
  66.     if (!p)
  67.         return NULL;
  68.  
  69.     info = (struct fb_info *) p;
  70.  
  71.     if (size)
  72.         info->par = p + fb_info_size;
  73.  
  74.     return info;
  75. #undef PADDING
  76. #undef BYTES_PER_LONG
  77. }
  78.  
  79.  
  80. static struct fb_ops intelfb_ops = {
  81.         .owner = THIS_MODULE,
  82.         .fb_check_var = drm_fb_helper_check_var,
  83.         .fb_set_par = drm_fb_helper_set_par,
  84. //   .fb_fillrect = cfb_fillrect,
  85. //   .fb_copyarea = cfb_copyarea,
  86. //   .fb_imageblit = cfb_imageblit,
  87. //   .fb_pan_display = drm_fb_helper_pan_display,
  88.         .fb_blank = drm_fb_helper_blank,
  89. //   .fb_setcmap = drm_fb_helper_setcmap,
  90. //   .fb_debug_enter = drm_fb_helper_debug_enter,
  91. //   .fb_debug_leave = drm_fb_helper_debug_leave,
  92. };
  93.  
  94. static int intelfb_create(struct drm_fb_helper *helper,
  95.                           struct drm_fb_helper_surface_size *sizes)
  96. {
  97.         struct intel_fbdev *ifbdev = (struct intel_fbdev *)helper;
  98.         struct drm_device *dev = ifbdev->helper.dev;
  99.         struct drm_i915_private *dev_priv = dev->dev_private;
  100.         struct fb_info *info;
  101.         struct drm_framebuffer *fb;
  102.         struct drm_mode_fb_cmd2 mode_cmd = {};
  103.         struct drm_i915_gem_object *obj;
  104.         struct device *device = &dev->pdev->dev;
  105.         int size, ret;
  106.  
  107.         /* we don't do packed 24bpp */
  108.         if (sizes->surface_bpp == 24)
  109.                 sizes->surface_bpp = 32;
  110.  
  111.         mode_cmd.width = sizes->surface_width;
  112.         mode_cmd.height = sizes->surface_height;
  113.  
  114.         mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((sizes->surface_bpp + 7) /
  115.                                                       8), 64);
  116.         mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
  117.                                                           sizes->surface_depth);
  118.  
  119.         size = mode_cmd.pitches[0] * mode_cmd.height;
  120.         size = ALIGN(size, PAGE_SIZE);
  121.         obj = i915_gem_alloc_object(dev, size);
  122.         if (!obj) {
  123.                 DRM_ERROR("failed to allocate framebuffer\n");
  124.                 ret = -ENOMEM;
  125.                 goto out;
  126.         }
  127.  
  128.         mutex_lock(&dev->struct_mutex);
  129.  
  130. #if 0
  131. // skip this part and use existing framebiffer
  132.  
  133.         /* Flush everything out, we'll be doing GTT only from now on */
  134.         ret = intel_pin_and_fence_fb_obj(dev, obj, false);
  135.         if (ret) {
  136.                 DRM_ERROR("failed to pin fb: %d\n", ret);
  137.                 goto out_unref;
  138.         }
  139. #endif
  140.  
  141. /***********************************************************************/
  142.     {
  143. #define LFB_SIZE 0xC00000
  144.  
  145.         static struct drm_mm_node lfb_vm_node;
  146.  
  147.         lfb_vm_node.size = LFB_SIZE;
  148.         lfb_vm_node.start = 0;
  149.         lfb_vm_node.mm = NULL;
  150.  
  151.         obj->gtt_space = &lfb_vm_node;
  152.         obj->gtt_offset = 0;
  153.         obj->pin_count = 2;
  154.         obj->cache_level = I915_CACHE_NONE;
  155.             obj->base.write_domain = 0;
  156.             obj->base.read_domains = I915_GEM_DOMAIN_GTT;
  157.  
  158.     }
  159. /***********************************************************************/
  160.  
  161.         info = framebuffer_alloc(0, device);
  162.         if (!info) {
  163.                 ret = -ENOMEM;
  164.                 goto out_unpin;
  165.         }
  166.  
  167.         info->par = ifbdev;
  168.  
  169.         ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj);
  170.         if (ret)
  171.                 goto out_unpin;
  172.  
  173.         fb = &ifbdev->ifb.base;
  174.  
  175.         ifbdev->helper.fb = fb;
  176.         ifbdev->helper.fbdev = info;
  177.  
  178.     strcpy(info->fix.id, "inteldrmfb");
  179.  
  180.     info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
  181.     info->fbops = &intelfb_ops;
  182.  
  183.     /* setup aperture base/size for vesafb takeover */
  184.         info->apertures = alloc_apertures(1);
  185.         if (!info->apertures) {
  186.                 ret = -ENOMEM;
  187.                 goto out_unpin;
  188.         }
  189.         info->apertures->ranges[0].base = dev->mode_config.fb_base;
  190.         info->apertures->ranges[0].size = dev_priv->gtt.mappable_end;
  191.  
  192.         info->fix.smem_start = dev->mode_config.fb_base + obj->gtt_offset;
  193.         info->fix.smem_len = size;
  194.  
  195.         info->screen_base = (void*) 0xFE000000;
  196.         info->screen_size = size;
  197.  
  198. //      memset(info->screen_base, 0, size);
  199.  
  200.         drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
  201.         drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height);
  202.  
  203.         /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
  204.  
  205.         DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08x, bo %p\n",
  206.                       fb->width, fb->height,
  207.                       obj->gtt_offset, obj);
  208.  
  209.  
  210.         mutex_unlock(&dev->struct_mutex);
  211.  
  212.     fb_obj = obj;
  213.  
  214.         return 0;
  215.  
  216. out_unpin:
  217.         i915_gem_object_unpin(obj);
  218. out_unref:
  219.         drm_gem_object_unreference(&obj->base);
  220.         mutex_unlock(&dev->struct_mutex);
  221. out:
  222.         return ret;
  223. }
  224.  
  225. static struct drm_fb_helper_funcs intel_fb_helper_funcs = {
  226.         .gamma_set = intel_crtc_fb_gamma_set,
  227.         .gamma_get = intel_crtc_fb_gamma_get,
  228.         .fb_probe = intelfb_create,
  229. };
  230.  
  231.  
  232. int intel_fbdev_init(struct drm_device *dev)
  233. {
  234.         struct intel_fbdev *ifbdev;
  235.         drm_i915_private_t *dev_priv = dev->dev_private;
  236.         int ret;
  237.  
  238.         ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL);
  239.         if (!ifbdev)
  240.                 return -ENOMEM;
  241.  
  242.         dev_priv->fbdev = ifbdev;
  243.         ifbdev->helper.funcs = &intel_fb_helper_funcs;
  244.  
  245.         ret = drm_fb_helper_init(dev, &ifbdev->helper,
  246.                                  INTEL_INFO(dev)->num_pipes,
  247.                                  INTELFB_CONN_LIMIT);
  248.         if (ret) {
  249.                 kfree(ifbdev);
  250.                 return ret;
  251.         }
  252.  
  253.         drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
  254.  
  255.     return 0;
  256. }
  257.  
  258. void intel_fbdev_initial_config(struct drm_device *dev)
  259. {
  260.         drm_i915_private_t *dev_priv = dev->dev_private;
  261.  
  262.         /* Due to peculiar init order wrt to hpd handling this is separate. */
  263.         drm_fb_helper_initial_config(&dev_priv->fbdev->helper, 32);
  264. }
  265.  
  266. void intel_fb_output_poll_changed(struct drm_device *dev)
  267. {
  268.         drm_i915_private_t *dev_priv = dev->dev_private;
  269.         drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper);
  270. }
  271.