acpi 自动注册platform_device 2

在acpi_create_platform_device中找到acpi_device的resource后,这个resource主要是针对PCIe设备的,其他的设备没啥作用,
具体分析如下
    } else if (count > 0) {
        resources = kzalloc(count * sizeof(struct resource),
                    GFP_KERNEL);
        if (!resources) {
            dev_err(&adev->dev, "No memory for resources\n");
            acpi_dev_free_resource_list(&resource_list);
            return ERR_PTR(-ENOMEM);
        }
        count = 0;
        list_for_each_entry(rentry, &resource_list, node)
            acpi_platform_fill_resource(adev, rentry->res,
                            &resources[count++]);

        acpi_dev_free_resource_list(&resource_list);
    }
会调用首先申请一个resource,然后调用acpi_platform_fill_resource 来填充resource
static void acpi_platform_fill_resource(struct acpi_device *adev,
    const struct resource *src, struct resource *dest)
{
    struct device *parent;

    *dest = *src;

    /*
     * If the device has parent we need to take its resources into
     * account as well because this device might consume part of those.
     */
    parent = acpi_get_first_physical_node(adev->parent);
    if (parent && dev_is_pci(parent))
        dest->parent = pci_find_resource(to_pci_dev(parent), dest);
}
如果这个device 有parent的话,就需要找到。如果parent 不是NULL且是pci设备的话,也要将parent的resource添加到当前device的
resource中
具体是根据dev_is_pci(parent) 来判断是不是pcie设备
#define dev_is_pci(d) ((d)->bus == &pci_bus_type)
只要bus是pci_bus_type就是pcie设备,这个是必然的.
最后会将的得到的resource 赋值给dev
    pdevinfo.res = resources;
如果不是pcie设备,那resource 应该指向一段zero memory.
在acpi_create_platform_device 中还要判断是被是否支持dma
    if (acpi_dma_supported(adev))
        pdevinfo.dma_mask = DMA_BIT_MASK(32);
    else
        pdevinfo.dma_mask = 0;
如果支持的话,dma_mask==32,所以不支持mask不是32的dma,这部分可能要在自己的probe函数中自己去修改.
判断是否支持dma的方法如下:
bool acpi_dma_supported(struct acpi_device *adev)
{
    if (!adev)
        return false;

    if (adev->flags.cca_seen)
        return true;

    /*
    * Per ACPI 6.0 sec 6.2.17, assume devices can do cache-coherent
    * DMA on "Intel platforms".  Presumably that includes all x86 and
    * ia64, and other arches will set CONFIG_ACPI_CCA_REQUIRED=y.
    */
    if (!IS_ENABLED(CONFIG_ACPI_CCA_REQUIRED))
        return true;

    return false;
}

可见只要设定adev->flags.cca_seen 或者没有定义CONFIG_ACPI_CCA_REQUIRED 就返回true,代表支持dma.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
platform_driver结构体是Linux内核中用于管理平台设备驱动的结构体,它包含了平台驱动程序的所有信息和操作方法,包括设备的初始化、配置、挂载、卸载等功能。以下是platform_driver结构体的主要成员: 1. driver:指向一个struct device_driver结构体的指针,描述了该驱动程序的所有属性和操作方法。 2. probe:设备探测函数指针,当一个平台设备被发现时,该函数会被调用,用于初始化和配置设备。 3. remove:设备卸载函数指针,当一个平台设备被移除时,该函数会被调用,用于释放设备资源和清理设备状态。 4. suspend:设备挂起函数指针,当系统需要挂起设备时,该函数会被调用,用于保存设备状态和关闭设备。 5. resume:设备恢复函数指针,当系统需要恢复设备时,该函数会被调用,用于恢复设备状态和打开设备。 6. id_table:平台设备ID表,包含了该驱动程序支持的所有平台设备的ID。 7. driver.name:驱动程序的名称。 8. driver.owner:驱动程序的所有者。 9. driver.bus:驱动程序所属的总线类型。 10. driver.of_match_table:设备树匹配表,用于匹配设备树中的平台设备。 11. driver.acpi_match_table:ACPI匹配表,用于匹配ACPI设备。 12. driver.pm:设备的电源管理,用于控制设备的电源状态。 13. driver.probe_type:设备探测类型,用于指定设备探测的方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值