Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/atkbdc.c
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
#include "atkbdc.h" | #include "atkbdc.h" | ||||
#include "inout.h" | #include "inout.h" | ||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "pci_irq.h" | #include "pci_irq.h" | ||||
#include "pci_lpc.h" | #include "pci_lpc.h" | ||||
#include "ps2kbd.h" | #include "ps2kbd.h" | ||||
#include "ps2mouse.h" | #include "ps2mouse.h" | ||||
#ifdef BHYVE_SNAPSHOT | |||||
#include "snapshot.h" | |||||
#endif | |||||
#define KBD_DATA_PORT 0x60 | #define KBD_DATA_PORT 0x60 | ||||
#define KBD_STS_CTL_PORT 0x64 | #define KBD_STS_CTL_PORT 0x64 | ||||
#define KBDC_RESET 0xfe | #define KBDC_RESET 0xfe | ||||
#define KBD_DEV_IRQ 1 | #define KBD_DEV_IRQ 1 | ||||
#define AUX_DEV_IRQ 12 | #define AUX_DEV_IRQ 12 | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | struct atkbdc_softc { | ||||
uint32_t curcmd; /* current command for next byte */ | uint32_t curcmd; /* current command for next byte */ | ||||
uint32_t ctrlbyte; | uint32_t ctrlbyte; | ||||
struct kbd_dev kbd; | struct kbd_dev kbd; | ||||
struct aux_dev aux; | struct aux_dev aux; | ||||
}; | }; | ||||
#ifdef BHYVE_SNAPSHOT | |||||
static struct atkbdc_softc *atkbdc_sc = NULL; | |||||
#endif | |||||
static void | static void | ||||
atkbdc_assert_kbd_intr(struct atkbdc_softc *sc) | atkbdc_assert_kbd_intr(struct atkbdc_softc *sc) | ||||
{ | { | ||||
if ((sc->ram[0] & KBD_ENABLE_KBD_INT) != 0) { | if ((sc->ram[0] & KBD_ENABLE_KBD_INT) != 0) { | ||||
sc->kbd.irq_active = true; | sc->kbd.irq_active = true; | ||||
vm_isa_pulse_irq(sc->ctx, sc->kbd.irq, sc->kbd.irq); | vm_isa_pulse_irq(sc->ctx, sc->kbd.irq, sc->kbd.irq); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void | void | ||||
atkbdc_init(struct vmctx *ctx) | atkbdc_init(struct vmctx *ctx) | ||||
{ | { | ||||
struct inout_port iop; | struct inout_port iop; | ||||
struct atkbdc_softc *sc; | struct atkbdc_softc *sc; | ||||
int error; | int error; | ||||
#ifdef BHYVE_SNAPSHOT | |||||
struct vm_snapshot_dev_info *dev_info; | |||||
#endif | |||||
sc = calloc(1, sizeof(struct atkbdc_softc)); | sc = calloc(1, sizeof(struct atkbdc_softc)); | ||||
sc->ctx = ctx; | sc->ctx = ctx; | ||||
pthread_mutex_init(&sc->mtx, NULL); | pthread_mutex_init(&sc->mtx, NULL); | ||||
bzero(&iop, sizeof(struct inout_port)); | bzero(&iop, sizeof(struct inout_port)); | ||||
iop.name = "atkdbc"; | iop.name = "atkdbc"; | ||||
Show All 22 Lines | #endif | ||||
pci_irq_reserve(AUX_DEV_IRQ); | pci_irq_reserve(AUX_DEV_IRQ); | ||||
sc->aux.irq = AUX_DEV_IRQ; | sc->aux.irq = AUX_DEV_IRQ; | ||||
sc->ps2kbd_sc = ps2kbd_init(sc); | sc->ps2kbd_sc = ps2kbd_init(sc); | ||||
sc->ps2mouse_sc = ps2mouse_init(sc); | sc->ps2mouse_sc = ps2mouse_init(sc); | ||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
assert(atkbdc_sc == NULL); | dev_info = calloc(1, sizeof(*dev_info)); | ||||
atkbdc_sc = sc; | |||||
if (dev_info == NULL) { | |||||
error = -1; | |||||
fprintf(stderr, "Error allocating space for dev_info"); | |||||
} | |||||
assert(error == 0); | |||||
dev_info->dev_name = "atkbdc"; | |||||
dev_info->was_restored = 0; | |||||
gusev.vitaliy_gmail.com: calloc(3) initialises all memory with zero, so you don't need explicitly assign `was_restored`… | |||||
dev_info->snapshot_cb = atkbdc_snapshot; | |||||
dev_info->meta_data = sc; | |||||
insert_registered_devs(dev_info); | |||||
#endif | #endif | ||||
} | } | ||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
int | int | ||||
atkbdc_snapshot(struct vm_snapshot_meta *meta) | atkbdc_snapshot(struct vm_snapshot_meta *meta, struct vm_snapshot_dev_info *dev_info) | ||||
{ | { | ||||
int ret; | int ret; | ||||
struct atkbdc_softc *atkbdc_sc; | |||||
assert(dev_info->meta_data != NULL); | |||||
atkbdc_sc = (struct atkbdc_softc*) dev_info->meta_data; | |||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->status, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->status, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->outport, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->outport, meta, ret, done); | ||||
SNAPSHOT_BUF_OR_LEAVE(atkbdc_sc->ram, | SNAPSHOT_BUF_OR_LEAVE(atkbdc_sc->ram, | ||||
sizeof(atkbdc_sc->ram), meta, ret, done); | sizeof(atkbdc_sc->ram), meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->curcmd, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->curcmd, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->ctrlbyte, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->ctrlbyte, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.irq_active, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.irq_active, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.irq, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.irq, meta, ret, done); | ||||
SNAPSHOT_BUF_OR_LEAVE(atkbdc_sc->kbd.buffer, | SNAPSHOT_BUF_OR_LEAVE(atkbdc_sc->kbd.buffer, | ||||
sizeof(atkbdc_sc->kbd.buffer), meta, ret, done); | sizeof(atkbdc_sc->kbd.buffer), meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.brd, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.brd, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.bwr, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.bwr, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.bcnt, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->kbd.bcnt, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->aux.irq_active, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->aux.irq_active, meta, ret, done); | ||||
SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->aux.irq, meta, ret, done); | SNAPSHOT_VAR_OR_LEAVE(atkbdc_sc->aux.irq, meta, ret, done); | ||||
ret = ps2kbd_snapshot(atkbdc_sc->ps2kbd_sc, meta); | ret = ps2kbd_snapshot(atkbdc_sc->ps2kbd_sc, meta); | ||||
if (ret != 0) | if (ret != 0) | ||||
goto done; | goto done; | ||||
ret = ps2mouse_snapshot(atkbdc_sc->ps2mouse_sc, meta); | ret = ps2mouse_snapshot(atkbdc_sc->ps2mouse_sc, meta); | ||||
done: | done: | ||||
return (ret); | return (ret); | ||||
Show All 37 Lines |
calloc(3) initialises all memory with zero, so you don't need explicitly assign was_restored to 0.
Also this is related to all below "was_restored = 0" changes.