drivers/gpu/drm/xe/xe_guc_klv_helpers.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_guc_klv_helpers.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/xe_guc_klv_helpers.c
Extension
.c
Size
4373 bytes
Lines
158
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (num_dwords < len) {
			drm_printf(p, "{ key %#06x : truncated %zu of %zu bytes %*ph } # %s\n",
				   key, num_dwords * sizeof(u32), len * sizeof(u32),
				   (int)(num_dwords * sizeof(u32)), klvs,
				   xe_guc_klv_key_to_string(key));
			return;
		}

		switch (len) {
		case 0:
			drm_printf(p, "{ key %#06x : no value } # %s\n",
				   key, xe_guc_klv_key_to_string(key));
			break;
		case 1:
			drm_printf(p, "{ key %#06x : 32b value %u } # %s\n",
				   key, klvs[0], xe_guc_klv_key_to_string(key));
			break;
		case 2:
			drm_printf(p, "{ key %#06x : 64b value %#llx } # %s\n",
				   key, make_u64(klvs[1], klvs[0]),
				   xe_guc_klv_key_to_string(key));
			break;
		default:
			drm_printf(p, "{ key %#06x : %zu bytes %*ph } # %s\n",
				   key, len * sizeof(u32), (int)(len * sizeof(u32)),
				   klvs, xe_guc_klv_key_to_string(key));
			break;
		}

		klvs += len;
		num_dwords -= len;
	}

	/* we don't expect any leftovers, fix if KLV header is ever changed */
	BUILD_BUG_ON(GUC_KLV_LEN_MIN > 1);
}

/**
 * xe_guc_klv_count - Count KLVs present in the buffer.
 * @klvs: the buffer with KLVs
 * @num_dwords: number of dwords (u32) in the buffer
 *
 * Return: number of recognized KLVs or
 *         a negative error code if KLV buffer is truncated.
 */
int xe_guc_klv_count(const u32 *klvs, u32 num_dwords)
{
	int num_klvs = 0;

	while (num_dwords >= GUC_KLV_LEN_MIN) {
		u32 len = FIELD_GET(GUC_KLV_0_LEN, klvs[0]);

		if (num_dwords < len + GUC_KLV_LEN_MIN)
			break;

		klvs += GUC_KLV_LEN_MIN + len;
		num_dwords -= GUC_KLV_LEN_MIN + len;
		num_klvs++;
	}

	return num_dwords ? -ENODATA : num_klvs;
}

Annotation

Implementation Notes