Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2014 Broadcom
  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.  
  24. #ifndef VC4_BUFMGR_H
  25. #define VC4_BUFMGR_H
  26.  
  27. #include <stdint.h>
  28. #include "util/u_inlines.h"
  29. #include "vc4_qir.h"
  30.  
  31. struct vc4_context;
  32.  
  33. struct vc4_bo {
  34.         struct pipe_reference reference;
  35.         struct vc4_screen *screen;
  36.         void *map;
  37.         const char *name;
  38.         uint32_t handle;
  39.         uint32_t size;
  40.  
  41. #ifdef USE_VC4_SIMULATOR
  42.         void *simulator_winsys_map;
  43.         uint32_t simulator_winsys_stride;
  44. #endif
  45.  
  46.         /** Entry in the linked list of buffers freed, by age. */
  47.         struct simple_node time_list;
  48.         /** Entry in the per-page-count linked list of buffers freed (by age). */
  49.         struct simple_node size_list;
  50.         /** Approximate second when the bo was freed. */
  51.         time_t free_time;
  52.         /**
  53.          * Whether only our process has a reference to the BO (meaning that
  54.          * it's safe to reuse it in the BO cache).
  55.          */
  56.         bool private;
  57. };
  58.  
  59. struct vc4_bo *vc4_bo_alloc(struct vc4_screen *screen, uint32_t size,
  60.                             const char *name);
  61. struct vc4_bo *vc4_bo_alloc_mem(struct vc4_screen *screen, const void *data,
  62.                                 uint32_t size, const char *name);
  63. void vc4_bo_last_unreference(struct vc4_bo *bo);
  64. void vc4_bo_last_unreference_locked_timed(struct vc4_bo *bo, time_t time);
  65. struct vc4_bo *vc4_bo_open_name(struct vc4_screen *screen, uint32_t name,
  66.                                 uint32_t winsys_stride);
  67. struct vc4_bo *vc4_bo_open_dmabuf(struct vc4_screen *screen, int fd,
  68.                                   uint32_t winsys_stride);
  69. bool vc4_bo_flink(struct vc4_bo *bo, uint32_t *name);
  70. int vc4_bo_get_dmabuf(struct vc4_bo *bo);
  71.  
  72. static inline void
  73. vc4_bo_set_reference(struct vc4_bo **old_bo, struct vc4_bo *new_bo)
  74. {
  75.         if (pipe_reference(&(*old_bo)->reference, &new_bo->reference))
  76.                 vc4_bo_last_unreference(*old_bo);
  77.         *old_bo = new_bo;
  78. }
  79.  
  80. static inline struct vc4_bo *
  81. vc4_bo_reference(struct vc4_bo *bo)
  82. {
  83.         pipe_reference(NULL, &bo->reference);
  84.         return bo;
  85. }
  86.  
  87. static inline void
  88. vc4_bo_unreference(struct vc4_bo **bo)
  89. {
  90.         if (!*bo)
  91.                 return;
  92.  
  93.         if (pipe_reference(&(*bo)->reference, NULL))
  94.                 vc4_bo_last_unreference(*bo);
  95.         *bo = NULL;
  96. }
  97.  
  98. static inline void
  99. vc4_bo_unreference_locked_timed(struct vc4_bo **bo, time_t time)
  100. {
  101.         if (!*bo)
  102.                 return;
  103.  
  104.         if (pipe_reference(&(*bo)->reference, NULL))
  105.                 vc4_bo_last_unreference_locked_timed(*bo, time);
  106.         *bo = NULL;
  107. }
  108.  
  109. void *
  110. vc4_bo_map(struct vc4_bo *bo);
  111.  
  112. void *
  113. vc4_bo_map_unsynchronized(struct vc4_bo *bo);
  114.  
  115. bool
  116. vc4_bo_wait(struct vc4_bo *bo, uint64_t timeout_ns);
  117.  
  118. bool
  119. vc4_wait_seqno(struct vc4_screen *screen, uint64_t seqno, uint64_t timeout_ns);
  120.  
  121. void
  122. vc4_bufmgr_destroy(struct pipe_screen *pscreen);
  123.  
  124. #endif /* VC4_BUFMGR_H */
  125.  
  126.