From 5144e9479c6b31cac33e98b5ae00a6d103f19462 Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Tue, 22 Aug 2023 18:05:29 +0300 Subject: [PATCH] WIP: video: Replace all video_sync calls with a cyclic function --- boot/expo.c | 2 -- cmd/video.c | 2 -- drivers/serial/sandbox.c | 2 -- drivers/video/Kconfig | 1 + drivers/video/vidconsole-uclass.c | 35 +++---------------------------- drivers/video/video-uclass.c | 28 ++++++++++++++++++++++++- drivers/video/video_bmp.c | 2 +- include/video.h | 2 ++ lib/efi_loader/efi_gop.c | 2 -- 9 files changed, 34 insertions(+), 42 deletions(-) diff --git a/boot/expo.c b/boot/expo.c index 139d684f8e6e..03e858c03c80 100644 --- a/boot/expo.c +++ b/boot/expo.c @@ -208,8 +208,6 @@ int expo_render(struct expo *exp) return log_msg_ret("ren", ret); } - video_sync(dev, true); - return scn ? 0 : -ECHILD; } diff --git a/cmd/video.c b/cmd/video.c index 942f81c16336..98de2c9f1b8d 100644 --- a/cmd/video.c +++ b/cmd/video.c @@ -42,8 +42,6 @@ static int do_video_puts(struct cmd_tbl *cmdtp, int flag, int argc, if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) return CMD_RET_FAILURE; ret = vidconsole_put_string(dev, argv[1]); - if (!ret) - ret = video_sync(dev->parent, false); return ret ? CMD_RET_FAILURE : 0; } diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index f4003811ee75..586e1154a327 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -139,8 +139,6 @@ static int sandbox_serial_pending(struct udevice *dev, bool input) return 0; os_usleep(100); - if (IS_ENABLED(CONFIG_VIDEO) && !IS_ENABLED(CONFIG_SPL_BUILD)) - video_sync_all(); avail = membuff_putraw(&priv->buf, 100, false, &data); if (!avail) return 1; /* buffer full */ diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 09f2cb1a7321..530485102c78 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -7,6 +7,7 @@ menu "Graphics support" config VIDEO bool "Enable driver model support for LCD/video" depends on DM + select CYCLIC help This enables driver model for LCD and video devices. These support a bitmap display of various sizes and depths which can be drawn on diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index b5b3b6625902..876e80f9ebe5 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -77,7 +77,7 @@ static int vidconsole_back(struct udevice *dev) if (priv->ycur < 0) priv->ycur = 0; } - return video_sync(dev->parent, false); + return 0; } /* Move to a newline, scrolling the display if necessary */ @@ -87,7 +87,7 @@ static void vidconsole_newline(struct udevice *dev) struct udevice *vid_dev = dev->parent; struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); const int rows = CONFIG_VAL(CONSOLE_SCROLL_LINES); - int i, ret; + int i; priv->xcur_frac = priv->xstart_frac; priv->ycur += priv->y_charsize; @@ -101,13 +101,6 @@ static void vidconsole_newline(struct udevice *dev) priv->ycur -= rows * priv->y_charsize; } priv->last_ch = 0; - - ret = video_sync(dev->parent, false); - if (ret) { -#ifdef DEBUG - console_puts_select_stderr(true, "[vc err: video_sync]"); -#endif - } } static char *parsenum(char *s, int *num) @@ -298,15 +291,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) parsenum(priv->escape_buf + 1, &mode); if (mode == 2) { - int ret; - video_clear(dev->parent); - ret = video_sync(dev->parent, false); - if (ret) { -#ifdef DEBUG - console_puts_select_stderr(true, "[vc err: video_sync]"); -#endif - } priv->ycur = 0; priv->xcur_frac = priv->xstart_frac; } else { @@ -520,12 +505,6 @@ static void vidconsole_putc(struct stdio_dev *sdev, const char ch) if (ret) { #ifdef DEBUG console_puts_select_stderr(true, "[vc err: putc]"); -#endif - } - ret = video_sync(dev->parent, false); - if (ret) { -#ifdef DEBUG - console_puts_select_stderr(true, "[vc err: video_sync]"); #endif } } @@ -542,12 +521,6 @@ static void vidconsole_puts(struct stdio_dev *sdev, const char *s) snprintf(str, sizeof(str), "[vc err: puts %d]", ret); console_puts_select_stderr(true, str); -#endif - } - ret = video_sync(dev->parent, false); - if (ret) { -#ifdef DEBUG - console_puts_select_stderr(true, "[vc err: video_sync]"); #endif } } @@ -685,9 +658,7 @@ UCLASS_DRIVER(vidconsole) = { #ifdef CONFIG_VIDEO_COPY int vidconsole_sync_copy(struct udevice *dev, void *from, void *to) { - struct udevice *vid = dev_get_parent(dev); - - return video_sync_copy(vid, from, to); + return 0; } int vidconsole_memmove(struct udevice *dev, void *dst, const void *src, diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index f743ed74c818..099ba5acaa9b 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -6,6 +6,7 @@ #define LOG_CATEGORY UCLASS_VIDEO #include +#include #include #include #include @@ -249,7 +250,7 @@ int video_fill(struct udevice *dev, u32 colour) if (ret) return ret; - return video_sync(dev, false); + return 0; } int video_clear(struct udevice *dev) @@ -351,6 +352,24 @@ void video_set_default_colors(struct udevice *dev, bool invert) priv->colour_bg = video_index_to_colour(priv, back); } +static void video_cyclic(void *ctx) +{ + struct udevice *dev = ctx; + int ret; + + if (!device_active(dev)) + return; + + video_sync_copy_all(dev); + + ret = video_sync(dev, true); + if (ret) { +#ifdef DEBUG + console_puts_select_stderr(true, "[vc err: video_sync]"); +#endif + } +} + /* Flush video activity to the caches */ int video_sync(struct udevice *vid, bool force) { @@ -603,6 +622,13 @@ static int video_post_probe(struct udevice *dev) } } + /* Register video sync as a cyclic function at 60Hz */ + priv->cyclic = cyclic_register(video_cyclic, 16666, dev->name, dev); + if (!priv->cyclic) { + log_err("cyclic_register for %s video sync failed\n", dev->name); + return -ENODEV; + } + return 0; }; diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c index 45f003c8251a..90a0e4e98b11 100644 --- a/drivers/video/video_bmp.c +++ b/drivers/video/video_bmp.c @@ -466,5 +466,5 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, if (ret) return log_ret(ret); - return video_sync(dev, false); + return 0; } diff --git a/include/video.h b/include/video.h index 66d109ca5da6..31aa8df171fa 100644 --- a/include/video.h +++ b/include/video.h @@ -8,6 +8,7 @@ #define _VIDEO_H_ #include +#include struct udevice; @@ -118,6 +119,7 @@ struct video_priv { bool flush_dcache; u8 fg_col_idx; u8 bg_col_idx; + struct cyclic_info *cyclic; }; /** diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 778b693f983a..56ca0482d871 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -451,8 +451,6 @@ static efi_status_t EFIAPI gop_blt(struct efi_gop *this, if (ret != EFI_SUCCESS) return EFI_EXIT(ret); - video_sync_all(); - return EFI_EXIT(EFI_SUCCESS); } -- 2.40.1