Changeset 56fd7cf in mainline for uspace/drv/bus/pci/pciintel/pci.c


Ignore:
Timestamp:
2012-08-17T11:37:03Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1d5a540
Parents:
be2a38ad
Message:

Make ddf_dev_t and ddf_fun_t opaque. This further tighthens the DDF interface.

File:
1 edited

Legend:

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

    rbe2a38ad r56fd7cf  
    5050#include <ddf/driver.h>
    5151#include <ddf/log.h>
    52 #include <devman.h>
    53 #include <ipc/devman.h>
    5452#include <ipc/dev_iface.h>
    5553#include <ipc/irc.h>
     
    7169
    7270/** Obtain PCI function soft-state from DDF function node */
    73 #define PCI_FUN(fnode) ((pci_fun_t *) (fnode)->driver_data)
     71static pci_fun_t *pci_fun(ddf_fun_t *fnode)
     72{
     73        return ddf_fun_data_get(fnode);
     74}
    7475
    7576/** Obtain PCI bus soft-state from DDF device node */
    76 #define PCI_BUS(dnode) ((pci_bus_t *) (dnode)->driver_data)
     77#if 0
     78static pci_bus_t *pci_bus(ddf_dev_t *dnode)
     79{
     80        return ddf_dev_data_get(dnode);
     81}
     82#endif
    7783
    7884/** Obtain PCI bus soft-state from function soft-state */
    79 #define PCI_BUS_FROM_FUN(fun) ((fun)->busptr)
     85static pci_bus_t *pci_bus_from_fun(pci_fun_t *fun)
     86{
     87        return fun->busptr;
     88}
    8089
    8190/** Max is 47, align to something nice. */
     
    8493static hw_resource_list_t *pciintel_get_resources(ddf_fun_t *fnode)
    8594{
    86         pci_fun_t *fun = PCI_FUN(fnode);
     95        pci_fun_t *fun = pci_fun(fnode);
    8796       
    8897        if (fun == NULL)
     
    95104        /* This is an old ugly way */
    96105        assert(fnode);
    97         pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data;
     106        pci_fun_t *dev_data = pci_fun(fnode);
    98107       
    99108        sysarg_t apic;
     
    138147        if (address > 252)
    139148                return EINVAL;
    140         pci_conf_write_32(PCI_FUN(fun), address, data);
     149        pci_conf_write_32(pci_fun(fun), address, data);
    141150        return EOK;
    142151}
     
    147156        if (address > 254)
    148157                return EINVAL;
    149         pci_conf_write_16(PCI_FUN(fun), address, data);
     158        pci_conf_write_16(pci_fun(fun), address, data);
    150159        return EOK;
    151160}
     
    156165        if (address > 255)
    157166                return EINVAL;
    158         pci_conf_write_8(PCI_FUN(fun), address, data);
     167        pci_conf_write_8(pci_fun(fun), address, data);
    159168        return EOK;
    160169}
     
    165174        if (address > 252)
    166175                return EINVAL;
    167         *data = pci_conf_read_32(PCI_FUN(fun), address);
     176        *data = pci_conf_read_32(pci_fun(fun), address);
    168177        return EOK;
    169178}
     
    174183        if (address > 254)
    175184                return EINVAL;
    176         *data = pci_conf_read_16(PCI_FUN(fun), address);
     185        *data = pci_conf_read_16(pci_fun(fun), address);
    177186        return EOK;
    178187}
     
    183192        if (address > 255)
    184193                return EINVAL;
    185         *data = pci_conf_read_8(PCI_FUN(fun), address);
     194        *data = pci_conf_read_8(pci_fun(fun), address);
    186195        return EOK;
    187196}
     
    225234static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
    226235{
    227         pci_bus_t *bus = PCI_BUS_FROM_FUN(fun);
     236        pci_bus_t *bus = pci_bus_from_fun(fun);
    228237       
    229238        fibril_mutex_lock(&bus->conf_mutex);
     
    252261static void pci_conf_write(pci_fun_t *fun, int reg, uint8_t *buf, size_t len)
    253262{
    254         pci_bus_t *bus = PCI_BUS_FROM_FUN(fun);
     263        pci_bus_t *bus = pci_bus_from_fun(fun);
    255264       
    256265        fibril_mutex_lock(&bus->conf_mutex);
     
    480489        if (range_addr != 0) {
    481490                ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64
    482                     ", size = %x", fun->fnode->name, range_addr,
     491                    ", size = %x", ddf_fun_get_name(fun->fnode), range_addr,
    483492                    (unsigned int) range_size);
    484493        }
     
    506515        hw_res_list->count++;
    507516       
    508         ddf_msg(LVL_NOTE, "Function %s uses irq %x.", fun->fnode->name, irq);
     517        ddf_msg(LVL_NOTE, "Function %s uses irq %x.", ddf_fun_get_name(fun->fnode), irq);
    509518}
    510519
     
    523532void pci_bus_scan(pci_bus_t *bus, int bus_num)
    524533{
    525         ddf_fun_t *fnode;
    526534        pci_fun_t *fun;
     535        int rc;
    527536       
    528537        int child_bus = 0;
     
    531540        uint8_t header_type;
    532541       
    533         fun = pci_fun_new(bus);
    534        
    535542        for (dnum = 0; dnum < 32; dnum++) {
    536543                multi = true;
    537544                for (fnum = 0; multi && fnum < 8; fnum++) {
     545                        fun = pci_fun_new(bus);
     546                       
    538547                        pci_fun_init(fun, bus_num, dnum, fnum);
    539548                        if (fun->vendor_id == 0xffff) {
     549                                pci_fun_delete(fun);
    540550                                /*
    541551                                 * The device is not present, go on scanning the
     
    559569                        if (fun_name == NULL) {
    560570                                ddf_msg(LVL_ERROR, "Out of memory.");
     571                                pci_fun_delete(fun);
    561572                                return;
    562573                        }
    563574                       
    564                         fnode = ddf_fun_create(bus->dnode, fun_inner, fun_name);
     575                        rc = ddf_fun_set_name(fun->fnode, fun_name);
    565576                        free(fun_name);
    566                         if (fnode == NULL) {
    567                                 ddf_msg(LVL_ERROR, "Failed creating function.");
     577                        if (rc != EOK) {
     578                                ddf_msg(LVL_ERROR, "Failed setting function name.");
     579                                pci_fun_delete(fun);
    568580                                return;
    569581                        }
    570                        
    571                         fun->fnode = fnode;
    572582                       
    573583                        pci_alloc_resource_list(fun);
     
    575585                        pci_read_interrupt(fun);
    576586                       
    577                         fnode->ops = &pci_fun_ops;
    578                         fnode->driver_data = fun;
     587                        ddf_fun_set_ops(fun->fnode, &pci_fun_ops);
    579588                       
    580589                        ddf_msg(LVL_DEBUG, "Adding new function %s.",
    581                             fnode->name);
     590                            ddf_fun_get_name(fun->fnode));
    582591                       
    583592                        pci_fun_create_match_ids(fun);
    584593                       
    585                         if (ddf_fun_bind(fnode) != EOK) {
     594                        if (ddf_fun_bind(fun->fnode) != EOK) {
    586595                                pci_clean_resource_list(fun);
    587                                 clean_match_ids(&fnode->match_ids);
    588                                 free((char *) fnode->name);
    589                                 fnode->name = NULL;
     596                                pci_fun_delete(fun);
    590597                                continue;
    591598                        }
     
    601608                                        pci_bus_scan(bus, child_bus);
    602609                        }
    603                        
    604                         fun = pci_fun_new(bus);
    605610                }
    606         }
    607        
    608         if (fun->vendor_id == 0xffff) {
    609                 /* Free the auxiliary function structure. */
    610                 pci_fun_delete(fun);
    611611        }
    612612}
     
    617617        ddf_fun_t *ctl = NULL;
    618618        bool got_res = false;
     619        async_sess_t *sess;
    619620        int rc;
    620621       
    621622        ddf_msg(LVL_DEBUG, "pci_dev_add");
    622         dnode->parent_sess = NULL;
    623623       
    624624        bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t));
     
    631631
    632632        bus->dnode = dnode;
    633         dnode->driver_data = bus;
    634        
    635         dnode->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
    636             dnode->handle, IPC_FLAG_BLOCKING);
    637         if (!dnode->parent_sess) {
     633       
     634        sess = ddf_dev_parent_sess_create(dnode, EXCHANGE_SERIALIZE);
     635        if (sess == NULL) {
    638636                ddf_msg(LVL_ERROR, "pci_dev_add failed to connect to the "
    639637                    "parent driver.");
     
    644642        hw_resource_list_t hw_resources;
    645643       
    646         rc = hw_res_get_resource_list(dnode->parent_sess, &hw_resources);
     644        rc = hw_res_get_resource_list(sess, &hw_resources);
    647645        if (rc != EOK) {
    648646                ddf_msg(LVL_ERROR, "pci_dev_add failed to get hw resources "
     
    708706       
    709707fail:
    710         if (dnode->parent_sess)
    711                 async_hangup(dnode->parent_sess);
    712        
    713708        if (got_res)
    714709                hw_res_clean_resource_list(&hw_resources);
     
    742737{
    743738        pci_fun_t *fun;
    744        
    745         fun = (pci_fun_t *) calloc(1, sizeof(pci_fun_t));
     739        ddf_fun_t *fnode;
     740       
     741        fnode = ddf_fun_create(bus->dnode, fun_inner, NULL);
     742        if (fnode == NULL)
     743                return NULL;
     744
     745        fun = ddf_fun_data_alloc(fnode, sizeof(pci_fun_t));
    746746        if (fun == NULL)
    747747                return NULL;
    748748
    749749        fun->busptr = bus;
     750        fun->fnode = fnode;
    750751        return fun;
    751752}
     
    766767void pci_fun_delete(pci_fun_t *fun)
    767768{
    768         assert(fun != NULL);
    769769        hw_res_clean_resource_list(&fun->hw_resources);
    770         free(fun);
     770        if (fun->fnode != NULL)
     771                ddf_fun_destroy(fun->fnode);
    771772}
    772773
Note: See TracChangeset for help on using the changeset viewer.