DM: cleanup resource for uart.
Add deinit function for uart. Another work is add resource cleanup functions which is called by other components when they are using uart. Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
parent
c8585a22e3
commit
1a2a07476b
|
@ -106,9 +106,22 @@ pci_uart_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pci_uart_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
||||
{
|
||||
struct uart_vdev *uart = (struct uart_vdev *)dev->arg;
|
||||
|
||||
if (uart == NULL)
|
||||
return;
|
||||
|
||||
uart_release_backend(uart, opts);
|
||||
uart_deinit(uart);
|
||||
}
|
||||
|
||||
struct pci_vdev_ops pci_ops_com = {
|
||||
.class_name = "uart",
|
||||
.vdev_init = pci_uart_init,
|
||||
.vdev_deinit = pci_uart_deinit,
|
||||
.vdev_barwrite = pci_uart_write,
|
||||
.vdev_barread = pci_uart_read
|
||||
};
|
||||
|
|
|
@ -274,6 +274,18 @@ uart_opentty(struct uart_vdev *uart)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
uart_closetty(struct uart_vdev *uart)
|
||||
{
|
||||
if (uart->tty.fd != STDIN_FILENO)
|
||||
mevent_delete_close(uart->mev);
|
||||
else
|
||||
mevent_delete(uart->mev);
|
||||
|
||||
uart->mev = 0;
|
||||
ttyclose();
|
||||
}
|
||||
|
||||
static uint8_t
|
||||
modem_status(uint8_t mcr)
|
||||
{
|
||||
|
@ -692,3 +704,19 @@ uart_set_backend(struct uart_vdev *uart, const char *opts)
|
|||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
uart_release_backend(struct uart_vdev *uart, const char *opts)
|
||||
{
|
||||
if (opts == NULL)
|
||||
return;
|
||||
|
||||
uart_closetty(uart);
|
||||
if (strcmp("stdio", opts) == 0) {
|
||||
stdio_in_use = false;
|
||||
} else
|
||||
close(uart->tty.fd);
|
||||
|
||||
uart->tty.fd = 0;
|
||||
uart->tty.opened = false;
|
||||
}
|
||||
|
|
|
@ -44,4 +44,5 @@ void uart_legacy_dealloc(int which);
|
|||
uint8_t uart_read(struct uart_vdev *uart, int offset);
|
||||
void uart_write(struct uart_vdev *uart, int offset, uint8_t value);
|
||||
int uart_set_backend(struct uart_vdev *uart, const char *opt);
|
||||
void uart_release_backend(struct uart_vdev *uart, const char *opts);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue