Merge 4.19.207 into android-4.19-stable
Linux 4.19.207
s390/bpf: Fix 64-bit subtraction of the -0x80000000 constant
net: renesas: sh_eth: Fix freeing wrong tx descriptor
* ip_gre: validate csum_start only on pull
net/ipv4/ip_gre.c
qlcnic: Remove redundant unlock in qlcnic_pinit_from_rom
* fq_codel: reject silly quantum parameters
include/uapi/linux/pkt_sched.h
net/sched/sch_fq_codel.c
* netfilter: socket: icmp6: fix use-after-scope
net/ipv6/netfilter/nf_socket_ipv6.c
net: dsa: b53: Fix calculating number of switch ports
ARC: export clear_user_page() for modules
mtd: rawnand: cafe: Fix a resource leak in the error handling path of 'cafe_nand_probe()'
* PCI: Sync __pci_register_driver() stub for CONFIG_PCI=n
include/linux/pci.h
* KVM: arm64: Handle PSCI resets before userspace touches vCPU state
virt/kvm/arm/arm.c
* PCI: Fix pci_dev_str_match_path() alloc while atomic bug
drivers/pci/pci.c
mfd: axp20x: Update AXP288 volatile ranges
NTB: perf: Fix an error code in perf_setup_inbuf()
ethtool: Fix an error code in cxgb2.c
block, bfq: honor already-setup queue merges
net: usb: cdc_mbim: avoid altsetting toggling for Telit LN920
* PCI: Add ACS quirks for Cavium multi-function devices
drivers/pci/quirks.c
mfd: Don't use irq_create_mapping() to resolve a mapping
dt-bindings: mtd: gpmc: Fix the ECC bytes vs. OOB bytes equation
KVM: s390: index kvm->arch.idle_mask by vcpu_idx
* mm/memory_hotplug: use "unsigned long" for PFN in zone_for_pfn_range()
include/linux/memory_hotplug.h
mm/memory_hotplug.c
net: hns3: pad the short tunnel frame before sending to hardware
ibmvnic: check failover_pending in login response
qed: Handle management FW error
* tcp: fix tp->undo_retrans accounting in tcp_sacktag_one()
net/ipv4/tcp_input.c
* net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup
net/dsa/slave.c
* net/af_unix: fix a data-race in unix_dgram_poll
include/linux/skbuff.h
net/unix/af_unix.c
* events: Reuse value read using READ_ONCE instead of re-reading it
kernel/events/core.c
net/mlx5: Fix potential sleeping in atomic context
* perf machine: Initialize srcline string member in add_location struct
tools/perf/util/machine.c
* tipc: increase timeout in tipc_sk_enqueue()
net/tipc/socket.c
r6040: Restore MDIO clock frequency after MAC reset
* net/l2tp: Fix reference count leak in l2tp_udp_recv_core
net/l2tp/l2tp_core.c
* dccp: don't duplicate ccid when cloning dccp sock
net/dccp/minisocks.c
ptp: dp83640: don't define PAGE0
* net-caif: avoid user-triggerable WARN_ON(1)
net/caif/chnl_net.c
* tipc: fix an use-after-free issue in tipc_recvmsg
net/tipc/socket.c
x86/mm: Fix kern_addr_valid() to cope with existing but not present entries
* PCI: Add AMD GPU multi-function power dependencies
drivers/pci/quirks.c
PM: base: power: don't try to use non-existing RTC for storing data
* arm64/sve: Use correct size when reinitialising SVE state
arch/arm64/kernel/fpsimd.c
bnx2x: Fix enabling network interfaces without VFs
xen: reset legacy rtc flag for PV domU
dm thin metadata: Fix use-after-free in dm_bm_set_read_only
drm/amdgpu: Fix BUG_ON assert
platform/chrome: cros_ec_proto: Send command again when timeout occurs
* memcg: enable accounting for pids in nested pid namespaces
kernel/pid_namespace.c
* mm/hugetlb: initialize hugetlb_usage in mm_init
include/linux/hugetlb.h
kernel/fork.c
cpufreq: powernv: Fix init_chip_info initialization in numa=off
scsi: qla2xxx: Sync queue idx with queue_pair_map idx
scsi: BusLogic: Fix missing pr_cont() use
* ovl: fix BUG_ON() in may_delete() when called from ovl_cleanup()
fs/overlayfs/dir.c
parisc: fix crash with signals and alloca
net: w5100: check return value after calling platform_get_resource()
* net: fix NULL pointer reference in cipso_v4_doi_free
net/netlabel/netlabel_cipso_v4.c
ath9k: fix sleeping in atomic context
ath9k: fix OOB read ar9300_eeprom_restore_internal
parport: remove non-zero check on count
* ASoC: rockchip: i2s: Fixup config for DAIFMT_DSP_A/B
sound/soc/rockchip/rockchip_i2s.c
* ASoC: rockchip: i2s: Fix regmap_ops hang
sound/soc/rockchip/rockchip_i2s.c
usbip:vhci_hcd USB port can get stuck in the disabled state
usbip: give back URBs for unsent unlink requests during cleanup
usb: musb: musb_dsps: request_irq() after initializing musb
* Revert "USB: xhci: fix U1/U2 handling for hardware with XHCI_INTEL_HOST quirk set"
drivers/usb/host/xhci.c
* cifs: fix wrong release in sess_alloc_buffer() failed path
fs/cifs/sess.c
mmc: core: Return correct emmc response in case of ioctl error
* selftests/bpf: Enlarge select() timeout for test_maps
tools/testing/selftests/bpf/test_maps.c
mmc: rtsx_pci: Fix long reads when clock is prescaled
mmc: sdhci-of-arasan: Check return value of non-void funtions
* of: Don't allow __of_attached_node_sysfs() without CONFIG_SYSFS
drivers/of/kobj.c
* gfs2: Don't call dlm after protocol is unmounted
fs/gfs2/lock_dlm.c
staging: rts5208: Fix get_ms_information() heap buffer size
* rpc: fix gss_svc_init cleanup on failure
net/sunrpc/auth_gss/svcauth_gss.c
* tcp: enable data-less, empty-cookie SYN with TFO_SERVER_COOKIE_NOT_REQD
net/ipv4/tcp_fastopen.c
serial: sh-sci: fix break handling for sysrq
* Bluetooth: Fix handling of LE Enhanced Connection Complete
net/bluetooth/hci_event.c
ARM: tegra: tamonten: Fix UART pad setting
gpu: drm: amd: amdgpu: amdgpu_i2c: fix possible uninitialized-variable access in amdgpu_i2c_router_select_ddc_port()
* Bluetooth: avoid circular locks in sco_sock_connect
net/bluetooth/sco.c
* Bluetooth: schedule SCO timeouts with delayed_work
net/bluetooth/sco.c
net: ethernet: stmmac: Do not use unreachable() in ipq806x_gmac_probe()
arm64: dts: qcom: sdm660: use reg value for memory node
ARM: dts: imx53-ppd: Fix ACHC entry
media: tegra-cec: Handle errors of clk_prepare_enable()
media: TDA1997x: fix tda1997x_query_dv_timings() return value
* media: v4l2-dv-timings.c: fix wrong condition in two for-loops
drivers/media/v4l2-core/v4l2-dv-timings.c
media: imx258: Limit the max analogue gain to 480
media: imx258: Rectify mismatch of VTS value
* ASoC: Intel: bytcr_rt5640: Move "Platform Clock" routes to the maps for the matching in-/output
sound/soc/intel/boards/bytcr_rt5640.c
* bonding: 3ad: fix the concurrency between __bond_release_one() and bond_3ad_state_machine_handler()
drivers/net/bonding/bond_main.c
* Bluetooth: skip invalid hci_sync_conn_complete_evt
net/bluetooth/hci_event.c
ata: sata_dwc_460ex: No need to call phy_exit() befre phy_init()
* samples: bpf: Fix tracex7 error raised on the missing argument
samples/bpf/test_override_return.sh
samples/bpf/tracex7_user.c
staging: ks7010: Fix the initialization of the 'sleep_status' structure
serial: 8250_pci: make setup_port() parameters explicitly unsigned
hvsi: don't panic on tty_register_driver failure
xtensa: ISS: don't panic in rs_init
* serial: 8250: Define RX trigger levels for OxSemi 950 devices
include/uapi/linux/serial_reg.h
s390/jump_label: print real address in a case of a jump label bug
* flow_dissector: Fix out-of-bounds warnings
net/core/flow_dissector.c
* ipv4: ip_output.c: Fix out-of-bounds warning in ip_copy_addrs()
net/ipv4/ip_output.c
video: fbdev: riva: Error out if 'pixclock' equals zero
video: fbdev: kyro: Error out if 'pixclock' equals zero
video: fbdev: asiliantfb: Error out if 'pixclock' equals zero
* bpf/tests: Do not PASS tests without actually testing the result
lib/test_bpf.c
* bpf/tests: Fix copy-and-paste error in double word test
lib/test_bpf.c
drm/amd/amdgpu: Update debugfs link_settings output link_rate field in hex
tty: serial: jsm: hold port lock when reporting modem line changes
staging: board: Fix uninitialized spinlock when attaching genpd
* usb: gadget: composite: Allow bMaxPower=0 if self-powered
drivers/usb/gadget/composite.c
* usb: gadget: u_ether: fix a potential null pointer dereference
drivers/usb/gadget/function/u_ether.c
usb: host: fotg210: fix the actual_length of an iso packet
usb: host: fotg210: fix the endpoint's transactional opportunities calculation
* Smack: Fix wrong semantics in smk_access_entry()
security/smack/smack_access.c
* netlink: Deal with ESRCH error in nlmsg_notify()
net/netlink/af_netlink.c
video: fbdev: kyro: fix a DoS bug by restricting user input
ARM: dts: qcom: apq8064: correct clock names
iio: dac: ad5624r: Fix incorrect handling of an optional regulator.
* tipc: keep the skb in rcv queue until the whole data is read
net/tipc/socket.c
* PCI: Use pci_update_current_state() in pci_enable_device_flags()
drivers/pci/pci.c
crypto: mxs-dcp - Use sg_mapping_iter to copy data
media: dib8000: rewrite the init prbs logic
* userfaultfd: prevent concurrent API initialization
fs/userfaultfd.c
MIPS: Malta: fix alignment of the devicetree buffer
* f2fs: fix to unmap pages from userspace process in punch_hole()
fs/f2fs/file.c
* f2fs: fix to account missing .skipped_gc_rwsem
fs/f2fs/gc.c
* fscache: Fix cookie key hashing
fs/fscache/cookie.c
fs/fscache/internal.h
fs/fscache/main.c
platform/x86: dell-smbios-wmi: Add missing kfree in error-exit from run_smbios_call
scsi: qedi: Fix error codes in qedi_alloc_global_queues()
pinctrl: single: Fix error return code in pcs_parse_bits_in_pinctrl_entry()
openrisc: don't printk() unconditionally
powerpc/stacktrace: Include linux/delay.h
* vfio: Use config not menuconfig for VFIO_NOIOMMU
drivers/vfio/Kconfig
pinctrl: samsung: Fix pinctrl bank pin count
docs: Fix infiniband uverbs minor number
RDMA/iwcm: Release resources if iw_cm module initialization fails
* HID: input: do not report stylus battery state as "full"
drivers/hid/hid-input.c
PCI: aardvark: Fix masking and unmasking legacy INTx interrupts
PCI: aardvark: Increase polling delay to 1.5s while waiting for PIO response
PCI: xilinx-nwl: Enable the clock through CCF
* PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure
drivers/pci/syscall.c
* PCI: Restrict ASMedia ASM1062 SATA Max Payload Size Supported
drivers/pci/quirks.c
ARM: 9105/1: atags_to_fdt: don't warn about stack size
libata: add ATA_HORKAGE_NO_NCQ_TRIM for Samsung 860 and 870 SSDs
media: rc-loopback: return number of emitters rather than error
media: uvc: don't do DMA on stack
VMCI: fix NULL pointer dereference when unmapping queue pair
dm crypt: Avoid percpu_counter spinlock contention in crypt_page_alloc()
power: supply: max17042: handle fails of reading status register
block: bfq: fix bfq_set_next_ioprio_data()
* crypto: public_key: fix overflow during implicit conversion
include/crypto/public_key.h
* arm64: head: avoid over-mapping in map_memory
arch/arm64/include/asm/kernel-pgtable.h
arch/arm64/kernel/head.S
soc: aspeed: lpc-ctrl: Fix boundary check for mmap
* tools/thermal/tmon: Add cross compiling support
tools/thermal/tmon/Makefile
* bpf: Fix pointer arithmetic mask tightening under state pruning
include/linux/bpf_verifier.h
kernel/bpf/verifier.c
* bpf: verifier: Allocate idmap scratch in verifier env
include/linux/bpf_verifier.h
kernel/bpf/verifier.c
* bpf: Fix leakage due to insufficient speculative store bypass mitigation
include/linux/bpf_verifier.h
kernel/bpf/verifier.c
* bpf: Introduce BPF nospec instruction for mitigating Spectre v4
arch/arm64/net/bpf_jit_comp.c
include/linux/filter.h
kernel/bpf/core.c
kernel/bpf/disasm.c
* selftests/bpf: fix tests due to const spill/fill
tools/testing/selftests/bpf/test_verifier.c
* bpf: track spill/fill of constants
kernel/bpf/verifier.c
* selftests/bpf: Test variable offset stack access
tools/testing/selftests/bpf/test_verifier.c
* bpf: Sanity check max value for var_off stack access
kernel/bpf/verifier.c
* bpf: Reject indirect var_off stack access in unpriv mode
kernel/bpf/verifier.c
* bpf: Reject indirect var_off stack access in raw mode
kernel/bpf/verifier.c
* bpf: Support variable offset stack access from helpers
kernel/bpf/verifier.c
* bpf: correct slot_type marking logic to allow more stack slot sharing
kernel/bpf/verifier.c
tools/testing/selftests/bpf/test_verifier.c
* bpf/verifier: per-register parent pointers
include/linux/bpf_verifier.h
kernel/bpf/verifier.c
* 9p/xen: Fix end of loop tests for list_for_each_entry
net/9p/trans_xen.c
* include/linux/list.h: add a macro to test if entry is pointing to the head
include/linux/list.h
xen: fix setting of max_pfn in shared_info
powerpc/perf/hv-gpci: Fix counter value parsing
* PCI/MSI: Skip masking MSI-X on Xen PV
drivers/pci/msi.c
blk-zoned: allow BLKREPORTZONE without CAP_SYS_ADMIN
blk-zoned: allow zone management send operations without CAP_SYS_ADMIN
btrfs: reset replace target device to allocation state on close
rtc: tps65910: Correct driver module alias
clk: kirkwood: Fix a clocking boot regression
backlight: pwm_bl: Improve bootloader/kernel device handover
fbmem: don't allow too huge resolutions
* IMA: remove the dependency on CRYPTO_MD5
security/integrity/ima/Kconfig
* IMA: remove -Wmissing-prototypes warning
security/integrity/ima/ima_mok.c
KVM: x86: Update vCPU's hv_clock before back to guest when tsc_offset is adjusted
x86/resctrl: Fix a maybe-uninitialized build warning treated as error
* tty: Fix data race between tiocsti() and flush_to_ldisc()
drivers/tty/tty_io.c
* ubifs: report correct st_size for encrypted symlinks
fs/ubifs/file.c
* f2fs: report correct st_size for encrypted symlinks
fs/f2fs/namei.c
* ext4: report correct st_size for encrypted symlinks
fs/ext4/symlink.c
* fscrypt: add fscrypt_symlink_getattr() for computing st_size
fs/crypto/hooks.c
* netns: protect netns ID lookups with RCU
net/core/net_namespace.c
* ipv4: fix endianness issue in inet_rtm_getroute_build_skb()
net/ipv4/route.c
net: qualcomm: fix QCA7000 checksum handling
* net: sched: Fix qdisc_rate_table refcount leak when get tcf_block failed
net/sched/sch_cbq.c
* ipv4: make exception cache less predictible
net/ipv4/route.c
bcma: Fix memory leak for internally-handled cores
ath6kl: wmi: fix an error code in ath6kl_wmi_sync_point()
tty: serial: fsl_lpuart: fix the wrong mapbase value
usb: bdc: Fix an error handling path in 'bdc_probe()' when no suitable DMA config is available
usb: ehci-orion: Handle errors of clk_prepare_enable() in probe
i2c: mt65xx: fix IRQ check
* CIFS: Fix a potencially linear read overflow
fs/cifs/cifs_unicode.c
mmc: moxart: Fix issue with uninitialized dma_slave_config
mmc: dw_mmc: Fix issue with uninitialized dma_slave_config
i2c: s3c2410: fix IRQ check
i2c: iop3xx: fix deferred probing
* Bluetooth: add timeout sanity check to hci_inquiry
net/bluetooth/hci_core.c
usb: gadget: mv_u3d: request_irq() after initializing UDC
* mac80211: Fix insufficient headroom issue for AMSDU
net/mac80211/tx.c
usb: phy: tahvo: add IRQ check
usb: host: ohci-tmio: add IRQ check
* Bluetooth: Move shutdown callback before flushing tx and rx queue
net/bluetooth/hci_core.c
usb: phy: twl6030: add IRQ checks
usb: phy: fsl-usb: add IRQ check
usb: gadget: udc: at91: add IRQ check
drm/msm/dsi: Fix some reference counted resource leaks
* Bluetooth: fix repeated calls to sco_sock_kill
net/bluetooth/sco.c
arm64: dts: exynos: correct GIC CPU interfaces address range on Exynos7
drm/msm/dpu: make dpu_hw_ctl_clear_all_blendstages clear necessary LMs
* Bluetooth: increase BTNAMSIZ to 21 chars to fix potential buffer overflow
net/bluetooth/cmtp/cmtp.h
soc: qcom: smsm: Fix missed interrupts if state changes while masked
* PCI: PM: Enable PME if it can be signaled from D3cold
drivers/pci/pci.c
* PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently
drivers/pci/pci.c
media: venus: venc: Fix potential null pointer dereference on pointer fmt
media: em28xx-input: fix refcount bug in em28xx_usb_disconnect
i2c: highlander: add IRQ check
* net: cipso: fix warnings in netlbl_cipsov4_add_std
net/netlabel/netlabel_cipso_v4.c
* tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos
net/ipv4/tcp_ipv4.c
* Bluetooth: sco: prevent information leak in sco_conn_defer_accept()
net/bluetooth/sco.c
media: go7007: remove redundant initialization
media: dvb-usb: fix uninit-value in vp702x_read_mac_addr
media: dvb-usb: fix uninit-value in dvb_usb_adapter_dvb_init
* soc: rockchip: ROCKCHIP_GRF should not default to y, unconditionally
drivers/soc/rockchip/Kconfig
media: TDA1997x: enable EDID support
spi: sprd: Fix the wrong WDG_LOAD_VAL
* certs: Trigger creation of RSA module signing key if it's not an RSA key
certs/Makefile
crypto: qat - use proper type for vf_mask
clocksource/drivers/sh_cmt: Fix wrong setting if don't request IRQ for clock source channel
* lib/mpi: use kcalloc in mpi_resize
lib/mpi/mpiutil.c
spi: spi-pic32: Fix issue with uninitialized dma_slave_config
spi: spi-fsl-dspi: Fix issue with uninitialized dma_slave_config
m68k: emu: Fix invalid free in nfeth_cleanup()
* udf_get_extendedattr() had no boundary checks.
fs/udf/misc.c
* fcntl: fix potential deadlock for &fasync_struct.fa_lock
fs/fcntl.c
crypto: qat - do not export adf_iov_putmsg()
crypto: qat - fix naming for init/shutdown VF to PF notifications
crypto: qat - fix reuse of completion variable
crypto: qat - handle both source of interrupt in VF ISR
crypto: qat - do not ignore errors from enable_vf2pf_comms()
libata: fix ata_host_start()
s390/cio: add dev_busid sysfs entry for each subchannel
* power: supply: max17042_battery: fix typo in MAx17042_TOFF
include/linux/power/max17042_battery.h
nvme-rdma: don't update queue count when failing to set io queues
bcache: add proper error unwinding in bcache_device_init
* isofs: joliet: Fix iocharset=utf8 mount option
fs/isofs/inode.c
fs/isofs/isofs.h
fs/isofs/joliet.c
* udf: Check LVID earlier
fs/udf/super.c
* hrtimer: Avoid double reprogramming in __hrtimer_start_range_ns()
kernel/time/hrtimer.c
* sched/deadline: Fix missing clock update in migrate_task_rq_dl()
kernel/sched/deadline.c
crypto: omap-sham - clear dma flags only after omap_sham_update_dma_stop()
power: supply: axp288_fuel_gauge: Report register-address on readb / writeb errors
* sched/deadline: Fix reset_on_fork reporting of DL tasks
kernel/sched/deadline.c
kernel/sched/sched.h
crypto: mxs-dcp - Check for DMA mapping errors
* regmap: fix the offset of register error log
drivers/base/regmap/regmap.c
* locking/mutex: Fix HANDOFF condition
kernel/locking/mutex.c
* PCI: Call Max Payload Size-related fixup quirks early
drivers/pci/quirks.c
x86/reboot: Limit Dell Optiplex 990 quirk to early BIOS versions
usb: mtu3: fix the wrong HS mult value
usb: mtu3: use @mult for HS isoc or intr
usb: host: xhci-rcar: Don't reload firmware after the completion
* ALSA: usb-audio: Add registration quirk for JBL Quantum 800
sound/usb/quirks.c
Revert "btrfs: compression: don't try to compress if we don't have enough pages"
* mm/page_alloc: speed up the iteration of max_order
mm/page_alloc.c
net: ll_temac: Remove left-over debug message
powerpc/boot: Delete unneeded .globl _zimage_start
powerpc/module64: Fix comment in R_PPC64_ENTRY handling
crypto: talitos - reduce max key size for SEC1
* SUNRPC/nfs: Fix return value for nfs4_callback_compound()
fs/nfs/callback_xdr.c
include/linux/sunrpc/svc.h
net/sunrpc/svc.c
* ipv4/icmp: l3mdev: Perform icmp error route lookup on source device routing table (v2)
net/ipv4/icmp.c
USB: serial: mos7720: improve OOM-handling in read_mos_reg()
* igmp: Add ip_mc_list lock in ip_check_mc_rcu
net/ipv4/igmp.c
ARM: imx: fix missing 3rd argument in macro imx_mmdc_perf_init
ARM: imx: add missing clk_disable_unprepare()
media: stkwebcam: fix memory leak in stk_camera_probe
* clk: fix build warning for orphan_list
drivers/clk/clk.c
* ALSA: pcm: fix divide error in snd_pcm_lib_ioctl
sound/core/pcm_lib.c
ARM: 8918/2: only build return_address() if needed
* cryptoloop: add a deprecation warning
drivers/block/Kconfig
perf/x86/amd/ibs: Work around erratum #1197
perf/x86/intel/pt: Fix mask of num_address_ranges
qede: Fix memset corruption
net: macb: Add a NULL check on desc_ptp
qed: Fix the VF msix vectors flow
gpu: ipu-v3: Fix i.MX IPU-v3 offset calculations for (semi)planar U/V formats
xtensa: fix kconfig unmet dependency warning for HAVE_FUTEX_CMPXCHG
* ext4: fix race writing to an inline_data file while its xattrs are changing
fs/ext4/inline.c
Merge 4.19.206 into android-4.19-stable
Linux 4.19.206
* net: don't unconditionally copy_from_user a struct ifreq for socket ioctls
include/linux/netdevice.h
net/socket.c
Revert "floppy: reintroduce O_NDELAY fix"
KVM: x86/mmu: Treat NX as used (not reserved) for all !TDP shadow MMUs
fbmem: add margin check to fb_check_caps()
vt_kdsetmode: extend console locking
* net/rds: dma_map_sg is entitled to merge entries
net/rds/ib_frmr.c
drm/nouveau/disp: power down unused DP links during init
* drm: Copy drm_wait_vblank to user before returning
drivers/gpu/drm/drm_ioc32.c
qed: Fix null-pointer dereference in qed_rdma_create_qp()
qed: qed ll2 race condition fixes
vringh: Use wiov->used to check for read/write desc order
virtio_pci: Support surprise removal of virtio pci device
virtio: Improve vq->broken access to avoid any compiler optimization
* opp: remove WARN when no valid OPPs remain
drivers/opp/of.c
usb: gadget: u_audio: fix race condition on endpoint stop
net: hns3: fix get wrong pfc_en when query PFC configuration
net: marvell: fix MVNETA_TX_IN_PRGRS bit number
xgene-v2: Fix a resource leak in the error handling path of 'xge_probe()'
* ip_gre: add validation for csum_start
net/ipv4/ip_gre.c
e1000e: Fix the max snoop/no-snoop latency for 10M
IB/hfi1: Fix possible null-pointer dereference in _extend_sdma_tx_descs()
* usb: dwc3: gadget: Stop EP0 transfers during pullup disable
drivers/usb/dwc3/gadget.c
* usb: dwc3: gadget: Fix dwc3_calc_trbs_left()
drivers/usb/dwc3/gadget.c
USB: serial: option: add new VID/PID to support Fibocom FG150
Revert "USB: serial: ch341: fix character loss at high transfer rates"
can: usb: esd_usb2: esd_usb2_rx_event(): fix the interchange of the CAN RX and TX error counters
* once: Fix panic when module unload
include/linux/once.h
lib/once.c
* netfilter: conntrack: collect all entries in one cycle
net/netfilter/nf_conntrack_core.c
ARC: Fix CONFIG_STACKDEPOT
* bpf: Fix truncation handling for mod32 dst reg wrt zero
kernel/bpf/verifier.c
* bpf: Fix 32 bit src register truncation on div/mod
include/linux/filter.h
kernel/bpf/verifier.c
* bpf: Do not use ax register in interpreter on div/mod
kernel/bpf/core.c
* net: qrtr: fix another OOB Read in qrtr_endpoint_post
net/qrtr/qrtr.c
Bug: 201722185
Change-Id: Ib431fe52b39577bd49f14f4b28c49b54fa247c54
Signed-off-by: Wilson Sung <wilsonsung@google.com>
953 lines
25 KiB
C
953 lines
25 KiB
C
/*
|
|
* Generic OPP OF helpers
|
|
*
|
|
* Copyright (C) 2009-2010 Texas Instruments Incorporated.
|
|
* Nishanth Menon
|
|
* Romit Dasgupta
|
|
* Kevin Hilman
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/cpu.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/device.h>
|
|
#include <linux/of_device.h>
|
|
#include <linux/pm_domain.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/export.h>
|
|
#include <linux/energy_model.h>
|
|
|
|
#include "opp.h"
|
|
|
|
static struct opp_table *_managed_opp(const struct device_node *np)
|
|
{
|
|
struct opp_table *opp_table, *managed_table = NULL;
|
|
|
|
mutex_lock(&opp_table_lock);
|
|
|
|
list_for_each_entry(opp_table, &opp_tables, node) {
|
|
if (opp_table->np == np) {
|
|
/*
|
|
* Multiple devices can point to the same OPP table and
|
|
* so will have same node-pointer, np.
|
|
*
|
|
* But the OPPs will be considered as shared only if the
|
|
* OPP table contains a "opp-shared" property.
|
|
*/
|
|
if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) {
|
|
_get_opp_table_kref(opp_table);
|
|
managed_table = opp_table;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
mutex_unlock(&opp_table_lock);
|
|
|
|
return managed_table;
|
|
}
|
|
|
|
void _of_init_opp_table(struct opp_table *opp_table, struct device *dev)
|
|
{
|
|
struct device_node *np;
|
|
|
|
/*
|
|
* Only required for backward compatibility with v1 bindings, but isn't
|
|
* harmful for other cases. And so we do it unconditionally.
|
|
*/
|
|
np = of_node_get(dev->of_node);
|
|
if (np) {
|
|
u32 val;
|
|
|
|
if (!of_property_read_u32(np, "clock-latency", &val))
|
|
opp_table->clock_latency_ns_max = val;
|
|
of_property_read_u32(np, "voltage-tolerance",
|
|
&opp_table->voltage_tolerance_v1);
|
|
of_node_put(np);
|
|
}
|
|
}
|
|
|
|
static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,
|
|
struct device_node *np)
|
|
{
|
|
unsigned int count = opp_table->supported_hw_count;
|
|
u32 version;
|
|
int ret;
|
|
|
|
if (!opp_table->supported_hw) {
|
|
/*
|
|
* In the case that no supported_hw has been set by the
|
|
* platform but there is an opp-supported-hw value set for
|
|
* an OPP then the OPP should not be enabled as there is
|
|
* no way to see if the hardware supports it.
|
|
*/
|
|
if (of_find_property(np, "opp-supported-hw", NULL))
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
while (count--) {
|
|
ret = of_property_read_u32_index(np, "opp-supported-hw", count,
|
|
&version);
|
|
if (ret) {
|
|
dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n",
|
|
__func__, count, ret);
|
|
return false;
|
|
}
|
|
|
|
/* Both of these are bitwise masks of the versions */
|
|
if (!(version & opp_table->supported_hw[count]))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
|
|
struct opp_table *opp_table)
|
|
{
|
|
u32 *microvolt, *microamp = NULL;
|
|
int supplies = opp_table->regulator_count, vcount, icount, ret, i, j;
|
|
struct property *prop = NULL;
|
|
char name[NAME_MAX];
|
|
|
|
/* Search for "opp-microvolt-<name>" */
|
|
if (opp_table->prop_name) {
|
|
snprintf(name, sizeof(name), "opp-microvolt-%s",
|
|
opp_table->prop_name);
|
|
prop = of_find_property(opp->np, name, NULL);
|
|
}
|
|
|
|
if (!prop) {
|
|
/* Search for "opp-microvolt" */
|
|
sprintf(name, "opp-microvolt");
|
|
prop = of_find_property(opp->np, name, NULL);
|
|
|
|
/* Missing property isn't a problem, but an invalid entry is */
|
|
if (!prop) {
|
|
if (unlikely(supplies == -1)) {
|
|
/* Initialize regulator_count */
|
|
opp_table->regulator_count = 0;
|
|
return 0;
|
|
}
|
|
|
|
if (!supplies)
|
|
return 0;
|
|
|
|
dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n",
|
|
__func__);
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
if (unlikely(supplies == -1)) {
|
|
/* Initialize regulator_count */
|
|
supplies = opp_table->regulator_count = 1;
|
|
} else if (unlikely(!supplies)) {
|
|
dev_err(dev, "%s: opp-microvolt wasn't expected\n", __func__);
|
|
return -EINVAL;
|
|
}
|
|
|
|
vcount = of_property_count_u32_elems(opp->np, name);
|
|
if (vcount < 0) {
|
|
dev_err(dev, "%s: Invalid %s property (%d)\n",
|
|
__func__, name, vcount);
|
|
return vcount;
|
|
}
|
|
|
|
/* There can be one or three elements per supply */
|
|
if (vcount != supplies && vcount != supplies * 3) {
|
|
dev_err(dev, "%s: Invalid number of elements in %s property (%d) with supplies (%d)\n",
|
|
__func__, name, vcount, supplies);
|
|
return -EINVAL;
|
|
}
|
|
|
|
microvolt = kmalloc_array(vcount, sizeof(*microvolt), GFP_KERNEL);
|
|
if (!microvolt)
|
|
return -ENOMEM;
|
|
|
|
ret = of_property_read_u32_array(opp->np, name, microvolt, vcount);
|
|
if (ret) {
|
|
dev_err(dev, "%s: error parsing %s: %d\n", __func__, name, ret);
|
|
ret = -EINVAL;
|
|
goto free_microvolt;
|
|
}
|
|
|
|
/* Search for "opp-microamp-<name>" */
|
|
prop = NULL;
|
|
if (opp_table->prop_name) {
|
|
snprintf(name, sizeof(name), "opp-microamp-%s",
|
|
opp_table->prop_name);
|
|
prop = of_find_property(opp->np, name, NULL);
|
|
}
|
|
|
|
if (!prop) {
|
|
/* Search for "opp-microamp" */
|
|
sprintf(name, "opp-microamp");
|
|
prop = of_find_property(opp->np, name, NULL);
|
|
}
|
|
|
|
if (prop) {
|
|
icount = of_property_count_u32_elems(opp->np, name);
|
|
if (icount < 0) {
|
|
dev_err(dev, "%s: Invalid %s property (%d)\n", __func__,
|
|
name, icount);
|
|
ret = icount;
|
|
goto free_microvolt;
|
|
}
|
|
|
|
if (icount != supplies) {
|
|
dev_err(dev, "%s: Invalid number of elements in %s property (%d) with supplies (%d)\n",
|
|
__func__, name, icount, supplies);
|
|
ret = -EINVAL;
|
|
goto free_microvolt;
|
|
}
|
|
|
|
microamp = kmalloc_array(icount, sizeof(*microamp), GFP_KERNEL);
|
|
if (!microamp) {
|
|
ret = -EINVAL;
|
|
goto free_microvolt;
|
|
}
|
|
|
|
ret = of_property_read_u32_array(opp->np, name, microamp,
|
|
icount);
|
|
if (ret) {
|
|
dev_err(dev, "%s: error parsing %s: %d\n", __func__,
|
|
name, ret);
|
|
ret = -EINVAL;
|
|
goto free_microamp;
|
|
}
|
|
}
|
|
|
|
for (i = 0, j = 0; i < supplies; i++) {
|
|
opp->supplies[i].u_volt = microvolt[j++];
|
|
|
|
if (vcount == supplies) {
|
|
opp->supplies[i].u_volt_min = opp->supplies[i].u_volt;
|
|
opp->supplies[i].u_volt_max = opp->supplies[i].u_volt;
|
|
} else {
|
|
opp->supplies[i].u_volt_min = microvolt[j++];
|
|
opp->supplies[i].u_volt_max = microvolt[j++];
|
|
}
|
|
|
|
if (microamp)
|
|
opp->supplies[i].u_amp = microamp[i];
|
|
}
|
|
|
|
free_microamp:
|
|
kfree(microamp);
|
|
free_microvolt:
|
|
kfree(microvolt);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
|
|
* entries
|
|
* @dev: device pointer used to lookup OPP table.
|
|
*
|
|
* Free OPPs created using static entries present in DT.
|
|
*/
|
|
void dev_pm_opp_of_remove_table(struct device *dev)
|
|
{
|
|
_dev_pm_opp_find_and_remove_table(dev, false);
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
|
|
|
|
/* Returns opp descriptor node for a device node, caller must
|
|
* do of_node_put() */
|
|
static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np,
|
|
int index)
|
|
{
|
|
/* "operating-points-v2" can be an array for power domain providers */
|
|
return of_parse_phandle(np, "operating-points-v2", index);
|
|
}
|
|
|
|
/* Returns opp descriptor node for a device, caller must do of_node_put() */
|
|
struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
|
|
{
|
|
return _opp_of_get_opp_desc_node(dev->of_node, 0);
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node);
|
|
|
|
/**
|
|
* _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
|
|
* @opp_table: OPP table
|
|
* @dev: device for which we do this operation
|
|
* @np: device node
|
|
*
|
|
* This function adds an opp definition to the opp table and returns status. The
|
|
* opp can be controlled using dev_pm_opp_enable/disable functions and may be
|
|
* removed by dev_pm_opp_remove.
|
|
*
|
|
* Return:
|
|
* 0 On success OR
|
|
* Duplicate OPPs (both freq and volt are same) and opp->available
|
|
* -EEXIST Freq are same and volt are different OR
|
|
* Duplicate OPPs (both freq and volt are same) and !opp->available
|
|
* -ENOMEM Memory allocation failure
|
|
* -EINVAL Failed parsing the OPP node
|
|
*/
|
|
static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
|
|
struct device_node *np)
|
|
{
|
|
struct dev_pm_opp *new_opp;
|
|
u64 rate = 0;
|
|
u32 val;
|
|
int ret;
|
|
bool rate_not_available = false;
|
|
|
|
new_opp = _opp_allocate(opp_table);
|
|
if (!new_opp)
|
|
return -ENOMEM;
|
|
|
|
ret = of_property_read_u64(np, "opp-hz", &rate);
|
|
if (ret < 0) {
|
|
/* "opp-hz" is optional for devices like power domains. */
|
|
if (!of_find_property(dev->of_node, "#power-domain-cells",
|
|
NULL)) {
|
|
dev_err(dev, "%s: opp-hz not found\n", __func__);
|
|
goto free_opp;
|
|
}
|
|
|
|
rate_not_available = true;
|
|
} else {
|
|
/*
|
|
* Rate is defined as an unsigned long in clk API, and so
|
|
* casting explicitly to its type. Must be fixed once rate is 64
|
|
* bit guaranteed in clk API.
|
|
*/
|
|
new_opp->rate = (unsigned long)rate;
|
|
}
|
|
|
|
/* Check if the OPP supports hardware's hierarchy of versions or not */
|
|
if (!_opp_is_supported(dev, opp_table, np)) {
|
|
dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate);
|
|
goto free_opp;
|
|
}
|
|
|
|
new_opp->turbo = of_property_read_bool(np, "turbo-mode");
|
|
|
|
new_opp->np = np;
|
|
new_opp->dynamic = false;
|
|
new_opp->available = true;
|
|
|
|
if (!of_property_read_u32(np, "clock-latency-ns", &val))
|
|
new_opp->clock_latency_ns = val;
|
|
|
|
new_opp->pstate = of_genpd_opp_to_performance_state(dev, np);
|
|
|
|
ret = opp_parse_supplies(new_opp, dev, opp_table);
|
|
if (ret)
|
|
goto free_opp;
|
|
|
|
ret = _opp_add(dev, new_opp, opp_table, rate_not_available);
|
|
if (ret) {
|
|
/* Don't return error for duplicate OPPs */
|
|
if (ret == -EBUSY)
|
|
ret = 0;
|
|
goto free_opp;
|
|
}
|
|
|
|
/* OPP to select on device suspend */
|
|
if (of_property_read_bool(np, "opp-suspend")) {
|
|
if (opp_table->suspend_opp) {
|
|
dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n",
|
|
__func__, opp_table->suspend_opp->rate,
|
|
new_opp->rate);
|
|
} else {
|
|
new_opp->suspend = true;
|
|
opp_table->suspend_opp = new_opp;
|
|
}
|
|
}
|
|
|
|
if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max)
|
|
opp_table->clock_latency_ns_max = new_opp->clock_latency_ns;
|
|
|
|
pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n",
|
|
__func__, new_opp->turbo, new_opp->rate,
|
|
new_opp->supplies[0].u_volt, new_opp->supplies[0].u_volt_min,
|
|
new_opp->supplies[0].u_volt_max, new_opp->clock_latency_ns);
|
|
|
|
/*
|
|
* Notify the changes in the availability of the operable
|
|
* frequency/voltage list.
|
|
*/
|
|
blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp);
|
|
return 0;
|
|
|
|
free_opp:
|
|
_opp_free(new_opp);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* Initializes OPP tables based on new bindings */
|
|
static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
|
|
{
|
|
struct device_node *np;
|
|
struct opp_table *opp_table;
|
|
int ret = 0, count = 0, pstate_count = 0;
|
|
struct dev_pm_opp *opp;
|
|
|
|
opp_table = _managed_opp(opp_np);
|
|
if (opp_table) {
|
|
/* OPPs are already managed */
|
|
if (!_add_opp_dev(dev, opp_table))
|
|
ret = -ENOMEM;
|
|
goto put_opp_table;
|
|
}
|
|
|
|
opp_table = dev_pm_opp_get_opp_table(dev);
|
|
if (!opp_table)
|
|
return -ENOMEM;
|
|
|
|
/* We have opp-table node now, iterate over it and add OPPs */
|
|
for_each_available_child_of_node(opp_np, np) {
|
|
count++;
|
|
|
|
ret = _opp_add_static_v2(opp_table, dev, np);
|
|
if (ret) {
|
|
dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
|
|
ret);
|
|
_dev_pm_opp_remove_table(opp_table, dev, false);
|
|
of_node_put(np);
|
|
goto put_opp_table;
|
|
}
|
|
}
|
|
|
|
/* There should be one or more OPPs defined */
|
|
if (!count) {
|
|
dev_err(dev, "%s: no supported OPPs", __func__);
|
|
ret = -ENOENT;
|
|
goto put_opp_table;
|
|
}
|
|
|
|
list_for_each_entry(opp, &opp_table->opp_list, node)
|
|
pstate_count += !!opp->pstate;
|
|
|
|
/* Either all or none of the nodes shall have performance state set */
|
|
if (pstate_count && pstate_count != count) {
|
|
dev_err(dev, "Not all nodes have performance state set (%d: %d)\n",
|
|
count, pstate_count);
|
|
ret = -ENOENT;
|
|
_dev_pm_opp_remove_table(opp_table, dev, false);
|
|
goto put_opp_table;
|
|
}
|
|
|
|
if (pstate_count)
|
|
opp_table->genpd_performance_state = true;
|
|
|
|
opp_table->np = opp_np;
|
|
if (of_property_read_bool(opp_np, "opp-shared"))
|
|
opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED;
|
|
else
|
|
opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE;
|
|
|
|
put_opp_table:
|
|
dev_pm_opp_put_opp_table(opp_table);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* Initializes OPP tables based on old-deprecated bindings */
|
|
static int _of_add_opp_table_v1(struct device *dev)
|
|
{
|
|
struct opp_table *opp_table;
|
|
const struct property *prop;
|
|
const __be32 *val;
|
|
int nr, ret = 0;
|
|
|
|
prop = of_find_property(dev->of_node, "operating-points", NULL);
|
|
if (!prop)
|
|
return -ENODEV;
|
|
if (!prop->value)
|
|
return -ENODATA;
|
|
|
|
/*
|
|
* Each OPP is a set of tuples consisting of frequency and
|
|
* voltage like <freq-kHz vol-uV>.
|
|
*/
|
|
nr = prop->length / sizeof(u32);
|
|
if (nr % 2) {
|
|
dev_err(dev, "%s: Invalid OPP table\n", __func__);
|
|
return -EINVAL;
|
|
}
|
|
|
|
opp_table = dev_pm_opp_get_opp_table(dev);
|
|
if (!opp_table)
|
|
return -ENOMEM;
|
|
|
|
val = prop->value;
|
|
while (nr) {
|
|
unsigned long freq = be32_to_cpup(val++) * 1000;
|
|
unsigned long volt = be32_to_cpup(val++);
|
|
|
|
ret = _opp_add_v1(opp_table, dev, freq, volt, false);
|
|
if (ret) {
|
|
dev_err(dev, "%s: Failed to add OPP %ld (%d)\n",
|
|
__func__, freq, ret);
|
|
_dev_pm_opp_remove_table(opp_table, dev, false);
|
|
break;
|
|
}
|
|
nr -= 2;
|
|
}
|
|
|
|
dev_pm_opp_put_opp_table(opp_table);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* dev_pm_opp_of_add_table() - Initialize opp table from device tree
|
|
* @dev: device pointer used to lookup OPP table.
|
|
*
|
|
* Register the initial OPP table with the OPP library for given device.
|
|
*
|
|
* Return:
|
|
* 0 On success OR
|
|
* Duplicate OPPs (both freq and volt are same) and opp->available
|
|
* -EEXIST Freq are same and volt are different OR
|
|
* Duplicate OPPs (both freq and volt are same) and !opp->available
|
|
* -ENOMEM Memory allocation failure
|
|
* -ENODEV when 'operating-points' property is not found or is invalid data
|
|
* in device node.
|
|
* -ENODATA when empty 'operating-points' property is found
|
|
* -EINVAL when invalid entries are found in opp-v2 table
|
|
*/
|
|
int dev_pm_opp_of_add_table(struct device *dev)
|
|
{
|
|
struct device_node *opp_np;
|
|
int ret;
|
|
|
|
/*
|
|
* OPPs have two version of bindings now. The older one is deprecated,
|
|
* try for the new binding first.
|
|
*/
|
|
opp_np = dev_pm_opp_of_get_opp_desc_node(dev);
|
|
if (!opp_np) {
|
|
/*
|
|
* Try old-deprecated bindings for backward compatibility with
|
|
* older dtbs.
|
|
*/
|
|
return _of_add_opp_table_v1(dev);
|
|
}
|
|
|
|
ret = _of_add_opp_table_v2(dev, opp_np);
|
|
of_node_put(opp_np);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);
|
|
|
|
/**
|
|
* dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
|
|
* @dev: device pointer used to lookup OPP table.
|
|
* @index: Index number.
|
|
*
|
|
* Register the initial OPP table with the OPP library for given device only
|
|
* using the "operating-points-v2" property.
|
|
*
|
|
* Return:
|
|
* 0 On success OR
|
|
* Duplicate OPPs (both freq and volt are same) and opp->available
|
|
* -EEXIST Freq are same and volt are different OR
|
|
* Duplicate OPPs (both freq and volt are same) and !opp->available
|
|
* -ENOMEM Memory allocation failure
|
|
* -ENODEV when 'operating-points' property is not found or is invalid data
|
|
* in device node.
|
|
* -ENODATA when empty 'operating-points' property is found
|
|
* -EINVAL when invalid entries are found in opp-v2 table
|
|
*/
|
|
int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
|
|
{
|
|
struct device_node *opp_np;
|
|
int ret, count;
|
|
|
|
again:
|
|
opp_np = _opp_of_get_opp_desc_node(dev->of_node, index);
|
|
if (!opp_np) {
|
|
/*
|
|
* If only one phandle is present, then the same OPP table
|
|
* applies for all index requests.
|
|
*/
|
|
count = of_count_phandle_with_args(dev->of_node,
|
|
"operating-points-v2", NULL);
|
|
if (count == 1 && index) {
|
|
index = 0;
|
|
goto again;
|
|
}
|
|
|
|
return -ENODEV;
|
|
}
|
|
|
|
ret = _of_add_opp_table_v2(dev, opp_np);
|
|
of_node_put(opp_np);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed);
|
|
|
|
/* CPU device specific helpers */
|
|
|
|
/**
|
|
* dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask
|
|
* @cpumask: cpumask for which OPP table needs to be removed
|
|
*
|
|
* This removes the OPP tables for CPUs present in the @cpumask.
|
|
* This should be used only to remove static entries created from DT.
|
|
*/
|
|
void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
|
|
{
|
|
_dev_pm_opp_cpumask_remove_table(cpumask, true);
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table);
|
|
|
|
/**
|
|
* dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask
|
|
* @cpumask: cpumask for which OPP table needs to be added.
|
|
*
|
|
* This adds the OPP tables for CPUs present in the @cpumask.
|
|
*/
|
|
int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
|
|
{
|
|
struct device *cpu_dev;
|
|
int cpu, ret = 0;
|
|
|
|
WARN_ON(cpumask_empty(cpumask));
|
|
|
|
for_each_cpu(cpu, cpumask) {
|
|
cpu_dev = get_cpu_device(cpu);
|
|
if (!cpu_dev) {
|
|
pr_err("%s: failed to get cpu%d device\n", __func__,
|
|
cpu);
|
|
continue;
|
|
}
|
|
|
|
ret = dev_pm_opp_of_add_table(cpu_dev);
|
|
if (ret) {
|
|
/*
|
|
* OPP may get registered dynamically, don't print error
|
|
* message here.
|
|
*/
|
|
pr_debug("%s: couldn't find opp table for cpu:%d, %d\n",
|
|
__func__, cpu, ret);
|
|
|
|
/* Free all other OPPs */
|
|
dev_pm_opp_of_cpumask_remove_table(cpumask);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table);
|
|
|
|
/*
|
|
* Works only for OPP v2 bindings.
|
|
*
|
|
* Returns -ENOENT if operating-points-v2 bindings aren't supported.
|
|
*/
|
|
/**
|
|
* dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with
|
|
* @cpu_dev using operating-points-v2
|
|
* bindings.
|
|
*
|
|
* @cpu_dev: CPU device for which we do this operation
|
|
* @cpumask: cpumask to update with information of sharing CPUs
|
|
*
|
|
* This updates the @cpumask with CPUs that are sharing OPPs with @cpu_dev.
|
|
*
|
|
* Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.
|
|
*/
|
|
int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,
|
|
struct cpumask *cpumask)
|
|
{
|
|
struct device_node *np, *tmp_np, *cpu_np;
|
|
int cpu, ret = 0;
|
|
|
|
/* Get OPP descriptor node */
|
|
np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
|
|
if (!np) {
|
|
dev_dbg(cpu_dev, "%s: Couldn't find opp node.\n", __func__);
|
|
return -ENOENT;
|
|
}
|
|
|
|
cpumask_set_cpu(cpu_dev->id, cpumask);
|
|
|
|
/* OPPs are shared ? */
|
|
if (!of_property_read_bool(np, "opp-shared"))
|
|
goto put_cpu_node;
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
if (cpu == cpu_dev->id)
|
|
continue;
|
|
|
|
cpu_np = of_cpu_device_node_get(cpu);
|
|
if (!cpu_np) {
|
|
dev_err(cpu_dev, "%s: failed to get cpu%d node\n",
|
|
__func__, cpu);
|
|
ret = -ENOENT;
|
|
goto put_cpu_node;
|
|
}
|
|
|
|
/* Get OPP descriptor node */
|
|
tmp_np = _opp_of_get_opp_desc_node(cpu_np, 0);
|
|
of_node_put(cpu_np);
|
|
if (!tmp_np) {
|
|
pr_err("%pOF: Couldn't find opp node\n", cpu_np);
|
|
ret = -ENOENT;
|
|
goto put_cpu_node;
|
|
}
|
|
|
|
/* CPUs are sharing opp node */
|
|
if (np == tmp_np)
|
|
cpumask_set_cpu(cpu, cpumask);
|
|
|
|
of_node_put(tmp_np);
|
|
}
|
|
|
|
put_cpu_node:
|
|
of_node_put(np);
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
|
|
|
|
/**
|
|
* of_dev_pm_opp_find_required_opp() - Search for required OPP.
|
|
* @dev: The device whose OPP node is referenced by the 'np' DT node.
|
|
* @np: Node that contains the "required-opps" property.
|
|
*
|
|
* Returns the OPP of the device 'dev', whose phandle is present in the "np"
|
|
* node. Although the "required-opps" property supports having multiple
|
|
* phandles, this helper routine only parses the very first phandle in the list.
|
|
*
|
|
* Return: Matching opp, else returns ERR_PTR in case of error and should be
|
|
* handled using IS_ERR.
|
|
*
|
|
* The callers are required to call dev_pm_opp_put() for the returned OPP after
|
|
* use.
|
|
*/
|
|
struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev,
|
|
struct device_node *np)
|
|
{
|
|
struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ENODEV);
|
|
struct device_node *required_np;
|
|
struct opp_table *opp_table;
|
|
|
|
opp_table = _find_opp_table(dev);
|
|
if (IS_ERR(opp_table))
|
|
return ERR_CAST(opp_table);
|
|
|
|
required_np = of_parse_phandle(np, "required-opps", 0);
|
|
if (unlikely(!required_np)) {
|
|
dev_err(dev, "Unable to parse required-opps\n");
|
|
goto put_opp_table;
|
|
}
|
|
|
|
mutex_lock(&opp_table->lock);
|
|
|
|
list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
|
|
if (temp_opp->available && temp_opp->np == required_np) {
|
|
opp = temp_opp;
|
|
|
|
/* Increment the reference count of OPP */
|
|
dev_pm_opp_get(opp);
|
|
break;
|
|
}
|
|
}
|
|
|
|
mutex_unlock(&opp_table->lock);
|
|
|
|
of_node_put(required_np);
|
|
put_opp_table:
|
|
dev_pm_opp_put_opp_table(opp_table);
|
|
|
|
return opp;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_dev_pm_opp_find_required_opp);
|
|
|
|
/**
|
|
* dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
|
|
* @opp: opp for which DT node has to be returned for
|
|
*
|
|
* Return: DT node corresponding to the opp, else 0 on success.
|
|
*
|
|
* The caller needs to put the node with of_node_put() after using it.
|
|
*/
|
|
struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
|
|
{
|
|
if (IS_ERR_OR_NULL(opp)) {
|
|
pr_err("%s: Invalid parameters\n", __func__);
|
|
return NULL;
|
|
}
|
|
|
|
return of_node_get(opp->np);
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);
|
|
|
|
/**
|
|
* of_dev_pm_opp_get_cpu_power() - Estimates the power of a CPU
|
|
* @mW: pointer to the power estimate in milli-watts
|
|
* @KHz: pointer to the OPP's frequency, in kilo-hertz
|
|
* @cpu: CPU for which power needs to be estimated
|
|
*
|
|
* Computes the power estimated by @CPU at the first OPP above @KHz (ceil),
|
|
* and updates @KHz and @mW accordingly.
|
|
*
|
|
* The power is estimated as P = C * V^2 * f, with C the CPU's capacitance
|
|
* (read from the 'dynamic-power-coefficient' devicetree binding) and V and f
|
|
* respectively the voltage and frequency of the OPP.
|
|
*
|
|
* Return: -ENODEV if the CPU device cannot be found, -EINVAL if the power
|
|
* calculation failed because of missing parameters, 0 otherwise.
|
|
*/
|
|
int of_dev_pm_opp_get_cpu_power(unsigned long *mW, unsigned long *KHz, int cpu)
|
|
{
|
|
unsigned long mV, Hz, MHz;
|
|
struct device *cpu_dev;
|
|
struct dev_pm_opp *opp;
|
|
struct device_node *np;
|
|
u32 cap;
|
|
u64 tmp;
|
|
int ret;
|
|
|
|
cpu_dev = get_cpu_device(cpu);
|
|
if (!cpu_dev)
|
|
return -ENODEV;
|
|
|
|
np = of_node_get(cpu_dev->of_node);
|
|
if (!np)
|
|
return -EINVAL;
|
|
|
|
ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap);
|
|
of_node_put(np);
|
|
if (ret)
|
|
return -EINVAL;
|
|
|
|
Hz = *KHz * 1000;
|
|
opp = dev_pm_opp_find_freq_ceil(cpu_dev, &Hz);
|
|
if (IS_ERR(opp))
|
|
return -EINVAL;
|
|
|
|
mV = dev_pm_opp_get_voltage(opp) / 1000;
|
|
dev_pm_opp_put(opp);
|
|
if (!mV)
|
|
return -EINVAL;
|
|
|
|
MHz = Hz / 1000000;
|
|
tmp = (u64)cap * mV * mV * MHz;
|
|
do_div(tmp, 1000000000);
|
|
|
|
*mW = (unsigned long)tmp;
|
|
*KHz = Hz / 1000;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(of_dev_pm_opp_get_cpu_power);
|
|
|
|
/*
|
|
* Callback function provided to the Energy Model framework upon registration.
|
|
* This computes the power estimated by @CPU at @kHz if it is the frequency
|
|
* of an existing OPP, or at the frequency of the first OPP above @kHz otherwise
|
|
* (see dev_pm_opp_find_freq_ceil()). This function updates @kHz to the ceiled
|
|
* frequency and @mW to the associated power. The power is estimated as
|
|
* P = C * V^2 * f with C being the CPU's capacitance and V and f respectively
|
|
* the voltage and frequency of the OPP.
|
|
*
|
|
* Returns -ENODEV if the CPU device cannot be found, -EINVAL if the power
|
|
* calculation failed because of missing parameters, 0 otherwise.
|
|
*/
|
|
static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz,
|
|
int cpu)
|
|
{
|
|
struct device *cpu_dev;
|
|
struct dev_pm_opp *opp;
|
|
struct device_node *np;
|
|
unsigned long mV, Hz;
|
|
u32 cap;
|
|
u64 tmp;
|
|
int ret;
|
|
|
|
cpu_dev = get_cpu_device(cpu);
|
|
if (!cpu_dev)
|
|
return -ENODEV;
|
|
|
|
np = of_node_get(cpu_dev->of_node);
|
|
if (!np)
|
|
return -EINVAL;
|
|
|
|
ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap);
|
|
of_node_put(np);
|
|
if (ret)
|
|
return -EINVAL;
|
|
|
|
Hz = *kHz * 1000;
|
|
opp = dev_pm_opp_find_freq_ceil(cpu_dev, &Hz);
|
|
if (IS_ERR(opp))
|
|
return -EINVAL;
|
|
|
|
mV = dev_pm_opp_get_voltage(opp) / 1000;
|
|
dev_pm_opp_put(opp);
|
|
if (!mV)
|
|
return -EINVAL;
|
|
|
|
tmp = (u64)cap * mV * mV * (Hz / 1000000);
|
|
do_div(tmp, 1000000000);
|
|
|
|
*mW = (unsigned long)tmp;
|
|
*kHz = Hz / 1000;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* dev_pm_opp_of_register_em() - Attempt to register an Energy Model
|
|
* @cpus : CPUs for which an Energy Model has to be registered
|
|
*
|
|
* This checks whether the "dynamic-power-coefficient" devicetree property has
|
|
* been specified, and tries to register an Energy Model with it if it has.
|
|
*/
|
|
void dev_pm_opp_of_register_em(struct cpumask *cpus)
|
|
{
|
|
struct em_data_callback em_cb = EM_DATA_CB(_get_cpu_power);
|
|
int ret, nr_opp, cpu = cpumask_first(cpus);
|
|
struct device *cpu_dev;
|
|
struct device_node *np;
|
|
u32 cap;
|
|
|
|
cpu_dev = get_cpu_device(cpu);
|
|
if (!cpu_dev)
|
|
return;
|
|
|
|
nr_opp = dev_pm_opp_get_opp_count(cpu_dev);
|
|
if (nr_opp <= 0)
|
|
return;
|
|
|
|
np = of_node_get(cpu_dev->of_node);
|
|
if (!np)
|
|
return;
|
|
|
|
/*
|
|
* Register an EM only if the 'dynamic-power-coefficient' property is
|
|
* set in devicetree. It is assumed the voltage values are known if that
|
|
* property is set since it is useless otherwise. If voltages are not
|
|
* known, just let the EM registration fail with an error to alert the
|
|
* user about the inconsistent configuration.
|
|
*/
|
|
ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap);
|
|
of_node_put(np);
|
|
if (ret || !cap)
|
|
return;
|
|
|
|
em_register_perf_domain(cpus, nr_opp, &em_cb);
|
|
}
|
|
EXPORT_SYMBOL_GPL(dev_pm_opp_of_register_em);
|