MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_pci_device_alloc_resource

Function rt_pci_device_alloc_resource

components/drivers/pci/pci.c:528–717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526}
527
528rt_err_t rt_pci_device_alloc_resource(struct rt_pci_host_bridge *host_bridge,
529 struct rt_pci_device *pdev)
530{
531 rt_err_t err = RT_EOK;
532 rt_size_t size;
533 rt_ubase_t addr = 0;
534 rt_uint32_t cfg;
535 rt_size_t bars_nr;
536 rt_uint8_t hdr_type;
537 rt_bool_t prefetch = RT_FALSE;
538 rt_uint16_t class, command = 0;
539
540 for (int i = 0; i < host_bridge->bus_regions_nr; ++i)
541 {
542 if (host_bridge->bus_regions[i].flags == PCI_BUS_REGION_F_PREFETCH)
543 {
544 prefetch = RT_TRUE;
545 break;
546 }
547 }
548
549 rt_pci_read_config_u16(pdev, PCIR_COMMAND, &command);
550 command = (command & ~(PCIM_CMD_PORTEN | PCIM_CMD_MEMEN)) | PCIM_CMD_BUSMASTEREN;
551 rt_pci_read_config_u8(pdev, PCIR_HDRTYPE, &hdr_type);
552
553 if (pdev->hdr_type != hdr_type)
554 {
555 LOG_W("%s may not initialized", rt_dm_dev_get_name(&pdev->parent));
556 }
557
558 switch (hdr_type)
559 {
560 case PCIM_HDRTYPE_NORMAL:
561 bars_nr = PCI_STD_NUM_BARS;
562 break;
563
564 case PCIM_HDRTYPE_BRIDGE:
565 bars_nr = 2;
566 break;
567
568 case PCIM_HDRTYPE_CARDBUS:
569 bars_nr = 0;
570 break;
571
572 default:
573 bars_nr = 0;
574 break;
575 }
576
577 for (int i = 0; i < bars_nr; ++i)
578 {
579 rt_ubase_t flags;
580 rt_ubase_t bar_base;
581 rt_bool_t mem64 = RT_FALSE;
582 struct rt_pci_bus_region *region;
583
584 cfg = 0;
585 bar_base = PCIR_BAR(i);

Callers 1

rt_pci_setup_deviceFunction · 0.85

Calls 8

rt_pci_read_config_u16Function · 0.85
rt_pci_read_config_u8Function · 0.85
rt_dm_dev_get_nameFunction · 0.85
rt_pci_write_config_u32Function · 0.85
rt_pci_read_config_u32Function · 0.85
rt_pci_region_allocFunction · 0.85
rt_pci_write_config_u16Function · 0.85
rt_pci_write_config_u8Function · 0.85

Tested by

no test coverage detected