drivers/gpu/drm/amd/display/modules/vmid/vmid.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/display/modules/vmid/vmid.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/display/modules/vmid/vmid.c- Extension
.c- Size
- 4702 bytes
- Lines
- 179
- 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.
- 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
mod_vmid.h
Detected Declarations
struct core_vmidfunction container_offunction clear_entry_from_vmid_tablefunction evict_vmidsfunction get_existing_vmid_for_ptbfunction get_next_available_vmidfunction mod_vmid_get_for_ptbfunction mod_vmid_resetfunction mod_vmid_destroy
Annotated Snippet
struct core_vmid {
struct mod_vmid public;
struct dc *dc;
unsigned int num_vmid;
unsigned int num_vmids_available;
uint64_t ptb_assigned_to_vmid[MAX_VMID];
struct dc_virtual_addr_space_config base_config;
};
#define MOD_VMID_TO_CORE(mod_vmid)\
container_of(mod_vmid, struct core_vmid, public)
static void add_ptb_to_table(struct core_vmid *core_vmid, unsigned int vmid, uint64_t ptb)
{
if (vmid < MAX_VMID) {
core_vmid->ptb_assigned_to_vmid[vmid] = ptb;
core_vmid->num_vmids_available--;
}
}
static void clear_entry_from_vmid_table(struct core_vmid *core_vmid, unsigned int vmid)
{
if (vmid < MAX_VMID) {
core_vmid->ptb_assigned_to_vmid[vmid] = 0;
core_vmid->num_vmids_available++;
}
}
static void evict_vmids(struct core_vmid *core_vmid)
{
unsigned int i;
int ord_int = dc_get_vmid_use_vector(core_vmid->dc);
ASSERT(ord_int >= 0 && ord_int <= 0xFFFF);
uint16_t ord = (uint16_t)ord_int;
// At this point any positions with value 0 are unused vmids, evict them
for (i = 1; i < core_vmid->num_vmid; i++) {
if (!(ord & (1u << i)))
clear_entry_from_vmid_table(core_vmid, i);
}
}
// Return value of -1 indicates vmid table uninitialized or ptb dne in the table
static int get_existing_vmid_for_ptb(struct core_vmid *core_vmid, uint64_t ptb)
{
unsigned int i;
for (i = 0; i < core_vmid->num_vmid; i++) {
if (core_vmid->ptb_assigned_to_vmid[i] == ptb)
return i;
}
return -1;
}
// Expected to be called only when there's an available vmid
static int get_next_available_vmid(struct core_vmid *core_vmid)
{
unsigned int i;
for (i = 1; i < core_vmid->num_vmid; i++) {
if (core_vmid->ptb_assigned_to_vmid[i] == 0)
return i;
}
return -1;
}
uint8_t mod_vmid_get_for_ptb(struct mod_vmid *mod_vmid, uint64_t ptb)
{
struct core_vmid *core_vmid = MOD_VMID_TO_CORE(mod_vmid);
int vmid = 0;
// Physical address gets vmid 0
if (ptb == 0)
return 0;
vmid = get_existing_vmid_for_ptb(core_vmid, ptb);
if (vmid == -1) {
struct dc_virtual_addr_space_config va_config = core_vmid->base_config;
va_config.page_table_base_addr = ptb;
if (core_vmid->num_vmids_available == 0)
evict_vmids(core_vmid);
vmid = get_next_available_vmid(core_vmid);
Annotation
- Immediate include surface: `mod_vmid.h`.
- Detected declarations: `struct core_vmid`, `function container_of`, `function clear_entry_from_vmid_table`, `function evict_vmids`, `function get_existing_vmid_for_ptb`, `function get_next_available_vmid`, `function mod_vmid_get_for_ptb`, `function mod_vmid_reset`, `function mod_vmid_destroy`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
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.