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 #include "mos_util_debug.h"
44
45 /** @file mos_bufmgr_api.c
46 *
47 * Convenience functions for buffer management methods.
48 */
49
50 struct mos_linux_bo *
mos_bo_alloc(struct mos_bufmgr * bufmgr,struct mos_drm_bo_alloc * alloc)51 mos_bo_alloc(struct mos_bufmgr *bufmgr,
52 struct mos_drm_bo_alloc *alloc)
53 {
54 if(!bufmgr || !alloc)
55 {
56 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
57 return nullptr;
58 }
59
60 if (bufmgr->bo_alloc)
61 {
62 return bufmgr->bo_alloc(bufmgr, alloc);
63 }
64 else
65 {
66 MOS_OS_CRITICALMESSAGE("Unsupported\n");
67 return nullptr;
68 }
69 }
70
71 struct mos_linux_bo *
mos_bo_alloc_userptr(struct mos_bufmgr * bufmgr,struct mos_drm_bo_alloc_userptr * alloc_uptr)72 mos_bo_alloc_userptr(struct mos_bufmgr *bufmgr,
73 struct mos_drm_bo_alloc_userptr *alloc_uptr)
74 {
75 if(!bufmgr || !alloc_uptr)
76 {
77 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
78 return nullptr;
79 }
80
81 if (bufmgr->bo_alloc_userptr)
82 {
83 return bufmgr->bo_alloc_userptr(bufmgr, alloc_uptr);
84 }
85 else
86 {
87 MOS_OS_CRITICALMESSAGE("Unsupported\n");
88 return nullptr;
89 }
90 }
91
92 struct mos_linux_bo *
mos_bo_alloc_tiled(struct mos_bufmgr * bufmgr,struct mos_drm_bo_alloc_tiled * alloc_tiled)93 mos_bo_alloc_tiled(struct mos_bufmgr *bufmgr,
94 struct mos_drm_bo_alloc_tiled *alloc_tiled)
95 {
96 if(!bufmgr || !alloc_tiled)
97 {
98 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
99 return nullptr;
100 }
101
102 if (bufmgr->bo_alloc_tiled)
103 {
104 return bufmgr->bo_alloc_tiled(bufmgr, alloc_tiled);
105 }
106 else
107 {
108 MOS_OS_CRITICALMESSAGE("Unsupported\n");
109 return nullptr;
110 }
111 }
112
113 void
mos_bo_reference(struct mos_linux_bo * bo)114 mos_bo_reference(struct mos_linux_bo *bo)
115 {
116 if(!bo)
117 {
118 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
119 return;
120 }
121
122 if (bo->bufmgr && bo->bufmgr->bo_reference)
123 {
124 bo->bufmgr->bo_reference(bo);
125 }
126 else
127 {
128 MOS_OS_CRITICALMESSAGE("Unsupported\n");
129 }
130 }
131
132 void
mos_bo_unreference(struct mos_linux_bo * bo)133 mos_bo_unreference(struct mos_linux_bo *bo)
134 {
135 if(!bo)
136 {
137 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
138 return;
139 }
140
141 if (bo->bufmgr && bo->bufmgr->bo_unreference)
142 {
143 bo->bufmgr->bo_unreference(bo);
144 }
145 else
146 {
147 MOS_OS_CRITICALMESSAGE("Unsupported\n");
148 }
149 }
150
151 int
mos_bo_map(struct mos_linux_bo * bo,int write_enable)152 mos_bo_map(struct mos_linux_bo *bo, int write_enable)
153
154 {
155 if(!bo)
156 {
157 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
158 return -EINVAL;
159 }
160
161 if (bo->bufmgr && bo->bufmgr->bo_map)
162 {
163 return bo->bufmgr->bo_map(bo, write_enable);
164 }
165 else
166 {
167 MOS_OS_CRITICALMESSAGE("Unsupported\n");
168 return -EPERM;
169 }
170 }
171
172 int
mos_bo_unmap(struct mos_linux_bo * bo)173 mos_bo_unmap(struct mos_linux_bo *bo)
174 {
175 if(!bo)
176 {
177 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
178 return -EINVAL;
179 }
180
181 if (bo->bufmgr && bo->bufmgr->bo_unmap)
182 {
183 return bo->bufmgr->bo_unmap(bo);
184 }
185 else
186 {
187 MOS_OS_CRITICALMESSAGE("Unsupported\n");
188 return -EPERM;
189 }
190 }
191
192 void
mos_bo_wait_rendering(struct mos_linux_bo * bo)193 mos_bo_wait_rendering(struct mos_linux_bo *bo)
194 {
195 if(!bo)
196 {
197 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
198 return;
199 }
200
201 if (bo->bufmgr && bo->bufmgr->bo_wait_rendering)
202 {
203 bo->bufmgr->bo_wait_rendering(bo);
204 }
205 else
206 {
207 MOS_OS_CRITICALMESSAGE("Unsupported\n");
208 }
209 }
210
211 int
mos_bo_exec(struct mos_linux_bo * bo,int used,drm_clip_rect_t * cliprects,int num_cliprects,int DR4)212 mos_bo_exec(struct mos_linux_bo *bo, int used,
213 drm_clip_rect_t * cliprects, int num_cliprects, int DR4)
214 {
215 if(!bo)
216 {
217 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
218 return -EINVAL;
219 }
220
221 if (bo->bufmgr && bo->bufmgr->bo_exec)
222 {
223 return bo->bufmgr->bo_exec(bo, used, cliprects, num_cliprects, DR4);
224 }
225 else
226 {
227 MOS_OS_CRITICALMESSAGE("Unsupported\n");
228 return -EPERM;
229 }
230 }
231
232 int
mos_bo_mrb_exec(struct mos_linux_bo * bo,int used,drm_clip_rect_t * cliprects,int num_cliprects,int DR4,unsigned int rings)233 mos_bo_mrb_exec(struct mos_linux_bo *bo, int used,
234 drm_clip_rect_t *cliprects, int num_cliprects, int DR4,
235 unsigned int rings)
236 {
237 if(!bo)
238 {
239 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
240 return -EINVAL;
241 }
242
243 if (bo->bufmgr && bo->bufmgr->bo_mrb_exec)
244 {
245 return bo->bufmgr->bo_mrb_exec(bo, used,
246 cliprects, num_cliprects, DR4,
247 rings);
248 }
249
250 switch (rings) {
251 case I915_EXEC_DEFAULT:
252 case I915_EXEC_RENDER:
253 if (bo->bufmgr && bo->bufmgr->bo_exec)
254 {
255 return bo->bufmgr->bo_exec(bo, used, cliprects, num_cliprects, DR4);
256 }
257 else
258 {
259 MOS_OS_CRITICALMESSAGE("Unsupported\n");
260 return -EPERM;
261 }
262 break;
263 default:
264 return -ENODEV;
265 }
266 }
267
268 int
mos_bo_emit_reloc(struct mos_linux_bo * bo,uint32_t offset,struct mos_linux_bo * target_bo,uint32_t target_offset,uint32_t read_domains,uint32_t write_domain,uint64_t presumed_offset)269 mos_bo_emit_reloc(struct mos_linux_bo *bo, uint32_t offset,
270 struct mos_linux_bo *target_bo, uint32_t target_offset,
271 uint32_t read_domains, uint32_t write_domain,
272 uint64_t presumed_offset)
273 {
274 if(!bo)
275 {
276 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
277 return -EINVAL;
278 }
279
280 if (bo->bufmgr && bo->bufmgr->bo_emit_reloc)
281 {
282 return bo->bufmgr->bo_emit_reloc(bo, offset,
283 target_bo, target_offset,
284 read_domains, write_domain,
285 presumed_offset);
286 }
287 else
288 {
289 MOS_OS_CRITICALMESSAGE("Unsupported\n");
290 return -EPERM;
291 }
292 }
293
294 int
mos_bo_set_tiling(struct mos_linux_bo * bo,uint32_t * tiling_mode,uint32_t stride)295 mos_bo_set_tiling(struct mos_linux_bo *bo, uint32_t * tiling_mode,
296 uint32_t stride)
297 {
298 if(!bo)
299 {
300 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
301 return -EINVAL;
302 }
303
304 if (bo->bufmgr && bo->bufmgr->bo_set_tiling)
305 {
306 return bo->bufmgr->bo_set_tiling(bo, tiling_mode, stride);
307 }
308 else
309 {
310 MOS_OS_CRITICALMESSAGE("Unsupported\n");
311 }
312
313 *tiling_mode = TILING_NONE;
314 return -EPERM;
315 }
316
317 int
mos_bo_get_tiling(struct mos_linux_bo * bo,uint32_t * tiling_mode,uint32_t * swizzle_mode)318 mos_bo_get_tiling(struct mos_linux_bo *bo, uint32_t * tiling_mode,
319 uint32_t * swizzle_mode)
320 {
321 if(!bo)
322 {
323 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
324 return -EINVAL;
325 }
326
327 if (bo->bufmgr && bo->bufmgr->bo_get_tiling)
328 {
329 return bo->bufmgr->bo_get_tiling(bo, tiling_mode, swizzle_mode);
330 }
331 else
332 {
333 MOS_OS_CRITICALMESSAGE("Unsupported\n");
334 }
335
336 *tiling_mode = TILING_NONE;
337 *swizzle_mode = I915_BIT_6_SWIZZLE_NONE;
338 return -EPERM;
339 }
340
341 int
mos_bo_flink(struct mos_linux_bo * bo,uint32_t * name)342 mos_bo_flink(struct mos_linux_bo *bo, uint32_t * name)
343 {
344 if(!bo)
345 {
346 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
347 return -EINVAL;
348 }
349
350 if (bo->bufmgr && bo->bufmgr->bo_flink)
351 {
352 return bo->bufmgr->bo_flink(bo, name);
353 }
354 else
355 {
356 MOS_OS_CRITICALMESSAGE("Unsupported\n");
357 return -ENODEV;
358 }
359 }
360
361 int
mos_bo_busy(struct mos_linux_bo * bo)362 mos_bo_busy(struct mos_linux_bo *bo)
363 {
364 if(!bo)
365 {
366 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
367 return -EINVAL;
368 }
369
370 if (bo->bufmgr && bo->bufmgr->bo_busy)
371 {
372 return bo->bufmgr->bo_busy(bo);
373 }
374 else
375 {
376 MOS_OS_CRITICALMESSAGE("Unsupported\n");
377 }
378
379 return 0;
380 }
381
382 int
mos_bo_madvise(struct mos_linux_bo * bo,int madv)383 mos_bo_madvise(struct mos_linux_bo *bo, int madv)
384 {
385 if(!bo)
386 {
387 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
388 return -EINVAL;
389 }
390
391 if (bo->bufmgr && bo->bufmgr->bo_madvise)
392 {
393 return bo->bufmgr->bo_madvise(bo, madv);
394 }
395 else
396 {
397 MOS_OS_CRITICALMESSAGE("Unsupported\n");
398 return -EPERM;
399 }
400 }
401
402 int
mos_bo_use_48b_address_range(struct mos_linux_bo * bo,uint32_t enable)403 mos_bo_use_48b_address_range(struct mos_linux_bo *bo, uint32_t enable)
404 {
405 if(!bo)
406 {
407 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
408 return -EINVAL;
409 }
410
411 if (bo->bufmgr && bo->bufmgr->bo_use_48b_address_range)
412 {
413 bo->bufmgr->bo_use_48b_address_range(bo, enable);
414 return 0;
415 }
416 else
417 {
418 MOS_OS_CRITICALMESSAGE("Unsupported\n");
419 return -ENODEV;
420 }
421 }
422
423 void
mos_bo_set_object_async(struct mos_linux_bo * bo)424 mos_bo_set_object_async(struct mos_linux_bo *bo)
425 {
426 if(!bo)
427 {
428 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
429 return;
430 }
431
432 if(bo->bufmgr && bo->bufmgr->set_object_async)
433 {
434 bo->bufmgr->set_object_async(bo);
435 }
436 else
437 {
438 MOS_OS_CRITICALMESSAGE("Unsupported\n");
439 }
440 }
441
442 void
mos_bo_set_exec_object_async(struct mos_linux_bo * bo,struct mos_linux_bo * target_bo)443 mos_bo_set_exec_object_async(struct mos_linux_bo *bo, struct mos_linux_bo *target_bo)
444 {
445 if(!bo)
446 {
447 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
448 return;
449 }
450
451 if(bo->bufmgr && bo->bufmgr->set_exec_object_async)
452 {
453 bo->bufmgr->set_exec_object_async(bo, target_bo);
454 }
455 else
456 {
457 MOS_OS_CRITICALMESSAGE("Unsupported\n");
458 }
459 }
460
461 void
mos_bo_set_object_capture(struct mos_linux_bo * bo)462 mos_bo_set_object_capture(struct mos_linux_bo *bo)
463 {
464 if(!bo)
465 {
466 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
467 return;
468 }
469
470 if (bo->bufmgr && bo->bufmgr->set_object_capture)
471 {
472 bo->bufmgr->set_object_capture(bo);
473 }
474 else
475 {
476 MOS_OS_CRITICALMESSAGE("Unsupported\n");
477 }
478 }
479
480 int
mos_bo_set_softpin(struct mos_linux_bo * bo)481 mos_bo_set_softpin(struct mos_linux_bo *bo)
482 {
483 if(!bo)
484 {
485 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
486 return -EINVAL;
487 }
488
489 if (bo->bufmgr && bo->bufmgr->bo_set_softpin)
490 {
491 return bo->bufmgr->bo_set_softpin(bo);
492 }
493 else
494 {
495 MOS_OS_CRITICALMESSAGE("Unsupported\n");
496 return -ENODEV;
497 }
498 }
499
500 int
mos_bo_add_softpin_target(struct mos_linux_bo * bo,struct mos_linux_bo * target_bo,bool write_flag)501 mos_bo_add_softpin_target(struct mos_linux_bo *bo, struct mos_linux_bo *target_bo, bool write_flag)
502 {
503 if(!bo)
504 {
505 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
506 return -EINVAL;
507 }
508
509 if (bo->bufmgr && bo->bufmgr->bo_add_softpin_target)
510 {
511 return bo->bufmgr->bo_add_softpin_target(bo, target_bo, write_flag);
512 }
513 else
514 {
515 MOS_OS_CRITICALMESSAGE("Unsupported\n");
516 return -ENODEV;
517 }
518 }
519
mos_bo_get_softpin_targets_info(struct mos_linux_bo * bo,int * count)520 mos_oca_exec_list_info* mos_bo_get_softpin_targets_info(struct mos_linux_bo *bo, int *count)
521 {
522 if(!bo)
523 {
524 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
525 return nullptr;
526 }
527
528 if (bo->bufmgr && bo->bufmgr->bo_get_softpin_targets_info)
529 {
530 return bo->bufmgr->bo_get_softpin_targets_info(bo, count);
531
532 }
533 else
534 {
535 MOS_OS_CRITICALMESSAGE("Unsupported\n");
536 return nullptr;
537 }
538 }
539
540 int
mos_bo_disable_reuse(struct mos_linux_bo * bo)541 mos_bo_disable_reuse(struct mos_linux_bo *bo)
542 {
543 if(!bo)
544 {
545 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
546 return -EINVAL;
547 }
548
549 if (bo->bufmgr && bo->bufmgr->bo_disable_reuse)
550 {
551 return bo->bufmgr->bo_disable_reuse(bo);
552 }
553 else
554 {
555 MOS_OS_CRITICALMESSAGE("Unsupported\n");
556 }
557
558 return 0;
559 }
560
561 int
mos_bo_is_reusable(struct mos_linux_bo * bo)562 mos_bo_is_reusable(struct mos_linux_bo *bo)
563 {
564 if(!bo)
565 {
566 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
567 return -EINVAL;
568 }
569
570 if (bo->bufmgr && bo->bufmgr->bo_is_reusable)
571 {
572 return bo->bufmgr->bo_is_reusable(bo);
573 }
574 else
575 {
576 MOS_OS_CRITICALMESSAGE("Unsupported\n");
577 }
578
579 return 0;
580 }
581
582 int
mos_bo_references(struct mos_linux_bo * bo,struct mos_linux_bo * target_bo)583 mos_bo_references(struct mos_linux_bo *bo, struct mos_linux_bo *target_bo)
584 {
585 if(!bo)
586 {
587 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
588 return -EINVAL;
589 }
590
591 if (bo->bufmgr && bo->bufmgr->bo_references)
592 {
593 return bo->bufmgr->bo_references(bo, target_bo);
594 }
595 else
596 {
597 MOS_OS_CRITICALMESSAGE("Unsupported\n");
598 return -ENODEV;
599 }
600 }
601
602 int
mos_bo_pad_to_size(struct mos_linux_bo * bo,uint64_t pad_to_size)603 mos_bo_pad_to_size(struct mos_linux_bo *bo, uint64_t pad_to_size)
604 {
605 if(!bo)
606 {
607 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
608 return -EINVAL;
609 }
610
611 if (bo->bufmgr && bo->bufmgr->bo_pad_to_size)
612 {
613 return bo->bufmgr->bo_pad_to_size(bo, pad_to_size);
614 }
615 else
616 {
617 MOS_OS_CRITICALMESSAGE("Unsupported\n");
618 return -ENODEV;
619 }
620 }
621
622 struct mos_linux_bo *
mos_bo_create_from_name(struct mos_bufmgr * bufmgr,const char * name,unsigned int handle)623 mos_bo_create_from_name(struct mos_bufmgr *bufmgr,
624 const char *name,
625 unsigned int handle)
626 {
627 if(!bufmgr)
628 {
629 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
630 return nullptr;
631 }
632
633 if (bufmgr->bo_create_from_name)
634 {
635 return bufmgr->bo_create_from_name(bufmgr, name, handle);
636 }
637 else
638 {
639 MOS_OS_CRITICALMESSAGE("Unsupported\n");
640 return nullptr;
641 }
642 }
643
644 int
mos_bo_map_unsynchronized(struct mos_linux_bo * bo)645 mos_bo_map_unsynchronized(struct mos_linux_bo *bo)
646 {
647 if(!bo)
648 {
649 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
650 return -EINVAL;
651 }
652
653 if (bo->bufmgr && bo->bufmgr->bo_map_unsynchronized)
654 {
655 return bo->bufmgr->bo_map_unsynchronized(bo);
656 }
657 else
658 {
659 MOS_OS_CRITICALMESSAGE("Unsupported\n");
660 return -EPERM;
661 }
662
663 }
664
665 int
mos_bo_map_gtt(struct mos_linux_bo * bo)666 mos_bo_map_gtt(struct mos_linux_bo *bo)
667 {
668 if(!bo)
669 {
670 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
671 return -EINVAL;
672 }
673
674 if (bo->bufmgr && bo->bufmgr->bo_map_gtt)
675 {
676 return bo->bufmgr->bo_map_gtt(bo);
677 }
678 else
679 {
680 MOS_OS_CRITICALMESSAGE("Unsupported\n");
681 return -EPERM;
682 }
683 }
684
685 int
mos_bo_unmap_gtt(struct mos_linux_bo * bo)686 mos_bo_unmap_gtt(struct mos_linux_bo *bo)
687 {
688 if(!bo)
689 {
690 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
691 return -EINVAL;
692 }
693
694 if (bo->bufmgr && bo->bufmgr->bo_unmap_gtt)
695 {
696 return bo->bufmgr->bo_unmap_gtt(bo);
697 }
698 else
699 {
700 MOS_OS_CRITICALMESSAGE("Unsupported\n");
701 return -EPERM;
702 }
703 }
704
705 drm_export int
mos_bo_map_wc(struct mos_linux_bo * bo)706 mos_bo_map_wc(struct mos_linux_bo *bo)
707 {
708 if(!bo)
709 {
710 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
711 return -EINVAL;
712 }
713
714 if (bo->bufmgr && bo->bufmgr->bo_map_wc)
715 {
716 return bo->bufmgr->bo_map_wc(bo);
717 }
718 else
719 {
720 MOS_OS_CRITICALMESSAGE("Unsupported\n");
721 return -EPERM;
722 }
723 }
724
725 int
mos_bo_unmap_wc(struct mos_linux_bo * bo)726 mos_bo_unmap_wc(struct mos_linux_bo *bo)
727 {
728 if(!bo)
729 {
730 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
731 return -EINVAL;
732 }
733
734 if (bo->bufmgr && bo->bufmgr->bo_unmap_wc)
735 {
736 return bo->bufmgr->bo_unmap_wc(bo);
737 }
738 else
739 {
740 MOS_OS_CRITICALMESSAGE("Unsupported\n");
741 return -EPERM;
742 }
743 }
744
745 void
mos_bo_start_gtt_access(struct mos_linux_bo * bo,int write_enable)746 mos_bo_start_gtt_access(struct mos_linux_bo *bo, int write_enable)
747 {
748 if(!bo)
749 {
750 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
751 return;
752 }
753
754 if (bo->bufmgr && bo->bufmgr->bo_start_gtt_access)
755 {
756 bo->bufmgr->bo_start_gtt_access(bo, write_enable);
757 }
758 else
759 {
760 MOS_OS_CRITICALMESSAGE("Unsupported\n");
761 }
762 }
763
764 int
mos_bo_context_exec2(struct mos_linux_bo * bo,int used,struct mos_linux_context * ctx,struct drm_clip_rect * cliprects,int num_cliprects,int DR4,unsigned int flags,int * fence)765 mos_bo_context_exec2(struct mos_linux_bo *bo, int used, struct mos_linux_context *ctx,
766 struct drm_clip_rect *cliprects, int num_cliprects, int DR4,
767 unsigned int flags, int *fence)
768
769 {
770 if(!bo)
771 {
772 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
773 return -EINVAL;
774 }
775
776 if (bo->bufmgr && bo->bufmgr->bo_context_exec2)
777 {
778 return bo->bufmgr->bo_context_exec2(bo, used, ctx, cliprects, num_cliprects, DR4, flags, fence);
779 }
780 else
781 {
782 MOS_OS_CRITICALMESSAGE("Unsupported\n");
783 return -EPERM;
784 }
785 }
786
787 int
mos_bo_context_exec3(struct mos_linux_bo ** bo,int num_bo,struct mos_linux_context * ctx,struct drm_clip_rect * cliprects,int num_cliprects,int DR4,unsigned int flags,int * fence)788 mos_bo_context_exec3(struct mos_linux_bo **bo, int num_bo, struct mos_linux_context *ctx,
789 struct drm_clip_rect *cliprects, int num_cliprects, int DR4,
790 unsigned int flags, int *fence)
791 {
792 if(!bo)
793 {
794 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
795 return -EINVAL;
796 }
797
798 if ((*bo)->bufmgr && (*bo)->bufmgr->bo_context_exec3)
799 {
800 return (*bo)->bufmgr->bo_context_exec3(bo, num_bo, ctx, cliprects, num_cliprects, DR4, flags, fence);
801 }
802 else
803 {
804 MOS_OS_CRITICALMESSAGE("Unsupported\n");
805 return -EPERM;
806 }
807 }
808
809 drm_export bool
mos_bo_is_exec_object_async(struct mos_linux_bo * bo)810 mos_bo_is_exec_object_async(struct mos_linux_bo *bo)
811 {
812 if(!bo)
813 {
814 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
815 return false;
816 }
817
818 if (bo->bufmgr && bo->bufmgr->bo_is_exec_object_async)
819 {
820 return bo->bufmgr->bo_is_exec_object_async(bo);
821 }
822 else
823 {
824 MOS_OS_CRITICALMESSAGE("Unsupported\n");
825 return false;
826 }
827 }
828
829 drm_export bool
mos_bo_is_softpin(struct mos_linux_bo * bo)830 mos_bo_is_softpin(struct mos_linux_bo *bo)
831 {
832 if(!bo)
833 {
834 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
835 return false;
836 }
837
838 if (bo->bufmgr && bo->bufmgr->bo_is_softpin)
839 {
840 return bo->bufmgr->bo_is_softpin(bo);
841 }
842 else
843 {
844 MOS_OS_CRITICALMESSAGE("Unsupported\n");
845 return false;
846 }
847 }
848
849 drm_export int
mos_bo_wait(struct mos_linux_bo * bo,int64_t timeout_ns)850 mos_bo_wait(struct mos_linux_bo *bo, int64_t timeout_ns)
851 {
852 if(!bo)
853 {
854 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
855 return -EINVAL;
856 }
857
858 if (bo->bufmgr && bo->bufmgr->bo_wait)
859 {
860 return bo->bufmgr->bo_wait(bo, timeout_ns);
861 }
862 else
863 {
864 MOS_OS_CRITICALMESSAGE("Unsupported\n");
865 return -EPERM;
866 }
867 }
868
869 drm_export void
mos_bo_clear_relocs(struct mos_linux_bo * bo,int start)870 mos_bo_clear_relocs(struct mos_linux_bo *bo, int start)
871 {
872 if(!bo)
873 {
874 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
875 return;
876 }
877
878 if (bo->bufmgr && bo->bufmgr->bo_clear_relocs)
879 {
880 bo->bufmgr->bo_clear_relocs(bo, start);
881 }
882 else
883 {
884 MOS_OS_CRITICALMESSAGE("Unsupported\n");
885 }
886 }
887
888 int
mos_bo_export_to_prime(struct mos_linux_bo * bo,int * prime_fd)889 mos_bo_export_to_prime(struct mos_linux_bo *bo, int *prime_fd)
890 {
891 if(!bo)
892 {
893 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
894 return -EINVAL;
895 }
896
897 if (bo->bufmgr && bo->bufmgr->bo_export_to_prime)
898 {
899 return bo->bufmgr->bo_export_to_prime(bo, prime_fd);
900 }
901 else
902 {
903 MOS_OS_CRITICALMESSAGE("Unsupported\n");
904 return -EPERM;
905 }
906 }
907
908 struct mos_linux_bo *
mos_bo_create_from_prime(struct mos_bufmgr * bufmgr,struct mos_drm_bo_alloc_prime * alloc_prime)909 mos_bo_create_from_prime(struct mos_bufmgr *bufmgr,
910 struct mos_drm_bo_alloc_prime *alloc_prime)
911 {
912 if(!bufmgr || !alloc_prime)
913 {
914 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
915 return nullptr;
916 }
917
918 if (bufmgr->bo_create_from_prime)
919 {
920 return bufmgr->bo_create_from_prime(bufmgr, alloc_prime);
921 }
922 else
923 {
924 MOS_OS_CRITICALMESSAGE("Unsupported\n");
925 return nullptr;
926 }
927 }
928
929 int
mos_bufmgr_check_aperture_space(struct mos_linux_bo ** bo_array,int count)930 mos_bufmgr_check_aperture_space(struct mos_linux_bo ** bo_array, int count)
931 {
932 if(!bo_array)
933 {
934 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
935 return -EINVAL;
936 }
937
938 if (bo_array[0]->bufmgr && bo_array[0]->bufmgr->check_aperture_space)
939 {
940 return bo_array[0]->bufmgr->check_aperture_space(bo_array, count);
941 }
942 else
943 {
944 MOS_OS_CRITICALMESSAGE("Unsupported\n");
945 return -EPERM;
946 }
947 }
948
949 void
mos_bufmgr_destroy(struct mos_bufmgr * bufmgr)950 mos_bufmgr_destroy(struct mos_bufmgr *bufmgr)
951 {
952 if(!bufmgr)
953 {
954 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
955 return;
956 }
957
958 if (bufmgr->destroy)
959 {
960 bufmgr->destroy(bufmgr);
961 }
962 else
963 {
964 MOS_OS_CRITICALMESSAGE("Unsupported\n");
965 }
966 }
967
968 void
mos_bufmgr_set_debug(struct mos_bufmgr * bufmgr,int enable_debug)969 mos_bufmgr_set_debug(struct mos_bufmgr *bufmgr, int enable_debug)
970 {
971 if(!bufmgr)
972 {
973 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
974 return;
975 }
976
977 bufmgr->debug = enable_debug;
978 }
979
980 struct mos_linux_context *
mos_context_create(struct mos_bufmgr * bufmgr)981 mos_context_create(struct mos_bufmgr *bufmgr)
982 {
983 if(!bufmgr)
984 {
985 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
986 return nullptr;
987 }
988
989 if (bufmgr->context_create)
990 {
991 return bufmgr->context_create(bufmgr);
992 }
993 else
994 {
995 MOS_OS_CRITICALMESSAGE("Unsupported\n");
996 return nullptr;
997 }
998 }
999
1000 struct mos_linux_context *
mos_context_create_ext(struct mos_bufmgr * bufmgr,__u32 flags,bool bContextProtected)1001 mos_context_create_ext(
1002 struct mos_bufmgr *bufmgr,
1003 __u32 flags,
1004 bool bContextProtected)
1005 {
1006 if(!bufmgr)
1007 {
1008 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1009 return nullptr;
1010 }
1011
1012 if (bufmgr->context_create_ext)
1013 {
1014 return bufmgr->context_create_ext(bufmgr, flags, bContextProtected);
1015 }
1016 else
1017 {
1018 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1019 return nullptr;
1020 }
1021
1022 }
1023
1024 struct mos_linux_context *
mos_context_create_shared(struct mos_bufmgr * bufmgr,mos_linux_context * ctx,__u32 flags,bool bContextProtected,void * engine_map,uint8_t ctx_width,uint8_t num_placements,uint32_t ctx_type)1025 mos_context_create_shared(
1026 struct mos_bufmgr *bufmgr,
1027 mos_linux_context* ctx,
1028 __u32 flags,
1029 bool bContextProtected,
1030 void *engine_map,
1031 uint8_t ctx_width,
1032 uint8_t num_placements,
1033 uint32_t ctx_type)
1034 {
1035 if(!bufmgr)
1036 {
1037 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1038 return nullptr;
1039 }
1040
1041 if (bufmgr->context_create_shared)
1042 {
1043 return bufmgr->context_create_shared(bufmgr, ctx, flags, bContextProtected,
1044 engine_map, ctx_width, num_placements, ctx_type);
1045 }
1046 else
1047 {
1048 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1049 return nullptr;
1050 }
1051 }
1052
1053 __u32
mos_vm_create(struct mos_bufmgr * bufmgr)1054 mos_vm_create(struct mos_bufmgr *bufmgr)
1055 {
1056 if(!bufmgr)
1057 {
1058 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1059 return INVALID_VM;
1060 }
1061
1062 if (bufmgr->vm_create)
1063 {
1064 return bufmgr->vm_create(bufmgr);
1065 }
1066 else
1067 {
1068 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1069 return INVALID_VM;
1070 }
1071 }
1072
1073 void
mos_vm_destroy(struct mos_bufmgr * bufmgr,__u32 vm_id)1074 mos_vm_destroy(struct mos_bufmgr *bufmgr, __u32 vm_id)
1075 {
1076 if(!bufmgr)
1077 {
1078 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1079 return;
1080 }
1081
1082 if (bufmgr->vm_destroy)
1083 {
1084 bufmgr->vm_destroy(bufmgr, vm_id);
1085 }
1086 else
1087 {
1088 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1089 }
1090 }
1091
1092 void
mos_bufmgr_enable_reuse(struct mos_bufmgr * bufmgr)1093 mos_bufmgr_enable_reuse(struct mos_bufmgr *bufmgr)
1094 {
1095 if(!bufmgr)
1096 {
1097 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1098 return;
1099 }
1100
1101 if (bufmgr->enable_reuse)
1102 {
1103 bufmgr->enable_reuse(bufmgr);
1104 }
1105 else
1106 {
1107 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1108 }
1109 }
1110
1111 void
mos_bufmgr_enable_softpin(struct mos_bufmgr * bufmgr,bool va1m_align)1112 mos_bufmgr_enable_softpin(struct mos_bufmgr *bufmgr, bool va1m_align)
1113 {
1114 if(!bufmgr)
1115 {
1116 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1117 return;
1118 }
1119
1120 if (bufmgr->enable_softpin)
1121 {
1122 bufmgr->enable_softpin(bufmgr, va1m_align);
1123 }
1124 else
1125 {
1126 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1127 }
1128 }
1129
1130 void
mos_bufmgr_enable_vmbind(struct mos_bufmgr * bufmgr)1131 mos_bufmgr_enable_vmbind(struct mos_bufmgr *bufmgr)
1132 {
1133 if(!bufmgr)
1134 {
1135 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1136 return;
1137 }
1138
1139 if (bufmgr->enable_vmbind)
1140 {
1141 bufmgr->enable_vmbind(bufmgr);
1142 }
1143 {
1144 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1145 }
1146 }
1147
1148 void
mos_bufmgr_disable_object_capture(struct mos_bufmgr * bufmgr)1149 mos_bufmgr_disable_object_capture(struct mos_bufmgr *bufmgr)
1150 {
1151 if(!bufmgr)
1152 {
1153 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1154 return;
1155 }
1156
1157 if (bufmgr->disable_object_capture)
1158 {
1159 bufmgr->disable_object_capture(bufmgr);
1160 }
1161 else
1162 {
1163 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1164 }
1165 }
1166
1167 int
mos_bufmgr_get_memory_info(struct mos_bufmgr * bufmgr,char * info,uint32_t length)1168 mos_bufmgr_get_memory_info(struct mos_bufmgr *bufmgr, char *info, uint32_t length)
1169 {
1170 if(!bufmgr)
1171 {
1172 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1173 return -EINVAL;
1174 }
1175
1176 if (bufmgr->get_memory_info)
1177 {
1178 return bufmgr->get_memory_info(bufmgr, info, length);
1179 }
1180 else
1181 {
1182 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1183 return -EPERM;
1184 }
1185 }
1186
1187 int
mos_bufmgr_get_devid(struct mos_bufmgr * bufmgr)1188 mos_bufmgr_get_devid(struct mos_bufmgr *bufmgr)
1189 {
1190 if(!bufmgr)
1191 {
1192 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1193 return -EINVAL;
1194 }
1195
1196 if (bufmgr->get_devid)
1197 {
1198 return bufmgr->get_devid(bufmgr);
1199 }
1200 else
1201 {
1202 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1203 return -EPERM;
1204 }
1205 }
1206
1207 void
mos_bufmgr_realloc_cache(struct mos_bufmgr * bufmgr,uint8_t alloc_mode)1208 mos_bufmgr_realloc_cache(struct mos_bufmgr *bufmgr, uint8_t alloc_mode)
1209 {
1210 if(!bufmgr)
1211 {
1212 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1213 return;
1214 }
1215
1216 if (bufmgr->realloc_cache)
1217 {
1218 return bufmgr->realloc_cache(bufmgr, alloc_mode);
1219 }
1220 else
1221 {
1222 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1223 }
1224 }
1225
1226 int
mos_query_engines_count(struct mos_bufmgr * bufmgr,unsigned int * nengine)1227 mos_query_engines_count(struct mos_bufmgr *bufmgr,
1228 unsigned int *nengine)
1229 {
1230 if(!bufmgr)
1231 {
1232 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1233 return -EINVAL;
1234 }
1235
1236 if (bufmgr->query_engines_count)
1237 {
1238 return bufmgr->query_engines_count(bufmgr, nengine);
1239 }
1240 else
1241 {
1242 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1243 return -EPERM;
1244 }
1245 }
1246
1247 int
mos_query_engines(struct mos_bufmgr * bufmgr,__u16 engine_class,__u64 caps,unsigned int * nengine,void * ci)1248 mos_query_engines(struct mos_bufmgr *bufmgr,
1249 __u16 engine_class,
1250 __u64 caps,
1251 unsigned int *nengine,
1252 void *ci)
1253 {
1254 if(!bufmgr)
1255 {
1256 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1257 return -EINVAL;
1258 }
1259
1260 if (bufmgr->query_engines)
1261 {
1262 return bufmgr->query_engines(bufmgr, engine_class, caps, nengine, ci);
1263 }
1264 else
1265 {
1266 MOS_OS_CRITICALMESSAGE("Unsupported bufmgr:0x%x\n", bufmgr);
1267 return -EPERM;
1268 }
1269 }
1270
1271 size_t
mos_get_engine_class_size(struct mos_bufmgr * bufmgr)1272 mos_get_engine_class_size(struct mos_bufmgr *bufmgr)
1273 {
1274 if(!bufmgr)
1275 {
1276 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1277 return 0;
1278 }
1279
1280 if (bufmgr->get_engine_class_size)
1281 {
1282 return bufmgr->get_engine_class_size();
1283 }
1284 else
1285 {
1286 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1287 return 0;
1288 }
1289 }
1290
1291 int
mos_query_sys_engines(struct mos_bufmgr * bufmgr,MEDIA_SYSTEM_INFO * gfx_info)1292 mos_query_sys_engines(struct mos_bufmgr *bufmgr, MEDIA_SYSTEM_INFO* gfx_info)
1293 {
1294 if(!bufmgr)
1295 {
1296 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1297 return -EINVAL;
1298 }
1299
1300 if (bufmgr->query_sys_engines)
1301 {
1302 return bufmgr->query_sys_engines(bufmgr, gfx_info);
1303 }
1304 else
1305 {
1306 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1307 return -EPERM;
1308 }
1309
1310 }
1311
1312 int
mos_query_device_blob(struct mos_bufmgr * bufmgr,MEDIA_SYSTEM_INFO * gfx_info)1313 mos_query_device_blob(struct mos_bufmgr *bufmgr, MEDIA_SYSTEM_INFO* gfx_info)
1314 {
1315 if(!bufmgr)
1316 {
1317 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1318 return -EINVAL;
1319 }
1320
1321 if (bufmgr->query_device_blob)
1322 {
1323 return bufmgr->query_device_blob(bufmgr, gfx_info);
1324 }
1325 else
1326 {
1327 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1328 return -EPERM;
1329 }
1330 }
1331
1332 void
mos_select_fixed_engine(struct mos_bufmgr * bufmgr,void * engine_map,uint32_t * nengine,uint32_t fixed_instance_mask)1333 mos_select_fixed_engine(struct mos_bufmgr *bufmgr,
1334 void *engine_map,
1335 uint32_t *nengine,
1336 uint32_t fixed_instance_mask)
1337 {
1338 if (bufmgr && bufmgr->select_fixed_engine)
1339 {
1340 return bufmgr->select_fixed_engine(bufmgr,
1341 engine_map,
1342 nengine,
1343 fixed_instance_mask);
1344 }
1345
1346 }
1347
1348 int
mos_get_driver_info(struct mos_bufmgr * bufmgr,struct LinuxDriverInfo * drvInfo)1349 mos_get_driver_info(struct mos_bufmgr *bufmgr, struct LinuxDriverInfo *drvInfo)
1350 {
1351 if(!bufmgr)
1352 {
1353 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1354 return -EINVAL;
1355 }
1356
1357 if (bufmgr->get_driver_info)
1358 {
1359 return bufmgr->get_driver_info(bufmgr, drvInfo);
1360 }
1361 else
1362 {
1363 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1364 return -EPERM;
1365 }
1366 }
1367
1368 int
mos_query_hw_ip_version(struct mos_bufmgr * bufmgr,__u16 engine_class,void * ip_ver_info)1369 mos_query_hw_ip_version(struct mos_bufmgr *bufmgr, __u16 engine_class, void *ip_ver_info)
1370 {
1371 if(!bufmgr)
1372 {
1373 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1374 return -EINVAL;
1375 }
1376
1377 if (bufmgr->query_hw_ip_version)
1378 {
1379 return bufmgr->query_hw_ip_version(bufmgr, engine_class, ip_ver_info);
1380 }
1381 else
1382 {
1383 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1384 return -EPERM;
1385 }
1386 }
1387
1388 uint64_t
mos_get_platform_information(struct mos_bufmgr * bufmgr)1389 mos_get_platform_information(struct mos_bufmgr *bufmgr)
1390 {
1391 if(!bufmgr)
1392 {
1393 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1394 return 0;
1395 }
1396
1397 if (bufmgr->get_platform_information)
1398 {
1399 return bufmgr->get_platform_information(bufmgr);
1400 }
1401 else
1402 {
1403 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1404 }
1405
1406 return 0;
1407 }
1408
1409 void
mos_set_platform_information(struct mos_bufmgr * bufmgr,uint64_t p)1410 mos_set_platform_information(struct mos_bufmgr *bufmgr, uint64_t p)
1411 {
1412 if(!bufmgr)
1413 {
1414 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1415 return;
1416 }
1417
1418 if (bufmgr->set_platform_information)
1419 {
1420 bufmgr->set_platform_information(bufmgr, p);
1421 }
1422 else
1423 {
1424 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1425 }
1426 }
1427
1428 bool
mos_has_bsd2(struct mos_bufmgr * bufmgr)1429 mos_has_bsd2(struct mos_bufmgr *bufmgr)
1430 {
1431 if(!bufmgr)
1432 {
1433 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1434 return false;
1435 }
1436
1437 if (bufmgr->has_bsd2)
1438 {
1439 return bufmgr->has_bsd2(bufmgr);
1440 }
1441 else
1442 {
1443 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1444 return false;
1445 }
1446 }
1447
1448 void
mos_enable_turbo_boost(struct mos_bufmgr * bufmgr)1449 mos_enable_turbo_boost(struct mos_bufmgr *bufmgr)
1450 {
1451 if(!bufmgr)
1452 {
1453 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1454 return;
1455 }
1456
1457 if (bufmgr->enable_turbo_boost)
1458 {
1459 bufmgr->enable_turbo_boost(bufmgr);
1460 }
1461 else
1462 {
1463 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1464 }
1465 }
1466
1467 int
mos_get_ts_frequency(struct mos_bufmgr * bufmgr,uint32_t * ts_freq)1468 mos_get_ts_frequency(struct mos_bufmgr *bufmgr, uint32_t *ts_freq)
1469 {
1470 if(!bufmgr)
1471 {
1472 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1473 return -EINVAL;
1474 }
1475
1476 if (bufmgr->get_ts_frequency)
1477 {
1478 return bufmgr->get_ts_frequency(bufmgr, ts_freq);
1479 }
1480 else
1481 {
1482 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1483 return -EPERM;
1484 }
1485 }
1486
1487
1488 int
mos_reg_read(struct mos_bufmgr * bufmgr,uint32_t offset,uint64_t * result)1489 mos_reg_read(struct mos_bufmgr *bufmgr,
1490 uint32_t offset,
1491 uint64_t *result)
1492 {
1493 if(!bufmgr)
1494 {
1495 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1496 return -EINVAL;
1497 }
1498
1499 if (bufmgr->reg_read)
1500 {
1501 return bufmgr->reg_read(bufmgr, offset, result);
1502 }
1503 else
1504 {
1505 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1506 return -EPERM;
1507 }
1508 }
1509
1510 int
mos_get_reset_stats(struct mos_linux_context * ctx,uint32_t * reset_count,uint32_t * active,uint32_t * pending)1511 mos_get_reset_stats(struct mos_linux_context *ctx,
1512 uint32_t *reset_count,
1513 uint32_t *active,
1514 uint32_t *pending)
1515 {
1516 if(!ctx)
1517 {
1518 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1519 return -EINVAL;
1520 }
1521
1522 if (ctx->bufmgr && ctx->bufmgr->get_reset_stats)
1523 {
1524 return ctx->bufmgr->get_reset_stats(ctx, reset_count, active, pending);
1525 }
1526 else
1527 {
1528 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1529 return -EPERM;
1530 }
1531 }
1532
1533 int
mos_get_context_param_sseu(struct mos_linux_context * ctx,struct drm_i915_gem_context_param_sseu * sseu)1534 mos_get_context_param_sseu(struct mos_linux_context *ctx,
1535 struct drm_i915_gem_context_param_sseu *sseu)
1536 {
1537 if(!ctx)
1538 {
1539 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1540 return -EINVAL;
1541 }
1542
1543 if (ctx->bufmgr && ctx->bufmgr->get_context_param_sseu)
1544 {
1545 return ctx->bufmgr->get_context_param_sseu(ctx, sseu);
1546 }
1547 else
1548 {
1549 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1550 return -EPERM;
1551 }
1552 }
1553
1554 int
mos_set_context_param_sseu(struct mos_linux_context * ctx,struct drm_i915_gem_context_param_sseu sseu)1555 mos_set_context_param_sseu(struct mos_linux_context *ctx,
1556 struct drm_i915_gem_context_param_sseu sseu)
1557 {
1558 if(!ctx)
1559 {
1560 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1561 return -EINVAL;
1562 }
1563
1564 if (ctx->bufmgr && ctx->bufmgr->set_context_param_sseu)
1565 {
1566 return ctx->bufmgr->set_context_param_sseu(ctx, sseu);
1567 }
1568 else
1569 {
1570 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1571 return -EPERM;
1572 }
1573 }
1574
1575 int
mos_set_context_param(struct mos_linux_context * ctx,uint32_t size,uint64_t param,uint64_t value)1576 mos_set_context_param(struct mos_linux_context *ctx,
1577 uint32_t size,
1578 uint64_t param,
1579 uint64_t value)
1580 {
1581 if(!ctx)
1582 {
1583 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1584 return -EINVAL;
1585 }
1586
1587 if (ctx->bufmgr && ctx->bufmgr->set_context_param)
1588 {
1589 return ctx->bufmgr->set_context_param(ctx, size, param, value);
1590 }
1591 else
1592 {
1593 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1594 return -EPERM;
1595 }
1596 }
1597
1598 int
mos_set_context_param_parallel(struct mos_linux_context * ctx,struct i915_engine_class_instance * ci,unsigned int count)1599 mos_set_context_param_parallel(struct mos_linux_context *ctx,
1600 struct i915_engine_class_instance *ci,
1601 unsigned int count)
1602 {
1603 if(!ctx)
1604 {
1605 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1606 return -EINVAL;
1607 }
1608
1609 if (ctx->bufmgr && ctx->bufmgr->set_context_param_parallel)
1610 {
1611 return ctx->bufmgr->set_context_param_parallel(ctx, ci, count);
1612 }
1613 else
1614 {
1615 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1616 return -EPERM;
1617 }
1618
1619 }
1620
1621 int
mos_set_context_param_load_balance(struct mos_linux_context * ctx,struct i915_engine_class_instance * ci,unsigned int count)1622 mos_set_context_param_load_balance(struct mos_linux_context *ctx,
1623 struct i915_engine_class_instance *ci,
1624 unsigned int count)
1625 {
1626 if(!ctx)
1627 {
1628 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1629 return -EINVAL;
1630 }
1631
1632 if (ctx->bufmgr && ctx->bufmgr->set_context_param_load_balance)
1633 {
1634 return ctx->bufmgr->set_context_param_load_balance(ctx, ci, count);
1635 }
1636 else
1637 {
1638 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1639 return -EPERM;
1640 }
1641 }
1642
1643 int
mos_set_context_param_bond(struct mos_linux_context * ctx,struct i915_engine_class_instance master_ci,struct i915_engine_class_instance * bond_ci,unsigned int bond_count)1644 mos_set_context_param_bond(struct mos_linux_context *ctx,
1645 struct i915_engine_class_instance master_ci,
1646 struct i915_engine_class_instance *bond_ci,
1647 unsigned int bond_count)
1648 {
1649 if(!ctx)
1650 {
1651 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1652 return -EINVAL;
1653 }
1654
1655 if (ctx->bufmgr && ctx->bufmgr->set_context_param_bond)
1656 {
1657 return ctx->bufmgr->set_context_param_bond(ctx, master_ci, bond_ci, bond_count);
1658 }
1659 else
1660 {
1661 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1662 return -EPERM;
1663 }
1664 }
1665
1666 int
mos_get_context_param(struct mos_linux_context * ctx,uint32_t size,uint64_t param,uint64_t * value)1667 mos_get_context_param(struct mos_linux_context *ctx,
1668 uint32_t size,
1669 uint64_t param,
1670 uint64_t *value)
1671 {
1672 if(!ctx)
1673 {
1674 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1675 return -EINVAL;
1676 }
1677
1678 if (ctx->bufmgr && ctx->bufmgr->get_context_param)
1679 {
1680 return ctx->bufmgr->get_context_param(ctx, size, param, value);
1681 }
1682 else
1683 {
1684 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1685 return -EPERM;
1686 }
1687 }
1688
1689 uint8_t
mos_switch_off_n_bits(struct mos_linux_context * ctx,uint8_t in_mask,int n)1690 mos_switch_off_n_bits(struct mos_linux_context *ctx, uint8_t in_mask, int n)
1691 {
1692 if(!ctx)
1693 {
1694 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1695 return 0;
1696 }
1697
1698 if (ctx->bufmgr && ctx->bufmgr->switch_off_n_bits)
1699 {
1700 return ctx->bufmgr->switch_off_n_bits(ctx, in_mask, n);
1701 }
1702 else
1703 {
1704 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1705 }
1706
1707 return 0;
1708 }
1709
1710 unsigned int
mos_hweight8(struct mos_linux_context * ctx,uint8_t w)1711 mos_hweight8(struct mos_linux_context *ctx, uint8_t w)
1712 {
1713 if(!ctx)
1714 {
1715 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1716 return 0;
1717 }
1718
1719 if (ctx->bufmgr && ctx->bufmgr->hweight8)
1720 {
1721 return ctx->bufmgr->hweight8(ctx, w);
1722 }
1723 else
1724 {
1725 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1726 }
1727
1728 return 0;
1729 }
1730
1731 void
mos_context_destroy(struct mos_linux_context * ctx)1732 mos_context_destroy(struct mos_linux_context *ctx)
1733 {
1734 if(!ctx)
1735 {
1736 MOS_OS_CRITICALMESSAGE("Input null ptr\n");
1737 return;
1738 }
1739
1740 if (ctx->bufmgr && ctx->bufmgr->context_destroy)
1741 {
1742 ctx->bufmgr->context_destroy(ctx);
1743 }
1744 else
1745 {
1746 MOS_OS_CRITICALMESSAGE("Unsupported\n");
1747 }
1748 }
1749
1750