Changeset c289457 in mainline


Ignore:
Timestamp:
2011-11-03T22:19:03Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
54de4836
Parents:
3ce78580 (diff), cb94e69b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

PCI driver improvements.

Add match ids based on pci class, subclass, …:

  • VGA and ide drvers ca be moved to DDF
  • UHCI/OHCI/EHCI drivers can use one rule instead of list PCI ID list

Few fixes.

Location:
uspace
Files:
3 edited

Legend:

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

    r3ce78580 rc289457  
    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                                /*
     
    511560                       
    512561                        fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
     562                        free(fun_name);
    513563                        if (fnode == NULL) {
    514564                                ddf_msg(LVL_ERROR, "Failed creating function.");
     
    516566                        }
    517567                       
    518                         free(fun_name);
    519568                        fun->fnode = fnode;
    520569                       
     
    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
     
    711766bool pci_alloc_resource_list(pci_fun_t *fun)
    712767{
    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;
     768        fun->hw_resources.resources = fun->resources;
     769        return true;
    716770}
    717771
    718772void pci_clean_resource_list(pci_fun_t *fun)
    719773{
    720         if (fun->hw_resources.resources != NULL) {
    721                 free(fun->hw_resources.resources);
    722                 fun->hw_resources.resources = NULL;
    723         }
     774        fun->hw_resources.resources = NULL;
    724775}
    725776
  • uspace/drv/bus/pci/pciintel/pci.h

    r3ce78580 rc289457  
    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;
     67        hw_resource_t resources[PCI_MAX_HW_RES];
    6368} pci_fun_t;
    6469
  • uspace/lib/drv/generic/driver.c

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