/** * device_get_next_child_node - Return the next child node handle for a device * @dev: Device to find the next child node for. * @child: Handle to one of the device's child nodes or a null handle. */ struct fwnode_handle *device_get_next_child_node(struct device *dev, struct fwnode_handle *child) { struct acpi_device *adev = ACPI_COMPANION(dev); struct fwnode_handle *fwnode = NULL; if (dev->of_node) fwnode = &dev->of_node->fwnode; else if (adev) fwnode = acpi_fwnode_handle(adev); return fwnode_get_next_child_node(fwnode, child); }
/** * device_get_next_child_node - Return the next child node handle for a device * @dev: Device to find the next child node for. * @child: Handle to one of the device's child nodes or a null handle. */ struct fwnode_handle *device_get_next_child_node(struct device *dev, struct fwnode_handle *child) { if (IS_ENABLED(CONFIG_OF) && dev->of_node) { struct device_node *node; node = of_get_next_available_child(dev->of_node, to_of_node(child)); if (node) return &node->fwnode; } else if (IS_ENABLED(CONFIG_ACPI)) { struct acpi_device *node; node = acpi_get_next_child(dev, to_acpi_node(child)); if (node) return acpi_fwnode_handle(node); } return NULL; }
/** * fwnode_get_reference_node - Find the firmware node referenced * @fwnode: Firmware node to get the property from. * @propname: Name of the property * @index: Index of the reference * * Returns referenced fwnode handler pointer, or an NULL if not found */ struct fwnode_handle *fwnode_get_reference_node(struct fwnode_handle *fwnode, const char *propname, int index) { if (is_of_node(fwnode)) { struct device_node *np; np = of_parse_phandle(to_of_node(fwnode), propname, index); if(!np) return NULL; return &np->fwnode; } else if (is_acpi_node(fwnode)) { struct acpi_device *adev; adev = acpi_dev_get_reference_device(to_acpi_device_node(fwnode), propname, index); if(!adev) return NULL; return acpi_fwnode_handle(adev); } return NULL; }
static bool acpi_pci_bridge_d3(struct pci_dev *dev) { const struct fwnode_handle *fwnode; struct acpi_device *adev; struct pci_dev *root; u8 val; if (!dev->is_hotplug_bridge) return false; /* * Look for a special _DSD property for the root port and if it * is set we know the hierarchy behind it supports D3 just fine. */ root = pci_find_pcie_root_port(dev); if (!root) return false; adev = ACPI_COMPANION(&root->dev); if (root == dev) { /* * It is possible that the ACPI companion is not yet bound * for the root port so look it up manually here. */ if (!adev && !pci_dev_is_added(root)) adev = acpi_pci_find_companion(&root->dev); } if (!adev) return false; fwnode = acpi_fwnode_handle(adev); if (fwnode_property_read_u8(fwnode, "HotPlugSupportInD3", &val)) return false; return val == 1; }
mutex_lock(&acpi_parent->physical_node_lock); list = &acpi_parent->physical_node_list; if (!list_empty(list)) { entry = list_first_entry(list, struct acpi_device_physical_node, node); pdevinfo.parent = entry->dev; } mutex_unlock(&acpi_parent->physical_node_lock); } pdevinfo.name = dev_name(&adev->dev); pdevinfo.id = -1; pdevinfo.res = resources; pdevinfo.num_res = count; pdevinfo.fwnode = acpi_fwnode_handle(adev); if (acpi_dma_supported(adev)) pdevinfo.dma_mask = DMA_BIT_MASK(32); else pdevinfo.dma_mask = 0; pdev = platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) dev_err(&adev->dev, "platform device creation failed: %ld\n", PTR_ERR(pdev)); else dev_dbg(&adev->dev, "created platform device %s\n", dev_name(&pdev->dev)); kfree(resources);
static struct sdw_intel_ctx *sdw_intel_add_controller(struct sdw_intel_res *res) { struct platform_device_info pdevinfo; struct platform_device *pdev; struct sdw_link_data *link; struct sdw_intel_ctx *ctx; struct acpi_device *adev; int ret, i; u8 count; u32 caps; if (acpi_bus_get_device(res->handle, &adev)) return NULL; /* Found controller, find links supported */ count = 0; ret = fwnode_property_read_u8_array(acpi_fwnode_handle(adev), "mipi-sdw-master-count", &count, 1); /* Don't fail on error, continue and use hw value */ if (ret) { dev_err(&adev->dev, "Failed to read mipi-sdw-master-count: %d\n", ret); count = SDW_MAX_LINKS; } /* Check SNDWLCAP.LCOUNT */ caps = ioread32(res->mmio_base + SDW_SHIM_BASE + SDW_SHIM_LCAP); /* Check HW supported vs property value and use min of two */ count = min_t(u8, caps, count); /* Check count is within bounds */ if (count > SDW_MAX_LINKS) { dev_err(&adev->dev, "Link count %d exceeds max %d\n", count, SDW_MAX_LINKS); return NULL; } dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count); ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return NULL; ctx->count = count; ctx->links = kcalloc(ctx->count, sizeof(*ctx->links), GFP_KERNEL); if (!ctx->links) goto link_err; link = ctx->links; /* Create SDW Master devices */ for (i = 0; i < count; i++) { link->res.irq = res->irq; link->res.registers = res->mmio_base + SDW_LINK_BASE + (SDW_LINK_SIZE * i); link->res.shim = res->mmio_base + SDW_SHIM_BASE; link->res.alh = res->mmio_base + SDW_ALH_BASE; link->res.ops = res->ops; link->res.arg = res->arg; memset(&pdevinfo, 0, sizeof(pdevinfo)); pdevinfo.parent = res->parent; pdevinfo.name = "int-sdw"; pdevinfo.id = i; pdevinfo.fwnode = acpi_fwnode_handle(adev); pdevinfo.data = &link->res; pdevinfo.size_data = sizeof(link->res); pdev = platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) { dev_err(&adev->dev, "platform device creation failed: %ld\n", PTR_ERR(pdev)); goto pdev_err; } link->pdev = pdev; link++; } return ctx; pdev_err: sdw_intel_cleanup_pdev(ctx); link_err: kfree(ctx); return NULL; }
/** * acpi_create_platform_device - Create platform device for ACPI device node * @adev: ACPI device node to create a platform device for. * * Check if the given @adev can be represented as a platform device and, if * that's the case, create and register a platform device, populate its common * resources and returns a pointer to it. Otherwise, return %NULL. * * Name of the platform device will be the same as @adev's. */ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) { struct platform_device *pdev = NULL; struct platform_device_info pdevinfo; struct resource_entry *rentry; struct list_head resource_list; struct resource *resources = NULL; int count; /* If the ACPI node already has a physical device attached, skip it. */ if (adev->physical_node_count) return NULL; if (!acpi_match_device_ids(adev, forbidden_id_list)) return ERR_PTR(-EINVAL); INIT_LIST_HEAD(&resource_list); count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); if (count < 0) { return NULL; } else if (count > 0) { resources = kmalloc(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) resources[count++] = *rentry->res; acpi_dev_free_resource_list(&resource_list); } memset(&pdevinfo, 0, sizeof(pdevinfo)); /* * If the ACPI node has a parent and that parent has a physical device * attached to it, that physical device should be the parent of the * platform device we are about to create. */ pdevinfo.parent = adev->parent ? acpi_get_first_physical_node(adev->parent) : NULL; pdevinfo.name = dev_name(&adev->dev); pdevinfo.id = -1; pdevinfo.res = resources; pdevinfo.num_res = count; pdevinfo.fwnode = acpi_fwnode_handle(adev); if (acpi_dma_supported(adev)) pdevinfo.dma_mask = DMA_BIT_MASK(32); else pdevinfo.dma_mask = 0; pdev = platform_device_register_full(&pdevinfo); if (IS_ERR(pdev)) dev_err(&adev->dev, "platform device creation failed: %ld\n", PTR_ERR(pdev)); else dev_dbg(&adev->dev, "created platform device %s\n", dev_name(&pdev->dev)); kfree(resources); return pdev; }