Subversion Repositories Kolibri OS

Rev

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

  1. /**************************************************************************
  2.  
  3. Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
  4. Copyright © 2002 David Dawes
  5.  
  6. All Rights Reserved.
  7.  
  8. Permission is hereby granted, free of charge, to any person obtaining a
  9. copy of this software and associated documentation files (the
  10. "Software"), to deal in the Software without restriction, including
  11. without limitation the rights to use, copy, modify, merge, publish,
  12. distribute, sub license, and/or sell copies of the Software, and to
  13. permit persons to whom the Software is furnished to do so, subject to
  14. the following conditions:
  15.  
  16. The above copyright notice and this permission notice (including the
  17. next paragraph) shall be included in all copies or substantial portions
  18. of the Software.
  19.  
  20. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
  24. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27.  
  28. **************************************************************************/
  29.  
  30. /*
  31.  * Authors:
  32.  *   Keith Whitwell <keith@tungstengraphics.com>
  33.  *   David Dawes <dawes@xfree86.org>
  34.  *
  35.  */
  36.  
  37. #ifdef HAVE_CONFIG_H
  38. #include "config.h"
  39. #endif
  40.  
  41. #if 0
  42. #define I830DEBUG
  43. #endif
  44.  
  45. #include <stdint.h>
  46.  
  47. #ifndef REMAP_RESERVED
  48. #define REMAP_RESERVED 0
  49. #endif
  50.  
  51. #include "picture.h"
  52. #include <pciaccess.h>
  53. #include "intel_bufmgr.h"
  54. #include "i915_drm.h"
  55.  
  56. #include "intel_driver.h"
  57. #include "intel_list.h"
  58.  
  59. # define ENTER() printf("ENTER %s\n", __FUNCTION__)
  60. # define LEAVE() printf("LEAVE %s\n", __FUNCTION__)
  61. # define FAIL() printf("FAIL %s\n", __FUNCTION__)
  62.  
  63. typedef int ScrnInfoPtr;
  64. typedef int ScreenPtr;
  65.  
  66. typedef int Bool;
  67.  
  68. #define  TRUE  (Bool)(1)
  69. #define  FALSE (Bool)(0)
  70.  
  71. typedef struct pixman_transform PictTransform, *PictTransformPtr;
  72. typedef struct _Pixmap  *PixmapPtr;
  73. typedef struct _Picture *PicturePtr;
  74.  
  75. /* remain compatible to xorg-server 1.6 */
  76. #ifndef MONITOR_EDID_COMPLETE_RAWDATA
  77. #define MONITOR_EDID_COMPLETE_RAWDATA EDID_COMPLETE_RAWDATA
  78. #endif
  79.  
  80. #if XF86_CRTC_VERSION >= 5
  81. #define INTEL_PIXMAP_SHARING 1
  82. #endif
  83.  
  84. struct intel_pixmap {
  85.         dri_bo *bo;
  86.  
  87.         struct list batch;
  88.  
  89.         uint16_t stride;
  90.         uint8_t tiling;
  91.         int8_t busy :2;
  92.         uint8_t dirty :1;
  93.         uint8_t offscreen :1;
  94.         uint8_t pinned :3;
  95. #define PIN_SCANOUT 0x1
  96. #define PIN_DRI 0x2
  97. #define PIN_GLAMOR 0x4
  98. };
  99.  
  100. #if HAS_DEVPRIVATEKEYREC
  101. extern DevPrivateKeyRec uxa_pixmap_index;
  102. #else
  103. extern int uxa_pixmap_index;
  104. #endif
  105.  
  106. /*
  107. static inline struct intel_pixmap *intel_get_pixmap_private(PixmapPtr pixmap)
  108. {
  109. #if HAS_DEVPRIVATEKEYREC
  110.         return dixGetPrivate(&pixmap->devPrivates, &uxa_pixmap_index);
  111. #else
  112.         return dixLookupPrivate(&pixmap->devPrivates, &uxa_pixmap_index);
  113. #endif
  114. }
  115. */
  116.  
  117. static inline Bool intel_pixmap_is_busy(struct intel_pixmap *priv)
  118. {
  119.         if (priv->busy == -1)
  120.                 priv->busy = drm_intel_bo_busy(priv->bo);
  121.         return priv->busy;
  122. }
  123.  
  124. static inline void intel_set_pixmap_private(PixmapPtr pixmap, struct intel_pixmap *intel)
  125. {
  126.         dixSetPrivate(&pixmap->devPrivates, &uxa_pixmap_index, intel);
  127. }
  128.  
  129. static inline Bool intel_pixmap_is_dirty(PixmapPtr pixmap)
  130. {
  131.         return pixmap && pixmap->private->dirty;
  132. }
  133.  
  134. static inline Bool intel_pixmap_tiled(PixmapPtr pixmap)
  135. {
  136.         return pixmap->private->tiling != I915_TILING_NONE;
  137. }
  138.  
  139. dri_bo *intel_get_pixmap_bo(PixmapPtr pixmap);
  140. void intel_set_pixmap_bo(PixmapPtr pixmap, dri_bo * bo);
  141.  
  142. #include "common.h"
  143.  
  144. #define PITCH_NONE 0
  145.  
  146. /** enumeration of 3d consumers so some can maintain invariant state. */
  147. enum last_3d {
  148.     LAST_3D_OTHER,
  149.     LAST_3D_VIDEO,
  150.     LAST_3D_RENDER,
  151.     LAST_3D_ROTATION
  152. };
  153.  
  154. enum dri_type {
  155.         DRI_DISABLED,
  156.         DRI_NONE,
  157.         DRI_DRI2
  158. };
  159.  
  160. typedef struct intel_screen_private {
  161.         int scrn;
  162.     int cpp;
  163.  
  164. #define RENDER_BATCH                I915_EXEC_RENDER
  165. #define BLT_BATCH                   I915_EXEC_BLT
  166.         unsigned int current_batch;
  167.  
  168.         void *modes;
  169.         drm_intel_bo *front_buffer, *back_buffer;
  170.         PixmapPtr back_pixmap;
  171.         unsigned int back_name;
  172.         long front_pitch, front_tiling;
  173.  
  174.     dri_bufmgr *bufmgr;
  175.  
  176.     uint32_t batch_ptr[4096];
  177.     /** Byte offset in batch_ptr for the next dword to be emitted. */
  178.     unsigned int batch_used;
  179.     /** Position in batch_ptr at the start of the current BEGIN_BATCH */
  180.     unsigned int batch_emit_start;
  181.     /** Number of bytes to be emitted in the current BEGIN_BATCH. */
  182.     uint32_t batch_emitting;
  183.     dri_bo *batch_bo, *last_batch_bo[2];
  184.     /** Whether we're in a section of code that can't tolerate flushing */
  185.     Bool in_batch_atomic;
  186.     /** Ending batch_used that was verified by intel_start_batch_atomic() */
  187.     int batch_atomic_limit;
  188.     struct list batch_pixmaps;
  189.     drm_intel_bo *wa_scratch_bo;
  190.  
  191.     unsigned int tiling;
  192. #define INTEL_TILING_FB     0x1
  193. #define INTEL_TILING_2D     0x2
  194. #define INTEL_TILING_3D     0x4
  195. #define INTEL_TILING_ALL   (~0)
  196.  
  197.         Bool swapbuffers_wait;
  198.     Bool has_relaxed_fencing;
  199.  
  200.     int Chipset;
  201.         struct pci_device *PciInfo;
  202.         const struct intel_device_info *info;
  203.  
  204.     unsigned int BR[20];
  205.  
  206.         void (*context_switch) (struct intel_screen_private *intel,
  207.                                 int new_mode);
  208.     void (*vertex_flush) (struct intel_screen_private *intel);
  209.     void (*batch_flush) (struct intel_screen_private *intel);
  210.     void (*batch_commit_notify) (struct intel_screen_private *intel);
  211.  
  212.     Bool need_sync;
  213.     int accel_pixmap_offset_alignment;
  214.     int accel_max_x;
  215.     int accel_max_y;
  216.     int max_bo_size;
  217.     int max_gtt_map_size;
  218.     int max_tiling_size;
  219.  
  220.     struct {
  221.         drm_intel_bo *gen4_vs_bo;
  222.         drm_intel_bo *gen4_sf_bo;
  223.         drm_intel_bo *gen4_wm_packed_bo;
  224.         drm_intel_bo *gen4_wm_planar_bo;
  225.         drm_intel_bo *gen4_cc_bo;
  226.         drm_intel_bo *gen4_cc_vp_bo;
  227.         drm_intel_bo *gen4_sampler_bo;
  228.         drm_intel_bo *gen4_sip_kernel_bo;
  229.         drm_intel_bo *wm_prog_packed_bo;
  230.         drm_intel_bo *wm_prog_planar_bo;
  231.         drm_intel_bo *gen6_blend_bo;
  232.         drm_intel_bo *gen6_depth_stencil_bo;
  233.     } video;
  234.  
  235.     /* Render accel state */
  236.     float scale_units[2][2];
  237.     /** Transform pointers for src/mask, or NULL if identity */
  238.     PictTransform *transform[2];
  239.  
  240.     PixmapPtr render_source, render_mask, render_dest;
  241.     PicturePtr render_source_picture, render_mask_picture, render_dest_picture;
  242.     Bool needs_3d_invariant;
  243.     Bool needs_render_state_emit;
  244.     Bool needs_render_vertex_emit;
  245.  
  246.     /* i830 render accel state */
  247.     uint32_t render_dest_format;
  248.     uint32_t cblend, ablend, s8_blendctl;
  249.  
  250.     /* i915 render accel state */
  251.     PixmapPtr texture[2];
  252.     uint32_t mapstate[6];
  253.     uint32_t samplerstate[6];
  254.  
  255.     struct {
  256.         int op;
  257.         uint32_t dst_format;
  258.     } i915_render_state;
  259.  
  260.     struct {
  261.         int num_sf_outputs;
  262.         int drawrect;
  263.         uint32_t blend;
  264.         dri_bo *samplers;
  265.         dri_bo *kernel;
  266.     } gen6_render_state;
  267.  
  268.     uint32_t prim_offset;
  269.     void (*prim_emit)(struct intel_screen_private *intel,
  270.               int srcX, int srcY,
  271.               int maskX, int maskY,
  272.               int dstX, int dstY,
  273.               int w, int h);
  274.     int floats_per_vertex;
  275.     int last_floats_per_vertex;
  276.     uint16_t vertex_offset;
  277.     uint16_t vertex_count;
  278.     uint16_t vertex_index;
  279.     uint16_t vertex_used;
  280.     uint32_t vertex_id;
  281.     float vertex_ptr[4*1024];
  282.     dri_bo *vertex_bo;
  283.  
  284.     uint8_t surface_data[16*1024];
  285.     uint16_t surface_used;
  286.     uint16_t surface_table;
  287.     uint32_t surface_reloc;
  288.     dri_bo *surface_bo;
  289.  
  290.     /* 965 render acceleration state */
  291.     struct gen4_render_state *gen4_render_state;
  292.  
  293.     Bool use_pageflipping;
  294.     Bool use_triple_buffer;
  295.     Bool force_fallback;
  296.     Bool has_kernel_flush;
  297.     Bool needs_flush;
  298.  
  299.     enum last_3d last_3d;
  300.  
  301.     /**
  302.      * User option to print acceleration fallback info to the server log.
  303.      */
  304.     Bool fallback_debug;
  305.     unsigned debug_flush;
  306.     Bool has_prime_vmap_flush;
  307. } intel_screen_private;
  308.  
  309. #define INTEL_INFO(intel) ((intel)->info)
  310. #define IS_GENx(intel, X) (INTEL_INFO(intel)->gen >= 8*(X) && INTEL_INFO(intel)->gen < 8*((X)+1))
  311. #define IS_GEN1(intel) IS_GENx(intel, 1)
  312. #define IS_GEN2(intel) IS_GENx(intel, 2)
  313. #define IS_GEN3(intel) IS_GENx(intel, 3)
  314. #define IS_GEN4(intel) IS_GENx(intel, 4)
  315. #define IS_GEN5(intel) IS_GENx(intel, 5)
  316. #define IS_GEN6(intel) IS_GENx(intel, 6)
  317. #define IS_GEN7(intel) IS_GENx(intel, 7)
  318. #define IS_HSW(intel) (INTEL_INFO(intel)->gen == 075)
  319.  
  320. /* Some chips have specific errata (or limits) that we need to workaround. */
  321. #define IS_I830(intel) ((intel)->PciInfo->device_id == PCI_CHIP_I830_M)
  322. #define IS_845G(intel) ((intel)->PciInfo->device_id == PCI_CHIP_845_G)
  323. #define IS_I865G(intel) ((intel)->PciInfo->device_id == PCI_CHIP_I865_G)
  324.  
  325. #define IS_I915G(pI810) ((intel)->PciInfo->device_id == PCI_CHIP_I915_G || (intel)->PciInfo->device_id == PCI_CHIP_E7221_G)
  326. #define IS_I915GM(pI810) ((intel)->PciInfo->device_id == PCI_CHIP_I915_GM)
  327.  
  328. #define IS_965_Q(pI810) ((intel)->PciInfo->device_id == PCI_CHIP_I965_Q)
  329.  
  330. /* supports Y tiled surfaces (pre-965 Mesa isn't ready yet) */
  331. #define SUPPORTS_YTILING(pI810) (INTEL_INFO(intel)->gen >= 040)
  332. #define HAS_BLT(pI810) (INTEL_INFO(intel)->gen >= 060)
  333.  
  334. #ifndef I915_PARAM_HAS_PRIME_VMAP_FLUSH
  335. #define I915_PARAM_HAS_PRIME_VMAP_FLUSH 21
  336. #endif
  337.  
  338. enum {
  339.         DEBUG_FLUSH_BATCHES = 0x1,
  340.         DEBUG_FLUSH_CACHES = 0x2,
  341.         DEBUG_FLUSH_WAIT = 0x4,
  342. };
  343.  
  344. extern intel_screen_private *driverPrivate;
  345.  
  346. static inline intel_screen_private *
  347. intel_get_screen_private()
  348. {
  349.         return driverPrivate;
  350. }
  351.  
  352. #ifndef ARRAY_SIZE
  353. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
  354. #endif
  355.  
  356. #ifndef ALIGN
  357. #define ALIGN(i,m)      (((i) + (m) - 1) & ~((m) - 1))
  358. #endif
  359.  
  360. #ifndef MIN
  361. #define MIN(a,b)        ((a) < (b) ? (a) : (b))
  362. #endif
  363.  
  364. static inline unsigned long intel_pixmap_pitch(PixmapPtr pixmap)
  365. {
  366.         return (unsigned long)pixmap->devKind;
  367. }
  368.  
  369. /* Batchbuffer support macros and functions */
  370. #include "intel_batchbuffer.h"
  371. void i965_vertex_flush(intel_screen_private *intel);
  372. void i965_batch_flush(intel_screen_private *intel);
  373. void i965_batch_commit_notify(intel_screen_private *intel);
  374. /**
  375.  * Little wrapper around drm_intel_bo_reloc to return the initial value you
  376.  * should stuff into the relocation entry.
  377.  *
  378.  * If only we'd done this before settling on the library API.
  379.  */
  380. static inline uint32_t
  381. intel_emit_reloc(drm_intel_bo * bo, uint32_t offset,
  382.                  drm_intel_bo * target_bo, uint32_t target_offset,
  383.                  uint32_t read_domains, uint32_t write_domain)
  384. {
  385.         drm_intel_bo_emit_reloc(bo, offset, target_bo, target_offset,
  386.                                 read_domains, write_domain);
  387.  
  388.         return target_bo->offset + target_offset;
  389. }
  390.  
  391. static inline drm_intel_bo *intel_bo_alloc_for_data(intel_screen_private *intel,
  392.                                                     const void *data,
  393.                                                     unsigned int size,
  394.                                                     const char *name)
  395. {
  396.         drm_intel_bo *bo;
  397.         int ret;
  398.  
  399.         bo = drm_intel_bo_alloc(intel->bufmgr, name, size, 4096);
  400.         assert(bo);
  401.  
  402.         ret = drm_intel_bo_subdata(bo, 0, size, data);
  403.         assert(ret == 0);
  404.  
  405.         return bo;
  406.         (void)ret;
  407. }
  408.