Skip to contentSkip to conversation

video: efi: Improve the EFI-app video console

PATCH Superseded Simon Glass 2 participants 19 messages Feb 22, 2023 – Feb 23, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover video: efi: Improve the EFI-app video console

This does not work on some 64-bit machines since only a 32-bit address for the framebuffer is supported in the VESA structure.

This series corrects this and makes a few other minor, video-related improvements.

Changes in v2:
- Obtain copy framebuffer size from EFI instead of using a fixed value
- Dropping debugging printf()
- use new bootph-xxx tag
- Add new patch to show the size of the copy framebuffer with bdinfo

Simon Glass (13):
efi: video: Move payload code into a function
efi: video: Return mode info for app also
efi: Support a 64-bit frame buffer address
x86: Add a few more items to bdinfo
efi: Use a fixed value for the timer clock
efi: Support copy framebuffer
video: Allow a copy framebuffer with pre-allocated fb
bbinfo: Show the size of the copy framebuffer
efi: Adjust script to show pre-relocation output on terminal
video: Remove duplicate cursor-positioning function
video: Clear the vidconsole rather than the video
efi: Add dhrystone, dcache and scroll lines to app
video: Add a note about the broken implementation

 arch/x86/dts/efi-x86_app.dts      |   1 +
 arch/x86/lib/bdinfo.c             |   4 +
 arch/x86/lib/fsp/fsp_graphics.c   |   2 +-
 cmd/bdinfo.c                      |   6 +-
 cmd/cls.c                         |  20 +++--
 configs/efi-x86_app64_defconfig   |   3 +
 drivers/pci/pci_rom.c             |  10 ++-
 drivers/timer/tsc_timer.c         |   4 +
 drivers/video/coreboot.c          |   2 +-
 drivers/video/efi.c               | 137 ++++++++++++++++++++++--------
 drivers/video/vidconsole-uclass.c |  48 ++++-------
 drivers/video/video-uclass.c      |  32 +++++--
 include/vesa.h                    |  16 +++-
 include/video.h                   |   2 +
 include/video_console.h           |   9 ++
 scripts/build-efi.sh              |   2 +
 16 files changed, 212 insertions(+), 86 deletions(-)
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#1 lore raw

PATCH v2 1/13 efi: video: Move payload code into a function

Put this into a function, as we have done for the app implementation. Comment both functions. FOr now the app still does not access it correctly.

---

(no changes since v1)

 drivers/video/efi.c | 83 +++++++++++++++++++++++++++++++--------------
 1 file changed, 57 insertions(+), 26 deletions(-)
drivers/video/efi.c +57 -26
index b11e42c0ebf..fc37a68b376 100644
@@ -50,6 +50,15 @@ static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
 	*size = len;
 }
 
+/**
+ * get_mode_info() - Ask EFI for the mode information
+ *
+ * Gets info from the graphics-output protocol
+ *
+ * @vesa: Place to put the mode information
+ * Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
+ * the protocol is not supported by EFI
+ */
 static int get_mode_info(struct vesa_mode_info *vesa)
 {
 	efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
@@ -72,32 +81,54 @@ static int get_mode_info(struct vesa_mode_info *vesa)
 	return 0;
 }
 
+/**
+ * get_mode_from_entry() - Obtain fb info from the EFIET_GOP_MODE payload entry
+ *
+ * This gets the mode information provided by the stub to the payload and puts
+ * it into a vesa structure. It also returns the mode information.
+ *
+ * @vesa: Place to put the mode information
+ * @infop: Returns a pointer to the mode info
+ * Returns: 0 if OK, -ve on error
+ */
+static int get_mode_from_entry(struct vesa_mode_info *vesa,
+			       struct efi_gop_mode_info **infop)
+{
+	struct efi_gop_mode *mode;
+	int size;
+	int ret;
+
+	ret = efi_info_get(EFIET_GOP_MODE, (void **)&mode, &size);
+	if (ret) {
+		printf("EFI graphics output entry not found\n");
+		return ret;
+	}
+	vesa->phys_base_ptr = mode->fb_base;
+	vesa->x_resolution = mode->info->width;
+	vesa->y_resolution = mode->info->height;
+	*infop = mode->info;
+
+	return 0;
+}
+
 static int save_vesa_mode(struct vesa_mode_info *vesa)
 {
-	struct efi_entry_gopmode *mode;
 	const struct efi_framebuffer *fbinfo;
-	int size;
+	struct efi_gop_mode_info *info;
 	int ret;
 
-	if (IS_ENABLED(CONFIG_EFI_APP)) {
+	if (IS_ENABLED(CONFIG_EFI_APP))
 		ret = get_mode_info(vesa);
-		if (ret) {
-			printf("EFI graphics output protocol not found\n");
-			return -ENXIO;
-		}
-	} else {
-		ret = efi_info_get(EFIET_GOP_MODE, (void **)&mode, &size);
-		if (ret == -ENOENT) {
-			printf("EFI graphics output protocol mode not found\n");
-			return -ENXIO;
-		}
-		vesa->phys_base_ptr = mode->fb_base;
-		vesa->x_resolution = mode->info->width;
-		vesa->y_resolution = mode->info->height;
+	else
+		ret = get_mode_from_entry(vesa, &info);
+	if (ret) {
+		printf("EFI graphics output protocol not found (err=%dE)\n",
+		       ret);
+		return ret;
 	}
 
-	if (mode->info->pixel_format < EFI_GOT_BITMASK) {
-		fbinfo = &efi_framebuffer_format_map[mode->info->pixel_format];
+	if (info->pixel_format < EFI_GOT_BITMASK) {
+		fbinfo = &efi_framebuffer_format_map[info->pixel_format];
 		vesa->red_mask_size = fbinfo->red.size;
 		vesa->red_mask_pos = fbinfo->red.pos;
 		vesa->green_mask_size = fbinfo->green.size;
@@ -108,29 +139,29 @@ static int save_vesa_mode(struct vesa_mode_info *vesa)
 		vesa->reserved_mask_pos = fbinfo->rsvd.pos;
 
 		vesa->bits_per_pixel = 32;
-		vesa->bytes_per_scanline = mode->info->pixels_per_scanline * 4;
-	} else if (mode->info->pixel_format == EFI_GOT_BITMASK) {
-		efi_find_pixel_bits(mode->info->pixel_bitmask[0],
+		vesa->bytes_per_scanline = info->pixels_per_scanline * 4;
+	} else if (info->pixel_format == EFI_GOT_BITMASK) {
+		efi_find_pixel_bits(info->pixel_bitmask[0],
 				    &vesa->red_mask_pos,
 				    &vesa->red_mask_size);
-		efi_find_pixel_bits(mode->info->pixel_bitmask[1],
+		efi_find_pixel_bits(info->pixel_bitmask[1],
 				    &vesa->green_mask_pos,
 				    &vesa->green_mask_size);
-		efi_find_pixel_bits(mode->info->pixel_bitmask[2],
+		efi_find_pixel_bits(info->pixel_bitmask[2],
 				    &vesa->blue_mask_pos,
 				    &vesa->blue_mask_size);
-		efi_find_pixel_bits(mode->info->pixel_bitmask[3],
+		efi_find_pixel_bits(info->pixel_bitmask[3],
 				    &vesa->reserved_mask_pos,
 				    &vesa->reserved_mask_size);
 		vesa->bits_per_pixel = vesa->red_mask_size +
 				       vesa->green_mask_size +
 				       vesa->blue_mask_size +
 				       vesa->reserved_mask_size;
-		vesa->bytes_per_scanline = (mode->info->pixels_per_scanline *
+		vesa->bytes_per_scanline = (info->pixels_per_scanline *
 					    vesa->bits_per_pixel) / 8;
 	} else {
 		debug("efi set unknown framebuffer format: %d\n",
-		      mode->info->pixel_format);
+		      info->pixel_format);
 		return -EINVAL;
 	}
 
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#2 lore raw

PATCH v2 2/13 efi: video: Return mode info for app also

In reply to Simon Glass

The mode info is currently not initialised for the app. Fix this by returning it from the function.

---

(no changes since v1)

 drivers/video/efi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/video/efi.c +5 -2
index fc37a68b376..0479f207032 100644
@@ -56,10 +56,12 @@ static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
  * Gets info from the graphics-output protocol
  *
  * @vesa: Place to put the mode information
+ * @infop: Returns a pointer to the mode info
  * Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
  * the protocol is not supported by EFI
  */
-static int get_mode_info(struct vesa_mode_info *vesa)
+static int get_mode_info(struct vesa_mode_info *vesa,
+			 struct efi_gop_mode_info **infop)
 {
 	efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
 	struct efi_boot_services *boot = efi_get_boot();
@@ -77,6 +79,7 @@ static int get_mode_info(struct vesa_mode_info *vesa)
 	vesa->phys_base_ptr = mode->fb_base;
 	vesa->x_resolution = mode->info->width;
 	vesa->y_resolution = mode->info->height;
+	*infop = mode->info;
 
 	return 0;
 }
@@ -118,7 +121,7 @@ static int save_vesa_mode(struct vesa_mode_info *vesa)
 	int ret;
 
 	if (IS_ENABLED(CONFIG_EFI_APP))
-		ret = get_mode_info(vesa);
+		ret = get_mode_info(vesa, &info);
 	else
 		ret = get_mode_from_entry(vesa, &info);
 	if (ret) {
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#3 lore raw

PATCH v2 3/13 efi: Support a 64-bit frame buffer address

In reply to Simon Glass

The current vesa structure only provides a 32-bit value for the frame buffer. Many modern machines use an address outside the range.

It is still useful to have this common struct, but add a separate frame-buffer address as well.

Add a comment for vesa_setup_video_priv() while we are here.

---

(no changes since v1)

 arch/x86/lib/fsp/fsp_graphics.c |  2 +-
 drivers/pci/pci_rom.c           | 10 ++++++----
 drivers/video/coreboot.c        |  2 +-
 drivers/video/efi.c             | 34 +++++++++++++++++++++------------
 include/vesa.h                  | 16 +++++++++++++++-
 5 files changed, 45 insertions(+), 19 deletions(-)
arch/x86/lib/fsp/fsp_graphics.c +1 -1
index b07c666caf7..2bcc49f6051 100644
@@ -106,7 +106,7 @@ static int fsp_video_probe(struct udevice *dev)
 	vesa->phys_base_ptr = dm_pci_read_bar32(dev, 2);
 	gd->fb_base = vesa->phys_base_ptr;
 
-	ret = vesa_setup_video_priv(vesa, uc_priv, plat);
+	ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat);
 	if (ret)
 		goto err;
 
drivers/pci/pci_rom.c +6 -4
index 47b6e6e5bcf..f0dfe631490 100644
@@ -325,7 +325,7 @@ err:
 	return ret;
 }
 
-int vesa_setup_video_priv(struct vesa_mode_info *vesa,
+int vesa_setup_video_priv(struct vesa_mode_info *vesa, u64 fb,
 			  struct video_priv *uc_priv,
 			  struct video_uc_plat *plat)
 {
@@ -348,9 +348,9 @@ int vesa_setup_video_priv(struct vesa_mode_info *vesa,
 
 	/* Use double buffering if enabled */
 	if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->base)
-		plat->copy_base = vesa->phys_base_ptr;
+		plat->copy_base = fb;
 	else
-		plat->base = vesa->phys_base_ptr;
+		plat->base = fb;
 	log_debug("base = %lx, copy_base = %lx\n", plat->base, plat->copy_base);
 	plat->size = vesa->bytes_per_scanline * vesa->y_resolution;
 
@@ -377,7 +377,9 @@ int vesa_setup_video(struct udevice *dev, int (*int15_handler)(void))
 		return ret;
 	}
 
-	ret = vesa_setup_video_priv(&mode_info.vesa, uc_priv, plat);
+	ret = vesa_setup_video_priv(&mode_info.vesa,
+				    mode_info.vesa.phys_base_ptr, uc_priv,
+				    plat);
 	if (ret) {
 		if (ret == -ENFILE) {
 			/*
drivers/video/coreboot.c +1 -1
index d2d87c75c89..c586475e41e 100644
@@ -57,7 +57,7 @@ static int coreboot_video_probe(struct udevice *dev)
 		goto err;
 	}
 
-	ret = vesa_setup_video_priv(vesa, uc_priv, plat);
+	ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat);
 	if (ret) {
 		ret = log_msg_ret("setup", ret);
 		goto err;
drivers/video/efi.c +22 -12
index 0479f207032..169637c2882 100644
@@ -5,6 +5,8 @@
  * EFI framebuffer driver based on GOP
  */
 
+#define LOG_CATEGORY LOGC_EFI
+
 #include <common.h>
 #include <dm.h>
 #include <efi_api.h>
@@ -56,11 +58,12 @@ static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
  * Gets info from the graphics-output protocol
  *
  * @vesa: Place to put the mode information
+ * @fbp: Returns the address of the frame buffer
  * @infop: Returns a pointer to the mode info
  * Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
  * the protocol is not supported by EFI
  */
-static int get_mode_info(struct vesa_mode_info *vesa,
+static int get_mode_info(struct vesa_mode_info *vesa, u64 *fbp,
 			 struct efi_gop_mode_info **infop)
 {
 	efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
@@ -74,9 +77,13 @@ static int get_mode_info(struct vesa_mode_info *vesa,
 	ret = boot->locate_protocol(&efi_gop_guid, NULL, (void **)&gop);
 	if (ret)
 		return log_msg_ret("prot", -ENOTSUPP);
-
 	mode = gop->mode;
+	log_debug("maxmode %u, mode %u, info %p, size %lx, fb %lx, fb_size %lx\n",
+		  mode->max_mode, mode->mode, mode->info, mode->info_size,
+		  (ulong)mode->fb_base, (ulong)mode->fb_size);
+
 	vesa->phys_base_ptr = mode->fb_base;
+	*fbp = mode->fb_base;
 	vesa->x_resolution = mode->info->width;
 	vesa->y_resolution = mode->info->height;
 	*infop = mode->info;
@@ -91,10 +98,11 @@ static int get_mode_info(struct vesa_mode_info *vesa,
  * it into a vesa structure. It also returns the mode information.
  *
  * @vesa: Place to put the mode information
+ * @fbp: Returns the address of the frame buffer
  * @infop: Returns a pointer to the mode info
  * Returns: 0 if OK, -ve on error
  */
-static int get_mode_from_entry(struct vesa_mode_info *vesa,
+static int get_mode_from_entry(struct vesa_mode_info *vesa, u64 *fbp,
 			       struct efi_gop_mode_info **infop)
 {
 	struct efi_gop_mode *mode;
@@ -107,6 +115,7 @@ static int get_mode_from_entry(struct vesa_mode_info *vesa,
 		return ret;
 	}
 	vesa->phys_base_ptr = mode->fb_base;
+	*fbp = mode->fb_base;
 	vesa->x_resolution = mode->info->width;
 	vesa->y_resolution = mode->info->height;
 	*infop = mode->info;
@@ -114,16 +123,17 @@ static int get_mode_from_entry(struct vesa_mode_info *vesa,
 	return 0;
 }
 
-static int save_vesa_mode(struct vesa_mode_info *vesa)
+static int save_vesa_mode(struct vesa_mode_info *vesa, u64 *fbp)
 {
 	const struct efi_framebuffer *fbinfo;
 	struct efi_gop_mode_info *info;
 	int ret;
 
+	printf("start\n");
 	if (IS_ENABLED(CONFIG_EFI_APP))
-		ret = get_mode_info(vesa, &info);
+		ret = get_mode_info(vesa, fbp, &info);
 	else
-		ret = get_mode_from_entry(vesa, &info);
+		ret = get_mode_from_entry(vesa, fbp, &info);
 	if (ret) {
 		printf("EFI graphics output protocol not found (err=%dE)\n",
 		       ret);
@@ -163,8 +173,7 @@ static int save_vesa_mode(struct vesa_mode_info *vesa)
 		vesa->bytes_per_scanline = (info->pixels_per_scanline *
 					    vesa->bits_per_pixel) / 8;
 	} else {
-		debug("efi set unknown framebuffer format: %d\n",
-		      info->pixel_format);
+		log_err("Unknown framebuffer format: %d\n", info->pixel_format);
 		return -EINVAL;
 	}
 
@@ -176,19 +185,20 @@ static int efi_video_probe(struct udevice *dev)
 	struct video_uc_plat *plat = dev_get_uclass_plat(dev);
 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
 	struct vesa_mode_info *vesa = &mode_info.vesa;
+	u64 fb;
 	int ret;
 
 	/* Initialize vesa_mode_info structure */
-	ret = save_vesa_mode(vesa);
+	ret = save_vesa_mode(vesa, &fb);
 	if (ret)
 		goto err;
 
-	ret = vesa_setup_video_priv(vesa, uc_priv, plat);
+	ret = vesa_setup_video_priv(vesa, fb, uc_priv, plat);
 	if (ret)
 		goto err;
 
-	printf("Video: %dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
-	       vesa->bits_per_pixel);
+	printf("Video: %dx%dx%d @ %lx\n", uc_priv->xsize, uc_priv->ysize,
+	       vesa->bits_per_pixel, (ulong)fb);
 
 	return 0;
 
include/vesa.h +15 -1
index a42c1796863..98112208114 100644
@@ -108,7 +108,21 @@ extern struct vesa_state mode_info;
 
 struct video_priv;
 struct video_uc_plat;
-int vesa_setup_video_priv(struct vesa_mode_info *vesa,
+
+/**
+ * vesa_setup_video_priv() - Set up a video device using VESA information
+ *
+ * The vesa struct is used by various x86 drivers, so this is a common function
+ * to use it to set up the video.
+ *
+ * @vesa: Vesa information to use (vesa->phys_base_ptr is ignored)
+ * @fb: Frame buffer address (since vesa->phys_base_ptr is only 32 bits)
+ * @uc_priv: Video device's uclass-private information
+ * @plat: Video devices's uclass-private platform data
+ * @return 0 if OK, -ENXIO if the x resolution is 0, -EEPROTONOSUPPORT if the
+ * pixel format is not supported
+ */
+int vesa_setup_video_priv(struct vesa_mode_info *vesa, u64 fb,
 			  struct video_priv *uc_priv,
 			  struct video_uc_plat *plat);
 int vesa_setup_video(struct udevice *dev, int (*int15_handler)(void));
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#4 lore raw

Re: [PATCH v2 03/13] efi: Support a 64-bit frame buffer address

Quoted 212 lines · Simon Glass

The current vesa structure only provides a 32-bit value for the frame buffer. Many modern machines use an address outside the range.

It is still useful to have this common struct, but add a separate frame-buffer address as well.

Add a comment for vesa_setup_video_priv() while we are here.

---

(no changes since v1)

  arch/x86/lib/fsp/fsp_graphics.c |  2 +-
  drivers/pci/pci_rom.c           | 10 ++++++----
  drivers/video/coreboot.c        |  2 +-
  drivers/video/efi.c             | 34 +++++++++++++++++++++------------
  include/vesa.h                  | 16 +++++++++++++++-
  5 files changed, 45 insertions(+), 19 deletions(-)
arch/x86/lib/fsp/fsp_graphics.c +1 -1
index b07c666caf7..2bcc49f6051 100644
@@ -106,7 +106,7 @@ static int fsp_video_probe(struct udevice *dev)
  	vesa->phys_base_ptr = dm_pci_read_bar32(dev, 2);
  	gd->fb_base = vesa->phys_base_ptr;
 
-	ret = vesa_setup_video_priv(vesa, uc_priv, plat);
+	ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat);
  	if (ret)
  		goto err;
 
drivers/pci/pci_rom.c +6 -4
index 47b6e6e5bcf..f0dfe631490 100644
@@ -325,7 +325,7 @@ err:
  	return ret;
  }
 
-int vesa_setup_video_priv(struct vesa_mode_info *vesa,
+int vesa_setup_video_priv(struct vesa_mode_info *vesa, u64 fb,
  			  struct video_priv *uc_priv,
  			  struct video_uc_plat *plat)
  {
@@ -348,9 +348,9 @@ int vesa_setup_video_priv(struct vesa_mode_info *vesa,
 
  	/* Use double buffering if enabled */
  	if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->base)
-		plat->copy_base = vesa->phys_base_ptr;
+		plat->copy_base = fb;
  	else
-		plat->base = vesa->phys_base_ptr;
+		plat->base = fb;
  	log_debug("base = %lx, copy_base = %lx\n", plat->base, plat->copy_base);
  	plat->size = vesa->bytes_per_scanline * vesa->y_resolution;
 
@@ -377,7 +377,9 @@ int vesa_setup_video(struct udevice *dev, int (*int15_handler)(void))
  		return ret;
  	}
 
-	ret = vesa_setup_video_priv(&mode_info.vesa, uc_priv, plat);
+	ret = vesa_setup_video_priv(&mode_info.vesa,
+				    mode_info.vesa.phys_base_ptr, uc_priv,
+				    plat);
  	if (ret) {
  		if (ret == -ENFILE) {
  			/*
drivers/video/coreboot.c +1 -1
index d2d87c75c89..c586475e41e 100644
@@ -57,7 +57,7 @@ static int coreboot_video_probe(struct udevice *dev)
  		goto err;
  	}
 
-	ret = vesa_setup_video_priv(vesa, uc_priv, plat);
+	ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat);
  	if (ret) {
  		ret = log_msg_ret("setup", ret);
  		goto err;
drivers/video/efi.c +22 -12
index 0479f207032..169637c2882 100644
@@ -5,6 +5,8 @@
   * EFI framebuffer driver based on GOP
   */
 
+#define LOG_CATEGORY LOGC_EFI
+
  #include <common.h>
  #include <dm.h>
  #include <efi_api.h>
@@ -56,11 +58,12 @@ static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
   * Gets info from the graphics-output protocol
   *
   * @vesa: Place to put the mode information
+ * @fbp: Returns the address of the frame buffer
   * @infop: Returns a pointer to the mode info
   * Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
   * the protocol is not supported by EFI
   */
-static int get_mode_info(struct vesa_mode_info *vesa,
+static int get_mode_info(struct vesa_mode_info *vesa, u64 *fbp,
  			 struct efi_gop_mode_info **infop)
  {
  	efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
@@ -74,9 +77,13 @@ static int get_mode_info(struct vesa_mode_info *vesa,
  	ret = boot->locate_protocol(&efi_gop_guid, NULL, (void **)&gop);
  	if (ret)
  		return log_msg_ret("prot", -ENOTSUPP);
-
  	mode = gop->mode;
+	log_debug("maxmode %u, mode %u, info %p, size %lx, fb %lx, fb_size %lx\n",
+		  mode->max_mode, mode->mode, mode->info, mode->info_size,
+		  (ulong)mode->fb_base, (ulong)mode->fb_size);
+
  	vesa->phys_base_ptr = mode->fb_base;
+	*fbp = mode->fb_base;
  	vesa->x_resolution = mode->info->width;
  	vesa->y_resolution = mode->info->height;
  	*infop = mode->info;
@@ -91,10 +98,11 @@ static int get_mode_info(struct vesa_mode_info *vesa,
   * it into a vesa structure. It also returns the mode information.
   *
   * @vesa: Place to put the mode information
+ * @fbp: Returns the address of the frame buffer
   * @infop: Returns a pointer to the mode info
   * Returns: 0 if OK, -ve on error
   */
-static int get_mode_from_entry(struct vesa_mode_info *vesa,
+static int get_mode_from_entry(struct vesa_mode_info *vesa, u64 *fbp,
  			       struct efi_gop_mode_info **infop)
  {
  	struct efi_gop_mode *mode;
@@ -107,6 +115,7 @@ static int get_mode_from_entry(struct vesa_mode_info *vesa,
  		return ret;
  	}
  	vesa->phys_base_ptr = mode->fb_base;
+	*fbp = mode->fb_base;
  	vesa->x_resolution = mode->info->width;
  	vesa->y_resolution = mode->info->height;
  	*infop = mode->info;
@@ -114,16 +123,17 @@ static int get_mode_from_entry(struct vesa_mode_info *vesa,
  	return 0;
  }
 
-static int save_vesa_mode(struct vesa_mode_info *vesa)
+static int save_vesa_mode(struct vesa_mode_info *vesa, u64 *fbp)
  {
  	const struct efi_framebuffer *fbinfo;
  	struct efi_gop_mode_info *info;
  	int ret;
 
+	printf("start\n");
  	if (IS_ENABLED(CONFIG_EFI_APP))
-		ret = get_mode_info(vesa, &info);
+		ret = get_mode_info(vesa, fbp, &info);
  	else
-		ret = get_mode_from_entry(vesa, &info);
+		ret = get_mode_from_entry(vesa, fbp, &info);
  	if (ret) {
  		printf("EFI graphics output protocol not found (err=%dE)\n",
  		       ret);
@@ -163,8 +173,7 @@ static int save_vesa_mode(struct vesa_mode_info *vesa)
  		vesa->bytes_per_scanline = (info->pixels_per_scanline *
  					    vesa->bits_per_pixel) / 8;
  	} else {
-		debug("efi set unknown framebuffer format: %d\n",
-		      info->pixel_format);
+		log_err("Unknown framebuffer format: %d\n", info->pixel_format);
  		return -EINVAL;
  	}
 
@@ -176,19 +185,20 @@ static int efi_video_probe(struct udevice *dev)
  	struct video_uc_plat *plat = dev_get_uclass_plat(dev);
  	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  	struct vesa_mode_info *vesa = &mode_info.vesa;
+	u64 fb;
  	int ret;
 
  	/* Initialize vesa_mode_info structure */
-	ret = save_vesa_mode(vesa);
+	ret = save_vesa_mode(vesa, &fb);
  	if (ret)
  		goto err;
 
-	ret = vesa_setup_video_priv(vesa, uc_priv, plat);
+	ret = vesa_setup_video_priv(vesa, fb, uc_priv, plat);
  	if (ret)
  		goto err;
 
-	printf("Video: %dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
-	       vesa->bits_per_pixel);
+	printf("Video: %dx%dx%d @ %lx\n", uc_priv->xsize, uc_priv->ysize,
+	       vesa->bits_per_pixel, (ulong)fb);
 
  	return 0;
 
include/vesa.h +2 -1
index a42c1796863..98112208114 100644
@@ -108,7 +108,21 @@ extern struct vesa_state mode_info;
 
  struct video_priv;
  struct video_uc_plat;
-int vesa_setup_video_priv(struct vesa_mode_info *vesa,
+
+/**

include/vesa.h extern struct vesa_state mode_info; · line 122

Quoted 10 lines
include/vesa.h +10 -0
+ * vesa_setup_video_priv() - Set up a video device using VESA information
+ *
+ * The vesa struct is used by various x86 drivers, so this is a common function
+ * to use it to set up the video.
+ *
+ * @vesa: Vesa information to use (vesa->phys_base_ptr is ignored)
+ * @fb: Frame buffer address (since vesa->phys_base_ptr is only 32 bits)
+ * @uc_priv: Video device's uclass-private information
+ * @plat: Video devices's uclass-private platform data
+ * @return 0 if OK, -ENXIO if the x resolution is 0, -EEPROTONOSUPPORT if the

%s/@return/Return:/g

cf. https://docs.kernel.org/doc-guide/kernel-doc.html#return-values

Best regards

Heinrich

Quoted 6 lines
include/vesa.h +3 -0
+ * pixel format is not supported
+ */
+int vesa_setup_video_priv(struct vesa_mode_info *vesa, u64 fb,
  			  struct video_priv *uc_priv,
  			  struct video_uc_plat *plat);
  int vesa_setup_video(struct udevice *dev, int (*int15_handler)(void));
#5 lore raw

PATCH v2 4/13 x86: Add a few more items to bdinfo

In reply to Simon Glass

Add the timer and vendor/model information.

---

(no changes since v1)

 arch/x86/lib/bdinfo.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/lib/bdinfo.c +4 -0
index 0cb79b01bd3..896de37dce4 100644
@@ -16,6 +16,10 @@ DECLARE_GLOBAL_DATA_PTR;
 void arch_print_bdinfo(void)
 {
 	bdinfo_print_num_l("prev table", gd->arch.table);
+	bdinfo_print_num_l("clock_rate", gd->arch.clock_rate);
+	bdinfo_print_num_l("tsc_base", gd->arch.tsc_base);
+	bdinfo_print_num_l("vendor", gd->arch.x86_vendor);
+	bdinfo_print_num_l("model", gd->arch.x86_model);
 
 	if (IS_ENABLED(CONFIG_EFI_STUB))
 		efi_show_bdinfo();
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#6 lore raw

Re: [PATCH v2 04/13] x86: Add a few more items to bdinfo

Quoted 15 lines · Simon Glass

Add the timer and vendor/model information.

---

(no changes since v1)

  arch/x86/lib/bdinfo.c | 4 ++++
  1 file changed, 4 insertions(+)
arch/x86/lib/bdinfo.c +0 -0
index 0cb79b01bd3..896de37dce4 100644

arch/x86/lib/bdinfo.c DECLARE_GLOBAL_DATA_PTR; · line 21

Quoted 6 lines
arch/x86/lib/bdinfo.c +3 -0
@@ -16,6 +16,10 @@ DECLARE_GLOBAL_DATA_PTR;
  void arch_print_bdinfo(void)
  {
  	bdinfo_print_num_l("prev table", gd->arch.table);
+	bdinfo_print_num_l("clock_rate", gd->arch.clock_rate);
+	bdinfo_print_num_l("tsc_base", gd->arch.tsc_base);
+	bdinfo_print_num_l("vendor", gd->arch.x86_vendor);

Who would know which vendor uses which number? Please, use cpu_vendor_name() and present a string.

Best regards

Heinrich

Quoted 4 lines
arch/x86/lib/bdinfo.c +1 -0
+	bdinfo_print_num_l("model", gd->arch.x86_model);
 
  	if (IS_ENABLED(CONFIG_EFI_STUB))
  		efi_show_bdinfo();
#7 lore raw

PATCH v2 5/13 efi: Use a fixed value for the timer clock

In reply to Simon Glass

It is not yet clear how to read the timer via EFI. The current value seems much too high on a Framework laptop I tried. Adjust it to a lower hard-coded value for now.

---

(no changes since v1)

 drivers/timer/tsc_timer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/timer/tsc_timer.c +4 -0
index 192c7b71a5a..1d2a3f20e4e 100644
@@ -404,6 +404,10 @@ static void tsc_timer_ensure_setup(bool early)
 	if (!gd->arch.clock_rate) {
 		unsigned long fast_calibrate;
 
+		if (IS_ENABLED(CONFIG_EFI_APP)) {
+			fast_calibrate = 2750;
+			goto done;
+		}
 		fast_calibrate = native_calibrate_tsc();
 		if (fast_calibrate)
 			goto done;
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#8 lore raw

Re: [PATCH v2 05/13] efi: Use a fixed value for the timer clock

Quoted 17 lines · Simon Glass

It is not yet clear how to read the timer via EFI. The current value seems much too high on a Framework laptop I tried. Adjust it to a lower hard-coded value for now.

---

(no changes since v1)

  drivers/timer/tsc_timer.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/timer/tsc_timer.c +0 -0
index 192c7b71a5a..1d2a3f20e4e 100644

drivers/timer/tsc_timer.c static void tsc_timer_ensure_setup(bool early) · line 407

Quoted 4 lines
drivers/timer/tsc_timer.c +1 -0
@@ -404,6 +404,10 @@ static void tsc_timer_ensure_setup(bool early)
  	if (!gd->arch.clock_rate) {
  		unsigned long fast_calibrate;
 
+		if (IS_ENABLED(CONFIG_EFI_APP)) {

This needs a code comment telling why you use this 2.75 GHz value.

Why would none of the methods in tsc_timer_ensure_setup() work correctly in the EFI app?

Best regards

Heinrich

Quoted 6 lines
drivers/timer/tsc_timer.c +3 -0
+			fast_calibrate = 2750;
+			goto done;
+		}
  		fast_calibrate = native_calibrate_tsc();
  		if (fast_calibrate)
  			goto done;
#9 lore raw

PATCH v2 6/13 efi: Support copy framebuffer

In reply to Simon Glass

Add support for this to EFI in case it becomes useful. At present it just slows things down. You can enable CONFIG_VIDEO_COPY to turn it on.

---

Changes in v2:
- Obtain copy framebuffer size from EFI instead of using a fixed value
- Dropping debugging printf()
- use new bootph-xxx tag

 arch/x86/dts/efi-x86_app.dts |  1 +
 drivers/video/efi.c          | 25 ++++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
arch/x86/dts/efi-x86_app.dts +1 -0
index 6d843a9820b..59e2e402d5e 100644
@@ -27,6 +27,7 @@
 	};
 	efi-fb {
 		compatible = "efi-fb";
+		bootph-some-ram;
 	};
 
 };
drivers/video/efi.c +24 -1
index 169637c2882..a8e9282ab87 100644
@@ -129,7 +129,6 @@ static int save_vesa_mode(struct vesa_mode_info *vesa, u64 *fbp)
 	struct efi_gop_mode_info *info;
 	int ret;
 
-	printf("start\n");
 	if (IS_ENABLED(CONFIG_EFI_APP))
 		ret = get_mode_info(vesa, fbp, &info);
 	else
@@ -207,6 +206,29 @@ err:
 	return ret;
 }
 
+static int efi_video_bind(struct udevice *dev)
+{
+	if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
+		struct video_uc_plat *plat = dev_get_uclass_plat(dev);
+		struct vesa_mode_info vesa;
+		int ret;
+		u64 fb;
+
+		/*
+		 * Initialise vesa_mode_info structure so we can figure out the
+		 * required framebuffer size. If something goes wrong, just do
+		 * without a copy framebuffer
+		 */
+		ret = save_vesa_mode(&vesa, &fb);
+		if (!ret) {
+			plat->copy_size = vesa.bytes_per_scanline *
+				vesa.y_resolution;
+		}
+	}
+
+	return 0;
+}
+
 static const struct udevice_id efi_video_ids[] = {
 	{ .compatible = "efi-fb" },
 	{ }
@@ -216,5 +238,6 @@ U_BOOT_DRIVER(efi_video) = {
 	.name	= "efi_video",
 	.id	= UCLASS_VIDEO,
 	.of_match = efi_video_ids,
+	.bind	= efi_video_bind,
 	.probe	= efi_video_probe,
 };
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#10 lore raw

Re: [PATCH v2 06/13] efi: Support copy framebuffer

Quoted 40 lines · Simon Glass

Add support for this to EFI in case it becomes useful. At present it just slows things down. You can enable CONFIG_VIDEO_COPY to turn it on.

---

Changes in v2:
- Obtain copy framebuffer size from EFI instead of using a fixed value
- Dropping debugging printf()
- use new bootph-xxx tag

  arch/x86/dts/efi-x86_app.dts |  1 +
  drivers/video/efi.c          | 25 ++++++++++++++++++++++++-
  2 files changed, 25 insertions(+), 1 deletion(-)
arch/x86/dts/efi-x86_app.dts +1 -0
index 6d843a9820b..59e2e402d5e 100644
@@ -27,6 +27,7 @@
  	};
  	efi-fb {
  		compatible = "efi-fb";
+		bootph-some-ram;
  	};
 
  };
drivers/video/efi.c +0 -1
index 169637c2882..a8e9282ab87 100644
@@ -129,7 +129,6 @@ static int save_vesa_mode(struct vesa_mode_info *vesa, u64 *fbp)
  	struct efi_gop_mode_info *info;
  	int ret;
 
-	printf("start\n");
  	if (IS_ENABLED(CONFIG_EFI_APP))
  		ret = get_mode_info(vesa, fbp, &info);
  	else

drivers/video/efi.c err: · line 213

Quoted 8 lines
drivers/video/efi.c +5 -0
@@ -207,6 +206,29 @@ err:
  	return ret;
  }
 
+static int efi_video_bind(struct udevice *dev)
+{
+	if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
+		struct video_uc_plat *plat = dev_get_uclass_plat(dev);
+		struct vesa_mode_info vesa;

struct vesa_mode_info vesa = {0};

see below

drivers/video/efi.c err: · line 225

Quoted 12 lines
drivers/video/efi.c +12 -0
+		int ret;
+		u64 fb;
+
+		/*
+		 * Initialise vesa_mode_info structure so we can figure out the
+		 * required framebuffer size. If something goes wrong, just do
+		 * without a copy framebuffer
+		 */
+		ret = save_vesa_mode(&vesa, &fb);
+		if (!ret) {
+			plat->copy_size = vesa.bytes_per_scanline *
+				vesa.y_resolution;

If there is no EFI_GRAPHICS_OUTPUT_PROTOCOL, ret = -ENXIO but vesa is *not* initialized. You don't want to use random bytes from the stack to calculate copy_size and afterwards write into a non-existent framebuffer.

If you initialize vesa to zero, you can test if copy_size == 0 and in this case return 1 to indicate that binding failed.

Best regards

Heinrich

Quoted 16 lines
drivers/video/efi.c +7 -0
+		}
+	}
+
+	return 0;
+}
+
  static const struct udevice_id efi_video_ids[] = {
  	{ .compatible = "efi-fb" },
  	{ }
@@ -216,5 +238,6 @@ U_BOOT_DRIVER(efi_video) = {
  	.name	= "efi_video",
  	.id	= UCLASS_VIDEO,
  	.of_match = efi_video_ids,
+	.bind	= efi_video_bind,
  	.probe	= efi_video_probe,
  };
#11 lore raw

Re: [PATCH v2 06/13] efi: Support copy framebuffer

Hi Heinrich,

Quoted 68 lines · Heinrich Schuchardt
Quoted 40 lines · Simon Glass

Add support for this to EFI in case it becomes useful. At present it just slows things down. You can enable CONFIG_VIDEO_COPY to turn it on.

---

Changes in v2:
- Obtain copy framebuffer size from EFI instead of using a fixed value
- Dropping debugging printf()
- use new bootph-xxx tag

  arch/x86/dts/efi-x86_app.dts |  1 +
  drivers/video/efi.c          | 25 ++++++++++++++++++++++++-
  2 files changed, 25 insertions(+), 1 deletion(-)
arch/x86/dts/efi-x86_app.dts +1 -0
index 6d843a9820b..59e2e402d5e 100644
@@ -27,6 +27,7 @@
      };
      efi-fb {
              compatible = "efi-fb";
+             bootph-some-ram;
      };
 
  };
drivers/video/efi.c +0 -1
index 169637c2882..a8e9282ab87 100644
@@ -129,7 +129,6 @@ static int save_vesa_mode(struct vesa_mode_info *vesa, u64 *fbp)
      struct efi_gop_mode_info *info;
      int ret;
 
-     printf("start\n");
      if (IS_ENABLED(CONFIG_EFI_APP))
              ret = get_mode_info(vesa, fbp, &info);
      else

drivers/video/efi.c err: · line 213

Quoted 8 lines
drivers/video/efi.c +5 -0
@@ -207,6 +206,29 @@ err:
      return ret;
  }
 
+static int efi_video_bind(struct udevice *dev)
+{
+     if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
+             struct video_uc_plat *plat = dev_get_uclass_plat(dev);
+             struct vesa_mode_info vesa;

struct vesa_mode_info vesa = {0};

see below

drivers/video/efi.c err: · line 225

Quoted 12 lines
drivers/video/efi.c +12 -0
+             int ret;
+             u64 fb;
+
+             /*
+              * Initialise vesa_mode_info structure so we can figure out the
+              * required framebuffer size. If something goes wrong, just do
+              * without a copy framebuffer
+              */
+             ret = save_vesa_mode(&vesa, &fb);
+             if (!ret) {
+                     plat->copy_size = vesa.bytes_per_scanline *
+                             vesa.y_resolution;
Quoted 3 lines

If there is no EFI_GRAPHICS_OUTPUT_PROTOCOL, ret = -ENXIO but vesa is *not* initialized. You don't want to use random bytes from the stack to calculate copy_size and afterwards write into a non-existent framebuffer.

But if ret is -ENXIO then the copy size is not set, right?

Quoted 3 lines

If you initialize vesa to zero, you can test if copy_size == 0 and in this case return 1 to indicate that binding failed.

If it fails we just don't have a copy buffer. Everything still works OK.

Regards,
Simon

#12 lore raw

PATCH v2 7/13 video: Allow a copy framebuffer with pre-allocated fb

In reply to Simon Glass

At present it is not possible for the video driver to use a pre-allocated frame buffer (such as is done with EFI) with the copy framebuffer. This can be useful to speed up the display.

Adjust the implementation so that copy_size can be set to the required size, with this being allocated if the normal framebuffer size is 0.

---

(no changes since v1)

 drivers/video/video-uclass.c | 32 ++++++++++++++++++++++++--------
 include/video.h              |  2 ++
 2 files changed, 26 insertions(+), 8 deletions(-)
drivers/video/video-uclass.c +24 -8
index ab482f11e5d..da89f431441 100644
@@ -78,24 +78,40 @@ void video_set_flush_dcache(struct udevice *dev, bool flush)
 	priv->flush_dcache = flush;
 }
 
+static ulong alloc_fb_(ulong align, ulong size, ulong *addrp)
+{
+	ulong base;
+
+	align = align ? align : 1 << 20;
+	base = *addrp - size;
+	base &= ~(align - 1);
+	size = *addrp - base;
+	*addrp = base;
+
+	return size;
+}
+
 static ulong alloc_fb(struct udevice *dev, ulong *addrp)
 {
 	struct video_uc_plat *plat = dev_get_uclass_plat(dev);
-	ulong base, align, size;
+	ulong size;
+
+	if (!plat->size) {
+		if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_size) {
+			size = alloc_fb_(plat->align, plat->copy_size, addrp);
+			plat->copy_base = *addrp;
+			return size;
+		}
 
-	if (!plat->size)
 		return 0;
+	}
 
 	/* Allow drivers to allocate the frame buffer themselves */
 	if (plat->base)
 		return 0;
 
-	align = plat->align ? plat->align : 1 << 20;
-	base = *addrp - plat->size;
-	base &= ~(align - 1);
-	plat->base = base;
-	size = *addrp - base;
-	*addrp = base;
+	size = alloc_fb_(plat->align, plat->size, addrp);
+	plat->base = *addrp;
 
 	return size;
 }
include/video.h +2 -0
index 3f67a93bc93..4d99e5dc27f 100644
@@ -24,6 +24,7 @@ struct udevice;
  * @base: Base address of frame buffer, 0 if not yet known
  * @copy_base: Base address of a hardware copy of the frame buffer. See
  *	CONFIG_VIDEO_COPY.
+ * @copy_size: Size of copy framebuffer, used if @size is 0
  * @hide_logo: Hide the logo (used for testing)
  */
 struct video_uc_plat {
@@ -31,6 +32,7 @@ struct video_uc_plat {
 	uint size;
 	ulong base;
 	ulong copy_base;
+	ulong copy_size;
 	bool hide_logo;
 };
 
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#13 lore raw

PATCH v2 8/13 bbinfo: Show the size of the copy framebuffer

In reply to Simon Glass

If the copy framebuffer is enabled, show its size.

---

Changes in v2:
- Add new patch to show the size of the copy framebuffer with bdinfo

 cmd/bdinfo.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
cmd/bdinfo.c +5 -1
index bf002f84475..a75299f822f 100644
@@ -83,11 +83,15 @@ static void show_video_info(void)
 		       device_active(dev) ? "" : "in");
 		if (device_active(dev)) {
 			struct video_priv *upriv = dev_get_uclass_priv(dev);
+			struct video_uc_plat *plat = dev_get_uclass_plat(dev);
 
 			bdinfo_print_num_ll("FB base", (ulong)upriv->fb);
-			if (upriv->copy_fb)
+			if (upriv->copy_fb) {
 				bdinfo_print_num_ll("FB copy",
 						    (ulong)upriv->copy_fb);
+				bdinfo_print_num_l(" copy size",
+						   plat->copy_size);
+			}
 			printf("%-12s= %dx%dx%d\n", "FB size", upriv->xsize,
 			       upriv->ysize, 1 << upriv->bpix);
 		}
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#14 lore raw

PATCH v2 9/13 efi: Adjust script to show pre-relocation output on terminal

In reply to Simon Glass

When running with video enabled, the pre-relocation output of U-Boot is currently lost. Add a -serial flag to show it on the terminal.

---

(no changes since v1)

 scripts/build-efi.sh | 2 ++
 1 file changed, 2 insertions(+)
scripts/build-efi.sh +2 -0
index bc9aeebbf4f..46c28807ef1 100755
@@ -96,6 +96,8 @@ run_qemu() {
 	fi
 	if [[ -n "${serial}" ]]; then
 		extra="-display none -serial mon:stdio"
+	else
+		extra="-serial mon:stdio"
 	fi
 	echo "Running ${qemu}"
 	# Use 512MB since U-Boot EFI likes to have 256MB to play with
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#15 lore raw

PATCH v2 10/13 video: Remove duplicate cursor-positioning function

In reply to Simon Glass

There are two functions for positioning the cursor on the console. Remove one of them.

---

(no changes since v1)

 drivers/video/vidconsole-uclass.c | 44 +++++++------------------------
 1 file changed, 10 insertions(+), 34 deletions(-)
drivers/video/vidconsole-uclass.c +10 -34
index 72a13d30527..9f8b8ebe8ac 100644
@@ -126,26 +126,14 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y)
 	priv->ycur = y;
 }
 
-/**
- * set_cursor_position() - set cursor position
- *
- * @priv:	private data of the video console
- * @row:	new row
- * @col:	new column
- */
-static void set_cursor_position(struct vidconsole_priv *priv, int row, int col)
+void vidconsole_position_cursor(struct udevice *dev, uint col, uint row)
 {
-	/*
-	 * Ensure we stay in the bounds of the screen.
-	 */
-	if (row >= priv->rows)
-		row = priv->rows - 1;
-	if (col >= priv->cols)
-		col = priv->cols - 1;
-
-	priv->ycur = row * priv->y_charsize;
-	priv->xcur_frac = priv->xstart_frac +
-			  VID_TO_POS(col * priv->x_charsize);
+	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+	short x, y;
+
+	x = min_t(short, col, priv->cols - 1) * priv->x_charsize;
+	y = min_t(short, row, priv->rows - 1) * priv->y_charsize;
+	vidconsole_set_cursor_pos(dev, x, y);
 }
 
 /**
@@ -192,7 +180,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)
 			int row = priv->row_saved;
 			int col = priv->col_saved;
 
-			set_cursor_position(priv, row, col);
+			vidconsole_position_cursor(dev, col, row);
 			priv->escape = 0;
 			return;
 		}
@@ -254,7 +242,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)
 		if (row < 0)
 			row = 0;
 		/* Right and bottom overflows are handled in the callee. */
-		set_cursor_position(priv, row, col);
+		vidconsole_position_cursor(dev, col, row);
 		break;
 	}
 	case 'H':
@@ -278,7 +266,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)
 		if (col)
 			--col;
 
-		set_cursor_position(priv, row, col);
+		vidconsole_position_cursor(dev, col, row);
 
 		break;
 	}
@@ -644,15 +632,3 @@ int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
 	return vidconsole_sync_copy(dev, dst, dst + size);
 }
 #endif
-
-void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row)
-{
-	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct udevice *vid_dev = dev->parent;
-	struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
-	short x, y;
-
-	x = min_t(short, col * priv->x_charsize, vid_priv->xsize - 1);
-	y = min_t(short, row * priv->y_charsize, vid_priv->ysize - 1);
-	vidconsole_set_cursor_pos(dev, x, y);
-}
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#16 lore raw

PATCH v2 11/13 video: Clear the vidconsole rather than the video

In reply to Simon Glass

It is better to clear the console device rather than the video device, since the console has the text display. We also need to reset the cursor position with the console, but not with the video device.

Add a new function to handle this and update the 'cls' command to use it.

---

(no changes since v1)

 cmd/cls.c                         | 12 ++++++++----
 drivers/video/vidconsole-uclass.c | 12 ++++++++++++
 include/video_console.h           |  9 +++++++++
 3 files changed, 29 insertions(+), 4 deletions(-)
cmd/cls.c +8 -4
index 40a32eeab63..073ba5a6c86 100644
@@ -8,7 +8,7 @@
 #include <common.h>
 #include <command.h>
 #include <dm.h>
-#include <video.h>
+#include <video_console.h>
 
 #define CSI "\x1b["
 
@@ -19,12 +19,16 @@ static int do_video_clear(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/*  Send clear screen and home */
 	printf(CSI "2J" CSI "1;1H");
-	if (IS_ENABLED(CONFIG_VIDEO) && !IS_ENABLED(CONFIG_VIDEO_ANSI)) {
-		if (uclass_first_device_err(UCLASS_VIDEO, &dev))
+	if (IS_ENABLED(CONFIG_VIDEO_ANSI))
+		return 0;
+
+	if (IS_ENABLED(CONFIG_VIDEO)) {
+		if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
 			return CMD_RET_FAILURE;
-		if (video_clear(dev))
+		if (vidconsole_clear_and_reset(dev))
 			return CMD_RET_FAILURE;
 	}
+
 	return CMD_RET_SUCCESS;
 }
 
drivers/video/vidconsole-uclass.c +12 -0
index 9f8b8ebe8ac..1bb36bd66c7 100644
@@ -632,3 +632,15 @@ int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
 	return vidconsole_sync_copy(dev, dst, dst + size);
 }
 #endif
+
+int vidconsole_clear_and_reset(struct udevice *dev)
+{
+	int ret;
+
+	ret = video_clear(dev_get_parent(dev));
+	if (ret)
+		return ret;
+	vidconsole_position_cursor(dev, 0, 0);
+
+	return 0;
+}
include/video_console.h +9 -0
index 9d2c0f210e4..aebf1d5eb99 100644
@@ -276,6 +276,15 @@ int vidconsole_put_string(struct udevice *dev, const char *str);
 void vidconsole_position_cursor(struct udevice *dev, unsigned col,
 				unsigned row);
 
+/**
+ * vidconsole_clear_and_reset() - Clear the console and reset the cursor
+ *
+ * The cursor is placed at the start of the console
+ *
+ * @dev:	vidconsole device to adjust
+ */
+int vidconsole_clear_and_reset(struct udevice *dev);
+
 /**
  * vidconsole_set_cursor_pos() - set cursor position
  *
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#17 lore raw

PATCH v2 12/13 efi: Add dhrystone, dcache and scroll lines to app

In reply to Simon Glass

Add these options to provide some performance measurement, see cache status and slightly speed up the appallingly slow console.

---

(no changes since v1)

 configs/efi-x86_app64_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/efi-x86_app64_defconfig +3 -0
index 605d49ff8cb..dae48840493 100644
@@ -22,6 +22,7 @@ CONFIG_SYS_PBSIZE=532
 # CONFIG_CMD_BOOTM is not set
 CONFIG_CMD_PART=y
 # CONFIG_CMD_NET is not set
+CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
@@ -39,7 +40,9 @@ CONFIG_BOOTFILE="bzImage"
 CONFIG_USE_ROOTPATH=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
+CONFIG_CONSOLE_SCROLL_LINES=5
 # CONFIG_REGEX is not set
+CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
 CONFIG_EFI=y
 CONFIG_EFI_APP_64BIT=y
Signature · 1 line
2.39.2.637.g21b0678d19-goog
#18 lore raw

PATCH v2 13/13 video: Add a note about the broken implementation

In reply to Simon Glass

The cls command is broken. Previous discussion about this was at [1] and [2]. For now, add a note to the source code.

[1] https://patchwork.ozlabs.org/project/uboot/patch/

       [email protected]/
[2] https://patchwork.ozlabs.org/project/uboot/patch/
       [email protected]/

---

(no changes since v1)

 cmd/cls.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
cmd/cls.c +7 -1
index 073ba5a6c86..1125a3f81bb 100644
@@ -17,7 +17,13 @@ static int do_video_clear(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	__maybe_unused struct udevice *dev;
 
-	/*  Send clear screen and home */
+	/*
+	 * Send clear screen and home
+	 *
+	 * FIXME(Heinrich Schuchardt <[email protected]>): This should go
+	 * through an API and only be written to serial terminals, not video
+	 * displays
+	 */
 	printf(CSI "2J" CSI "1;1H");
 	if (IS_ENABLED(CONFIG_VIDEO_ANSI))
 		return 0;
Signature · 1 line
2.39.2.637.g21b0678d19-goog