Changes in uspace/drv/pciintel/pci.c [d93aafed:663f41c4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/pciintel/pci.c
rd93aafed r663f41c4 65 65 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; 66 66 67 if ( dev_data == NULL)67 if (NULL == dev_data) 68 68 return NULL; 69 69 return &dev_data->hw_resources; … … 109 109 110 110 bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t)); 111 if ( bus_data != NULL) {111 if (NULL != bus_data) { 112 112 memset(bus_data, 0, sizeof(pci_bus_data_t)); 113 113 fibril_mutex_initialize(&bus_data->conf_mutex); 114 114 } 115 116 115 return bus_data; 117 116 } … … 124 123 static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len) 125 124 { 126 assert( dev->parent != NULL);125 assert(NULL != dev->parent); 127 126 128 127 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; … … 154 153 static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len) 155 154 { 156 assert( dev->parent != NULL);155 assert(NULL != dev->parent); 157 156 158 157 pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data; … … 225 224 226 225 match_id = create_match_id(); 227 if ( match_id != NULL) {226 if (NULL != match_id) { 228 227 asprintf(&match_id_str, "pci/ven=%04x&dev=%04x", 229 228 dev_data->vendor_id, dev_data->device_id); … … 231 230 match_id->score = 90; 232 231 add_match_id(&dev->match_ids, match_id); 233 } 234 232 } 235 233 /* TODO add more ids (with subsys ids, using class id etc.) */ 236 234 } … … 244 242 size_t count = hw_res_list->count; 245 243 246 assert( hw_resources != NULL);244 assert(NULL != hw_resources); 247 245 assert(count < PCI_MAX_HW_RES); 248 246 … … 277 275 bool io; 278 276 /* 64-bit wide address */ 279 bool addrw64;277 bool w64; 280 278 281 279 /* Size of the io or memory range specified by the BAR */ … … 289 287 io = (bool) (val & 1); 290 288 if (io) { 291 addrw64 = false;289 w64 = false; 292 290 } else { 293 291 switch ((val >> 1) & 3) { 294 292 case 0: 295 addrw64 = false;293 w64 = false; 296 294 break; 297 295 case 2: 298 addrw64 = true;296 w64 = true; 299 297 break; 300 298 default: … … 314 312 range_size = pci_bar_mask_to_size(mask); 315 313 316 if ( addrw64) {314 if (w64) { 317 315 range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) | 318 316 (val & 0xfffffff0); … … 321 319 } 322 320 323 if ( range_addr != 0) {321 if (0 != range_addr) { 324 322 printf(NAME ": device %s : ", dev->name); 325 323 printf("address = %x", range_addr); … … 329 327 pci_add_range(dev, range_addr, range_size, io); 330 328 331 if ( addrw64)329 if (w64) 332 330 return addr + 8; 333 331 … … 356 354 { 357 355 uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE); 358 if ( irq != 0xff)356 if (0xff != irq) 359 357 pci_add_interrupt(dev, irq); 360 358 } … … 417 415 create_pci_match_ids(dev); 418 416 419 if ( child_device_register(dev, parent) != EOK) {417 if (EOK != child_device_register(dev, parent)) { 420 418 pci_clean_resource_list(dev); 421 419 clean_match_ids(&dev->match_ids); … … 426 424 427 425 if (header_type == PCI_HEADER_TYPE_BRIDGE || 428 header_type == PCI_HEADER_TYPE_CARDBUS ) {426 header_type == PCI_HEADER_TYPE_CARDBUS ) { 429 427 child_bus = pci_conf_read_8(dev, 430 428 PCI_BRIDGE_SEC_BUS_NUM); 431 429 printf(NAME ": device is pci-to-pci bridge, " 432 430 "secondary bus number = %d.\n", bus_num); 433 if 431 if(child_bus > bus_num) 434 432 pci_bus_scan(parent, child_bus); 435 433 } … … 455 453 456 454 pci_bus_data_t *bus_data = create_pci_bus_data(); 457 if ( bus_data == NULL) {455 if (NULL == bus_data) { 458 456 printf(NAME ": pci_add_device allocation failed.\n"); 459 457 return ENOMEM; … … 515 513 } 516 514 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 addresses571 * 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 the579 * 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 592 515 int main(int argc, char *argv[]) 593 516 {
Note:
See TracChangeset
for help on using the changeset viewer.