13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
33464ebd5Sriastradh * Copyright © 2009 Jakob Bornecrantz
43464ebd5Sriastradh *
53464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
63464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"),
73464ebd5Sriastradh * to deal in the Software without restriction, including without limitation
83464ebd5Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
93464ebd5Sriastradh * and/or sell copies of the Software, and to permit persons to whom the
103464ebd5Sriastradh * Software is furnished to do so, subject to the following conditions:
113464ebd5Sriastradh *
123464ebd5Sriastradh * The above copyright notice and this permission notice (including the next
133464ebd5Sriastradh * paragraph) shall be included in all copies or substantial portions of the
143464ebd5Sriastradh * Software.
153464ebd5Sriastradh *
163464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
173464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
183464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
193464ebd5Sriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
203464ebd5Sriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
213464ebd5Sriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
223464ebd5Sriastradh * DEALINGS IN THE SOFTWARE.
233464ebd5Sriastradh *
243464ebd5Sriastradh **************************************************************************/
253464ebd5Sriastradh
263464ebd5Sriastradh#ifndef I915_WINSYS_H
273464ebd5Sriastradh#define I915_WINSYS_H
283464ebd5Sriastradh
293464ebd5Sriastradh#include "pipe/p_compiler.h"
303464ebd5Sriastradh
313464ebd5Sriastradhstruct i915_winsys;
323464ebd5Sriastradhstruct i915_winsys_buffer;
333464ebd5Sriastradhstruct i915_winsys_batchbuffer;
343464ebd5Sriastradhstruct pipe_resource;
353464ebd5Sriastradhstruct pipe_fence_handle;
363464ebd5Sriastradhstruct winsys_handle;
373464ebd5Sriastradh
387ec681f3Smrgenum i915_winsys_buffer_usage {
393464ebd5Sriastradh   /* use on textures */
407ec681f3Smrg   I915_USAGE_RENDER = 0x01,
417ec681f3Smrg   I915_USAGE_SAMPLER = 0x02,
423464ebd5Sriastradh   I915_USAGE_2D_TARGET = 0x04,
433464ebd5Sriastradh   I915_USAGE_2D_SOURCE = 0x08,
443464ebd5Sriastradh   /* use on vertex */
457ec681f3Smrg   I915_USAGE_VERTEX = 0x10
463464ebd5Sriastradh};
473464ebd5Sriastradh
487ec681f3Smrgenum i915_winsys_buffer_type {
493464ebd5Sriastradh   I915_NEW_TEXTURE,
503464ebd5Sriastradh   I915_NEW_SCANOUT, /**< a texture used for scanning out from */
513464ebd5Sriastradh   I915_NEW_VERTEX
523464ebd5Sriastradh};
533464ebd5Sriastradh
543464ebd5Sriastradh/* These need to be in sync with the definitions of libdrm-intel! */
557ec681f3Smrgenum i915_winsys_buffer_tile { I915_TILE_NONE, I915_TILE_X, I915_TILE_Y };
563464ebd5Sriastradh
577ec681f3Smrgenum i915_winsys_flush_flags {
58af69d88dSmrg   I915_FLUSH_ASYNC = 0,
59af69d88dSmrg   I915_FLUSH_END_OF_FRAME = 1
60af69d88dSmrg};
61af69d88dSmrg
623464ebd5Sriastradhstruct i915_winsys_batchbuffer {
633464ebd5Sriastradh
643464ebd5Sriastradh   struct i915_winsys *iws;
653464ebd5Sriastradh
663464ebd5Sriastradh   /**
673464ebd5Sriastradh    * Values exported to speed up the writing the batchbuffer,
683464ebd5Sriastradh    * instead of having to go trough a accesor function for
693464ebd5Sriastradh    * each dword written.
703464ebd5Sriastradh    */
713464ebd5Sriastradh   /*{@*/
723464ebd5Sriastradh   uint8_t *map;
733464ebd5Sriastradh   uint8_t *ptr;
743464ebd5Sriastradh   size_t size;
753464ebd5Sriastradh
763464ebd5Sriastradh   size_t relocs;
773464ebd5Sriastradh   /*@}*/
783464ebd5Sriastradh};
793464ebd5Sriastradh
803464ebd5Sriastradhstruct i915_winsys {
813464ebd5Sriastradh
823464ebd5Sriastradh   unsigned pci_id; /**< PCI ID for the device */
833464ebd5Sriastradh
843464ebd5Sriastradh   /**
853464ebd5Sriastradh    * Batchbuffer functions.
863464ebd5Sriastradh    */
873464ebd5Sriastradh   /*@{*/
883464ebd5Sriastradh   /**
893464ebd5Sriastradh    * Create a new batchbuffer.
903464ebd5Sriastradh    */
917ec681f3Smrg   struct i915_winsys_batchbuffer *(*batchbuffer_create)(
927ec681f3Smrg      struct i915_winsys *iws);
933464ebd5Sriastradh
943464ebd5Sriastradh   /**
953464ebd5Sriastradh    * Validate buffers for usage in this batchbuffer.
963464ebd5Sriastradh    * Does space-checking and asorted other book-keeping.
973464ebd5Sriastradh    *
983464ebd5Sriastradh    * @batch
993464ebd5Sriastradh    * @buffers array to buffers to validate
1003464ebd5Sriastradh    * @num_of_buffers size of the passed array
1013464ebd5Sriastradh    */
1027ec681f3Smrg   bool (*validate_buffers)(struct i915_winsys_batchbuffer *batch,
1037ec681f3Smrg                            struct i915_winsys_buffer **buffers,
1047ec681f3Smrg                            int num_of_buffers);
1053464ebd5Sriastradh
1063464ebd5Sriastradh   /**
1073464ebd5Sriastradh    * Emit a relocation to a buffer.
1083464ebd5Sriastradh    * Target position in batchbuffer is the same as ptr.
1093464ebd5Sriastradh    *
1103464ebd5Sriastradh    * @batch
1113464ebd5Sriastradh    * @reloc buffer address to be inserted into target.
1123464ebd5Sriastradh    * @usage how is the hardware going to use the buffer.
1133464ebd5Sriastradh    * @offset add this to the reloc buffers address
1143464ebd5Sriastradh    * @target buffer where to write the address, null for batchbuffer.
1153464ebd5Sriastradh    * @fenced relocation needs a fence.
1163464ebd5Sriastradh    */
1173464ebd5Sriastradh   int (*batchbuffer_reloc)(struct i915_winsys_batchbuffer *batch,
1183464ebd5Sriastradh                            struct i915_winsys_buffer *reloc,
1193464ebd5Sriastradh                            enum i915_winsys_buffer_usage usage,
1207ec681f3Smrg                            unsigned offset, bool fenced);
1213464ebd5Sriastradh
1223464ebd5Sriastradh   /**
1233464ebd5Sriastradh    * Flush a bufferbatch.
1243464ebd5Sriastradh    */
1253464ebd5Sriastradh   void (*batchbuffer_flush)(struct i915_winsys_batchbuffer *batch,
126af69d88dSmrg                             struct pipe_fence_handle **fence,
127af69d88dSmrg                             enum i915_winsys_flush_flags flags);
1283464ebd5Sriastradh
1293464ebd5Sriastradh   /**
1303464ebd5Sriastradh    * Destroy a batchbuffer.
1313464ebd5Sriastradh    */
1323464ebd5Sriastradh   void (*batchbuffer_destroy)(struct i915_winsys_batchbuffer *batch);
1333464ebd5Sriastradh   /*@}*/
1343464ebd5Sriastradh
1353464ebd5Sriastradh   /**
1363464ebd5Sriastradh    * Buffer functions.
1373464ebd5Sriastradh    */
1383464ebd5Sriastradh   /*@{*/
1393464ebd5Sriastradh   /**
1403464ebd5Sriastradh    * Create a buffer.
1413464ebd5Sriastradh    */
1427ec681f3Smrg   struct i915_winsys_buffer *(*buffer_create)(
1437ec681f3Smrg      struct i915_winsys *iws, unsigned size,
1447ec681f3Smrg      enum i915_winsys_buffer_type type);
1453464ebd5Sriastradh
1463464ebd5Sriastradh   /**
1473464ebd5Sriastradh    * Create a tiled buffer.
1483464ebd5Sriastradh    *
1493464ebd5Sriastradh    * *stride, height are in bytes. The winsys tries to allocate the buffer with
1503464ebd5Sriastradh    * the tiling mode provide in *tiling. If tiling is no possible, *tiling will
1513464ebd5Sriastradh    * be set to I915_TILE_NONE. The calculated stride (incorporateing hw/kernel
1523464ebd5Sriastradh    * requirements) is always returned in *stride.
1533464ebd5Sriastradh    */
1547ec681f3Smrg   struct i915_winsys_buffer *(*buffer_create_tiled)(
1557ec681f3Smrg      struct i915_winsys *iws, unsigned *stride, unsigned height,
1567ec681f3Smrg      enum i915_winsys_buffer_tile *tiling, enum i915_winsys_buffer_type type);
1573464ebd5Sriastradh
1583464ebd5Sriastradh   /**
1593464ebd5Sriastradh    * Creates a buffer from a handle.
1603464ebd5Sriastradh    * Used to implement pipe_screen::resource_from_handle.
1613464ebd5Sriastradh    * Also provides the stride information needed for the
1623464ebd5Sriastradh    * texture via the stride argument.
1633464ebd5Sriastradh    */
1647ec681f3Smrg   struct i915_winsys_buffer *(*buffer_from_handle)(
1657ec681f3Smrg      struct i915_winsys *iws, struct winsys_handle *whandle, unsigned height,
1667ec681f3Smrg      enum i915_winsys_buffer_tile *tiling, unsigned *stride);
1673464ebd5Sriastradh
1683464ebd5Sriastradh   /**
1693464ebd5Sriastradh    * Used to implement pipe_screen::resource_get_handle.
1703464ebd5Sriastradh    * The winsys might need the stride information.
1713464ebd5Sriastradh    */
1727ec681f3Smrg   bool (*buffer_get_handle)(struct i915_winsys *iws,
1737ec681f3Smrg                             struct i915_winsys_buffer *buffer,
1747ec681f3Smrg                             struct winsys_handle *whandle, unsigned stride);
1753464ebd5Sriastradh
1763464ebd5Sriastradh   /**
1773464ebd5Sriastradh    * Map a buffer.
1783464ebd5Sriastradh    */
1793464ebd5Sriastradh   void *(*buffer_map)(struct i915_winsys *iws,
1807ec681f3Smrg                       struct i915_winsys_buffer *buffer, bool write);
1813464ebd5Sriastradh
1823464ebd5Sriastradh   /**
1833464ebd5Sriastradh    * Unmap a buffer.
1843464ebd5Sriastradh    */
1853464ebd5Sriastradh   void (*buffer_unmap)(struct i915_winsys *iws,
1863464ebd5Sriastradh                        struct i915_winsys_buffer *buffer);
1873464ebd5Sriastradh
1883464ebd5Sriastradh   /**
1893464ebd5Sriastradh    * Write to a buffer.
1903464ebd5Sriastradh    *
1913464ebd5Sriastradh    * Arguments follows pipe_buffer_write.
1923464ebd5Sriastradh    */
1937ec681f3Smrg   int (*buffer_write)(struct i915_winsys *iws, struct i915_winsys_buffer *dst,
1947ec681f3Smrg                       size_t offset, size_t size, const void *data);
1953464ebd5Sriastradh
1963464ebd5Sriastradh   void (*buffer_destroy)(struct i915_winsys *iws,
1973464ebd5Sriastradh                          struct i915_winsys_buffer *buffer);
1983464ebd5Sriastradh
1993464ebd5Sriastradh   /**
2003464ebd5Sriastradh    * Check if a buffer is busy.
2013464ebd5Sriastradh    */
2027ec681f3Smrg   bool (*buffer_is_busy)(struct i915_winsys *iws,
2037ec681f3Smrg                          struct i915_winsys_buffer *buffer);
2043464ebd5Sriastradh   /*@}*/
2053464ebd5Sriastradh
2063464ebd5Sriastradh   /**
2073464ebd5Sriastradh    * Fence functions.
2083464ebd5Sriastradh    */
2093464ebd5Sriastradh   /*@{*/
2103464ebd5Sriastradh   /**
2113464ebd5Sriastradh    * Reference fence and set ptr to fence.
2123464ebd5Sriastradh    */
2133464ebd5Sriastradh   void (*fence_reference)(struct i915_winsys *iws,
2143464ebd5Sriastradh                           struct pipe_fence_handle **ptr,
2153464ebd5Sriastradh                           struct pipe_fence_handle *fence);
2163464ebd5Sriastradh
2173464ebd5Sriastradh   /**
2183464ebd5Sriastradh    * Check if a fence has finished.
2193464ebd5Sriastradh    */
2203464ebd5Sriastradh   int (*fence_signalled)(struct i915_winsys *iws,
2213464ebd5Sriastradh                          struct pipe_fence_handle *fence);
2223464ebd5Sriastradh
2233464ebd5Sriastradh   /**
2243464ebd5Sriastradh    * Wait on a fence to finish.
2253464ebd5Sriastradh    */
2263464ebd5Sriastradh   int (*fence_finish)(struct i915_winsys *iws,
2273464ebd5Sriastradh                       struct pipe_fence_handle *fence);
2283464ebd5Sriastradh   /*@}*/
2293464ebd5Sriastradh
230af69d88dSmrg   /**
231af69d88dSmrg    * Retrieve the aperture size (in MiB) of the device.
232af69d88dSmrg    */
233af69d88dSmrg   int (*aperture_size)(struct i915_winsys *iws);
234af69d88dSmrg
2353464ebd5Sriastradh   /**
2363464ebd5Sriastradh    * Destroy the winsys.
2373464ebd5Sriastradh    */
2383464ebd5Sriastradh   void (*destroy)(struct i915_winsys *iws);
2393464ebd5Sriastradh};
2403464ebd5Sriastradh
2413464ebd5Sriastradh#endif
242