]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Implement keyboard reset method
authorSasha Levin <levinsasha928@gmail.com>
Fri, 17 Jun 2011 20:41:28 +0000 (16:41 -0400)
committerPekka Enberg <penberg@kernel.org>
Fri, 17 Jun 2011 21:38:39 +0000 (00:38 +0300)
Implement the keyboard reset method which allows guest kernel
to reboot the guest using the keyboard controller.

This will allow guest kernel to reboot the guest when it needs to,
for example - kernel panic (when passing "panic=1" as kernel parameter).

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/hw/i8042.c
tools/kvm/include/kvm/kvm-cpu.h
tools/kvm/kvm-cpu.c
tools/kvm/kvm-run.c

index 21a779e2c45e84b85b3ec968560037c29c24fa6c..262368e92b76c9f6c2c041cddbc59c6cb2da410f 100644 (file)
@@ -5,6 +5,7 @@
 #include "kvm/term.h"
 #include "kvm/kvm.h"
 #include "kvm/i8042.h"
+#include "kvm/kvm-cpu.h"
 
 #include <stdint.h>
 
@@ -30,6 +31,7 @@
 #define I8042_CMD_AUX_TEST     0xA9
 #define I8042_CMD_AUX_DISABLE  0xA7
 #define I8042_CMD_AUX_ENABLE   0xA8
+#define I8042_CMD_SYSTEM_RESET 0xFE
 
 #define RESPONSE_ACK           0xFA
 
@@ -138,7 +140,7 @@ void kbd_queue(u8 c)
        kbd_update_irq();
 }
 
-static void kbd_write_command(u8 val)
+static void kbd_write_command(struct kvm *kvm, u8 val)
 {
        switch (val) {
        case I8042_CMD_CTL_RCTR:
@@ -159,6 +161,9 @@ static void kbd_write_command(u8 val)
        case I8042_CMD_AUX_ENABLE:
                state.mode &= ~MODE_DISABLE_AUX;
                break;
+       case I8042_CMD_SYSTEM_RESET:
+               kvm_cpu__reboot();
+               break;
        default:
                break;
        }
@@ -314,7 +319,7 @@ static bool kbd_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data
        switch (port) {
        case I8042_COMMAND_REG: {
                u8 value = ioport__read8(data);
-               kbd_write_command(value);
+               kbd_write_command(kvm, value);
                break;
        }
        case I8042_DATA_REG: {
index 1eb4a525663a98fbcca2623652e6d5a8adfdba28..95f3f9ddfd127d77ed82a1fd332373025dc0a977 100644 (file)
@@ -34,6 +34,7 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu);
 void kvm_cpu__setup_cpuid(struct kvm_cpu *vcpu);
 void kvm_cpu__enable_singlestep(struct kvm_cpu *vcpu);
 void kvm_cpu__run(struct kvm_cpu *vcpu);
+void kvm_cpu__reboot(void);
 int kvm_cpu__start(struct kvm_cpu *cpu);
 
 void kvm_cpu__show_code(struct kvm_cpu *vcpu);
index 1fb1c7482903c0f8678a51c53e496b3f3a75c29e..f57d42e054520dd302686a4bffd36023a07b3a3e 100644 (file)
@@ -16,6 +16,7 @@
 
 #define PAGE_SIZE (sysconf(_SC_PAGE_SIZE))
 
+extern struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
 extern __thread struct kvm_cpu *current_kvm_cpu;
 
 static inline bool is_in_protected_mode(struct kvm_cpu *vcpu)
@@ -393,7 +394,7 @@ void kvm_cpu__run(struct kvm_cpu *vcpu)
 static void kvm_cpu_signal_handler(int signum)
 {
        if (signum == SIGKVMEXIT) {
-               if (current_kvm_cpu->is_running) {
+               if (current_kvm_cpu && current_kvm_cpu->is_running) {
                        current_kvm_cpu->is_running = false;
                        pthread_kill(pthread_self(), SIGKVMEXIT);
                }
@@ -418,6 +419,11 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu *cpu)
        }
 }
 
+void kvm_cpu__reboot(void)
+{
+       pthread_kill(kvm_cpus[0]->thread, SIGKVMEXIT);
+}
+
 int kvm_cpu__start(struct kvm_cpu *cpu)
 {
        sigset_t sigset;
index 60fc07b55732279e67914b7469287a1cbbd52a3e..9724e3715ce48461c459a2880ad8af43f68305f2 100644 (file)
@@ -570,7 +570,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
                vidmode = 0;
 
        memset(real_cmdline, 0, sizeof(real_cmdline));
-       strcpy(real_cmdline, "notsc noapic noacpi pci=conf1");
+       strcpy(real_cmdline, "notsc noapic noacpi pci=conf1 reboot=k");
        if (vnc || sdl) {
                strcat(real_cmdline, " video=vesafb console=tty0");
        } else
@@ -661,17 +661,17 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
        kvm__init_ram(kvm);
 
+       kbd__init(kvm);
+
        if (vnc || sdl)
                fb = vesa__init(kvm);
 
        if (vnc) {
-               kbd__init(kvm);
                if (fb)
                        vnc__init(fb);
        }
 
        if (sdl) {
-               kbd__init(kvm);
                if (fb)
                        sdl__init(fb);
        }