dm: refine the uart_core

Make uart_init and uart_deinit internal functions. And make
uart_set_backend/uart_release_backend cover uart_init/uart_deinit
function.

This will make mevent teardown callback adding easier for uart_core.

Tracked-On: #1877
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Yin Fengwei
2018-12-13 18:09:34 +08:00
committed by wenlingz
parent b6603015bc
commit 83f19b7507
4 changed files with 40 additions and 46 deletions

View File

@@ -175,7 +175,6 @@ lpc_deinit(struct vmctx *ctx)
unregister_inout(&iop);
uart_release_backend(lpc_uart->uart, lpc_uart->opts);
uart_deinit(lpc_uart->uart);
uart_legacy_dealloc(unit);
lpc_uart->uart = NULL;
lpc_uart->enabled = 0;
@@ -205,23 +204,9 @@ lpc_init(struct vmctx *ctx)
}
pci_irq_reserve(lpc_uart->irq);
lpc_uart->uart = uart_init(lpc_uart_intr_assert,
lpc_uart_intr_deassert, lpc_uart);
if (lpc_uart->uart < 0) {
uart_legacy_dealloc(unit);
goto init_failed;
}
error = uart_set_backend(lpc_uart->uart, lpc_uart->opts);
/*
* Continue to initialize LPC UART device if opts is invalid,
* and the data will be dropped by uart_write in UART DM.
*/
if (error && error != -EINVAL) {
fprintf(stderr, "Unable to initialize backend '%s' "
"for LPC device %s\n", lpc_uart->opts, name);
uart_deinit(lpc_uart->uart);
lpc_uart->uart = uart_set_backend(lpc_uart_intr_assert, lpc_uart_intr_deassert,
lpc_uart, lpc_uart->opts);
if (lpc_uart->uart == NULL) {
uart_legacy_dealloc(unit);
goto init_failed;
}

View File

@@ -82,9 +82,6 @@ pci_uart_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
static int
pci_uart_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
{
struct uart_vdev *uart;
int ret;
pci_emul_alloc_bar(dev, 0, PCIBAR_IO, UART_IO_BAR_SIZE);
pci_lintr_request(dev);
@@ -93,11 +90,8 @@ pci_uart_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
pci_set_cfgdata16(dev, PCIR_VENDOR, COM_VENDOR);
pci_set_cfgdata8(dev, PCIR_CLASS, PCIC_SIMPLECOMM);
uart = uart_init(pci_uart_intr_assert, pci_uart_intr_deassert, dev);
dev->arg = uart;
ret = uart_set_backend(uart, opts);
if (ret && ret != -EINVAL) {
dev->arg = uart_set_backend(pci_uart_intr_assert, pci_uart_intr_deassert, dev, opts);
if (dev->arg == NULL) {
fprintf(stderr, "Unable to initialize backend '%s' for "
"pci uart at %d:%d\n", opts, dev->slot, dev->func);
return -1;
@@ -115,7 +109,6 @@ pci_uart_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
return;
uart_release_backend(uart, opts);
uart_deinit(uart);
}
struct pci_vdev_ops pci_ops_com = {