drivers/gpu/drm/xe/xe_oa.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_oa.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/xe/xe_oa.c- Extension
.c- Size
- 79896 bytes
- Lines
- 2868
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/anon_inodes.hlinux/delay.hlinux/nospec.hlinux/poll.hdrm/drm_drv.hdrm/drm_gem.hdrm/drm_managed.hdrm/drm_syncobj.huapi/drm/xe_drm.hgenerated/xe_wa_oob.hgenerated/xe_device_wa_oob.habi/guc_actions_slpc_abi.hinstructions/xe_mi_commands.hregs/xe_engine_regs.hregs/xe_gt_regs.hregs/xe_oa_regs.hxe_assert.hxe_bb.hxe_bo.hxe_device.hxe_exec_queue.hxe_force_wake.hxe_gt.hxe_gt_mcr.hxe_gt_printk.hxe_guc_rc.hxe_macros.hxe_mmio.hxe_oa.hxe_observation.hxe_pm.hxe_sched_job.h
Detected Declarations
struct xe_oa_regstruct xe_oa_configstruct xe_oa_open_paramstruct xe_oa_config_bostruct xe_oa_fenceenum xe_oam_unit_typeenum xe_oa_submit_depsenum xe_oa_user_extn_fromfunction xe_oa_circ_difffunction xe_oa_circ_incrfunction xe_oa_config_releasefunction xe_oa_config_putfunction free_oa_config_bofunction xe_oa_hw_tail_readfunction oa_report_idfunction oa_report_id_clearfunction oa_timestampfunction oa_timestamp_clearfunction mert_wa_14026633728function xe_oa_buffer_check_unlockedfunction xe_oa_poll_check_timer_cbfunction xe_oa_copy_to_userfunction xe_oa_append_reportfunction xe_oa_append_reportsfunction xe_oa_init_oa_bufferfunction __format_to_oactrlfunction __oa_ccs_selectfunction __oactrl_used_bitsfunction xe_oa_enablefunction xe_oa_disablefunction xe_oa_wait_unlockedfunction __xe_oa_readfunction xe_oa_readfunction xe_oa_poll_lockedfunction xe_oa_pollfunction xe_oa_lock_vmafunction xe_oa_unlock_vmafunction write_cs_mi_lrifunction num_lri_dwordsfunction xe_oa_free_oa_bufferfunction xe_oa_free_configsfunction xe_oa_load_with_lrifunction xe_oa_configure_oar_contextfunction xe_oa_configure_oac_contextfunction xe_oa_configure_oa_contextfunction oag_configure_mmio_triggerfunction xe_oa_disable_metric_setfunction xe_oa_stream_destroy
Annotated Snippet
static const struct file_operations xe_oa_fops = {
.owner = THIS_MODULE,
.release = xe_oa_release,
.poll = xe_oa_poll,
.read = xe_oa_read,
.unlocked_ioctl = xe_oa_ioctl,
.mmap = xe_oa_mmap,
};
static int xe_oa_stream_init(struct xe_oa_stream *stream,
struct xe_oa_open_param *param)
{
struct xe_gt *gt = param->hwe->gt;
int ret;
stream->exec_q = param->exec_q;
stream->poll_period_ns = DEFAULT_POLL_PERIOD_NS;
stream->oa_unit = param->oa_unit;
stream->hwe = param->hwe;
stream->gt = stream->hwe->gt;
stream->oa_buffer.format = &stream->oa->oa_formats[param->oa_format];
stream->sample = param->sample;
stream->periodic = param->period_exponent >= 0;
stream->period_exponent = param->period_exponent;
stream->no_preempt = param->no_preempt;
stream->wait_num_reports = param->wait_num_reports;
stream->xef = xe_file_get(param->xef);
stream->num_syncs = param->num_syncs;
stream->syncs = param->syncs;
/*
* For Xe2+, when overrun mode is enabled, there are no partial reports at the end
* of buffer, making the OA buffer effectively a non-power-of-2 size circular
* buffer whose size, circ_size, is a multiple of the report size
*/
if (GRAPHICS_VER(stream->oa->xe) >= 20 &&
stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG && stream->sample)
stream->oa_buffer.circ_size =
param->oa_buffer_size -
param->oa_buffer_size % stream->oa_buffer.format->size;
else
stream->oa_buffer.circ_size = param->oa_buffer_size;
stream->oa_config = xe_oa_get_oa_config(stream->oa, param->metric_set);
if (!stream->oa_config) {
drm_dbg(&stream->oa->xe->drm, "Invalid OA config id=%i\n", param->metric_set);
ret = -EINVAL;
goto exit;
}
/* Take runtime pm ref and forcewake to disable RC6 */
xe_pm_runtime_get(stream->oa->xe);
stream->fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
if (!xe_force_wake_ref_has_domain(stream->fw_ref, XE_FORCEWAKE_ALL)) {
ret = -ETIMEDOUT;
goto err_fw_put;
}
ret = xe_oa_alloc_oa_buffer(stream, param->oa_buffer_size);
if (ret)
goto err_fw_put;
stream->k_exec_q = xe_exec_queue_create(stream->oa->xe, NULL,
BIT(stream->hwe->logical_instance), 1,
stream->hwe, EXEC_QUEUE_FLAG_KERNEL, 0);
if (IS_ERR(stream->k_exec_q)) {
ret = PTR_ERR(stream->k_exec_q);
drm_err(&stream->oa->xe->drm, "gt%d, hwe %s, xe_exec_queue_create failed=%d",
stream->gt->info.id, stream->hwe->name, ret);
goto err_free_oa_buf;
}
ret = xe_oa_enable_metric_set(stream);
if (ret) {
drm_dbg(&stream->oa->xe->drm, "Unable to enable metric set\n");
goto err_put_k_exec_q;
}
drm_dbg(&stream->oa->xe->drm, "opening stream oa config uuid=%s\n",
stream->oa_config->uuid);
WRITE_ONCE(stream->oa_unit->exclusive_stream, stream);
hrtimer_setup(&stream->poll_check_timer, xe_oa_poll_check_timer_cb, CLOCK_MONOTONIC,
HRTIMER_MODE_REL);
init_waitqueue_head(&stream->poll_wq);
spin_lock_init(&stream->oa_buffer.ptr_lock);
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/delay.h`, `linux/nospec.h`, `linux/poll.h`, `drm/drm_drv.h`, `drm/drm_gem.h`, `drm/drm_managed.h`, `drm/drm_syncobj.h`.
- Detected declarations: `struct xe_oa_reg`, `struct xe_oa_config`, `struct xe_oa_open_param`, `struct xe_oa_config_bo`, `struct xe_oa_fence`, `enum xe_oam_unit_type`, `enum xe_oa_submit_deps`, `enum xe_oa_user_extn_from`, `function xe_oa_circ_diff`, `function xe_oa_circ_incr`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.