Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
7fc90e8
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
comedi
connector
counter
cpufreq
cpuidle
crypto
cxl
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
arm_ffa
arm_scmi
broadcom
cirrus
efi
libstub
test
Kconfig
Makefile
apple-properties.c
arm-runtime.c
capsule-loader.c
capsule.c
cper-arm.c
cper-x86.c
cper.c
dev-path-parser.c
earlycon.c
efi-bgrt.c
efi-init.c
efi-pstore.c
efi.c
efibc.c
embedded-firmware.c
esrt.c
fake_mem.c
fake_mem.h
fdtparams.c
memattr.c
memmap.c
mokvar-table.c
rci2-table.c
reboot.c
riscv-runtime.c
runtime-map.c
runtime-wrappers.c
sysfb_efi.c
tpm.c
vars.c
x86_fake_mem.c
google
imx
meson
psci
smccc
tegra
xilinx
Kconfig
Makefile
arm_scpi.c
arm_sdei.c
dmi-id.c
dmi-sysfs.c
dmi_scan.c
edd.c
iscsi_ibft.c
iscsi_ibft_find.c
memmap.c
mtk-adsp-ipc.c
pcdp.c
pcdp.h
qcom_scm-legacy.c
qcom_scm-smc.c
qcom_scm.c
qcom_scm.h
qemu_fw_cfg.c
raspberrypi.c
scpi_pm_domain.c
stratix10-rsu.c
stratix10-svc.c
sysfb.c
sysfb_simplefb.c
ti_sci.c
ti_sci.h
trusted_foundations.c
turris-mox-rwtm.c
fpga
fsi
gnss
gpio
gpu
greybus
hid
hsi
hte
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
most
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
parisc
parport
pci
pcmcia
peci
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
ufs
uio
usb
vdpa
vfio
vhost
video
virt
virtio
vlynq
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
io_uring
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
firmware
/
efi
/
dev-path-parser.c
Blame
Blame
Latest commit
History
History
184 lines (160 loc) · 5.31 KB
Breadcrumbs
linux
/
drivers
/
firmware
/
efi
/
dev-path-parser.c
Top
File metadata and controls
Code
Blame
184 lines (160 loc) · 5.31 KB
Raw
// SPDX-License-Identifier: GPL-2.0 /* * dev-path-parser.c - EFI Device Path parser * Copyright (C) 2016 Lukas Wunner <lukas@wunner.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License (version 2) as * published by the Free Software Foundation. */ #include <linux/acpi.h> #include <linux/efi.h> #include <linux/pci.h> static long __init parse_acpi_path(const struct efi_dev_path *node, struct device *parent, struct device **child) { struct acpi_device *adev; struct device *phys_dev; char hid[ACPI_ID_LEN]; u64 uid; int ret; if (node->header.length != 12) return -EINVAL; sprintf(hid, "%c%c%c%04X", 'A' + ((node->acpi.hid >> 10) & 0x1f) - 1, 'A' + ((node->acpi.hid >> 5) & 0x1f) - 1, 'A' + ((node->acpi.hid >> 0) & 0x1f) - 1, node->acpi.hid >> 16); for_each_acpi_dev_match(adev, hid, NULL, -1) { ret = acpi_dev_uid_to_integer(adev, &uid); if (ret == 0 && node->acpi.uid == uid) break; if (ret == -ENODATA && node->acpi.uid == 0) break; } if (!adev) return -ENODEV; phys_dev = acpi_get_first_physical_node(adev); if (phys_dev) { *child = get_device(phys_dev); acpi_dev_put(adev); } else *child = &adev->dev; return 0; } static int __init match_pci_dev(struct device *dev, void *data) { unsigned int devfn = *(unsigned int *)data; return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn; } static long __init parse_pci_path(const struct efi_dev_path *node, struct device *parent, struct device **child) { unsigned int devfn; if (node->header.length != 6) return -EINVAL; if (!parent) return -EINVAL; devfn = PCI_DEVFN(node->pci.dev, node->pci.fn); *child = device_find_child(parent, &devfn, match_pci_dev); if (!*child) return -ENODEV; return 0; } /* * Insert parsers for further node types here. * * Each parser takes a pointer to the @node and to the @parent (will be NULL * for the first device path node). If a device corresponding to @node was * found below @parent, its reference count should be incremented and the * device returned in @child. * * The return value should be 0 on success or a negative int on failure. * The special return values 0x01 (EFI_DEV_END_INSTANCE) and 0xFF * (EFI_DEV_END_ENTIRE) signal the end of the device path, only * parse_end_path() is supposed to return this. * * Be sure to validate the node length and contents before commencing the * search for a device. */ static long __init parse_end_path(const struct efi_dev_path *node, struct device *parent, struct device **child) { if (node->header.length != 4) return -EINVAL; if (node->header.sub_type != EFI_DEV_END_INSTANCE && node->header.sub_type != EFI_DEV_END_ENTIRE) return -EINVAL; if (!parent) return -ENODEV; *child = get_device(parent); return node->header.sub_type; } /** * efi_get_device_by_path - find device by EFI Device Path * @node: EFI Device Path * @len: maximum length of EFI Device Path in bytes * * Parse a series of EFI Device Path nodes at @node and find the corresponding * device. If the device was found, its reference count is incremented and a * pointer to it is returned. The caller needs to drop the reference with * put_device() after use. The @node pointer is updated to point to the * location immediately after the "End of Hardware Device Path" node. * * If another Device Path instance follows, @len is decremented by the number * of bytes consumed. Otherwise @len is set to %0. * * If a Device Path node is malformed or its corresponding device is not found, * @node is updated to point to this offending node and an ERR_PTR is returned. * * If @len is initially %0, the function returns %NULL. Thus, to iterate over * all instances in a path, the following idiom may be used: * * while (!IS_ERR_OR_NULL(dev = efi_get_device_by_path(&node, &len))) { * // do something with dev * put_device(dev); * } * if (IS_ERR(dev)) * // report error * * Devices can only be found if they're already instantiated. Most buses * instantiate devices in the "subsys" initcall level, hence the earliest * initcall level in which this function should be called is "fs". * * Returns the device on success or * %ERR_PTR(-ENODEV) if no device was found, * %ERR_PTR(-EINVAL) if a node is malformed or exceeds @len, * %ERR_PTR(-ENOTSUPP) if support for a node type is not yet implemented. */ struct device * __init efi_get_device_by_path(const struct efi_dev_path **node, size_t *len) { struct device *parent = NULL, *child; long ret = 0; if (!*len) return NULL; while (!ret) { if (*len < 4 || *len < (*node)->header.length) ret = -EINVAL; else if ((*node)->header.type == EFI_DEV_ACPI && (*node)->header.sub_type == EFI_DEV_BASIC_ACPI) ret = parse_acpi_path(*node, parent, &child); else if ((*node)->header.type == EFI_DEV_HW && (*node)->header.sub_type == EFI_DEV_PCI) ret = parse_pci_path(*node, parent, &child); else if (((*node)->header.type == EFI_DEV_END_PATH || (*node)->header.type == EFI_DEV_END_PATH2)) ret = parse_end_path(*node, parent, &child); else ret = -ENOTSUPP; put_device(parent); if (ret < 0) return ERR_PTR(ret); parent = child; *node = (void *)*node + (*node)->header.length; *len -= (*node)->header.length; } if (ret == EFI_DEV_END_ENTIRE) *len = 0; return child; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
You can’t perform that action at this time.