drivers/gpu/drm/amd/amdkfd/kfd_debugfs.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdkfd/kfd_debugfs.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/amd/amdkfd/kfd_debugfs.c
Extension
.c
Size
5274 bytes
Lines
188
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations kfd_debugfs_fops = {
	.owner = THIS_MODULE,
	.open = kfd_debugfs_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
};

static const struct file_operations kfd_debugfs_hang_hws_fops = {
	.owner = THIS_MODULE,
	.open = kfd_debugfs_open,
	.read = seq_read,
	.write = kfd_debugfs_hang_hws_write,
	.llseek = seq_lseek,
	.release = single_release,
};

void kfd_debugfs_init(void)
{
	debugfs_root = debugfs_create_dir("kfd", NULL);
	debugfs_proc = debugfs_create_dir("proc", debugfs_root);
	INIT_LIST_HEAD(&procs);

	debugfs_create_file("mqds", S_IFREG | 0444, debugfs_root,
			    kfd_debugfs_mqds_by_process, &kfd_debugfs_fops);
	debugfs_create_file("hqds", S_IFREG | 0444, debugfs_root,
			    kfd_debugfs_hqds_by_device, &kfd_debugfs_fops);
	debugfs_create_file("rls", S_IFREG | 0444, debugfs_root,
			    kfd_debugfs_rls_by_device, &kfd_debugfs_fops);
	debugfs_create_file("hang_hws", S_IFREG | 0200, debugfs_root,
			    kfd_debugfs_hang_hws_read, &kfd_debugfs_hang_hws_fops);
	debugfs_create_file("mem_limit", S_IFREG | 0200, debugfs_root,
			    kfd_debugfs_kfd_mem_limits, &kfd_debugfs_fops);
}

void kfd_debugfs_fini(void)
{
	debugfs_remove_recursive(debugfs_proc);
	debugfs_remove_recursive(debugfs_root);
}

static ssize_t kfd_debugfs_pasid_read(struct file *file, char __user *buf,
				      size_t count, loff_t *ppos)
{
	struct kfd_process_device *pdd = file_inode(file)->i_private;
	char tmp[32];
	int len;

	len = snprintf(tmp, sizeof(tmp), "%u\n", pdd->pasid);

	return simple_read_from_buffer(buf, count, ppos, tmp, len);
}

static const struct file_operations kfd_debugfs_pasid_fops = {
	.owner = THIS_MODULE,
	.read = kfd_debugfs_pasid_read,
};

void kfd_debugfs_add_process(struct kfd_process *p)
{
	int i;
	char name[MAX_DEBUGFS_FILENAME_LEN];
	struct debugfs_proc_entry *entry;

	entry = kzalloc_obj(*entry);
	if (!entry)
		return;

	list_add(&entry->list, &procs);
	entry->pid = p->lead_thread->pid;
	snprintf(name, MAX_DEBUGFS_FILENAME_LEN, "%d",
		 (int)entry->pid);
	entry->proc_dentry = debugfs_create_dir(name, debugfs_proc);

	/* Create debugfs files for each GPU:
	 * - proc/<pid>/pasid_<gpuid>
	 */
	for (i = 0; i < p->n_pdds; i++) {
		struct kfd_process_device *pdd = p->pdds[i];

		snprintf(name, MAX_DEBUGFS_FILENAME_LEN, "pasid_%u",
			 pdd->dev->id);
		debugfs_create_file((const char *)name, S_IFREG | 0444,
				    entry->proc_dentry, pdd,
				    &kfd_debugfs_pasid_fops);
	}
}

void kfd_debugfs_remove_process(struct kfd_process *p)
{

Annotation

Implementation Notes