xref: /openbmc/u-boot/drivers/pci/pci_rom.c (revision 9649c5343fb1e105109f8aac499134dd4bd723ca)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0
26854f87cSSimon Glass /*
36854f87cSSimon Glass  * Copyright (C) 2014 Google, Inc
46854f87cSSimon Glass  *
56854f87cSSimon Glass  * From coreboot, originally based on the Linux kernel (drivers/pci/pci.c).
66854f87cSSimon Glass  *
76854f87cSSimon Glass  * Modifications are:
86854f87cSSimon Glass  * Copyright (C) 2003-2004 Linux Networx
96854f87cSSimon Glass  * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
106854f87cSSimon Glass  * Copyright (C) 2003-2006 Ronald G. Minnich <rminnich@gmail.com>
116854f87cSSimon Glass  * Copyright (C) 2004-2005 Li-Ta Lo <ollie@lanl.gov>
126854f87cSSimon Glass  * Copyright (C) 2005-2006 Tyan
136854f87cSSimon Glass  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
146854f87cSSimon Glass  * Copyright (C) 2005-2009 coresystems GmbH
156854f87cSSimon Glass  * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
166854f87cSSimon Glass  *
176854f87cSSimon Glass  * PCI Bus Services, see include/linux/pci.h for further explanation.
186854f87cSSimon Glass  *
196854f87cSSimon Glass  * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
206854f87cSSimon Glass  * David Mosberger-Tang
216854f87cSSimon Glass  *
226854f87cSSimon Glass  * Copyright 1997 -- 1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
236854f87cSSimon Glass  */
246854f87cSSimon Glass 
256854f87cSSimon Glass #include <common.h>
266854f87cSSimon Glass #include <bios_emul.h>
273f4e1e8eSSimon Glass #include <dm.h>
286854f87cSSimon Glass #include <errno.h>
296854f87cSSimon Glass #include <malloc.h>
306854f87cSSimon Glass #include <pci.h>
316854f87cSSimon Glass #include <pci_rom.h>
326854f87cSSimon Glass #include <vbe.h>
33ee87ee82SSimon Glass #include <video.h>
346854f87cSSimon Glass #include <video_fb.h>
35a4520022SBin Meng #include <linux/screen_info.h>
366854f87cSSimon Glass 
3768769ebcSBin Meng #ifdef CONFIG_X86
3868769ebcSBin Meng #include <asm/acpi_s3.h>
3968769ebcSBin Meng DECLARE_GLOBAL_DATA_PTR;
4068769ebcSBin Meng #endif
4168769ebcSBin Meng 
board_should_run_oprom(struct udevice * dev)423f4e1e8eSSimon Glass __weak bool board_should_run_oprom(struct udevice *dev)
436854f87cSSimon Glass {
4468769ebcSBin Meng #if defined(CONFIG_X86) && defined(CONFIG_HAVE_ACPI_RESUME)
4568769ebcSBin Meng 	if (gd->arch.prev_sleep_state == ACPI_S3) {
4668769ebcSBin Meng 		if (IS_ENABLED(CONFIG_S3_VGA_ROM_RUN))
4768769ebcSBin Meng 			return true;
4868769ebcSBin Meng 		else
4968769ebcSBin Meng 			return false;
5068769ebcSBin Meng 	}
5168769ebcSBin Meng #endif
5268769ebcSBin Meng 
536854f87cSSimon Glass 	return true;
546854f87cSSimon Glass }
556854f87cSSimon Glass 
board_should_load_oprom(struct udevice * dev)56f698baa9SBin Meng __weak bool board_should_load_oprom(struct udevice *dev)
576854f87cSSimon Glass {
58c0aea6baSBin Meng 	return true;
596854f87cSSimon Glass }
606854f87cSSimon Glass 
board_map_oprom_vendev(uint32_t vendev)616854f87cSSimon Glass __weak uint32_t board_map_oprom_vendev(uint32_t vendev)
626854f87cSSimon Glass {
636854f87cSSimon Glass 	return vendev;
646854f87cSSimon Glass }
656854f87cSSimon Glass 
pci_rom_probe(struct udevice * dev,struct pci_rom_header ** hdrp)663f4e1e8eSSimon Glass static int pci_rom_probe(struct udevice *dev, struct pci_rom_header **hdrp)
676854f87cSSimon Glass {
683f4e1e8eSSimon Glass 	struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
696854f87cSSimon Glass 	struct pci_rom_header *rom_header;
706854f87cSSimon Glass 	struct pci_rom_data *rom_data;
7140305240SSimon Glass 	u16 rom_vendor, rom_device;
72d57c2f24SBin Meng 	u32 rom_class;
736854f87cSSimon Glass 	u32 vendev;
746854f87cSSimon Glass 	u32 mapped_vendev;
756854f87cSSimon Glass 	u32 rom_address;
766854f87cSSimon Glass 
773f4e1e8eSSimon Glass 	vendev = pplat->vendor << 16 | pplat->device;
786854f87cSSimon Glass 	mapped_vendev = board_map_oprom_vendev(vendev);
796854f87cSSimon Glass 	if (vendev != mapped_vendev)
806854f87cSSimon Glass 		debug("Device ID mapped to %#08x\n", mapped_vendev);
816854f87cSSimon Glass 
82786a08e0SBin Meng #ifdef CONFIG_VGA_BIOS_ADDR
83786a08e0SBin Meng 	rom_address = CONFIG_VGA_BIOS_ADDR;
846854f87cSSimon Glass #else
854a2708a0SSimon Glass 
863f4e1e8eSSimon Glass 	dm_pci_read_config32(dev, PCI_ROM_ADDRESS, &rom_address);
876854f87cSSimon Glass 	if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
886854f87cSSimon Glass 		debug("%s: rom_address=%x\n", __func__, rom_address);
896854f87cSSimon Glass 		return -ENOENT;
906854f87cSSimon Glass 	}
916854f87cSSimon Glass 
926854f87cSSimon Glass 	/* Enable expansion ROM address decoding. */
933f4e1e8eSSimon Glass 	dm_pci_write_config32(dev, PCI_ROM_ADDRESS,
946854f87cSSimon Glass 			      rom_address | PCI_ROM_ADDRESS_ENABLE);
956854f87cSSimon Glass #endif
966854f87cSSimon Glass 	debug("Option ROM address %x\n", rom_address);
97ef2d17feSMinghuan Lian 	rom_header = (struct pci_rom_header *)(unsigned long)rom_address;
986854f87cSSimon Glass 
996854f87cSSimon Glass 	debug("PCI expansion ROM, signature %#04x, INIT size %#04x, data ptr %#04x\n",
10040305240SSimon Glass 	      le16_to_cpu(rom_header->signature),
10140305240SSimon Glass 	      rom_header->size * 512, le16_to_cpu(rom_header->data));
1026854f87cSSimon Glass 
10340305240SSimon Glass 	if (le16_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
1046854f87cSSimon Glass 		printf("Incorrect expansion ROM header signature %04x\n",
10540305240SSimon Glass 		       le16_to_cpu(rom_header->signature));
106f110da99SBin Meng #ifndef CONFIG_VGA_BIOS_ADDR
107f110da99SBin Meng 		/* Disable expansion ROM address decoding */
1083f4e1e8eSSimon Glass 		dm_pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address);
109f110da99SBin Meng #endif
1106854f87cSSimon Glass 		return -EINVAL;
1116854f87cSSimon Glass 	}
1126854f87cSSimon Glass 
11340305240SSimon Glass 	rom_data = (((void *)rom_header) + le16_to_cpu(rom_header->data));
11440305240SSimon Glass 	rom_vendor = le16_to_cpu(rom_data->vendor);
11540305240SSimon Glass 	rom_device = le16_to_cpu(rom_data->device);
1166854f87cSSimon Glass 
1176854f87cSSimon Glass 	debug("PCI ROM image, vendor ID %04x, device ID %04x,\n",
11840305240SSimon Glass 	      rom_vendor, rom_device);
1196854f87cSSimon Glass 
1206854f87cSSimon Glass 	/* If the device id is mapped, a mismatch is expected */
1213f4e1e8eSSimon Glass 	if ((pplat->vendor != rom_vendor || pplat->device != rom_device) &&
1226854f87cSSimon Glass 	    (vendev == mapped_vendev)) {
1236854f87cSSimon Glass 		printf("ID mismatch: vendor ID %04x, device ID %04x\n",
12440305240SSimon Glass 		       rom_vendor, rom_device);
125c5caba03SSimon Glass 		/* Continue anyway */
1266854f87cSSimon Glass 	}
1276854f87cSSimon Glass 
128d57c2f24SBin Meng 	rom_class = (le16_to_cpu(rom_data->class_hi) << 8) | rom_data->class_lo;
129d57c2f24SBin Meng 	debug("PCI ROM image, Class Code %06x, Code Type %02x\n",
130d57c2f24SBin Meng 	      rom_class, rom_data->type);
1316854f87cSSimon Glass 
1323f4e1e8eSSimon Glass 	if (pplat->class != rom_class) {
133d57c2f24SBin Meng 		debug("Class Code mismatch ROM %06x, dev %06x\n",
1343f4e1e8eSSimon Glass 		      rom_class, pplat->class);
1356854f87cSSimon Glass 	}
1366854f87cSSimon Glass 	*hdrp = rom_header;
1376854f87cSSimon Glass 
1386854f87cSSimon Glass 	return 0;
1396854f87cSSimon Glass }
1406854f87cSSimon Glass 
141d830b152SSimon Glass /**
142d830b152SSimon Glass  * pci_rom_load() - Load a ROM image and return a pointer to it
143d830b152SSimon Glass  *
144d830b152SSimon Glass  * @rom_header:		Pointer to ROM image
145d830b152SSimon Glass  * @ram_headerp:	Returns a pointer to the image in RAM
146d830b152SSimon Glass  * @allocedp:		Returns true if @ram_headerp was allocated and needs
147d830b152SSimon Glass  *			to be freed
148d830b152SSimon Glass  * @return 0 if OK, -ve on error. Note that @allocedp is set up regardless of
149d830b152SSimon Glass  * the error state. Even if this function returns an error, it may have
150d830b152SSimon Glass  * allocated memory.
151d830b152SSimon Glass  */
pci_rom_load(struct pci_rom_header * rom_header,struct pci_rom_header ** ram_headerp,bool * allocedp)152d830b152SSimon Glass static int pci_rom_load(struct pci_rom_header *rom_header,
153d830b152SSimon Glass 			struct pci_rom_header **ram_headerp, bool *allocedp)
1546854f87cSSimon Glass {
1556854f87cSSimon Glass 	struct pci_rom_data *rom_data;
1566854f87cSSimon Glass 	unsigned int rom_size;
1576854f87cSSimon Glass 	unsigned int image_size = 0;
1586854f87cSSimon Glass 	void *target;
1596854f87cSSimon Glass 
160d830b152SSimon Glass 	*allocedp = false;
1616854f87cSSimon Glass 	do {
1626854f87cSSimon Glass 		/* Get next image, until we see an x86 version */
1636854f87cSSimon Glass 		rom_header = (struct pci_rom_header *)((void *)rom_header +
1646854f87cSSimon Glass 							    image_size);
1656854f87cSSimon Glass 
1666854f87cSSimon Glass 		rom_data = (struct pci_rom_data *)((void *)rom_header +
16740305240SSimon Glass 				le16_to_cpu(rom_header->data));
1686854f87cSSimon Glass 
16940305240SSimon Glass 		image_size = le16_to_cpu(rom_data->ilen) * 512;
17040305240SSimon Glass 	} while ((rom_data->type != 0) && (rom_data->indicator == 0));
1716854f87cSSimon Glass 
1726854f87cSSimon Glass 	if (rom_data->type != 0)
1736854f87cSSimon Glass 		return -EACCES;
1746854f87cSSimon Glass 
1756854f87cSSimon Glass 	rom_size = rom_header->size * 512;
1766854f87cSSimon Glass 
177bdc88d4eSSimon Glass #ifdef PCI_VGA_RAM_IMAGE_START
1786854f87cSSimon Glass 	target = (void *)PCI_VGA_RAM_IMAGE_START;
179bdc88d4eSSimon Glass #else
180bdc88d4eSSimon Glass 	target = (void *)malloc(rom_size);
181bdc88d4eSSimon Glass 	if (!target)
182bdc88d4eSSimon Glass 		return -ENOMEM;
183d830b152SSimon Glass 	*allocedp = true;
184bdc88d4eSSimon Glass #endif
1856854f87cSSimon Glass 	if (target != rom_header) {
186fba7eac1SSimon Glass 		ulong start = get_timer(0);
187fba7eac1SSimon Glass 
1886854f87cSSimon Glass 		debug("Copying VGA ROM Image from %p to %p, 0x%x bytes\n",
1896854f87cSSimon Glass 		      rom_header, target, rom_size);
1906854f87cSSimon Glass 		memcpy(target, rom_header, rom_size);
1916854f87cSSimon Glass 		if (memcmp(target, rom_header, rom_size)) {
1926854f87cSSimon Glass 			printf("VGA ROM copy failed\n");
1936854f87cSSimon Glass 			return -EFAULT;
1946854f87cSSimon Glass 		}
195fba7eac1SSimon Glass 		debug("Copy took %lums\n", get_timer(start));
1966854f87cSSimon Glass 	}
1976854f87cSSimon Glass 	*ram_headerp = target;
1986854f87cSSimon Glass 
1996854f87cSSimon Glass 	return 0;
2006854f87cSSimon Glass }
2016854f87cSSimon Glass 
202153e1ddaSBin Meng struct vbe_mode_info mode_info;
2036854f87cSSimon Glass 
setup_video(struct screen_info * screen_info)204a4520022SBin Meng void setup_video(struct screen_info *screen_info)
205a4520022SBin Meng {
206a4520022SBin Meng 	struct vesa_mode_info *vesa = &mode_info.vesa;
207a4520022SBin Meng 
2081e7a0473SBin Meng 	/* Sanity test on VESA parameters */
2091e7a0473SBin Meng 	if (!vesa->x_resolution || !vesa->y_resolution)
2101e7a0473SBin Meng 		return;
2111e7a0473SBin Meng 
212a4520022SBin Meng 	screen_info->orig_video_isVGA = VIDEO_TYPE_VLFB;
213a4520022SBin Meng 
214a4520022SBin Meng 	screen_info->lfb_width = vesa->x_resolution;
215a4520022SBin Meng 	screen_info->lfb_height = vesa->y_resolution;
216a4520022SBin Meng 	screen_info->lfb_depth = vesa->bits_per_pixel;
217a4520022SBin Meng 	screen_info->lfb_linelength = vesa->bytes_per_scanline;
218a4520022SBin Meng 	screen_info->lfb_base = vesa->phys_base_ptr;
219a4520022SBin Meng 	screen_info->lfb_size =
220a4520022SBin Meng 		ALIGN(screen_info->lfb_linelength * screen_info->lfb_height,
221a4520022SBin Meng 		      65536);
222a4520022SBin Meng 	screen_info->lfb_size >>= 16;
223a4520022SBin Meng 	screen_info->red_size = vesa->red_mask_size;
224a4520022SBin Meng 	screen_info->red_pos = vesa->red_mask_pos;
225a4520022SBin Meng 	screen_info->green_size = vesa->green_mask_size;
226a4520022SBin Meng 	screen_info->green_pos = vesa->green_mask_pos;
227a4520022SBin Meng 	screen_info->blue_size = vesa->blue_mask_size;
228a4520022SBin Meng 	screen_info->blue_pos = vesa->blue_mask_pos;
229a4520022SBin Meng 	screen_info->rsvd_size = vesa->reserved_mask_size;
230a4520022SBin Meng 	screen_info->rsvd_pos = vesa->reserved_mask_pos;
231a4520022SBin Meng }
232a4520022SBin Meng 
dm_pci_run_vga_bios(struct udevice * dev,int (* int15_handler)(void),int exec_method)2333f4e1e8eSSimon Glass int dm_pci_run_vga_bios(struct udevice *dev, int (*int15_handler)(void),
2343f4e1e8eSSimon Glass 			int exec_method)
2356854f87cSSimon Glass {
2363f4e1e8eSSimon Glass 	struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
237ed48899cSAndreas Bießmann 	struct pci_rom_header *rom = NULL, *ram = NULL;
2386854f87cSSimon Glass 	int vesa_mode = -1;
239d830b152SSimon Glass 	bool emulate, alloced;
2406854f87cSSimon Glass 	int ret;
2416854f87cSSimon Glass 
2426854f87cSSimon Glass 	/* Only execute VGA ROMs */
2433f4e1e8eSSimon Glass 	if (((pplat->class >> 8) ^ PCI_CLASS_DISPLAY_VGA) & 0xff00) {
2443f4e1e8eSSimon Glass 		debug("%s: Class %#x, should be %#x\n", __func__, pplat->class,
2456854f87cSSimon Glass 		      PCI_CLASS_DISPLAY_VGA);
2466854f87cSSimon Glass 		return -ENODEV;
2476854f87cSSimon Glass 	}
2486854f87cSSimon Glass 
249f698baa9SBin Meng 	if (!board_should_load_oprom(dev))
250595aac98SSimon Glass 		return log_msg_ret("Should not load OPROM", -ENXIO);
2516854f87cSSimon Glass 
2523f4e1e8eSSimon Glass 	ret = pci_rom_probe(dev, &rom);
2536854f87cSSimon Glass 	if (ret)
2546854f87cSSimon Glass 		return ret;
2556854f87cSSimon Glass 
256d830b152SSimon Glass 	ret = pci_rom_load(rom, &ram, &alloced);
2576854f87cSSimon Glass 	if (ret)
258d830b152SSimon Glass 		goto err;
2596854f87cSSimon Glass 
260d830b152SSimon Glass 	if (!board_should_run_oprom(dev)) {
261d830b152SSimon Glass 		ret = -ENXIO;
262d830b152SSimon Glass 		goto err;
263d830b152SSimon Glass 	}
2646854f87cSSimon Glass 
2656854f87cSSimon Glass #if defined(CONFIG_FRAMEBUFFER_SET_VESA_MODE) && \
2666854f87cSSimon Glass 		defined(CONFIG_FRAMEBUFFER_VESA_MODE)
2676854f87cSSimon Glass 	vesa_mode = CONFIG_FRAMEBUFFER_VESA_MODE;
2686854f87cSSimon Glass #endif
2699a99caf3SSimon Glass 	debug("Selected vesa mode %#x\n", vesa_mode);
270bc17d8f4SSimon Glass 
271bc17d8f4SSimon Glass 	if (exec_method & PCI_ROM_USE_NATIVE) {
272bc17d8f4SSimon Glass #ifdef CONFIG_X86
273bc17d8f4SSimon Glass 		emulate = false;
274bc17d8f4SSimon Glass #else
275bc17d8f4SSimon Glass 		if (!(exec_method & PCI_ROM_ALLOW_FALLBACK)) {
276bc17d8f4SSimon Glass 			printf("BIOS native execution is only available on x86\n");
277d830b152SSimon Glass 			ret = -ENOSYS;
278d830b152SSimon Glass 			goto err;
279bc17d8f4SSimon Glass 		}
280bc17d8f4SSimon Glass 		emulate = true;
281bc17d8f4SSimon Glass #endif
282bc17d8f4SSimon Glass 	} else {
283bc17d8f4SSimon Glass #ifdef CONFIG_BIOSEMU
284bc17d8f4SSimon Glass 		emulate = true;
285bc17d8f4SSimon Glass #else
286bc17d8f4SSimon Glass 		if (!(exec_method & PCI_ROM_ALLOW_FALLBACK)) {
287bc17d8f4SSimon Glass 			printf("BIOS emulation not available - see CONFIG_BIOSEMU\n");
288d830b152SSimon Glass 			ret = -ENOSYS;
289d830b152SSimon Glass 			goto err;
290bc17d8f4SSimon Glass 		}
291bc17d8f4SSimon Glass 		emulate = false;
292bc17d8f4SSimon Glass #endif
293bc17d8f4SSimon Glass 	}
294bc17d8f4SSimon Glass 
2956854f87cSSimon Glass 	if (emulate) {
2966854f87cSSimon Glass #ifdef CONFIG_BIOSEMU
2976854f87cSSimon Glass 		BE_VGAInfo *info;
2986854f87cSSimon Glass 
2997282672dSSimon Glass 		ret = biosemu_setup(dev, &info);
3006854f87cSSimon Glass 		if (ret)
301d830b152SSimon Glass 			goto err;
3026854f87cSSimon Glass 		biosemu_set_interrupt_handler(0x15, int15_handler);
3037282672dSSimon Glass 		ret = biosemu_run(dev, (uchar *)ram, 1 << 16, info,
3047282672dSSimon Glass 				  true, vesa_mode, &mode_info);
3056854f87cSSimon Glass 		if (ret)
306d830b152SSimon Glass 			goto err;
3076854f87cSSimon Glass #endif
3086854f87cSSimon Glass 	} else {
30905cbd985SSimon Glass #if defined(CONFIG_X86) && CONFIG_IS_ENABLED(X86_32BIT_INIT)
3106854f87cSSimon Glass 		bios_set_interrupt_handler(0x15, int15_handler);
3116854f87cSSimon Glass 
3128beb0bdaSSimon Glass 		bios_run_on_x86(dev, (unsigned long)ram, vesa_mode,
3138beb0bdaSSimon Glass 				&mode_info);
3146854f87cSSimon Glass #endif
3156854f87cSSimon Glass 	}
3169a99caf3SSimon Glass 	debug("Final vesa mode %#x\n", mode_info.video_mode);
317d830b152SSimon Glass 	ret = 0;
3186854f87cSSimon Glass 
319d830b152SSimon Glass err:
320d830b152SSimon Glass 	if (alloced)
321d830b152SSimon Glass 		free(ram);
322d830b152SSimon Glass 	return ret;
3236854f87cSSimon Glass }
324ee87ee82SSimon Glass 
325ee87ee82SSimon Glass #ifdef CONFIG_DM_VIDEO
vbe_setup_video_priv(struct vesa_mode_info * vesa,struct video_priv * uc_priv,struct video_uc_platdata * plat)3265f6ad029SBin Meng int vbe_setup_video_priv(struct vesa_mode_info *vesa,
327ee87ee82SSimon Glass 			 struct video_priv *uc_priv,
328ee87ee82SSimon Glass 			 struct video_uc_platdata *plat)
329ee87ee82SSimon Glass {
330ee87ee82SSimon Glass 	if (!vesa->x_resolution)
331595aac98SSimon Glass 		return log_msg_ret("No x resolution", -ENXIO);
332ee87ee82SSimon Glass 	uc_priv->xsize = vesa->x_resolution;
333ee87ee82SSimon Glass 	uc_priv->ysize = vesa->y_resolution;
334*06696ebeSSimon Glass 	uc_priv->line_length = vesa->bytes_per_scanline;
335ee87ee82SSimon Glass 	switch (vesa->bits_per_pixel) {
336ee87ee82SSimon Glass 	case 32:
337ee87ee82SSimon Glass 	case 24:
338ee87ee82SSimon Glass 		uc_priv->bpix = VIDEO_BPP32;
339ee87ee82SSimon Glass 		break;
340ee87ee82SSimon Glass 	case 16:
341ee87ee82SSimon Glass 		uc_priv->bpix = VIDEO_BPP16;
342ee87ee82SSimon Glass 		break;
343ee87ee82SSimon Glass 	default:
344ee87ee82SSimon Glass 		return -EPROTONOSUPPORT;
345ee87ee82SSimon Glass 	}
346ee87ee82SSimon Glass 	plat->base = vesa->phys_base_ptr;
347ee87ee82SSimon Glass 	plat->size = vesa->bytes_per_scanline * vesa->y_resolution;
348ee87ee82SSimon Glass 
349ee87ee82SSimon Glass 	return 0;
350ee87ee82SSimon Glass }
351ee87ee82SSimon Glass 
vbe_setup_video(struct udevice * dev,int (* int15_handler)(void))352ee87ee82SSimon Glass int vbe_setup_video(struct udevice *dev, int (*int15_handler)(void))
353ee87ee82SSimon Glass {
354ee87ee82SSimon Glass 	struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
355ee87ee82SSimon Glass 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
356ee87ee82SSimon Glass 	int ret;
357ee87ee82SSimon Glass 
358ee87ee82SSimon Glass 	/* If we are running from EFI or coreboot, this can't work */
359f0920e4aSBin Meng 	if (!ll_boot_init()) {
360f0920e4aSBin Meng 		printf("Not available (previous bootloader prevents it)\n");
361ee87ee82SSimon Glass 		return -EPERM;
362f0920e4aSBin Meng 	}
363ee87ee82SSimon Glass 	bootstage_start(BOOTSTAGE_ID_ACCUM_LCD, "vesa display");
364ee87ee82SSimon Glass 	ret = dm_pci_run_vga_bios(dev, int15_handler, PCI_ROM_USE_NATIVE |
365ee87ee82SSimon Glass 					PCI_ROM_ALLOW_FALLBACK);
366ee87ee82SSimon Glass 	bootstage_accum(BOOTSTAGE_ID_ACCUM_LCD);
367ee87ee82SSimon Glass 	if (ret) {
368ee87ee82SSimon Glass 		debug("failed to run video BIOS: %d\n", ret);
369ee87ee82SSimon Glass 		return ret;
370ee87ee82SSimon Glass 	}
371ee87ee82SSimon Glass 
372ee87ee82SSimon Glass 	ret = vbe_setup_video_priv(&mode_info.vesa, uc_priv, plat);
373ee87ee82SSimon Glass 	if (ret) {
374ee87ee82SSimon Glass 		debug("No video mode configured\n");
375ee87ee82SSimon Glass 		return ret;
376ee87ee82SSimon Glass 	}
377ee87ee82SSimon Glass 
37861130938SBin Meng 	printf("Video: %dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
379f0920e4aSBin Meng 	       mode_info.vesa.bits_per_pixel);
380f0920e4aSBin Meng 
381ee87ee82SSimon Glass 	return 0;
382ee87ee82SSimon Glass }
383ee87ee82SSimon Glass #endif
384