| 1 |
/* |
| 2 |
* Copyright © 2007 Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice (including the next |
| 12 |
* paragraph) shall be included in all copies or substantial portions of the |
| 13 |
* Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 |
* IN THE SOFTWARE. |
| 22 |
* |
| 23 |
* Authors: |
| 24 |
* Eric Anholt <[email protected]> |
| 25 |
* |
| 26 |
*/ |
| 27 |
|
| 28 |
#ifdef HAVE_CONFIG_H |
| 29 |
#include "config.h" |
| 30 |
#endif |
| 31 |
|
| 32 |
#include <string.h> |
| 33 |
#include <stdlib.h> |
| 34 |
#include <stdint.h> |
| 35 |
#include <assert.h> |
| 36 |
#include <errno.h> |
| 37 |
#include "drm.h" |
| 38 |
#include "i915_drm.h" |
| 39 |
#include "libdrm_macros.h" |
| 40 |
#include "mos_bufmgr.h" |
| 41 |
#include "mos_bufmgr_priv.h" |
| 42 |
#include "xf86drm.h" |
| 43 |
|
| 44 |
/** @file mos_bufmgr_api_mock.c |
| 45 |
* |
| 46 |
* Convenience functions for buffer management methods. |
| 47 |
*/ |
| 48 |
|
| 49 |
struct mos_linux_bo * |
| 50 |
mos_bo_alloc(struct mos_bufmgr *bufmgr, |
| 51 |
struct mos_drm_bo_alloc *alloc) |
| 52 |
{ |
| 53 |
if (bufmgr && alloc && bufmgr->bo_alloc) |
| 54 |
{ |
| 55 |
return bufmgr->bo_alloc(bufmgr, alloc); |
| 56 |
} |
| 57 |
return nullptr; |
| 58 |
} |
| 59 |
|
| 60 |
struct mos_linux_bo * |
| 61 |
mos_bo_alloc_userptr(struct mos_bufmgr *bufmgr, |
| 62 |
struct mos_drm_bo_alloc_userptr *alloc_uptr) |
| 63 |
{ |
| 64 |
if (bufmgr && alloc_uptr && bufmgr->bo_alloc_userptr) |
| 65 |
{ |
| 66 |
return bufmgr->bo_alloc_userptr(bufmgr, alloc_uptr); |
| 67 |
} |
| 68 |
return nullptr; |
| 69 |
} |
| 70 |
|
| 71 |
struct mos_linux_bo * |
| 72 |
mos_bo_alloc_tiled(struct mos_bufmgr *bufmgr, |
| 73 |
struct mos_drm_bo_alloc_tiled *alloc_tiled) |
| 74 |
{ |
| 75 |
if (bufmgr && alloc_tiled && bufmgr->bo_alloc_tiled) |
| 76 |
{ |
| 77 |
return bufmgr->bo_alloc_tiled(bufmgr, alloc_tiled); |
| 78 |
} |
| 79 |
return nullptr; |
| 80 |
} |
| 81 |
|
| 82 |
void |
| 83 |
mos_bo_reference(struct mos_linux_bo *bo) |
| 84 |
{ |
| 85 |
bo->bufmgr->bo_reference(bo); |
| 86 |
} |
| 87 |
|
| 88 |
void |
| 89 |
mos_bo_unreference(struct mos_linux_bo *bo) |
| 90 |
{ |
| 91 |
if (bo == nullptr) |
| 92 |
return; |
| 93 |
|
| 94 |
bo->bufmgr->bo_unreference(bo); |
| 95 |
} |
| 96 |
|
| 97 |
int |
| 98 |
mos_bo_map(struct mos_linux_bo *buf, int write_enable) |
| 99 |
{ |
| 100 |
return buf->bufmgr->bo_map(buf, write_enable); |
| 101 |
} |
| 102 |
|
| 103 |
int |
| 104 |
mos_bo_unmap(struct mos_linux_bo *buf) |
| 105 |
{ |
| 106 |
return buf->bufmgr->bo_unmap(buf); |
| 107 |
} |
| 108 |
|
| 109 |
void |
| 110 |
mos_bo_wait_rendering(struct mos_linux_bo *bo) |
| 111 |
{ |
| 112 |
bo->bufmgr->bo_wait_rendering(bo); |
| 113 |
} |
| 114 |
|
| 115 |
void |
| 116 |
mos_bufmgr_destroy(struct mos_bufmgr *bufmgr) |
| 117 |
{ |
| 118 |
bufmgr->destroy(bufmgr); |
| 119 |
} |
| 120 |
|
| 121 |
int |
| 122 |
mos_bo_exec(struct mos_linux_bo *bo, int used, |
| 123 |
drm_clip_rect_t * cliprects, int num_cliprects, int DR4) |
| 124 |
{ |
| 125 |
return bo->bufmgr->bo_exec(bo, used, cliprects, num_cliprects, DR4); |
| 126 |
} |
| 127 |
|
| 128 |
int |
| 129 |
mos_bo_mrb_exec(struct mos_linux_bo *bo, int used, |
| 130 |
drm_clip_rect_t *cliprects, int num_cliprects, int DR4, |
| 131 |
unsigned int rings) |
| 132 |
{ |
| 133 |
if (bo->bufmgr->bo_mrb_exec) |
| 134 |
return bo->bufmgr->bo_mrb_exec(bo, used, |
| 135 |
cliprects, num_cliprects, DR4, |
| 136 |
rings); |
| 137 |
|
| 138 |
switch (rings) { |
| 139 |
case I915_EXEC_DEFAULT: |
| 140 |
case I915_EXEC_RENDER: |
| 141 |
return bo->bufmgr->bo_exec(bo, used, |
| 142 |
cliprects, num_cliprects, DR4); |
| 143 |
default: |
| 144 |
return -ENODEV; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
void |
| 149 |
mos_bufmgr_set_debug(struct mos_bufmgr *bufmgr, int enable_debug) |
| 150 |
{ |
| 151 |
bufmgr->debug = enable_debug; |
| 152 |
} |
| 153 |
|
| 154 |
int |
| 155 |
mos_bufmgr_check_aperture_space(struct mos_linux_bo ** bo_array, int count) |
| 156 |
{ |
| 157 |
return bo_array[0]->bufmgr->check_aperture_space(bo_array, count); |
| 158 |
} |
| 159 |
|
| 160 |
int |
| 161 |
mos_bo_flink(struct mos_linux_bo *bo, uint32_t * name) |
| 162 |
{ |
| 163 |
if (bo->bufmgr->bo_flink) |
| 164 |
return bo->bufmgr->bo_flink(bo, name); |
| 165 |
|
| 166 |
return -ENODEV; |
| 167 |
} |
| 168 |
|
| 169 |
int |
| 170 |
mos_bo_emit_reloc(struct mos_linux_bo *bo, uint32_t offset, |
| 171 |
struct mos_linux_bo *target_bo, uint32_t target_offset, |
| 172 |
uint32_t read_domains, uint32_t write_domain, |
| 173 |
uint64_t presumed_offset) |
| 174 |
{ |
| 175 |
return bo->bufmgr->bo_emit_reloc(bo, offset, |
| 176 |
target_bo, target_offset, |
| 177 |
read_domains, write_domain, |
| 178 |
presumed_offset); |
| 179 |
} |
| 180 |
|
| 181 |
int |
| 182 |
mos_bo_set_tiling(struct mos_linux_bo *bo, uint32_t * tiling_mode, |
| 183 |
uint32_t stride) |
| 184 |
{ |
| 185 |
if (bo->bufmgr->bo_set_tiling) |
| 186 |
return bo->bufmgr->bo_set_tiling(bo, tiling_mode, stride); |
| 187 |
|
| 188 |
*tiling_mode = I915_TILING_NONE; |
| 189 |
return 0; |
| 190 |
} |
| 191 |
|
| 192 |
int |
| 193 |
mos_bo_get_tiling(struct mos_linux_bo *bo, uint32_t * tiling_mode, |
| 194 |
uint32_t * swizzle_mode) |
| 195 |
{ |
| 196 |
if (bo->bufmgr->bo_get_tiling) |
| 197 |
return bo->bufmgr->bo_get_tiling(bo, tiling_mode, swizzle_mode); |
| 198 |
|
| 199 |
*tiling_mode = I915_TILING_NONE; |
| 200 |
*swizzle_mode = I915_BIT_6_SWIZZLE_NONE; |
| 201 |
return 0; |
| 202 |
} |
| 203 |
|
| 204 |
int |
| 205 |
mos_bo_set_softpin(struct mos_linux_bo *bo) |
| 206 |
{ |
| 207 |
if (bo->bufmgr->bo_set_softpin) |
| 208 |
return bo->bufmgr->bo_set_softpin(bo); |
| 209 |
|
| 210 |
return -ENODEV; |
| 211 |
} |
| 212 |
|
| 213 |
int |
| 214 |
mos_bo_add_softpin_target(struct mos_linux_bo *bo, struct mos_linux_bo *target_bo, bool write_flag) |
| 215 |
{ |
| 216 |
if (bo->bufmgr->bo_add_softpin_target) |
| 217 |
return bo->bufmgr->bo_add_softpin_target(bo, target_bo, write_flag); |
| 218 |
|
| 219 |
return -ENODEV; |
| 220 |
} |
| 221 |
|
| 222 |
int |
| 223 |
mos_bo_disable_reuse(struct mos_linux_bo *bo) |
| 224 |
{ |
| 225 |
if (bo->bufmgr->bo_disable_reuse) |
| 226 |
return bo->bufmgr->bo_disable_reuse(bo); |
| 227 |
return 0; |
| 228 |
} |
| 229 |
|
| 230 |
int |
| 231 |
mos_bo_is_reusable(struct mos_linux_bo *bo) |
| 232 |
{ |
| 233 |
if (bo->bufmgr->bo_is_reusable) |
| 234 |
return bo->bufmgr->bo_is_reusable(bo); |
| 235 |
return 0; |
| 236 |
} |
| 237 |
|
| 238 |
int |
| 239 |
mos_bo_busy(struct mos_linux_bo *bo) |
| 240 |
{ |
| 241 |
if (bo->bufmgr->bo_busy) |
| 242 |
return bo->bufmgr->bo_busy(bo); |
| 243 |
return 0; |
| 244 |
} |
| 245 |
|
| 246 |
int |
| 247 |
mos_bo_madvise(struct mos_linux_bo *bo, int madv) |
| 248 |
{ |
| 249 |
if (bo->bufmgr->bo_madvise) |
| 250 |
return bo->bufmgr->bo_madvise(bo, madv); |
| 251 |
return -1; |
| 252 |
} |
| 253 |
|
| 254 |
int |
| 255 |
mos_bo_use_48b_address_range(struct mos_linux_bo *bo, uint32_t enable) |
| 256 |
{ |
| 257 |
if (bo->bufmgr->bo_use_48b_address_range) { |
| 258 |
bo->bufmgr->bo_use_48b_address_range(bo, enable); |
| 259 |
return 0; |
| 260 |
} |
| 261 |
|
| 262 |
return -ENODEV; |
| 263 |
} |
| 264 |
|
| 265 |
void |
| 266 |
mos_bo_set_object_async(struct mos_linux_bo *bo) |
| 267 |
{ |
| 268 |
if( bo->bufmgr->set_object_async) |
| 269 |
bo->bufmgr->set_object_async(bo); |
| 270 |
} |
| 271 |
|
| 272 |
void |
| 273 |
mos_bo_set_exec_object_async(struct mos_linux_bo *bo, struct mos_linux_bo *target_bo) |
| 274 |
{ |
| 275 |
if( bo->bufmgr->set_exec_object_async) |
| 276 |
bo->bufmgr->set_exec_object_async(bo, target_bo); |
| 277 |
} |
| 278 |
|
| 279 |
int |
| 280 |
mos_bo_pad_to_size(struct mos_linux_bo *bo, uint64_t pad_to_size) |
| 281 |
{ |
| 282 |
return bo->bufmgr->bo_pad_to_size(bo, pad_to_size); |
| 283 |
} |
| 284 |
|
| 285 |
int |
| 286 |
mos_bo_references(struct mos_linux_bo *bo, struct mos_linux_bo *target_bo) |
| 287 |
{ |
| 288 |
return bo->bufmgr->bo_references(bo, target_bo); |
| 289 |
} |
| 290 |
|
| 291 |
drm_export int |
| 292 |
mos_bo_wait(struct mos_linux_bo *bo, int64_t timeout_ns) |
| 293 |
{ |
| 294 |
return bo->bufmgr->bo_wait(bo, timeout_ns); |
| 295 |
} |
| 296 |
|
| 297 |
drm_export void |
| 298 |
mos_bo_clear_relocs(struct mos_linux_bo *bo, int start) |
| 299 |
{ |
| 300 |
bo->bufmgr->bo_clear_relocs(bo, start); |
| 301 |
} |
| 302 |
|
| 303 |
struct mos_linux_context * |
| 304 |
mos_context_create(struct mos_bufmgr *bufmgr) |
| 305 |
{ |
| 306 |
return bufmgr->context_create(bufmgr); |
| 307 |
} |
| 308 |
|
| 309 |
struct mos_linux_context * |
| 310 |
mos_context_create_ext( |
| 311 |
struct mos_bufmgr *bufmgr, |
| 312 |
__u32 flags, |
| 313 |
bool bContextProtected) |
| 314 |
{ |
| 315 |
return bufmgr->context_create_ext(bufmgr, flags, bContextProtected); |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
struct mos_linux_context * |
| 320 |
mos_context_create_shared( |
| 321 |
struct mos_bufmgr *bufmgr, |
| 322 |
mos_linux_context* ctx, |
| 323 |
__u32 flags, |
| 324 |
bool bContextProtected, |
| 325 |
void *engine_map, |
| 326 |
uint8_t ctx_width, |
| 327 |
uint8_t num_placements, |
| 328 |
uint32_t ctx_type) |
| 329 |
{ |
| 330 |
return bufmgr->context_create_shared(bufmgr, ctx, flags, bContextProtected, |
| 331 |
engine_map, ctx_width, num_placements, ctx_type); |
| 332 |
} |
| 333 |
|
| 334 |
void |
| 335 |
mos_context_destroy(struct mos_linux_context *ctx) |
| 336 |
{ |
| 337 |
return ctx->bufmgr->context_destroy(ctx); |
| 338 |
} |
| 339 |
|
| 340 |
__u32 |
| 341 |
mos_vm_create(struct mos_bufmgr *bufmgr) |
| 342 |
{ |
| 343 |
return bufmgr->vm_create(bufmgr); |
| 344 |
} |
| 345 |
|
| 346 |
void |
| 347 |
mos_vm_destroy(struct mos_bufmgr *bufmgr, __u32 vm_id) |
| 348 |
{ |
| 349 |
return bufmgr->vm_destroy(bufmgr, vm_id); |
| 350 |
} |
| 351 |
|
| 352 |
int |
| 353 |
mos_bo_context_exec2(struct mos_linux_bo *bo, int used, struct mos_linux_context *ctx, |
| 354 |
struct drm_clip_rect *cliprects, int num_cliprects, int DR4, |
| 355 |
unsigned int flags, int *fence) |
| 356 |
|
| 357 |
{ |
| 358 |
return bo->bufmgr->bo_context_exec2(bo, used, ctx, cliprects, num_cliprects, DR4, flags, fence); |
| 359 |
} |
| 360 |
|
| 361 |
int |
| 362 |
mos_bo_context_exec3(struct mos_linux_bo **bo, int num_bo, struct mos_linux_context *ctx, |
| 363 |
struct drm_clip_rect *cliprects, int num_cliprects, int DR4, |
| 364 |
unsigned int flags, int *fence) |
| 365 |
{ |
| 366 |
return (*bo)->bufmgr->bo_context_exec3(bo, num_bo, ctx, cliprects, num_cliprects, DR4, flags, fence); |
| 367 |
} |
| 368 |
|
| 369 |
drm_export bool |
| 370 |
mos_bo_is_softpin(struct mos_linux_bo *bo) |
| 371 |
{ |
| 372 |
return bo->bufmgr->bo_is_softpin(bo); |
| 373 |
} |
| 374 |
|
| 375 |
int |
| 376 |
mos_bo_map_gtt(struct mos_linux_bo *bo) |
| 377 |
{ |
| 378 |
return bo->bufmgr->bo_map_gtt(bo); |
| 379 |
} |
| 380 |
int |
| 381 |
mos_bo_unmap_gtt(struct mos_linux_bo *bo) |
| 382 |
{ |
| 383 |
return bo->bufmgr->bo_unmap_gtt(bo); |
| 384 |
} |
| 385 |
|
| 386 |
drm_export int |
| 387 |
mos_bo_map_wc(struct mos_linux_bo *bo) |
| 388 |
{ |
| 389 |
return bo->bufmgr->bo_map_wc(bo); |
| 390 |
} |
| 391 |
|
| 392 |
int |
| 393 |
mos_bo_unmap_wc(struct mos_linux_bo *bo) |
| 394 |
{ |
| 395 |
return bo->bufmgr->bo_unmap_wc(bo); |
| 396 |
} |
| 397 |
|
| 398 |
int |
| 399 |
mos_bo_map_unsynchronized(struct mos_linux_bo *bo) |
| 400 |
{ |
| 401 |
return bo->bufmgr->bo_map_unsynchronized(bo); |
| 402 |
} |
| 403 |
|
| 404 |
void |
| 405 |
mos_bo_start_gtt_access(struct mos_linux_bo *bo, int write_enable) |
| 406 |
{ |
| 407 |
return bo->bufmgr->bo_start_gtt_access(bo, write_enable); |
| 408 |
} |
| 409 |
|
| 410 |
int |
| 411 |
mos_set_context_param(struct mos_linux_context *ctx, |
| 412 |
uint32_t size, |
| 413 |
uint64_t param, |
| 414 |
uint64_t value) |
| 415 |
{ |
| 416 |
return ctx->bufmgr->set_context_param(ctx, size, param, value); |
| 417 |
} |
| 418 |
|
| 419 |
int |
| 420 |
mos_set_context_param_load_balance(struct mos_linux_context *ctx, |
| 421 |
struct i915_engine_class_instance *ci, |
| 422 |
unsigned int count) |
| 423 |
{ |
| 424 |
return ctx->bufmgr->set_context_param_load_balance(ctx, ci, count); |
| 425 |
} |
| 426 |
|
| 427 |
int |
| 428 |
mos_get_context_param(struct mos_linux_context *ctx, |
| 429 |
uint32_t size, |
| 430 |
uint64_t param, |
| 431 |
uint64_t *value) |
| 432 |
{ |
| 433 |
return ctx->bufmgr->get_context_param(ctx, size, param, value); |
| 434 |
} |
| 435 |
|
| 436 |
struct mos_linux_bo * |
| 437 |
mos_bo_create_from_prime(struct mos_bufmgr *bufmgr, |
| 438 |
struct mos_drm_bo_alloc_prime *alloc_prime) |
| 439 |
{ |
| 440 |
return bufmgr->bo_create_from_prime(bufmgr, alloc_prime); |
| 441 |
} |
| 442 |
|
| 443 |
int |
| 444 |
mos_bo_export_to_prime(struct mos_linux_bo *bo, int *prime_fd) |
| 445 |
{ |
| 446 |
return bo->bufmgr->bo_export_to_prime(bo, prime_fd); |
| 447 |
} |
| 448 |
|
| 449 |
int |
| 450 |
mos_reg_read(struct mos_bufmgr *bufmgr, |
| 451 |
uint32_t offset, |
| 452 |
uint64_t *result) |
| 453 |
{ |
| 454 |
return bufmgr->reg_read(bufmgr, offset, result); |
| 455 |
} |
| 456 |
|
| 457 |
int |
| 458 |
mos_get_reset_stats(struct mos_linux_context *ctx, |
| 459 |
uint32_t *reset_count, |
| 460 |
uint32_t *active, |
| 461 |
uint32_t *pending) |
| 462 |
{ |
| 463 |
return ctx->bufmgr->get_reset_stats(ctx, reset_count, active, pending); |
| 464 |
} |
| 465 |
|
| 466 |
int |
| 467 |
mos_get_context_param_sseu(struct mos_linux_context *ctx, |
| 468 |
struct drm_i915_gem_context_param_sseu *sseu) |
| 469 |
{ |
| 470 |
return ctx->bufmgr->get_context_param_sseu(ctx, sseu); |
| 471 |
} |
| 472 |
|
| 473 |
int |
| 474 |
mos_set_context_param_sseu(struct mos_linux_context *ctx, |
| 475 |
struct drm_i915_gem_context_param_sseu sseu) |
| 476 |
{ |
| 477 |
return ctx->bufmgr->set_context_param_sseu(ctx, sseu); |
| 478 |
} |
| 479 |
|
| 480 |
uint64_t |
| 481 |
mos_get_platform_information(struct mos_bufmgr *bufmgr) |
| 482 |
{ |
| 483 |
return bufmgr->get_platform_information(bufmgr); |
| 484 |
} |
| 485 |
|
| 486 |
void |
| 487 |
mos_set_platform_information(struct mos_bufmgr *bufmgr, uint64_t p) |
| 488 |
{ |
| 489 |
return bufmgr->set_platform_information(bufmgr, p); |
| 490 |
} |
| 491 |
|
| 492 |
uint8_t |
| 493 |
mos_switch_off_n_bits(struct mos_linux_context *ctx, uint8_t in_mask, int n) |
| 494 |
{ |
| 495 |
return ctx->bufmgr->switch_off_n_bits(ctx, in_mask, n); |
| 496 |
} |
| 497 |
|
| 498 |
unsigned int |
| 499 |
mos_hweight8(struct mos_linux_context *ctx, uint8_t w) |
| 500 |
{ |
| 501 |
return ctx->bufmgr->hweight8(ctx, w); |
| 502 |
} |
| 503 |
|