drivers/firmware/efi/mokvar-table.c

Source file repositories/reference/linux-study-clean/drivers/firmware/efi/mokvar-table.c

File Facts

System
Linux kernel
Corpus path
drivers/firmware/efi/mokvar-table.c
Extension
.c
Size
10893 bytes
Lines
360
Domain
Driver Families
Bucket
drivers/firmware
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

struct efi_mokvar_sysfs_attr {
	struct bin_attribute bin_attr;
	struct list_head node;
};

static LIST_HEAD(efi_mokvar_sysfs_list);
static struct kobject *mokvar_kobj;

/*
 * efi_mokvar_table_init() - Early boot validation of EFI MOK config table
 *
 * If present, validate and compute the size of the EFI MOK variable
 * configuration table. This table may be provided by an EFI boot loader
 * as an alternative to ordinary EFI variables, due to platform-dependent
 * limitations. The memory occupied by this table is marked as reserved.
 *
 * This routine must be called before efi_unmap_boot_services() in order
 * to guarantee that it can mark the table as reserved.
 *
 * Implicit inputs:
 * efi.mokvar_table:	Physical address of EFI MOK variable config table
 *			or special value that indicates no such table.
 *
 * Implicit outputs:
 * efi_mokvar_table_size: Computed size of EFI MOK variable config table.
 *			The table is considered present and valid if this
 *			is non-zero.
 */
void __init efi_mokvar_table_init(void)
{
	struct efi_mokvar_table_entry __aligned(1) *mokvar_entry, *next_entry;
	efi_memory_desc_t md;
	void *va = NULL;
	unsigned long cur_offset = 0;
	unsigned long offset_limit;
	unsigned long map_size_needed = 0;
	unsigned long size;
	int err;

	if (!efi_enabled(EFI_MEMMAP))
		return;

	if (efi.mokvar_table == EFI_INVALID_TABLE_ADDR)
		return;
	/*
	 * The EFI MOK config table must fit within a single EFI memory
	 * descriptor range.
	 */
	err = efi_mem_desc_lookup(efi.mokvar_table, &md);
	if (err) {
		pr_warn("EFI MOKvar config table is not within the EFI memory map\n");
		return;
	}

	offset_limit = efi_mem_desc_end(&md) - efi.mokvar_table;

	/*
	 * Validate the MOK config table. Since there is no table header
	 * from which we could get the total size of the MOK config table,
	 * we compute the total size as we validate each variably sized
	 * entry, remapping as necessary.
	 */
	err = -EINVAL;
	while (cur_offset + sizeof(*mokvar_entry) <= offset_limit) {
		if (va)
			early_memunmap(va, sizeof(*mokvar_entry));
		va = early_memremap(efi.mokvar_table + cur_offset, sizeof(*mokvar_entry));
		if (!va) {
			pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%zu.\n",
			       efi.mokvar_table + cur_offset, sizeof(*mokvar_entry));
			return;
		}
		mokvar_entry = va;
next:
		/* Check for last sentinel entry */
		if (mokvar_entry->name[0] == '\0') {
			if (mokvar_entry->data_size != 0)
				break;
			err = 0;
			map_size_needed = cur_offset + sizeof(*mokvar_entry);
			break;
		}

		/* Enforce that the name is NUL terminated */
		mokvar_entry->name[sizeof(mokvar_entry->name) - 1] = '\0';

		/* Advance to the next entry */
		size = sizeof(*mokvar_entry) + mokvar_entry->data_size;
		cur_offset += size;

Annotation

Implementation Notes