drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c- Extension
.c- Size
- 16788 bytes
- Lines
- 640
- 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.
- 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
amdgpu_ids.hlinux/xarray.hlinux/dma-fence-array.hamdgpu.hamdgpu_trace.h
Detected Declarations
struct amdgpu_pasid_cbfunction amdgpu_pasid_allocfunction amdgpu_pasid_freefunction amdgpu_pasid_free_cbfunction amdgpu_pasid_free_delayedfunction amdgpu_vmid_had_gpu_resetfunction amdgpu_vmid_gds_switch_neededfunction amdgpu_vmid_compatiblefunction amdgpu_vmid_grab_idlefunction amdgpu_vmid_grab_reservedfunction amdgpu_vmid_grab_usedfunction amdgpu_vmid_grabfunction amdgpu_vmid_uses_reservedfunction amdgpu_vmid_alloc_reservedfunction amdgpu_vmid_free_reservedfunction amdgpu_vmid_resetfunction amdgpu_vmid_reset_allfunction amdgpu_vmid_mgr_initfunction amdgpu_vmid_mgr_finifunction amdgpu_pasid_mgr_cleanup
Annotated Snippet
struct amdgpu_pasid_cb {
struct dma_fence_cb cb;
u32 pasid;
};
/**
* amdgpu_pasid_alloc - Allocate a PASID
* @bits: Maximum width of the PASID in bits, must be at least 1
*
* Uses kernel's IDR cyclic allocator (same as PID allocation).
* Allocates sequentially with automatic wrap-around.
*
* Returns a positive integer on success. Returns %-EINVAL if bits==0.
* Returns %-ENOSPC if no PASID was available. Returns %-ENOMEM on
* memory allocation failure.
*/
int amdgpu_pasid_alloc(unsigned int bits)
{
u32 pasid;
int r;
if (bits == 0)
return -EINVAL;
r = xa_alloc_cyclic_irq(&amdgpu_pasid_xa, &pasid, xa_mk_value(0),
XA_LIMIT(1, (1U << bits) - 1),
&amdgpu_pasid_xa_next, GFP_KERNEL);
if (r < 0)
return r;
trace_amdgpu_pasid_allocated(pasid);
return pasid;
}
/**
* amdgpu_pasid_free - Free a PASID
* @pasid: PASID to free
*
* Called in IRQ context.
*/
void amdgpu_pasid_free(u32 pasid)
{
unsigned long flags;
trace_amdgpu_pasid_freed(pasid);
xa_lock_irqsave(&amdgpu_pasid_xa, flags);
__xa_erase(&amdgpu_pasid_xa, pasid);
xa_unlock_irqrestore(&amdgpu_pasid_xa, flags);
}
static void amdgpu_pasid_free_cb(struct dma_fence *fence,
struct dma_fence_cb *_cb)
{
struct amdgpu_pasid_cb *cb =
container_of(_cb, struct amdgpu_pasid_cb, cb);
amdgpu_pasid_free(cb->pasid);
dma_fence_put(fence);
kfree(cb);
}
/**
* amdgpu_pasid_free_delayed - free pasid when fences signal
*
* @resv: reservation object with the fences to wait for
* @pasid: pasid to free
*
* Free the pasid only after all the fences in resv are signaled.
*/
void amdgpu_pasid_free_delayed(struct dma_resv *resv,
u32 pasid)
{
struct amdgpu_pasid_cb *cb;
struct dma_fence *fence;
int r;
r = dma_resv_get_singleton(resv, DMA_RESV_USAGE_BOOKKEEP, &fence);
if (r)
goto fallback;
if (!fence) {
amdgpu_pasid_free(pasid);
return;
}
cb = kmalloc_obj(*cb);
if (!cb) {
/* Last resort when we are OOM */
dma_fence_wait(fence, false);
Annotation
- Immediate include surface: `amdgpu_ids.h`, `linux/xarray.h`, `linux/dma-fence-array.h`, `amdgpu.h`, `amdgpu_trace.h`.
- Detected declarations: `struct amdgpu_pasid_cb`, `function amdgpu_pasid_alloc`, `function amdgpu_pasid_free`, `function amdgpu_pasid_free_cb`, `function amdgpu_pasid_free_delayed`, `function amdgpu_vmid_had_gpu_reset`, `function amdgpu_vmid_gds_switch_needed`, `function amdgpu_vmid_compatible`, `function amdgpu_vmid_grab_idle`, `function amdgpu_vmid_grab_reserved`.
- 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.