1 // SPDX-License-Identifier: GPL-2.0
3 * Modified from coreboot bochs.c
6 #define LOG_CATEGORY UCLASS_VIDEO
14 #include <linux/sizes.h>
17 static int xsize = CONFIG_VIDEO_BOCHS_SIZE_X;
18 static int ysize = CONFIG_VIDEO_BOCHS_SIZE_Y;
20 static void bochs_write(void *mmio, int index, int val)
22 writew(val, mmio + MMIO_BASE + index * 2);
25 static int bochs_read(void *mmio, int index)
27 return readw(mmio + MMIO_BASE + index * 2);
30 static void bochs_vga_write(void *mmio, int index, uint8_t val)
32 writeb(val, mmio + VGA_BASE + index);
35 static int bochs_init_fb(struct udevice *dev)
37 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
38 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
43 log_debug("probing %s at PCI %x\n", dev->name, dm_pci_get_bdf(dev));
44 fb = dm_pci_read_bar32(dev, 0);
46 return log_msg_ret("fb", -EIO);
48 /* MMIO bar supported since qemu 3.0+ */
49 mmio = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_2, 0, 0, PCI_REGION_TYPE,
53 return log_msg_ret("map", -EIO);
55 /* bochs dispi detection */
56 id = bochs_read(mmio, INDEX_ID);
57 if ((id & 0xfff0) != ID0) {
58 log_debug("ID mismatch\n");
59 return -EPROTONOSUPPORT;
61 mem = bochs_read(mmio, INDEX_VIDEO_MEMORY_64K) * SZ_64K;
62 log_debug("QEMU VGA: bochs @ %p: %d MiB FB at %lx\n", mmio, mem / SZ_1M,
65 uc_priv->xsize = xsize;
66 uc_priv->ysize = ysize;
67 uc_priv->bpix = VIDEO_BPP32;
69 /* setup video mode */
70 bochs_write(mmio, INDEX_ENABLE, 0);
71 bochs_write(mmio, INDEX_BANK, 0);
72 bochs_write(mmio, INDEX_BPP, VNBITS(uc_priv->bpix));
73 bochs_write(mmio, INDEX_XRES, xsize);
74 bochs_write(mmio, INDEX_YRES, ysize);
75 bochs_write(mmio, INDEX_VIRT_WIDTH, xsize);
76 bochs_write(mmio, INDEX_VIRT_HEIGHT, ysize);
77 bochs_write(mmio, INDEX_X_OFFSET, 0);
78 bochs_write(mmio, INDEX_Y_OFFSET, 0);
79 bochs_write(mmio, INDEX_ENABLE, ENABLED | LFB_ENABLED);
81 /* disable blanking */
82 bochs_vga_write(mmio, VGA_ATT_W - VGA_INDEX, VGA_AR_ENABLE_DISPLAY);
89 static int bochs_video_probe(struct udevice *dev)
93 ret = bochs_init_fb(dev);
100 static int bochs_video_bind(struct udevice *dev)
102 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
104 /* Set the frame buffer size per configuration */
105 uc_plat->size = xsize * ysize * 32 / 8;
106 log_debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
111 U_BOOT_DRIVER(bochs_video) = {
112 .name = "bochs_video",
114 .bind = bochs_video_bind,
115 .probe = bochs_video_probe,
118 static struct pci_device_id bochs_video_supported[] = {
119 { PCI_DEVICE(0x1234, 0x1111) },
123 U_BOOT_PCI_DEVICE(bochs_video, bochs_video_supported);