Changeset 00aece0 in mainline for uspace/drv/bus/pci/pciintel/pci.c


Ignore:
Timestamp:
2012-02-18T16:47:38Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4449c6c
Parents:
bd5f3b7 (diff), f943dd3 (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:

Merge mainline changes.

File:
1 edited

Legend:

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

    rbd5f3b7 r00aece0  
    7878#define PCI_BUS_FROM_FUN(fun) ((fun)->busptr)
    7979
     80/** Max is 47, align to something nice. */
     81#define ID_MAX_STR_LEN 50
     82
    8083static hw_resource_list_t *pciintel_get_resources(ddf_fun_t *fnode)
    8184{
     
    8992static bool pciintel_enable_interrupt(ddf_fun_t *fnode)
    9093{
    91         /* This is an old ugly way, copied from ne2000 driver */
     94        /* This is an old ugly way */
    9295        assert(fnode);
    9396        pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data;
     
    184187
    185188static hw_res_ops_t pciintel_hw_res_ops = {
    186         &pciintel_get_resources,
    187         &pciintel_enable_interrupt
     189        .get_resource_list = &pciintel_get_resources,
     190        .enable_interrupt = &pciintel_enable_interrupt,
    188191};
    189192
     
    202205};
    203206
    204 static int pci_add_device(ddf_dev_t *);
     207static int pci_dev_add(ddf_dev_t *);
     208static int pci_fun_online(ddf_fun_t *);
     209static int pci_fun_offline(ddf_fun_t *);
    205210
    206211/** PCI bus driver standard operations */
    207212static driver_ops_t pci_ops = {
    208         .add_device = &pci_add_device
     213        .dev_add = &pci_dev_add,
     214        .fun_online = &pci_fun_online,
     215        .fun_offline = &pci_fun_offline,
    209216};
    210217
     
    215222};
    216223
    217 static pci_bus_t *pci_bus_new(void)
    218 {
    219         pci_bus_t *bus;
    220        
    221         bus = (pci_bus_t *) calloc(1, sizeof(pci_bus_t));
    222         if (bus == NULL)
    223                 return NULL;
    224        
    225         fibril_mutex_initialize(&bus->conf_mutex);
    226         return bus;
    227 }
    228 
    229 static void pci_bus_delete(pci_bus_t *bus)
    230 {
    231         assert(bus != NULL);
    232         free(bus);
    233 }
    234 
    235224static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
    236225{
     
    239228        fibril_mutex_lock(&bus->conf_mutex);
    240229       
    241         uint32_t conf_addr;
    242         conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
     230        const uint32_t conf_addr = CONF_ADDR(fun->bus, fun->dev, fun->fn, reg);
    243231        void *addr = bus->conf_data_port + (reg & 3);
    244232       
     
    325313void pci_fun_create_match_ids(pci_fun_t *fun)
    326314{
    327         char *match_id_str;
    328315        int rc;
    329        
    330         asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
     316        char match_id_str[ID_MAX_STR_LEN];
     317
     318        /* Vendor ID & Device ID, length(incl \0) 22 */
     319        rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/ven=%04x&dev=%04x",
    331320            fun->vendor_id, fun->device_id);
    332 
    333         if (match_id_str == NULL) {
    334                 ddf_msg(LVL_ERROR, "Out of memory creating match ID.");
    335                 return;
     321        if (rc < 0) {
     322                ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
     323                    str_error(rc));
    336324        }
    337325
    338326        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 90);
    339327        if (rc != EOK) {
    340                 ddf_msg(LVL_ERROR, "Failed adding match ID: %s",
     328                ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
     329        }
     330
     331        /* Class, subclass, prog IF, revision, length(incl \0) 47 */
     332        rc = snprintf(match_id_str, ID_MAX_STR_LEN,
     333            "pci/class=%02x&subclass=%02x&progif=%02x&revision=%02x",
     334            fun->class_code, fun->subclass_code, fun->prog_if, fun->revision);
     335        if (rc < 0) {
     336                ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
    341337                    str_error(rc));
    342338        }
    343        
    344         free(match_id_str);
    345        
    346         /* TODO add more ids (with subsys ids, using class id etc.) */
     339
     340        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 70);
     341        if (rc != EOK) {
     342                ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
     343        }
     344
     345        /* Class, subclass, prog IF, length(incl \0) 35 */
     346        rc = snprintf(match_id_str, ID_MAX_STR_LEN,
     347            "pci/class=%02x&subclass=%02x&progif=%02x",
     348            fun->class_code, fun->subclass_code, fun->prog_if);
     349        if (rc < 0) {
     350                ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
     351                    str_error(rc));
     352        }
     353
     354        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 60);
     355        if (rc != EOK) {
     356                ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
     357        }
     358
     359        /* Class, subclass, length(incl \0) 25 */
     360        rc = snprintf(match_id_str, ID_MAX_STR_LEN,
     361            "pci/class=%02x&subclass=%02x",
     362            fun->class_code, fun->subclass_code);
     363        if (rc < 0) {
     364                ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
     365                    str_error(rc));
     366        }
     367
     368        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 50);
     369        if (rc != EOK) {
     370                ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
     371        }
     372
     373        /* Class, length(incl \0) 13 */
     374        rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/class=%02x",
     375            fun->class_code);
     376        if (rc < 0) {
     377                ddf_msg(LVL_ERROR, "Failed creating match ID str: %s",
     378                    str_error(rc));
     379        }
     380
     381        rc = ddf_fun_add_match_id(fun->fnode, match_id_str, 40);
     382        if (rc != EOK) {
     383                ddf_msg(LVL_ERROR, "Failed adding match ID: %s", str_error(rc));
     384        }
     385
     386        /* TODO add subsys ids, but those exist only in header type 0 */
    347387}
    348388
     
    495535                for (fnum = 0; multi && fnum < 8; fnum++) {
    496536                        pci_fun_init(fun, bus_num, dnum, fnum);
    497                         fun->vendor_id = pci_conf_read_16(fun,
    498                             PCI_VENDOR_ID);
    499                         fun->device_id = pci_conf_read_16(fun,
    500                             PCI_DEVICE_ID);
    501537                        if (fun->vendor_id == 0xffff) {
    502538                                /*
     
    525561                       
    526562                        fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
     563                        free(fun_name);
    527564                        if (fnode == NULL) {
    528565                                ddf_msg(LVL_ERROR, "Failed creating function.");
     
    530567                        }
    531568                       
    532                         free(fun_name);
    533569                        fun->fnode = fnode;
    534570                       
     
    574610}
    575611
    576 static int pci_add_device(ddf_dev_t *dnode)
     612static int pci_dev_add(ddf_dev_t *dnode)
    577613{
    578614        pci_bus_t *bus = NULL;
     
    581617        int rc;
    582618       
    583         ddf_msg(LVL_DEBUG, "pci_add_device");
     619        ddf_msg(LVL_DEBUG, "pci_dev_add");
    584620        dnode->parent_sess = NULL;
    585621       
    586         bus = pci_bus_new();
     622        bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t));
    587623        if (bus == NULL) {
    588                 ddf_msg(LVL_ERROR, "pci_add_device allocation failed.");
     624                ddf_msg(LVL_ERROR, "pci_dev_add allocation failed.");
    589625                rc = ENOMEM;
    590626                goto fail;
    591627        }
     628        fibril_mutex_initialize(&bus->conf_mutex);
     629
    592630        bus->dnode = dnode;
    593631        dnode->driver_data = bus;
     
    596634            dnode->handle, IPC_FLAG_BLOCKING);
    597635        if (!dnode->parent_sess) {
    598                 ddf_msg(LVL_ERROR, "pci_add_device failed to connect to the "
     636                ddf_msg(LVL_ERROR, "pci_dev_add failed to connect to the "
    599637                    "parent driver.");
    600638                rc = ENOENT;
     
    606644        rc = hw_res_get_resource_list(dnode->parent_sess, &hw_resources);
    607645        if (rc != EOK) {
    608                 ddf_msg(LVL_ERROR, "pci_add_device failed to get hw resources "
     646                ddf_msg(LVL_ERROR, "pci_dev_add failed to get hw resources "
    609647                    "for the device.");
    610648                goto fail;
     
    655693       
    656694fail:
    657         if (bus != NULL)
    658                 pci_bus_delete(bus);
    659        
    660695        if (dnode->parent_sess)
    661696                async_hangup(dnode->parent_sess);
     
    668703       
    669704        return rc;
     705}
     706
     707static int pci_fun_online(ddf_fun_t *fun)
     708{
     709        ddf_msg(LVL_DEBUG, "pci_fun_online()");
     710        return ddf_fun_online(fun);
     711}
     712
     713static int pci_fun_offline(ddf_fun_t *fun)
     714{
     715        ddf_msg(LVL_DEBUG, "pci_fun_offline()");
     716        return ddf_fun_offline(fun);
    670717}
    671718
     
    694741        fun->dev = dev;
    695742        fun->fn = fn;
     743        fun->vendor_id = pci_conf_read_16(fun, PCI_VENDOR_ID);
     744        fun->device_id = pci_conf_read_16(fun, PCI_DEVICE_ID);
     745        fun->class_code = pci_conf_read_8(fun, PCI_BASE_CLASS);
     746        fun->subclass_code = pci_conf_read_8(fun, PCI_SUB_CLASS);
     747        fun->prog_if = pci_conf_read_8(fun, PCI_PROG_IF);
     748        fun->revision = pci_conf_read_8(fun, PCI_REVISION_ID);
    696749}
    697750
     
    714767bool pci_alloc_resource_list(pci_fun_t *fun)
    715768{
    716         fun->hw_resources.resources =
    717             (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
    718         return fun->hw_resources.resources != NULL;
     769        fun->hw_resources.resources = fun->resources;
     770        return true;
    719771}
    720772
    721773void pci_clean_resource_list(pci_fun_t *fun)
    722774{
    723         if (fun->hw_resources.resources != NULL) {
    724                 free(fun->hw_resources.resources);
    725                 fun->hw_resources.resources = NULL;
    726         }
     775        fun->hw_resources.resources = NULL;
    727776}
    728777
Note: See TracChangeset for help on using the changeset viewer.