Skip to content

Commit 8d12c06

Browse files
fyin1lijinxia
authored andcommitted
dm: introduce system/full reset and suspend
Guest has erquirement to support system/full reboot and S3. Which could trigger different reset path in guest Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent 76662a6 commit 8d12c06

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

devicemodel/arch/x86/pm.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* SUCH DAMAGE.
2626
*/
2727

28+
#include <sys/cdefs.h>
29+
#include <sys/types.h>
30+
#include <stdio.h>
2831
#include <assert.h>
2932
#include <errno.h>
3033
#include <pthread.h>
@@ -53,7 +56,6 @@ reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
5356
uint32_t *eax, void *arg)
5457
{
5558
int error;
56-
5759
static uint8_t reset_control;
5860

5961
if (bytes != 1)
@@ -63,15 +65,17 @@ reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
6365
else {
6466
reset_control = *eax;
6567

66-
/* Treat hard and soft resets the same. */
67-
if (reset_control & 0x4) {
68-
error = vm_suspend(ctx, VM_SUSPEND_RESET);
69-
assert(error == 0 || errno == EALREADY);
70-
}
71-
72-
/* cold reset should clear the value in 0xcf9 */
73-
if (reset_control & 0x8) {
68+
if (*eax & 0x8) {
69+
fprintf(stderr, "full reset\r\n");
70+
error = vm_suspend(ctx, VM_SUSPEND_FULL_RESET);
71+
assert(error ==0 || errno == EALREADY);
72+
mevent_notify();
7473
reset_control = 0;
74+
} else if (*eax & 0x4) {
75+
fprintf(stderr, "system reset\r\n");
76+
error = vm_suspend(ctx, VM_SUSPEND_SYSTEM_RESET);
77+
assert(error ==0 || errno == EALREADY);
78+
mevent_notify();
7579
}
7680
}
7781
return 0;

devicemodel/core/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ main(int argc, char *argv[])
887887
vm_pause(ctx);
888888
delete_cpu(ctx, BSP);
889889

890-
if (vm_get_suspend_mode() != VM_SUSPEND_RESET)
890+
if (vm_get_suspend_mode() != VM_SUSPEND_FULL_RESET)
891891
break;
892892

893893
vm_deinit_vdevs(ctx);

devicemodel/core/mevent.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ mevent_dispatch(void)
328328
*/
329329
mevent_handle(eventlist, ret);
330330

331-
if (vm_get_suspend_mode() != VM_SUSPEND_NONE)
331+
if ((vm_get_suspend_mode() != VM_SUSPEND_NONE) &&
332+
(vm_get_suspend_mode() != VM_SUSPEND_SYSTEM_RESET))
332333
break;
333334
}
334335
}

devicemodel/hw/pci/wdt_i6300esb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ wdt_expired_thread(union sigval v)
105105
wdt_timeout = 1;
106106

107107
/* watchdog timer out, set the uos to reboot */
108-
vm_set_suspend_mode(VM_SUSPEND_RESET);
108+
vm_set_suspend_mode(VM_SUSPEND_FULL_RESET);
109109
mevent_notify();
110110
} else {
111111
/* if not need reboot, just loop timer */

devicemodel/hw/platform/atkbdc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "ps2kbd.h"
4343
#include "ps2mouse.h"
4444
#include "vmmapi.h"
45+
#include "mevent.h"
4546

4647
static void
4748
atkbdc_assert_kbd_intr(struct atkbdc_base *base)
@@ -359,8 +360,9 @@ atkbdc_sts_ctl_handler(struct vmctx *ctx, int vcpu, int in, int port,
359360
base->status |= KBDS_AUX_BUFFER_FULL |
360361
KBDS_KBD_BUFFER_FULL;
361362
break;
362-
case KBDC_RESET: /* Pulse "reset" line */
363-
error = vm_suspend(ctx, VM_SUSPEND_RESET);
363+
case KBDC_RESET: /* Pulse "cold reset" line */
364+
error = vm_suspend(ctx, VM_SUSPEND_FULL_RESET);
365+
mevent_notify();
364366
assert(error == 0 || errno == EALREADY);
365367
break;
366368
default:

devicemodel/include/vmm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@
5757

5858
enum vm_suspend_how {
5959
VM_SUSPEND_NONE,
60-
VM_SUSPEND_RESET,
60+
VM_SUSPEND_SYSTEM_RESET,
61+
VM_SUSPEND_FULL_RESET,
6162
VM_SUSPEND_POWEROFF,
63+
VM_SUSPEND_SUSPEND,
6264
VM_SUSPEND_HALT,
6365
VM_SUSPEND_TRIPLEFAULT,
6466
VM_SUSPEND_LAST

0 commit comments

Comments
 (0)