在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.
具体分析如下
} 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.