Skip to contentSkip to conversation

x86: retrieve keyboard shift status flags from BIOS

PATCH In review Jan Beulich 3 participants 5 messages Sep 11, 2012 – Sep 24, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: retrieve keyboard shift status flags from BIOS

Recent Linux tries to make use of this, and has no way of getting at these bits without Xen assisting it.

There doesn't appear to be a way to obtain the same information from UEFI.

xen/arch/x86/boot/trampoline.S +9 -0
@@ -184,11 +184,16 @@ trampoline_boot_cpu_entry:
          *  1. Get memory map.
          *  2. Get Enhanced Disk Drive (EDD) information.
          *  3. Set video mode.
+         *  4. Get keyboard shift flags.
          */
         call    get_memory_map
         call    get_edd
         call    video
 
+        mov     $0x0200,%ax
+        int     $0x16
+        mov     %al,bootsym(kbd_shift_flags)
+
         /* Disable irqs before returning to protected mode. */
         cli
 
@@ -221,6 +226,10 @@ trampoline_boot_cpu_entry:
 skip_realmode:
         .byte   0
 
+        .globl kbd_shift_flags
+kbd_shift_flags:
+        .byte   0
+
 rm_idt: .word   256*4-1, 0, 0
 
 #include "mem.S"
xen/arch/x86/platform_hypercall.c +13 -0
@@ -29,6 +29,7 @@
 #include <asm/edd.h>
 #include <asm/mtrr.h>
 #include <asm/io_apic.h>
+#include <asm/setup.h>
 #include "cpu/mtrr/mtrr.h"
 #include <xsm/xsm.h>
 
@@ -319,6 +320,18 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
                                      u.firmware_info.u.efi_info) )
                 ret = -EFAULT;
             break;
+        case XEN_FW_KBD_SHIFT_FLAGS:
+            ret = -ESRCH;
+            if ( op->u.firmware_info.index != 0 )
+                break;
+
+            op->u.firmware_info.u.kbd_shift_flags = bootsym(kbd_shift_flags);
+
+            ret = 0;
+            if ( copy_field_to_guest(u_xenpf_op, op,
+                                     u.firmware_info.u.kbd_shift_flags) )
+                ret = -EFAULT;
+            break;
         default:
             ret = -EINVAL;
             break;
xen/include/asm-x86/setup.h +2 -0
@@ -41,4 +41,6 @@ int xen_in_range(unsigned long mfn);
 void microcode_grab_module(
     unsigned long *, const multiboot_info_t *, void *(*)(const module_t *));
 
+extern uint8_t kbd_shift_flags;
+
 #endif
xen/include/public/platform.h +4 -0
@@ -218,6 +218,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_efi_runtim
 #define  XEN_FW_EFI_VENDOR         2
 #define  XEN_FW_EFI_MEM_INFO       3
 #define  XEN_FW_EFI_RT_VERSION     4
+#define XEN_FW_KBD_SHIFT_FLAGS    5
 struct xenpf_firmware_info {
     /* IN variables. */
     uint32_t type;
@@ -266,6 +267,9 @@ struct xenpf_firmware_info {
                 uint32_t type;
             } mem;
         } efi_info; /* XEN_FW_EFI_INFO */
+
+        /* Int16, Fn02: Get keyboard shift flags. */
+        uint8_t kbd_shift_flags; /* XEN_FW_KBD_SHIFT_FLAGS */
     } u;
 };
 typedef struct xenpf_firmware_info xenpf_firmware_info_t;

x86: retrieve keyboard shift status flags from BIOS

Recent Linux tries to make use of this, and has no way of getting at these bits without Xen assisting it.

There doesn't appear to be a way to obtain the same information from UEFI.

xen/arch/x86/boot/trampoline.S +9 -0
@@ -184,11 +184,16 @@ trampoline_boot_cpu_entry:
          *  1. Get memory map.
          *  2. Get Enhanced Disk Drive (EDD) information.
          *  3. Set video mode.
+         *  4. Get keyboard shift flags.
          */
         call    get_memory_map
         call    get_edd
         call    video
 
+        mov     $0x0200,%ax
+        int     $0x16
+        mov     %al,bootsym(kbd_shift_flags)
+
         /* Disable irqs before returning to protected mode. */
         cli
 
@@ -221,6 +226,10 @@ trampoline_boot_cpu_entry:
 skip_realmode:
         .byte   0
 
+        .globl kbd_shift_flags
+kbd_shift_flags:
+        .byte   0
+
 rm_idt: .word   256*4-1, 0, 0
 
 #include "mem.S"
xen/arch/x86/platform_hypercall.c +13 -0
@@ -29,6 +29,7 @@
 #include <asm/edd.h>
 #include <asm/mtrr.h>
 #include <asm/io_apic.h>
+#include <asm/setup.h>
 #include "cpu/mtrr/mtrr.h"
 #include <xsm/xsm.h>
 
@@ -319,6 +320,18 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
                                      u.firmware_info.u.efi_info) )
                 ret = -EFAULT;
             break;
+        case XEN_FW_KBD_SHIFT_FLAGS:
+            ret = -ESRCH;
+            if ( op->u.firmware_info.index != 0 )
+                break;
+
+            op->u.firmware_info.u.kbd_shift_flags = bootsym(kbd_shift_flags);
+
+            ret = 0;
+            if ( copy_field_to_guest(u_xenpf_op, op,
+                                     u.firmware_info.u.kbd_shift_flags) )
+                ret = -EFAULT;
+            break;
         default:
             ret = -EINVAL;
             break;
xen/include/asm-x86/setup.h +2 -0
@@ -41,4 +41,6 @@ int xen_in_range(unsigned long mfn);
 void microcode_grab_module(
     unsigned long *, const multiboot_info_t *, void *(*)(const module_t *));
 
+extern uint8_t kbd_shift_flags;
+
 #endif
xen/include/public/platform.h +4 -0
@@ -218,6 +218,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_efi_runtim
 #define  XEN_FW_EFI_VENDOR         2
 #define  XEN_FW_EFI_MEM_INFO       3
 #define  XEN_FW_EFI_RT_VERSION     4
+#define XEN_FW_KBD_SHIFT_FLAGS    5
 struct xenpf_firmware_info {
     /* IN variables. */
     uint32_t type;
@@ -266,6 +267,9 @@ struct xenpf_firmware_info {
                 uint32_t type;
             } mem;
         } efi_info; /* XEN_FW_EFI_INFO */
+
+        /* Int16, Fn02: Get keyboard shift flags. */
+        uint8_t kbd_shift_flags; /* XEN_FW_KBD_SHIFT_FLAGS */
     } u;
 };
 typedef struct xenpf_firmware_info xenpf_firmware_info_t;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

Recent Linux tries to make use of this, and has no way of getting at these bits without Xen assisting it.

There doesn't appear to be a way to obtain the same information from UEFI.

Quoted 95 lines
xen/arch/x86/boot/trampoline.S +9 -0
@@ -184,11 +184,16 @@ trampoline_boot_cpu_entry:
          *  1. Get memory map.
          *  2. Get Enhanced Disk Drive (EDD) information.
          *  3. Set video mode.
+         *  4. Get keyboard shift flags.
          */
         call    get_memory_map
         call    get_edd
         call    video
 
+        mov     $0x0200,%ax
+        int     $0x16
+        mov     %al,bootsym(kbd_shift_flags)
+
         /* Disable irqs before returning to protected mode. */
         cli
 
@@ -221,6 +226,10 @@ trampoline_boot_cpu_entry:
 skip_realmode:
         .byte   0
 
+        .globl kbd_shift_flags
+kbd_shift_flags:
+        .byte   0
+
 rm_idt: .word   256*4-1, 0, 0
 
 #include "mem.S"
xen/arch/x86/platform_hypercall.c +13 -0
@@ -29,6 +29,7 @@
 #include <asm/edd.h>
 #include <asm/mtrr.h>
 #include <asm/io_apic.h>
+#include <asm/setup.h>
 #include "cpu/mtrr/mtrr.h"
 #include <xsm/xsm.h>
 
@@ -319,6 +320,18 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
                                      u.firmware_info.u.efi_info) )
                 ret = -EFAULT;
             break;
+        case XEN_FW_KBD_SHIFT_FLAGS:
+            ret = -ESRCH;
+            if ( op->u.firmware_info.index != 0 )
+                break;
+
+            op->u.firmware_info.u.kbd_shift_flags = bootsym(kbd_shift_flags);
+
+            ret = 0;
+            if ( copy_field_to_guest(u_xenpf_op, op,
+                                     u.firmware_info.u.kbd_shift_flags) )
+                ret = -EFAULT;
+            break;
         default:
             ret = -EINVAL;
             break;
xen/include/asm-x86/setup.h +2 -0
@@ -41,4 +41,6 @@ int xen_in_range(unsigned long mfn);
 void microcode_grab_module(
     unsigned long *, const multiboot_info_t *, void *(*)(const module_t *));
 
+extern uint8_t kbd_shift_flags;
+
 #endif
xen/include/public/platform.h +4 -0
@@ -218,6 +218,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_efi_runtim
 #define  XEN_FW_EFI_VENDOR         2
 #define  XEN_FW_EFI_MEM_INFO       3
 #define  XEN_FW_EFI_RT_VERSION     4
+#define XEN_FW_KBD_SHIFT_FLAGS    5
 struct xenpf_firmware_info {
     /* IN variables. */
     uint32_t type;
@@ -266,6 +267,9 @@ struct xenpf_firmware_info {
                 uint32_t type;
             } mem;
         } efi_info; /* XEN_FW_EFI_INFO */
+
+        /* Int16, Fn02: Get keyboard shift flags. */
+        uint8_t kbd_shift_flags; /* XEN_FW_KBD_SHIFT_FLAGS */
     } u;
 };
 typedef struct xenpf_firmware_info xenpf_firmware_info_t;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Jan Beulich
Quoted 5 lines · Jan Beulich

Recent Linux tries to make use of this, and has no way of getting at these bits without Xen assisting it.

There doesn't appear to be a way to obtain the same information from UEFI.

And here is a variant for the upstream:

Quoted 1 line

From 21b4fdf0592156ac3020f5c492139368dcdfcf71 Mon Sep 17 00:00:00 2001

From: Konrad Rzeszutek Wilk <[email protected]>
Date: Fri, 21 Sep 2012 12:30:35 -0400
Subject: [PATCH] xen/x86: retrieve keyboard shift status flags from
hypervisor.

The xen c/s 25873 allows the hypervisor to retrieve the NUMLOCK flag. With this patch, the Linux kernel can get the state according to the data in the BIOS.

---
 arch/x86/xen/enlighten.c         |    8 ++++++++
 include/xen/interface/platform.h |    3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)
arch/x86/xen/enlighten.c +8 -0
index 9642d4a..89a7c57 100644
@@ -1441,11 +1441,19 @@ asmlinkage void __init xen_start_kernel(void)
 		const struct dom0_vga_console_info *info =
 			(void *)((char *)xen_start_info +
 				 xen_start_info->console.dom0.info_off);
+		struct xen_platform_op op = {
+			.cmd = XENPF_firmware_info,
+			.interface_version = XENPF_INTERFACE_VERSION,
+			.u.firmware_info.type = XEN_FW_KBD_SHIFT_FLAGS,
+		};
 
 		xen_init_vga(info, xen_start_info->console.dom0.info_size);
 		xen_start_info->console.domU.mfn = 0;
 		xen_start_info->console.domU.evtchn = 0;
 
+		if (HYPERVISOR_dom0_op(&op) == 0)
+			boot_params.kbd_status = op.u.firmware_info.u.kbd_shift_flags;
+
 		xen_init_apic();
 
 		/* Make sure ACS will be enabled */
include/xen/interface/platform.h +3 -0
index 61fa661..81eee3b 100644
@@ -112,6 +112,7 @@ DEFINE_GUEST_HANDLE_STRUCT(xenpf_platform_quirk_t);
 #define XEN_FW_DISK_INFO          1 /* from int 13 AH=08/41/48 */
 #define XEN_FW_DISK_MBR_SIGNATURE 2 /* from MBR offset 0x1b8 */
 #define XEN_FW_VBEDDC_INFO        3 /* from int 10 AX=4f15 */
+#define XEN_FW_KBD_SHIFT_FLAGS    5 /* Int16, Fn02: Get keyboard shift flags. */
 struct xenpf_firmware_info {
 	/* IN variables. */
 	uint32_t type;
@@ -142,6 +143,8 @@ struct xenpf_firmware_info {
 			/* must refer to 128-byte buffer */
 			GUEST_HANDLE(uchar) edid;
 		} vbeddc_info; /* XEN_FW_VBEDDC_INFO */
+		uint8_t kbd_shift_flags; /* XEN_FW_KBD_SHIFT_FLAGS */
+
 	} u;
 };
 DEFINE_GUEST_HANDLE_STRUCT(xenpf_firmware_info_t);
Signature · 1 line
1.7.7.6
author Acked-by
#3 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk

And here is a variant for the upstream:

From 21b4fdf0592156ac3020f5c492139368dcdfcf71 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Fri, 21 Sep 2012 12:30:35 -0400
Subject: [PATCH] xen/x86: retrieve keyboard shift status flags from
hypervisor.

Quoted 5 lines

The xen c/s 25873 allows the hypervisor to retrieve the NUMLOCK flag. With this patch, the Linux kernel can get the state according to the data in the BIOS.

(but also see below)

Quoted 37 lines
arch/x86/xen/enlighten.c +8 -0
@@ -1441,11 +1441,19 @@ asmlinkage void __init xen_start_kernel(void)
 		const struct dom0_vga_console_info *info =
 			(void *)((char *)xen_start_info +
 				 xen_start_info->console.dom0.info_off);
+		struct xen_platform_op op = {
+			.cmd = XENPF_firmware_info,
+			.interface_version = XENPF_INTERFACE_VERSION,
+			.u.firmware_info.type = XEN_FW_KBD_SHIFT_FLAGS,
+		};
 
 		xen_init_vga(info, xen_start_info->console.dom0.info_size);
 		xen_start_info->console.domU.mfn = 0;
 		xen_start_info->console.domU.evtchn = 0;
 
+		if (HYPERVISOR_dom0_op(&op) == 0)
+			boot_params.kbd_status = op.u.firmware_info.u.kbd_shift_flags;
+
 		xen_init_apic();
 
 		/* Make sure ACS will be enabled */
include/xen/interface/platform.h +1 -0
index 61fa661..81eee3b 100644
@@ -112,6 +112,7 @@ DEFINE_GUEST_HANDLE_STRUCT(xenpf_platform_quirk_t);
 #define XEN_FW_DISK_INFO          1 /* from int 13 AH=08/41/48 */
 #define XEN_FW_DISK_MBR_SIGNATURE 2 /* from MBR offset 0x1b8 */
 #define XEN_FW_VBEDDC_INFO        3 /* from int 10 AX=4f15 */
+#define XEN_FW_KBD_SHIFT_FLAGS    5 /* Int16, Fn02: Get keyboard shift 

flags. */
struct xenpf_firmware_info {

include/xen/interface/platform.h +0 -0
 	/* IN variables. */
 	uint32_t type;

include/xen/interface/platform.h struct xenpf_firmware_info { · line 147

Quoted 5 lines
include/xen/interface/platform.h +2 -0
@@ -142,6 +143,8 @@ struct xenpf_firmware_info {
 			/* must refer to 128-byte buffer */
 			GUEST_HANDLE(uchar) edid;
 		} vbeddc_info; /* XEN_FW_VBEDDC_INFO */
+		uint8_t kbd_shift_flags; /* XEN_FW_KBD_SHIFT_FLAGS */
+

I'd prefer to not have stray empty line here - if anything, it should go before the new union member.

Jan

Quoted 5 lines
include/xen/interface/platform.h +0 -0
 	} u;
 };
 DEFINE_GUEST_HANDLE_STRUCT(xenpf_firmware_info_t);
Signature · 1 line
1.7.7.6
#4 lore raw
Quoted 5 lines
Quoted 1 line

(but also see below)

.. snip..

Quoted 5 lines
Quoted 5 lines

flags. */
struct xenpf_firmware_info {

include/xen/interface/platform.h +0 -0
 	/* IN variables. */
 	uint32_t type;
@@ -142,6 +143,8 @@ struct xenpf_firmware_info {
Quoted 9 lines

include/xen/interface/platform.h struct xenpf_firmware_info { · line 147

Quoted 5 lines
include/xen/interface/platform.h +2 -0
 			/* must refer to 128-byte buffer */
 			GUEST_HANDLE(uchar) edid;
 		} vbeddc_info; /* XEN_FW_VBEDDC_INFO */
+		uint8_t kbd_shift_flags; /* XEN_FW_KBD_SHIFT_FLAGS */
+

I'd prefer to not have stray empty line here - if anything, it should go before the new union member.

Done! Thx for the review.