Changeset 184f2f8a in mainline


Ignore:
Timestamp:
2018-10-29T11:35:40Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b25970f, f5837524
Parents:
889cdb1
git-author:
Jiri Svoboda <jiri@…> (2018-10-28 21:35:14)
git-committer:
Jiri Svoboda <jiri@…> (2018-10-29 11:35:40)
Message:

PCI driver should fail when no devices are found. Handle error properly. Bind needs to come after HW initialization.

Location:
uspace/drv/bus/pci/pciintel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/pci/pciintel/pci.c

    r889cdb1 r184f2f8a  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
    3  * Copyright (c) 2011 Jiri Svoboda
     3 * Copyright (c) 2018 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    596596 * @param bus           Host-to-PCI bridge
    597597 * @param bus_num       Bus number
     598 *
     599 * @return EOK on success, ENOENT if no PCI devices found, ENOMEM if out of
     600 *         memory, EIO on other I/O error
    598601 */
    599 void pci_bus_scan(pci_bus_t *bus, int bus_num)
     602errno_t pci_bus_scan(pci_bus_t *bus, int bus_num)
    600603{
    601604        pci_fun_t *fun;
     
    606609        bool multi;
    607610        uint8_t header_type;
     611        bool device_found;
     612
     613        device_found = false;
    608614
    609615        for (dnum = 0; dnum < 32; dnum++) {
     
    625631                        }
    626632
     633                        device_found = true;
     634
    627635                        header_type = pci_conf_read_8(fun, PCI_HEADER_TYPE);
    628636                        if (fnum == 0) {
     
    637645                                ddf_msg(LVL_ERROR, "Out of memory.");
    638646                                pci_fun_delete(fun);
    639                                 return;
     647                                return ENOMEM;
    640648                        }
    641649
     
    645653                                ddf_msg(LVL_ERROR, "Failed setting function name.");
    646654                                pci_fun_delete(fun);
    647                                 return;
     655                                return EIO;
    648656                        }
    649657
     
    661669
    662670                        pci_fun_create_match_ids(fun);
    663 
    664                         if (ddf_fun_bind(fun->fnode) != EOK) {
    665                                 pci_clean_resource_list(fun);
    666                                 pci_fun_delete(fun);
    667                                 continue;
    668                         }
    669671
    670672                        if (header_type == PCI_HEADER_TYPE_BRIDGE ||
     
    675677                                    "bridge, secondary bus number = %d.",
    676678                                    bus_num);
    677                                 if (child_bus > bus_num)
    678                                         pci_bus_scan(bus, child_bus);
     679                                if (child_bus > bus_num) {
     680                                        rc = pci_bus_scan(bus, child_bus);
     681                                        if (rc != EOK) {
     682                                                pci_fun_delete(fun);
     683                                                return rc;
     684                                        }
     685                                }
     686                        }
     687
     688                        if (ddf_fun_bind(fun->fnode) != EOK) {
     689                                pci_clean_resource_list(fun);
     690                                pci_fun_delete(fun);
     691                                continue;
    679692                        }
    680693                }
    681694        }
     695
     696        /* Fail bus scan if no devices are found. */
     697        if (!device_found)
     698                return ENOENT;
     699
     700        return EOK;
    682701}
    683702
     
    783802        }
    784803
     804        /* Enumerate functions. */
     805        ddf_msg(LVL_DEBUG, "Enumerating the bus");
     806        rc = pci_bus_scan(bus, 0);
     807        if (rc != EOK) {
     808                ddf_msg(LVL_ERROR, "Bus enumeration failed.");
     809                goto fail;
     810        }
     811
    785812        rc = ddf_fun_bind(ctl);
    786813        if (rc != EOK) {
     
    788815                goto fail;
    789816        }
    790 
    791         /* Enumerate functions. */
    792         ddf_msg(LVL_DEBUG, "Scanning the bus");
    793         pci_bus_scan(bus, 0);
    794817
    795818        hw_res_clean_resource_list(&hw_resources);
  • uspace/drv/bus/pci/pciintel/pci.h

    r889cdb1 r184f2f8a  
    9090extern char *pci_fun_create_name(pci_fun_t *);
    9191
    92 extern void pci_bus_scan(pci_bus_t *, int);
     92extern errno_t pci_bus_scan(pci_bus_t *, int);
    9393
    9494extern bool pci_alloc_resource_list(pci_fun_t *);
Note: See TracChangeset for help on using the changeset viewer.