drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
Extension
.c
Size
10699 bytes
Lines
395
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 ta_load_debugfs_fops = {
	.write  = ta_if_load_debugfs_write,
	.llseek = default_llseek,
	.owner  = THIS_MODULE
};

static const struct file_operations ta_unload_debugfs_fops = {
	.write  = ta_if_unload_debugfs_write,
	.llseek = default_llseek,
	.owner  = THIS_MODULE
};

static const struct file_operations ta_invoke_debugfs_fops = {
	.write  = ta_if_invoke_debugfs_write,
	.llseek = default_llseek,
	.owner  = THIS_MODULE
};

/*
 * DOC: AMDGPU TA debugfs interfaces
 *
 * Three debugfs interfaces can be opened by a program to
 * load/invoke/unload TA,
 *
 * - /sys/kernel/debug/dri/<N>/ta_if/ta_load
 * - /sys/kernel/debug/dri/<N>/ta_if/ta_invoke
 * - /sys/kernel/debug/dri/<N>/ta_if/ta_unload
 *
 * How to use the interfaces in a program?
 *
 * A program needs to provide transmit buffer to the interfaces
 * and will receive buffer from the interfaces below,
 *
 * - For TA load debugfs interface:
 *   Transmit buffer:
 *    - TA type (4bytes)
 *    - TA bin length (4bytes)
 *    - TA bin
 *   Receive buffer:
 *    - TA ID (4bytes)
 *
 * - For TA invoke debugfs interface:
 *   Transmit buffer:
 *    - TA type (4bytes)
 *    - TA ID (4bytes)
 *    - TA CMD ID (4bytes)
 *    - TA shard buf length
 *      (4bytes, value not beyond TA shared memory size)
 *    - TA shared buf
 *   Receive buffer:
 *    - TA shared buf
 *
 * - For TA unload debugfs interface:
 *   Transmit buffer:
 *    - TA type (4bytes)
 *    - TA ID (4bytes)
 */

static ssize_t ta_if_load_debugfs_write(struct file *fp, const char *buf, size_t len, loff_t *off)
{
	uint32_t ta_type    = 0;
	uint32_t ta_bin_len = 0;
	uint8_t  *ta_bin    = NULL;
	uint32_t copy_pos   = 0;
	int      ret        = 0;

	struct amdgpu_device *adev    = (struct amdgpu_device *)file_inode(fp)->i_private;
	struct psp_context   *psp     = &adev->psp;
	struct ta_context    *context = NULL;

	if (!buf)
		return -EINVAL;

	ret = copy_from_user((void *)&ta_type, &buf[copy_pos], sizeof(uint32_t));
	if (ret || (!is_ta_type_valid(ta_type)))
		return -EFAULT;

	copy_pos += sizeof(uint32_t);

	ret = copy_from_user((void *)&ta_bin_len, &buf[copy_pos], sizeof(uint32_t));
	if (ret)
		return -EFAULT;

	if (ta_bin_len > PSP_1_MEG)
		return -EINVAL;

	copy_pos += sizeof(uint32_t);

	ta_bin = memdup_user(&buf[copy_pos], ta_bin_len);
	if (IS_ERR(ta_bin))

Annotation

Implementation Notes