drivers/gpu/drm/xe/xe_guc_hwconfig.c

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/xe_guc_hwconfig.c
Extension
.c
Size
4378 bytes
Lines
203
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 (i + len_dw > num_dw) {
			drm_printf(p, "Error: Attribute %u is %u dwords, but only %llu remain\n",
				   attribute, len_dw, num_dw - i);
			len_dw = num_dw - i;
		}

		/*
		 * If it's a single dword (as most hwconfig attributes are),
		 * then it's probably a number that makes sense to display
		 * in decimal form.  In the rare cases where it's more than
		 * one dword, just print it in hex form and let the user
		 * figure out how to interpret it.
		 */
		if (len_dw == 1)
			drm_printf(p, "[%2u] = %u\n", attribute, hwconfig[i]);
		else
			drm_printf(p, "[%2u] = { %*ph }\n", attribute,
				   (int)(len_dw * sizeof(u32)), &hwconfig[i]);
		i += len_dw;
	}

	if (i < num_dw || extra_bytes)
		drm_printf(p, "Error: %llu extra bytes at end of hwconfig\n",
			   (num_dw - i) * sizeof(u32) + extra_bytes);

	kfree(hwconfig);
}

/*
 * Lookup a specific 32-bit attribute value in the GuC's hwconfig table.
 */
int xe_guc_hwconfig_lookup_u32(struct xe_guc *guc, u32 attribute, u32 *val)
{
	size_t size = xe_guc_hwconfig_size(guc);
	u64 num_dw = div_u64(size, sizeof(u32));
	u32 *hwconfig;
	bool found = false;
	int i = 0;

	if (num_dw == 0)
		return -EINVAL;

	hwconfig = kzalloc(size, GFP_KERNEL);
	if (!hwconfig)
		return -ENOMEM;

	xe_guc_hwconfig_copy(guc, hwconfig);

	/* An entry requires at least three dwords for key, length, value */
	while (i + 3 <= num_dw) {
		u32 key = hwconfig[i++];
		u32 len_dw = hwconfig[i++];

		if (key != attribute) {
			i += len_dw;
			continue;
		}

		*val = hwconfig[i];
		found = true;
		break;
	}

	kfree(hwconfig);

	return found ? 0 : -ENOENT;
}

Annotation

Implementation Notes