Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 21 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
| 28 | /* Originally a fake version of the buffer manager so that we can |
| 29 | * prototype the changes in a driver fairly quickly, has been fleshed |
| 30 | * out to a fully functional interim solution. |
| 31 | * |
| 32 | * Basically wraps the old style memory management in the new |
| 33 | * programming interface, but is more expressive and avoids many of |
| 34 | * the bugs in the old texture manager. |
| 35 | */ |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 36 | |
Eric Anholt | 368b392 | 2008-09-10 13:54:34 -0700 | [diff] [blame] | 37 | #ifdef HAVE_CONFIG_H |
| 38 | #include "config.h" |
| 39 | #endif |
| 40 | |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 41 | #include <stdlib.h> |
| 42 | #include <string.h> |
| 43 | #include <assert.h> |
Eric Anholt | 869d8be | 2008-09-06 03:07:41 +0100 | [diff] [blame] | 44 | #include <errno.h> |
Eric Anholt | 738e36a | 2008-09-05 10:35:32 +0100 | [diff] [blame] | 45 | #include <xf86drm.h> |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 46 | #include <pthread.h> |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 47 | #include "intel_bufmgr.h" |
Eric Anholt | 738e36a | 2008-09-05 10:35:32 +0100 | [diff] [blame] | 48 | #include "intel_bufmgr_priv.h" |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 49 | #include "drm.h" |
| 50 | #include "i915_drm.h" |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 51 | #include "mm.h" |
Emil Velikov | 42465fe | 2015-04-05 15:51:59 +0100 | [diff] [blame] | 52 | #include "libdrm_macros.h" |
Eric Anholt | f7a9940 | 2008-08-08 15:55:34 -0700 | [diff] [blame] | 53 | #include "libdrm_lists.h" |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 54 | |
| 55 | #define DBG(...) do { \ |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 56 | if (bufmgr_fake->bufmgr.debug) \ |
| 57 | drmMsg(__VA_ARGS__); \ |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 58 | } while (0) |
| 59 | |
| 60 | /* Internal flags: |
| 61 | */ |
| 62 | #define BM_NO_BACKING_STORE 0x00000001 |
| 63 | #define BM_NO_FENCE_SUBDATA 0x00000002 |
| 64 | #define BM_PINNED 0x00000004 |
| 65 | |
| 66 | /* Wrapper around mm.c's mem_block, which understands that you must |
| 67 | * wait for fences to expire before memory can be freed. This is |
| 68 | * specific to our use of memcpy for uploads - an upload that was |
| 69 | * processed through the command queue wouldn't need to care about |
| 70 | * fences. |
| 71 | */ |
| 72 | #define MAX_RELOCS 4096 |
| 73 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 74 | struct fake_buffer_reloc { |
| 75 | /** Buffer object that the relocation points at. */ |
| 76 | drm_intel_bo *target_buf; |
| 77 | /** Offset of the relocation entry within reloc_buf. */ |
| 78 | uint32_t offset; |
| 79 | /** |
| 80 | * Cached value of the offset when we last performed this relocation. |
| 81 | */ |
| 82 | uint32_t last_target_offset; |
| 83 | /** Value added to target_buf's offset to get the relocation entry. */ |
| 84 | uint32_t delta; |
| 85 | /** Cache domains the target buffer is read into. */ |
| 86 | uint32_t read_domains; |
| 87 | /** Cache domain the target buffer will have dirty cachelines in. */ |
| 88 | uint32_t write_domain; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | struct block { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 92 | struct block *next, *prev; |
| 93 | struct mem_block *mem; /* BM_MEM_AGP */ |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 94 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Marks that the block is currently in the aperture and has yet to be |
| 97 | * fenced. |
| 98 | */ |
| 99 | unsigned on_hardware:1; |
| 100 | /** |
| 101 | * Marks that the block is currently fenced (being used by rendering) |
| 102 | * and can't be freed until @fence is passed. |
| 103 | */ |
| 104 | unsigned fenced:1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 105 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 106 | /** Fence cookie for the block. */ |
| 107 | unsigned fence; /* Split to read_fence, write_fence */ |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 108 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 109 | drm_intel_bo *bo; |
| 110 | void *virtual; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | typedef struct _bufmgr_fake { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 114 | drm_intel_bufmgr bufmgr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 115 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 116 | pthread_mutex_t lock; |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 117 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 118 | unsigned long low_offset; |
| 119 | unsigned long size; |
| 120 | void *virtual; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 121 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 122 | struct mem_block *heap; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 123 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 124 | unsigned buf_nr; /* for generating ids */ |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 125 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 126 | /** |
| 127 | * List of blocks which are currently in the GART but haven't been |
| 128 | * fenced yet. |
| 129 | */ |
| 130 | struct block on_hardware; |
| 131 | /** |
| 132 | * List of blocks which are in the GART and have an active fence on |
| 133 | * them. |
| 134 | */ |
| 135 | struct block fenced; |
| 136 | /** |
| 137 | * List of blocks which have an expired fence and are ready to be |
| 138 | * evicted. |
| 139 | */ |
| 140 | struct block lru; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 141 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 142 | unsigned int last_fence; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 143 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 144 | unsigned fail:1; |
| 145 | unsigned need_fence:1; |
| 146 | int thrashing; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 147 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Driver callback to emit a fence, returning the cookie. |
| 150 | * |
| 151 | * This allows the driver to hook in a replacement for the DRM usage in |
| 152 | * bufmgr_fake. |
| 153 | * |
| 154 | * Currently, this also requires that a write flush be emitted before |
| 155 | * emitting the fence, but this should change. |
| 156 | */ |
| 157 | unsigned int (*fence_emit) (void *private); |
| 158 | /** Driver callback to wait for a fence cookie to have passed. */ |
| 159 | void (*fence_wait) (unsigned int fence, void *private); |
| 160 | void *fence_priv; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 161 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Driver callback to execute a buffer. |
| 164 | * |
| 165 | * This allows the driver to hook in a replacement for the DRM usage in |
| 166 | * bufmgr_fake. |
| 167 | */ |
| 168 | int (*exec) (drm_intel_bo *bo, unsigned int used, void *priv); |
| 169 | void *exec_priv; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 170 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 171 | /** Driver-supplied argument to driver callbacks */ |
| 172 | void *driver_priv; |
| 173 | /** |
| 174 | * Pointer to kernel-updated sarea data for the last completed user irq |
| 175 | */ |
| 176 | volatile int *last_dispatch; |
Eric Anholt | 869d8be | 2008-09-06 03:07:41 +0100 | [diff] [blame] | 177 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 178 | int fd; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 179 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 180 | int debug; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 181 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 182 | int performed_rendering; |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 183 | } drm_intel_bufmgr_fake; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 184 | |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 185 | typedef struct _drm_intel_bo_fake { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 186 | drm_intel_bo bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 187 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 188 | unsigned id; /* debug only */ |
| 189 | const char *name; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 190 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 191 | unsigned dirty:1; |
| 192 | /** |
| 193 | * has the card written to this buffer - we make need to copy it back |
| 194 | */ |
| 195 | unsigned card_dirty:1; |
| 196 | unsigned int refcount; |
| 197 | /* Flags may consist of any of the DRM_BO flags, plus |
| 198 | * DRM_BO_NO_BACKING_STORE and BM_NO_FENCE_SUBDATA, which are the |
| 199 | * first two driver private flags. |
| 200 | */ |
| 201 | uint64_t flags; |
| 202 | /** Cache domains the target buffer is read into. */ |
| 203 | uint32_t read_domains; |
| 204 | /** Cache domain the target buffer will have dirty cachelines in. */ |
| 205 | uint32_t write_domain; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 206 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 207 | unsigned int alignment; |
| 208 | int is_static, validated; |
| 209 | unsigned int map_count; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 210 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 211 | /** relocation list */ |
| 212 | struct fake_buffer_reloc *relocs; |
| 213 | int nr_relocs; |
| 214 | /** |
| 215 | * Total size of the target_bos of this buffer. |
| 216 | * |
| 217 | * Used for estimation in check_aperture. |
| 218 | */ |
| 219 | unsigned int child_size; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 220 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 221 | struct block *block; |
| 222 | void *backing_store; |
| 223 | void (*invalidate_cb) (drm_intel_bo *bo, void *ptr); |
| 224 | void *invalidate_ptr; |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 225 | } drm_intel_bo_fake; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 226 | |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 227 | static int clear_fenced(drm_intel_bufmgr_fake *bufmgr_fake, |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 228 | unsigned int fence_cookie); |
| 229 | |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 230 | #define MAXFENCE 0x7fffffff |
| 231 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 232 | static int |
| 233 | FENCE_LTE(unsigned a, unsigned b) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 234 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 235 | if (a == b) |
| 236 | return 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 237 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 238 | if (a < b && b - a < (1 << 24)) |
| 239 | return 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 240 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 241 | if (a > b && MAXFENCE - a + b < (1 << 24)) |
| 242 | return 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 243 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 244 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Emil Velikov | 0f8da82 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 247 | void |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 248 | drm_intel_bufmgr_fake_set_fence_callback(drm_intel_bufmgr *bufmgr, |
| 249 | unsigned int (*emit) (void *priv), |
| 250 | void (*wait) (unsigned int fence, |
| 251 | void *priv), |
| 252 | void *priv) |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 253 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 254 | drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 255 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 256 | bufmgr_fake->fence_emit = emit; |
| 257 | bufmgr_fake->fence_wait = wait; |
| 258 | bufmgr_fake->fence_priv = priv; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 261 | static unsigned int |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 262 | _fence_emit_internal(drm_intel_bufmgr_fake *bufmgr_fake) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 263 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 264 | struct drm_i915_irq_emit ie; |
| 265 | int ret, seq = 1; |
Eric Anholt | 869d8be | 2008-09-06 03:07:41 +0100 | [diff] [blame] | 266 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 267 | if (bufmgr_fake->fence_emit != NULL) { |
| 268 | seq = bufmgr_fake->fence_emit(bufmgr_fake->fence_priv); |
| 269 | return seq; |
| 270 | } |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 271 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 272 | ie.irq_seq = &seq; |
| 273 | ret = drmCommandWriteRead(bufmgr_fake->fd, DRM_I915_IRQ_EMIT, |
| 274 | &ie, sizeof(ie)); |
| 275 | if (ret) { |
Emil Velikov | 41eb131 | 2015-04-05 16:50:33 +0100 | [diff] [blame] | 276 | drmMsg("%s: drm_i915_irq_emit: %d\n", __func__, ret); |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 277 | abort(); |
| 278 | } |
Eric Anholt | 869d8be | 2008-09-06 03:07:41 +0100 | [diff] [blame] | 279 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 280 | DBG("emit 0x%08x\n", seq); |
| 281 | return seq; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 285 | _fence_wait_internal(drm_intel_bufmgr_fake *bufmgr_fake, int seq) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 286 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 287 | struct drm_i915_irq_wait iw; |
| 288 | int hw_seq, busy_count = 0; |
| 289 | int ret; |
| 290 | int kernel_lied; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 291 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 292 | if (bufmgr_fake->fence_wait != NULL) { |
| 293 | bufmgr_fake->fence_wait(seq, bufmgr_fake->fence_priv); |
| 294 | clear_fenced(bufmgr_fake, seq); |
| 295 | return; |
| 296 | } |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 297 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 298 | iw.irq_seq = seq; |
Eric Anholt | 0dccf01 | 2008-09-23 10:48:39 -0700 | [diff] [blame] | 299 | |
Eric Anholt | 58e54f6 | 2010-05-25 20:11:23 -0700 | [diff] [blame] | 300 | DBG("wait 0x%08x\n", iw.irq_seq); |
| 301 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 302 | /* The kernel IRQ_WAIT implementation is all sorts of broken. |
| 303 | * 1) It returns 1 to 0x7fffffff instead of using the full 32-bit |
| 304 | * unsigned range. |
| 305 | * 2) It returns 0 if hw_seq >= seq, not seq - hw_seq < 0 on the 32-bit |
| 306 | * signed range. |
| 307 | * 3) It waits if seq < hw_seq, not seq - hw_seq > 0 on the 32-bit |
| 308 | * signed range. |
| 309 | * 4) It returns -EBUSY in 3 seconds even if the hardware is still |
| 310 | * successfully chewing through buffers. |
| 311 | * |
| 312 | * Assume that in userland we treat sequence numbers as ints, which |
| 313 | * makes some of the comparisons convenient, since the sequence |
| 314 | * numbers are all postive signed integers. |
| 315 | * |
| 316 | * From this we get several cases we need to handle. Here's a timeline. |
| 317 | * 0x2 0x7 0x7ffffff8 0x7ffffffd |
| 318 | * | | | | |
| 319 | * ------------------------------------------------------------ |
| 320 | * |
| 321 | * A) Normal wait for hw to catch up |
| 322 | * hw_seq seq |
| 323 | * | | |
| 324 | * ------------------------------------------------------------ |
| 325 | * seq - hw_seq = 5. If we call IRQ_WAIT, it will wait for hw to |
| 326 | * catch up. |
| 327 | * |
| 328 | * B) Normal wait for a sequence number that's already passed. |
| 329 | * seq hw_seq |
| 330 | * | | |
| 331 | * ------------------------------------------------------------ |
| 332 | * seq - hw_seq = -5. If we call IRQ_WAIT, it returns 0 quickly. |
| 333 | * |
| 334 | * C) Hardware has already wrapped around ahead of us |
| 335 | * hw_seq seq |
| 336 | * | | |
| 337 | * ------------------------------------------------------------ |
| 338 | * seq - hw_seq = 0x80000000 - 5. If we called IRQ_WAIT, it would wait |
| 339 | * for hw_seq >= seq, which may never occur. Thus, we want to catch |
| 340 | * this in userland and return 0. |
| 341 | * |
| 342 | * D) We've wrapped around ahead of the hardware. |
| 343 | * seq hw_seq |
| 344 | * | | |
| 345 | * ------------------------------------------------------------ |
| 346 | * seq - hw_seq = -(0x80000000 - 5). If we called IRQ_WAIT, it would |
| 347 | * return 0 quickly because hw_seq >= seq, even though the hardware |
| 348 | * isn't caught up. Thus, we need to catch this early return in |
| 349 | * userland and bother the kernel until the hardware really does |
| 350 | * catch up. |
| 351 | * |
| 352 | * E) Hardware might wrap after we test in userland. |
| 353 | * hw_seq seq |
| 354 | * | | |
| 355 | * ------------------------------------------------------------ |
| 356 | * seq - hw_seq = 5. If we call IRQ_WAIT, it will likely see seq >= |
| 357 | * hw_seq and wait. However, suppose hw_seq wraps before we make it |
| 358 | * into the kernel. The kernel sees hw_seq >= seq and waits for 3 |
| 359 | * seconds then returns -EBUSY. This is case C). We should catch |
| 360 | * this and then return successfully. |
| 361 | * |
| 362 | * F) Hardware might take a long time on a buffer. |
| 363 | * hw_seq seq |
| 364 | * | | |
| 365 | * ------------------------------------------------------------------- |
| 366 | * seq - hw_seq = 5. If we call IRQ_WAIT, if sequence 2 through 5 |
| 367 | * take too long, it will return -EBUSY. Batchbuffers in the |
| 368 | * gltestperf demo were seen to take up to 7 seconds. We should |
| 369 | * catch early -EBUSY return and keep trying. |
| 370 | */ |
Eric Anholt | 2db8e0c | 2008-09-23 17:06:01 -0700 | [diff] [blame] | 371 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 372 | do { |
| 373 | /* Keep a copy of last_dispatch so that if the wait -EBUSYs |
| 374 | * because the hardware didn't catch up in 3 seconds, we can |
| 375 | * see if it at least made progress and retry. |
| 376 | */ |
| 377 | hw_seq = *bufmgr_fake->last_dispatch; |
Eric Anholt | 0dccf01 | 2008-09-23 10:48:39 -0700 | [diff] [blame] | 378 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 379 | /* Catch case C */ |
| 380 | if (seq - hw_seq > 0x40000000) |
| 381 | return; |
Eric Anholt | 0dccf01 | 2008-09-23 10:48:39 -0700 | [diff] [blame] | 382 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 383 | ret = drmCommandWrite(bufmgr_fake->fd, DRM_I915_IRQ_WAIT, |
| 384 | &iw, sizeof(iw)); |
| 385 | /* Catch case D */ |
| 386 | kernel_lied = (ret == 0) && (seq - *bufmgr_fake->last_dispatch < |
| 387 | -0x40000000); |
Eric Anholt | 0dccf01 | 2008-09-23 10:48:39 -0700 | [diff] [blame] | 388 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 389 | /* Catch case E */ |
| 390 | if (ret == -EBUSY |
| 391 | && (seq - *bufmgr_fake->last_dispatch > 0x40000000)) |
| 392 | ret = 0; |
Eric Anholt | 2db8e0c | 2008-09-23 17:06:01 -0700 | [diff] [blame] | 393 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 394 | /* Catch case F: Allow up to 15 seconds chewing on one buffer. */ |
| 395 | if ((ret == -EBUSY) && (hw_seq != *bufmgr_fake->last_dispatch)) |
| 396 | busy_count = 0; |
| 397 | else |
| 398 | busy_count++; |
| 399 | } while (kernel_lied || ret == -EAGAIN || ret == -EINTR || |
| 400 | (ret == -EBUSY && busy_count < 5)); |
Eric Anholt | 869d8be | 2008-09-06 03:07:41 +0100 | [diff] [blame] | 401 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 402 | if (ret != 0) { |
| 403 | drmMsg("%s:%d: Error waiting for fence: %s.\n", __FILE__, |
| 404 | __LINE__, strerror(-ret)); |
| 405 | abort(); |
| 406 | } |
| 407 | clear_fenced(bufmgr_fake, seq); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 410 | static int |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 411 | _fence_test(drm_intel_bufmgr_fake *bufmgr_fake, unsigned fence) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 412 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 413 | /* Slight problem with wrap-around: |
| 414 | */ |
| 415 | return fence == 0 || FENCE_LTE(fence, bufmgr_fake->last_fence); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Allocate a memory manager block for the buffer. |
| 420 | */ |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 421 | static int |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 422 | alloc_block(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 423 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 424 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
| 425 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 426 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 427 | struct block *block = (struct block *)calloc(sizeof *block, 1); |
| 428 | unsigned int align_log2 = ffs(bo_fake->alignment) - 1; |
| 429 | unsigned int sz; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 430 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 431 | if (!block) |
| 432 | return 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 433 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 434 | sz = (bo->size + bo_fake->alignment - 1) & ~(bo_fake->alignment - 1); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 435 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 436 | block->mem = mmAllocMem(bufmgr_fake->heap, sz, align_log2, 0); |
| 437 | if (!block->mem) { |
| 438 | free(block); |
| 439 | return 0; |
| 440 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 441 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 442 | DRMINITLISTHEAD(block); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 443 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 444 | /* Insert at head or at tail??? */ |
| 445 | DRMLISTADDTAIL(block, &bufmgr_fake->lru); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 446 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 447 | block->virtual = (uint8_t *) bufmgr_fake->virtual + |
| 448 | block->mem->ofs - bufmgr_fake->low_offset; |
| 449 | block->bo = bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 450 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 451 | bo_fake->block = block; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 452 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 453 | return 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* Release the card storage associated with buf: |
| 457 | */ |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 458 | static void |
| 459 | free_block(drm_intel_bufmgr_fake *bufmgr_fake, struct block *block, |
| 460 | int skip_dirty_copy) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 461 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 462 | drm_intel_bo_fake *bo_fake; |
| 463 | DBG("free block %p %08x %d %d\n", block, block->mem->ofs, |
| 464 | block->on_hardware, block->fenced); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 465 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 466 | if (!block) |
| 467 | return; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 468 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 469 | bo_fake = (drm_intel_bo_fake *) block->bo; |
Eric Anholt | efa485b | 2009-02-24 21:36:56 -0800 | [diff] [blame] | 470 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 471 | if (bo_fake->flags & (BM_PINNED | BM_NO_BACKING_STORE)) |
| 472 | skip_dirty_copy = 1; |
Eric Anholt | efa485b | 2009-02-24 21:36:56 -0800 | [diff] [blame] | 473 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 474 | if (!skip_dirty_copy && (bo_fake->card_dirty == 1)) { |
| 475 | memcpy(bo_fake->backing_store, block->virtual, block->bo->size); |
| 476 | bo_fake->card_dirty = 0; |
| 477 | bo_fake->dirty = 1; |
| 478 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 479 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 480 | if (block->on_hardware) { |
| 481 | block->bo = NULL; |
| 482 | } else if (block->fenced) { |
| 483 | block->bo = NULL; |
| 484 | } else { |
| 485 | DBG(" - free immediately\n"); |
| 486 | DRMLISTDEL(block); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 487 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 488 | mmFreeMem(block->mem); |
| 489 | free(block); |
| 490 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 494 | alloc_backing_store(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 495 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 496 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 497 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 498 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
| 499 | assert(!bo_fake->backing_store); |
| 500 | assert(!(bo_fake->flags & (BM_PINNED | BM_NO_BACKING_STORE))); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 501 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 502 | bo_fake->backing_store = malloc(bo->size); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 503 | |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 504 | DBG("alloc_backing - buf %d %p %lu\n", bo_fake->id, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 505 | bo_fake->backing_store, bo->size); |
| 506 | assert(bo_fake->backing_store); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 510 | free_backing_store(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 511 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 512 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 513 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 514 | if (bo_fake->backing_store) { |
| 515 | assert(!(bo_fake->flags & (BM_PINNED | BM_NO_BACKING_STORE))); |
| 516 | free(bo_fake->backing_store); |
| 517 | bo_fake->backing_store = NULL; |
| 518 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 522 | set_dirty(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 523 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 524 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 525 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 526 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 527 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 528 | if (bo_fake->flags & BM_NO_BACKING_STORE |
| 529 | && bo_fake->invalidate_cb != NULL) |
| 530 | bo_fake->invalidate_cb(bo, bo_fake->invalidate_ptr); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 531 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 532 | assert(!(bo_fake->flags & BM_PINNED)); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 533 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 534 | DBG("set_dirty - buf %d\n", bo_fake->id); |
| 535 | bo_fake->dirty = 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 538 | static int |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 539 | evict_lru(drm_intel_bufmgr_fake *bufmgr_fake, unsigned int max_fence) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 540 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 541 | struct block *block, *tmp; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 542 | |
Emil Velikov | 41eb131 | 2015-04-05 16:50:33 +0100 | [diff] [blame] | 543 | DBG("%s\n", __func__); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 544 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 545 | DRMLISTFOREACHSAFE(block, tmp, &bufmgr_fake->lru) { |
| 546 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) block->bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 547 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 548 | if (bo_fake != NULL && (bo_fake->flags & BM_NO_FENCE_SUBDATA)) |
| 549 | continue; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 550 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 551 | if (block->fence && max_fence && !FENCE_LTE(block->fence, |
| 552 | max_fence)) |
| 553 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 554 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 555 | set_dirty(&bo_fake->bo); |
| 556 | bo_fake->block = NULL; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 557 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 558 | free_block(bufmgr_fake, block, 0); |
| 559 | return 1; |
| 560 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 561 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 562 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 565 | static int |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 566 | evict_mru(drm_intel_bufmgr_fake *bufmgr_fake) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 567 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 568 | struct block *block, *tmp; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 569 | |
Emil Velikov | 41eb131 | 2015-04-05 16:50:33 +0100 | [diff] [blame] | 570 | DBG("%s\n", __func__); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 571 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 572 | DRMLISTFOREACHSAFEREVERSE(block, tmp, &bufmgr_fake->lru) { |
| 573 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) block->bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 574 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 575 | if (bo_fake && (bo_fake->flags & BM_NO_FENCE_SUBDATA)) |
| 576 | continue; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 577 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 578 | set_dirty(&bo_fake->bo); |
| 579 | bo_fake->block = NULL; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 580 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 581 | free_block(bufmgr_fake, block, 0); |
| 582 | return 1; |
| 583 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 584 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 585 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Removes all objects from the fenced list older than the given fence. |
| 590 | */ |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 591 | static int |
| 592 | clear_fenced(drm_intel_bufmgr_fake *bufmgr_fake, unsigned int fence_cookie) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 593 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 594 | struct block *block, *tmp; |
| 595 | int ret = 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 596 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 597 | bufmgr_fake->last_fence = fence_cookie; |
| 598 | DRMLISTFOREACHSAFE(block, tmp, &bufmgr_fake->fenced) { |
| 599 | assert(block->fenced); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 600 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 601 | if (_fence_test(bufmgr_fake, block->fence)) { |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 602 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 603 | block->fenced = 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 604 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 605 | if (!block->bo) { |
| 606 | DBG("delayed free: offset %x sz %x\n", |
| 607 | block->mem->ofs, block->mem->size); |
| 608 | DRMLISTDEL(block); |
| 609 | mmFreeMem(block->mem); |
| 610 | free(block); |
| 611 | } else { |
| 612 | DBG("return to lru: offset %x sz %x\n", |
| 613 | block->mem->ofs, block->mem->size); |
| 614 | DRMLISTDEL(block); |
| 615 | DRMLISTADDTAIL(block, &bufmgr_fake->lru); |
| 616 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 617 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 618 | ret = 1; |
| 619 | } else { |
| 620 | /* Blocks are ordered by fence, so if one fails, all |
| 621 | * from here will fail also: |
| 622 | */ |
| 623 | DBG("fence not passed: offset %x sz %x %d %d \n", |
| 624 | block->mem->ofs, block->mem->size, block->fence, |
| 625 | bufmgr_fake->last_fence); |
| 626 | break; |
| 627 | } |
| 628 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 629 | |
Emil Velikov | 41eb131 | 2015-04-05 16:50:33 +0100 | [diff] [blame] | 630 | DBG("%s: %d\n", __func__, ret); |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 631 | return ret; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 634 | static void |
| 635 | fence_blocks(drm_intel_bufmgr_fake *bufmgr_fake, unsigned fence) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 636 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 637 | struct block *block, *tmp; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 638 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 639 | DRMLISTFOREACHSAFE(block, tmp, &bufmgr_fake->on_hardware) { |
| 640 | DBG("Fence block %p (sz 0x%x ofs %x buf %p) with fence %d\n", |
| 641 | block, block->mem->size, block->mem->ofs, block->bo, fence); |
| 642 | block->fence = fence; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 643 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 644 | block->on_hardware = 0; |
| 645 | block->fenced = 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 646 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 647 | /* Move to tail of pending list here |
| 648 | */ |
| 649 | DRMLISTDEL(block); |
| 650 | DRMLISTADDTAIL(block, &bufmgr_fake->fenced); |
| 651 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 652 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 653 | assert(DRMLISTEMPTY(&bufmgr_fake->on_hardware)); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 656 | static int |
| 657 | evict_and_alloc_block(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 658 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 659 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 660 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 661 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 662 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 663 | assert(bo_fake->block == NULL); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 664 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 665 | /* Search for already free memory: |
| 666 | */ |
| 667 | if (alloc_block(bo)) |
| 668 | return 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 669 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 670 | /* If we're not thrashing, allow lru eviction to dig deeper into |
| 671 | * recently used textures. We'll probably be thrashing soon: |
| 672 | */ |
| 673 | if (!bufmgr_fake->thrashing) { |
| 674 | while (evict_lru(bufmgr_fake, 0)) |
| 675 | if (alloc_block(bo)) |
| 676 | return 1; |
| 677 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 678 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 679 | /* Keep thrashing counter alive? |
| 680 | */ |
| 681 | if (bufmgr_fake->thrashing) |
| 682 | bufmgr_fake->thrashing = 20; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 683 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 684 | /* Wait on any already pending fences - here we are waiting for any |
| 685 | * freed memory that has been submitted to hardware and fenced to |
| 686 | * become available: |
| 687 | */ |
| 688 | while (!DRMLISTEMPTY(&bufmgr_fake->fenced)) { |
| 689 | uint32_t fence = bufmgr_fake->fenced.next->fence; |
| 690 | _fence_wait_internal(bufmgr_fake, fence); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 691 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 692 | if (alloc_block(bo)) |
| 693 | return 1; |
| 694 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 695 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 696 | if (!DRMLISTEMPTY(&bufmgr_fake->on_hardware)) { |
| 697 | while (!DRMLISTEMPTY(&bufmgr_fake->fenced)) { |
| 698 | uint32_t fence = bufmgr_fake->fenced.next->fence; |
| 699 | _fence_wait_internal(bufmgr_fake, fence); |
| 700 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 701 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 702 | if (!bufmgr_fake->thrashing) { |
| 703 | DBG("thrashing\n"); |
| 704 | } |
| 705 | bufmgr_fake->thrashing = 20; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 706 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 707 | if (alloc_block(bo)) |
| 708 | return 1; |
| 709 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 710 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 711 | while (evict_mru(bufmgr_fake)) |
| 712 | if (alloc_block(bo)) |
| 713 | return 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 714 | |
Emil Velikov | 41eb131 | 2015-04-05 16:50:33 +0100 | [diff] [blame] | 715 | DBG("%s 0x%lx bytes failed\n", __func__, bo->size); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 716 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 717 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /*********************************************************************** |
| 721 | * Public functions |
| 722 | */ |
| 723 | |
| 724 | /** |
| 725 | * Wait for hardware idle by emitting a fence and waiting for it. |
| 726 | */ |
| 727 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 728 | drm_intel_bufmgr_fake_wait_idle(drm_intel_bufmgr_fake *bufmgr_fake) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 729 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 730 | unsigned int cookie; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 731 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 732 | cookie = _fence_emit_internal(bufmgr_fake); |
| 733 | _fence_wait_internal(bufmgr_fake, cookie); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Wait for rendering to a buffer to complete. |
| 738 | * |
| 739 | * It is assumed that the bathcbuffer which performed the rendering included |
| 740 | * the necessary flushing. |
| 741 | */ |
| 742 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 743 | drm_intel_fake_bo_wait_rendering_locked(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 744 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 745 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 746 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 747 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 748 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 749 | if (bo_fake->block == NULL || !bo_fake->block->fenced) |
| 750 | return; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 751 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 752 | _fence_wait_internal(bufmgr_fake, bo_fake->block->fence); |
Eric Anholt | 3e03d78 | 2008-10-13 13:41:10 -0700 | [diff] [blame] | 753 | } |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 754 | |
Eric Anholt | 3e03d78 | 2008-10-13 13:41:10 -0700 | [diff] [blame] | 755 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 756 | drm_intel_fake_bo_wait_rendering(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 757 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 758 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 759 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 760 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 761 | pthread_mutex_lock(&bufmgr_fake->lock); |
| 762 | drm_intel_fake_bo_wait_rendering_locked(bo); |
| 763 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /* Specifically ignore texture memory sharing. |
| 767 | * -- just evict everything |
| 768 | * -- and wait for idle |
| 769 | */ |
Emil Velikov | 0f8da82 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 770 | void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 771 | drm_intel_bufmgr_fake_contended_lock_take(drm_intel_bufmgr *bufmgr) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 772 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 773 | drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
| 774 | struct block *block, *tmp; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 775 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 776 | pthread_mutex_lock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 777 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 778 | bufmgr_fake->need_fence = 1; |
| 779 | bufmgr_fake->fail = 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 780 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 781 | /* Wait for hardware idle. We don't know where acceleration has been |
| 782 | * happening, so we'll need to wait anyway before letting anything get |
| 783 | * put on the card again. |
| 784 | */ |
| 785 | drm_intel_bufmgr_fake_wait_idle(bufmgr_fake); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 786 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 787 | /* Check that we hadn't released the lock without having fenced the last |
| 788 | * set of buffers. |
| 789 | */ |
| 790 | assert(DRMLISTEMPTY(&bufmgr_fake->fenced)); |
| 791 | assert(DRMLISTEMPTY(&bufmgr_fake->on_hardware)); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 792 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 793 | DRMLISTFOREACHSAFE(block, tmp, &bufmgr_fake->lru) { |
| 794 | assert(_fence_test(bufmgr_fake, block->fence)); |
| 795 | set_dirty(block->bo); |
| 796 | } |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 797 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 798 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 801 | static drm_intel_bo * |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 802 | drm_intel_fake_bo_alloc(drm_intel_bufmgr *bufmgr, |
| 803 | const char *name, |
| 804 | unsigned long size, |
| 805 | unsigned int alignment) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 806 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 807 | drm_intel_bufmgr_fake *bufmgr_fake; |
| 808 | drm_intel_bo_fake *bo_fake; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 809 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 810 | bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 811 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 812 | assert(size != 0); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 813 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 814 | bo_fake = calloc(1, sizeof(*bo_fake)); |
| 815 | if (!bo_fake) |
| 816 | return NULL; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 817 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 818 | bo_fake->bo.size = size; |
| 819 | bo_fake->bo.offset = -1; |
| 820 | bo_fake->bo.virtual = NULL; |
| 821 | bo_fake->bo.bufmgr = bufmgr; |
| 822 | bo_fake->refcount = 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 823 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 824 | /* Alignment must be a power of two */ |
| 825 | assert((alignment & (alignment - 1)) == 0); |
| 826 | if (alignment == 0) |
| 827 | alignment = 1; |
| 828 | bo_fake->alignment = alignment; |
| 829 | bo_fake->id = ++bufmgr_fake->buf_nr; |
| 830 | bo_fake->name = name; |
| 831 | bo_fake->flags = 0; |
| 832 | bo_fake->is_static = 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 833 | |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 834 | DBG("drm_bo_alloc: (buf %d: %s, %lu kb)\n", bo_fake->id, bo_fake->name, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 835 | bo_fake->bo.size / 1024); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 836 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 837 | return &bo_fake->bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Jesse Barnes | 3a7dfcd | 2009-10-06 14:34:06 -0700 | [diff] [blame] | 840 | static drm_intel_bo * |
| 841 | drm_intel_fake_bo_alloc_tiled(drm_intel_bufmgr * bufmgr, |
| 842 | const char *name, |
| 843 | int x, int y, int cpp, |
| 844 | uint32_t *tiling_mode, |
| 845 | unsigned long *pitch, |
| 846 | unsigned long flags) |
| 847 | { |
| 848 | unsigned long stride, aligned_y; |
| 849 | |
| 850 | /* No runtime tiling support for fake. */ |
| 851 | *tiling_mode = I915_TILING_NONE; |
| 852 | |
| 853 | /* Align it for being a render target. Shouldn't need anything else. */ |
| 854 | stride = x * cpp; |
| 855 | stride = ROUND_UP_TO(stride, 64); |
| 856 | |
| 857 | /* 965 subspan loading alignment */ |
| 858 | aligned_y = ALIGN(y, 2); |
| 859 | |
| 860 | *pitch = stride; |
| 861 | |
| 862 | return drm_intel_fake_bo_alloc(bufmgr, name, stride * aligned_y, |
| 863 | 4096); |
| 864 | } |
| 865 | |
Emil Velikov | 0f8da82 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 866 | drm_intel_bo * |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 867 | drm_intel_bo_fake_alloc_static(drm_intel_bufmgr *bufmgr, |
| 868 | const char *name, |
| 869 | unsigned long offset, |
| 870 | unsigned long size, void *virtual) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 871 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 872 | drm_intel_bufmgr_fake *bufmgr_fake; |
| 873 | drm_intel_bo_fake *bo_fake; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 874 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 875 | bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 876 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 877 | assert(size != 0); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 878 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 879 | bo_fake = calloc(1, sizeof(*bo_fake)); |
| 880 | if (!bo_fake) |
| 881 | return NULL; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 882 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 883 | bo_fake->bo.size = size; |
| 884 | bo_fake->bo.offset = offset; |
| 885 | bo_fake->bo.virtual = virtual; |
| 886 | bo_fake->bo.bufmgr = bufmgr; |
| 887 | bo_fake->refcount = 1; |
| 888 | bo_fake->id = ++bufmgr_fake->buf_nr; |
| 889 | bo_fake->name = name; |
| 890 | bo_fake->flags = BM_PINNED; |
| 891 | bo_fake->is_static = 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 892 | |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 893 | DBG("drm_bo_alloc_static: (buf %d: %s, %lu kb)\n", bo_fake->id, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 894 | bo_fake->name, bo_fake->bo.size / 1024); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 895 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 896 | return &bo_fake->bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 900 | drm_intel_fake_bo_reference(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 901 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 902 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 903 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 904 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 905 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 906 | pthread_mutex_lock(&bufmgr_fake->lock); |
| 907 | bo_fake->refcount++; |
| 908 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 912 | drm_intel_fake_bo_reference_locked(drm_intel_bo *bo) |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 913 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 914 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 915 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 916 | bo_fake->refcount++; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 920 | drm_intel_fake_bo_unreference_locked(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 921 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 922 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 923 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 924 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
| 925 | int i; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 926 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 927 | if (--bo_fake->refcount == 0) { |
| 928 | assert(bo_fake->map_count == 0); |
| 929 | /* No remaining references, so free it */ |
| 930 | if (bo_fake->block) |
| 931 | free_block(bufmgr_fake, bo_fake->block, 1); |
| 932 | free_backing_store(bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 933 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 934 | for (i = 0; i < bo_fake->nr_relocs; i++) |
| 935 | drm_intel_fake_bo_unreference_locked(bo_fake->relocs[i]. |
| 936 | target_buf); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 937 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 938 | DBG("drm_bo_unreference: free buf %d %s\n", bo_fake->id, |
| 939 | bo_fake->name); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 940 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 941 | free(bo_fake->relocs); |
| 942 | free(bo); |
| 943 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 946 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 947 | drm_intel_fake_bo_unreference(drm_intel_bo *bo) |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 948 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 949 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 950 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 951 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 952 | pthread_mutex_lock(&bufmgr_fake->lock); |
| 953 | drm_intel_fake_bo_unreference_locked(bo); |
| 954 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 957 | /** |
| 958 | * Set the buffer as not requiring backing store, and instead get the callback |
| 959 | * invoked whenever it would be set dirty. |
| 960 | */ |
Emil Velikov | 0f8da82 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 961 | void |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 962 | drm_intel_bo_fake_disable_backing_store(drm_intel_bo *bo, |
| 963 | void (*invalidate_cb) (drm_intel_bo *bo, |
| 964 | void *ptr), |
| 965 | void *ptr) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 966 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 967 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 968 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 969 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 970 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 971 | pthread_mutex_lock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 972 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 973 | if (bo_fake->backing_store) |
| 974 | free_backing_store(bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 975 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 976 | bo_fake->flags |= BM_NO_BACKING_STORE; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 977 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 978 | DBG("disable_backing_store set buf %d dirty\n", bo_fake->id); |
| 979 | bo_fake->dirty = 1; |
| 980 | bo_fake->invalidate_cb = invalidate_cb; |
| 981 | bo_fake->invalidate_ptr = ptr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 982 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 983 | /* Note that it is invalid right from the start. Also note |
| 984 | * invalidate_cb is called with the bufmgr locked, so cannot |
| 985 | * itself make bufmgr calls. |
| 986 | */ |
| 987 | if (invalidate_cb != NULL) |
| 988 | invalidate_cb(bo, ptr); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 989 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 990 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /** |
| 994 | * Map a buffer into bo->virtual, allocating either card memory space (If |
| 995 | * BM_NO_BACKING_STORE or BM_PINNED) or backing store, as necessary. |
| 996 | */ |
| 997 | static int |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 998 | drm_intel_fake_bo_map_locked(drm_intel_bo *bo, int write_enable) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 999 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1000 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1001 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 1002 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1003 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1004 | /* Static buffers are always mapped. */ |
| 1005 | if (bo_fake->is_static) { |
| 1006 | if (bo_fake->card_dirty) { |
| 1007 | drm_intel_bufmgr_fake_wait_idle(bufmgr_fake); |
| 1008 | bo_fake->card_dirty = 0; |
| 1009 | } |
| 1010 | return 0; |
| 1011 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1012 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1013 | /* Allow recursive mapping. Mesa may recursively map buffers with |
| 1014 | * nested display loops, and it is used internally in bufmgr_fake |
| 1015 | * for relocation. |
| 1016 | */ |
| 1017 | if (bo_fake->map_count++ != 0) |
| 1018 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1019 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1020 | { |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 1021 | DBG("drm_bo_map: (buf %d: %s, %lu kb)\n", bo_fake->id, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1022 | bo_fake->name, bo_fake->bo.size / 1024); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1023 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1024 | if (bo->virtual != NULL) { |
Emil Velikov | 41eb131 | 2015-04-05 16:50:33 +0100 | [diff] [blame] | 1025 | drmMsg("%s: already mapped\n", __func__); |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1026 | abort(); |
| 1027 | } else if (bo_fake->flags & (BM_NO_BACKING_STORE | BM_PINNED)) { |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1028 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1029 | if (!bo_fake->block && !evict_and_alloc_block(bo)) { |
Emil Velikov | 41eb131 | 2015-04-05 16:50:33 +0100 | [diff] [blame] | 1030 | DBG("%s: alloc failed\n", __func__); |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1031 | bufmgr_fake->fail = 1; |
| 1032 | return 1; |
| 1033 | } else { |
| 1034 | assert(bo_fake->block); |
| 1035 | bo_fake->dirty = 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1036 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1037 | if (!(bo_fake->flags & BM_NO_FENCE_SUBDATA) && |
| 1038 | bo_fake->block->fenced) { |
| 1039 | drm_intel_fake_bo_wait_rendering_locked |
| 1040 | (bo); |
| 1041 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1042 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1043 | bo->virtual = bo_fake->block->virtual; |
| 1044 | } |
| 1045 | } else { |
| 1046 | if (write_enable) |
| 1047 | set_dirty(bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1048 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1049 | if (bo_fake->backing_store == 0) |
| 1050 | alloc_backing_store(bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1051 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1052 | if ((bo_fake->card_dirty == 1) && bo_fake->block) { |
| 1053 | if (bo_fake->block->fenced) |
| 1054 | drm_intel_fake_bo_wait_rendering_locked |
| 1055 | (bo); |
Xiang, Haihao | 604759d | 2008-10-09 11:57:13 +0800 | [diff] [blame] | 1056 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1057 | memcpy(bo_fake->backing_store, |
| 1058 | bo_fake->block->virtual, |
| 1059 | bo_fake->block->bo->size); |
| 1060 | bo_fake->card_dirty = 0; |
| 1061 | } |
Xiang, Haihao | 073cb5e | 2008-09-27 11:01:24 +0800 | [diff] [blame] | 1062 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1063 | bo->virtual = bo_fake->backing_store; |
| 1064 | } |
| 1065 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1066 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1067 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | static int |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1071 | drm_intel_fake_bo_map(drm_intel_bo *bo, int write_enable) |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1072 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1073 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1074 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 1075 | int ret; |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1076 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1077 | pthread_mutex_lock(&bufmgr_fake->lock); |
| 1078 | ret = drm_intel_fake_bo_map_locked(bo, write_enable); |
| 1079 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1080 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1081 | return ret; |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | static int |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1085 | drm_intel_fake_bo_unmap_locked(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1086 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1087 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1088 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 1089 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1090 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1091 | /* Static buffers are always mapped. */ |
| 1092 | if (bo_fake->is_static) |
| 1093 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1094 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1095 | assert(bo_fake->map_count != 0); |
| 1096 | if (--bo_fake->map_count != 0) |
| 1097 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1098 | |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 1099 | DBG("drm_bo_unmap: (buf %d: %s, %lu kb)\n", bo_fake->id, bo_fake->name, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1100 | bo_fake->bo.size / 1024); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1101 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1102 | bo->virtual = NULL; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1103 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1104 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1107 | static int drm_intel_fake_bo_unmap(drm_intel_bo *bo) |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1108 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1109 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1110 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 1111 | int ret; |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1112 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1113 | pthread_mutex_lock(&bufmgr_fake->lock); |
| 1114 | ret = drm_intel_fake_bo_unmap_locked(bo); |
| 1115 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1116 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1117 | return ret; |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Eric Anholt | f45305c | 2010-11-01 06:54:58 -0700 | [diff] [blame] | 1120 | static int |
| 1121 | drm_intel_fake_bo_subdata(drm_intel_bo *bo, unsigned long offset, |
| 1122 | unsigned long size, const void *data) |
| 1123 | { |
| 1124 | int ret; |
| 1125 | |
| 1126 | if (size == 0 || data == NULL) |
| 1127 | return 0; |
| 1128 | |
| 1129 | ret = drm_intel_bo_map(bo, 1); |
| 1130 | if (ret) |
| 1131 | return ret; |
| 1132 | memcpy((unsigned char *)bo->virtual + offset, data, size); |
| 1133 | drm_intel_bo_unmap(bo); |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1137 | static void |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1138 | drm_intel_fake_kick_all_locked(drm_intel_bufmgr_fake *bufmgr_fake) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1139 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1140 | struct block *block, *tmp; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1141 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1142 | bufmgr_fake->performed_rendering = 0; |
| 1143 | /* okay for ever BO that is on the HW kick it off. |
| 1144 | seriously not afraid of the POLICE right now */ |
| 1145 | DRMLISTFOREACHSAFE(block, tmp, &bufmgr_fake->on_hardware) { |
| 1146 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) block->bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1147 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1148 | block->on_hardware = 0; |
| 1149 | free_block(bufmgr_fake, block, 0); |
| 1150 | bo_fake->block = NULL; |
| 1151 | bo_fake->validated = 0; |
| 1152 | if (!(bo_fake->flags & BM_NO_BACKING_STORE)) |
| 1153 | bo_fake->dirty = 1; |
| 1154 | } |
Jesse Barnes | 9583c09 | 2008-12-10 15:47:28 -0800 | [diff] [blame] | 1155 | |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | static int |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1159 | drm_intel_fake_bo_validate(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1160 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1161 | drm_intel_bufmgr_fake *bufmgr_fake; |
| 1162 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1163 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1164 | bufmgr_fake = (drm_intel_bufmgr_fake *) bo->bufmgr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1165 | |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 1166 | DBG("drm_bo_validate: (buf %d: %s, %lu kb)\n", bo_fake->id, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1167 | bo_fake->name, bo_fake->bo.size / 1024); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1168 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1169 | /* Sanity check: Buffers should be unmapped before being validated. |
| 1170 | * This is not so much of a problem for bufmgr_fake, but TTM refuses, |
| 1171 | * and the problem is harder to debug there. |
| 1172 | */ |
| 1173 | assert(bo_fake->map_count == 0); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1174 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1175 | if (bo_fake->is_static) { |
| 1176 | /* Add it to the needs-fence list */ |
| 1177 | bufmgr_fake->need_fence = 1; |
| 1178 | return 0; |
| 1179 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1180 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1181 | /* Allocate the card memory */ |
| 1182 | if (!bo_fake->block && !evict_and_alloc_block(bo)) { |
| 1183 | bufmgr_fake->fail = 1; |
| 1184 | DBG("Failed to validate buf %d:%s\n", bo_fake->id, |
| 1185 | bo_fake->name); |
| 1186 | return -1; |
| 1187 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1188 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1189 | assert(bo_fake->block); |
| 1190 | assert(bo_fake->block->bo == &bo_fake->bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1191 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1192 | bo->offset = bo_fake->block->mem->ofs; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1193 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1194 | /* Upload the buffer contents if necessary */ |
| 1195 | if (bo_fake->dirty) { |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 1196 | DBG("Upload dirty buf %d:%s, sz %lu offset 0x%x\n", bo_fake->id, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1197 | bo_fake->name, bo->size, bo_fake->block->mem->ofs); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1198 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1199 | assert(!(bo_fake->flags & (BM_NO_BACKING_STORE | BM_PINNED))); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1200 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1201 | /* Actually, should be able to just wait for a fence on the |
| 1202 | * mmory, hich we would be tracking when we free it. Waiting |
| 1203 | * for idle is a sufficiently large hammer for now. |
| 1204 | */ |
| 1205 | drm_intel_bufmgr_fake_wait_idle(bufmgr_fake); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1206 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1207 | /* we may never have mapped this BO so it might not have any |
| 1208 | * backing store if this happens it should be rare, but 0 the |
| 1209 | * card memory in any case */ |
| 1210 | if (bo_fake->backing_store) |
| 1211 | memcpy(bo_fake->block->virtual, bo_fake->backing_store, |
| 1212 | bo->size); |
| 1213 | else |
| 1214 | memset(bo_fake->block->virtual, 0, bo->size); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1215 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1216 | bo_fake->dirty = 0; |
| 1217 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1218 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1219 | bo_fake->block->fenced = 0; |
| 1220 | bo_fake->block->on_hardware = 1; |
| 1221 | DRMLISTDEL(bo_fake->block); |
| 1222 | DRMLISTADDTAIL(bo_fake->block, &bufmgr_fake->on_hardware); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1223 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1224 | bo_fake->validated = 1; |
| 1225 | bufmgr_fake->need_fence = 1; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1226 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1227 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 1231 | drm_intel_fake_fence_validated(drm_intel_bufmgr *bufmgr) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1232 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1233 | drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
| 1234 | unsigned int cookie; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1235 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1236 | cookie = _fence_emit_internal(bufmgr_fake); |
| 1237 | fence_blocks(bufmgr_fake, cookie); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1238 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1239 | DBG("drm_fence_validated: 0x%08x cookie\n", cookie); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 1243 | drm_intel_fake_destroy(drm_intel_bufmgr *bufmgr) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1244 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1245 | drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1246 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1247 | pthread_mutex_destroy(&bufmgr_fake->lock); |
| 1248 | mmDestroy(bufmgr_fake->heap); |
| 1249 | free(bufmgr); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | static int |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 1253 | drm_intel_fake_emit_reloc(drm_intel_bo *bo, uint32_t offset, |
| 1254 | drm_intel_bo *target_bo, uint32_t target_offset, |
| 1255 | uint32_t read_domains, uint32_t write_domain) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1256 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1257 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1258 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 1259 | struct fake_buffer_reloc *r; |
| 1260 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
| 1261 | drm_intel_bo_fake *target_fake = (drm_intel_bo_fake *) target_bo; |
| 1262 | int i; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1263 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1264 | pthread_mutex_lock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1265 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1266 | assert(bo); |
| 1267 | assert(target_bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1268 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1269 | if (bo_fake->relocs == NULL) { |
| 1270 | bo_fake->relocs = |
| 1271 | malloc(sizeof(struct fake_buffer_reloc) * MAX_RELOCS); |
| 1272 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1273 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1274 | r = &bo_fake->relocs[bo_fake->nr_relocs++]; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1275 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1276 | assert(bo_fake->nr_relocs <= MAX_RELOCS); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1277 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1278 | drm_intel_fake_bo_reference_locked(target_bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1279 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1280 | if (!target_fake->is_static) { |
| 1281 | bo_fake->child_size += |
| 1282 | ALIGN(target_bo->size, target_fake->alignment); |
| 1283 | bo_fake->child_size += target_fake->child_size; |
| 1284 | } |
| 1285 | r->target_buf = target_bo; |
| 1286 | r->offset = offset; |
| 1287 | r->last_target_offset = target_bo->offset; |
| 1288 | r->delta = target_offset; |
| 1289 | r->read_domains = read_domains; |
| 1290 | r->write_domain = write_domain; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1291 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1292 | if (bufmgr_fake->debug) { |
| 1293 | /* Check that a conflicting relocation hasn't already been |
| 1294 | * emitted. |
| 1295 | */ |
| 1296 | for (i = 0; i < bo_fake->nr_relocs - 1; i++) { |
| 1297 | struct fake_buffer_reloc *r2 = &bo_fake->relocs[i]; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1298 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1299 | assert(r->offset != r2->offset); |
| 1300 | } |
| 1301 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1302 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1303 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1304 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1305 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | /** |
| 1309 | * Incorporates the validation flags associated with each relocation into |
| 1310 | * the combined validation flags for the buffer on this batchbuffer submission. |
| 1311 | */ |
| 1312 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 1313 | drm_intel_fake_calculate_domains(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1314 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1315 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
| 1316 | int i; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1317 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1318 | for (i = 0; i < bo_fake->nr_relocs; i++) { |
| 1319 | struct fake_buffer_reloc *r = &bo_fake->relocs[i]; |
| 1320 | drm_intel_bo_fake *target_fake = |
| 1321 | (drm_intel_bo_fake *) r->target_buf; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1322 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1323 | /* Do the same for the tree of buffers we depend on */ |
| 1324 | drm_intel_fake_calculate_domains(r->target_buf); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1325 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1326 | target_fake->read_domains |= r->read_domains; |
| 1327 | target_fake->write_domain |= r->write_domain; |
| 1328 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1331 | static int |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 1332 | drm_intel_fake_reloc_and_validate_buffer(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1333 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1334 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1335 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 1336 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
| 1337 | int i, ret; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1338 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1339 | assert(bo_fake->map_count == 0); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1340 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1341 | for (i = 0; i < bo_fake->nr_relocs; i++) { |
| 1342 | struct fake_buffer_reloc *r = &bo_fake->relocs[i]; |
| 1343 | drm_intel_bo_fake *target_fake = |
| 1344 | (drm_intel_bo_fake *) r->target_buf; |
| 1345 | uint32_t reloc_data; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1346 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1347 | /* Validate the target buffer if that hasn't been done. */ |
| 1348 | if (!target_fake->validated) { |
| 1349 | ret = |
| 1350 | drm_intel_fake_reloc_and_validate_buffer(r->target_buf); |
| 1351 | if (ret != 0) { |
| 1352 | if (bo->virtual != NULL) |
| 1353 | drm_intel_fake_bo_unmap_locked(bo); |
| 1354 | return ret; |
| 1355 | } |
| 1356 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1357 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1358 | /* Calculate the value of the relocation entry. */ |
| 1359 | if (r->target_buf->offset != r->last_target_offset) { |
| 1360 | reloc_data = r->target_buf->offset + r->delta; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1361 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1362 | if (bo->virtual == NULL) |
| 1363 | drm_intel_fake_bo_map_locked(bo, 1); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1364 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1365 | *(uint32_t *) ((uint8_t *) bo->virtual + r->offset) = |
| 1366 | reloc_data; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1367 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1368 | r->last_target_offset = r->target_buf->offset; |
| 1369 | } |
| 1370 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1371 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1372 | if (bo->virtual != NULL) |
| 1373 | drm_intel_fake_bo_unmap_locked(bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1374 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1375 | if (bo_fake->write_domain != 0) { |
| 1376 | if (!(bo_fake->flags & (BM_NO_BACKING_STORE | BM_PINNED))) { |
| 1377 | if (bo_fake->backing_store == 0) |
| 1378 | alloc_backing_store(bo); |
| 1379 | } |
| 1380 | bo_fake->card_dirty = 1; |
| 1381 | bufmgr_fake->performed_rendering = 1; |
| 1382 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1383 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1384 | return drm_intel_fake_bo_validate(bo); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1387 | static void |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 1388 | drm_intel_bo_fake_post_submit(drm_intel_bo *bo) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1389 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1390 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1391 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 1392 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo; |
| 1393 | int i; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1394 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1395 | for (i = 0; i < bo_fake->nr_relocs; i++) { |
| 1396 | struct fake_buffer_reloc *r = &bo_fake->relocs[i]; |
| 1397 | drm_intel_bo_fake *target_fake = |
| 1398 | (drm_intel_bo_fake *) r->target_buf; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1399 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1400 | if (target_fake->validated) |
| 1401 | drm_intel_bo_fake_post_submit(r->target_buf); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1402 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1403 | DBG("%s@0x%08x + 0x%08x -> %s@0x%08x + 0x%08x\n", |
| 1404 | bo_fake->name, (uint32_t) bo->offset, r->offset, |
| 1405 | target_fake->name, (uint32_t) r->target_buf->offset, |
| 1406 | r->delta); |
| 1407 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1408 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1409 | assert(bo_fake->map_count == 0); |
| 1410 | bo_fake->validated = 0; |
| 1411 | bo_fake->read_domains = 0; |
| 1412 | bo_fake->write_domain = 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Emil Velikov | 0f8da82 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 1415 | void |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1416 | drm_intel_bufmgr_fake_set_exec_callback(drm_intel_bufmgr *bufmgr, |
| 1417 | int (*exec) (drm_intel_bo *bo, |
| 1418 | unsigned int used, |
| 1419 | void *priv), |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 1420 | void *priv) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1421 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1422 | drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1423 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1424 | bufmgr_fake->exec = exec; |
| 1425 | bufmgr_fake->exec_priv = priv; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | static int |
Eric Anholt | 4b98264 | 2008-10-30 09:33:07 -0700 | [diff] [blame] | 1429 | drm_intel_fake_bo_exec(drm_intel_bo *bo, int used, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1430 | drm_clip_rect_t * cliprects, int num_cliprects, int DR4) |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1431 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1432 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1433 | (drm_intel_bufmgr_fake *) bo->bufmgr; |
| 1434 | drm_intel_bo_fake *batch_fake = (drm_intel_bo_fake *) bo; |
| 1435 | struct drm_i915_batchbuffer batch; |
| 1436 | int ret; |
| 1437 | int retry_count = 0; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1438 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1439 | pthread_mutex_lock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1440 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1441 | bufmgr_fake->performed_rendering = 0; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1442 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1443 | drm_intel_fake_calculate_domains(bo); |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1444 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1445 | batch_fake->read_domains = I915_GEM_DOMAIN_COMMAND; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1446 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1447 | /* we've ran out of RAM so blow the whole lot away and retry */ |
| 1448 | restart: |
| 1449 | ret = drm_intel_fake_reloc_and_validate_buffer(bo); |
| 1450 | if (bufmgr_fake->fail == 1) { |
| 1451 | if (retry_count == 0) { |
| 1452 | retry_count++; |
| 1453 | drm_intel_fake_kick_all_locked(bufmgr_fake); |
| 1454 | bufmgr_fake->fail = 0; |
| 1455 | goto restart; |
| 1456 | } else /* dump out the memory here */ |
| 1457 | mmDumpMemInfo(bufmgr_fake->heap); |
| 1458 | } |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1459 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1460 | assert(ret == 0); |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1461 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1462 | if (bufmgr_fake->exec != NULL) { |
| 1463 | int ret = bufmgr_fake->exec(bo, used, bufmgr_fake->exec_priv); |
| 1464 | if (ret != 0) { |
| 1465 | pthread_mutex_unlock(&bufmgr_fake->lock); |
| 1466 | return ret; |
| 1467 | } |
| 1468 | } else { |
| 1469 | batch.start = bo->offset; |
| 1470 | batch.used = used; |
| 1471 | batch.cliprects = cliprects; |
| 1472 | batch.num_cliprects = num_cliprects; |
| 1473 | batch.DR1 = 0; |
| 1474 | batch.DR4 = DR4; |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1475 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1476 | if (drmCommandWrite |
| 1477 | (bufmgr_fake->fd, DRM_I915_BATCHBUFFER, &batch, |
| 1478 | sizeof(batch))) { |
| 1479 | drmMsg("DRM_I915_BATCHBUFFER: %d\n", -errno); |
| 1480 | pthread_mutex_unlock(&bufmgr_fake->lock); |
| 1481 | return -errno; |
| 1482 | } |
| 1483 | } |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1484 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1485 | drm_intel_fake_fence_validated(bo->bufmgr); |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1486 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1487 | drm_intel_bo_fake_post_submit(bo); |
Eric Anholt | f9d98be | 2008-09-08 08:51:40 -0700 | [diff] [blame] | 1488 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1489 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1490 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1491 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Eric Anholt | 46e9274 | 2008-08-08 13:13:46 -0700 | [diff] [blame] | 1494 | /** |
| 1495 | * Return an error if the list of BOs will exceed the aperture size. |
| 1496 | * |
| 1497 | * This is a rough guess and likely to fail, as during the validate sequence we |
| 1498 | * may place a buffer in an inopportune spot early on and then fail to fit |
| 1499 | * a set smaller than the aperture. |
| 1500 | */ |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1501 | static int |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1502 | drm_intel_fake_check_aperture_space(drm_intel_bo ** bo_array, int count) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1503 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1504 | drm_intel_bufmgr_fake *bufmgr_fake = |
| 1505 | (drm_intel_bufmgr_fake *) bo_array[0]->bufmgr; |
| 1506 | unsigned int sz = 0; |
| 1507 | int i; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1508 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1509 | for (i = 0; i < count; i++) { |
| 1510 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) bo_array[i]; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1511 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1512 | if (bo_fake == NULL) |
| 1513 | continue; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1514 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1515 | if (!bo_fake->is_static) |
| 1516 | sz += ALIGN(bo_array[i]->size, bo_fake->alignment); |
| 1517 | sz += bo_fake->child_size; |
| 1518 | } |
Eric Anholt | 46e9274 | 2008-08-08 13:13:46 -0700 | [diff] [blame] | 1519 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1520 | if (sz > bufmgr_fake->size) { |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 1521 | DBG("check_space: overflowed bufmgr size, %ukb vs %lukb\n", |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1522 | sz / 1024, bufmgr_fake->size / 1024); |
| 1523 | return -1; |
| 1524 | } |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1525 | |
Thierry Reding | 3d7a51e | 2014-04-08 22:18:18 +0200 | [diff] [blame] | 1526 | DBG("drm_check_space: sz %ukb vs bufgr %lukb\n", sz / 1024, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1527 | bufmgr_fake->size / 1024); |
| 1528 | return 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Eric Anholt | d198e9b | 2008-06-05 08:44:46 -0700 | [diff] [blame] | 1531 | /** |
| 1532 | * Evicts all buffers, waiting for fences to pass and copying contents out |
| 1533 | * as necessary. |
| 1534 | * |
| 1535 | * Used by the X Server on LeaveVT, when the card memory is no longer our |
| 1536 | * own. |
| 1537 | */ |
Emil Velikov | 0f8da82 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 1538 | void |
Maarten Lankhorst | 07fead4 | 2014-07-31 15:07:27 +0200 | [diff] [blame] | 1539 | drm_intel_bufmgr_fake_evict_all(drm_intel_bufmgr *bufmgr) |
Eric Anholt | d198e9b | 2008-06-05 08:44:46 -0700 | [diff] [blame] | 1540 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1541 | drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
| 1542 | struct block *block, *tmp; |
Eric Anholt | d198e9b | 2008-06-05 08:44:46 -0700 | [diff] [blame] | 1543 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1544 | pthread_mutex_lock(&bufmgr_fake->lock); |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1545 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1546 | bufmgr_fake->need_fence = 1; |
| 1547 | bufmgr_fake->fail = 0; |
Eric Anholt | d198e9b | 2008-06-05 08:44:46 -0700 | [diff] [blame] | 1548 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1549 | /* Wait for hardware idle. We don't know where acceleration has been |
| 1550 | * happening, so we'll need to wait anyway before letting anything get |
| 1551 | * put on the card again. |
| 1552 | */ |
| 1553 | drm_intel_bufmgr_fake_wait_idle(bufmgr_fake); |
Eric Anholt | d198e9b | 2008-06-05 08:44:46 -0700 | [diff] [blame] | 1554 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1555 | /* Check that we hadn't released the lock without having fenced the last |
| 1556 | * set of buffers. |
| 1557 | */ |
| 1558 | assert(DRMLISTEMPTY(&bufmgr_fake->fenced)); |
| 1559 | assert(DRMLISTEMPTY(&bufmgr_fake->on_hardware)); |
Eric Anholt | d198e9b | 2008-06-05 08:44:46 -0700 | [diff] [blame] | 1560 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1561 | DRMLISTFOREACHSAFE(block, tmp, &bufmgr_fake->lru) { |
| 1562 | drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) block->bo; |
| 1563 | /* Releases the memory, and memcpys dirty contents out if |
| 1564 | * necessary. |
| 1565 | */ |
| 1566 | free_block(bufmgr_fake, block, 0); |
| 1567 | bo_fake->block = NULL; |
| 1568 | } |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1569 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1570 | pthread_mutex_unlock(&bufmgr_fake->lock); |
Eric Anholt | d198e9b | 2008-06-05 08:44:46 -0700 | [diff] [blame] | 1571 | } |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1572 | |
Emil Velikov | 0f8da82 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 1573 | void |
Maarten Lankhorst | 07fead4 | 2014-07-31 15:07:27 +0200 | [diff] [blame] | 1574 | drm_intel_bufmgr_fake_set_last_dispatch(drm_intel_bufmgr *bufmgr, |
| 1575 | volatile unsigned int |
| 1576 | *last_dispatch) |
Eric Anholt | 869d8be | 2008-09-06 03:07:41 +0100 | [diff] [blame] | 1577 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1578 | drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; |
Eric Anholt | 869d8be | 2008-09-06 03:07:41 +0100 | [diff] [blame] | 1579 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1580 | bufmgr_fake->last_dispatch = (volatile int *)last_dispatch; |
Eric Anholt | 869d8be | 2008-09-06 03:07:41 +0100 | [diff] [blame] | 1581 | } |
Eric Anholt | d198e9b | 2008-06-05 08:44:46 -0700 | [diff] [blame] | 1582 | |
Emil Velikov | 0f8da82 | 2015-03-31 22:32:11 +0100 | [diff] [blame] | 1583 | drm_intel_bufmgr * |
Maarten Lankhorst | 07fead4 | 2014-07-31 15:07:27 +0200 | [diff] [blame] | 1584 | drm_intel_bufmgr_fake_init(int fd, unsigned long low_offset, |
| 1585 | void *low_virtual, unsigned long size, |
| 1586 | volatile unsigned int *last_dispatch) |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1587 | { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1588 | drm_intel_bufmgr_fake *bufmgr_fake; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1589 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1590 | bufmgr_fake = calloc(1, sizeof(*bufmgr_fake)); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1591 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1592 | if (pthread_mutex_init(&bufmgr_fake->lock, NULL) != 0) { |
| 1593 | free(bufmgr_fake); |
| 1594 | return NULL; |
| 1595 | } |
Eric Anholt | 6df7b07 | 2008-06-12 23:22:26 -0700 | [diff] [blame] | 1596 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1597 | /* Initialize allocator */ |
| 1598 | DRMINITLISTHEAD(&bufmgr_fake->fenced); |
| 1599 | DRMINITLISTHEAD(&bufmgr_fake->on_hardware); |
| 1600 | DRMINITLISTHEAD(&bufmgr_fake->lru); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1601 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1602 | bufmgr_fake->low_offset = low_offset; |
| 1603 | bufmgr_fake->virtual = low_virtual; |
| 1604 | bufmgr_fake->size = size; |
| 1605 | bufmgr_fake->heap = mmInit(low_offset, size); |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1606 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1607 | /* Hook in methods */ |
| 1608 | bufmgr_fake->bufmgr.bo_alloc = drm_intel_fake_bo_alloc; |
| 1609 | bufmgr_fake->bufmgr.bo_alloc_for_render = drm_intel_fake_bo_alloc; |
Jesse Barnes | 3a7dfcd | 2009-10-06 14:34:06 -0700 | [diff] [blame] | 1610 | bufmgr_fake->bufmgr.bo_alloc_tiled = drm_intel_fake_bo_alloc_tiled; |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1611 | bufmgr_fake->bufmgr.bo_reference = drm_intel_fake_bo_reference; |
| 1612 | bufmgr_fake->bufmgr.bo_unreference = drm_intel_fake_bo_unreference; |
| 1613 | bufmgr_fake->bufmgr.bo_map = drm_intel_fake_bo_map; |
| 1614 | bufmgr_fake->bufmgr.bo_unmap = drm_intel_fake_bo_unmap; |
Eric Anholt | f45305c | 2010-11-01 06:54:58 -0700 | [diff] [blame] | 1615 | bufmgr_fake->bufmgr.bo_subdata = drm_intel_fake_bo_subdata; |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1616 | bufmgr_fake->bufmgr.bo_wait_rendering = |
| 1617 | drm_intel_fake_bo_wait_rendering; |
| 1618 | bufmgr_fake->bufmgr.bo_emit_reloc = drm_intel_fake_emit_reloc; |
| 1619 | bufmgr_fake->bufmgr.destroy = drm_intel_fake_destroy; |
| 1620 | bufmgr_fake->bufmgr.bo_exec = drm_intel_fake_bo_exec; |
| 1621 | bufmgr_fake->bufmgr.check_aperture_space = |
| 1622 | drm_intel_fake_check_aperture_space; |
| 1623 | bufmgr_fake->bufmgr.debug = 0; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1624 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1625 | bufmgr_fake->fd = fd; |
| 1626 | bufmgr_fake->last_dispatch = (volatile int *)last_dispatch; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1627 | |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 1628 | return &bufmgr_fake->bufmgr; |
Eric Anholt | 6a9eb08 | 2008-06-03 09:27:37 -0700 | [diff] [blame] | 1629 | } |