drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c- Extension
.c- Size
- 27871 bytes
- Lines
- 995
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/seq_file.hlinux/atomic.hlinux/wait.hlinux/kref.hlinux/slab.hlinux/firmware.hlinux/pm_runtime.hdrm/drm_drv.hamdgpu.hamdgpu_trace.hamdgpu_reset.h
Detected Declarations
function memoryfunction memoryfunction ringfunction ringfunction amdgpu_fence_schedule_fallbackfunction amdgpu_fence_processfunction amdgpu_fence_fallbackfunction signalfunction signalfunction ringfunction amdgpu_fence_last_unsignaled_time_usfunction amdgpu_fence_update_start_timestampfunction processingfunction ringfunction ringsfunction amdgpu_fence_need_ring_interrupt_restorefunction ringsfunction amdgpu_fence_driver_isr_togglefunction amdgpu_fence_driver_sw_finifunction ringsfunction amdgpu_fence_driver_set_errorfunction amdgpu_fence_driver_force_completionfunction pointerfunction amdgpu_ring_backup_unprocessed_commandfunction amdgpu_ring_backup_unprocessed_commandsfunction amdgpu_fence_enable_signalingfunction amdgpu_fence_freefunction amdgpu_fence_releasefunction amdgpu_debugfs_fence_info_showfunction gpu_recover_getfunction amdgpu_debugfs_reset_workfunction amdgpu_debugfs_fence_init
Annotated Snippet
if (old) {
/*
* dma_fence_wait(old, false) is not interruptible.
* It will not return an error in this case.
* So we can safely ignore the return value.
*/
dma_fence_wait(old, false);
dma_fence_put(old);
}
}
to_amdgpu_fence(fence)->start_timestamp = ktime_get();
/* This function can't be called concurrently anyway, otherwise
* emitting the fence would mess up the hardware ring buffer.
*/
rcu_assign_pointer(*ptr, dma_fence_get(fence));
}
/**
* amdgpu_fence_emit_polling - emit a fence on the requeste ring
*
* @ring: ring the fence is associated with
* @s: resulting sequence number
* @timeout: the timeout for waiting in usecs
*
* Emits a fence command on the requested ring (all asics).
* Used For polling fence.
* Returns 0 on success, -ENOMEM on failure.
*/
int amdgpu_fence_emit_polling(struct amdgpu_ring *ring, uint32_t *s,
uint32_t timeout)
{
uint32_t seq;
signed long r;
if (!s)
return -EINVAL;
seq = ++ring->fence_drv.sync_seq;
r = amdgpu_fence_wait_polling(ring,
seq - ring->fence_drv.num_fences_mask,
timeout);
if (r < 1)
return -ETIMEDOUT;
amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr,
seq, 0);
*s = seq;
return 0;
}
/**
* amdgpu_fence_schedule_fallback - schedule fallback check
*
* @ring: pointer to struct amdgpu_ring
*
* Start a timer as fallback to our interrupts.
*/
static void amdgpu_fence_schedule_fallback(struct amdgpu_ring *ring)
{
mod_timer(&ring->fence_drv.fallback_timer,
jiffies + AMDGPU_FENCE_JIFFIES_TIMEOUT);
}
/**
* amdgpu_fence_process - check for fence activity
*
* @ring: pointer to struct amdgpu_ring
*
* Checks the current fence value and calculates the last
* signalled fence value. Wakes the fence queue if the
* sequence number has increased.
*
* Returns true if fence was processed
*/
bool amdgpu_fence_process(struct amdgpu_ring *ring)
{
struct amdgpu_fence_driver *drv = &ring->fence_drv;
struct amdgpu_device *adev = ring->adev;
uint32_t seq, last_seq;
do {
last_seq = atomic_read(&ring->fence_drv.last_seq);
seq = amdgpu_fence_read(ring);
} while (atomic_cmpxchg(&drv->last_seq, last_seq, seq) != last_seq);
Annotation
- Immediate include surface: `linux/seq_file.h`, `linux/atomic.h`, `linux/wait.h`, `linux/kref.h`, `linux/slab.h`, `linux/firmware.h`, `linux/pm_runtime.h`, `drm/drm_drv.h`.
- Detected declarations: `function memory`, `function memory`, `function ring`, `function ring`, `function amdgpu_fence_schedule_fallback`, `function amdgpu_fence_process`, `function amdgpu_fence_fallback`, `function signal`, `function signal`, `function ring`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- 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.