From 8495595d9177f6de69ebd2d478594968debaa685 Mon Sep 17 00:00:00 2001 From: LeoLiu-oc Date: Wed, 13 Aug 2025 20:35:24 +0800 Subject: [PATCH] Optimizations for Zhaoxin processors and graphics cards Signed-off-by: LeoLiu-oc --- ...puid-family-when-flush-cache-only-on.patch | 39 +++++++++ ...time-of-set-VESA-mode-by-clearing-FB.patch | 82 +++++++++++++++++++ grub.patches | 2 + grub2.spec | 9 +- 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 0001-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch create mode 100644 0002-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch diff --git a/0001-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch b/0001-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch new file mode 100644 index 0000000..713c8da --- /dev/null +++ b/0001-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch @@ -0,0 +1,39 @@ +From e2ea843d0062d89586165cd38b7628279a9d4b51 Mon Sep 17 00:00:00 2001 +From: LeoLiu-oc +Date: Wed, 13 Aug 2025 20:28:33 +0800 +Subject: [PATCH 1/2] i386: Check for cpuid family when flush cache only on VIA + CPUs + +Due to company changes, Zhaoxin is currently using the CPU ID +CentaurHauls. +CPUs designed and developed by Zhaoxin start with a family of 7, and the +model may be less than 10. + +Zhaoxin CPUs do not have cache coherence problems, add this patch to +avoid executing wbinvd on Zhaoxin CPUs. + +Signed-off-by: Tony W Wang-oc +Signed-off-by: LeoLiu-oc +--- + grub-core/kern/i386/pc/init.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c +index 326d491..f42c129 100644 +--- a/grub-core/kern/i386/pc/init.c ++++ b/grub-core/kern/i386/pc/init.c +@@ -204,6 +204,11 @@ grub_via_workaround_init (void) + { + grub_cpuid (1, proc_info, /* Don't care. */ manufacturer[0], + manufacturer[2], manufacturer[1]); ++ ++ /* Check family, apply only to family 6 and lower. */ ++ if (((proc_info & 0xf00) >> 8) > 6) ++ return; ++ + /* Check model, apply only to VIA C3 and lower. */ + if (((proc_info & 0xf0) >> 4 | (proc_info & 0xf0000) >> 12) > 10) + return; +-- +2.43.0 + diff --git a/0002-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch b/0002-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch new file mode 100644 index 0000000..2a5d284 --- /dev/null +++ b/0002-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch @@ -0,0 +1,82 @@ +From 5c07724c84963fa1dcf0e8a1d268d40c5c817d81 Mon Sep 17 00:00:00 2001 +From: LeoLiu-oc +Date: Wed, 13 Aug 2025 20:29:53 +0800 +Subject: [PATCH 2/2] i386: Reduce the time of set VESA mode by clearing FB + directly for Zhaoxin/Glenfly card + +While calling VBIOS to set VESA mode, BIOS/GRUB can indicate VBIOS to +clear frame buffer, it can also indicate VBIOS to skip this and do the +clearing itself by access linear frame buffer directly. + +Zhaoxin/Glenfly VBIOS is running at real mode and can only access the +first 1M memory, which means it can't access linear frame buffer directly. +So the first way will take more time. + +Add a patch here to use the second way to save time for Zhaoxin/Glenfly +card. + +Signed-off-by: Joanne Bao +Signed-off-by: Tony W Wang-oc +Tested-by: Sherry Zhang +Suggested-by: Jason He +Signed-off-by: LeoLiu-oc +--- + grub-core/video/i386/pc/vbe.c | 42 +++++++++++++++++++++++++++++++++++ + 1 file changed, 42 insertions(+) + +diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c +index a0bb9af..9b2aa7c 100644 +--- a/grub-core/video/i386/pc/vbe.c ++++ b/grub-core/video/i386/pc/vbe.c +@@ -618,6 +618,48 @@ grub_vbe_set_video_mode (grub_uint32_t vbe_mode, + if (grub_errno != GRUB_ERR_NONE) + return grub_errno; + ++ grub_uint32_t string_seg = (controller_info.oem_string_ptr & 0xFFFF0000) >> 16; ++ grub_uint32_t string_offset = controller_info.oem_string_ptr & 0xFFFF; ++ const char * oem_string = (const char *) (string_seg << 4) + string_offset; ++ ++ /* ++ * While calling VBIOS to set VESA mode, BIOS/GRUB can indicate VBIOS to clear ++ * frame buffer, it can also indicate VBIOS to skip this and do the clearing ++ * itself by access linear frame buffer directly. ++ * ++ * Zhaoxin/Glenfly VBIOS is running at real mode and can only access the first ++ * 1M memory, which means it can't access linear frame buffer directly. So the ++ * first way will take more time. ++ */ ++ ++ if (vbe_mode >= 0x100 && oem_string != NULL && *oem_string != '\0') ++ { ++ if (grub_strncmp(oem_string, "Zhaoxin", 7) == 0 || grub_strncmp(oem_string, "Glenfly", 7) == 0) ++ { ++ grub_uint8_t * fb_ptr; ++ struct grub_video_mode_info local_mode_info; ++ grub_size_t page_size; ++ grub_size_t vram_size = controller_info.total_memory << 16; ++ local_mode_info.height = new_vbe_mode_info.y_resolution; ++ ++ if (controller_info.version >= 0x300) ++ local_mode_info.pitch = new_vbe_mode_info.lin_bytes_per_scan_line; ++ else ++ local_mode_info.pitch = new_vbe_mode_info.bytes_per_scan_line; ++ ++ fb_ptr = (grub_uint8_t *) new_vbe_mode_info.phys_base_addr; ++ ++ page_size = local_mode_info.pitch * local_mode_info.height; ++ ++ if (vram_size >= 2 * page_size) ++ grub_memset(fb_ptr, 0, 2 * page_size); ++ else ++ grub_memset(fb_ptr, 0, page_size); ++ ++ vbe_mode |= 1 << 15; ++ } ++ } ++ + /* Try to get mode info. */ + grub_vbe_get_video_mode_info (vbe_mode, &new_vbe_mode_info); + if (grub_errno != GRUB_ERR_NONE) +-- +2.43.0 + diff --git a/grub.patches b/grub.patches index 9470e26..1c8a731 100644 --- a/grub.patches +++ b/grub.patches @@ -323,3 +323,5 @@ Patch326: sw64-Add-auxiliary-files.patch Patch327: sw64-Add-to-build-system.patch Patch328: backport-fix-CVE-2024-56738.patch Patch329: LoongArch-bugfix-clear-buffer-for-screen-info.patch +Patch330: 0001-i386-Check-for-cpuid-family-when-flush-cache-only-on.patch +Patch331: 0002-i386-Reduce-the-time-of-set-VESA-mode-by-clearing-FB.patch diff --git a/grub2.spec b/grub2.spec index e6beeeb..ad851cd 100644 --- a/grub2.spec +++ b/grub2.spec @@ -23,7 +23,7 @@ Name: grub2 Epoch: 1 Version: 2.12 -Release: 42 +Release: 43 Summary: Bootloader with support for Linux, Multiboot and more License: GPLv3+ URL: http://www.gnu.org/software/grub/ @@ -464,6 +464,13 @@ fi %{_datadir}/man/man* %changelog +* Wed Aug 13 2025 LeoLiu-oc - 1:2.12-43 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:i386: Check for cpuid family when flush cache only on VIA CPUs + i386: Reduce the time of set VESA mode by clearing FB directly for Zhaoxin/Glenfly card + * Thu Aug 7 2025 zhangqiumiao - 1:2.12-42 - Type:bugfix - CVE:NA -- Gitee