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
24 if (node->header.length != 12) in parse_acpi_path()
25 return -EINVAL; in parse_acpi_path()
28 'A' + ((node->acpi.hid >> 10) & 0x1f) - 1, in parse_acpi_path()
29 'A' + ((node->acpi.hid >> 5) & 0x1f) - 1, in parse_acpi_path()
30 'A' + ((node->acpi.hid >> 0) & 0x1f) - 1, in parse_acpi_path()
31 node->acpi.hid >> 16); in parse_acpi_path()
33 for_each_acpi_dev_match(adev, hid, NULL, -1) { in parse_acpi_path()
35 if (ret == 0 && node->acpi.uid == uid) in parse_acpi_path()
37 if (ret == -ENODATA && node->acpi.uid == 0) in parse_acpi_path()
41 return -ENODEV; in parse_acpi_path()
45 *child = get_device(phys_dev); in parse_acpi_path()
48 *child = &adev->dev; in parse_acpi_path()
57 return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn; in match_pci_dev()
60 static long __init parse_pci_path(const struct efi_dev_path *node, in parse_pci_path() argument
61 struct device *parent, struct device **child) in parse_pci_path() argument
65 if (node->header.length != 6) in parse_pci_path()
66 return -EINVAL; in parse_pci_path()
68 return -EINVAL; in parse_pci_path()
70 devfn = PCI_DEVFN(node->pci.dev, node->pci.fn); in parse_pci_path()
72 *child = device_find_child(parent, &devfn, match_pci_dev); in parse_pci_path()
73 if (!*child) in parse_pci_path()
74 return -ENODEV; in parse_pci_path()
80 * Insert parsers for further node types here.
82 * Each parser takes a pointer to the @node and to the @parent (will be NULL
83 * for the first device path node). If a device corresponding to @node was
85 * device returned in @child.
92 * Be sure to validate the node length and contents before commencing the
96 static long __init parse_end_path(const struct efi_dev_path *node, in parse_end_path() argument
97 struct device *parent, struct device **child) in parse_end_path() argument
99 if (node->header.length != 4) in parse_end_path()
100 return -EINVAL; in parse_end_path()
101 if (node->header.sub_type != EFI_DEV_END_INSTANCE && in parse_end_path()
102 node->header.sub_type != EFI_DEV_END_ENTIRE) in parse_end_path()
103 return -EINVAL; in parse_end_path()
105 return -ENODEV; in parse_end_path()
107 *child = get_device(parent); in parse_end_path()
108 return node->header.sub_type; in parse_end_path()
112 * efi_get_device_by_path - find device by EFI Device Path
113 * @node: EFI Device Path
116 * Parse a series of EFI Device Path nodes at @node and find the corresponding
119 * put_device() after use. The @node pointer is updated to point to the
120 * location immediately after the "End of Hardware Device Path" node.
125 * If a Device Path node is malformed or its corresponding device is not found,
126 * @node is updated to point to this offending node and an ERR_PTR is returned.
131 * while (!IS_ERR_OR_NULL(dev = efi_get_device_by_path(&node, &len))) {
143 * %ERR_PTR(-ENODEV) if no device was found,
144 * %ERR_PTR(-EINVAL) if a node is malformed or exceeds @len,
145 * %ERR_PTR(-ENOTSUPP) if support for a node type is not yet implemented.
147 struct device * __init efi_get_device_by_path(const struct efi_dev_path **node, in efi_get_device_by_path() argument
150 struct device *parent = NULL, *child; in efi_get_device_by_path() local
157 if (*len < 4 || *len < (*node)->header.length) in efi_get_device_by_path()
158 ret = -EINVAL; in efi_get_device_by_path()
159 else if ((*node)->header.type == EFI_DEV_ACPI && in efi_get_device_by_path()
160 (*node)->header.sub_type == EFI_DEV_BASIC_ACPI) in efi_get_device_by_path()
161 ret = parse_acpi_path(*node, parent, &child); in efi_get_device_by_path()
162 else if ((*node)->header.type == EFI_DEV_HW && in efi_get_device_by_path()
163 (*node)->header.sub_type == EFI_DEV_PCI) in efi_get_device_by_path()
164 ret = parse_pci_path(*node, parent, &child); in efi_get_device_by_path()
165 else if (((*node)->header.type == EFI_DEV_END_PATH || in efi_get_device_by_path()
166 (*node)->header.type == EFI_DEV_END_PATH2)) in efi_get_device_by_path()
167 ret = parse_end_path(*node, parent, &child); in efi_get_device_by_path()
169 ret = -ENOTSUPP; in efi_get_device_by_path()
175 parent = child; in efi_get_device_by_path()
176 *node = (void *)*node + (*node)->header.length; in efi_get_device_by_path()
177 *len -= (*node)->header.length; in efi_get_device_by_path()
183 return child; in efi_get_device_by_path()