Skip to content

Commit 80a9fe5

Browse files
fyin1jren1
authored andcommitted
DM: add deinit function to virtual keyboard device
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>
1 parent f6db755 commit 80a9fe5

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

devicemodel/core/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ do_close_post(struct vmctx *ctx)
542542
{
543543
pci_irq_deinit(ctx);
544544
deinit_pci(ctx);
545+
atkbdc_deinit(ctx);
545546
vm_destroy(ctx);
546547
vm_close(ctx);
547548
}

devicemodel/hw/platform/atkbdc.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ atkbdc_init(struct vmctx *ctx)
422422
assert(base != NULL);
423423

424424
base->ctx = ctx;
425+
ctx->atkbdc_base = base;
425426

426427
pthread_mutex_init(&base->mtx, NULL);
427428

@@ -457,6 +458,33 @@ atkbdc_init(struct vmctx *ctx)
457458
base->ps2mouse = ps2mouse_init(base);
458459
}
459460

461+
void
462+
atkbdc_deinit(struct vmctx *ctx)
463+
{
464+
struct inout_port iop;
465+
struct atkbdc_base *base = ctx->atkbdc_base;
466+
467+
ps2kbd_deinit(base);
468+
base->ps2kbd = NULL;
469+
ps2mouse_deinit(base);
470+
base->ps2mouse = NULL;
471+
472+
bzero(&iop, sizeof(struct inout_port));
473+
iop.name = "atkdbc";
474+
iop.port = KBD_DATA_PORT;
475+
iop.size = 1;
476+
unregister_inout(&iop);
477+
478+
bzero(&iop, sizeof(struct inout_port));
479+
iop.name = "atkdbc";
480+
iop.port = KBD_STS_CTL_PORT;
481+
iop.size = 1;
482+
unregister_inout(&iop);
483+
484+
free(base);
485+
ctx->atkbdc_base = NULL;
486+
}
487+
460488
static void
461489
atkbdc_dsdt(void)
462490
{

devicemodel/include/atkbdc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct atkbdc_base {
114114
};
115115

116116
void atkbdc_init(struct vmctx *ctx);
117+
void atkbdc_deinit(struct vmctx *ctx);
117118
void atkbdc_event(struct atkbdc_base *base, int iskbd);
118119

119120
#endif /* _ATKBDC_H_ */

devicemodel/include/vmmapi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "types.h"
3535
#include "vmm.h"
3636

37+
#include "atkbdc.h"
38+
3739
/*
3840
* API version for out-of-tree consumers for making compile time decisions.
3941
*/
@@ -54,6 +56,9 @@ struct vmctx {
5456
char *baseaddr;
5557
char *name;
5658
uuid_t vm_uuid;
59+
60+
/* fields to track virtual devices */
61+
struct atkbdc_base *atkbdc_base;
5762
};
5863

5964
/*

0 commit comments

Comments
 (0)