Allow uart(4) to use MSI interrupts on single-port PCI instances.

Do this here as puc(4) disallows single-port instances; at least
one multi-port PCIe UART chip (in this case, the ASIX MCS9922)
present separate PCI configuration space (functions) for each UART.

Tested using lrzsz and a null-modem cable. The ExpressCard/34
variants containing the MCS9922 should also use MSI with this change.

Reviewed by:		jhb, imp, rpokala
MFC after:		2 weeks
Differential Revision:	https://reviews.freebsd.org/D9123
This commit is contained in:
Bruce M Simpson 2017-01-12 16:30:27 +00:00
parent 25a3341048
commit fb1d9b7f41
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311987
2 changed files with 40 additions and 3 deletions

View File

@ -45,12 +45,14 @@ __FBSDID("$FreeBSD$");
#define DEFAULT_RCLK 1843200
static int uart_pci_probe(device_t dev);
static int uart_pci_attach(device_t dev);
static int uart_pci_detach(device_t dev);
static device_method_t uart_pci_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, uart_pci_probe),
DEVMETHOD(device_attach, uart_bus_attach),
DEVMETHOD(device_detach, uart_bus_detach),
DEVMETHOD(device_attach, uart_pci_attach),
DEVMETHOD(device_detach, uart_pci_detach),
DEVMETHOD(device_resume, uart_bus_resume),
DEVMETHOD_END
};
@ -209,4 +211,40 @@ uart_pci_probe(device_t dev)
return (result);
}
static int
uart_pci_attach(device_t dev)
{
struct uart_softc *sc;
int count;
sc = device_get_softc(dev);
/*
* Use MSI in preference to legacy IRQ if available.
* Whilst some PCIe UARTs support >1 MSI vector, use only the first.
*/
if (pci_msi_count(dev) > 0) {
count = 1;
if (pci_alloc_msi(dev, &count) == 0) {
sc->sc_irid = 1;
device_printf(dev, "Using %d MSI message\n", count);
}
}
return (uart_bus_attach(dev));
}
static int
uart_pci_detach(device_t dev)
{
struct uart_softc *sc;
sc = device_get_softc(dev);
if (sc->sc_irid != 0)
pci_release_msi(dev);
return (uart_bus_detach(dev));
}
DRIVER_MODULE(uart, pci, uart_pci_driver, uart_devclass, NULL, NULL);

View File

@ -677,7 +677,6 @@ uart_bus_attach(device_t dev)
* safest thing to do.
*/
if (filt != FILTER_SCHEDULE_THREAD && !uart_force_poll) {
sc->sc_irid = 0;
sc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ,
&sc->sc_irid, RF_ACTIVE | RF_SHAREABLE);
}