xref: /openbmc/u-boot/drivers/pci/pci_rom.c (revision 5f6ad029f31e897fa8bd62d3f42092e051932bc2)
16854f87cSSimon Glass /*
26854f87cSSimon Glass  * Copyright (C) 2014 Google, Inc
36854f87cSSimon Glass  *
46854f87cSSimon Glass  * From coreboot, originally based on the Linux kernel (drivers/pci/pci.c).
56854f87cSSimon Glass  *
66854f87cSSimon Glass  * Modifications are:
76854f87cSSimon Glass  * Copyright (C) 2003-2004 Linux Networx
86854f87cSSimon Glass  * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
96854f87cSSimon Glass  * Copyright (C) 2003-2006 Ronald G. Minnich <rminnich@gmail.com>
106854f87cSSimon Glass  * Copyright (C) 2004-2005 Li-Ta Lo <ollie@lanl.gov>
116854f87cSSimon Glass  * Copyright (C) 2005-2006 Tyan
126854f87cSSimon Glass  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
136854f87cSSimon Glass  * Copyright (C) 2005-2009 coresystems GmbH
146854f87cSSimon Glass  * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
156854f87cSSimon Glass  *
166854f87cSSimon Glass  * PCI Bus Services, see include/linux/pci.h for further explanation.
176854f87cSSimon Glass  *
186854f87cSSimon Glass  * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
196854f87cSSimon Glass  * David Mosberger-Tang
206854f87cSSimon Glass  *
216854f87cSSimon Glass  * Copyright 1997 -- 1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
226854f87cSSimon Glass 
236854f87cSSimon Glass  * SPDX-License-Identifier:	GPL-2.0
246854f87cSSimon Glass  */
256854f87cSSimon Glass 
266854f87cSSimon Glass #include <common.h>
276854f87cSSimon Glass #include <bios_emul.h>
283f4e1e8eSSimon Glass #include <dm.h>
296854f87cSSimon Glass #include <errno.h>
306854f87cSSimon Glass #include <malloc.h>
316854f87cSSimon Glass #include <pci.h>
326854f87cSSimon Glass #include <pci_rom.h>
336854f87cSSimon Glass #include <vbe.h>
34ee87ee82SSimon Glass #include <video.h>
356854f87cSSimon Glass #include <video_fb.h>
36a4520022SBin Meng #include <linux/screen_info.h>
376854f87cSSimon Glass 
383f4e1e8eSSimon Glass __weak bool board_should_run_oprom(struct udevice *dev)
396854f87cSSimon Glass {
406854f87cSSimon Glass 	return true;
416854f87cSSimon Glass }
426854f87cSSimon Glass 
43f698baa9SBin Meng __weak bool board_should_load_oprom(struct udevice *dev)
446854f87cSSimon Glass {
45c0aea6baSBin Meng 	return true;
466854f87cSSimon Glass }
476854f87cSSimon Glass 
486854f87cSSimon Glass __weak uint32_t board_map_oprom_vendev(uint32_t vendev)
496854f87cSSimon Glass {
506854f87cSSimon Glass 	return vendev;
516854f87cSSimon Glass }
526854f87cSSimon Glass 
533f4e1e8eSSimon Glass static int pci_rom_probe(struct udevice *dev, struct pci_rom_header **hdrp)
546854f87cSSimon Glass {
553f4e1e8eSSimon Glass 	struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
566854f87cSSimon Glass 	struct pci_rom_header *rom_header;
576854f87cSSimon Glass 	struct pci_rom_data *rom_data;
5840305240SSimon Glass 	u16 rom_vendor, rom_device;
59d57c2f24SBin Meng 	u32 rom_class;
606854f87cSSimon Glass 	u32 vendev;
616854f87cSSimon Glass 	u32 mapped_vendev;
626854f87cSSimon Glass 	u32 rom_address;
636854f87cSSimon Glass 
643f4e1e8eSSimon Glass 	vendev = pplat->vendor << 16 | pplat->device;
656854f87cSSimon Glass 	mapped_vendev = board_map_oprom_vendev(vendev);
666854f87cSSimon Glass 	if (vendev != mapped_vendev)
676854f87cSSimon Glass 		debug("Device ID mapped to %#08x\n", mapped_vendev);
686854f87cSSimon Glass 
69786a08e0SBin Meng #ifdef CONFIG_VGA_BIOS_ADDR
70786a08e0SBin Meng 	rom_address = CONFIG_VGA_BIOS_ADDR;
716854f87cSSimon Glass #else
724a2708a0SSimon Glass 
733f4e1e8eSSimon Glass 	dm_pci_read_config32(dev, PCI_ROM_ADDRESS, &rom_address);
746854f87cSSimon Glass 	if (rom_address == 0x00000000 || rom_address == 0xffffffff) {
756854f87cSSimon Glass 		debug("%s: rom_address=%x\n", __func__, rom_address);
766854f87cSSimon Glass 		return -ENOENT;
776854f87cSSimon Glass 	}
786854f87cSSimon Glass 
796854f87cSSimon Glass 	/* Enable expansion ROM address decoding. */
803f4e1e8eSSimon Glass 	dm_pci_write_config32(dev, PCI_ROM_ADDRESS,
816854f87cSSimon Glass 			      rom_address | PCI_ROM_ADDRESS_ENABLE);
826854f87cSSimon Glass #endif
836854f87cSSimon Glass 	debug("Option ROM address %x\n", rom_address);
84ef2d17feSMinghuan Lian 	rom_header = (struct pci_rom_header *)(unsigned long)rom_address;
856854f87cSSimon Glass 
866854f87cSSimon Glass 	debug("PCI expansion ROM, signature %#04x, INIT size %#04x, data ptr %#04x\n",
8740305240SSimon Glass 	      le16_to_cpu(rom_header->signature),
8840305240SSimon Glass 	      rom_header->size * 512, le16_to_cpu(rom_header->data));
896854f87cSSimon Glass 
9040305240SSimon Glass 	if (le16_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
916854f87cSSimon Glass 		printf("Incorrect expansion ROM header signature %04x\n",
9240305240SSimon Glass 		       le16_to_cpu(rom_header->signature));
93f110da99SBin Meng #ifndef CONFIG_VGA_BIOS_ADDR
94f110da99SBin Meng 		/* Disable expansion ROM address decoding */
953f4e1e8eSSimon Glass 		dm_pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address);
96f110da99SBin Meng #endif
976854f87cSSimon Glass 		return -EINVAL;
986854f87cSSimon Glass 	}
996854f87cSSimon Glass 
10040305240SSimon Glass 	rom_data = (((void *)rom_header) + le16_to_cpu(rom_header->data));
10140305240SSimon Glass 	rom_vendor = le16_to_cpu(rom_data->vendor);
10240305240SSimon Glass 	rom_device = le16_to_cpu(rom_data->device);
1036854f87cSSimon Glass 
1046854f87cSSimon Glass 	debug("PCI ROM image, vendor ID %04x, device ID %04x,\n",
10540305240SSimon Glass 	      rom_vendor, rom_device);
1066854f87cSSimon Glass 
1076854f87cSSimon Glass 	/* If the device id is mapped, a mismatch is expected */
1083f4e1e8eSSimon Glass 	if ((pplat->vendor != rom_vendor || pplat->device != rom_device) &&
1096854f87cSSimon Glass 	    (vendev == mapped_vendev)) {
1106854f87cSSimon Glass 		printf("ID mismatch: vendor ID %04x, device ID %04x\n",
11140305240SSimon Glass 		       rom_vendor, rom_device);
112c5caba03SSimon Glass 		/* Continue anyway */
1136854f87cSSimon Glass 	}
1146854f87cSSimon Glass 
115d57c2f24SBin Meng 	rom_class = (le16_to_cpu(rom_data->class_hi) << 8) | rom_data->class_lo;
116d57c2f24SBin Meng 	debug("PCI ROM image, Class Code %06x, Code Type %02x\n",
117d57c2f24SBin Meng 	      rom_class, rom_data->type);
1186854f87cSSimon Glass 
1193f4e1e8eSSimon Glass 	if (pplat->class != rom_class) {
120d57c2f24SBin Meng 		debug("Class Code mismatch ROM %06x, dev %06x\n",
1213f4e1e8eSSimon Glass 		      rom_class, pplat->class);
1226854f87cSSimon Glass 	}
1236854f87cSSimon Glass 	*hdrp = rom_header;
1246854f87cSSimon Glass 
1256854f87cSSimon Glass 	return 0;
1266854f87cSSimon Glass }
1276854f87cSSimon Glass 
128d830b152SSimon Glass /**
129d830b152SSimon Glass  * pci_rom_load() - Load a ROM image and return a pointer to it
130d830b152SSimon Glass  *
131d830b152SSimon Glass  * @rom_header:		Pointer to ROM image
132d830b152SSimon Glass  * @ram_headerp:	Returns a pointer to the image in RAM
133d830b152SSimon Glass  * @allocedp:		Returns true if @ram_headerp was allocated and needs
134d830b152SSimon Glass  *			to be freed
135d830b152SSimon Glass  * @return 0 if OK, -ve on error. Note that @allocedp is set up regardless of
136d830b152SSimon Glass  * the error state. Even if this function returns an error, it may have
137d830b152SSimon Glass  * allocated memory.
138d830b152SSimon Glass  */
139d830b152SSimon Glass static int pci_rom_load(struct pci_rom_header *rom_header,
140d830b152SSimon Glass 			struct pci_rom_header **ram_headerp, bool *allocedp)
1416854f87cSSimon Glass {
1426854f87cSSimon Glass 	struct pci_rom_data *rom_data;
1436854f87cSSimon Glass 	unsigned int rom_size;
1446854f87cSSimon Glass 	unsigned int image_size = 0;
1456854f87cSSimon Glass 	void *target;
1466854f87cSSimon Glass 
147d830b152SSimon Glass 	*allocedp = false;
1486854f87cSSimon Glass 	do {
1496854f87cSSimon Glass 		/* Get next image, until we see an x86 version */
1506854f87cSSimon Glass 		rom_header = (struct pci_rom_header *)((void *)rom_header +
1516854f87cSSimon Glass 							    image_size);
1526854f87cSSimon Glass 
1536854f87cSSimon Glass 		rom_data = (struct pci_rom_data *)((void *)rom_header +
15440305240SSimon Glass 				le16_to_cpu(rom_header->data));
1556854f87cSSimon Glass 
15640305240SSimon Glass 		image_size = le16_to_cpu(rom_data->ilen) * 512;
15740305240SSimon Glass 	} while ((rom_data->type != 0) && (rom_data->indicator == 0));
1586854f87cSSimon Glass 
1596854f87cSSimon Glass 	if (rom_data->type != 0)
1606854f87cSSimon Glass 		return -EACCES;
1616854f87cSSimon Glass 
1626854f87cSSimon Glass 	rom_size = rom_header->size * 512;
1636854f87cSSimon Glass 
164bdc88d4eSSimon Glass #ifdef PCI_VGA_RAM_IMAGE_START
1656854f87cSSimon Glass 	target = (void *)PCI_VGA_RAM_IMAGE_START;
166bdc88d4eSSimon Glass #else
167bdc88d4eSSimon Glass 	target = (void *)malloc(rom_size);
168bdc88d4eSSimon Glass 	if (!target)
169bdc88d4eSSimon Glass 		return -ENOMEM;
170d830b152SSimon Glass 	*allocedp = true;
171bdc88d4eSSimon Glass #endif
1726854f87cSSimon Glass 	if (target != rom_header) {
173fba7eac1SSimon Glass 		ulong start = get_timer(0);
174fba7eac1SSimon Glass 
1756854f87cSSimon Glass 		debug("Copying VGA ROM Image from %p to %p, 0x%x bytes\n",
1766854f87cSSimon Glass 		      rom_header, target, rom_size);
1776854f87cSSimon Glass 		memcpy(target, rom_header, rom_size);
1786854f87cSSimon Glass 		if (memcmp(target, rom_header, rom_size)) {
1796854f87cSSimon Glass 			printf("VGA ROM copy failed\n");
1806854f87cSSimon Glass 			return -EFAULT;
1816854f87cSSimon Glass 		}
182fba7eac1SSimon Glass 		debug("Copy took %lums\n", get_timer(start));
1836854f87cSSimon Glass 	}
1846854f87cSSimon Glass 	*ram_headerp = target;
1856854f87cSSimon Glass 
1866854f87cSSimon Glass 	return 0;
1876854f87cSSimon Glass }
1886854f87cSSimon Glass 
189153e1ddaSBin Meng struct vbe_mode_info mode_info;
1906854f87cSSimon Glass 
1916854f87cSSimon Glass int vbe_get_video_info(struct graphic_device *gdev)
1926854f87cSSimon Glass {
1936854f87cSSimon Glass #ifdef CONFIG_FRAMEBUFFER_SET_VESA_MODE
1946854f87cSSimon Glass 	struct vesa_mode_info *vesa = &mode_info.vesa;
1956854f87cSSimon Glass 
1966854f87cSSimon Glass 	gdev->winSizeX = vesa->x_resolution;
1976854f87cSSimon Glass 	gdev->winSizeY = vesa->y_resolution;
1986854f87cSSimon Glass 
1996854f87cSSimon Glass 	gdev->plnSizeX = vesa->x_resolution;
2006854f87cSSimon Glass 	gdev->plnSizeY = vesa->y_resolution;
2016854f87cSSimon Glass 
2026854f87cSSimon Glass 	gdev->gdfBytesPP = vesa->bits_per_pixel / 8;
2036854f87cSSimon Glass 
2046854f87cSSimon Glass 	switch (vesa->bits_per_pixel) {
2050e98a147SJian Luo 	case 32:
2066854f87cSSimon Glass 	case 24:
2076854f87cSSimon Glass 		gdev->gdfIndex = GDF_32BIT_X888RGB;
2086854f87cSSimon Glass 		break;
2096854f87cSSimon Glass 	case 16:
2106854f87cSSimon Glass 		gdev->gdfIndex = GDF_16BIT_565RGB;
2116854f87cSSimon Glass 		break;
2126854f87cSSimon Glass 	default:
2136854f87cSSimon Glass 		gdev->gdfIndex = GDF__8BIT_INDEX;
2146854f87cSSimon Glass 		break;
2156854f87cSSimon Glass 	}
2166854f87cSSimon Glass 
2176854f87cSSimon Glass 	gdev->isaBase = CONFIG_SYS_ISA_IO_BASE_ADDRESS;
2186854f87cSSimon Glass 	gdev->pciBase = vesa->phys_base_ptr;
2196854f87cSSimon Glass 
2206854f87cSSimon Glass 	gdev->frameAdrs = vesa->phys_base_ptr;
2216854f87cSSimon Glass 	gdev->memSize = vesa->bytes_per_scanline * vesa->y_resolution;
2226854f87cSSimon Glass 
2236854f87cSSimon Glass 	gdev->vprBase = vesa->phys_base_ptr;
2246854f87cSSimon Glass 	gdev->cprBase = vesa->phys_base_ptr;
2256854f87cSSimon Glass 
22623609c71SSimon Glass 	return gdev->winSizeX ? 0 : -ENOSYS;
2276854f87cSSimon Glass #else
2286854f87cSSimon Glass 	return -ENOSYS;
2296854f87cSSimon Glass #endif
2306854f87cSSimon Glass }
2316854f87cSSimon Glass 
232a4520022SBin Meng void setup_video(struct screen_info *screen_info)
233a4520022SBin Meng {
234a4520022SBin Meng 	struct vesa_mode_info *vesa = &mode_info.vesa;
235a4520022SBin Meng 
2361e7a0473SBin Meng 	/* Sanity test on VESA parameters */
2371e7a0473SBin Meng 	if (!vesa->x_resolution || !vesa->y_resolution)
2381e7a0473SBin Meng 		return;
2391e7a0473SBin Meng 
240a4520022SBin Meng 	screen_info->orig_video_isVGA = VIDEO_TYPE_VLFB;
241a4520022SBin Meng 
242a4520022SBin Meng 	screen_info->lfb_width = vesa->x_resolution;
243a4520022SBin Meng 	screen_info->lfb_height = vesa->y_resolution;
244a4520022SBin Meng 	screen_info->lfb_depth = vesa->bits_per_pixel;
245a4520022SBin Meng 	screen_info->lfb_linelength = vesa->bytes_per_scanline;
246a4520022SBin Meng 	screen_info->lfb_base = vesa->phys_base_ptr;
247a4520022SBin Meng 	screen_info->lfb_size =
248a4520022SBin Meng 		ALIGN(screen_info->lfb_linelength * screen_info->lfb_height,
249a4520022SBin Meng 		      65536);
250a4520022SBin Meng 	screen_info->lfb_size >>= 16;
251a4520022SBin Meng 	screen_info->red_size = vesa->red_mask_size;
252a4520022SBin Meng 	screen_info->red_pos = vesa->red_mask_pos;
253a4520022SBin Meng 	screen_info->green_size = vesa->green_mask_size;
254a4520022SBin Meng 	screen_info->green_pos = vesa->green_mask_pos;
255a4520022SBin Meng 	screen_info->blue_size = vesa->blue_mask_size;
256a4520022SBin Meng 	screen_info->blue_pos = vesa->blue_mask_pos;
257a4520022SBin Meng 	screen_info->rsvd_size = vesa->reserved_mask_size;
258a4520022SBin Meng 	screen_info->rsvd_pos = vesa->reserved_mask_pos;
259a4520022SBin Meng }
260a4520022SBin Meng 
2613f4e1e8eSSimon Glass int dm_pci_run_vga_bios(struct udevice *dev, int (*int15_handler)(void),
2623f4e1e8eSSimon Glass 			int exec_method)
2636854f87cSSimon Glass {
2643f4e1e8eSSimon Glass 	struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
265ed48899cSAndreas Bießmann 	struct pci_rom_header *rom = NULL, *ram = NULL;
2666854f87cSSimon Glass 	int vesa_mode = -1;
267d830b152SSimon Glass 	bool emulate, alloced;
2686854f87cSSimon Glass 	int ret;
2696854f87cSSimon Glass 
2706854f87cSSimon Glass 	/* Only execute VGA ROMs */
2713f4e1e8eSSimon Glass 	if (((pplat->class >> 8) ^ PCI_CLASS_DISPLAY_VGA) & 0xff00) {
2723f4e1e8eSSimon Glass 		debug("%s: Class %#x, should be %#x\n", __func__, pplat->class,
2736854f87cSSimon Glass 		      PCI_CLASS_DISPLAY_VGA);
2746854f87cSSimon Glass 		return -ENODEV;
2756854f87cSSimon Glass 	}
2766854f87cSSimon Glass 
277f698baa9SBin Meng 	if (!board_should_load_oprom(dev))
2786854f87cSSimon Glass 		return -ENXIO;
2796854f87cSSimon Glass 
2803f4e1e8eSSimon Glass 	ret = pci_rom_probe(dev, &rom);
2816854f87cSSimon Glass 	if (ret)
2826854f87cSSimon Glass 		return ret;
2836854f87cSSimon Glass 
284d830b152SSimon Glass 	ret = pci_rom_load(rom, &ram, &alloced);
2856854f87cSSimon Glass 	if (ret)
286d830b152SSimon Glass 		goto err;
2876854f87cSSimon Glass 
288d830b152SSimon Glass 	if (!board_should_run_oprom(dev)) {
289d830b152SSimon Glass 		ret = -ENXIO;
290d830b152SSimon Glass 		goto err;
291d830b152SSimon Glass 	}
2926854f87cSSimon Glass 
2936854f87cSSimon Glass #if defined(CONFIG_FRAMEBUFFER_SET_VESA_MODE) && \
2946854f87cSSimon Glass 		defined(CONFIG_FRAMEBUFFER_VESA_MODE)
2956854f87cSSimon Glass 	vesa_mode = CONFIG_FRAMEBUFFER_VESA_MODE;
2966854f87cSSimon Glass #endif
2979a99caf3SSimon Glass 	debug("Selected vesa mode %#x\n", vesa_mode);
298bc17d8f4SSimon Glass 
299bc17d8f4SSimon Glass 	if (exec_method & PCI_ROM_USE_NATIVE) {
300bc17d8f4SSimon Glass #ifdef CONFIG_X86
301bc17d8f4SSimon Glass 		emulate = false;
302bc17d8f4SSimon Glass #else
303bc17d8f4SSimon Glass 		if (!(exec_method & PCI_ROM_ALLOW_FALLBACK)) {
304bc17d8f4SSimon Glass 			printf("BIOS native execution is only available on x86\n");
305d830b152SSimon Glass 			ret = -ENOSYS;
306d830b152SSimon Glass 			goto err;
307bc17d8f4SSimon Glass 		}
308bc17d8f4SSimon Glass 		emulate = true;
309bc17d8f4SSimon Glass #endif
310bc17d8f4SSimon Glass 	} else {
311bc17d8f4SSimon Glass #ifdef CONFIG_BIOSEMU
312bc17d8f4SSimon Glass 		emulate = true;
313bc17d8f4SSimon Glass #else
314bc17d8f4SSimon Glass 		if (!(exec_method & PCI_ROM_ALLOW_FALLBACK)) {
315bc17d8f4SSimon Glass 			printf("BIOS emulation not available - see CONFIG_BIOSEMU\n");
316d830b152SSimon Glass 			ret = -ENOSYS;
317d830b152SSimon Glass 			goto err;
318bc17d8f4SSimon Glass 		}
319bc17d8f4SSimon Glass 		emulate = false;
320bc17d8f4SSimon Glass #endif
321bc17d8f4SSimon Glass 	}
322bc17d8f4SSimon Glass 
3236854f87cSSimon Glass 	if (emulate) {
3246854f87cSSimon Glass #ifdef CONFIG_BIOSEMU
3256854f87cSSimon Glass 		BE_VGAInfo *info;
3266854f87cSSimon Glass 
3277282672dSSimon Glass 		ret = biosemu_setup(dev, &info);
3286854f87cSSimon Glass 		if (ret)
329d830b152SSimon Glass 			goto err;
3306854f87cSSimon Glass 		biosemu_set_interrupt_handler(0x15, int15_handler);
3317282672dSSimon Glass 		ret = biosemu_run(dev, (uchar *)ram, 1 << 16, info,
3327282672dSSimon Glass 				  true, vesa_mode, &mode_info);
3336854f87cSSimon Glass 		if (ret)
334d830b152SSimon Glass 			goto err;
3356854f87cSSimon Glass #endif
3366854f87cSSimon Glass 	} else {
3376854f87cSSimon Glass #ifdef CONFIG_X86
3386854f87cSSimon Glass 		bios_set_interrupt_handler(0x15, int15_handler);
3396854f87cSSimon Glass 
3408beb0bdaSSimon Glass 		bios_run_on_x86(dev, (unsigned long)ram, vesa_mode,
3418beb0bdaSSimon Glass 				&mode_info);
3426854f87cSSimon Glass #endif
3436854f87cSSimon Glass 	}
3449a99caf3SSimon Glass 	debug("Final vesa mode %#x\n", mode_info.video_mode);
345d830b152SSimon Glass 	ret = 0;
3466854f87cSSimon Glass 
347d830b152SSimon Glass err:
348d830b152SSimon Glass 	if (alloced)
349d830b152SSimon Glass 		free(ram);
350d830b152SSimon Glass 	return ret;
3516854f87cSSimon Glass }
352ee87ee82SSimon Glass 
353ee87ee82SSimon Glass #ifdef CONFIG_DM_VIDEO
354*5f6ad029SBin Meng int vbe_setup_video_priv(struct vesa_mode_info *vesa,
355ee87ee82SSimon Glass 			 struct video_priv *uc_priv,
356ee87ee82SSimon Glass 			 struct video_uc_platdata *plat)
357ee87ee82SSimon Glass {
358ee87ee82SSimon Glass 	if (!vesa->x_resolution)
359ee87ee82SSimon Glass 		return -ENXIO;
360ee87ee82SSimon Glass 	uc_priv->xsize = vesa->x_resolution;
361ee87ee82SSimon Glass 	uc_priv->ysize = vesa->y_resolution;
362ee87ee82SSimon Glass 	switch (vesa->bits_per_pixel) {
363ee87ee82SSimon Glass 	case 32:
364ee87ee82SSimon Glass 	case 24:
365ee87ee82SSimon Glass 		uc_priv->bpix = VIDEO_BPP32;
366ee87ee82SSimon Glass 		break;
367ee87ee82SSimon Glass 	case 16:
368ee87ee82SSimon Glass 		uc_priv->bpix = VIDEO_BPP16;
369ee87ee82SSimon Glass 		break;
370ee87ee82SSimon Glass 	default:
371ee87ee82SSimon Glass 		return -EPROTONOSUPPORT;
372ee87ee82SSimon Glass 	}
373ee87ee82SSimon Glass 	plat->base = vesa->phys_base_ptr;
374ee87ee82SSimon Glass 	plat->size = vesa->bytes_per_scanline * vesa->y_resolution;
375ee87ee82SSimon Glass 
376ee87ee82SSimon Glass 	return 0;
377ee87ee82SSimon Glass }
378ee87ee82SSimon Glass 
379ee87ee82SSimon Glass int vbe_setup_video(struct udevice *dev, int (*int15_handler)(void))
380ee87ee82SSimon Glass {
381ee87ee82SSimon Glass 	struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
382ee87ee82SSimon Glass 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
383ee87ee82SSimon Glass 	int ret;
384ee87ee82SSimon Glass 
385f0920e4aSBin Meng 	printf("Video: ");
386f0920e4aSBin Meng 
387ee87ee82SSimon Glass 	/* If we are running from EFI or coreboot, this can't work */
388f0920e4aSBin Meng 	if (!ll_boot_init()) {
389f0920e4aSBin Meng 		printf("Not available (previous bootloader prevents it)\n");
390ee87ee82SSimon Glass 		return -EPERM;
391f0920e4aSBin Meng 	}
392ee87ee82SSimon Glass 	bootstage_start(BOOTSTAGE_ID_ACCUM_LCD, "vesa display");
393ee87ee82SSimon Glass 	ret = dm_pci_run_vga_bios(dev, int15_handler, PCI_ROM_USE_NATIVE |
394ee87ee82SSimon Glass 					PCI_ROM_ALLOW_FALLBACK);
395ee87ee82SSimon Glass 	bootstage_accum(BOOTSTAGE_ID_ACCUM_LCD);
396ee87ee82SSimon Glass 	if (ret) {
397ee87ee82SSimon Glass 		debug("failed to run video BIOS: %d\n", ret);
398ee87ee82SSimon Glass 		return ret;
399ee87ee82SSimon Glass 	}
400ee87ee82SSimon Glass 
401ee87ee82SSimon Glass 	ret = vbe_setup_video_priv(&mode_info.vesa, uc_priv, plat);
402ee87ee82SSimon Glass 	if (ret) {
403ee87ee82SSimon Glass 		debug("No video mode configured\n");
404ee87ee82SSimon Glass 		return ret;
405ee87ee82SSimon Glass 	}
406ee87ee82SSimon Glass 
407f0920e4aSBin Meng 	printf("%dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
408f0920e4aSBin Meng 	       mode_info.vesa.bits_per_pixel);
409f0920e4aSBin Meng 
410ee87ee82SSimon Glass 	return 0;
411ee87ee82SSimon Glass }
412ee87ee82SSimon Glass #endif
413