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()
31 for_each_acpi_dev_match(adev, hid, NULL, -1) { in parse_acpi_path()
32 if (acpi_dev_uid_match(adev, node->acpi.uid)) in parse_acpi_path()
34 if (!acpi_device_uid(adev) && node->acpi.uid == 0) in parse_acpi_path()
38 return -ENODEV; in parse_acpi_path()
42 *child = get_device(phys_dev); in parse_acpi_path()
45 *child = &adev->dev; in parse_acpi_path()
54 return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn; in match_pci_dev()
57 static long __init parse_pci_path(const struct efi_dev_path *node, in parse_pci_path() argument
58 struct device *parent, struct device **child) in parse_pci_path() argument
62 if (node->header.length != 6) in parse_pci_path()
63 return -EINVAL; in parse_pci_path()
65 return -EINVAL; in parse_pci_path()
67 devfn = PCI_DEVFN(node->pci.dev, node->pci.fn); in parse_pci_path()
69 *child = device_find_child(parent, &devfn, match_pci_dev); in parse_pci_path()
70 if (!*child) in parse_pci_path()
71 return -ENODEV; in parse_pci_path()
77 * Insert parsers for further node types here.
79 * Each parser takes a pointer to the @node and to the @parent (will be NULL
80 * for the first device path node). If a device corresponding to @node was
82 * device returned in @child.
89 * Be sure to validate the node length and contents before commencing the
93 static long __init parse_end_path(const struct efi_dev_path *node, in parse_end_path() argument
94 struct device *parent, struct device **child) in parse_end_path() argument
96 if (node->header.length != 4) in parse_end_path()
97 return -EINVAL; in parse_end_path()
98 if (node->header.sub_type != EFI_DEV_END_INSTANCE && in parse_end_path()
99 node->header.sub_type != EFI_DEV_END_ENTIRE) in parse_end_path()
100 return -EINVAL; in parse_end_path()
102 return -ENODEV; in parse_end_path()
104 *child = get_device(parent); in parse_end_path()
105 return node->header.sub_type; in parse_end_path()
109 * efi_get_device_by_path - find device by EFI Device Path
110 * @node: EFI Device Path
113 * Parse a series of EFI Device Path nodes at @node and find the corresponding
116 * put_device() after use. The @node pointer is updated to point to the
117 * location immediately after the "End of Hardware Device Path" node.
122 * If a Device Path node is malformed or its corresponding device is not found,
123 * @node is updated to point to this offending node and an ERR_PTR is returned.
128 * while (!IS_ERR_OR_NULL(dev = efi_get_device_by_path(&node, &len))) {
140 * %ERR_PTR(-ENODEV) if no device was found,
141 * %ERR_PTR(-EINVAL) if a node is malformed or exceeds @len,
142 * %ERR_PTR(-ENOTSUPP) if support for a node type is not yet implemented.
144 struct device * __init efi_get_device_by_path(const struct efi_dev_path **node, in efi_get_device_by_path() argument
147 struct device *parent = NULL, *child; in efi_get_device_by_path() local
154 if (*len < 4 || *len < (*node)->header.length) in efi_get_device_by_path()
155 ret = -EINVAL; in efi_get_device_by_path()
156 else if ((*node)->header.type == EFI_DEV_ACPI && in efi_get_device_by_path()
157 (*node)->header.sub_type == EFI_DEV_BASIC_ACPI) in efi_get_device_by_path()
158 ret = parse_acpi_path(*node, parent, &child); in efi_get_device_by_path()
159 else if ((*node)->header.type == EFI_DEV_HW && in efi_get_device_by_path()
160 (*node)->header.sub_type == EFI_DEV_PCI) in efi_get_device_by_path()
161 ret = parse_pci_path(*node, parent, &child); in efi_get_device_by_path()
162 else if (((*node)->header.type == EFI_DEV_END_PATH || in efi_get_device_by_path()
163 (*node)->header.type == EFI_DEV_END_PATH2)) in efi_get_device_by_path()
164 ret = parse_end_path(*node, parent, &child); in efi_get_device_by_path()
166 ret = -ENOTSUPP; in efi_get_device_by_path()
172 parent = child; in efi_get_device_by_path()
173 *node = (void *)*node + (*node)->header.length; in efi_get_device_by_path()
174 *len -= (*node)->header.length; in efi_get_device_by_path()
180 return child; in efi_get_device_by_path()