Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
  3.  * Copyright 2010 Marek Olšák <maraeo@gmail.com>
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the "Software"),
  7.  * to deal in the Software without restriction, including without limitation
  8.  * on the rights to use, copy, modify, merge, publish, distribute, sub
  9.  * license, and/or sell copies of the Software, and to permit persons to whom
  10.  * the Software is furnished to do so, subject to the following conditions:
  11.  *
  12.  * The above copyright notice and this permission notice (including the next
  13.  * paragraph) shall be included in all copies or substantial portions of the
  14.  * Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19.  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22.  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
  23.  
  24. #ifndef RADEON_WINSYS_H
  25. #define RADEON_WINSYS_H
  26.  
  27. /* The public winsys interface header for the radeon driver. */
  28.  
  29. /* R300 features in DRM.
  30.  *
  31.  * 2.6.0:
  32.  * - Hyper-Z
  33.  * - GB_Z_PEQ_CONFIG on rv350->r4xx
  34.  * - R500 FG_ALPHA_VALUE
  35.  *
  36.  * 2.8.0:
  37.  * - R500 US_FORMAT regs
  38.  * - R500 ARGB2101010 colorbuffer
  39.  * - CMask and AA regs
  40.  * - R16F/RG16F
  41.  */
  42.  
  43. #include "pipebuffer/pb_buffer.h"
  44. #include "libdrm/radeon_surface.h"
  45.  
  46. #define RADEON_MAX_CMDBUF_DWORDS (16 * 1024)
  47.  
  48. #define RADEON_FLUSH_ASYNC              (1 << 0)
  49. #define RADEON_FLUSH_KEEP_TILING_FLAGS  (1 << 1) /* needs DRM 2.12.0 */
  50. #define RADEON_FLUSH_COMPUTE            (1 << 2)
  51. #define RADEON_FLUSH_END_OF_FRAME       (1 << 3)
  52.  
  53. /* Tiling flags. */
  54. enum radeon_bo_layout {
  55.     RADEON_LAYOUT_LINEAR = 0,
  56.     RADEON_LAYOUT_TILED,
  57.     RADEON_LAYOUT_SQUARETILED,
  58.  
  59.     RADEON_LAYOUT_UNKNOWN
  60. };
  61.  
  62. enum radeon_bo_domain { /* bitfield */
  63.     RADEON_DOMAIN_GTT  = 2,
  64.     RADEON_DOMAIN_VRAM = 4
  65. };
  66.  
  67. enum radeon_bo_usage { /* bitfield */
  68.     RADEON_USAGE_READ = 2,
  69.     RADEON_USAGE_WRITE = 4,
  70.     RADEON_USAGE_READWRITE = RADEON_USAGE_READ | RADEON_USAGE_WRITE
  71. };
  72.  
  73. enum radeon_family {
  74.     CHIP_UNKNOWN = 0,
  75.     CHIP_R300, /* R3xx-based cores. */
  76.     CHIP_R350,
  77.     CHIP_RV350,
  78.     CHIP_RV370,
  79.     CHIP_RV380,
  80.     CHIP_RS400,
  81.     CHIP_RC410,
  82.     CHIP_RS480,
  83.     CHIP_R420,     /* R4xx-based cores. */
  84.     CHIP_R423,
  85.     CHIP_R430,
  86.     CHIP_R480,
  87.     CHIP_R481,
  88.     CHIP_RV410,
  89.     CHIP_RS600,
  90.     CHIP_RS690,
  91.     CHIP_RS740,
  92.     CHIP_RV515,    /* R5xx-based cores. */
  93.     CHIP_R520,
  94.     CHIP_RV530,
  95.     CHIP_R580,
  96.     CHIP_RV560,
  97.     CHIP_RV570,
  98.     CHIP_R600,
  99.     CHIP_RV610,
  100.     CHIP_RV630,
  101.     CHIP_RV670,
  102.     CHIP_RV620,
  103.     CHIP_RV635,
  104.     CHIP_RS780,
  105.     CHIP_RS880,
  106.     CHIP_RV770,
  107.     CHIP_RV730,
  108.     CHIP_RV710,
  109.     CHIP_RV740,
  110.     CHIP_CEDAR,
  111.     CHIP_REDWOOD,
  112.     CHIP_JUNIPER,
  113.     CHIP_CYPRESS,
  114.     CHIP_HEMLOCK,
  115.     CHIP_PALM,
  116.     CHIP_SUMO,
  117.     CHIP_SUMO2,
  118.     CHIP_BARTS,
  119.     CHIP_TURKS,
  120.     CHIP_CAICOS,
  121.     CHIP_CAYMAN,
  122.     CHIP_ARUBA,
  123.     CHIP_TAHITI,
  124.     CHIP_PITCAIRN,
  125.     CHIP_VERDE,
  126.     CHIP_OLAND,
  127.     CHIP_HAINAN,
  128.     CHIP_BONAIRE,
  129.     CHIP_KAVERI,
  130.     CHIP_KABINI,
  131.     CHIP_LAST,
  132. };
  133.  
  134. enum chip_class {
  135.     CLASS_UNKNOWN = 0,
  136.     R300,
  137.     R400,
  138.     R500,
  139.     R600,
  140.     R700,
  141.     EVERGREEN,
  142.     CAYMAN,
  143.     SI,
  144.     CIK,
  145. };
  146.  
  147. enum ring_type {
  148.     RING_GFX = 0,
  149.     RING_DMA,
  150.     RING_UVD,
  151.     RING_LAST,
  152. };
  153.  
  154. enum radeon_value_id {
  155.     RADEON_REQUESTED_VRAM_MEMORY,
  156.     RADEON_REQUESTED_GTT_MEMORY,
  157.     RADEON_BUFFER_WAIT_TIME_NS,
  158.     RADEON_TIMESTAMP
  159. };
  160.  
  161. struct winsys_handle;
  162. struct radeon_winsys_cs_handle;
  163.  
  164. struct radeon_winsys_cs {
  165.     unsigned                    cdw;  /* Number of used dwords. */
  166.     uint32_t                    *buf; /* The command buffer. */
  167.     enum ring_type              ring_type;
  168. };
  169.  
  170. struct radeon_info {
  171.     uint32_t                    pci_id;
  172.     enum radeon_family          family;
  173.     enum chip_class             chip_class;
  174.     uint32_t                    gart_size;
  175.     uint32_t                    vram_size;
  176.  
  177.     uint32_t                    drm_major; /* version */
  178.     uint32_t                    drm_minor;
  179.     uint32_t                    drm_patchlevel;
  180.  
  181.     boolean                     has_uvd;
  182.  
  183.     uint32_t                    r300_num_gb_pipes;
  184.     uint32_t                    r300_num_z_pipes;
  185.  
  186.     uint32_t                    r600_num_backends;
  187.     uint32_t                    r600_clock_crystal_freq;
  188.     uint32_t                    r600_tiling_config;
  189.     uint32_t                    r600_num_tile_pipes;
  190.     uint32_t                    r600_backend_map;
  191.     uint32_t                    r600_va_start;
  192.     uint32_t                    r600_ib_vm_max_size;
  193.     uint32_t                    r600_max_pipes;
  194.     boolean                     r600_backend_map_valid;
  195.     boolean                     r600_virtual_address;
  196.     boolean                     r600_has_dma;
  197. };
  198.  
  199. enum radeon_feature_id {
  200.     RADEON_FID_R300_HYPERZ_ACCESS,     /* ZMask + HiZ */
  201.     RADEON_FID_R300_CMASK_ACCESS,
  202. };
  203.  
  204. struct radeon_winsys {
  205.     /**
  206.      * Reference counting
  207.      */
  208.     struct pipe_reference reference;
  209.  
  210.     /**
  211.      * Destroy this winsys.
  212.      *
  213.      * \param ws        The winsys this function is called from.
  214.      */
  215.     void (*destroy)(struct radeon_winsys *ws);
  216.  
  217.     /**
  218.      * Query an info structure from winsys.
  219.      *
  220.      * \param ws        The winsys this function is called from.
  221.      * \param info      Return structure
  222.      */
  223.     void (*query_info)(struct radeon_winsys *ws,
  224.                        struct radeon_info *info);
  225.  
  226.     /**************************************************************************
  227.      * Buffer management. Buffer attributes are mostly fixed over its lifetime.
  228.      *
  229.      * Remember that gallium gets to choose the interface it needs, and the
  230.      * window systems must then implement that interface (rather than the
  231.      * other way around...).
  232.      *************************************************************************/
  233.  
  234.     /**
  235.      * Create a buffer object.
  236.      *
  237.      * \param ws        The winsys this function is called from.
  238.      * \param size      The size to allocate.
  239.      * \param alignment An alignment of the buffer in memory.
  240.      * \param use_reusable_pool Whether the cache buffer manager should be used.
  241.      * \param domain    A bitmask of the RADEON_DOMAIN_* flags.
  242.      * \return          The created buffer object.
  243.      */
  244.     struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws,
  245.                                        unsigned size,
  246.                                        unsigned alignment,
  247.                                        boolean use_reusable_pool,
  248.                                        enum radeon_bo_domain domain);
  249.  
  250.     struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)(
  251.             struct pb_buffer *buf);
  252.  
  253.     /**
  254.      * Map the entire data store of a buffer object into the client's address
  255.      * space.
  256.      *
  257.      * \param buf       A winsys buffer object to map.
  258.      * \param cs        A command stream to flush if the buffer is referenced by it.
  259.      * \param usage     A bitmask of the PIPE_TRANSFER_* flags.
  260.      * \return          The pointer at the beginning of the buffer.
  261.      */
  262.     void *(*buffer_map)(struct radeon_winsys_cs_handle *buf,
  263.                         struct radeon_winsys_cs *cs,
  264.                         enum pipe_transfer_usage usage);
  265.  
  266.     /**
  267.      * Unmap a buffer object from the client's address space.
  268.      *
  269.      * \param buf       A winsys buffer object to unmap.
  270.      */
  271.     void (*buffer_unmap)(struct radeon_winsys_cs_handle *buf);
  272.  
  273.     /**
  274.      * Return TRUE if a buffer object is being used by the GPU.
  275.      *
  276.      * \param buf       A winsys buffer object.
  277.      * \param usage     Only check whether the buffer is busy for the given usage.
  278.      */
  279.     boolean (*buffer_is_busy)(struct pb_buffer *buf,
  280.                               enum radeon_bo_usage usage);
  281.  
  282.     /**
  283.      * Wait for a buffer object until it is not used by a GPU. This is
  284.      * equivalent to a fence placed after the last command using the buffer,
  285.      * and synchronizing to the fence.
  286.      *
  287.      * \param buf       A winsys buffer object to wait for.
  288.      * \param usage     Only wait until the buffer is idle for the given usage,
  289.      *                  but may still be busy for some other usage.
  290.      */
  291.     void (*buffer_wait)(struct pb_buffer *buf, enum radeon_bo_usage usage);
  292.  
  293.     /**
  294.      * Return tiling flags describing a memory layout of a buffer object.
  295.      *
  296.      * \param buf       A winsys buffer object to get the flags from.
  297.      * \param macrotile A pointer to the return value of the microtile flag.
  298.      * \param microtile A pointer to the return value of the macrotile flag.
  299.      *
  300.      * \note microtile and macrotile are not bitmasks!
  301.      */
  302.     void (*buffer_get_tiling)(struct pb_buffer *buf,
  303.                               enum radeon_bo_layout *microtile,
  304.                               enum radeon_bo_layout *macrotile,
  305.                               unsigned *bankw, unsigned *bankh,
  306.                               unsigned *tile_split,
  307.                               unsigned *stencil_tile_split,
  308.                               unsigned *mtilea);
  309.  
  310.     /**
  311.      * Set tiling flags describing a memory layout of a buffer object.
  312.      *
  313.      * \param buf       A winsys buffer object to set the flags for.
  314.      * \param cs        A command stream to flush if the buffer is referenced by it.
  315.      * \param macrotile A macrotile flag.
  316.      * \param microtile A microtile flag.
  317.      * \param stride    A stride of the buffer in bytes, for texturing.
  318.      *
  319.      * \note microtile and macrotile are not bitmasks!
  320.      */
  321.     void (*buffer_set_tiling)(struct pb_buffer *buf,
  322.                               struct radeon_winsys_cs *rcs,
  323.                               enum radeon_bo_layout microtile,
  324.                               enum radeon_bo_layout macrotile,
  325.                               unsigned bankw, unsigned bankh,
  326.                               unsigned tile_split,
  327.                               unsigned stencil_tile_split,
  328.                               unsigned mtilea,
  329.                               unsigned stride);
  330.  
  331.     /**
  332.      * Get a winsys buffer from a winsys handle. The internal structure
  333.      * of the handle is platform-specific and only a winsys should access it.
  334.      *
  335.      * \param ws        The winsys this function is called from.
  336.      * \param whandle   A winsys handle pointer as was received from a state
  337.      *                  tracker.
  338.      * \param stride    The returned buffer stride in bytes.
  339.      */
  340.     struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws,
  341.                                             struct winsys_handle *whandle,
  342.                                             unsigned *stride);
  343.  
  344.     /**
  345.      * Get a winsys handle from a winsys buffer. The internal structure
  346.      * of the handle is platform-specific and only a winsys should access it.
  347.      *
  348.      * \param buf       A winsys buffer object to get the handle from.
  349.      * \param whandle   A winsys handle pointer.
  350.      * \param stride    A stride of the buffer in bytes, for texturing.
  351.      * \return          TRUE on success.
  352.      */
  353.     boolean (*buffer_get_handle)(struct pb_buffer *buf,
  354.                                  unsigned stride,
  355.                                  struct winsys_handle *whandle);
  356.  
  357.     /**
  358.      * Return the virtual address of a buffer.
  359.      *
  360.      * \param buf       A winsys buffer object
  361.      * \return          virtual address
  362.      */
  363.     uint64_t (*buffer_get_virtual_address)(struct radeon_winsys_cs_handle *buf);
  364.  
  365.     /**************************************************************************
  366.      * Command submission.
  367.      *
  368.      * Each pipe context should create its own command stream and submit
  369.      * commands independently of other contexts.
  370.      *************************************************************************/
  371.  
  372.     /**
  373.      * Create a command stream.
  374.      *
  375.      * \param ws        The winsys this function is called from.
  376.      * \param ring_type The ring type (GFX, DMA, UVD)
  377.      * \param trace_buf Trace buffer when tracing is enabled
  378.      */
  379.     struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws,
  380.                                           enum ring_type ring_type,
  381.                                           struct radeon_winsys_cs_handle *trace_buf);
  382.  
  383.     /**
  384.      * Destroy a command stream.
  385.      *
  386.      * \param cs        A command stream to destroy.
  387.      */
  388.     void (*cs_destroy)(struct radeon_winsys_cs *cs);
  389.  
  390.     /**
  391.      * Add a new buffer relocation. Every relocation must first be added
  392.      * before it can be written.
  393.      *
  394.      * \param cs  A command stream to add buffer for validation against.
  395.      * \param buf A winsys buffer to validate.
  396.      * \param usage   Whether the buffer is used for read and/or write.
  397.      * \param domain  Bitmask of the RADEON_DOMAIN_* flags.
  398.      * \return Relocation index.
  399.      */
  400.     unsigned (*cs_add_reloc)(struct radeon_winsys_cs *cs,
  401.                              struct radeon_winsys_cs_handle *buf,
  402.                              enum radeon_bo_usage usage,
  403.                              enum radeon_bo_domain domain);
  404.  
  405.     /**
  406.      * Return TRUE if there is enough memory in VRAM and GTT for the relocs
  407.      * added so far. If the validation fails, all the relocations which have
  408.      * been added since the last call of cs_validate will be removed and
  409.      * the CS will be flushed (provided there are still any relocations).
  410.      *
  411.      * \param cs        A command stream to validate.
  412.      */
  413.     boolean (*cs_validate)(struct radeon_winsys_cs *cs);
  414.  
  415.     /**
  416.      * Return TRUE if there is enough memory in VRAM and GTT for the relocs
  417.      * added so far.
  418.      *
  419.      * \param cs        A command stream to validate.
  420.      * \param vram      VRAM memory size pending to be use
  421.      * \param gtt       GTT memory size pending to be use
  422.      */
  423.     boolean (*cs_memory_below_limit)(struct radeon_winsys_cs *cs, uint64_t vram, uint64_t gtt);
  424.  
  425.     /**
  426.      * Write a relocated dword to a command buffer.
  427.      *
  428.      * \param cs        A command stream the relocation is written to.
  429.      * \param buf       A winsys buffer to write the relocation for.
  430.      */
  431.     void (*cs_write_reloc)(struct radeon_winsys_cs *cs,
  432.                            struct radeon_winsys_cs_handle *buf);
  433.  
  434.     /**
  435.      * Flush a command stream.
  436.      *
  437.      * \param cs          A command stream to flush.
  438.      * \param flags,      RADEON_FLUSH_ASYNC or 0.
  439.      * \param cs_trace_id A unique identifiant for the cs
  440.      */
  441.     void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags, uint32_t cs_trace_id);
  442.  
  443.     /**
  444.      * Set a flush callback which is called from winsys when flush is
  445.      * required.
  446.      *
  447.      * \param cs        A command stream to set the callback for.
  448.      * \param flush     A flush callback function associated with the command stream.
  449.      * \param user      A user pointer that will be passed to the flush callback.
  450.      */
  451.     void (*cs_set_flush_callback)(struct radeon_winsys_cs *cs,
  452.                                   void (*flush)(void *ctx, unsigned flags),
  453.                                   void *ctx);
  454.  
  455.     /**
  456.      * Return TRUE if a buffer is referenced by a command stream.
  457.      *
  458.      * \param cs        A command stream.
  459.      * \param buf       A winsys buffer.
  460.      */
  461.     boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
  462.                                        struct radeon_winsys_cs_handle *buf,
  463.                                        enum radeon_bo_usage usage);
  464.  
  465.     /**
  466.      * Request access to a feature for a command stream.
  467.      *
  468.      * \param cs        A command stream.
  469.      * \param fid       Feature ID, one of RADEON_FID_*
  470.      * \param enable    Whether to enable or disable the feature.
  471.      */
  472.     boolean (*cs_request_feature)(struct radeon_winsys_cs *cs,
  473.                                   enum radeon_feature_id fid,
  474.                                   boolean enable);
  475.      /**
  476.       * Make sure all asynchronous flush of the cs have completed
  477.       *
  478.       * \param cs        A command stream.
  479.       */
  480.     void (*cs_sync_flush)(struct radeon_winsys_cs *cs);
  481.  
  482.     /**
  483.      * Initialize surface
  484.      *
  485.      * \param ws        The winsys this function is called from.
  486.      * \param surf      Surface structure ptr
  487.      */
  488.     int (*surface_init)(struct radeon_winsys *ws,
  489.                         struct radeon_surface *surf);
  490.  
  491.     /**
  492.      * Find best values for a surface
  493.      *
  494.      * \param ws        The winsys this function is called from.
  495.      * \param surf      Surface structure ptr
  496.      */
  497.     int (*surface_best)(struct radeon_winsys *ws,
  498.                         struct radeon_surface *surf);
  499.  
  500.     uint64_t (*query_value)(struct radeon_winsys *ws,
  501.                             enum radeon_value_id value);
  502. };
  503.  
  504. #endif
  505.