Lines Matching refs:stream

147 static u32 xe_oa_circ_diff(struct xe_oa_stream *stream, u32 tail, u32 head)
150 tail + stream->oa_buffer.circ_size - head;
153 static u32 xe_oa_circ_incr(struct xe_oa_stream *stream, u32 ptr, u32 n)
155 return ptr + n >= stream->oa_buffer.circ_size ?
156 ptr + n - stream->oa_buffer.circ_size : ptr + n;
202 static const struct xe_oa_regs *__oa_regs(struct xe_oa_stream *stream)
204 return &stream->oa_unit->regs;
207 static u32 xe_oa_hw_tail_read(struct xe_oa_stream *stream)
209 return xe_mmio_read32(&stream->gt->mmio, __oa_regs(stream)->oa_tail_ptr) &
216 static u64 oa_report_id(struct xe_oa_stream *stream, void *report)
218 return oa_report_header_64bit(stream) ? *(u64 *)report : *(u32 *)report;
221 static void oa_report_id_clear(struct xe_oa_stream *stream, u32 *report)
223 if (oa_report_header_64bit(stream))
229 static u64 oa_timestamp(struct xe_oa_stream *stream, void *report)
231 return oa_report_header_64bit(stream) ?
236 static void oa_timestamp_clear(struct xe_oa_stream *stream, u32 *report)
238 if (oa_report_header_64bit(stream))
244 static bool xe_oa_buffer_check_unlocked(struct xe_oa_stream *stream)
246 u32 gtt_offset = xe_bo_ggtt_addr(stream->oa_buffer.bo);
248 int report_size = stream->oa_buffer.format->size;
251 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
253 hw_tail = xe_oa_hw_tail_read(stream);
261 partial_report_size = xe_oa_circ_diff(stream, hw_tail, stream->oa_buffer.tail);
265 hw_tail = xe_oa_circ_diff(stream, hw_tail, partial_report_size);
270 * Walk the stream backward until we find a report with report id and timestamp
277 while (xe_oa_circ_diff(stream, tail, stream->oa_buffer.tail) >= report_size) {
278 void *report = stream->oa_buffer.vaddr + tail;
280 if (oa_report_id(stream, report) || oa_timestamp(stream, report))
283 tail = xe_oa_circ_diff(stream, tail, report_size);
286 if (xe_oa_circ_diff(stream, hw_tail, tail) > report_size)
287 drm_dbg(&stream->oa->xe->drm,
289 stream->oa_buffer.head, tail, hw_tail);
291 stream->oa_buffer.tail = tail;
293 available = xe_oa_circ_diff(stream, stream->oa_buffer.tail, stream->oa_buffer.head);
294 stream->pollin = available >= stream->wait_num_reports * report_size;
296 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
298 return stream->pollin;
303 struct xe_oa_stream *stream =
304 container_of(hrtimer, typeof(*stream), poll_check_timer);
306 if (xe_oa_buffer_check_unlocked(stream))
307 wake_up(&stream->poll_wq);
309 hrtimer_forward_now(hrtimer, ns_to_ktime(stream->poll_period_ns));
314 static int xe_oa_append_report(struct xe_oa_stream *stream, char __user *buf,
317 int report_size = stream->oa_buffer.format->size;
326 oa_buf_end = stream->oa_buffer.vaddr + stream->oa_buffer.circ_size;
334 if (copy_to_user(buf, stream->oa_buffer.vaddr,
346 static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,
349 int report_size = stream->oa_buffer.format->size;
350 u8 *oa_buf_base = stream->oa_buffer.vaddr;
351 u32 gtt_offset = xe_bo_ggtt_addr(stream->oa_buffer.bo);
357 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
358 head = stream->oa_buffer.head;
359 tail = stream->oa_buffer.tail;
360 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
362 xe_assert(stream->oa->xe,
363 head < stream->oa_buffer.circ_size && tail < stream->oa_buffer.circ_size);
365 for (; xe_oa_circ_diff(stream, tail, head);
366 head = xe_oa_circ_incr(stream, head, report_size)) {
369 ret = xe_oa_append_report(stream, buf, count, offset, report);
373 if (!(stream->oa_buffer.circ_size % report_size)) {
375 oa_report_id_clear(stream, (void *)report);
376 oa_timestamp_clear(stream, (void *)report);
378 u8 *oa_buf_end = stream->oa_buffer.vaddr + stream->oa_buffer.circ_size;
392 struct xe_reg oaheadptr = __oa_regs(stream)->oa_head_ptr;
394 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
395 xe_mmio_write32(&stream->gt->mmio, oaheadptr,
397 stream->oa_buffer.head = head;
398 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
404 static void xe_oa_init_oa_buffer(struct xe_oa_stream *stream)
406 u32 gtt_offset = xe_bo_ggtt_addr(stream->oa_buffer.bo);
407 int size_exponent = __ffs(xe_bo_size(stream->oa_buffer.bo));
409 struct xe_mmio *mmio = &stream->gt->mmio;
419 spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
421 xe_mmio_write32(mmio, __oa_regs(stream)->oa_status, 0);
422 xe_mmio_write32(mmio, __oa_regs(stream)->oa_head_ptr,
424 stream->oa_buffer.head = 0;
429 xe_mmio_write32(mmio, __oa_regs(stream)->oa_buffer, oa_buf);
430 xe_mmio_write32(mmio, __oa_regs(stream)->oa_tail_ptr,
434 stream->oa_buffer.tail = 0;
436 spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
439 memset(stream->oa_buffer.vaddr, 0, xe_bo_size(stream->oa_buffer.bo));
449 static u32 __oa_ccs_select(struct xe_oa_stream *stream)
453 if (stream->hwe->class != XE_ENGINE_CLASS_COMPUTE)
456 val = REG_FIELD_PREP(OAG_OACONTROL_OA_CCS_SELECT_MASK, stream->hwe->instance);
457 xe_assert(stream->oa->xe,
458 REG_FIELD_GET(OAG_OACONTROL_OA_CCS_SELECT_MASK, val) == stream->hwe->instance);
462 static u32 __oactrl_used_bits(struct xe_oa_stream *stream)
464 return stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG ?
468 static void xe_oa_enable(struct xe_oa_stream *stream)
470 const struct xe_oa_format *format = stream->oa_buffer.format;
475 * BSpec: 46822: Bit 0. Even if stream->sample is 0, for OAR to function, the OA
478 xe_oa_init_oa_buffer(stream);
480 regs = __oa_regs(stream);
482 __oa_ccs_select(stream) | OAG_OACONTROL_OA_COUNTER_ENABLE;
484 if (GRAPHICS_VER(stream->oa->xe) >= 20 &&
485 stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG)
488 xe_mmio_rmw32(&stream->gt->mmio, regs->oa_ctrl, __oactrl_used_bits(stream), val);
491 static void xe_oa_disable(struct xe_oa_stream *stream)
493 struct xe_mmio *mmio = &stream->gt->mmio;
495 xe_mmio_rmw32(mmio, __oa_regs(stream)->oa_ctrl, __oactrl_used_bits(stream), 0);
496 if (xe_mmio_wait32(mmio, __oa_regs(stream)->oa_ctrl,
498 drm_err(&stream->oa->xe->drm,
501 if (GRAPHICS_VERx100(stream->oa->xe) <= 1270 && GRAPHICS_VERx100(stream->oa->xe) != 1260) {
505 drm_err(&stream->oa->xe->drm,
510 static int xe_oa_wait_unlocked(struct xe_oa_stream *stream)
513 if (!stream->periodic)
516 return wait_event_interruptible(stream->poll_wq,
517 xe_oa_buffer_check_unlocked(stream));
523 static int __xe_oa_read(struct xe_oa_stream *stream, char __user *buf,
527 stream->oa_status = xe_mmio_rmw32(&stream->gt->mmio, __oa_regs(stream)->oa_status,
531 * @DRM_XE_OBSERVATION_IOCTL_STATUS observation stream fd ioctl
533 if (stream->oa_status & OASTATUS_RELEVANT_BITS)
536 return xe_oa_append_reports(stream, buf, count, offset);
542 struct xe_oa_stream *stream = file->private_data;
547 if (!stream->enabled || !stream->sample)
552 ret = xe_oa_wait_unlocked(stream);
556 mutex_lock(&stream->stream_lock);
557 ret = __xe_oa_read(stream, buf, count, &offset);
558 mutex_unlock(&stream->stream_lock);
561 xe_oa_buffer_check_unlocked(stream);
562 mutex_lock(&stream->stream_lock);
563 ret = __xe_oa_read(stream, buf, count, &offset);
564 mutex_unlock(&stream->stream_lock);
577 stream->pollin = false;
583 static __poll_t xe_oa_poll_locked(struct xe_oa_stream *stream,
588 poll_wait(file, &stream->poll_wq, wait);
596 if (stream->pollin)
604 struct xe_oa_stream *stream = file->private_data;
607 mutex_lock(&stream->stream_lock);
608 ret = xe_oa_poll_locked(stream, file, wait);
609 mutex_unlock(&stream->stream_lock);
630 static struct dma_fence *xe_oa_submit_bb(struct xe_oa_stream *stream, enum xe_oa_submit_deps deps,
633 struct xe_exec_queue *q = stream->exec_q ?: stream->k_exec_q;
648 for (int i = 0; i < stream->num_syncs && !err; i++)
649 err = xe_sync_entry_add_deps(&stream->syncs[i], job);
651 drm_dbg(&stream->oa->xe->drm, "xe_sync_entry_add_deps err %d\n", err);
700 static void xe_oa_free_oa_buffer(struct xe_oa_stream *stream)
702 xe_bo_unpin_map_no_vm(stream->oa_buffer.bo);
705 static void xe_oa_free_configs(struct xe_oa_stream *stream)
709 xe_oa_config_put(stream->oa_config);
710 llist_for_each_entry_safe(oa_bo, tmp, stream->oa_config_bos.first, node)
711 free_oa_config_bo(oa_bo, stream->last_fence);
712 dma_fence_put(stream->last_fence);
715 static int xe_oa_load_with_lri(struct xe_oa_stream *stream, struct xe_oa_reg *reg_lri, u32 count)
721 bb = xe_bb_new(stream->gt, 2 * count + 1, false);
729 fence = xe_oa_submit_bb(stream, XE_OA_SUBMIT_NO_DEPS, bb);
744 static int xe_oa_configure_oar_context(struct xe_oa_stream *stream, bool enable)
746 const struct xe_oa_format *format = stream->oa_buffer.format;
752 OACTXCONTROL(stream->hwe->mmio_base),
760 RING_CONTEXT_CONTROL(stream->hwe->mmio_base),
766 return xe_oa_load_with_lri(stream, reg_lri, ARRAY_SIZE(reg_lri));
769 static int xe_oa_configure_oac_context(struct xe_oa_stream *stream, bool enable)
771 const struct xe_oa_format *format = stream->oa_buffer.format;
776 OACTXCONTROL(stream->hwe->mmio_base),
784 RING_CONTEXT_CONTROL(stream->hwe->mmio_base),
792 xe_mmio_write32(&stream->gt->mmio, __oa_regs(stream)->oa_ctrl,
793 __oa_ccs_select(stream));
795 return xe_oa_load_with_lri(stream, reg_lri, ARRAY_SIZE(reg_lri));
798 static int xe_oa_configure_oa_context(struct xe_oa_stream *stream, bool enable)
800 switch (stream->hwe->class) {
802 return xe_oa_configure_oar_context(stream, enable);
804 return xe_oa_configure_oac_context(stream, enable);
813 static u32 oag_configure_mmio_trigger(const struct xe_oa_stream *stream, bool enable)
816 enable && stream && stream->sample ?
820 static void xe_oa_disable_metric_set(struct xe_oa_stream *stream)
822 struct xe_mmio *mmio = &stream->gt->mmio;
826 if (XE_GT_WA(stream->gt, 1508761755)) {
827 xe_gt_mcr_multicast_write(stream->gt, ROW_CHICKEN,
829 xe_gt_mcr_multicast_write(stream->gt, ROW_CHICKEN2,
833 xe_mmio_write32(mmio, __oa_regs(stream)->oa_debug,
834 oag_configure_mmio_trigger(stream, false));
837 if (stream->exec_q)
838 xe_oa_configure_oa_context(stream, false);
841 if (GT_VER(stream->gt) < 35)
845 (HAS_OA_BPC_REPORTING(stream->oa->xe) ? SQCNT1_OABPC : 0);
850 if ((stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAM ||
851 stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAM_SAG) &&
852 GRAPHICS_VER(stream->oa->xe) >= 30)
856 static void xe_oa_stream_destroy(struct xe_oa_stream *stream)
858 struct xe_oa_unit *u = stream->oa_unit;
859 struct xe_gt *gt = stream->hwe->gt;
861 if (WARN_ON(stream != u->exclusive_stream))
866 mutex_destroy(&stream->stream_lock);
868 xe_oa_disable_metric_set(stream);
869 xe_exec_queue_put(stream->k_exec_q);
871 xe_oa_free_oa_buffer(stream);
873 xe_force_wake_put(gt_to_fw(gt), stream->fw_ref);
874 xe_pm_runtime_put(stream->oa->xe);
877 if (stream->override_gucrc)
880 xe_oa_free_configs(stream);
881 xe_file_put(stream->xef);
884 static int xe_oa_alloc_oa_buffer(struct xe_oa_stream *stream, size_t size)
888 bo = xe_bo_create_pin_map_novm(stream->oa->xe, stream->gt->tile,
894 stream->oa_buffer.bo = bo;
896 xe_assert(stream->oa->xe, bo->vmap.is_iomem == 0);
897 stream->oa_buffer.vaddr = bo->vmap.vaddr;
902 __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oa_config)
915 bb = xe_bb_new(stream->gt, config_length, false);
923 llist_add(&oa_bo->node, &stream->oa_config_bos);
932 xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oa_config)
936 /* Look for the buffer in the already allocated BOs attached to the stream */
937 llist_for_each_entry(oa_bo, stream->oa_config_bos.first, node) {
944 oa_bo = __xe_oa_alloc_config_buffer(stream, oa_config);
949 static void xe_oa_update_last_fence(struct xe_oa_stream *stream, struct dma_fence *fence)
951 dma_fence_put(stream->last_fence);
952 stream->last_fence = dma_fence_get(fence);
992 static int xe_oa_emit_oa_config(struct xe_oa_stream *stream, struct xe_oa_config *config)
1006 oa_bo = xe_oa_alloc_config_buffer(stream, config);
1013 fence = xe_oa_submit_bb(stream, XE_OA_SUBMIT_ADD_DEPS, oa_bo->bb);
1023 for (i = 0; i < stream->num_syncs; i++) {
1024 if (stream->syncs[i].flags & DRM_XE_SYNC_FLAG_SIGNAL)
1026 xe_sync_entry_signal(&stream->syncs[i], &ofence->base);
1034 xe_oa_update_last_fence(stream, fence);
1038 xe_gt_assert(stream->gt, !err || err == -ENOENT);
1049 for (i = 0; i < stream->num_syncs; i++)
1050 xe_sync_entry_cleanup(&stream->syncs[i]);
1051 kfree(stream->syncs);
1059 static u32 oag_report_ctx_switches(const struct xe_oa_stream *stream)
1063 stream->sample ?
1067 static u32 oag_buf_size_select(const struct xe_oa_stream *stream)
1070 xe_bo_size(stream->oa_buffer.bo) > SZ_16M ?
1074 static int xe_oa_enable_metric_set(struct xe_oa_stream *stream)
1076 struct xe_mmio *mmio = &stream->gt->mmio;
1084 if (XE_GT_WA(stream->gt, 1508761755)) {
1085 xe_gt_mcr_multicast_write(stream->gt, ROW_CHICKEN,
1087 xe_gt_mcr_multicast_write(stream->gt, ROW_CHICKEN2,
1095 if (GRAPHICS_VER(stream->oa->xe) >= 20)
1102 xe_mmio_write32(mmio, __oa_regs(stream)->oa_debug,
1104 oag_report_ctx_switches(stream) |
1105 oag_buf_size_select(stream) |
1106 oag_configure_mmio_trigger(stream, true));
1108 xe_mmio_write32(mmio, __oa_regs(stream)->oa_ctx_ctrl,
1110 (stream->periodic ?
1113 stream->period_exponent) : 0));
1121 (HAS_OA_BPC_REPORTING(stream->oa->xe) ? SQCNT1_OABPC : 0);
1124 if ((stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAM ||
1125 stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAM_SAG) &&
1126 GRAPHICS_VER(stream->oa->xe) >= 30)
1130 if (stream->exec_q) {
1131 ret = xe_oa_configure_oa_context(stream, true);
1136 return xe_oa_emit_oa_config(stream, stream->oa_config);
1399 struct xe_oa_stream *stream,
1421 stream->ufence_syncobj,
1422 ++stream->ufence_timeline_value, 0);
1445 static void xe_oa_stream_enable(struct xe_oa_stream *stream)
1447 stream->pollin = false;
1449 xe_oa_enable(stream);
1451 if (stream->sample)
1452 hrtimer_start(&stream->poll_check_timer,
1453 ns_to_ktime(stream->poll_period_ns),
1457 static void xe_oa_stream_disable(struct xe_oa_stream *stream)
1459 xe_oa_disable(stream);
1461 if (stream->sample)
1462 hrtimer_cancel(&stream->poll_check_timer);
1465 static int xe_oa_enable_preempt_timeslice(struct xe_oa_stream *stream)
1467 struct xe_exec_queue *q = stream->exec_q;
1471 ret1 = q->ops->set_timeslice(q, stream->hwe->eclass->sched_props.timeslice_us);
1472 ret2 = q->ops->set_preempt_timeout(q, stream->hwe->eclass->sched_props.preempt_timeout_us);
1477 drm_dbg(&stream->oa->xe->drm, "%s failed ret1 %d ret2 %d\n", __func__, ret1, ret2);
1481 static int xe_oa_disable_preempt_timeslice(struct xe_oa_stream *stream)
1483 struct xe_exec_queue *q = stream->exec_q;
1497 xe_oa_enable_preempt_timeslice(stream);
1498 drm_dbg(&stream->oa->xe->drm, "%s failed %d\n", __func__, ret);
1502 static int xe_oa_enable_locked(struct xe_oa_stream *stream)
1504 if (stream->enabled)
1507 if (stream->no_preempt) {
1508 int ret = xe_oa_disable_preempt_timeslice(stream);
1514 xe_oa_stream_enable(stream);
1516 stream->enabled = true;
1520 static int xe_oa_disable_locked(struct xe_oa_stream *stream)
1524 if (!stream->enabled)
1527 xe_oa_stream_disable(stream);
1529 if (stream->no_preempt)
1530 ret = xe_oa_enable_preempt_timeslice(stream);
1532 stream->enabled = false;
1536 static long xe_oa_config_locked(struct xe_oa_stream *stream, u64 arg)
1539 long ret = stream->oa_config->id;
1543 err = xe_oa_user_extensions(stream->oa, XE_OA_USER_EXTN_FROM_CONFIG, arg, 0, &param);
1547 config = xe_oa_get_oa_config(stream->oa, param.metric_set);
1551 param.xef = stream->xef;
1552 err = xe_oa_parse_syncs(stream->oa, stream, &param);
1556 stream->num_syncs = param.num_syncs;
1557 stream->syncs = param.syncs;
1559 err = xe_oa_emit_oa_config(stream, config);
1561 config = xchg(&stream->oa_config, config);
1562 drm_dbg(&stream->oa->xe->drm, "changed to oa config uuid=%s\n",
1563 stream->oa_config->uuid);
1572 static long xe_oa_status_locked(struct xe_oa_stream *stream, unsigned long arg)
1578 if (stream->oa_status & OASTATUS_REPORT_LOST)
1580 if (stream->oa_status & OASTATUS_BUFFER_OVERFLOW)
1582 if (stream->oa_status & OASTATUS_COUNTER_OVERFLOW)
1584 if (stream->oa_status & OASTATUS_MMIO_TRG_Q_FULL)
1593 static long xe_oa_info_locked(struct xe_oa_stream *stream, unsigned long arg)
1595 struct drm_xe_oa_stream_info info = { .oa_buf_size = xe_bo_size(stream->oa_buffer.bo), };
1604 static long xe_oa_ioctl_locked(struct xe_oa_stream *stream,
1610 return xe_oa_enable_locked(stream);
1612 return xe_oa_disable_locked(stream);
1614 return xe_oa_config_locked(stream, arg);
1616 return xe_oa_status_locked(stream, arg);
1618 return xe_oa_info_locked(stream, arg);
1628 struct xe_oa_stream *stream = file->private_data;
1631 mutex_lock(&stream->stream_lock);
1632 ret = xe_oa_ioctl_locked(stream, cmd, arg);
1633 mutex_unlock(&stream->stream_lock);
1638 static void xe_oa_destroy_locked(struct xe_oa_stream *stream)
1640 if (stream->enabled)
1641 xe_oa_disable_locked(stream);
1643 xe_oa_stream_destroy(stream);
1645 if (stream->exec_q)
1646 xe_exec_queue_put(stream->exec_q);
1648 drm_syncobj_put(stream->ufence_syncobj);
1649 kfree(stream);
1654 struct xe_oa_stream *stream = file->private_data;
1655 struct xe_gt *gt = stream->gt;
1659 xe_oa_destroy_locked(stream);
1663 /* Release the reference the OA stream kept on the driver */
1671 struct xe_oa_stream *stream = file->private_data;
1672 struct xe_bo *bo = stream->oa_buffer.bo;
1677 drm_dbg(&stream->oa->xe->drm, "Insufficient privilege to map OA buffer\n");
1682 if (vma->vm_end - vma->vm_start != xe_bo_size(stream->oa_buffer.bo)) {
1683 drm_dbg(&stream->oa->xe->drm, "Wrong mmap size, must be OA buffer size\n");
1692 drm_dbg(&stream->oa->xe->drm, "mmap must be read only\n");
1698 xe_assert(stream->oa->xe, bo->ttm.ttm->num_pages == vma_pages(vma));
1720 static int xe_oa_stream_init(struct xe_oa_stream *stream,
1726 stream->exec_q = param->exec_q;
1727 stream->poll_period_ns = DEFAULT_POLL_PERIOD_NS;
1728 stream->oa_unit = param->oa_unit;
1729 stream->hwe = param->hwe;
1730 stream->gt = stream->hwe->gt;
1731 stream->oa_buffer.format = &stream->oa->oa_formats[param->oa_format];
1733 stream->sample = param->sample;
1734 stream->periodic = param->period_exponent >= 0;
1735 stream->period_exponent = param->period_exponent;
1736 stream->no_preempt = param->no_preempt;
1737 stream->wait_num_reports = param->wait_num_reports;
1739 stream->xef = xe_file_get(param->xef);
1740 stream->num_syncs = param->num_syncs;
1741 stream->syncs = param->syncs;
1748 if (GRAPHICS_VER(stream->oa->xe) >= 20 &&
1749 stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG && stream->sample)
1750 stream->oa_buffer.circ_size =
1752 param->oa_buffer_size % stream->oa_buffer.format->size;
1754 stream->oa_buffer.circ_size = param->oa_buffer_size;
1756 stream->oa_config = xe_oa_get_oa_config(stream->oa, param->metric_set);
1757 if (!stream->oa_config) {
1758 drm_dbg(&stream->oa->xe->drm, "Invalid OA config id=%i\n", param->metric_set);
1767 if (XE_GT_WA(stream->gt, 1509372804)) {
1773 stream->override_gucrc = true;
1777 xe_pm_runtime_get(stream->oa->xe);
1778 stream->fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
1779 if (!xe_force_wake_ref_has_domain(stream->fw_ref, XE_FORCEWAKE_ALL)) {
1784 ret = xe_oa_alloc_oa_buffer(stream, param->oa_buffer_size);
1788 stream->k_exec_q = xe_exec_queue_create(stream->oa->xe, NULL,
1789 BIT(stream->hwe->logical_instance), 1,
1790 stream->hwe, EXEC_QUEUE_FLAG_KERNEL, 0);
1791 if (IS_ERR(stream->k_exec_q)) {
1792 ret = PTR_ERR(stream->k_exec_q);
1793 drm_err(&stream->oa->xe->drm, "gt%d, hwe %s, xe_exec_queue_create failed=%d",
1794 stream->gt->info.id, stream->hwe->name, ret);
1798 ret = xe_oa_enable_metric_set(stream);
1800 drm_dbg(&stream->oa->xe->drm, "Unable to enable metric set\n");
1804 drm_dbg(&stream->oa->xe->drm, "opening stream oa config uuid=%s\n",
1805 stream->oa_config->uuid);
1807 WRITE_ONCE(stream->oa_unit->exclusive_stream, stream);
1809 hrtimer_setup(&stream->poll_check_timer, xe_oa_poll_check_timer_cb, CLOCK_MONOTONIC,
1811 init_waitqueue_head(&stream->poll_wq);
1813 spin_lock_init(&stream->oa_buffer.ptr_lock);
1814 mutex_init(&stream->stream_lock);
1819 xe_oa_disable_metric_set(stream);
1820 xe_exec_queue_put(stream->k_exec_q);
1822 xe_oa_free_oa_buffer(stream);
1824 xe_force_wake_put(gt_to_fw(gt), stream->fw_ref);
1825 xe_pm_runtime_put(stream->oa->xe);
1826 if (stream->override_gucrc)
1829 xe_oa_free_configs(stream);
1831 xe_file_put(stream->xef);
1838 struct xe_oa_stream *stream;
1855 stream = kzalloc_obj(*stream);
1856 if (!stream) {
1860 stream->ufence_syncobj = ufence_syncobj;
1861 stream->oa = oa;
1863 ret = xe_oa_parse_syncs(oa, stream, param);
1867 ret = xe_oa_stream_init(stream, param);
1876 ret = xe_oa_enable_locked(stream);
1881 stream_fd = anon_inode_getfd("[xe_oa]", &xe_oa_fops, stream, 0);
1888 drm_dev_get(&stream->oa->xe->drm);
1893 xe_oa_disable_locked(stream);
1895 xe_oa_stream_destroy(stream);
1897 kfree(stream);
1963 /* A hwe must be assigned to stream/oa_unit for batch submissions */
2005 * xe_oa_stream_open_ioctl - Opens an OA stream
2010 * The functions opens an OA stream. An OA stream, opened with specified
2054 * without global stream access, can be an unprivileged operation
2069 drm_dbg(&oa->xe->drm, "Insufficient privileges to open xe OA stream\n");
2333 * OA stream.
2663 /* Ensure MMIO trigger remains disabled till there is a stream */