Changes in / [c289457:3ce78580] in mainline


Ignore:
Location:
uspace
Files:
3 edited

Legend:

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

    rc289457 r3ce78580  
    225225        fibril_mutex_lock(&bus->conf_mutex);
    226226       
    227         const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
     227        uint32_t conf_addr;
     228        conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    228229        void *addr = bus->conf_data_port + (reg & 3);
    229230       
     
    310311void pci_fun_create_match_ids(pci_fun_t *fun)
    311312{
    312 #define ID_MAX_STR_LEN 50 /* Max is 47, align to something nice. */
    313 
     313        char *match_id_str;
    314314        int rc;
    315         char match_id_str[ID_MAX_STR_LEN];
    316 
    317         /* Vendor ID & Device ID, length(incl \0) 22 */
    318         rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/ven=%04x&dev=%04x",
     315       
     316        asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
    319317            fun->vendor_id, fun->device_id);
    320         if (rc < 0) {
    321                 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
    322                     str_error(rc));
     318
     319        if (match_id_str == NULL) {
     320                ddf_msg(LVL_ERROR, "Out of memory creating match ID.");
     321                return;
    323322        }
    324323
    325324        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90);
    326325        if (rc != EOK) {
    327                 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
    328         }
    329 
    330         /* Class, subclass, prog IF, revision, length(incl \0) 47 */
    331         rc = snprintf(match_id_str, ID_MAX_STR_LEN,
    332             "pci/class=%02x&subclass=%02x&progif=%02x&revision=%02x",
    333             fun->class_code, fun->subclass_code, fun->prog_if, fun->revision);
    334         if (rc < 0) {
    335                 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
     326                ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
    336327                    str_error(rc));
    337328        }
    338 
    339         rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 70);
    340         if (rc != EOK) {
    341                 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
    342         }
    343 
    344         /* Class, subclass, prog IF, length(incl \0) 35 */
    345         rc = snprintf(match_id_str, ID_MAX_STR_LEN,
    346             "pci/class=%02x&subclass=%02x&progif=%02x",
    347             fun->class_code, fun->subclass_code, fun->prog_if);
    348         if (rc < 0) {
    349                 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
    350                     str_error(rc));
    351         }
    352 
    353         rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 60);
    354         if (rc != EOK) {
    355                 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
    356         }
    357 
    358         /* Class, subclass, length(incl \0) 25 */
    359         rc = snprintf(match_id_str, ID_MAX_STR_LEN,
    360             "pci/class=%02x&subclass=%02x",
    361             fun->class_code, fun->subclass_code);
    362         if (rc < 0) {
    363                 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
    364                     str_error(rc));
    365         }
    366 
    367         rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 50);
    368         if (rc != EOK) {
    369                 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
    370         }
    371 
    372         /* Class, length(incl \0) 13 */
    373         rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/class=%02x",
    374             fun->class_code);
    375         if (rc < 0) {
    376                 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
    377                     str_error(rc));
    378         }
    379 
    380         rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 40);
    381         if (rc != EOK) {
    382                 ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
    383         }
    384 
    385         /* TODO add subsys ids, but those exist only in header type 0 */
     329       
     330        free(match_id_str);
     331       
     332        /* TODO add more ids (with subsys ids, using class id etc.) */
    386333}
    387334
     
    534481                for (fnum = 0; multi && fnum < 8; fnum++) {
    535482                        pci_fun_init(fun, bus_num, dnum, fnum);
     483                        fun->vendor_id = pci_conf_read_16(fun,
     484                            PCI_VENDOR_ID);
     485                        fun->device_id = pci_conf_read_16(fun,
     486                            PCI_DEVICE_ID);
    536487                        if (fun->vendor_id == 0xffff) {
    537488                                /*
     
    560511                       
    561512                        fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
    562                         free(fun_name);
    563513                        if (fnode == NULL) {
    564514                                ddf_msg(LVL_ERROR, "Failed creating function.");
     
    566516                        }
    567517                       
     518                        free(fun_name);
    568519                        fun->fnode = fnode;
    569520                       
     
    740691        fun->dev = dev;
    741692        fun->fn = fn;
    742         fun->vendor_id = pci_conf_read_16(fun, PCI_VENDOR_ID);
    743         fun->device_id = pci_conf_read_16(fun, PCI_DEVICE_ID);
    744         fun->class_code = pci_conf_read_8(fun, PCI_BASE_CLASS);
    745         fun->subclass_code = pci_conf_read_8(fun, PCI_SUB_CLASS);
    746         fun->prog_if = pci_conf_read_8(fun, PCI_PROG_IF);
    747         fun->revision = pci_conf_read_8(fun, PCI_REVISION_ID);
    748693}
    749694
     
    766711bool pci_alloc_resource_list(pci_fun_t *fun)
    767712{
    768         fun->hw_resources.resources = fun->resources;
    769         return true;
     713        fun->hw_resources.resources =
     714            (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
     715        return fun->hw_resources.resources != NULL;
    770716}
    771717
    772718void pci_clean_resource_list(pci_fun_t *fun)
    773719{
    774         fun->hw_resources.resources = NULL;
     720        if (fun->hw_resources.resources != NULL) {
     721                free(fun->hw_resources.resources);
     722                fun->hw_resources.resources = NULL;
     723        }
    775724}
    776725
  • uspace/drv/bus/pci/pciintel/pci.h

    rc289457 r3ce78580  
    6060        int vendor_id;
    6161        int device_id;
    62         uint8_t class_code;
    63         uint8_t subclass_code;
    64         uint8_t prog_if;
    65         uint8_t revision;
    6662        hw_resource_list_t hw_resources;
    67         hw_resource_t resources[PCI_MAX_HW_RES];
    6863} pci_fun_t;
    6964
  • uspace/lib/drv/generic/driver.c

    rc289457 r3ce78580  
    970970       
    971971        match_id->id = str_dup(match_id_str);
    972         match_id->score = match_score;
     972        match_id->score = 90;
    973973       
    974974        add_match_id(&fun->match_ids, match_id);
Note: See TracChangeset for help on using the changeset viewer.