Changeset 97a62fe in mainline for uspace/drv/pciintel/pci.c


Ignore:
Timestamp:
2011-02-14T21:41:50Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cd0684d
Parents:
7df0477e
Message:

Refactor create_function(), delete_function() and register_function() into
ddf_fun_create(), ddf_fun_destroy() and ddf_fun_bind(). This is not just
a rename.

File:
1 edited

Legend:

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

    r7df0477e r97a62fe  
    6969
    7070/** Obtain PCI bus soft-state from function soft-state */
    71 #define PCI_BUS_FROM_FUN(fun) (PCI_BUS(fun->fnode->dev))
     71#define PCI_BUS_FROM_FUN(fun) ((fun)->busptr)
    7272
    7373static hw_resource_list_t *pciintel_get_resources(function_t *fnode)
     
    361361void pci_bus_scan(pci_bus_t *bus, int bus_num)
    362362{
    363         function_t *fnode = create_function();
    364         pci_fun_t *fun = pci_fun_new();
    365         fnode->driver_data = fun;
     363        function_t *fnode;
     364        pci_fun_t *fun;
    366365       
    367366        int child_bus = 0;
     
    370369        uint8_t header_type;
    371370       
    372         /* We need this early, before registering. */
    373         fun->fnode = fnode;
    374         fnode->dev = bus->dnode;
    375         fnode->driver_data = fun;
     371        fun = pci_fun_new(bus);
    376372       
    377373        for (dnum = 0; dnum < 32; dnum++) {
     
    402398                        header_type = header_type & 0x7F;
    403399                       
    404                         pci_fun_create_name(fun);
     400                        char *fun_name = pci_fun_create_name(fun);
     401                        if (fun_name == NULL) {
     402                                printf(NAME ": out of memory.\n");
     403                                return;
     404                        }
     405                       
     406                        fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
     407                        if (fnode == NULL) {
     408                                printf(NAME ": error creating function.\n");
     409                                return;
     410                        }
     411                       
     412                        free(fun_name);
     413                        fun->fnode = fnode;
    405414                       
    406415                        pci_alloc_resource_list(fun);
     
    408417                        pci_read_interrupt(fun);
    409418                       
    410                         fnode->ftype = fun_inner;
    411419                        fnode->ops = &pci_fun_ops;
     420                        fnode->driver_data = fun;
    412421                       
    413422                        printf(NAME ": adding new function %s.\n",
     
    416425                        pci_fun_create_match_ids(fun);
    417426                       
    418                         if (register_function(fnode, bus->dnode) != EOK) {
     427                        if (ddf_fun_bind(fnode) != EOK) {
    419428                                pci_clean_resource_list(fun);
    420429                                clean_match_ids(&fnode->match_ids);
     
    434443                        }
    435444                       
    436                         /* Alloc new aux. fun. structure. */
    437                         fnode = create_function();
    438 
    439                         /* We need this early, before registering. */
    440                         fnode->dev = bus->dnode;
    441 
    442                         fun = pci_fun_new();
    443                         fun->fnode = fnode;
    444                         fnode->driver_data = fun;
     445                        fun = pci_fun_new(bus);
    445446                }
    446447        }
    447448       
    448449        if (fun->vendor_id == 0xffff) {
    449                 delete_function(fnode);
    450450                /* Free the auxiliary function structure. */
    451451                pci_fun_delete(fun);
     
    455455static int pci_add_device(device_t *dnode)
    456456{
     457        pci_bus_t *bus = NULL;
     458        function_t *ctl = NULL;
     459        bool got_res = false;
    457460        int rc;
    458461       
    459462        printf(NAME ": pci_add_device\n");
    460        
    461         pci_bus_t *bus = pci_bus_new();
     463        dnode->parent_phone = -1;
     464       
     465        bus = pci_bus_new();
    462466        if (bus == NULL) {
    463467                printf(NAME ": pci_add_device allocation failed.\n");
    464                 return ENOMEM;
     468                rc = ENOMEM;
     469                goto fail;
    465470        }
    466471        bus->dnode = dnode;
     
    472477                printf(NAME ": pci_add_device failed to connect to the "
    473478                    "parent's driver.\n");
    474                 pci_bus_delete(bus);
    475                 return dnode->parent_phone;
     479                rc = dnode->parent_phone;
     480                goto fail;
    476481        }
    477482       
     
    482487                printf(NAME ": pci_add_device failed to get hw resources for "
    483488                    "the device.\n");
    484                 pci_bus_delete(bus);
    485                 async_hangup(dnode->parent_phone);
    486                 return rc;
    487         }
     489                goto fail;
     490        }
     491        got_res = true;
    488492       
    489493        printf(NAME ": conf_addr = %" PRIx64 ".\n",
     
    500504            &bus->conf_addr_port)) {
    501505                printf(NAME ": failed to enable configuration ports.\n");
    502                 pci_bus_delete(bus);
    503                 async_hangup(dnode->parent_phone);
    504                 hw_res_clean_resource_list(&hw_resources);
    505                 return EADDRNOTAVAIL;
     506                rc = EADDRNOTAVAIL;
     507                goto fail;
    506508        }
    507509        bus->conf_data_port = (char *) bus->conf_addr_port + 4;
     
    510512        printf(NAME ": adding a 'ctl' function\n");
    511513       
    512         function_t *ctl = create_function();
    513         ctl->ftype = fun_exposed;
    514         ctl->name = "ctl";
    515         register_function(ctl, dnode);
     514        ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl");
     515        if (ctl == NULL) {
     516                printf(NAME ": error creating control function.\n");
     517                rc = ENOMEM;
     518                goto fail;
     519        }
     520       
     521        rc = ddf_fun_bind(ctl);
     522        if (rc != EOK) {
     523                printf(NAME ": error binding control function.\n");
     524                goto fail;
     525        }
    516526       
    517527        /* Enumerate functions. */
     
    522532       
    523533        return EOK;
     534       
     535fail:
     536        if (bus != NULL)
     537                pci_bus_delete(bus);
     538        if (dnode->parent_phone >= 0)
     539                async_hangup(dnode->parent_phone);
     540        if (got_res)
     541                hw_res_clean_resource_list(&hw_resources);
     542        if (ctl != NULL)
     543                ddf_fun_destroy(ctl);
     544
     545        return rc;
    524546}
    525547
     
    529551}
    530552
    531 pci_fun_t *pci_fun_new(void)
    532 {
    533         pci_fun_t *res;
    534        
    535         res = (pci_fun_t *) calloc(1, sizeof(pci_fun_t));
    536         return res;
     553pci_fun_t *pci_fun_new(pci_bus_t *bus)
     554{
     555        pci_fun_t *fun;
     556       
     557        fun = (pci_fun_t *) calloc(1, sizeof(pci_fun_t));
     558        if (fun == NULL)
     559                return NULL;
     560
     561        fun->busptr = bus;
     562        return fun;
    537563}
    538564
     
    551577}
    552578
    553 void pci_fun_create_name(pci_fun_t *fun)
     579char *pci_fun_create_name(pci_fun_t *fun)
    554580{
    555581        char *name = NULL;
     
    557583        asprintf(&name, "%02x:%02x.%01x", fun->bus, fun->dev,
    558584            fun->fn);
    559         fun->fnode->name = name;
     585        return name;
    560586}
    561587
Note: See TracChangeset for help on using the changeset viewer.