Changeset 1d53a78 in mainline


Ignore:
Timestamp:
2011-10-28T10:42:39Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
992b47ea
Parents:
8a363ab3
Message:

pciintel: Add rules based on class, subclass, prog if, revision.

Set id fields in pci_fun_init.
Use on stack buffer for strings.

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

Legend:

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

    r8a363ab3 r1d53a78  
    225225        fibril_mutex_lock(&bus->conf_mutex);
    226226       
    227         uint32_t conf_addr;
    228         conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
     227        const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    229228        void *addr = bus->conf_data_port + (reg & 3);
    230229       
     
    311310void pci_fun_create_match_ids(pci_fun_t *fun)
    312311{
    313         char *match_id_str;
     312#define ID_MAX_STR_LEN 50 /* Max is 47, align to something nice. */
     313
    314314        int rc;
    315        
    316         asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
     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",
    317319            fun->vendor_id, fun->device_id);
    318 
    319         if (match_id_str == NULL) {
    320                 ddf_msg(LVL_ERROR, "Out of memory creating match ID.");
    321                 return;
     320        if (rc < 0) {
     321                ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
     322                    str_error(rc));
    322323        }
    323324
    324325        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90);
    325326        if (rc != EOK) {
    326                 ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
     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",
    327336                    str_error(rc));
    328337        }
    329        
    330         free(match_id_str);
    331        
    332         /* TODO add more ids (with subsys ids, using class id etc.) */
     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 */
    333386}
    334387
     
    481534                for (fnum = 0; multi && fnum < 8; fnum++) {
    482535                        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);
    487536                        if (fun->vendor_id == 0xffff) {
    488537                                /*
     
    691740        fun->dev = dev;
    692741        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);
    693748}
    694749
  • uspace/drv/bus/pci/pciintel/pci.h

    r8a363ab3 r1d53a78  
    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;
    6266        hw_resource_list_t hw_resources;
    6367} pci_fun_t;
Note: See TracChangeset for help on using the changeset viewer.