Skip to content

Commit

Permalink
DM: add deinit function to virtual keyboard device
Browse files Browse the repository at this point in the history
old code has no deinit functionality for virtual keyboard device.
Which will trigger resource leak when system is reboot.

deinit function is added to:
1. deinit low ps2 based keyboard and mouse
2. release memory/io resource of virtual keyboard device
NOTE: IRQ resource will be handed in pci irq module

Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <Eddie.dong@intel.com>
  • Loading branch information
fyin1 authored and jren1 committed May 15, 2018
1 parent f6db755 commit 80a9fe5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions devicemodel/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ do_close_post(struct vmctx *ctx)
{
pci_irq_deinit(ctx);
deinit_pci(ctx);
atkbdc_deinit(ctx);
vm_destroy(ctx);
vm_close(ctx);
}
Expand Down
28 changes: 28 additions & 0 deletions devicemodel/hw/platform/atkbdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ atkbdc_init(struct vmctx *ctx)
assert(base != NULL);

base->ctx = ctx;
ctx->atkbdc_base = base;

pthread_mutex_init(&base->mtx, NULL);

Expand Down Expand Up @@ -457,6 +458,33 @@ atkbdc_init(struct vmctx *ctx)
base->ps2mouse = ps2mouse_init(base);
}

void
atkbdc_deinit(struct vmctx *ctx)
{
struct inout_port iop;
struct atkbdc_base *base = ctx->atkbdc_base;

ps2kbd_deinit(base);
base->ps2kbd = NULL;
ps2mouse_deinit(base);
base->ps2mouse = NULL;

bzero(&iop, sizeof(struct inout_port));
iop.name = "atkdbc";
iop.port = KBD_DATA_PORT;
iop.size = 1;
unregister_inout(&iop);

bzero(&iop, sizeof(struct inout_port));
iop.name = "atkdbc";
iop.port = KBD_STS_CTL_PORT;
iop.size = 1;
unregister_inout(&iop);

free(base);
ctx->atkbdc_base = NULL;
}

static void
atkbdc_dsdt(void)
{
Expand Down
1 change: 1 addition & 0 deletions devicemodel/include/atkbdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct atkbdc_base {
};

void atkbdc_init(struct vmctx *ctx);
void atkbdc_deinit(struct vmctx *ctx);
void atkbdc_event(struct atkbdc_base *base, int iskbd);

#endif /* _ATKBDC_H_ */
5 changes: 5 additions & 0 deletions devicemodel/include/vmmapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "types.h"
#include "vmm.h"

#include "atkbdc.h"

/*
* API version for out-of-tree consumers for making compile time decisions.
*/
Expand All @@ -54,6 +56,9 @@ struct vmctx {
char *baseaddr;
char *name;
uuid_t vm_uuid;

/* fields to track virtual devices */
struct atkbdc_base *atkbdc_base;
};

/*
Expand Down

0 comments on commit 80a9fe5

Please sign in to comment.