drivers/firmware/efi/libstub/gop.c

Source file repositories/reference/linux-study-clean/drivers/firmware/efi/libstub/gop.c

File Facts

System
Linux kernel
Corpus path
drivers/firmware/efi/libstub/gop.c
Extension
.c
Size
13571 bytes
Lines
533
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 match {
	u32	mode;
	u32	area;
	u8	depth;
};

static bool match_auto(const efi_graphics_output_mode_info_t *info, u32 mode, void *ctx)
{
	u32 area = info->horizontal_resolution * info->vertical_resolution;
	efi_pixel_bitmask_t pi = info->pixel_information;
	int pf = info->pixel_format;
	u8 depth = pixel_bpp(pf, pi);
	struct match *m = ctx;

	if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX)
		return false;

	if (area > m->area || (area == m->area && depth > m->depth))
		*m = (struct match){ mode, area, depth };

	return false;
}

static u32 choose_mode_auto(efi_graphics_output_protocol_t *gop)
{
	struct match match = {};

	choose_mode(gop, match_auto, &match);

	return match.mode;
}

static bool match_list(const efi_graphics_output_mode_info_t *info, u32 mode, void *ctx)
{
	efi_pixel_bitmask_t pi = info->pixel_information;
	u32 cur_mode = (unsigned long)ctx;
	int pf = info->pixel_format;
	const char *dstr;
	u8 depth = 0;
	bool valid;

	valid = !(pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX);

	switch (pf) {
	case PIXEL_RGB_RESERVED_8BIT_PER_COLOR:
		dstr = "rgb";
		break;
	case PIXEL_BGR_RESERVED_8BIT_PER_COLOR:
		dstr = "bgr";
		break;
	case PIXEL_BIT_MASK:
		dstr = "";
		depth = pixel_bpp(pf, pi);
		break;
	case PIXEL_BLT_ONLY:
		dstr = "blt";
		break;
	default:
		dstr = "xxx";
		break;
	}

	efi_printk("Mode %3u %c%c: Resolution %ux%u-%s%.0hhu\n",
		    mode,
		    (mode == cur_mode) ? '*' : ' ',
		    !valid ? '-' : ' ',
		    info->horizontal_resolution,
		    info->vertical_resolution,
		    dstr, depth);

	return false;
}

static u32 choose_mode_list(efi_graphics_output_protocol_t *gop)
{
	efi_graphics_output_protocol_mode_t *mode = efi_table_attr(gop, mode);
	unsigned long cur_mode = efi_table_attr(mode, mode);
	u32 max_mode = efi_table_attr(mode, max_mode);
	efi_input_key_t key;
	efi_status_t status;

	efi_printk("Available graphics modes are 0-%u\n", max_mode-1);
	efi_puts("  * = current mode\n"
		 "  - = unusable mode\n");

	choose_mode(gop, match_list, (void *)cur_mode);

	efi_puts("\nPress any key to continue (or wait 10 seconds)\n");
	status = efi_wait_for_key(10 * EFI_USEC_PER_SEC, &key);
	if (status != EFI_SUCCESS && status != EFI_TIMEOUT) {

Annotation

Implementation Notes