Ignore:
File:
1 edited

Legend:

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

    rd93aafed r663f41c4  
    6565        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    6666       
    67         if (dev_data == NULL)
     67        if (NULL == dev_data)
    6868                return NULL;
    6969        return &dev_data->hw_resources;
     
    109109       
    110110        bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
    111         if (bus_data != NULL) {
     111        if (NULL != bus_data) {
    112112                memset(bus_data, 0, sizeof(pci_bus_data_t));
    113113                fibril_mutex_initialize(&bus_data->conf_mutex);
    114114        }
    115 
    116115        return bus_data;
    117116}
     
    124123static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len)
    125124{
    126         assert(dev->parent != NULL);
     125        assert(NULL != dev->parent);
    127126       
    128127        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     
    154153static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len)
    155154{
    156         assert(dev->parent != NULL);
     155        assert(NULL != dev->parent);
    157156       
    158157        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     
    225224       
    226225        match_id = create_match_id();
    227         if (match_id != NULL) {
     226        if (NULL != match_id) {
    228227                asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
    229228                    dev_data->vendor_id, dev_data->device_id);
     
    231230                match_id->score = 90;
    232231                add_match_id(&dev->match_ids, match_id);
    233         }
    234 
     232        }       
    235233        /* TODO add more ids (with subsys ids, using class id etc.) */
    236234}
     
    244242        size_t count = hw_res_list->count;
    245243       
    246         assert(hw_resources != NULL);
     244        assert(NULL != hw_resources);
    247245        assert(count < PCI_MAX_HW_RES);
    248246       
     
    277275        bool io;
    278276        /* 64-bit wide address */
    279         bool addrw64;
     277        bool w64;
    280278       
    281279        /* Size of the io or memory range specified by the BAR */
     
    289287        io = (bool) (val & 1);
    290288        if (io) {
    291                 addrw64 = false;
     289                w64 = false;
    292290        } else {
    293291                switch ((val >> 1) & 3) {
    294292                case 0:
    295                         addrw64 = false;
     293                        w64 = false;
    296294                        break;
    297295                case 2:
    298                         addrw64 = true;
     296                        w64 = true;
    299297                        break;
    300298                default:
     
    314312        range_size = pci_bar_mask_to_size(mask);
    315313       
    316         if (addrw64) {
     314        if (w64) {
    317315                range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) |
    318316                    (val & 0xfffffff0);
     
    321319        }
    322320       
    323         if (range_addr != 0) {
     321        if (0 != range_addr) {
    324322                printf(NAME ": device %s : ", dev->name);
    325323                printf("address = %x", range_addr);
     
    329327        pci_add_range(dev, range_addr, range_size, io);
    330328       
    331         if (addrw64)
     329        if (w64)
    332330                return addr + 8;
    333331       
     
    356354{
    357355        uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE);
    358         if (irq != 0xff)
     356        if (0xff != irq)
    359357                pci_add_interrupt(dev, irq);
    360358}
     
    417415                        create_pci_match_ids(dev);
    418416                       
    419                         if (child_device_register(dev, parent) != EOK) {
     417                        if (EOK != child_device_register(dev, parent)) {
    420418                                pci_clean_resource_list(dev);
    421419                                clean_match_ids(&dev->match_ids);
     
    426424                       
    427425                        if (header_type == PCI_HEADER_TYPE_BRIDGE ||
    428                             header_type == PCI_HEADER_TYPE_CARDBUS) {
     426                            header_type == PCI_HEADER_TYPE_CARDBUS ) {
    429427                                child_bus = pci_conf_read_8(dev,
    430428                                    PCI_BRIDGE_SEC_BUS_NUM);
    431429                                printf(NAME ": device is pci-to-pci bridge, "
    432430                                    "secondary bus number = %d.\n", bus_num);
    433                                 if (child_bus > bus_num)
     431                                if(child_bus > bus_num)
    434432                                        pci_bus_scan(parent, child_bus);
    435433                        }
     
    455453       
    456454        pci_bus_data_t *bus_data = create_pci_bus_data();
    457         if (bus_data == NULL) {
     455        if (NULL == bus_data) {
    458456                printf(NAME ": pci_add_device allocation failed.\n");
    459457                return ENOMEM;
     
    515513}
    516514
    517 pci_dev_data_t *create_pci_dev_data(void)
    518 {
    519         pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
    520        
    521         if (res != NULL)
    522                 memset(res, 0, sizeof(pci_dev_data_t));
    523         return res;
    524 }
    525 
    526 void init_pci_dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn)
    527 {
    528         dev_data->bus = bus;
    529         dev_data->dev = dev;
    530         dev_data->fn = fn;
    531 }
    532 
    533 void delete_pci_dev_data(pci_dev_data_t *dev_data)
    534 {
    535         if (dev_data != NULL) {
    536                 clean_hw_resource_list(&dev_data->hw_resources);
    537                 free(dev_data);
    538         }
    539 }
    540 
    541 void create_pci_dev_name(device_t *dev)
    542 {
    543         pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    544         char *name = NULL;
    545        
    546         asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
    547             dev_data->fn);
    548         dev->name = name;
    549 }
    550 
    551 bool pci_alloc_resource_list(device_t *dev)
    552 {
    553         pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
    554        
    555         dev_data->hw_resources.resources =
    556             (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
    557         return dev_data->hw_resources.resources != NULL;
    558 }
    559 
    560 void pci_clean_resource_list(device_t *dev)
    561 {
    562         pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    563        
    564         if (dev_data->hw_resources.resources != NULL) {
    565                 free(dev_data->hw_resources.resources);
    566                 dev_data->hw_resources.resources = NULL;
    567         }
    568 }
    569 
    570 /** Read the base address registers (BARs) of the device and adds the addresses
    571  * to its hw resource list.
    572  *
    573  * @param dev the pci device.
    574  */
    575 void pci_read_bars(device_t *dev)
    576 {
    577         /*
    578          * Position of the BAR in the PCI configuration address space of the
    579          * device.
    580          */
    581         int addr = PCI_BASE_ADDR_0;
    582        
    583         while (addr <= PCI_BASE_ADDR_5)
    584                 addr = pci_read_bar(dev, addr);
    585 }
    586 
    587 size_t pci_bar_mask_to_size(uint32_t mask)
    588 {
    589         return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
    590 }
    591 
    592515int main(int argc, char *argv[])
    593516{
Note: See TracChangeset for help on using the changeset viewer.