Ignore:
File:
1 edited

Legend:

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

    r1b20da0 ra35b458  
    9393{
    9494        pci_fun_t *fun = pci_fun(fnode);
    95        
     95
    9696        if (fun == NULL)
    9797                return NULL;
     
    103103        size_t i;
    104104        hw_resource_list_t *res = &fun->hw_resources;
    105        
     105
    106106        for (i = 0; i < res->count; i++) {
    107107                if (res->resources[i].type == INTERRUPT &&
     
    110110                }
    111111        }
    112        
     112
    113113        return false;
    114114}
     
    117117{
    118118        pci_fun_t *fun = pci_fun(fnode);
    119        
     119
    120120        if (!pciintel_fun_owns_interrupt(fun, irq))
    121121                return EINVAL;
     
    127127{
    128128        pci_fun_t *fun = pci_fun(fnode);
    129        
     129
    130130        if (!pciintel_fun_owns_interrupt(fun, irq))
    131131                return EINVAL;
     
    137137{
    138138        pci_fun_t *fun = pci_fun(fnode);
    139        
     139
    140140        if (!pciintel_fun_owns_interrupt(fun, irq))
    141141                return EINVAL;
     
    147147{
    148148        pci_fun_t *fun = pci_fun(fnode);
    149        
     149
    150150        if (fun == NULL)
    151151                return NULL;
     
    256256        pci_bus_t *bus = pci_bus_from_fun(fun);
    257257        uint32_t val;
    258        
     258
    259259        fibril_mutex_lock(&bus->conf_mutex);
    260260
     
    285285                break;
    286286        }
    287        
     287
    288288        fibril_mutex_unlock(&bus->conf_mutex);
    289289}
     
    294294        pci_bus_t *bus = pci_bus_from_fun(fun);
    295295        uint32_t val = 0;
    296        
     296
    297297        fibril_mutex_lock(&bus->conf_mutex);
    298298
     
    317317                }
    318318        }
    319        
     319
    320320        switch (len) {
    321321        case 1:
     
    340340                    host2uint32_t_le(val));
    341341        }
    342        
     342
    343343        fibril_mutex_unlock(&bus->conf_mutex);
    344344}
     
    458458        hw_resource_t *hw_resources =  hw_res_list->resources;
    459459        size_t count = hw_res_list->count;
    460        
     460
    461461        assert(hw_resources != NULL);
    462462        assert(count < PCI_MAX_HW_RES);
    463        
     463
    464464        if (io) {
    465465                hw_resources[count].type = IO_RANGE;
     
    475475                hw_resources[count].res.mem_range.endianness = LITTLE_ENDIAN;
    476476        }
    477        
     477
    478478        hw_res_list->count++;
    479479}
     
    498498        /* 64-bit wide address */
    499499        bool addrw64;
    500        
     500
    501501        /* Size of the io or memory range specified by the BAR */
    502502        size_t range_size;
    503503        /* Beginning of the io or memory range specified by the BAR */
    504504        uint64_t range_addr;
    505        
     505
    506506        /* Get the value of the BAR. */
    507507        val = pci_conf_read_32(fun, addr);
     
    509509#define IO_MASK  (~0x3)
    510510#define MEM_MASK (~0xf)
    511        
     511
    512512        io = (val & 1) != 0;
    513513        if (io) {
     
    528528                }
    529529        }
    530        
     530
    531531        /* Get the address mask. */
    532532        pci_conf_write_32(fun, addr, 0xffffffff);
     
    544544        pci_conf_write_32(fun, addr, val);
    545545        val = pci_conf_read_32(fun, addr);
    546        
     546
    547547        range_size = pci_bar_mask_to_size(mask);
    548        
     548
    549549        if (addrw64) {
    550550                range_addr = ((uint64_t)pci_conf_read_32(fun, addr + 4) << 32) |
     
    553553                range_addr = (val & 0xfffffff0);
    554554        }
    555        
     555
    556556        if (range_addr != 0) {
    557557                ddf_msg(LVL_DEBUG, "Function %s : address = %" PRIx64
     
    559559                    (unsigned int) range_size);
    560560        }
    561        
     561
    562562        pci_add_range(fun, range_addr, range_size, io);
    563        
     563
    564564        if (addrw64)
    565565                return addr + 8;
    566        
     566
    567567        return addr + 4;
    568568}
     
    573573        hw_resource_t *hw_resources = hw_res_list->resources;
    574574        size_t count = hw_res_list->count;
    575        
     575
    576576        assert(NULL != hw_resources);
    577577        assert(count < PCI_MAX_HW_RES);
    578        
     578
    579579        hw_resources[count].type = INTERRUPT;
    580580        hw_resources[count].res.interrupt.irq = irq;
    581        
     581
    582582        hw_res_list->count++;
    583        
     583
    584584        ddf_msg(LVL_NOTE, "Function %s uses irq %x.", ddf_fun_get_name(fun->fnode), irq);
    585585}
     
    603603        pci_fun_t *fun;
    604604        errno_t rc;
    605        
     605
    606606        int child_bus = 0;
    607607        int dnum, fnum;
    608608        bool multi;
    609609        uint8_t header_type;
    610        
     610
    611611        for (dnum = 0; dnum < 32; dnum++) {
    612612                multi = true;
    613613                for (fnum = 0; multi && fnum < 8; fnum++) {
    614614                        fun = pci_fun_new(bus);
    615                        
     615
    616616                        pci_fun_init(fun, bus_num, dnum, fnum);
    617617                        if (fun->vendor_id == 0xffff) {
     
    626626                                        continue;
    627627                        }
    628                        
     628
    629629                        header_type = pci_conf_read_8(fun, PCI_HEADER_TYPE);
    630630                        if (fnum == 0) {
     
    634634                        /* Clear the multifunction bit. */
    635635                        header_type = header_type & 0x7F;
    636                        
     636
    637637                        char *fun_name = pci_fun_create_name(fun);
    638638                        if (fun_name == NULL) {
     
    641641                                return;
    642642                        }
    643                        
     643
    644644                        rc = ddf_fun_set_name(fun->fnode, fun_name);
    645645                        free(fun_name);
     
    649649                                return;
    650650                        }
    651                        
     651
    652652                        pci_alloc_resource_list(fun);
    653653                        pci_read_bars(fun);
     
    656656                        /* Propagate the PIO window to the function. */
    657657                        fun->pio_window = bus->pio_win;
    658                        
     658
    659659                        ddf_fun_set_ops(fun->fnode, &pci_fun_ops);
    660                        
     660
    661661                        ddf_msg(LVL_DEBUG, "Adding new function %s.",
    662662                            ddf_fun_get_name(fun->fnode));
    663663
    664664                        pci_fun_create_match_ids(fun);
    665                        
     665
    666666                        if (ddf_fun_bind(fun->fnode) != EOK) {
    667667                                pci_clean_resource_list(fun);
     
    669669                                continue;
    670670                        }
    671                        
     671
    672672                        if (header_type == PCI_HEADER_TYPE_BRIDGE ||
    673673                            header_type == PCI_HEADER_TYPE_CARDBUS) {
     
    692692        async_sess_t *sess;
    693693        errno_t rc;
    694        
     694
    695695        ddf_msg(LVL_DEBUG, "pci_dev_add");
    696        
     696
    697697        bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t));
    698698        if (bus == NULL) {
     
    704704
    705705        bus->dnode = dnode;
    706        
     706
    707707        sess = ddf_dev_parent_sess_get(dnode);
    708708        if (sess == NULL) {
     
    719719                goto fail;
    720720        }
    721        
     721
    722722        rc = hw_res_get_resource_list(sess, &hw_resources);
    723723        if (rc != EOK) {
     
    727727        }
    728728        got_res = true;
    729        
    730        
     729
     730
    731731        assert(hw_resources.count >= 1);
    732732
     
    745745                        goto fail;
    746746                }
    747                
     747
    748748        } else {
    749749                assert(hw_resources.resources[0].type == IO_RANGE);
    750750                assert(hw_resources.resources[0].res.io_range.size >= 4);
    751        
     751
    752752                assert(hw_resources.resources[1].type == IO_RANGE);
    753753                assert(hw_resources.resources[1].res.io_range.size >= 4);
    754        
     754
    755755                ddf_msg(LVL_DEBUG, "conf_addr = %" PRIx64 ".",
    756756                    hw_resources.resources[0].res.io_range.address);
    757757                ddf_msg(LVL_DEBUG, "data_addr = %" PRIx64 ".",
    758758                    hw_resources.resources[1].res.io_range.address);
    759        
     759
    760760                if (pio_enable_resource(&bus->pio_win,
    761761                    &hw_resources.resources[0],
     
    775775                }
    776776        }
    777        
     777
    778778        /* Make the bus device more visible. It has no use yet. */
    779779        ddf_msg(LVL_DEBUG, "Adding a 'ctl' function");
    780        
     780
    781781        ctl = ddf_fun_create(bus->dnode, fun_exposed, "ctl");
    782782        if (ctl == NULL) {
     
    785785                goto fail;
    786786        }
    787        
     787
    788788        rc = ddf_fun_bind(ctl);
    789789        if (rc != EOK) {
     
    791791                goto fail;
    792792        }
    793        
     793
    794794        /* Enumerate functions. */
    795795        ddf_msg(LVL_DEBUG, "Scanning the bus");
    796796        pci_bus_scan(bus, 0);
    797        
     797
    798798        hw_res_clean_resource_list(&hw_resources);
    799        
     799
    800800        return EOK;
    801        
     801
    802802fail:
    803803        if (got_res)
    804804                hw_res_clean_resource_list(&hw_resources);
    805        
     805
    806806        if (ctl != NULL)
    807807                ddf_fun_destroy(ctl);
    808        
     808
    809809        return rc;
    810810}
     
    831831        pci_fun_t *fun;
    832832        ddf_fun_t *fnode;
    833        
     833
    834834        fnode = ddf_fun_create(bus->dnode, fun_inner, NULL);
    835835        if (fnode == NULL)
     
    852852        fun->vendor_id = pci_conf_read_16(fun, PCI_VENDOR_ID);
    853853        fun->device_id = pci_conf_read_16(fun, PCI_DEVICE_ID);
    854        
     854
    855855        /* Explicitly enable PCI bus mastering */
    856856        fun->command = pci_conf_read_16(fun, PCI_COMMAND) |
    857857            PCI_COMMAND_MASTER;
    858858        pci_conf_write_16(fun, PCI_COMMAND, fun->command);
    859        
     859
    860860        fun->class_code = pci_conf_read_8(fun, PCI_BASE_CLASS);
    861861        fun->subclass_code = pci_conf_read_8(fun, PCI_SUB_CLASS);
     
    874874{
    875875        char *name = NULL;
    876        
     876
    877877        asprintf(&name, "%02x:%02x.%01x", fun->bus, fun->dev,
    878878            fun->fn);
     
    903903         */
    904904        int addr = PCI_BASE_ADDR_0;
    905        
     905
    906906        while (addr <= PCI_BASE_ADDR_5)
    907907                addr = pci_read_bar(fun, addr);
Note: See TracChangeset for help on using the changeset viewer.