Lines Matching +full:child +full:- +full:node
1 // SPDX-License-Identifier: GPL-2.0
3 * dev-path-parser.c - EFI Device Path parser
15 static long __init parse_acpi_path(const struct efi_dev_path *node, in parse_acpi_path() argument
16 struct device *parent, struct device **child) in parse_acpi_path() argument
22 if (node->header.length != 12) in parse_acpi_path()
23 return -EINVAL; in parse_acpi_path()
26 'A' + ((node->acpi.hid >> 10) & 0x1f) - 1, in parse_acpi_path()
27 'A' + ((node->acpi.hid >> 5) & 0x1f) - 1, in parse_acpi_path()
28 'A' + ((node->acpi.hid >> 0) & 0x1f) - 1, in parse_acpi_path()
29 node->acpi.hid >> 16); in parse_acpi_path()
30 sprintf(uid, "%u", node->acpi.uid); in parse_acpi_path()
32 for_each_acpi_dev_match(adev, hid, NULL, -1) { in parse_acpi_path()
33 if (adev->pnp.unique_id && !strcmp(adev->pnp.unique_id, uid)) in parse_acpi_path()
35 if (!adev->pnp.unique_id && node->acpi.uid == 0) in parse_acpi_path()
39 return -ENODEV; in parse_acpi_path()
43 *child = get_device(phys_dev); in parse_acpi_path()
46 *child = &adev->dev; in parse_acpi_path()
55 return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn; in match_pci_dev()
58 static long __init parse_pci_path(const struct efi_dev_path *node, in parse_pci_path() argument
59 struct device *parent, struct device **child) in parse_pci_path() argument
63 if (node->header.length != 6) in parse_pci_path()
64 return -EINVAL; in parse_pci_path()
66 return -EINVAL; in parse_pci_path()
68 devfn = PCI_DEVFN(node->pci.dev, node->pci.fn); in parse_pci_path()
70 *child = device_find_child(parent, &devfn, match_pci_dev); in parse_pci_path()
71 if (!*child) in parse_pci_path()
72 return -ENODEV; in parse_pci_path()
78 * Insert parsers for further node types here.
80 * Each parser takes a pointer to the @node and to the @parent (will be NULL
81 * for the first device path node). If a device corresponding to @node was
83 * device returned in @child.
90 * Be sure to validate the node length and contents before commencing the
94 static long __init parse_end_path(const struct efi_dev_path *node, in parse_end_path() argument
95 struct device *parent, struct device **child) in parse_end_path() argument
97 if (node->header.length != 4) in parse_end_path()
98 return -EINVAL; in parse_end_path()
99 if (node->header.sub_type != EFI_DEV_END_INSTANCE && in parse_end_path()
100 node->header.sub_type != EFI_DEV_END_ENTIRE) in parse_end_path()
101 return -EINVAL; in parse_end_path()
103 return -ENODEV; in parse_end_path()
105 *child = get_device(parent); in parse_end_path()
106 return node->header.sub_type; in parse_end_path()
110 * efi_get_device_by_path - find device by EFI Device Path
111 * @node: EFI Device Path
114 * Parse a series of EFI Device Path nodes at @node and find the corresponding
117 * put_device() after use. The @node pointer is updated to point to the
118 * location immediately after the "End of Hardware Device Path" node.
123 * If a Device Path node is malformed or its corresponding device is not found,
124 * @node is updated to point to this offending node and an ERR_PTR is returned.
129 * while (!IS_ERR_OR_NULL(dev = efi_get_device_by_path(&node, &len))) {
141 * %ERR_PTR(-ENODEV) if no device was found,
142 * %ERR_PTR(-EINVAL) if a node is malformed or exceeds @len,
143 * %ERR_PTR(-ENOTSUPP) if support for a node type is not yet implemented.
145 struct device * __init efi_get_device_by_path(const struct efi_dev_path **node, in efi_get_device_by_path() argument
148 struct device *parent = NULL, *child; in efi_get_device_by_path() local
155 if (*len < 4 || *len < (*node)->header.length) in efi_get_device_by_path()
156 ret = -EINVAL; in efi_get_device_by_path()
157 else if ((*node)->header.type == EFI_DEV_ACPI && in efi_get_device_by_path()
158 (*node)->header.sub_type == EFI_DEV_BASIC_ACPI) in efi_get_device_by_path()
159 ret = parse_acpi_path(*node, parent, &child); in efi_get_device_by_path()
160 else if ((*node)->header.type == EFI_DEV_HW && in efi_get_device_by_path()
161 (*node)->header.sub_type == EFI_DEV_PCI) in efi_get_device_by_path()
162 ret = parse_pci_path(*node, parent, &child); in efi_get_device_by_path()
163 else if (((*node)->header.type == EFI_DEV_END_PATH || in efi_get_device_by_path()
164 (*node)->header.type == EFI_DEV_END_PATH2)) in efi_get_device_by_path()
165 ret = parse_end_path(*node, parent, &child); in efi_get_device_by_path()
167 ret = -ENOTSUPP; in efi_get_device_by_path()
173 parent = child; in efi_get_device_by_path()
174 *node = (void *)*node + (*node)->header.length; in efi_get_device_by_path()
175 *len -= (*node)->header.length; in efi_get_device_by_path()
181 return child; in efi_get_device_by_path()