drivers/accel/habanalabs/common/security.c

Source file repositories/reference/linux-study-clean/drivers/accel/habanalabs/common/security.c

File Facts

System
Linux kernel
Corpus path
drivers/accel/habanalabs/common/security.c
Extension
.c
Size
23117 bytes
Lines
785
Domain
Driver Families
Bucket
drivers/accel
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (cause) {
			addr = RREG32(block_base + HL_BLOCK_GLBL_ERR_ADDR);
			hdev->asic_funcs->pb_print_security_errors(hdev,
					block_base, cause, addr);
			WREG32(block_base + HL_BLOCK_GLBL_ERR_CAUSE, cause);
		}
	}
}

/**
 * hl_config_glbl_sec - set pb in HW according to given pb array
 *
 * @hdev: pointer to hl_device structure
 * @pb_blocks: blocks array
 * @sgs_array: pb array
 * @block_offset: additional offset to the block
 * @array_size: blocks array size
 *
 */
void hl_config_glbl_sec(struct hl_device *hdev, const u32 pb_blocks[],
		struct hl_block_glbl_sec sgs_array[], u32 block_offset,
		int array_size)
{
	int i, j;
	u32 sgs_base;

	if (hdev->pldm)
		usleep_range(100, 1000);

	for (i = 0 ; i < array_size ; i++) {
		sgs_base = block_offset + pb_blocks[i] +
				HL_BLOCK_GLBL_SEC_OFFS;

		for (j = 0 ; j < HL_BLOCK_GLBL_SEC_LEN ; j++)
			WREG32(sgs_base + j * sizeof(u32),
				sgs_array[i].sec_array[j]);
	}
}

/**
 * hl_secure_block - locally memsets a block to 0
 *
 * @hdev: pointer to hl_device structure
 * @sgs_array: pb array to clear
 * @array_size: blocks array size
 *
 */
void hl_secure_block(struct hl_device *hdev,
		struct hl_block_glbl_sec sgs_array[], int array_size)
{
	int i;

	for (i = 0 ; i < array_size ; i++)
		memset((char *)(sgs_array[i].sec_array), 0,
			HL_BLOCK_GLBL_SEC_SIZE);
}

/**
 * hl_init_pb_with_mask - set selected pb instances with mask in HW according
 *                        to given configuration
 *
 * @hdev: pointer to hl_device structure
 * @num_dcores: number of decores to apply configuration to
 *              set to HL_PB_SHARED if need to apply only once
 * @dcore_offset: offset between dcores
 * @num_instances: number of instances to apply configuration to
 * @instance_offset: offset between instances
 * @pb_blocks: blocks array
 * @blocks_array_size: blocks array size
 * @user_regs_array: unsecured register array
 * @user_regs_array_size: unsecured register array size
 * @mask: enabled instances mask: 1- enabled, 0- disabled
 */
int hl_init_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
		u32 dcore_offset, u32 num_instances, u32 instance_offset,
		const u32 pb_blocks[], u32 blocks_array_size,
		const u32 *user_regs_array, u32 user_regs_array_size, u64 mask)
{
	int i, j;
	struct hl_block_glbl_sec *glbl_sec;

	glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
	if (!glbl_sec)
		return -ENOMEM;

	hl_secure_block(hdev, glbl_sec, blocks_array_size);
	hl_unsecure_registers(hdev, user_regs_array, user_regs_array_size, 0,
			pb_blocks, glbl_sec, blocks_array_size);

	/* Fill all blocks with the same configuration */

Annotation

Implementation Notes