【问题标题】:Multiple PCIe cards: Read device tree properties of the CURRENT PCIe card instance (within a kernel driver)多个 PCIe 卡:读取当前 PCIe 卡实例的设备树属性(在内核驱动程序内)
【发布时间】:2020-05-04 17:13:46
【问题描述】:

问题:

我们正在扩展设备驱动程序。我们的 PCIe 设备具有无法自动检测的属性。为了与 Linux 内核维护者保持一致,我们希望将此属性添加到设备树中。当系统中存在多个 PCIe 卡时,如何在驱动程序代码中访问驱动程序当前正在处理的 CURRENT 实例的属性?

上下文:

我们在以太网驱动程序的上下文中执行此操作,但是对于任何 PCIe 连接设备(甚至总线连接设备)的驱动程序,此问题都是通用的。

例子:

pcie@1ff00000 {
    ...
    host@0 {
        reg = < 0x00 0x00 0x00 0x00 0x00 >;
        #address-cells = < 0x03 >;
        #size-cells = < 0x02 >;

        ethernet@0 {
            compatible = "weiland-yutani,nostromo";
            reg = < 0x00 0x00 0x00 0x00 0x00 >;
            phy-connection-type = "rgmii";
        };
    };
    host@1 {
        reg = < 0x00 0x00 0x00 0x00 0x00 >;
        #address-cells = < 0x03 >;
        #size-cells = < 0x02 >;

        ethernet@0 {
            compatible = "weiland-yutani,nostromo";
            reg = < 0x00 0x00 0x00 0x00 0x00 >;
            phy-connection-type = "mii";
        };
    };
};

此示例显示了两个 PCIe 以太网卡,其中一个使用“rgmii”,另一个使用“mii”作为传输模式。 (仅作为示例,我们还有更多配置正在进行)。

在内核驱动程序代码中,如何访问属于我正在处理的当前 PCIe 实例 (pci_dev *pdev) 的节点?我的意思是,哪种 of_find_node_by_path() 调用或任何可以引导我找到正确实例的方法?因此,我可以向我的以太网驱动程序添加一个 if 语句,该语句对正确的 rgmii 或 mii 配置作出反应,具体取决于驱动程序当前正在处理的两张 PCIe 卡中的哪一张。

该方法需要通用,因为我们的目标是将其贡献回 Linux 内核。 (任意数量的 PCI 总线、卡、拓扑......)

非常感谢。

【问题讨论】:

    标签: linux driver device-tree pci-e


    【解决方案1】:

    当前节点由pdev->dev->of_node传递给驱动实例。

    示例:在上面的设备树中,驱动程序将直接访问 ethernet@0 节点,无需进一步遍历:

    static int nostromo_pcidev_probe(struct pci_dev *pdev, const struct pci_device_id *id)
    {
        const char *conn-type;    
        of_property_read_string(pdev->dev->of_node, "phy-connection-type", &conn-type);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-12
      • 2017-03-31
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      相关资源
      最近更新 更多