mirror of
https://github.com/torvalds/linux.git
synced 2026-06-07 14:04:54 +02:00
-----BEGIN PGP SIGNATURE-----
iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmHya+IACgkQONu9yGCS
aT7k/RAAqdd8bNhAiO6iDpvZbQtxq9jepx4KCkcd+gsYvSvePEnBQHaTaavfCK/7
+taWsc2i6Hwc1Z4oVfUiU02cCsqMJJXqb0nfJaavE5cZspbTc7QeS0zv9BkzSKUZ
+DxXWyjzeJquI7EbdU0n7inb0iwvBxmTGNIg2j1pPi81Q7XnpjmDsSvuoftRQ0AN
DGYefowWL1VcfsZRfhEudnpxWC/DjOdB8zD34SgXxKat6/O8YG4T5pM2BOUlKtOW
QcXFhpG6gU0XqmI3QQDvAESujOQxzC1u3AwIOHYJ/tlFYsUJXjiZIEVnMqPYGpNl
fXS8xcNSeo6fipXWkzsc489Tteq9H+bfm8sBG0jhExRnyGckkihJDhRFZ9yBrzo/
1PtUdUIJ4d5fUmdZp7gxucncFyIYFsyJm/5nsYmObP794oStPGKsH8llhp/PcEFF
ua1+Gy2WW2f6BOaDVFmt+jWZRMa/3oZnFhe8/FPRsAjGOj+q/+V6bsksGDYupsrM
x8/QQI6OVlnOZsrdpX7zkW46qLov0J0bO9cANTm7kcRaesrkikFKqiIF2uIW2OU6
W0tZZf0Jy/gSLEljkZ3SuMHCmldWKm/KxMYSjnQ3Y34QvOLYPNAZGF78rbV3s8/0
otGR3ra5TKCz1kxuDaE1FqZXxpPQidXbF4QUoaRIaPwA1k5NvLY=
=ktJL
-----END PGP SIGNATURE-----
Merge 5.10.94 into android12-5.10-lts
Changes in 5.10.94
KVM: VMX: switch blocked_vcpu_on_cpu_lock to raw spinlock
HID: uhid: Fix worker destroying device without any protection
HID: wacom: Reset expected and received contact counts at the same time
HID: wacom: Ignore the confidence flag when a touch is removed
HID: wacom: Avoid using stale array indicies to read contact count
f2fs: fix to do sanity check in is_alive()
nfc: llcp: fix NULL error pointer dereference on sendmsg() after failed bind()
mtd: rawnand: gpmi: Add ERR007117 protection for nfc_apply_timings
mtd: rawnand: gpmi: Remove explicit default gpmi clock setting for i.MX6
mtd: Fixed breaking list in __mtd_del_partition.
mtd: rawnand: davinci: Don't calculate ECC when reading page
mtd: rawnand: davinci: Avoid duplicated page read
mtd: rawnand: davinci: Rewrite function description
x86/gpu: Reserve stolen memory for first integrated Intel GPU
tools/nolibc: x86-64: Fix startup code bug
tools/nolibc: i386: fix initial stack alignment
tools/nolibc: fix incorrect truncation of exit code
rtc: cmos: take rtc_lock while reading from CMOS
media: v4l2-ioctl.c: readbuffers depends on V4L2_CAP_READWRITE
media: flexcop-usb: fix control-message timeouts
media: mceusb: fix control-message timeouts
media: em28xx: fix control-message timeouts
media: cpia2: fix control-message timeouts
media: s2255: fix control-message timeouts
media: dib0700: fix undefined behavior in tuner shutdown
media: redrat3: fix control-message timeouts
media: pvrusb2: fix control-message timeouts
media: stk1160: fix control-message timeouts
media: cec-pin: fix interrupt en/disable handling
can: softing_cs: softingcs_probe(): fix memleak on registration failure
iio: adc: ti-adc081c: Partial revert of removal of ACPI IDs
lkdtm: Fix content of section containing lkdtm_rodata_do_nothing()
iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure
gpu: host1x: Add back arm_iommu_detach_device()
dma_fence_array: Fix PENDING_ERROR leak in dma_fence_array_signaled()
PCI: Add function 1 DMA alias quirk for Marvell 88SE9125 SATA controller
mm_zone: add function to check if managed dma zone exists
dma/pool: create dma atomic pool only if dma zone has managed pages
mm/page_alloc.c: do not warn allocation failure on zone DMA if no managed pages
shmem: fix a race between shmem_unused_huge_shrink and shmem_evict_inode
drm/ttm: Put BO in its memory manager's lru list
Bluetooth: L2CAP: Fix not initializing sk_peer_pid
drm/bridge: display-connector: fix an uninitialized pointer in probe()
drm: fix null-ptr-deref in drm_dev_init_release()
drm/panel: kingdisplay-kd097d04: Delete panel on attach() failure
drm/panel: innolux-p079zca: Delete panel on attach() failure
drm/rockchip: dsi: Fix unbalanced clock on probe error
drm/rockchip: dsi: Hold pm-runtime across bind/unbind
drm/rockchip: dsi: Disable PLL clock on bind error
drm/rockchip: dsi: Reconfigure hardware on resume()
Bluetooth: cmtp: fix possible panic when cmtp_init_sockets() fails
clk: bcm-2835: Pick the closest clock rate
clk: bcm-2835: Remove rounding up the dividers
drm/vc4: hdmi: Set a default HSM rate
wcn36xx: ensure pairing of init_scan/finish_scan and start_scan/end_scan
wcn36xx: Indicate beacon not connection loss on MISSED_BEACON_IND
wcn36xx: Fix DMA channel enable/disable cycle
wcn36xx: Release DMA channel descriptor allocations
wcn36xx: Put DXE block into reset before freeing memory
wcn36xx: populate band before determining rate on RX
wcn36xx: fix RX BD rate mapping for 5GHz legacy rates
ath11k: Send PPDU_STATS_CFG with proper pdev mask to firmware
mtd: hyperbus: rpc-if: Check return value of rpcif_sw_init()
media: videobuf2: Fix the size printk format
media: atomisp: add missing media_device_cleanup() in atomisp_unregister_entities()
media: atomisp: fix punit_ddr_dvfs_enable() argument for mrfld_power up case
media: atomisp: fix inverted logic in buffers_needed()
media: atomisp: do not use err var when checking port validity for ISP2400
media: atomisp: fix inverted error check for ia_css_mipi_is_source_port_valid()
media: atomisp: fix ifdefs in sh_css.c
media: staging: media: atomisp: pci: Balance braces around conditional statements in file atomisp_cmd.c
media: atomisp: add NULL check for asd obtained from atomisp_video_pipe
media: atomisp: fix enum formats logic
media: atomisp: fix uninitialized bug in gmin_get_pmic_id_and_addr()
media: aspeed: fix mode-detect always time out at 2nd run
media: em28xx: fix memory leak in em28xx_init_dev
media: aspeed: Update signal status immediately to ensure sane hw state
arm64: dts: amlogic: meson-g12: Fix GPU operating point table node name
arm64: dts: amlogic: Fix SPI NOR flash node name for ODROID N2/N2+
arm64: dts: meson-gxbb-wetek: fix HDMI in early boot
arm64: dts: meson-gxbb-wetek: fix missing GPIO binding
fs: dlm: use sk->sk_socket instead of con->sock
fs: dlm: don't call kernel_getpeername() in error_report()
memory: renesas-rpc-if: Return error in case devm_ioremap_resource() fails
Bluetooth: stop proccessing malicious adv data
ath11k: Fix ETSI regd with weather radar overlap
ath11k: clear the keys properly via DISABLE_KEY
ath11k: reset RSN/WPA present state for open BSS
tee: fix put order in teedev_close_context()
fs: dlm: fix build with CONFIG_IPV6 disabled
drm/vboxvideo: fix a NULL vs IS_ERR() check
arm64: dts: renesas: cat875: Add rx/tx delays
media: dmxdev: fix UAF when dvb_register_device() fails
crypto: qce - fix uaf on qce_ahash_register_one
crypto: qce - fix uaf on qce_skcipher_register_one
mtd: hyperbus: rpc-if: fix bug in rpcif_hb_remove
ARM: dts: stm32: fix dtbs_check warning on ili9341 dts binding on stm32f429 disco
crypto: qat - fix spelling mistake: "messge" -> "message"
crypto: qat - remove unnecessary collision prevention step in PFVF
crypto: qat - make pfvf send message direction agnostic
crypto: qat - fix undetected PFVF timeout in ACK loop
ath11k: Use host CE parameters for CE interrupts configuration
arm64: dts: ti: k3-j721e: correct cache-sets info
tty: serial: atmel: Check return code of dmaengine_submit()
tty: serial: atmel: Call dma_async_issue_pending()
mfd: atmel-flexcom: Remove #ifdef CONFIG_PM_SLEEP
mfd: atmel-flexcom: Use .resume_noirq
media: rcar-csi2: Correct the selection of hsfreqrange
media: imx-pxp: Initialize the spinlock prior to using it
media: si470x-i2c: fix possible memory leak in si470x_i2c_probe()
media: mtk-vcodec: call v4l2_m2m_ctx_release first when file is released
media: coda: fix CODA960 JPEG encoder buffer overflow
media: venus: pm_helpers: Control core power domain manually
media: venus: core, venc, vdec: Fix probe dependency error
media: venus: core: Fix a potential NULL pointer dereference in an error handling path
media: venus: core: Fix a resource leak in the error handling path of 'venus_probe()'
thermal/drivers/imx: Implement runtime PM support
netfilter: bridge: add support for pppoe filtering
arm64: dts: qcom: msm8916: fix MMC controller aliases
cgroup: Trace event cgroup id fields should be u64
ACPI: EC: Rework flushing of EC work while suspended to idle
thermal/drivers/imx8mm: Enable ADC when enabling monitor
drm/amdgpu: Fix a NULL pointer dereference in amdgpu_connector_lcd_native_mode()
drm/radeon/radeon_kms: Fix a NULL pointer dereference in radeon_driver_open_kms()
arm64: dts: ti: k3-j7200: Fix the L2 cache sets
arm64: dts: ti: k3-j721e: Fix the L2 cache sets
arm64: dts: ti: k3-j7200: Correct the d-cache-sets info
tty: serial: uartlite: allow 64 bit address
serial: amba-pl011: do not request memory region twice
floppy: Fix hang in watchdog when disk is ejected
staging: rtl8192e: return error code from rtllib_softmac_init()
staging: rtl8192e: rtllib_module: fix error handle case in alloc_rtllib()
Bluetooth: btmtksdio: fix resume failure
sched/fair: Fix detection of per-CPU kthreads waking a task
sched/fair: Fix per-CPU kthread and wakee stacking for asym CPU capacity
bpf: Adjust BTF log size limit.
bpf: Disallow BPF_LOG_KERNEL log level for bpf(BPF_BTF_LOAD)
bpf: Remove config check to enable bpf support for branch records
arm64: lib: Annotate {clear, copy}_page() as position-independent
arm64: clear_page() shouldn't use DC ZVA when DCZID_EL0.DZP == 1
media: dib8000: Fix a memleak in dib8000_init()
media: saa7146: mxb: Fix a NULL pointer dereference in mxb_attach()
media: si2157: Fix "warm" tuner state detection
wireless: iwlwifi: Fix a double free in iwl_txq_dyn_alloc_dma
sched/rt: Try to restart rt period timer when rt runtime exceeded
drm/msm/dp: displayPort driver need algorithm rational
rcu/exp: Mark current CPU as exp-QS in IPI loop second pass
mwifiex: Fix possible ABBA deadlock
xfrm: fix a small bug in xfrm_sa_len()
x86/uaccess: Move variable into switch case statement
selftests: clone3: clone3: add case CLONE3_ARGS_NO_TEST
selftests: harness: avoid false negatives if test has no ASSERTs
crypto: stm32 - Fix last sparse warning in stm32_cryp_check_ctr_counter
crypto: stm32/cryp - fix CTR counter carry
crypto: stm32/cryp - fix xts and race condition in crypto_engine requests
crypto: stm32/cryp - check early input data
crypto: stm32/cryp - fix double pm exit
crypto: stm32/cryp - fix lrw chaining mode
crypto: stm32/cryp - fix bugs and crash in tests
crypto: stm32 - Revert broken pm_runtime_resume_and_get changes
ath11k: Fix deleting uninitialized kernel timer during fragment cache flush
ARM: dts: gemini: NAS4220-B: fis-index-block with 128 KiB sectors
media: dw2102: Fix use after free
media: msi001: fix possible null-ptr-deref in msi001_probe()
media: coda/imx-vdoa: Handle dma_set_coherent_mask error codes
ath11k: Fix a NULL pointer dereference in ath11k_mac_op_hw_scan()
arm64: dts: qcom: c630: Fix soundcard setup
arm64: dts: qcom: ipq6018: Fix gpio-ranges property
drm/msm/dpu: fix safe status debugfs file
drm/bridge: ti-sn65dsi86: Set max register for regmap
drm/tegra: vic: Fix DMA API misuse
media: hantro: Fix probe func error path
xfrm: interface with if_id 0 should return error
xfrm: state and policy should fail if XFRMA_IF_ID 0
ARM: 9159/1: decompressor: Avoid UNPREDICTABLE NOP encoding
usb: ftdi-elan: fix memory leak on device disconnect
arm64: dts: marvell: cn9130: add GPIO and SPI aliases
arm64: dts: marvell: cn9130: enable CP0 GPIO controllers
ARM: dts: armada-38x: Add generic compatible to UART nodes
iwlwifi: mvm: fix 32-bit build in FTM
iwlwifi: mvm: test roc running status bits before removing the sta
mmc: meson-mx-sdhc: add IRQ check
mmc: meson-mx-sdio: add IRQ check
selinux: fix potential memleak in selinux_add_opt()
um: fix ndelay/udelay defines
um: virtio_uml: Fix time-travel external time propagation
Bluetooth: L2CAP: Fix using wrong mode
bpftool: Enable line buffering for stdout
backlight: qcom-wled: Validate enabled string indices in DT
backlight: qcom-wled: Pass number of elements to read to read_u32_array
backlight: qcom-wled: Fix off-by-one maximum with default num_strings
backlight: qcom-wled: Override default length with qcom,enabled-strings
backlight: qcom-wled: Use cpu_to_le16 macro to perform conversion
backlight: qcom-wled: Respect enabled-strings in set_brightness
software node: fix wrong node passed to find nargs_prop
Bluetooth: hci_qca: Stop IBS timer during BT OFF
x86/boot/compressed: Move CLANG_FLAGS to beginning of KBUILD_CFLAGS
hwmon: (mr75203) fix wrong power-up delay value
x86/mce/inject: Avoid out-of-bounds write when setting flags
ACPI: scan: Create platform device for BCM4752 and LNV4752 ACPI nodes
pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region()
pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in nonstatic_find_mem_region()
power: reset: mt6397: Check for null res pointer
netfilter: ipt_CLUSTERIP: fix refcount leak in clusterip_tg_check()
bpf: Don't promote bogus looking registers after null check.
bpf: Fix SO_RCVBUF/SO_SNDBUF handling in _bpf_setsockopt().
netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone
ppp: ensure minimum packet size in ppp_write()
rocker: fix a sleeping in atomic bug
staging: greybus: audio: Check null pointer
fsl/fman: Check for null pointer after calling devm_ioremap
Bluetooth: hci_bcm: Check for error irq
Bluetooth: hci_qca: Fix NULL vs IS_ERR_OR_NULL check in qca_serdev_probe
usb: dwc3: qcom: Fix NULL vs IS_ERR checking in dwc3_qcom_probe
HID: hid-uclogic-params: Invalid parameter check in uclogic_params_init
HID: hid-uclogic-params: Invalid parameter check in uclogic_params_get_str_desc
HID: hid-uclogic-params: Invalid parameter check in uclogic_params_huion_init
HID: hid-uclogic-params: Invalid parameter check in uclogic_params_frame_init_v1_buttonpad
debugfs: lockdown: Allow reading debugfs files that are not world readable
net/mlx5e: Fix page DMA map/unmap attributes
net/mlx5e: Don't block routes with nexthop objects in SW
Revert "net/mlx5e: Block offload of outer header csum for UDP tunnels"
net/mlx5: Set command entry semaphore up once got index free
lib/mpi: Add the return value check of kcalloc()
Bluetooth: L2CAP: uninitialized variables in l2cap_sock_setsockopt()
spi: spi-meson-spifc: Add missing pm_runtime_disable() in meson_spifc_probe
ax25: uninitialized variable in ax25_setsockopt()
netrom: fix api breakage in nr_setsockopt()
regmap: Call regmap_debugfs_exit() prior to _init()
can: mcp251xfd: add missing newline to printed strings
tpm: add request_locality before write TPM_INT_ENABLE
tpm_tis: Fix an error handling path in 'tpm_tis_core_init()'
can: softing: softing_startstop(): fix set but not used variable warning
can: xilinx_can: xcan_probe(): check for error irq
pcmcia: fix setting of kthread task states
iwlwifi: mvm: Use div_s64 instead of do_div in iwl_mvm_ftm_rtt_smoothing()
net: mcs7830: handle usb read errors properly
ext4: avoid trim error on fs with small groups
ALSA: jack: Add missing rwsem around snd_ctl_remove() calls
ALSA: PCM: Add missing rwsem around snd_ctl_remove() calls
ALSA: hda: Add missing rwsem around snd_ctl_remove() calls
RDMA/bnxt_re: Scan the whole bitmap when checking if "disabling RCFW with pending cmd-bit"
RDMA/hns: Validate the pkey index
scsi: pm80xx: Update WARN_ON check in pm8001_mpi_build_cmd()
clk: imx8mn: Fix imx8mn_clko1_sels
powerpc/prom_init: Fix improper check of prom_getprop()
ASoC: uniphier: drop selecting non-existing SND_SOC_UNIPHIER_AIO_DMA
dt-bindings: thermal: Fix definition of cooling-maps contribution property
powerpc/64s: Convert some cpu_setup() and cpu_restore() functions to C
powerpc/perf: MMCR0 control for PMU registers under PMCC=00
powerpc/perf: move perf irq/nmi handling details into traps.c
powerpc/irq: Add helper to set regs->softe
powerpc/perf: Fix PMU callbacks to clear pending PMI before resetting an overflown PMC
powerpc/32s: Fix shift-out-of-bounds in KASAN init
clocksource: Reduce clocksource-skew threshold
clocksource: Avoid accidental unstable marking of clocksources
ALSA: oss: fix compile error when OSS_DEBUG is enabled
ALSA: usb-audio: Drop superfluous '0' in Presonus Studio 1810c's ID
char/mwave: Adjust io port register size
binder: fix handling of error during copy
openrisc: Add clone3 ABI wrapper
iommu/io-pgtable-arm: Fix table descriptor paddr formatting
scsi: ufs: Fix race conditions related to driver data
RDMA/qedr: Fix reporting max_{send/recv}_wr attrs
PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()
powerpc/powermac: Add additional missing lockdep_register_key()
RDMA/core: Let ib_find_gid() continue search even after empty entry
RDMA/cma: Let cma_resolve_ib_dev() continue search even after empty entry
ASoC: rt5663: Handle device_property_read_u32_array error codes
of: unittest: fix warning on PowerPC frame size warning
of: unittest: 64 bit dma address test requires arch support
clk: stm32: Fix ltdc's clock turn off by clk_disable_unused() after system enter shell
mips: add SYS_HAS_CPU_MIPS64_R5 config for MIPS Release 5 support
mips: fix Kconfig reference to PHYS_ADDR_T_64BIT
dmaengine: pxa/mmp: stop referencing config->slave_id
iommu/amd: Remove iommu_init_ga()
iommu/amd: Restore GA log/tail pointer on host resume
ASoC: Intel: catpt: Test dmaengine_submit() result before moving on
iommu/iova: Fix race between FQ timeout and teardown
scsi: block: pm: Always set request queue runtime active in blk_post_runtime_resume()
phy: uniphier-usb3ss: fix unintended writing zeros to PHY register
ASoC: mediatek: Check for error clk pointer
ASoC: samsung: idma: Check of ioremap return value
misc: lattice-ecp3-config: Fix task hung when firmware load failed
counter: stm32-lptimer-cnt: remove iio counter abi
arm64: tegra: Fix Tegra194 HDA {clock,reset}-names ordering
arm64: tegra: Remove non existent Tegra194 reset
mips: lantiq: add support for clk_set_parent()
mips: bcm63xx: add support for clk_set_parent()
powerpc/xive: Add missing null check after calling kmalloc
ASoC: fsl_mqs: fix MODULE_ALIAS
RDMA/cxgb4: Set queue pair state when being queried
ASoC: fsl_asrc: refine the check of available clock divider
clk: bm1880: remove kfrees on static allocations
of: base: Fix phandle argument length mismatch error message
ARM: dts: omap3-n900: Fix lp5523 for multi color
Bluetooth: Fix debugfs entry leak in hci_register_dev()
fs: dlm: filter user dlm messages for kernel locks
drm/lima: fix warning when CONFIG_DEBUG_SG=y & CONFIG_DMA_API_DEBUG=y
selftests/bpf: Fix bpf_object leak in skb_ctx selftest
ar5523: Fix null-ptr-deref with unexpected WDCMSG_TARGET_START reply
drm/bridge: dw-hdmi: handle ELD when DRM_BRIDGE_ATTACH_NO_CONNECTOR
drm/nouveau/pmu/gm200-: avoid touching PMU outside of DEVINIT/PREOS/ACR
media: atomisp: fix try_fmt logic
media: atomisp: set per-device's default mode
media: atomisp-ov2680: Fix ov2680_set_fmt() clobbering the exposure
ARM: shmobile: rcar-gen2: Add missing of_node_put()
batman-adv: allow netlink usage in unprivileged containers
media: atomisp: handle errors at sh_css_create_isp_params()
ath11k: Fix crash caused by uninitialized TX ring
usb: gadget: f_fs: Use stream_open() for endpoint files
drm: panel-orientation-quirks: Add quirk for the Lenovo Yoga Book X91F/L
HID: apple: Do not reset quirks when the Fn key is not found
media: b2c2: Add missing check in flexcop_pci_isr:
EDAC/synopsys: Use the quirk for version instead of ddr version
ARM: imx: rename DEBUG_IMX21_IMX27_UART to DEBUG_IMX27_UART
drm/amd/display: check top_pipe_to_program pointer
drm/amdgpu/display: set vblank_disable_immediate for DC
soc: ti: pruss: fix referenced node in error message
mlxsw: pci: Add shutdown method in PCI driver
drm/bridge: megachips: Ensure both bridges are probed before registration
tty: serial: imx: disable UCR4_OREN in .stop_rx() instead of .shutdown()
gpiolib: acpi: Do not set the IRQ type if the IRQ is already in use
HSI: core: Fix return freed object in hsi_new_client
crypto: jitter - consider 32 LSB for APT
mwifiex: Fix skb_over_panic in mwifiex_usb_recv()
rsi: Fix use-after-free in rsi_rx_done_handler()
rsi: Fix out-of-bounds read in rsi_read_pkt()
ath11k: Avoid NULL ptr access during mgmt tx cleanup
media: venus: avoid calling core_clk_setrate() concurrently during concurrent video sessions
ACPI / x86: Drop PWM2 device on Lenovo Yoga Book from always present table
ACPI: Change acpi_device_always_present() into acpi_device_override_status()
ACPI / x86: Allow specifying acpi_device_override_status() quirks by path
ACPI / x86: Add not-present quirk for the PCI0.SDHB.BRC1 device on the GPD win
arm64: dts: ti: j7200-main: Fix 'dtbs_check' serdes_ln_ctrl node
usb: uhci: add aspeed ast2600 uhci support
floppy: Add max size check for user space request
x86/mm: Flush global TLB when switching to trampoline page-table
drm: rcar-du: Fix CRTC timings when CMM is used
media: uvcvideo: Increase UVC_CTRL_CONTROL_TIMEOUT to 5 seconds.
media: rcar-vin: Update format alignment constraints
media: saa7146: hexium_orion: Fix a NULL pointer dereference in hexium_attach()
media: m920x: don't use stack on USB reads
thunderbolt: Runtime PM activate both ends of the device link
iwlwifi: mvm: synchronize with FW after multicast commands
iwlwifi: mvm: avoid clearing a just saved session protection id
ath11k: avoid deadlock by change ieee80211_queue_work for regd_update_work
ath10k: Fix tx hanging
net-sysfs: update the queue counts in the unregistration path
net: phy: prefer 1000baseT over 1000baseKX
gpio: aspeed: Convert aspeed_gpio.lock to raw_spinlock
selftests/ftrace: make kprobe profile testcase description unique
ath11k: Avoid false DEADLOCK warning reported by lockdep
x86/mce: Allow instrumentation during task work queueing
x86/mce: Mark mce_panic() noinstr
x86/mce: Mark mce_end() noinstr
x86/mce: Mark mce_read_aux() noinstr
net: bonding: debug: avoid printing debug logs when bond is not notifying peers
bpf: Do not WARN in bpf_warn_invalid_xdp_action()
HID: quirks: Allow inverting the absolute X/Y values
media: igorplugusb: receiver overflow should be reported
media: saa7146: hexium_gemini: Fix a NULL pointer dereference in hexium_attach()
mmc: core: Fixup storing of OCR for MMC_QUIRK_NONSTD_SDIO
audit: ensure userspace is penalized the same as the kernel when under pressure
arm64: dts: ls1028a-qds: move rtc node to the correct i2c bus
arm64: tegra: Adjust length of CCPLEX cluster MMIO region
PM: runtime: Add safety net to supplier device release
cpufreq: Fix initialization of min and max frequency QoS requests
usb: hub: Add delay for SuperSpeed hub resume to let links transit to U0
ath9k: Fix out-of-bound memcpy in ath9k_hif_usb_rx_stream
rtw88: 8822c: update rx settings to prevent potential hw deadlock
PM: AVS: qcom-cpr: Use div64_ul instead of do_div
iwlwifi: fix leaks/bad data after failed firmware load
iwlwifi: remove module loading failure message
iwlwifi: mvm: Fix calculation of frame length
iwlwifi: pcie: make sure prph_info is set when treating wakeup IRQ
um: registers: Rename function names to avoid conflicts and build problems
ath11k: Fix napi related hang
Bluetooth: vhci: Set HCI_QUIRK_VALID_LE_STATES
xfrm: rate limit SA mapping change message to user space
drm/etnaviv: consider completed fence seqno in hang check
jffs2: GC deadlock reading a page that is used in jffs2_write_begin()
ACPICA: actypes.h: Expand the ACPI_ACCESS_ definitions
ACPICA: Utilities: Avoid deleting the same object twice in a row
ACPICA: Executer: Fix the REFCLASS_REFOF case in acpi_ex_opcode_1A_0T_1R()
ACPICA: Fix wrong interpretation of PCC address
ACPICA: Hardware: Do not flush CPU cache when entering S4 and S5
drm/amdgpu: fixup bad vram size on gmc v8
amdgpu/pm: Make sysfs pm attributes as read-only for VFs
ACPI: battery: Add the ThinkPad "Not Charging" quirk
btrfs: remove BUG_ON() in find_parent_nodes()
btrfs: remove BUG_ON(!eie) in find_parent_nodes
net: mdio: Demote probed message to debug print
mac80211: allow non-standard VHT MCS-10/11
dm btree: add a defensive bounds check to insert_at()
dm space map common: add bounds check to sm_ll_lookup_bitmap()
mlxsw: pci: Avoid flow control for EMAD packets
net: phy: marvell: configure RGMII delays for 88E1118
net: gemini: allow any RGMII interface mode
regulator: qcom_smd: Align probe function with rpmh-regulator
serial: pl010: Drop CR register reset on set_termios
serial: core: Keep mctrl register state and cached copy in sync
random: do not throw away excess input to crng_fast_load
parisc: Avoid calling faulthandler_disabled() twice
x86/kbuild: Enable CONFIG_KALLSYMS_ALL=y in the defconfigs
powerpc/6xx: add missing of_node_put
powerpc/powernv: add missing of_node_put
powerpc/cell: add missing of_node_put
powerpc/btext: add missing of_node_put
powerpc/watchdog: Fix missed watchdog reset due to memory ordering race
i2c: i801: Don't silently correct invalid transfer size
powerpc/smp: Move setup_profiling_timer() under CONFIG_PROFILING
i2c: mpc: Correct I2C reset procedure
clk: meson: gxbb: Fix the SDM_EN bit for MPLL0 on GXBB
powerpc/powermac: Add missing lockdep_register_key()
KVM: PPC: Book3S: Suppress warnings when allocating too big memory slots
KVM: PPC: Book3S: Suppress failed alloc warning in H_COPY_TOFROM_GUEST
w1: Misuse of get_user()/put_user() reported by sparse
nvmem: core: set size for sysfs bin file
dm: fix alloc_dax error handling in alloc_dev
scsi: lpfc: Trigger SLI4 firmware dump before doing driver cleanup
ALSA: seq: Set upper limit of processed events
MIPS: Loongson64: Use three arguments for slti
powerpc/40x: Map 32Mbytes of memory at startup
selftests/powerpc/spectre_v2: Return skip code when miss_percent is high
powerpc: handle kdump appropriately with crash_kexec_post_notifiers option
powerpc/fadump: Fix inaccurate CPU state info in vmcore generated with panic
udf: Fix error handling in udf_new_inode()
MIPS: OCTEON: add put_device() after of_find_device_by_node()
irqchip/gic-v4: Disable redistributors' view of the VPE table at boot time
i2c: designware-pci: Fix to change data types of hcnt and lcnt parameters
MIPS: Octeon: Fix build errors using clang
scsi: sr: Don't use GFP_DMA
ASoC: mediatek: mt8173: fix device_node leak
ASoC: mediatek: mt8183: fix device_node leak
phy: mediatek: Fix missing check in mtk_mipi_tx_probe
rpmsg: core: Clean up resources on announce_create failure.
crypto: omap-aes - Fix broken pm_runtime_and_get() usage
crypto: stm32/crc32 - Fix kernel BUG triggered in probe()
crypto: caam - replace this_cpu_ptr with raw_cpu_ptr
ubifs: Error path in ubifs_remount_rw() seems to wrongly free write buffers
tpm: fix NPE on probe for missing device
spi: uniphier: Fix a bug that doesn't point to private data correctly
xen/gntdev: fix unmap notification order
fuse: Pass correct lend value to filemap_write_and_wait_range()
serial: Fix incorrect rs485 polarity on uart open
cputime, cpuacct: Include guest time in user time in cpuacct.stat
tracing/kprobes: 'nmissed' not showed correctly for kretprobe
iwlwifi: mvm: Increase the scan timeout guard to 30 seconds
s390/mm: fix 2KB pgtable release race
device property: Fix fwnode_graph_devcon_match() fwnode leak
drm/etnaviv: limit submit sizes
drm/nouveau/kms/nv04: use vzalloc for nv04_display
drm/bridge: analogix_dp: Make PSR-exit block less
parisc: Fix lpa and lpa_user defines
powerpc/64s/radix: Fix huge vmap false positive
PCI: xgene: Fix IB window setup
PCI: pciehp: Use down_read/write_nested(reset_lock) to fix lockdep errors
PCI: pci-bridge-emul: Make expansion ROM Base Address register read-only
PCI: pci-bridge-emul: Properly mark reserved PCIe bits in PCI config space
PCI: pci-bridge-emul: Fix definitions of reserved bits
PCI: pci-bridge-emul: Correctly set PCIe capabilities
PCI: pci-bridge-emul: Set PCI_STATUS_CAP_LIST for PCIe device
xfrm: fix policy lookup for ipv6 gre packets
btrfs: fix deadlock between quota enable and other quota operations
btrfs: check the root node for uptodate before returning it
btrfs: respect the max size in the header when activating swap file
ext4: make sure to reset inode lockdep class when quota enabling fails
ext4: make sure quota gets properly shutdown on error
ext4: fix a possible ABBA deadlock due to busy PA
ext4: initialize err_blk before calling __ext4_get_inode_loc
ext4: fix fast commit may miss tracking range for FALLOC_FL_ZERO_RANGE
ext4: set csum seed in tmp inode while migrating to extents
ext4: Fix BUG_ON in ext4_bread when write quota data
ext4: use ext4_ext_remove_space() for fast commit replay delete range
ext4: fast commit may miss tracking unwritten range during ftruncate
ext4: destroy ext4_fc_dentry_cachep kmemcache on module removal
ext4: fix null-ptr-deref in '__ext4_journal_ensure_credits'
ext4: don't use the orphan list when migrating an inode
drm/radeon: fix error handling in radeon_driver_open_kms
of: base: Improve argument length mismatch error
firmware: Update Kconfig help text for Google firmware
can: mcp251xfd: mcp251xfd_tef_obj_read(): fix typo in error message
media: rcar-csi2: Optimize the selection PHTW register
drm/vc4: hdmi: Make sure the device is powered with CEC
media: correct MEDIA_TEST_SUPPORT help text
Documentation: dmaengine: Correctly describe dmatest with channel unset
Documentation: ACPI: Fix data node reference documentation
Documentation: refer to config RANDOMIZE_BASE for kernel address-space randomization
Documentation: fix firewire.rst ABI file path error
Bluetooth: hci_sync: Fix not setting adv set duration
scsi: core: Show SCMD_LAST in text form
dmaengine: uniphier-xdmac: Fix type of address variables
RDMA/hns: Modify the mapping attribute of doorbell to device
RDMA/rxe: Fix a typo in opcode name
dmaengine: stm32-mdma: fix STM32_MDMA_CTBR_TSEL_MASK
Revert "net/mlx5: Add retry mechanism to the command entry index allocation"
powerpc/cell: Fix clang -Wimplicit-fallthrough warning
powerpc/fsl/dts: Enable WA for erratum A-009885 on fman3l MDIO buses
block: Fix fsync always failed if once failed
bpftool: Remove inclusion of utilities.mak from Makefiles
xdp: check prog type before updating BPF link
perf evsel: Override attr->sample_period for non-libpfm4 events
ipv4: update fib_info_cnt under spinlock protection
ipv4: avoid quadratic behavior in netns dismantle
net/fsl: xgmac_mdio: Add workaround for erratum A-009885
net/fsl: xgmac_mdio: Fix incorrect iounmap when removing module
parisc: pdc_stable: Fix memory leak in pdcs_register_pathentries
f2fs: compress: fix potential deadlock of compress file
f2fs: fix to reserve space for IO align feature
af_unix: annote lockless accesses to unix_tot_inflight & gc_in_progress
clk: Emit a stern warning with writable debugfs enabled
clk: si5341: Fix clock HW provider cleanup
net/smc: Fix hung_task when removing SMC-R devices
net: axienet: increase reset timeout
net: axienet: Wait for PhyRstCmplt after core reset
net: axienet: reset core on initialization prior to MDIO access
net: axienet: add missing memory barriers
net: axienet: limit minimum TX ring size
net: axienet: Fix TX ring slot available check
net: axienet: fix number of TX ring slots for available check
net: axienet: fix for TX busy handling
net: axienet: increase default TX ring size to 128
HID: vivaldi: fix handling devices not using numbered reports
rtc: pxa: fix null pointer dereference
vdpa/mlx5: Fix wrong configuration of virtio_version_1_0
virtio_ring: mark ring unused on error
taskstats: Cleanup the use of task->exit_code
inet: frags: annotate races around fqdir->dead and fqdir->high_thresh
netns: add schedule point in ops_exit_list()
xfrm: Don't accidentally set RTO_ONLINK in decode_session4()
gre: Don't accidentally set RTO_ONLINK in gre_fill_metadata_dst()
libcxgb: Don't accidentally set RTO_ONLINK in cxgb_find_route()
perf script: Fix hex dump character output
dmaengine: at_xdmac: Don't start transactions at tx_submit level
dmaengine: at_xdmac: Start transfer for cyclic channels in issue_pending
dmaengine: at_xdmac: Print debug message after realeasing the lock
dmaengine: at_xdmac: Fix concurrency over xfers_list
dmaengine: at_xdmac: Fix lld view setting
dmaengine: at_xdmac: Fix at_xdmac_lld struct definition
perf probe: Fix ppc64 'perf probe add events failed' case
devlink: Remove misleading internal_flags from health reporter dump
arm64: dts: qcom: msm8996: drop not documented adreno properties
net: bonding: fix bond_xmit_broadcast return value error bug
net_sched: restore "mpu xxx" handling
bcmgenet: add WOL IRQ check
net: ethernet: mtk_eth_soc: fix error checking in mtk_mac_config()
net: sfp: fix high power modules without diagnostic monitoring
net: mscc: ocelot: fix using match before it is set
dt-bindings: display: meson-dw-hdmi: add missing sound-name-prefix property
dt-bindings: display: meson-vpu: Add missing amlogic,canvas property
dt-bindings: watchdog: Require samsung,syscon-phandle for Exynos7
scripts/dtc: dtx_diff: remove broken example from help text
lib82596: Fix IRQ check in sni_82596_probe
mm/hmm.c: allow VM_MIXEDMAP to work with hmm_range_fault
lib/test_meminit: destroy cache in kmem_cache_alloc_bulk() test
mtd: nand: bbt: Fix corner case in bad block table handling
ath10k: Fix the MTU size on QCA9377 SDIO
scripts: sphinx-pre-install: add required ctex dependency
scripts: sphinx-pre-install: Fix ctex support on Debian
Linux 5.10.94
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I857f2417c899508815a1ba13d1285fd400a1f133
2315 lines
60 KiB
C
2315 lines
60 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Procedures for creating, accessing and interpreting the device tree.
|
|
*
|
|
* Paul Mackerras August 1996.
|
|
* Copyright (C) 1996-2005 Paul Mackerras.
|
|
*
|
|
* Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
|
|
* {engebret|bergner}@us.ibm.com
|
|
*
|
|
* Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net
|
|
*
|
|
* Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell and
|
|
* Grant Likely.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "OF: " fmt
|
|
|
|
#include <linux/bitmap.h>
|
|
#include <linux/console.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_device.h>
|
|
#include <linux/of_graph.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include "of_private.h"
|
|
|
|
LIST_HEAD(aliases_lookup);
|
|
|
|
struct device_node *of_root;
|
|
EXPORT_SYMBOL(of_root);
|
|
struct device_node *of_chosen;
|
|
struct device_node *of_aliases;
|
|
struct device_node *of_stdout;
|
|
static const char *of_stdout_options;
|
|
|
|
struct kset *of_kset;
|
|
|
|
/*
|
|
* Used to protect the of_aliases, to hold off addition of nodes to sysfs.
|
|
* This mutex must be held whenever modifications are being made to the
|
|
* device tree. The of_{attach,detach}_node() and
|
|
* of_{add,remove,update}_property() helpers make sure this happens.
|
|
*/
|
|
DEFINE_MUTEX(of_mutex);
|
|
|
|
/* use when traversing tree through the child, sibling,
|
|
* or parent members of struct device_node.
|
|
*/
|
|
DEFINE_RAW_SPINLOCK(devtree_lock);
|
|
|
|
bool of_node_name_eq(const struct device_node *np, const char *name)
|
|
{
|
|
const char *node_name;
|
|
size_t len;
|
|
|
|
if (!np)
|
|
return false;
|
|
|
|
node_name = kbasename(np->full_name);
|
|
len = strchrnul(node_name, '@') - node_name;
|
|
|
|
return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);
|
|
}
|
|
EXPORT_SYMBOL(of_node_name_eq);
|
|
|
|
bool of_node_name_prefix(const struct device_node *np, const char *prefix)
|
|
{
|
|
if (!np)
|
|
return false;
|
|
|
|
return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0;
|
|
}
|
|
EXPORT_SYMBOL(of_node_name_prefix);
|
|
|
|
static bool __of_node_is_type(const struct device_node *np, const char *type)
|
|
{
|
|
const char *match = __of_get_property(np, "device_type", NULL);
|
|
|
|
return np && match && type && !strcmp(match, type);
|
|
}
|
|
|
|
int of_bus_n_addr_cells(struct device_node *np)
|
|
{
|
|
u32 cells;
|
|
|
|
for (; np; np = np->parent)
|
|
if (!of_property_read_u32(np, "#address-cells", &cells))
|
|
return cells;
|
|
|
|
/* No #address-cells property for the root node */
|
|
return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
|
|
}
|
|
|
|
int of_n_addr_cells(struct device_node *np)
|
|
{
|
|
if (np->parent)
|
|
np = np->parent;
|
|
|
|
return of_bus_n_addr_cells(np);
|
|
}
|
|
EXPORT_SYMBOL(of_n_addr_cells);
|
|
|
|
int of_bus_n_size_cells(struct device_node *np)
|
|
{
|
|
u32 cells;
|
|
|
|
for (; np; np = np->parent)
|
|
if (!of_property_read_u32(np, "#size-cells", &cells))
|
|
return cells;
|
|
|
|
/* No #size-cells property for the root node */
|
|
return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
|
|
}
|
|
|
|
int of_n_size_cells(struct device_node *np)
|
|
{
|
|
if (np->parent)
|
|
np = np->parent;
|
|
|
|
return of_bus_n_size_cells(np);
|
|
}
|
|
EXPORT_SYMBOL(of_n_size_cells);
|
|
|
|
#ifdef CONFIG_NUMA
|
|
int __weak of_node_to_nid(struct device_node *np)
|
|
{
|
|
return NUMA_NO_NODE;
|
|
}
|
|
#endif
|
|
|
|
#define OF_PHANDLE_CACHE_BITS 7
|
|
#define OF_PHANDLE_CACHE_SZ BIT(OF_PHANDLE_CACHE_BITS)
|
|
|
|
static struct device_node *phandle_cache[OF_PHANDLE_CACHE_SZ];
|
|
|
|
static u32 of_phandle_cache_hash(phandle handle)
|
|
{
|
|
return hash_32(handle, OF_PHANDLE_CACHE_BITS);
|
|
}
|
|
|
|
/*
|
|
* Caller must hold devtree_lock.
|
|
*/
|
|
void __of_phandle_cache_inv_entry(phandle handle)
|
|
{
|
|
u32 handle_hash;
|
|
struct device_node *np;
|
|
|
|
if (!handle)
|
|
return;
|
|
|
|
handle_hash = of_phandle_cache_hash(handle);
|
|
|
|
np = phandle_cache[handle_hash];
|
|
if (np && handle == np->phandle)
|
|
phandle_cache[handle_hash] = NULL;
|
|
}
|
|
|
|
void __init of_core_init(void)
|
|
{
|
|
struct device_node *np;
|
|
|
|
|
|
/* Create the kset, and register existing nodes */
|
|
mutex_lock(&of_mutex);
|
|
of_kset = kset_create_and_add("devicetree", NULL, firmware_kobj);
|
|
if (!of_kset) {
|
|
mutex_unlock(&of_mutex);
|
|
pr_err("failed to register existing nodes\n");
|
|
return;
|
|
}
|
|
for_each_of_allnodes(np) {
|
|
__of_attach_node_sysfs(np);
|
|
if (np->phandle && !phandle_cache[of_phandle_cache_hash(np->phandle)])
|
|
phandle_cache[of_phandle_cache_hash(np->phandle)] = np;
|
|
}
|
|
mutex_unlock(&of_mutex);
|
|
|
|
/* Symlink in /proc as required by userspace ABI */
|
|
if (of_root)
|
|
proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base");
|
|
}
|
|
|
|
static struct property *__of_find_property(const struct device_node *np,
|
|
const char *name, int *lenp)
|
|
{
|
|
struct property *pp;
|
|
|
|
if (!np)
|
|
return NULL;
|
|
|
|
for (pp = np->properties; pp; pp = pp->next) {
|
|
if (of_prop_cmp(pp->name, name) == 0) {
|
|
if (lenp)
|
|
*lenp = pp->length;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return pp;
|
|
}
|
|
|
|
struct property *of_find_property(const struct device_node *np,
|
|
const char *name,
|
|
int *lenp)
|
|
{
|
|
struct property *pp;
|
|
unsigned long flags;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
pp = __of_find_property(np, name, lenp);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
|
|
return pp;
|
|
}
|
|
EXPORT_SYMBOL(of_find_property);
|
|
|
|
struct device_node *__of_find_all_nodes(struct device_node *prev)
|
|
{
|
|
struct device_node *np;
|
|
if (!prev) {
|
|
np = of_root;
|
|
} else if (prev->child) {
|
|
np = prev->child;
|
|
} else {
|
|
/* Walk back up looking for a sibling, or the end of the structure */
|
|
np = prev;
|
|
while (np->parent && !np->sibling)
|
|
np = np->parent;
|
|
np = np->sibling; /* Might be null at the end of the tree */
|
|
}
|
|
return np;
|
|
}
|
|
|
|
/**
|
|
* of_find_all_nodes - Get next node in global list
|
|
* @prev: Previous node or NULL to start iteration
|
|
* of_node_put() will be called on it
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_find_all_nodes(struct device_node *prev)
|
|
{
|
|
struct device_node *np;
|
|
unsigned long flags;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
np = __of_find_all_nodes(prev);
|
|
of_node_get(np);
|
|
of_node_put(prev);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_find_all_nodes);
|
|
|
|
/*
|
|
* Find a property with a given name for a given node
|
|
* and return the value.
|
|
*/
|
|
const void *__of_get_property(const struct device_node *np,
|
|
const char *name, int *lenp)
|
|
{
|
|
struct property *pp = __of_find_property(np, name, lenp);
|
|
|
|
return pp ? pp->value : NULL;
|
|
}
|
|
|
|
/*
|
|
* Find a property with a given name for a given node
|
|
* and return the value.
|
|
*/
|
|
const void *of_get_property(const struct device_node *np, const char *name,
|
|
int *lenp)
|
|
{
|
|
struct property *pp = of_find_property(np, name, lenp);
|
|
|
|
return pp ? pp->value : NULL;
|
|
}
|
|
EXPORT_SYMBOL(of_get_property);
|
|
|
|
/*
|
|
* arch_match_cpu_phys_id - Match the given logical CPU and physical id
|
|
*
|
|
* @cpu: logical cpu index of a core/thread
|
|
* @phys_id: physical identifier of a core/thread
|
|
*
|
|
* CPU logical to physical index mapping is architecture specific.
|
|
* However this __weak function provides a default match of physical
|
|
* id to logical cpu index. phys_id provided here is usually values read
|
|
* from the device tree which must match the hardware internal registers.
|
|
*
|
|
* Returns true if the physical identifier and the logical cpu index
|
|
* correspond to the same core/thread, false otherwise.
|
|
*/
|
|
bool __weak arch_match_cpu_phys_id(int cpu, u64 phys_id)
|
|
{
|
|
return (u32)phys_id == cpu;
|
|
}
|
|
|
|
/**
|
|
* Checks if the given "prop_name" property holds the physical id of the
|
|
* core/thread corresponding to the logical cpu 'cpu'. If 'thread' is not
|
|
* NULL, local thread number within the core is returned in it.
|
|
*/
|
|
static bool __of_find_n_match_cpu_property(struct device_node *cpun,
|
|
const char *prop_name, int cpu, unsigned int *thread)
|
|
{
|
|
const __be32 *cell;
|
|
int ac, prop_len, tid;
|
|
u64 hwid;
|
|
|
|
ac = of_n_addr_cells(cpun);
|
|
cell = of_get_property(cpun, prop_name, &prop_len);
|
|
if (!cell && !ac && arch_match_cpu_phys_id(cpu, 0))
|
|
return true;
|
|
if (!cell || !ac)
|
|
return false;
|
|
prop_len /= sizeof(*cell) * ac;
|
|
for (tid = 0; tid < prop_len; tid++) {
|
|
hwid = of_read_number(cell, ac);
|
|
if (arch_match_cpu_phys_id(cpu, hwid)) {
|
|
if (thread)
|
|
*thread = tid;
|
|
return true;
|
|
}
|
|
cell += ac;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* arch_find_n_match_cpu_physical_id - See if the given device node is
|
|
* for the cpu corresponding to logical cpu 'cpu'. Return true if so,
|
|
* else false. If 'thread' is non-NULL, the local thread number within the
|
|
* core is returned in it.
|
|
*/
|
|
bool __weak arch_find_n_match_cpu_physical_id(struct device_node *cpun,
|
|
int cpu, unsigned int *thread)
|
|
{
|
|
/* Check for non-standard "ibm,ppc-interrupt-server#s" property
|
|
* for thread ids on PowerPC. If it doesn't exist fallback to
|
|
* standard "reg" property.
|
|
*/
|
|
if (IS_ENABLED(CONFIG_PPC) &&
|
|
__of_find_n_match_cpu_property(cpun,
|
|
"ibm,ppc-interrupt-server#s",
|
|
cpu, thread))
|
|
return true;
|
|
|
|
return __of_find_n_match_cpu_property(cpun, "reg", cpu, thread);
|
|
}
|
|
|
|
/**
|
|
* of_get_cpu_node - Get device node associated with the given logical CPU
|
|
*
|
|
* @cpu: CPU number(logical index) for which device node is required
|
|
* @thread: if not NULL, local thread number within the physical core is
|
|
* returned
|
|
*
|
|
* The main purpose of this function is to retrieve the device node for the
|
|
* given logical CPU index. It should be used to initialize the of_node in
|
|
* cpu device. Once of_node in cpu device is populated, all the further
|
|
* references can use that instead.
|
|
*
|
|
* CPU logical to physical index mapping is architecture specific and is built
|
|
* before booting secondary cores. This function uses arch_match_cpu_phys_id
|
|
* which can be overridden by architecture specific implementation.
|
|
*
|
|
* Returns a node pointer for the logical cpu with refcount incremented, use
|
|
* of_node_put() on it when done. Returns NULL if not found.
|
|
*/
|
|
struct device_node *of_get_cpu_node(int cpu, unsigned int *thread)
|
|
{
|
|
struct device_node *cpun;
|
|
|
|
for_each_of_cpu_node(cpun) {
|
|
if (arch_find_n_match_cpu_physical_id(cpun, cpu, thread))
|
|
return cpun;
|
|
}
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(of_get_cpu_node);
|
|
|
|
/**
|
|
* of_cpu_node_to_id: Get the logical CPU number for a given device_node
|
|
*
|
|
* @cpu_node: Pointer to the device_node for CPU.
|
|
*
|
|
* Returns the logical CPU number of the given CPU device_node.
|
|
* Returns -ENODEV if the CPU is not found.
|
|
*/
|
|
int of_cpu_node_to_id(struct device_node *cpu_node)
|
|
{
|
|
int cpu;
|
|
bool found = false;
|
|
struct device_node *np;
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
np = of_cpu_device_node_get(cpu);
|
|
found = (cpu_node == np);
|
|
of_node_put(np);
|
|
if (found)
|
|
return cpu;
|
|
}
|
|
|
|
return -ENODEV;
|
|
}
|
|
EXPORT_SYMBOL(of_cpu_node_to_id);
|
|
|
|
/**
|
|
* of_get_cpu_state_node - Get CPU's idle state node at the given index
|
|
*
|
|
* @cpu_node: The device node for the CPU
|
|
* @index: The index in the list of the idle states
|
|
*
|
|
* Two generic methods can be used to describe a CPU's idle states, either via
|
|
* a flattened description through the "cpu-idle-states" binding or via the
|
|
* hierarchical layout, using the "power-domains" and the "domain-idle-states"
|
|
* bindings. This function check for both and returns the idle state node for
|
|
* the requested index.
|
|
*
|
|
* In case an idle state node is found at @index, the refcount is incremented
|
|
* for it, so call of_node_put() on it when done. Returns NULL if not found.
|
|
*/
|
|
struct device_node *of_get_cpu_state_node(struct device_node *cpu_node,
|
|
int index)
|
|
{
|
|
struct of_phandle_args args;
|
|
int err;
|
|
|
|
err = of_parse_phandle_with_args(cpu_node, "power-domains",
|
|
"#power-domain-cells", 0, &args);
|
|
if (!err) {
|
|
struct device_node *state_node =
|
|
of_parse_phandle(args.np, "domain-idle-states", index);
|
|
|
|
of_node_put(args.np);
|
|
if (state_node)
|
|
return state_node;
|
|
}
|
|
|
|
return of_parse_phandle(cpu_node, "cpu-idle-states", index);
|
|
}
|
|
EXPORT_SYMBOL(of_get_cpu_state_node);
|
|
|
|
/**
|
|
* __of_device_is_compatible() - Check if the node matches given constraints
|
|
* @device: pointer to node
|
|
* @compat: required compatible string, NULL or "" for any match
|
|
* @type: required device_type value, NULL or "" for any match
|
|
* @name: required node name, NULL or "" for any match
|
|
*
|
|
* Checks if the given @compat, @type and @name strings match the
|
|
* properties of the given @device. A constraints can be skipped by
|
|
* passing NULL or an empty string as the constraint.
|
|
*
|
|
* Returns 0 for no match, and a positive integer on match. The return
|
|
* value is a relative score with larger values indicating better
|
|
* matches. The score is weighted for the most specific compatible value
|
|
* to get the highest score. Matching type is next, followed by matching
|
|
* name. Practically speaking, this results in the following priority
|
|
* order for matches:
|
|
*
|
|
* 1. specific compatible && type && name
|
|
* 2. specific compatible && type
|
|
* 3. specific compatible && name
|
|
* 4. specific compatible
|
|
* 5. general compatible && type && name
|
|
* 6. general compatible && type
|
|
* 7. general compatible && name
|
|
* 8. general compatible
|
|
* 9. type && name
|
|
* 10. type
|
|
* 11. name
|
|
*/
|
|
static int __of_device_is_compatible(const struct device_node *device,
|
|
const char *compat, const char *type, const char *name)
|
|
{
|
|
struct property *prop;
|
|
const char *cp;
|
|
int index = 0, score = 0;
|
|
|
|
/* Compatible match has highest priority */
|
|
if (compat && compat[0]) {
|
|
prop = __of_find_property(device, "compatible", NULL);
|
|
for (cp = of_prop_next_string(prop, NULL); cp;
|
|
cp = of_prop_next_string(prop, cp), index++) {
|
|
if (of_compat_cmp(cp, compat, strlen(compat)) == 0) {
|
|
score = INT_MAX/2 - (index << 2);
|
|
break;
|
|
}
|
|
}
|
|
if (!score)
|
|
return 0;
|
|
}
|
|
|
|
/* Matching type is better than matching name */
|
|
if (type && type[0]) {
|
|
if (!__of_node_is_type(device, type))
|
|
return 0;
|
|
score += 2;
|
|
}
|
|
|
|
/* Matching name is a bit better than not */
|
|
if (name && name[0]) {
|
|
if (!of_node_name_eq(device, name))
|
|
return 0;
|
|
score++;
|
|
}
|
|
|
|
return score;
|
|
}
|
|
|
|
/** Checks if the given "compat" string matches one of the strings in
|
|
* the device's "compatible" property
|
|
*/
|
|
int of_device_is_compatible(const struct device_node *device,
|
|
const char *compat)
|
|
{
|
|
unsigned long flags;
|
|
int res;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
res = __of_device_is_compatible(device, compat, NULL, NULL);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL(of_device_is_compatible);
|
|
|
|
/** Checks if the device is compatible with any of the entries in
|
|
* a NULL terminated array of strings. Returns the best match
|
|
* score or 0.
|
|
*/
|
|
int of_device_compatible_match(struct device_node *device,
|
|
const char *const *compat)
|
|
{
|
|
unsigned int tmp, score = 0;
|
|
|
|
if (!compat)
|
|
return 0;
|
|
|
|
while (*compat) {
|
|
tmp = of_device_is_compatible(device, *compat);
|
|
if (tmp > score)
|
|
score = tmp;
|
|
compat++;
|
|
}
|
|
|
|
return score;
|
|
}
|
|
|
|
/**
|
|
* of_machine_is_compatible - Test root of device tree for a given compatible value
|
|
* @compat: compatible string to look for in root node's compatible property.
|
|
*
|
|
* Returns a positive integer if the root node has the given value in its
|
|
* compatible property.
|
|
*/
|
|
int of_machine_is_compatible(const char *compat)
|
|
{
|
|
struct device_node *root;
|
|
int rc = 0;
|
|
|
|
root = of_find_node_by_path("/");
|
|
if (root) {
|
|
rc = of_device_is_compatible(root, compat);
|
|
of_node_put(root);
|
|
}
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL(of_machine_is_compatible);
|
|
|
|
/**
|
|
* __of_device_is_available - check if a device is available for use
|
|
*
|
|
* @device: Node to check for availability, with locks already held
|
|
*
|
|
* Returns true if the status property is absent or set to "okay" or "ok",
|
|
* false otherwise
|
|
*/
|
|
static bool __of_device_is_available(const struct device_node *device)
|
|
{
|
|
const char *status;
|
|
int statlen;
|
|
|
|
if (!device)
|
|
return false;
|
|
|
|
status = __of_get_property(device, "status", &statlen);
|
|
if (status == NULL)
|
|
return true;
|
|
|
|
if (statlen > 0) {
|
|
if (!strcmp(status, "okay") || !strcmp(status, "ok"))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* of_device_is_available - check if a device is available for use
|
|
*
|
|
* @device: Node to check for availability
|
|
*
|
|
* Returns true if the status property is absent or set to "okay" or "ok",
|
|
* false otherwise
|
|
*/
|
|
bool of_device_is_available(const struct device_node *device)
|
|
{
|
|
unsigned long flags;
|
|
bool res;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
res = __of_device_is_available(device);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return res;
|
|
|
|
}
|
|
EXPORT_SYMBOL(of_device_is_available);
|
|
|
|
/**
|
|
* of_device_is_big_endian - check if a device has BE registers
|
|
*
|
|
* @device: Node to check for endianness
|
|
*
|
|
* Returns true if the device has a "big-endian" property, or if the kernel
|
|
* was compiled for BE *and* the device has a "native-endian" property.
|
|
* Returns false otherwise.
|
|
*
|
|
* Callers would nominally use ioread32be/iowrite32be if
|
|
* of_device_is_big_endian() == true, or readl/writel otherwise.
|
|
*/
|
|
bool of_device_is_big_endian(const struct device_node *device)
|
|
{
|
|
if (of_property_read_bool(device, "big-endian"))
|
|
return true;
|
|
if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) &&
|
|
of_property_read_bool(device, "native-endian"))
|
|
return true;
|
|
return false;
|
|
}
|
|
EXPORT_SYMBOL(of_device_is_big_endian);
|
|
|
|
/**
|
|
* of_get_parent - Get a node's parent if any
|
|
* @node: Node to get parent
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_get_parent(const struct device_node *node)
|
|
{
|
|
struct device_node *np;
|
|
unsigned long flags;
|
|
|
|
if (!node)
|
|
return NULL;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
np = of_node_get(node->parent);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_get_parent);
|
|
|
|
/**
|
|
* of_get_next_parent - Iterate to a node's parent
|
|
* @node: Node to get parent of
|
|
*
|
|
* This is like of_get_parent() except that it drops the
|
|
* refcount on the passed node, making it suitable for iterating
|
|
* through a node's parents.
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_get_next_parent(struct device_node *node)
|
|
{
|
|
struct device_node *parent;
|
|
unsigned long flags;
|
|
|
|
if (!node)
|
|
return NULL;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
parent = of_node_get(node->parent);
|
|
of_node_put(node);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return parent;
|
|
}
|
|
EXPORT_SYMBOL(of_get_next_parent);
|
|
|
|
static struct device_node *__of_get_next_child(const struct device_node *node,
|
|
struct device_node *prev)
|
|
{
|
|
struct device_node *next;
|
|
|
|
if (!node)
|
|
return NULL;
|
|
|
|
next = prev ? prev->sibling : node->child;
|
|
for (; next; next = next->sibling)
|
|
if (of_node_get(next))
|
|
break;
|
|
of_node_put(prev);
|
|
return next;
|
|
}
|
|
#define __for_each_child_of_node(parent, child) \
|
|
for (child = __of_get_next_child(parent, NULL); child != NULL; \
|
|
child = __of_get_next_child(parent, child))
|
|
|
|
/**
|
|
* of_get_next_child - Iterate a node childs
|
|
* @node: parent node
|
|
* @prev: previous child of the parent node, or NULL to get first
|
|
*
|
|
* Returns a node pointer with refcount incremented, use of_node_put() on
|
|
* it when done. Returns NULL when prev is the last child. Decrements the
|
|
* refcount of prev.
|
|
*/
|
|
struct device_node *of_get_next_child(const struct device_node *node,
|
|
struct device_node *prev)
|
|
{
|
|
struct device_node *next;
|
|
unsigned long flags;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
next = __of_get_next_child(node, prev);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return next;
|
|
}
|
|
EXPORT_SYMBOL(of_get_next_child);
|
|
|
|
/**
|
|
* of_get_next_available_child - Find the next available child node
|
|
* @node: parent node
|
|
* @prev: previous child of the parent node, or NULL to get first
|
|
*
|
|
* This function is like of_get_next_child(), except that it
|
|
* automatically skips any disabled nodes (i.e. status = "disabled").
|
|
*/
|
|
struct device_node *of_get_next_available_child(const struct device_node *node,
|
|
struct device_node *prev)
|
|
{
|
|
struct device_node *next;
|
|
unsigned long flags;
|
|
|
|
if (!node)
|
|
return NULL;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
next = prev ? prev->sibling : node->child;
|
|
for (; next; next = next->sibling) {
|
|
if (!__of_device_is_available(next))
|
|
continue;
|
|
if (of_node_get(next))
|
|
break;
|
|
}
|
|
of_node_put(prev);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return next;
|
|
}
|
|
EXPORT_SYMBOL(of_get_next_available_child);
|
|
|
|
/**
|
|
* of_get_next_cpu_node - Iterate on cpu nodes
|
|
* @prev: previous child of the /cpus node, or NULL to get first
|
|
*
|
|
* Returns a cpu node pointer with refcount incremented, use of_node_put()
|
|
* on it when done. Returns NULL when prev is the last child. Decrements
|
|
* the refcount of prev.
|
|
*/
|
|
struct device_node *of_get_next_cpu_node(struct device_node *prev)
|
|
{
|
|
struct device_node *next = NULL;
|
|
unsigned long flags;
|
|
struct device_node *node;
|
|
|
|
if (!prev)
|
|
node = of_find_node_by_path("/cpus");
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
if (prev)
|
|
next = prev->sibling;
|
|
else if (node) {
|
|
next = node->child;
|
|
of_node_put(node);
|
|
}
|
|
for (; next; next = next->sibling) {
|
|
if (!(of_node_name_eq(next, "cpu") ||
|
|
__of_node_is_type(next, "cpu")))
|
|
continue;
|
|
if (of_node_get(next))
|
|
break;
|
|
}
|
|
of_node_put(prev);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return next;
|
|
}
|
|
EXPORT_SYMBOL(of_get_next_cpu_node);
|
|
|
|
/**
|
|
* of_get_compatible_child - Find compatible child node
|
|
* @parent: parent node
|
|
* @compatible: compatible string
|
|
*
|
|
* Lookup child node whose compatible property contains the given compatible
|
|
* string.
|
|
*
|
|
* Returns a node pointer with refcount incremented, use of_node_put() on it
|
|
* when done; or NULL if not found.
|
|
*/
|
|
struct device_node *of_get_compatible_child(const struct device_node *parent,
|
|
const char *compatible)
|
|
{
|
|
struct device_node *child;
|
|
|
|
for_each_child_of_node(parent, child) {
|
|
if (of_device_is_compatible(child, compatible))
|
|
break;
|
|
}
|
|
|
|
return child;
|
|
}
|
|
EXPORT_SYMBOL(of_get_compatible_child);
|
|
|
|
/**
|
|
* of_get_child_by_name - Find the child node by name for a given parent
|
|
* @node: parent node
|
|
* @name: child name to look for.
|
|
*
|
|
* This function looks for child node for given matching name
|
|
*
|
|
* Returns a node pointer if found, with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
* Returns NULL if node is not found.
|
|
*/
|
|
struct device_node *of_get_child_by_name(const struct device_node *node,
|
|
const char *name)
|
|
{
|
|
struct device_node *child;
|
|
|
|
for_each_child_of_node(node, child)
|
|
if (of_node_name_eq(child, name))
|
|
break;
|
|
return child;
|
|
}
|
|
EXPORT_SYMBOL(of_get_child_by_name);
|
|
|
|
struct device_node *__of_find_node_by_path(struct device_node *parent,
|
|
const char *path)
|
|
{
|
|
struct device_node *child;
|
|
int len;
|
|
|
|
len = strcspn(path, "/:");
|
|
if (!len)
|
|
return NULL;
|
|
|
|
__for_each_child_of_node(parent, child) {
|
|
const char *name = kbasename(child->full_name);
|
|
if (strncmp(path, name, len) == 0 && (strlen(name) == len))
|
|
return child;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
struct device_node *__of_find_node_by_full_path(struct device_node *node,
|
|
const char *path)
|
|
{
|
|
const char *separator = strchr(path, ':');
|
|
|
|
while (node && *path == '/') {
|
|
struct device_node *tmp = node;
|
|
|
|
path++; /* Increment past '/' delimiter */
|
|
node = __of_find_node_by_path(node, path);
|
|
of_node_put(tmp);
|
|
path = strchrnul(path, '/');
|
|
if (separator && separator < path)
|
|
break;
|
|
}
|
|
return node;
|
|
}
|
|
|
|
/**
|
|
* of_find_node_opts_by_path - Find a node matching a full OF path
|
|
* @path: Either the full path to match, or if the path does not
|
|
* start with '/', the name of a property of the /aliases
|
|
* node (an alias). In the case of an alias, the node
|
|
* matching the alias' value will be returned.
|
|
* @opts: Address of a pointer into which to store the start of
|
|
* an options string appended to the end of the path with
|
|
* a ':' separator.
|
|
*
|
|
* Valid paths:
|
|
* /foo/bar Full path
|
|
* foo Valid alias
|
|
* foo/bar Valid alias + relative path
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_find_node_opts_by_path(const char *path, const char **opts)
|
|
{
|
|
struct device_node *np = NULL;
|
|
struct property *pp;
|
|
unsigned long flags;
|
|
const char *separator = strchr(path, ':');
|
|
|
|
if (opts)
|
|
*opts = separator ? separator + 1 : NULL;
|
|
|
|
if (strcmp(path, "/") == 0)
|
|
return of_node_get(of_root);
|
|
|
|
/* The path could begin with an alias */
|
|
if (*path != '/') {
|
|
int len;
|
|
const char *p = separator;
|
|
|
|
if (!p)
|
|
p = strchrnul(path, '/');
|
|
len = p - path;
|
|
|
|
/* of_aliases must not be NULL */
|
|
if (!of_aliases)
|
|
return NULL;
|
|
|
|
for_each_property_of_node(of_aliases, pp) {
|
|
if (strlen(pp->name) == len && !strncmp(pp->name, path, len)) {
|
|
np = of_find_node_by_path(pp->value);
|
|
break;
|
|
}
|
|
}
|
|
if (!np)
|
|
return NULL;
|
|
path = p;
|
|
}
|
|
|
|
/* Step down the tree matching path components */
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
if (!np)
|
|
np = of_node_get(of_root);
|
|
np = __of_find_node_by_full_path(np, path);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_find_node_opts_by_path);
|
|
|
|
/**
|
|
* of_find_node_by_name - Find a node by its "name" property
|
|
* @from: The node to start searching from or NULL; the node
|
|
* you pass will not be searched, only the next one
|
|
* will. Typically, you pass what the previous call
|
|
* returned. of_node_put() will be called on @from.
|
|
* @name: The name string to match against
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_find_node_by_name(struct device_node *from,
|
|
const char *name)
|
|
{
|
|
struct device_node *np;
|
|
unsigned long flags;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
for_each_of_allnodes_from(from, np)
|
|
if (of_node_name_eq(np, name) && of_node_get(np))
|
|
break;
|
|
of_node_put(from);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_find_node_by_name);
|
|
|
|
/**
|
|
* of_find_node_by_type - Find a node by its "device_type" property
|
|
* @from: The node to start searching from, or NULL to start searching
|
|
* the entire device tree. The node you pass will not be
|
|
* searched, only the next one will; typically, you pass
|
|
* what the previous call returned. of_node_put() will be
|
|
* called on from for you.
|
|
* @type: The type string to match against
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_find_node_by_type(struct device_node *from,
|
|
const char *type)
|
|
{
|
|
struct device_node *np;
|
|
unsigned long flags;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
for_each_of_allnodes_from(from, np)
|
|
if (__of_node_is_type(np, type) && of_node_get(np))
|
|
break;
|
|
of_node_put(from);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_find_node_by_type);
|
|
|
|
/**
|
|
* of_find_compatible_node - Find a node based on type and one of the
|
|
* tokens in its "compatible" property
|
|
* @from: The node to start searching from or NULL, the node
|
|
* you pass will not be searched, only the next one
|
|
* will; typically, you pass what the previous call
|
|
* returned. of_node_put() will be called on it
|
|
* @type: The type string to match "device_type" or NULL to ignore
|
|
* @compatible: The string to match to one of the tokens in the device
|
|
* "compatible" list.
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_find_compatible_node(struct device_node *from,
|
|
const char *type, const char *compatible)
|
|
{
|
|
struct device_node *np;
|
|
unsigned long flags;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
for_each_of_allnodes_from(from, np)
|
|
if (__of_device_is_compatible(np, compatible, type, NULL) &&
|
|
of_node_get(np))
|
|
break;
|
|
of_node_put(from);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_find_compatible_node);
|
|
|
|
/**
|
|
* of_find_node_with_property - Find a node which has a property with
|
|
* the given name.
|
|
* @from: The node to start searching from or NULL, the node
|
|
* you pass will not be searched, only the next one
|
|
* will; typically, you pass what the previous call
|
|
* returned. of_node_put() will be called on it
|
|
* @prop_name: The name of the property to look for.
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_find_node_with_property(struct device_node *from,
|
|
const char *prop_name)
|
|
{
|
|
struct device_node *np;
|
|
struct property *pp;
|
|
unsigned long flags;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
for_each_of_allnodes_from(from, np) {
|
|
for (pp = np->properties; pp; pp = pp->next) {
|
|
if (of_prop_cmp(pp->name, prop_name) == 0) {
|
|
of_node_get(np);
|
|
goto out;
|
|
}
|
|
}
|
|
}
|
|
out:
|
|
of_node_put(from);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_find_node_with_property);
|
|
|
|
static
|
|
const struct of_device_id *__of_match_node(const struct of_device_id *matches,
|
|
const struct device_node *node)
|
|
{
|
|
const struct of_device_id *best_match = NULL;
|
|
int score, best_score = 0;
|
|
|
|
if (!matches)
|
|
return NULL;
|
|
|
|
for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) {
|
|
score = __of_device_is_compatible(node, matches->compatible,
|
|
matches->type, matches->name);
|
|
if (score > best_score) {
|
|
best_match = matches;
|
|
best_score = score;
|
|
}
|
|
}
|
|
|
|
return best_match;
|
|
}
|
|
|
|
/**
|
|
* of_match_node - Tell if a device_node has a matching of_match structure
|
|
* @matches: array of of device match structures to search in
|
|
* @node: the of device structure to match against
|
|
*
|
|
* Low level utility function used by device matching.
|
|
*/
|
|
const struct of_device_id *of_match_node(const struct of_device_id *matches,
|
|
const struct device_node *node)
|
|
{
|
|
const struct of_device_id *match;
|
|
unsigned long flags;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
match = __of_match_node(matches, node);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return match;
|
|
}
|
|
EXPORT_SYMBOL(of_match_node);
|
|
|
|
/**
|
|
* of_find_matching_node_and_match - Find a node based on an of_device_id
|
|
* match table.
|
|
* @from: The node to start searching from or NULL, the node
|
|
* you pass will not be searched, only the next one
|
|
* will; typically, you pass what the previous call
|
|
* returned. of_node_put() will be called on it
|
|
* @matches: array of of device match structures to search in
|
|
* @match Updated to point at the matches entry which matched
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_find_matching_node_and_match(struct device_node *from,
|
|
const struct of_device_id *matches,
|
|
const struct of_device_id **match)
|
|
{
|
|
struct device_node *np;
|
|
const struct of_device_id *m;
|
|
unsigned long flags;
|
|
|
|
if (match)
|
|
*match = NULL;
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
for_each_of_allnodes_from(from, np) {
|
|
m = __of_match_node(matches, np);
|
|
if (m && of_node_get(np)) {
|
|
if (match)
|
|
*match = m;
|
|
break;
|
|
}
|
|
}
|
|
of_node_put(from);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_find_matching_node_and_match);
|
|
|
|
/**
|
|
* of_modalias_node - Lookup appropriate modalias for a device node
|
|
* @node: pointer to a device tree node
|
|
* @modalias: Pointer to buffer that modalias value will be copied into
|
|
* @len: Length of modalias value
|
|
*
|
|
* Based on the value of the compatible property, this routine will attempt
|
|
* to choose an appropriate modalias value for a particular device tree node.
|
|
* It does this by stripping the manufacturer prefix (as delimited by a ',')
|
|
* from the first entry in the compatible list property.
|
|
*
|
|
* This routine returns 0 on success, <0 on failure.
|
|
*/
|
|
int of_modalias_node(struct device_node *node, char *modalias, int len)
|
|
{
|
|
const char *compatible, *p;
|
|
int cplen;
|
|
|
|
compatible = of_get_property(node, "compatible", &cplen);
|
|
if (!compatible || strlen(compatible) > cplen)
|
|
return -ENODEV;
|
|
p = strchr(compatible, ',');
|
|
strlcpy(modalias, p ? p + 1 : compatible, len);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_modalias_node);
|
|
|
|
/**
|
|
* of_find_node_by_phandle - Find a node given a phandle
|
|
* @handle: phandle of the node to find
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_find_node_by_phandle(phandle handle)
|
|
{
|
|
struct device_node *np = NULL;
|
|
unsigned long flags;
|
|
u32 handle_hash;
|
|
|
|
if (!handle)
|
|
return NULL;
|
|
|
|
handle_hash = of_phandle_cache_hash(handle);
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
|
|
if (phandle_cache[handle_hash] &&
|
|
handle == phandle_cache[handle_hash]->phandle)
|
|
np = phandle_cache[handle_hash];
|
|
|
|
if (!np) {
|
|
for_each_of_allnodes(np)
|
|
if (np->phandle == handle &&
|
|
!of_node_check_flag(np, OF_DETACHED)) {
|
|
phandle_cache[handle_hash] = np;
|
|
break;
|
|
}
|
|
}
|
|
|
|
of_node_get(np);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
return np;
|
|
}
|
|
EXPORT_SYMBOL(of_find_node_by_phandle);
|
|
|
|
void of_print_phandle_args(const char *msg, const struct of_phandle_args *args)
|
|
{
|
|
int i;
|
|
printk("%s %pOF", msg, args->np);
|
|
for (i = 0; i < args->args_count; i++) {
|
|
const char delim = i ? ',' : ':';
|
|
|
|
pr_cont("%c%08x", delim, args->args[i]);
|
|
}
|
|
pr_cont("\n");
|
|
}
|
|
|
|
int of_phandle_iterator_init(struct of_phandle_iterator *it,
|
|
const struct device_node *np,
|
|
const char *list_name,
|
|
const char *cells_name,
|
|
int cell_count)
|
|
{
|
|
const __be32 *list;
|
|
int size;
|
|
|
|
memset(it, 0, sizeof(*it));
|
|
|
|
/*
|
|
* one of cell_count or cells_name must be provided to determine the
|
|
* argument length.
|
|
*/
|
|
if (cell_count < 0 && !cells_name)
|
|
return -EINVAL;
|
|
|
|
list = of_get_property(np, list_name, &size);
|
|
if (!list)
|
|
return -ENOENT;
|
|
|
|
it->cells_name = cells_name;
|
|
it->cell_count = cell_count;
|
|
it->parent = np;
|
|
it->list_end = list + size / sizeof(*list);
|
|
it->phandle_end = list;
|
|
it->cur = list;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_phandle_iterator_init);
|
|
|
|
int of_phandle_iterator_next(struct of_phandle_iterator *it)
|
|
{
|
|
uint32_t count = 0;
|
|
|
|
if (it->node) {
|
|
of_node_put(it->node);
|
|
it->node = NULL;
|
|
}
|
|
|
|
if (!it->cur || it->phandle_end >= it->list_end)
|
|
return -ENOENT;
|
|
|
|
it->cur = it->phandle_end;
|
|
|
|
/* If phandle is 0, then it is an empty entry with no arguments. */
|
|
it->phandle = be32_to_cpup(it->cur++);
|
|
|
|
if (it->phandle) {
|
|
|
|
/*
|
|
* Find the provider node and parse the #*-cells property to
|
|
* determine the argument length.
|
|
*/
|
|
it->node = of_find_node_by_phandle(it->phandle);
|
|
|
|
if (it->cells_name) {
|
|
if (!it->node) {
|
|
pr_err("%pOF: could not find phandle\n",
|
|
it->parent);
|
|
goto err;
|
|
}
|
|
|
|
if (of_property_read_u32(it->node, it->cells_name,
|
|
&count)) {
|
|
/*
|
|
* If both cell_count and cells_name is given,
|
|
* fall back to cell_count in absence
|
|
* of the cells_name property
|
|
*/
|
|
if (it->cell_count >= 0) {
|
|
count = it->cell_count;
|
|
} else {
|
|
pr_err("%pOF: could not get %s for %pOF\n",
|
|
it->parent,
|
|
it->cells_name,
|
|
it->node);
|
|
goto err;
|
|
}
|
|
}
|
|
} else {
|
|
count = it->cell_count;
|
|
}
|
|
|
|
/*
|
|
* Make sure that the arguments actually fit in the remaining
|
|
* property data length
|
|
*/
|
|
if (it->cur + count > it->list_end) {
|
|
if (it->cells_name)
|
|
pr_err("%pOF: %s = %d found %td\n",
|
|
it->parent, it->cells_name,
|
|
count, it->list_end - it->cur);
|
|
else
|
|
pr_err("%pOF: phandle %s needs %d, found %td\n",
|
|
it->parent, of_node_full_name(it->node),
|
|
count, it->list_end - it->cur);
|
|
goto err;
|
|
}
|
|
}
|
|
|
|
it->phandle_end = it->cur + count;
|
|
it->cur_count = count;
|
|
|
|
return 0;
|
|
|
|
err:
|
|
if (it->node) {
|
|
of_node_put(it->node);
|
|
it->node = NULL;
|
|
}
|
|
|
|
return -EINVAL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_phandle_iterator_next);
|
|
|
|
int of_phandle_iterator_args(struct of_phandle_iterator *it,
|
|
uint32_t *args,
|
|
int size)
|
|
{
|
|
int i, count;
|
|
|
|
count = it->cur_count;
|
|
|
|
if (WARN_ON(size < count))
|
|
count = size;
|
|
|
|
for (i = 0; i < count; i++)
|
|
args[i] = be32_to_cpup(it->cur++);
|
|
|
|
return count;
|
|
}
|
|
|
|
static int __of_parse_phandle_with_args(const struct device_node *np,
|
|
const char *list_name,
|
|
const char *cells_name,
|
|
int cell_count, int index,
|
|
struct of_phandle_args *out_args)
|
|
{
|
|
struct of_phandle_iterator it;
|
|
int rc, cur_index = 0;
|
|
|
|
/* Loop over the phandles until all the requested entry is found */
|
|
of_for_each_phandle(&it, rc, np, list_name, cells_name, cell_count) {
|
|
/*
|
|
* All of the error cases bail out of the loop, so at
|
|
* this point, the parsing is successful. If the requested
|
|
* index matches, then fill the out_args structure and return,
|
|
* or return -ENOENT for an empty entry.
|
|
*/
|
|
rc = -ENOENT;
|
|
if (cur_index == index) {
|
|
if (!it.phandle)
|
|
goto err;
|
|
|
|
if (out_args) {
|
|
int c;
|
|
|
|
c = of_phandle_iterator_args(&it,
|
|
out_args->args,
|
|
MAX_PHANDLE_ARGS);
|
|
out_args->np = it.node;
|
|
out_args->args_count = c;
|
|
} else {
|
|
of_node_put(it.node);
|
|
}
|
|
|
|
/* Found it! return success */
|
|
return 0;
|
|
}
|
|
|
|
cur_index++;
|
|
}
|
|
|
|
/*
|
|
* Unlock node before returning result; will be one of:
|
|
* -ENOENT : index is for empty phandle
|
|
* -EINVAL : parsing error on data
|
|
*/
|
|
|
|
err:
|
|
of_node_put(it.node);
|
|
return rc;
|
|
}
|
|
|
|
/**
|
|
* of_parse_phandle - Resolve a phandle property to a device_node pointer
|
|
* @np: Pointer to device node holding phandle property
|
|
* @phandle_name: Name of property holding a phandle value
|
|
* @index: For properties holding a table of phandles, this is the index into
|
|
* the table
|
|
*
|
|
* Returns the device_node pointer with refcount incremented. Use
|
|
* of_node_put() on it when done.
|
|
*/
|
|
struct device_node *of_parse_phandle(const struct device_node *np,
|
|
const char *phandle_name, int index)
|
|
{
|
|
struct of_phandle_args args;
|
|
|
|
if (index < 0)
|
|
return NULL;
|
|
|
|
if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
|
|
index, &args))
|
|
return NULL;
|
|
|
|
return args.np;
|
|
}
|
|
EXPORT_SYMBOL(of_parse_phandle);
|
|
|
|
/**
|
|
* of_parse_phandle_with_args() - Find a node pointed by phandle in a list
|
|
* @np: pointer to a device tree node containing a list
|
|
* @list_name: property name that contains a list
|
|
* @cells_name: property name that specifies phandles' arguments count
|
|
* @index: index of a phandle to parse out
|
|
* @out_args: optional pointer to output arguments structure (will be filled)
|
|
*
|
|
* This function is useful to parse lists of phandles and their arguments.
|
|
* Returns 0 on success and fills out_args, on error returns appropriate
|
|
* errno value.
|
|
*
|
|
* Caller is responsible to call of_node_put() on the returned out_args->np
|
|
* pointer.
|
|
*
|
|
* Example:
|
|
*
|
|
* phandle1: node1 {
|
|
* #list-cells = <2>;
|
|
* }
|
|
*
|
|
* phandle2: node2 {
|
|
* #list-cells = <1>;
|
|
* }
|
|
*
|
|
* node3 {
|
|
* list = <&phandle1 1 2 &phandle2 3>;
|
|
* }
|
|
*
|
|
* To get a device_node of the `node2' node you may call this:
|
|
* of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
|
|
*/
|
|
int of_parse_phandle_with_args(const struct device_node *np, const char *list_name,
|
|
const char *cells_name, int index,
|
|
struct of_phandle_args *out_args)
|
|
{
|
|
int cell_count = -1;
|
|
|
|
if (index < 0)
|
|
return -EINVAL;
|
|
|
|
/* If cells_name is NULL we assume a cell count of 0 */
|
|
if (!cells_name)
|
|
cell_count = 0;
|
|
|
|
return __of_parse_phandle_with_args(np, list_name, cells_name,
|
|
cell_count, index, out_args);
|
|
}
|
|
EXPORT_SYMBOL(of_parse_phandle_with_args);
|
|
|
|
/**
|
|
* of_parse_phandle_with_args_map() - Find a node pointed by phandle in a list and remap it
|
|
* @np: pointer to a device tree node containing a list
|
|
* @list_name: property name that contains a list
|
|
* @stem_name: stem of property names that specify phandles' arguments count
|
|
* @index: index of a phandle to parse out
|
|
* @out_args: optional pointer to output arguments structure (will be filled)
|
|
*
|
|
* This function is useful to parse lists of phandles and their arguments.
|
|
* Returns 0 on success and fills out_args, on error returns appropriate errno
|
|
* value. The difference between this function and of_parse_phandle_with_args()
|
|
* is that this API remaps a phandle if the node the phandle points to has
|
|
* a <@stem_name>-map property.
|
|
*
|
|
* Caller is responsible to call of_node_put() on the returned out_args->np
|
|
* pointer.
|
|
*
|
|
* Example:
|
|
*
|
|
* phandle1: node1 {
|
|
* #list-cells = <2>;
|
|
* }
|
|
*
|
|
* phandle2: node2 {
|
|
* #list-cells = <1>;
|
|
* }
|
|
*
|
|
* phandle3: node3 {
|
|
* #list-cells = <1>;
|
|
* list-map = <0 &phandle2 3>,
|
|
* <1 &phandle2 2>,
|
|
* <2 &phandle1 5 1>;
|
|
* list-map-mask = <0x3>;
|
|
* };
|
|
*
|
|
* node4 {
|
|
* list = <&phandle1 1 2 &phandle3 0>;
|
|
* }
|
|
*
|
|
* To get a device_node of the `node2' node you may call this:
|
|
* of_parse_phandle_with_args(node4, "list", "list", 1, &args);
|
|
*/
|
|
int of_parse_phandle_with_args_map(const struct device_node *np,
|
|
const char *list_name,
|
|
const char *stem_name,
|
|
int index, struct of_phandle_args *out_args)
|
|
{
|
|
char *cells_name, *map_name = NULL, *mask_name = NULL;
|
|
char *pass_name = NULL;
|
|
struct device_node *cur, *new = NULL;
|
|
const __be32 *map, *mask, *pass;
|
|
static const __be32 dummy_mask[] = { [0 ... MAX_PHANDLE_ARGS] = ~0 };
|
|
static const __be32 dummy_pass[] = { [0 ... MAX_PHANDLE_ARGS] = 0 };
|
|
__be32 initial_match_array[MAX_PHANDLE_ARGS];
|
|
const __be32 *match_array = initial_match_array;
|
|
int i, ret, map_len, match;
|
|
u32 list_size, new_size;
|
|
|
|
if (index < 0)
|
|
return -EINVAL;
|
|
|
|
cells_name = kasprintf(GFP_KERNEL, "#%s-cells", stem_name);
|
|
if (!cells_name)
|
|
return -ENOMEM;
|
|
|
|
ret = -ENOMEM;
|
|
map_name = kasprintf(GFP_KERNEL, "%s-map", stem_name);
|
|
if (!map_name)
|
|
goto free;
|
|
|
|
mask_name = kasprintf(GFP_KERNEL, "%s-map-mask", stem_name);
|
|
if (!mask_name)
|
|
goto free;
|
|
|
|
pass_name = kasprintf(GFP_KERNEL, "%s-map-pass-thru", stem_name);
|
|
if (!pass_name)
|
|
goto free;
|
|
|
|
ret = __of_parse_phandle_with_args(np, list_name, cells_name, -1, index,
|
|
out_args);
|
|
if (ret)
|
|
goto free;
|
|
|
|
/* Get the #<list>-cells property */
|
|
cur = out_args->np;
|
|
ret = of_property_read_u32(cur, cells_name, &list_size);
|
|
if (ret < 0)
|
|
goto put;
|
|
|
|
/* Precalculate the match array - this simplifies match loop */
|
|
for (i = 0; i < list_size; i++)
|
|
initial_match_array[i] = cpu_to_be32(out_args->args[i]);
|
|
|
|
ret = -EINVAL;
|
|
while (cur) {
|
|
/* Get the <list>-map property */
|
|
map = of_get_property(cur, map_name, &map_len);
|
|
if (!map) {
|
|
ret = 0;
|
|
goto free;
|
|
}
|
|
map_len /= sizeof(u32);
|
|
|
|
/* Get the <list>-map-mask property (optional) */
|
|
mask = of_get_property(cur, mask_name, NULL);
|
|
if (!mask)
|
|
mask = dummy_mask;
|
|
/* Iterate through <list>-map property */
|
|
match = 0;
|
|
while (map_len > (list_size + 1) && !match) {
|
|
/* Compare specifiers */
|
|
match = 1;
|
|
for (i = 0; i < list_size; i++, map_len--)
|
|
match &= !((match_array[i] ^ *map++) & mask[i]);
|
|
|
|
of_node_put(new);
|
|
new = of_find_node_by_phandle(be32_to_cpup(map));
|
|
map++;
|
|
map_len--;
|
|
|
|
/* Check if not found */
|
|
if (!new)
|
|
goto put;
|
|
|
|
if (!of_device_is_available(new))
|
|
match = 0;
|
|
|
|
ret = of_property_read_u32(new, cells_name, &new_size);
|
|
if (ret)
|
|
goto put;
|
|
|
|
/* Check for malformed properties */
|
|
if (WARN_ON(new_size > MAX_PHANDLE_ARGS))
|
|
goto put;
|
|
if (map_len < new_size)
|
|
goto put;
|
|
|
|
/* Move forward by new node's #<list>-cells amount */
|
|
map += new_size;
|
|
map_len -= new_size;
|
|
}
|
|
if (!match)
|
|
goto put;
|
|
|
|
/* Get the <list>-map-pass-thru property (optional) */
|
|
pass = of_get_property(cur, pass_name, NULL);
|
|
if (!pass)
|
|
pass = dummy_pass;
|
|
|
|
/*
|
|
* Successfully parsed a <list>-map translation; copy new
|
|
* specifier into the out_args structure, keeping the
|
|
* bits specified in <list>-map-pass-thru.
|
|
*/
|
|
match_array = map - new_size;
|
|
for (i = 0; i < new_size; i++) {
|
|
__be32 val = *(map - new_size + i);
|
|
|
|
if (i < list_size) {
|
|
val &= ~pass[i];
|
|
val |= cpu_to_be32(out_args->args[i]) & pass[i];
|
|
}
|
|
|
|
out_args->args[i] = be32_to_cpu(val);
|
|
}
|
|
out_args->args_count = list_size = new_size;
|
|
/* Iterate again with new provider */
|
|
out_args->np = new;
|
|
of_node_put(cur);
|
|
cur = new;
|
|
}
|
|
put:
|
|
of_node_put(cur);
|
|
of_node_put(new);
|
|
free:
|
|
kfree(mask_name);
|
|
kfree(map_name);
|
|
kfree(cells_name);
|
|
kfree(pass_name);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(of_parse_phandle_with_args_map);
|
|
|
|
/**
|
|
* of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
|
|
* @np: pointer to a device tree node containing a list
|
|
* @list_name: property name that contains a list
|
|
* @cell_count: number of argument cells following the phandle
|
|
* @index: index of a phandle to parse out
|
|
* @out_args: optional pointer to output arguments structure (will be filled)
|
|
*
|
|
* This function is useful to parse lists of phandles and their arguments.
|
|
* Returns 0 on success and fills out_args, on error returns appropriate
|
|
* errno value.
|
|
*
|
|
* Caller is responsible to call of_node_put() on the returned out_args->np
|
|
* pointer.
|
|
*
|
|
* Example:
|
|
*
|
|
* phandle1: node1 {
|
|
* }
|
|
*
|
|
* phandle2: node2 {
|
|
* }
|
|
*
|
|
* node3 {
|
|
* list = <&phandle1 0 2 &phandle2 2 3>;
|
|
* }
|
|
*
|
|
* To get a device_node of the `node2' node you may call this:
|
|
* of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
|
|
*/
|
|
int of_parse_phandle_with_fixed_args(const struct device_node *np,
|
|
const char *list_name, int cell_count,
|
|
int index, struct of_phandle_args *out_args)
|
|
{
|
|
if (index < 0)
|
|
return -EINVAL;
|
|
return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
|
|
index, out_args);
|
|
}
|
|
EXPORT_SYMBOL(of_parse_phandle_with_fixed_args);
|
|
|
|
/**
|
|
* of_count_phandle_with_args() - Find the number of phandles references in a property
|
|
* @np: pointer to a device tree node containing a list
|
|
* @list_name: property name that contains a list
|
|
* @cells_name: property name that specifies phandles' arguments count
|
|
*
|
|
* Returns the number of phandle + argument tuples within a property. It
|
|
* is a typical pattern to encode a list of phandle and variable
|
|
* arguments into a single property. The number of arguments is encoded
|
|
* by a property in the phandle-target node. For example, a gpios
|
|
* property would contain a list of GPIO specifies consisting of a
|
|
* phandle and 1 or more arguments. The number of arguments are
|
|
* determined by the #gpio-cells property in the node pointed to by the
|
|
* phandle.
|
|
*/
|
|
int of_count_phandle_with_args(const struct device_node *np, const char *list_name,
|
|
const char *cells_name)
|
|
{
|
|
struct of_phandle_iterator it;
|
|
int rc, cur_index = 0;
|
|
|
|
/*
|
|
* If cells_name is NULL we assume a cell count of 0. This makes
|
|
* counting the phandles trivial as each 32bit word in the list is a
|
|
* phandle and no arguments are to consider. So we don't iterate through
|
|
* the list but just use the length to determine the phandle count.
|
|
*/
|
|
if (!cells_name) {
|
|
const __be32 *list;
|
|
int size;
|
|
|
|
list = of_get_property(np, list_name, &size);
|
|
if (!list)
|
|
return -ENOENT;
|
|
|
|
return size / sizeof(*list);
|
|
}
|
|
|
|
rc = of_phandle_iterator_init(&it, np, list_name, cells_name, -1);
|
|
if (rc)
|
|
return rc;
|
|
|
|
while ((rc = of_phandle_iterator_next(&it)) == 0)
|
|
cur_index += 1;
|
|
|
|
if (rc != -ENOENT)
|
|
return rc;
|
|
|
|
return cur_index;
|
|
}
|
|
EXPORT_SYMBOL(of_count_phandle_with_args);
|
|
|
|
/**
|
|
* __of_add_property - Add a property to a node without lock operations
|
|
*/
|
|
int __of_add_property(struct device_node *np, struct property *prop)
|
|
{
|
|
struct property **next;
|
|
|
|
prop->next = NULL;
|
|
next = &np->properties;
|
|
while (*next) {
|
|
if (strcmp(prop->name, (*next)->name) == 0)
|
|
/* duplicate ! don't insert it */
|
|
return -EEXIST;
|
|
|
|
next = &(*next)->next;
|
|
}
|
|
*next = prop;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* of_add_property - Add a property to a node
|
|
*/
|
|
int of_add_property(struct device_node *np, struct property *prop)
|
|
{
|
|
unsigned long flags;
|
|
int rc;
|
|
|
|
mutex_lock(&of_mutex);
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
rc = __of_add_property(np, prop);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
|
|
if (!rc)
|
|
__of_add_property_sysfs(np, prop);
|
|
|
|
mutex_unlock(&of_mutex);
|
|
|
|
if (!rc)
|
|
of_property_notify(OF_RECONFIG_ADD_PROPERTY, np, prop, NULL);
|
|
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_add_property);
|
|
|
|
int __of_remove_property(struct device_node *np, struct property *prop)
|
|
{
|
|
struct property **next;
|
|
|
|
for (next = &np->properties; *next; next = &(*next)->next) {
|
|
if (*next == prop)
|
|
break;
|
|
}
|
|
if (*next == NULL)
|
|
return -ENODEV;
|
|
|
|
/* found the node */
|
|
*next = prop->next;
|
|
prop->next = np->deadprops;
|
|
np->deadprops = prop;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* of_remove_property - Remove a property from a node.
|
|
*
|
|
* Note that we don't actually remove it, since we have given out
|
|
* who-knows-how-many pointers to the data using get-property.
|
|
* Instead we just move the property to the "dead properties"
|
|
* list, so it won't be found any more.
|
|
*/
|
|
int of_remove_property(struct device_node *np, struct property *prop)
|
|
{
|
|
unsigned long flags;
|
|
int rc;
|
|
|
|
if (!prop)
|
|
return -ENODEV;
|
|
|
|
mutex_lock(&of_mutex);
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
rc = __of_remove_property(np, prop);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
|
|
if (!rc)
|
|
__of_remove_property_sysfs(np, prop);
|
|
|
|
mutex_unlock(&of_mutex);
|
|
|
|
if (!rc)
|
|
of_property_notify(OF_RECONFIG_REMOVE_PROPERTY, np, prop, NULL);
|
|
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_remove_property);
|
|
|
|
int __of_update_property(struct device_node *np, struct property *newprop,
|
|
struct property **oldpropp)
|
|
{
|
|
struct property **next, *oldprop;
|
|
|
|
for (next = &np->properties; *next; next = &(*next)->next) {
|
|
if (of_prop_cmp((*next)->name, newprop->name) == 0)
|
|
break;
|
|
}
|
|
*oldpropp = oldprop = *next;
|
|
|
|
if (oldprop) {
|
|
/* replace the node */
|
|
newprop->next = oldprop->next;
|
|
*next = newprop;
|
|
oldprop->next = np->deadprops;
|
|
np->deadprops = oldprop;
|
|
} else {
|
|
/* new node */
|
|
newprop->next = NULL;
|
|
*next = newprop;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* of_update_property - Update a property in a node, if the property does
|
|
* not exist, add it.
|
|
*
|
|
* Note that we don't actually remove it, since we have given out
|
|
* who-knows-how-many pointers to the data using get-property.
|
|
* Instead we just move the property to the "dead properties" list,
|
|
* and add the new property to the property list
|
|
*/
|
|
int of_update_property(struct device_node *np, struct property *newprop)
|
|
{
|
|
struct property *oldprop;
|
|
unsigned long flags;
|
|
int rc;
|
|
|
|
if (!newprop->name)
|
|
return -EINVAL;
|
|
|
|
mutex_lock(&of_mutex);
|
|
|
|
raw_spin_lock_irqsave(&devtree_lock, flags);
|
|
rc = __of_update_property(np, newprop, &oldprop);
|
|
raw_spin_unlock_irqrestore(&devtree_lock, flags);
|
|
|
|
if (!rc)
|
|
__of_update_property_sysfs(np, newprop, oldprop);
|
|
|
|
mutex_unlock(&of_mutex);
|
|
|
|
if (!rc)
|
|
of_property_notify(OF_RECONFIG_UPDATE_PROPERTY, np, newprop, oldprop);
|
|
|
|
return rc;
|
|
}
|
|
|
|
static void of_alias_add(struct alias_prop *ap, struct device_node *np,
|
|
int id, const char *stem, int stem_len)
|
|
{
|
|
ap->np = np;
|
|
ap->id = id;
|
|
strncpy(ap->stem, stem, stem_len);
|
|
ap->stem[stem_len] = 0;
|
|
list_add_tail(&ap->link, &aliases_lookup);
|
|
pr_debug("adding DT alias:%s: stem=%s id=%i node=%pOF\n",
|
|
ap->alias, ap->stem, ap->id, np);
|
|
}
|
|
|
|
/**
|
|
* of_alias_scan - Scan all properties of the 'aliases' node
|
|
*
|
|
* The function scans all the properties of the 'aliases' node and populates
|
|
* the global lookup table with the properties. It returns the
|
|
* number of alias properties found, or an error code in case of failure.
|
|
*
|
|
* @dt_alloc: An allocator that provides a virtual address to memory
|
|
* for storing the resulting tree
|
|
*/
|
|
void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
|
|
{
|
|
struct property *pp;
|
|
|
|
of_aliases = of_find_node_by_path("/aliases");
|
|
of_chosen = of_find_node_by_path("/chosen");
|
|
if (of_chosen == NULL)
|
|
of_chosen = of_find_node_by_path("/chosen@0");
|
|
|
|
if (of_chosen) {
|
|
/* linux,stdout-path and /aliases/stdout are for legacy compatibility */
|
|
const char *name = NULL;
|
|
|
|
if (of_property_read_string(of_chosen, "stdout-path", &name))
|
|
of_property_read_string(of_chosen, "linux,stdout-path",
|
|
&name);
|
|
if (IS_ENABLED(CONFIG_PPC) && !name)
|
|
of_property_read_string(of_aliases, "stdout", &name);
|
|
if (name)
|
|
of_stdout = of_find_node_opts_by_path(name, &of_stdout_options);
|
|
}
|
|
|
|
if (!of_aliases)
|
|
return;
|
|
|
|
for_each_property_of_node(of_aliases, pp) {
|
|
const char *start = pp->name;
|
|
const char *end = start + strlen(start);
|
|
struct device_node *np;
|
|
struct alias_prop *ap;
|
|
int id, len;
|
|
|
|
/* Skip those we do not want to proceed */
|
|
if (!strcmp(pp->name, "name") ||
|
|
!strcmp(pp->name, "phandle") ||
|
|
!strcmp(pp->name, "linux,phandle"))
|
|
continue;
|
|
|
|
np = of_find_node_by_path(pp->value);
|
|
if (!np)
|
|
continue;
|
|
|
|
/* walk the alias backwards to extract the id and work out
|
|
* the 'stem' string */
|
|
while (isdigit(*(end-1)) && end > start)
|
|
end--;
|
|
len = end - start;
|
|
|
|
if (kstrtoint(end, 10, &id) < 0)
|
|
continue;
|
|
|
|
/* Allocate an alias_prop with enough space for the stem */
|
|
ap = dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap));
|
|
if (!ap)
|
|
continue;
|
|
memset(ap, 0, sizeof(*ap) + len + 1);
|
|
ap->alias = start;
|
|
of_alias_add(ap, np, id, start, len);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* of_alias_get_id - Get alias id for the given device_node
|
|
* @np: Pointer to the given device_node
|
|
* @stem: Alias stem of the given device_node
|
|
*
|
|
* The function travels the lookup table to get the alias id for the given
|
|
* device_node and alias stem. It returns the alias id if found.
|
|
*/
|
|
int of_alias_get_id(struct device_node *np, const char *stem)
|
|
{
|
|
struct alias_prop *app;
|
|
int id = -ENODEV;
|
|
|
|
mutex_lock(&of_mutex);
|
|
list_for_each_entry(app, &aliases_lookup, link) {
|
|
if (strcmp(app->stem, stem) != 0)
|
|
continue;
|
|
|
|
if (np == app->np) {
|
|
id = app->id;
|
|
break;
|
|
}
|
|
}
|
|
mutex_unlock(&of_mutex);
|
|
|
|
return id;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_alias_get_id);
|
|
|
|
/**
|
|
* of_alias_get_alias_list - Get alias list for the given device driver
|
|
* @matches: Array of OF device match structures to search in
|
|
* @stem: Alias stem of the given device_node
|
|
* @bitmap: Bitmap field pointer
|
|
* @nbits: Maximum number of alias IDs which can be recorded in bitmap
|
|
*
|
|
* The function travels the lookup table to record alias ids for the given
|
|
* device match structures and alias stem.
|
|
*
|
|
* Return: 0 or -ENOSYS when !CONFIG_OF or
|
|
* -EOVERFLOW if alias ID is greater then allocated nbits
|
|
*/
|
|
int of_alias_get_alias_list(const struct of_device_id *matches,
|
|
const char *stem, unsigned long *bitmap,
|
|
unsigned int nbits)
|
|
{
|
|
struct alias_prop *app;
|
|
int ret = 0;
|
|
|
|
/* Zero bitmap field to make sure that all the time it is clean */
|
|
bitmap_zero(bitmap, nbits);
|
|
|
|
mutex_lock(&of_mutex);
|
|
pr_debug("%s: Looking for stem: %s\n", __func__, stem);
|
|
list_for_each_entry(app, &aliases_lookup, link) {
|
|
pr_debug("%s: stem: %s, id: %d\n",
|
|
__func__, app->stem, app->id);
|
|
|
|
if (strcmp(app->stem, stem) != 0) {
|
|
pr_debug("%s: stem comparison didn't pass %s\n",
|
|
__func__, app->stem);
|
|
continue;
|
|
}
|
|
|
|
if (of_match_node(matches, app->np)) {
|
|
pr_debug("%s: Allocated ID %d\n", __func__, app->id);
|
|
|
|
if (app->id >= nbits) {
|
|
pr_warn("%s: ID %d >= than bitmap field %d\n",
|
|
__func__, app->id, nbits);
|
|
ret = -EOVERFLOW;
|
|
} else {
|
|
set_bit(app->id, bitmap);
|
|
}
|
|
}
|
|
}
|
|
mutex_unlock(&of_mutex);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_alias_get_alias_list);
|
|
|
|
/**
|
|
* of_alias_get_highest_id - Get highest alias id for the given stem
|
|
* @stem: Alias stem to be examined
|
|
*
|
|
* The function travels the lookup table to get the highest alias id for the
|
|
* given alias stem. It returns the alias id if found.
|
|
*/
|
|
int of_alias_get_highest_id(const char *stem)
|
|
{
|
|
struct alias_prop *app;
|
|
int id = -ENODEV;
|
|
|
|
mutex_lock(&of_mutex);
|
|
list_for_each_entry(app, &aliases_lookup, link) {
|
|
if (strcmp(app->stem, stem) != 0)
|
|
continue;
|
|
|
|
if (app->id > id)
|
|
id = app->id;
|
|
}
|
|
mutex_unlock(&of_mutex);
|
|
|
|
return id;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_alias_get_highest_id);
|
|
|
|
/**
|
|
* of_console_check() - Test and setup console for DT setup
|
|
* @dn - Pointer to device node
|
|
* @name - Name to use for preferred console without index. ex. "ttyS"
|
|
* @index - Index to use for preferred console.
|
|
*
|
|
* Check if the given device node matches the stdout-path property in the
|
|
* /chosen node. If it does then register it as the preferred console and return
|
|
* TRUE. Otherwise return FALSE.
|
|
*/
|
|
bool of_console_check(struct device_node *dn, char *name, int index)
|
|
{
|
|
if (!dn || dn != of_stdout || console_set_on_cmdline)
|
|
return false;
|
|
|
|
/*
|
|
* XXX: cast `options' to char pointer to suppress complication
|
|
* warnings: printk, UART and console drivers expect char pointer.
|
|
*/
|
|
return !add_preferred_console(name, index, (char *)of_stdout_options);
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_console_check);
|
|
|
|
/**
|
|
* of_find_next_cache_node - Find a node's subsidiary cache
|
|
* @np: node of type "cpu" or "cache"
|
|
*
|
|
* Returns a node pointer with refcount incremented, use
|
|
* of_node_put() on it when done. Caller should hold a reference
|
|
* to np.
|
|
*/
|
|
struct device_node *of_find_next_cache_node(const struct device_node *np)
|
|
{
|
|
struct device_node *child, *cache_node;
|
|
|
|
cache_node = of_parse_phandle(np, "l2-cache", 0);
|
|
if (!cache_node)
|
|
cache_node = of_parse_phandle(np, "next-level-cache", 0);
|
|
|
|
if (cache_node)
|
|
return cache_node;
|
|
|
|
/* OF on pmac has nodes instead of properties named "l2-cache"
|
|
* beneath CPU nodes.
|
|
*/
|
|
if (IS_ENABLED(CONFIG_PPC_PMAC) && of_node_is_type(np, "cpu"))
|
|
for_each_child_of_node(np, child)
|
|
if (of_node_is_type(child, "cache"))
|
|
return child;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* of_find_last_cache_level - Find the level at which the last cache is
|
|
* present for the given logical cpu
|
|
*
|
|
* @cpu: cpu number(logical index) for which the last cache level is needed
|
|
*
|
|
* Returns the the level at which the last cache is present. It is exactly
|
|
* same as the total number of cache levels for the given logical cpu.
|
|
*/
|
|
int of_find_last_cache_level(unsigned int cpu)
|
|
{
|
|
u32 cache_level = 0;
|
|
struct device_node *prev = NULL, *np = of_cpu_device_node_get(cpu);
|
|
|
|
while (np) {
|
|
prev = np;
|
|
of_node_put(np);
|
|
np = of_find_next_cache_node(np);
|
|
}
|
|
|
|
of_property_read_u32(prev, "cache-level", &cache_level);
|
|
|
|
return cache_level;
|
|
}
|
|
|
|
/**
|
|
* of_map_id - Translate an ID through a downstream mapping.
|
|
* @np: root complex device node.
|
|
* @id: device ID to map.
|
|
* @map_name: property name of the map to use.
|
|
* @map_mask_name: optional property name of the mask to use.
|
|
* @target: optional pointer to a target device node.
|
|
* @id_out: optional pointer to receive the translated ID.
|
|
*
|
|
* Given a device ID, look up the appropriate implementation-defined
|
|
* platform ID and/or the target device which receives transactions on that
|
|
* ID, as per the "iommu-map" and "msi-map" bindings. Either of @target or
|
|
* @id_out may be NULL if only the other is required. If @target points to
|
|
* a non-NULL device node pointer, only entries targeting that node will be
|
|
* matched; if it points to a NULL value, it will receive the device node of
|
|
* the first matching target phandle, with a reference held.
|
|
*
|
|
* Return: 0 on success or a standard error code on failure.
|
|
*/
|
|
int of_map_id(struct device_node *np, u32 id,
|
|
const char *map_name, const char *map_mask_name,
|
|
struct device_node **target, u32 *id_out)
|
|
{
|
|
u32 map_mask, masked_id;
|
|
int map_len;
|
|
const __be32 *map = NULL;
|
|
|
|
if (!np || !map_name || (!target && !id_out))
|
|
return -EINVAL;
|
|
|
|
map = of_get_property(np, map_name, &map_len);
|
|
if (!map) {
|
|
if (target)
|
|
return -ENODEV;
|
|
/* Otherwise, no map implies no translation */
|
|
*id_out = id;
|
|
return 0;
|
|
}
|
|
|
|
if (!map_len || map_len % (4 * sizeof(*map))) {
|
|
pr_err("%pOF: Error: Bad %s length: %d\n", np,
|
|
map_name, map_len);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* The default is to select all bits. */
|
|
map_mask = 0xffffffff;
|
|
|
|
/*
|
|
* Can be overridden by "{iommu,msi}-map-mask" property.
|
|
* If of_property_read_u32() fails, the default is used.
|
|
*/
|
|
if (map_mask_name)
|
|
of_property_read_u32(np, map_mask_name, &map_mask);
|
|
|
|
masked_id = map_mask & id;
|
|
for ( ; map_len > 0; map_len -= 4 * sizeof(*map), map += 4) {
|
|
struct device_node *phandle_node;
|
|
u32 id_base = be32_to_cpup(map + 0);
|
|
u32 phandle = be32_to_cpup(map + 1);
|
|
u32 out_base = be32_to_cpup(map + 2);
|
|
u32 id_len = be32_to_cpup(map + 3);
|
|
|
|
if (id_base & ~map_mask) {
|
|
pr_err("%pOF: Invalid %s translation - %s-mask (0x%x) ignores id-base (0x%x)\n",
|
|
np, map_name, map_name,
|
|
map_mask, id_base);
|
|
return -EFAULT;
|
|
}
|
|
|
|
if (masked_id < id_base || masked_id >= id_base + id_len)
|
|
continue;
|
|
|
|
phandle_node = of_find_node_by_phandle(phandle);
|
|
if (!phandle_node)
|
|
return -ENODEV;
|
|
|
|
if (target) {
|
|
if (*target)
|
|
of_node_put(phandle_node);
|
|
else
|
|
*target = phandle_node;
|
|
|
|
if (*target != phandle_node)
|
|
continue;
|
|
}
|
|
|
|
if (id_out)
|
|
*id_out = masked_id - id_base + out_base;
|
|
|
|
pr_debug("%pOF: %s, using mask %08x, id-base: %08x, out-base: %08x, length: %08x, id: %08x -> %08x\n",
|
|
np, map_name, map_mask, id_base, out_base,
|
|
id_len, id, masked_id - id_base + out_base);
|
|
return 0;
|
|
}
|
|
|
|
pr_info("%pOF: no %s translation for id 0x%x on %pOF\n", np, map_name,
|
|
id, target && *target ? *target : NULL);
|
|
|
|
/* Bypasses translation */
|
|
if (id_out)
|
|
*id_out = id;
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_map_id);
|