Lines Matching +full:parent +full:- +full:child
1 // SPDX-License-Identifier: GPL-2.0
3 * dev-path-parser.c - EFI Device Path parser
28 if (adev->pnp.unique_id) in match_acpi_dev()
29 return !strcmp(adev->pnp.unique_id, hid_uid.uid); in match_acpi_dev()
35 struct device *parent, struct device **child) in parse_acpi_path() argument
40 if (node->header.length != 12) in parse_acpi_path()
41 return -EINVAL; in parse_acpi_path()
44 'A' + ((node->acpi.hid >> 10) & 0x1f) - 1, in parse_acpi_path()
45 'A' + ((node->acpi.hid >> 5) & 0x1f) - 1, in parse_acpi_path()
46 'A' + ((node->acpi.hid >> 0) & 0x1f) - 1, in parse_acpi_path()
47 node->acpi.hid >> 16); in parse_acpi_path()
48 sprintf(hid_uid.uid, "%u", node->acpi.uid); in parse_acpi_path()
50 *child = bus_find_device(&acpi_bus_type, NULL, &hid_uid, in parse_acpi_path()
52 if (!*child) in parse_acpi_path()
53 return -ENODEV; in parse_acpi_path()
55 phys_dev = acpi_get_first_physical_node(to_acpi_device(*child)); in parse_acpi_path()
58 put_device(*child); in parse_acpi_path()
59 *child = phys_dev; in parse_acpi_path()
69 return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn; in match_pci_dev()
73 struct device *parent, struct device **child) in parse_pci_path() argument
77 if (node->header.length != 6) in parse_pci_path()
78 return -EINVAL; in parse_pci_path()
79 if (!parent) in parse_pci_path()
80 return -EINVAL; in parse_pci_path()
82 devfn = PCI_DEVFN(node->pci.dev, node->pci.fn); in parse_pci_path()
84 *child = device_find_child(parent, &devfn, match_pci_dev); in parse_pci_path()
85 if (!*child) in parse_pci_path()
86 return -ENODEV; in parse_pci_path()
94 * Each parser takes a pointer to the @node and to the @parent (will be NULL
96 * found below @parent, its reference count should be incremented and the
97 * device returned in @child.
109 struct device *parent, struct device **child) in parse_end_path() argument
111 if (node->header.length != 4) in parse_end_path()
112 return -EINVAL; in parse_end_path()
113 if (node->header.sub_type != EFI_DEV_END_INSTANCE && in parse_end_path()
114 node->header.sub_type != EFI_DEV_END_ENTIRE) in parse_end_path()
115 return -EINVAL; in parse_end_path()
116 if (!parent) in parse_end_path()
117 return -ENODEV; in parse_end_path()
119 *child = get_device(parent); in parse_end_path()
120 return node->header.sub_type; in parse_end_path()
124 * efi_get_device_by_path - find device by EFI Device Path
155 * %ERR_PTR(-ENODEV) if no device was found,
156 * %ERR_PTR(-EINVAL) if a node is malformed or exceeds @len,
157 * %ERR_PTR(-ENOTSUPP) if support for a node type is not yet implemented.
162 struct device *parent = NULL, *child; in efi_get_device_by_path() local
169 if (*len < 4 || *len < (*node)->header.length) in efi_get_device_by_path()
170 ret = -EINVAL; in efi_get_device_by_path()
171 else if ((*node)->header.type == EFI_DEV_ACPI && in efi_get_device_by_path()
172 (*node)->header.sub_type == EFI_DEV_BASIC_ACPI) in efi_get_device_by_path()
173 ret = parse_acpi_path(*node, parent, &child); in efi_get_device_by_path()
174 else if ((*node)->header.type == EFI_DEV_HW && in efi_get_device_by_path()
175 (*node)->header.sub_type == EFI_DEV_PCI) in efi_get_device_by_path()
176 ret = parse_pci_path(*node, parent, &child); in efi_get_device_by_path()
177 else if (((*node)->header.type == EFI_DEV_END_PATH || in efi_get_device_by_path()
178 (*node)->header.type == EFI_DEV_END_PATH2)) in efi_get_device_by_path()
179 ret = parse_end_path(*node, parent, &child); in efi_get_device_by_path()
181 ret = -ENOTSUPP; in efi_get_device_by_path()
183 put_device(parent); in efi_get_device_by_path()
187 parent = child; in efi_get_device_by_path()
188 *node = (void *)*node + (*node)->header.length; in efi_get_device_by_path()
189 *len -= (*node)->header.length; in efi_get_device_by_path()
195 return child; in efi_get_device_by_path()