static void acpi_platform_fill_resource(struct acpi_device *adev,
const struct resource *src, struct resource *dest)
这个函数用于将src的的resource赋值给dest。
其源码分析如下:
static void acpi_platform_fill_resource(struct acpi_device *adev,
const struct resource *src, struct resource *dest)
{
struct device *parent;
#将src的resource 赋值给dest
*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.
*/
#找到这个acpi_device的父设备
parent = acpi_get_first_physical_node(adev->parent);
#如果这个父设备是一个pcie设备的的话。dest也好包含父设备的resource
if (parent && dev_is_pci(parent))
dest->parent = pci_find_resource(to_pci_dev(parent), dest);
}
struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
{
int i;
#遍历父设备的资源
for (i = 0; i < PCI_ROM_RESOURCE; i++) {
struct resource *r = &dev->resource[i];
#如果资源不为null,且已经包含自设备的资源,就返回这个资源
if (r->start && resource_contains(r, res))
return r;
}
return NULL;
}
resource_contains 的实现比较简单,只有在形参r1 完全包含r2的时候才返回true
static inline bool resource_contains(struct resource *r1, struct resource *r2)
{
#首先比较type 是否相等,type 不相等的话直接返回false
if (resource_type(r1) != resource_type(r2))
return false;
#父设备和子设备如果包含UNSET flags,则退出
if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
return false;
return r1->start <= r2->start && r1->end >= r2->end;
}
内核ACPI函数API之acpi_platform_fill_resource
最新推荐文章于 2021-05-18 10:10:37 发布