pci总线pci_dev的创建和匹配

pci总线注册


在pci-driver.c文件里会初始化注册pci总线
在这里插入图片描述
看pci总线结构体的申明

struct bus_type pci_bus_type = {
   
   
	.name		= "pci",
	.match		= pci_bus_match,
	.uevent		= pci_uevent,
	.probe		= pci_device_probe,
	.remove		= pci_device_remove,
	.shutdown	= pci_device_shutdown,
	.dev_groups	= pci_dev_groups,
	.bus_groups	= pci_bus_groups,
	.drv_groups	= pci_drv_groups,
	.pm		= PCI_PM_OPS_PTR,
	.num_vf		= pci_bus_num_vf,
	.dma_configure	= pci_dma_configure,
	.dma_cleanup	= pci_dma_cleanup,
};

这里重点看下pci-dev和pci-driver匹配的规则match回调函数

static int nv_resize_pcie_bars(struct pci_dev *pci_dev) { #if defined(NV_PCI_REBAR_GET_POSSIBLE_SIZES_PRESENT) u16 cmd; int r, old_size, requested_size; unsigned long sizes; int ret = 0; #if NV_IS_EXPORT_SYMBOL_PRESENT_pci_find_host_bridge struct pci_host_bridge *host; #endif /* if (NVreg_EnableResizableBar == 0) { nv_printf(NV_DBG_INFO, "NVRM: resizable BAR disabled by regkey, skipping\n"); return 0; }*/ // Check if BAR1 has PCIe rebar capabilities sizes = pci_rebar_get_possible_sizes(pci_dev, NV_GPU_BAR1); if (sizes == 0) { /* ReBAR not available. Nothing to do. */ return 0; } /* Try to resize the BAR to the largest supported size */ requested_size = fls(sizes) - 1; /* Save the current size, just in case things go wrong */ old_size = pci_rebar_bytes_to_size(pci_resource_len(pci_dev, NV_GPU_BAR1)); if (old_size == requested_size) { nv_printf(NV_DBG_INFO, "NVRM: %04x:%02x:%02x.%x: BAR1 already at requested size.\n", NV_PCI_DOMAIN_NUMBER(pci_dev), NV_PCI_BUS_NUMBER(pci_dev), NV_PCI_SLOT_NUMBER(pci_dev), PCI_FUNC(pci_dev->devfn)); return 0; } #if NV_IS_EXPORT_SYMBOL_PRESENT_pci_find_host_bridge /* If the kernel will refuse us, don't even try to resize, but give an informative error */ host = pci_find_host_bridge(pci_dev->bus); if (host->preserve_config) { nv_printf(NV_DBG_INFO, "NVRM: Not resizing BAR because the firmware forbids moving windows.\n"); return 0; } #endif nv_printf(NV_DBG_INFO, "NVRM: %04x:%02x:%02x.%x: Attempting to resize BAR1.\n", NV_PCI_DOMAIN_NUMBER(pci_dev), NV_PCI_BUS_NUMBER(pci_dev), NV_PCI_SLOT_NUMBER(pci_dev), PCI_FUNC(pci_dev->devfn)); /* Disable memory decoding - required by the kernel APIs */ pci_read_config_word(pci_dev, PCI_COMMAND, &cmd); pci_write_config_word(pci_dev, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY); /* Release BAR1 */ pci_release_resource(pci_dev, NV_GPU_BAR1); /* Release BAR3 - we don't want to resize it, it's in the same bridge, so we'll want to move it */ pci_release_resource(pci_dev, NV_GPU_BAR3); resize: /* Attempt to resize BAR1 to the largest supported size */ r = pci_resize_resource(pci_dev, NV_GPU_BAR1, requested_size); if (r) { if (r == -ENOSPC) { /* step through smaller sizes down to original size */ if (requested_size > old_size) { clear_bit(fls(sizes) - 1, &sizes); requested_size = fls(sizes) - 1; goto resize; } else { nv_printf(NV_DBG_ERRORS, "NVRM: No address space to allocate resized BAR1.\n"); } } else if (r == -EOPNOTSUPP) { nv_printf(NV_DBG_WARNINGS, "NVRM: BAR resize resource not supported.\n"); } else { nv_printf(NV_DBG_WARNINGS, "NVRM: BAR resizing failed with error `%d`.\n", r); } } /* Re-attempt assignment of PCIe resources */ pci_assign_unassigned_bus_resources(pci_dev->bus); if ((pci_resource_flags(pci_dev, NV_GPU_BAR1) & IORESOURCE_UNSET) || (pci_resource_flags(pci_dev, NV_GPU_BAR3) & IORESOURCE_UNSET)) { if (requested_size != old_size) { /* Try to get the BAR back with the original size */ requested_size = old_size; goto resize; } /* Something went horribly wrong and the kernel didn't manage to re-allocate BAR1. This is unlikely (because we had space before), but can happen. */ nv_printf(NV_DBG_ERRORS, "NVRM: FATAL: Failed to re-allocate BAR1.\n"); ret = -ENODEV; } /* Re-enable memory decoding */ pci_write_config_word(pci_dev, PCI_COMMAND, cmd); return ret; #else nv_printf(NV_DBG_INFO, "NVRM: Resizable BAR is not supported on this kernel version.\n"); return 0; #endif /* NV_PCI_REBAR_GET_POSSIBLE_SIZES_PRESENT */ } #if defined(NV_DEVICE_PROPERTY_READ_U64_PRESENT) && \ defined(CONFIG_ACPI_NUMA) && \ NV_IS_EXPORT_SYMBOL_PRESENT_pxm_to_node /*
07-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bruk_spp

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值