From 545774eb8899d4cbad29e845e591831c6e391f87 Mon Sep 17 00:00:00 2001 From: p-szafonimateusz Date: Tue, 17 Sep 2024 13:43:22 +0200 Subject: [PATCH] serial/pci_16550: make sure that interrupts are disabled during init Make sure that interrups are disabled during initialization. This is a proper fix for an unexpected MSI interrupt for PCI serial driver. Signed-off-by: p-szafonimateusz --- drivers/serial/uart_pci_16550.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/serial/uart_pci_16550.c b/drivers/serial/uart_pci_16550.c index e4c2ca5623..ab86bba8e8 100644 --- a/drivers/serial/uart_pci_16550.c +++ b/drivers/serial/uart_pci_16550.c @@ -546,6 +546,7 @@ static int pci_u16550_initialize(FAR struct pci_u16550_priv_s *priv, bool mmio) { int ret = 0; + int offset; /* Configure UART PCI */ @@ -563,6 +564,14 @@ static int pci_u16550_initialize(FAR struct pci_u16550_priv_s *priv, priv->common.regincr = type->regincr; priv->pcidev = dev; + /* Make sure that all interrupts are disabled otherwise spurious MSI + * interrupt can happen just after we connect MSI. + */ + + offset = (priv->common.regincr * sizeof(uart_datawidth_t) * + UART_IER_OFFSET); + priv->common.ops->putreg(&priv->common, offset, 0); + /* Allocate and connect MSI if supported */ ret = pci_alloc_irq(dev, &priv->common.irq, 1); @@ -586,14 +595,6 @@ legacy_irq: priv->common.irq = pci_get_irq(dev); - /* Attach interrupts early to prevent unexpected isr fault */ - - ret = irq_attach(priv->common.irq, priv->common.ops->isr, dev); - if (ret != OK) - { - pcierr("Failed to attach irq %d\n", ret); - } - return OK; }