Skip to content

Commit 7d8905d

Browse files
andy-shevgregkh
authored andcommitted
serial: 8250_pci: Enable device after we check black list
If the board we are guessing has been listed in black list we don't need to enable it twice. The associated driver, if any, will take care about proper initialization. To achieve this we split out two helper functions, i.e. serial_pci_is_class_communication() and serial_pci_is_blacklisted() which will be called before pcim_enable_device(). We can do this since PCI specification requires class, device and vendor ID registers to be always present in the configuration space. As an example what happens before this patch applied (These are some debug prints, don't search for them in kernel sources): serial 0000:00:04.1: Mapped GSI28 to IRQ28 serial 0000:00:04.2: Mapped GSI29 to IRQ29 serial 0000:00:04.3: Mapped GSI54 to IRQ54 8250_mid 0000:00:04.1: Mapped GSI28 to IRQ28 8250_mid 0000:00:04.2: Mapped GSI29 to IRQ29 8250_mid 0000:00:04.3: Mapped GSI54 to IRQ54 After we will have just last three lines out of above. 8250_mid 0000:00:04.1: Mapped GSI28 to IRQ28 8250_mid 0000:00:04.2: Mapped GSI29 to IRQ29 8250_mid 0000:00:04.3: Mapped GSI54 to IRQ54 While here, correct a value of error code mentioned in the comment of serial_pci_guess_board(). Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c7ac15c commit 7d8905d

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

drivers/tty/serial/8250/8250_pci.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,17 +3384,8 @@ static const struct pci_device_id blacklist[] = {
33843384
{ PCI_VDEVICE(COMMTECH, PCI_ANY_ID), },
33853385
};
33863386

3387-
/*
3388-
* Given a complete unknown PCI device, try to use some heuristics to
3389-
* guess what the configuration might be, based on the pitiful PCI
3390-
* serial specs. Returns 0 on success, 1 on failure.
3391-
*/
3392-
static int
3393-
serial_pci_guess_board(struct pci_dev *dev, struct pciserial_board *board)
3387+
static int serial_pci_is_class_communication(struct pci_dev *dev)
33943388
{
3395-
const struct pci_device_id *bldev;
3396-
int num_iomem, num_port, first_port = -1, i;
3397-
33983389
/*
33993390
* If it is not a communications device or the programming
34003391
* interface is greater than 6, give up.
@@ -3407,6 +3398,13 @@ serial_pci_guess_board(struct pci_dev *dev, struct pciserial_board *board)
34073398
(dev->class & 0xff) > 6)
34083399
return -ENODEV;
34093400

3401+
return 0;
3402+
}
3403+
3404+
static int serial_pci_is_blacklisted(struct pci_dev *dev)
3405+
{
3406+
const struct pci_device_id *bldev;
3407+
34103408
/*
34113409
* Do not access blacklisted devices that are known not to
34123410
* feature serial ports or are handled by other modules.
@@ -3419,6 +3417,19 @@ serial_pci_guess_board(struct pci_dev *dev, struct pciserial_board *board)
34193417
return -ENODEV;
34203418
}
34213419

3420+
return 0;
3421+
}
3422+
3423+
/*
3424+
* Given a complete unknown PCI device, try to use some heuristics to
3425+
* guess what the configuration might be, based on the pitiful PCI
3426+
* serial specs. Returns 0 on success, -ENODEV on failure.
3427+
*/
3428+
static int
3429+
serial_pci_guess_board(struct pci_dev *dev, struct pciserial_board *board)
3430+
{
3431+
int num_iomem, num_port, first_port = -1, i;
3432+
34223433
num_iomem = num_port = 0;
34233434
for (i = 0; i < PCI_NUM_BAR_RESOURCES; i++) {
34243435
if (pci_resource_flags(dev, i) & IORESOURCE_IO) {
@@ -3639,6 +3650,14 @@ pciserial_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
36393650

36403651
board = &pci_boards[ent->driver_data];
36413652

3653+
rc = serial_pci_is_class_communication(dev);
3654+
if (rc)
3655+
return rc;
3656+
3657+
rc = serial_pci_is_blacklisted(dev);
3658+
if (rc)
3659+
return rc;
3660+
36423661
rc = pcim_enable_device(dev);
36433662
pci_save_state(dev);
36443663
if (rc)

0 commit comments

Comments
 (0)