
Changes in 5.10.50 Bluetooth: hci_qca: fix potential GPF Bluetooth: btqca: Don't modify firmware contents in-place Bluetooth: Remove spurious error message ALSA: usb-audio: fix rate on Ozone Z90 USB headset ALSA: usb-audio: Fix OOB access at proc output ALSA: firewire-motu: fix stream format for MOTU 8pre FireWire ALSA: usb-audio: scarlett2: Fix wrong resume call ALSA: intel8x0: Fix breakage at ac97 clock measurement ALSA: hda/realtek: fix mute/micmute LEDs for HP ProBook 450 G8 ALSA: hda/realtek: fix mute/micmute LEDs for HP ProBook 445 G8 ALSA: hda/realtek: fix mute/micmute LEDs for HP ProBook 630 G8 ALSA: hda/realtek: Add another ALC236 variant support ALSA: hda/realtek: fix mute/micmute LEDs for HP EliteBook x360 830 G8 ALSA: hda/realtek: Improve fixup for HP Spectre x360 15-df0xxx ALSA: hda/realtek: Fix bass speaker DAC mapping for Asus UM431D ALSA: hda/realtek: Apply LED fixup for HP Dragonfly G1, too ALSA: hda/realtek: fix mute/micmute LEDs for HP EliteBook 830 G8 Notebook PC media: dvb-usb: fix wrong definition Input: usbtouchscreen - fix control-request directions net: can: ems_usb: fix use-after-free in ems_usb_disconnect() usb: gadget: eem: fix echo command packet response issue usb: renesas-xhci: Fix handling of unknown ROM state USB: cdc-acm: blacklist Heimann USB Appset device usb: dwc3: Fix debugfs creation flow usb: typec: Add the missed altmode_id_remove() in typec_register_altmode() xhci: solve a double free problem while doing s4 gfs2: Fix underflow in gfs2_page_mkwrite gfs2: Fix error handling in init_statfs ntfs: fix validity check for file name attribute selftests/lkdtm: Avoid needing explicit sub-shell copy_page_to_iter(): fix ITER_DISCARD case iov_iter_fault_in_readable() should do nothing in xarray case Input: joydev - prevent use of not validated data in JSIOCSBTNMAP ioctl crypto: nx - Fix memcpy() over-reading in nonce crypto: ccp - Annotate SEV Firmware file names arm_pmu: Fix write counter incorrect in ARMv7 big-endian mode ARM: dts: ux500: Fix LED probing ARM: dts: at91: sama5d4: fix pinctrl muxing btrfs: send: fix invalid path for unlink operations after parent orphanization btrfs: compression: don't try to compress if we don't have enough pages btrfs: clear defrag status of a root if starting transaction fails ext4: cleanup in-core orphan list if ext4_truncate() failed to get a transaction handle ext4: fix kernel infoleak via ext4_extent_header ext4: fix overflow in ext4_iomap_alloc() ext4: return error code when ext4_fill_flex_info() fails ext4: correct the cache_nr in tracepoint ext4_es_shrink_exit ext4: remove check for zero nr_to_scan in ext4_es_scan() ext4: fix avefreec in find_group_orlov ext4: use ext4_grp_locked_error in mb_find_extent can: bcm: delay release of struct bcm_op after synchronize_rcu() can: gw: synchronize rcu operations before removing gw job entry can: isotp: isotp_release(): omit unintended hrtimer restart on socket release can: j1939: j1939_sk_init(): set SOCK_RCU_FREE to call sk_destruct() after RCU is done can: peak_pciefd: pucan_handle_status(): fix a potential starvation issue in TX path mac80211: remove iwlwifi specific workaround that broke sta NDP tx SUNRPC: Fix the batch tasks count wraparound. SUNRPC: Should wake up the privileged task firstly. bus: mhi: Wait for M2 state during system resume mm/gup: fix try_grab_compound_head() race with split_huge_page() perf/smmuv3: Don't trample existing events with global filter KVM: nVMX: Handle split-lock #AC exceptions that happen in L2 KVM: PPC: Book3S HV: Workaround high stack usage with clang KVM: x86/mmu: Treat NX as used (not reserved) for all !TDP shadow MMUs KVM: x86/mmu: Use MMU's role to detect CR4.SMEP value in nested NPT walk s390/cio: dont call css_wait_for_slow_path() inside a lock s390: mm: Fix secure storage access exception handling f2fs: Prevent swap file in LFS mode clk: agilex/stratix10/n5x: fix how the bypass_reg is handled clk: agilex/stratix10: remove noc_clk clk: agilex/stratix10: fix bypass representation rtc: stm32: Fix unbalanced clk_disable_unprepare() on probe error path iio: frequency: adf4350: disable reg and clk on error in adf4350_probe() iio: light: tcs3472: do not free unallocated IRQ iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR iio: ltr501: ltr501_read_ps(): add missing endianness conversion iio: accel: bma180: Fix BMA25x bandwidth register values serial: mvebu-uart: fix calculation of clock divisor serial: sh-sci: Stop dmaengine transfer in sci_stop_tx() serial_cs: Add Option International GSM-Ready 56K/ISDN modem serial_cs: remove wrong GLOBETROTTER.cis entry ath9k: Fix kernel NULL pointer dereference during ath_reset_internal() ssb: sdio: Don't overwrite const buffer if block_write fails rsi: Assign beacon rate settings to the correct rate_info descriptor field rsi: fix AP mode with WPA failure due to encrypted EAPOL tracing/histograms: Fix parsing of "sym-offset" modifier tracepoint: Add tracepoint_probe_register_may_exist() for BPF tracing seq_buf: Make trace_seq_putmem_hex() support data longer than 8 powerpc/stacktrace: Fix spurious "stale" traces in raise_backtrace_ipi() loop: Fix missing discard support when using LOOP_CONFIGURE evm: Execute evm_inode_init_security() only when an HMAC key is loaded evm: Refuse EVM_ALLOW_METADATA_WRITES only if an HMAC key is loaded fuse: Fix crash in fuse_dentry_automount() error path fuse: Fix crash if superblock of submount gets killed early fuse: Fix infinite loop in sget_fc() fuse: ignore PG_workingset after stealing fuse: check connected before queueing on fpq->io fuse: reject internal errno thermal/cpufreq_cooling: Update offline CPUs per-cpu thermal_pressure spi: Make of_register_spi_device also set the fwnode Add a reference to ucounts for each cred staging: media: rkvdec: fix pm_runtime_get_sync() usage count media: marvel-ccic: fix some issues when getting pm_runtime media: mdk-mdp: fix pm_runtime_get_sync() usage count media: s5p: fix pm_runtime_get_sync() usage count media: am437x: fix pm_runtime_get_sync() usage count media: sh_vou: fix pm_runtime_get_sync() usage count media: mtk-vcodec: fix PM runtime get logic media: s5p-jpeg: fix pm_runtime_get_sync() usage count media: sunxi: fix pm_runtime_get_sync() usage count media: sti/bdisp: fix pm_runtime_get_sync() usage count media: exynos4-is: fix pm_runtime_get_sync() usage count media: exynos-gsc: fix pm_runtime_get_sync() usage count spi: spi-loopback-test: Fix 'tx_buf' might be 'rx_buf' spi: spi-topcliff-pch: Fix potential double free in pch_spi_process_messages() spi: omap-100k: Fix the length judgment problem regulator: uniphier: Add missing MODULE_DEVICE_TABLE sched/core: Initialize the idle task with preemption disabled hwrng: exynos - Fix runtime PM imbalance on error crypto: nx - add missing MODULE_DEVICE_TABLE media: sti: fix obj-$(config) targets media: cpia2: fix memory leak in cpia2_usb_probe media: cobalt: fix race condition in setting HPD media: hevc: Fix dependent slice segment flags media: pvrusb2: fix warning in pvr2_i2c_core_done media: imx: imx7_mipi_csis: Fix logging of only error event counters crypto: qat - check return code of qat_hal_rd_rel_reg() crypto: qat - remove unused macro in FW loader crypto: qce: skcipher: Fix incorrect sg count for dma transfers arm64: perf: Convert snprintf to sysfs_emit sched/fair: Fix ascii art by relpacing tabs media: i2c: ov2659: Use clk_{prepare_enable,disable_unprepare}() to set xvclk on/off media: bt878: do not schedule tasklet when it is not setup media: em28xx: Fix possible memory leak of em28xx struct media: hantro: Fix .buf_prepare media: cedrus: Fix .buf_prepare media: v4l2-core: Avoid the dangling pointer in v4l2_fh_release media: bt8xx: Fix a missing check bug in bt878_probe media: st-hva: Fix potential NULL pointer dereferences crypto: hisilicon/sec - fixup 3des minimum key size declaration Makefile: fix GDB warning with CONFIG_RELR media: dvd_usb: memory leak in cinergyt2_fe_attach memstick: rtsx_usb_ms: fix UAF mmc: sdhci-sprd: use sdhci_sprd_writew mmc: via-sdmmc: add a check against NULL pointer dereference spi: meson-spicc: fix a wrong goto jump for avoiding memory leak. spi: meson-spicc: fix memory leak in meson_spicc_probe crypto: shash - avoid comparing pointers to exported functions under CFI media: dvb_net: avoid speculation from net slot media: siano: fix device register error path media: imx-csi: Skip first few frames from a BT.656 source hwmon: (max31790) Report correct current pwm duty cycles hwmon: (max31790) Fix pwmX_enable attributes drivers/perf: fix the missed ida_simple_remove() in ddr_perf_probe() KVM: PPC: Book3S HV: Fix TLB management on SMT8 POWER9 and POWER10 processors btrfs: fix error handling in __btrfs_update_delayed_inode btrfs: abort transaction if we fail to update the delayed inode btrfs: sysfs: fix format string for some discard stats btrfs: don't clear page extent mapped if we're not invalidating the full page btrfs: disable build on platforms having page size 256K locking/lockdep: Fix the dep path printing for backwards BFS lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() KVM: s390: get rid of register asm usage regulator: mt6358: Fix vdram2 .vsel_mask regulator: da9052: Ensure enough delay time for .set_voltage_time_sel media: Fix Media Controller API config checks ACPI: video: use native backlight for GA401/GA502/GA503 HID: do not use down_interruptible() when unbinding devices EDAC/ti: Add missing MODULE_DEVICE_TABLE ACPI: processor idle: Fix up C-state latency if not ordered hv_utils: Fix passing zero to 'PTR_ERR' warning lib: vsprintf: Fix handling of number field widths in vsscanf Input: goodix - platform/x86: touchscreen_dmi - Move upside down quirks to touchscreen_dmi.c platform/x86: touchscreen_dmi: Add an extra entry for the upside down Goodix touchscreen on Teclast X89 tablets platform/x86: touchscreen_dmi: Add info for the Goodix GT912 panel of TM800A550L tablets ACPI: EC: Make more Asus laptops use ECDT _GPE block_dump: remove block_dump feature in mark_inode_dirty() blk-mq: grab rq->refcount before calling ->fn in blk_mq_tagset_busy_iter blk-mq: clear stale request in tags->rq[] before freeing one request pool fs: dlm: cancel work sync othercon random32: Fix implicit truncation warning in prandom_seed_state() open: don't silently ignore unknown O-flags in openat2() drivers: hv: Fix missing error code in vmbus_connect() fs: dlm: fix memory leak when fenced ACPICA: Fix memory leak caused by _CID repair function ACPI: bus: Call kobject_put() in acpi_init() error path ACPI: resources: Add checks for ACPI IRQ override block: fix race between adding/removing rq qos and normal IO platform/x86: asus-nb-wmi: Revert "Drop duplicate DMI quirk structures" platform/x86: asus-nb-wmi: Revert "add support for ASUS ROG Zephyrus G14 and G15" platform/x86: toshiba_acpi: Fix missing error code in toshiba_acpi_setup_keyboard() nvme-pci: fix var. type for increasing cq_head nvmet-fc: do not check for invalid target port in nvmet_fc_handle_fcp_rqst() EDAC/Intel: Do not load EDAC driver when running as a guest PCI: hv: Add check for hyperv_initialized in init_hv_pci_drv() cifs: improve fallocate emulation ACPI: EC: trust DSDT GPE for certain HP laptop clocksource: Retry clock read if long delays detected clocksource: Check per-CPU clock synchronization when marked unstable tpm_tis_spi: add missing SPI device ID entries ACPI: tables: Add custom DSDT file as makefile prerequisite HID: wacom: Correct base usage for capacitive ExpressKey status bits cifs: fix missing spinlock around update to ses->status mailbox: qcom: Use PLATFORM_DEVID_AUTO to register platform device block: fix discard request merge kthread_worker: fix return value when kthread_mod_delayed_work() races with kthread_cancel_delayed_work_sync() ia64: mca_drv: fix incorrect array size calculation writeback, cgroup: increment isw_nr_in_flight before grabbing an inode spi: Allow to have all native CSs in use along with GPIOs spi: Avoid undefined behaviour when counting unused native CSs media: venus: Rework error fail recover logic media: s5p_cec: decrement usage count if disabled media: hantro: do a PM resume earlier crypto: ixp4xx - dma_unmap the correct address crypto: ixp4xx - update IV after requests crypto: ux500 - Fix error return code in hash_hw_final() sata_highbank: fix deferred probing pata_rb532_cf: fix deferred probing media: I2C: change 'RST' to "RSET" to fix multiple build errors sched/uclamp: Fix wrong implementation of cpu.uclamp.min sched/uclamp: Fix locking around cpu_util_update_eff() kbuild: Fix objtool dependency for 'OBJECT_FILES_NON_STANDARD_<obj> := n' pata_octeon_cf: avoid WARN_ON() in ata_host_activate() evm: fix writing <securityfs>/evm overflow x86/elf: Use _BITUL() macro in UAPI headers crypto: sa2ul - Fix leaks on failure paths with sa_dma_init() crypto: sa2ul - Fix pm_runtime enable in sa_ul_probe() crypto: ccp - Fix a resource leak in an error handling path media: rc: i2c: Fix an error message pata_ep93xx: fix deferred probing locking/lockdep: Reduce LOCKDEP dependency list media: rkvdec: Fix .buf_prepare media: exynos4-is: Fix a use after free in isp_video_release media: au0828: fix a NULL vs IS_ERR() check media: tc358743: Fix error return code in tc358743_probe_of() media: gspca/gl860: fix zero-length control requests m68k: atari: Fix ATARI_KBD_CORE kconfig unmet dependency warning media: siano: Fix out-of-bounds warnings in smscore_load_firmware_family2() regulator: fan53880: Fix vsel_mask setting for FAN53880_BUCK crypto: nitrox - fix unchecked variable in nitrox_register_interrupts crypto: omap-sham - Fix PM reference leak in omap sham ops crypto: x86/curve25519 - fix cpu feature checking logic in mod_exit crypto: sm2 - remove unnecessary reset operations crypto: sm2 - fix a memory leak in sm2 mmc: usdhi6rol0: fix error return code in usdhi6_probe() arm64: consistently use reserved_pg_dir arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan media: subdev: remove VIDIOC_DQEVENT_TIME32 handling media: s5p-g2d: Fix a memory leak on ctx->fh.m2m_ctx hwmon: (lm70) Use device_get_match_data() hwmon: (lm70) Revert "hwmon: (lm70) Add support for ACPI" hwmon: (max31722) Remove non-standard ACPI device IDs hwmon: (max31790) Fix fan speed reporting for fan7..12 KVM: nVMX: Sync all PGDs on nested transition with shadow paging KVM: nVMX: Ensure 64-bit shift when checking VMFUNC bitmap KVM: nVMX: Don't clobber nested MMU's A/D status on EPTP switch KVM: x86/mmu: Fix return value in tdp_mmu_map_handle_target_level() perf/arm-cmn: Fix invalid pointer when access dtc object sharing the same IRQ number KVM: arm64: Don't zero the cycle count register when PMCR_EL0.P is set regulator: hi655x: Fix pass wrong pointer to config.driver_data btrfs: clear log tree recovering status if starting transaction fails x86/sev: Make sure IRQs are disabled while GHCB is active x86/sev: Split up runtime #VC handler for correct state tracking sched/rt: Fix RT utilization tracking during policy change sched/rt: Fix Deadline utilization tracking during policy change sched/uclamp: Fix uclamp_tg_restrict() lockdep: Fix wait-type for empty stack lockdep/selftests: Fix selftests vs PROVE_RAW_LOCK_NESTING spi: spi-sun6i: Fix chipselect/clock bug crypto: nx - Fix RCU warning in nx842_OF_upd_status psi: Fix race between psi_trigger_create/destroy media: v4l2-async: Clean v4l2_async_notifier_add_fwnode_remote_subdev media: video-mux: Skip dangling endpoints PM / devfreq: Add missing error code in devfreq_add_device() ACPI: PM / fan: Put fan device IDs into separate header file block: avoid double io accounting for flush request nvme-pci: look for StorageD3Enable on companion ACPI device instead ACPI: sysfs: Fix a buffer overrun problem with description_show() mark pstore-blk as broken clocksource/drivers/timer-ti-dm: Save and restore timer TIOCP_CFG extcon: extcon-max8997: Fix IRQ freeing at error path ACPI: APEI: fix synchronous external aborts in user-mode blk-wbt: introduce a new disable state to prevent false positive by rwb_enabled() blk-wbt: make sure throttle is enabled properly ACPI: Use DEVICE_ATTR_<RW|RO|WO> macros ACPI: bgrt: Fix CFI violation cpufreq: Make cpufreq_online() call driver->offline() on errors blk-mq: update hctx->dispatch_busy in case of real scheduler ocfs2: fix snprintf() checking dax: fix ENOMEM handling in grab_mapping_entry() mm/debug_vm_pgtable/basic: add validation for dirtiness after write protect mm/debug_vm_pgtable/basic: iterate over entire protection_map[] mm/debug_vm_pgtable: ensure THP availability via has_transparent_hugepage() swap: fix do_swap_page() race with swapoff mm/shmem: fix shmem_swapin() race with swapoff mm: memcg/slab: properly set up gfp flags for objcg pointer array mm: page_alloc: refactor setup_per_zone_lowmem_reserve() mm/page_alloc: fix counting of managed_pages xfrm: xfrm_state_mtu should return at least 1280 for ipv6 drm/bridge/sii8620: fix dependency on extcon drm/bridge: Fix the stop condition of drm_bridge_chain_pre_enable() drm/amd/dc: Fix a missing check bug in dm_dp_mst_detect() drm/ast: Fix missing conversions to managed API video: fbdev: imxfb: Fix an error message net: mvpp2: Put fwnode in error case during ->probe() net: pch_gbe: Propagate error from devm_gpio_request_one() pinctrl: renesas: r8a7796: Add missing bias for PRESET# pin pinctrl: renesas: r8a77990: JTAG pins do not have pull-down capabilities drm/vmwgfx: Mark a surface gpu-dirty after the SVGA3dCmdDXGenMips command drm/vmwgfx: Fix cpu updates of coherent multisample surfaces net: qrtr: ns: Fix error return code in qrtr_ns_init() clk: meson: g12a: fix gp0 and hifi ranges net: ftgmac100: add missing error return code in ftgmac100_probe() drm: rockchip: set alpha_en to 0 if it is not used drm/rockchip: cdn-dp-core: add missing clk_disable_unprepare() on error in cdn_dp_grf_write() drm/rockchip: dsi: move all lane config except LCDC mux to bind() drm/rockchip: lvds: Fix an error handling path drm/rockchip: cdn-dp: fix sign extension on an int multiply for a u64 result mptcp: fix pr_debug in mptcp_token_new_connect mptcp: generate subflow hmac after mptcp_finish_join() RDMA/srp: Fix a recently introduced memory leak RDMA/rtrs-clt: Check state of the rtrs_clt_sess before reading its stats RDMA/rtrs: Do not reset hb_missed_max after re-connection RDMA/rtrs-srv: Fix memory leak of unfreed rtrs_srv_stats object RDMA/rtrs-srv: Fix memory leak when having multiple sessions RDMA/rtrs-clt: Check if the queue_depth has changed during a reconnection RDMA/rtrs-clt: Fix memory leak of not-freed sess->stats and stats->pcpu_stats ehea: fix error return code in ehea_restart_qps() clk: tegra30: Use 300MHz for video decoder by default xfrm: remove the fragment check for ipv6 beet mode net/sched: act_vlan: Fix modify to allow 0 RDMA/core: Sanitize WQ state received from the userspace drm/pl111: depend on CONFIG_VEXPRESS_CONFIG RDMA/rxe: Fix failure during driver load drm/pl111: Actually fix CONFIG_VEXPRESS_CONFIG depends drm/vc4: hdmi: Fix error path of hpd-gpios clk: vc5: fix output disabling when enabling a FOD drm: qxl: ensure surf.data is ininitialized tools/bpftool: Fix error return code in do_batch() ath10k: go to path err_unsupported when chip id is not supported ath10k: add missing error return code in ath10k_pci_probe() wireless: carl9170: fix LEDS build errors & warnings ieee802154: hwsim: Fix possible memory leak in hwsim_subscribe_all_others clk: imx8mq: remove SYS PLL 1/2 clock gates wcn36xx: Move hal_buf allocation to devm_kmalloc in probe ssb: Fix error return code in ssb_bus_scan() brcmfmac: fix setting of station info chains bitmask brcmfmac: correctly report average RSSI in station info brcmfmac: Fix a double-free in brcmf_sdio_bus_reset brcmsmac: mac80211_if: Fix a resource leak in an error handling path cw1200: Revert unnecessary patches that fix unreal use-after-free bugs ath11k: Fix an error handling path in ath11k_core_fetch_board_data_api_n() ath10k: Fix an error code in ath10k_add_interface() ath11k: send beacon template after vdev_start/restart during csa netlabel: Fix memory leak in netlbl_mgmt_add_common RDMA/mlx5: Don't add slave port to unaffiliated list netfilter: nft_exthdr: check for IPv6 packet before further processing netfilter: nft_osf: check for TCP packet before further processing netfilter: nft_tproxy: restrict support to TCP and UDP transport protocols RDMA/rxe: Fix qp reference counting for atomic ops selftests/bpf: Whitelist test_progs.h from .gitignore xsk: Fix missing validation for skb and unaligned mode xsk: Fix broken Tx ring validation bpf: Fix libelf endian handling in resolv_btfids RDMA/rtrs-srv: Set minimal max_send_wr and max_recv_wr samples/bpf: Fix Segmentation fault for xdp_redirect command samples/bpf: Fix the error return code of xdp_redirect's main() mt76: fix possible NULL pointer dereference in mt76_tx mt76: mt7615: fix NULL pointer dereference in tx_prepare_skb() net: ethernet: aeroflex: fix UAF in greth_of_remove net: ethernet: ezchip: fix UAF in nps_enet_remove net: ethernet: ezchip: fix error handling vrf: do not push non-ND strict packets with a source LLA through packet taps again net: sched: add barrier to ensure correct ordering for lockless qdisc tls: prevent oversized sendfile() hangs by ignoring MSG_MORE netfilter: nf_tables_offload: check FLOW_DISSECTOR_KEY_BASIC in VLAN transfer logic pkt_sched: sch_qfq: fix qfq_change_class() error path xfrm: Fix xfrm offload fallback fail case iwlwifi: increase PNVM load timeout rtw88: 8822c: fix lc calibration timing vxlan: add missing rcu_read_lock() in neigh_reduce() ip6_tunnel: fix GRE6 segmentation net/ipv4: swap flow ports when validating source net: ti: am65-cpsw-nuss: Fix crash when changing number of TX queues tc-testing: fix list handling ieee802154: hwsim: Fix memory leak in hwsim_add_one ieee802154: hwsim: avoid possible crash in hwsim_del_edge_nl() bpf: Fix null ptr deref with mixed tail calls and subprogs drm/msm: Fix error return code in msm_drm_init() drm/msm/dpu: Fix error return code in dpu_mdss_init() mac80211: remove iwlwifi specific workaround NDPs of null_response net: bcmgenet: Fix attaching to PYH failed on RPi 4B ipv6: exthdrs: do not blindly use init_net can: j1939: j1939_sk_setsockopt(): prevent allocation of j1939 filter for optlen == 0 bpf: Do not change gso_size during bpf_skb_change_proto() i40e: Fix error handling in i40e_vsi_open i40e: Fix autoneg disabling for non-10GBaseT links i40e: Fix missing rtnl locking when setting up pf switch Revert "ibmvnic: remove duplicate napi_schedule call in open function" ibmvnic: set ltb->buff to NULL after freeing ibmvnic: free tx_pool if tso_pool alloc fails RDMA/cma: Protect RMW with qp_mutex net: macsec: fix the length used to copy the key for offloading net: phy: mscc: fix macsec key length net: atlantic: fix the macsec key length ipv6: fix out-of-bound access in ip6_parse_tlv() e1000e: Check the PCIm state net: dsa: sja1105: fix NULL pointer dereference in sja1105_reload_cbs() bpfilter: Specify the log level for the kmsg message RDMA/cma: Fix incorrect Packet Lifetime calculation gve: Fix swapped vars when fetching max queues Revert "be2net: disable bh with spin_lock in be_process_mcc" Bluetooth: mgmt: Fix slab-out-of-bounds in tlv_data_is_valid Bluetooth: Fix not sending Set Extended Scan Response Bluetooth: Fix Set Extended (Scan Response) Data Bluetooth: Fix handling of HCI_LE_Advertising_Set_Terminated event clk: actions: Fix UART clock dividers on Owl S500 SoC clk: actions: Fix SD clocks factor table on Owl S500 SoC clk: actions: Fix bisp_factor_table based clocks on Owl S500 SoC clk: actions: Fix AHPPREDIV-H-AHB clock chain on Owl S500 SoC clk: qcom: clk-alpha-pll: fix CAL_L write in alpha_pll_fabia_prepare clk: si5341: Wait for DEVICE_READY on startup clk: si5341: Avoid divide errors due to bogus register contents clk: si5341: Check for input clock presence and PLL lock on startup clk: si5341: Update initialization magic writeback: fix obtain a reference to a freeing memcg css net: lwtunnel: handle MTU calculation in forwading net: sched: fix warning in tcindex_alloc_perfect_hash net: tipc: fix FB_MTU eat two pages RDMA/mlx5: Don't access NULL-cleared mpi pointer RDMA/core: Always release restrack object MIPS: Fix PKMAP with 32-bit MIPS huge page support staging: fbtft: Rectify GPIO handling staging: fbtft: Don't spam logs when probe is deferred ASoC: rt5682: Disable irq on shutdown rcu: Invoke rcu_spawn_core_kthreads() from rcu_spawn_gp_kthread() serial: fsl_lpuart: don't modify arbitrary data on lpuart32 serial: fsl_lpuart: remove RTSCTS handling from get_mctrl() serial: 8250_omap: fix a timeout loop condition tty: nozomi: Fix a resource leak in an error handling function mwifiex: re-fix for unaligned accesses iio: adis_buffer: do not return ints in irq handlers iio: adis16400: do not return ints in irq handlers iio: adis16475: do not return ints in irq handlers iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: bma220: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: hid: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: kxcjk-1013: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: mxc4005: Fix overread of data and alignment issue. iio: accel: stk8312: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8ba50: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: ti-ads1015: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: vf610: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: gyro: bmg160: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: humidity: am2315: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: srf08: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: pulsed-light: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: as3935: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: magn: hmc5843: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: magn: bmc150: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: isl29125: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: tcs3414: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: tcs3472: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: chemical: atlas: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: cros_ec_sensors: Fix alignment of buffer in iio_push_to_buffers_with_timestamp() iio: potentiostat: lmp91000: Fix alignment of buffer in iio_push_to_buffers_with_timestamp() ASoC: rk3328: fix missing clk_disable_unprepare() on error in rk3328_platform_probe() ASoC: hisilicon: fix missing clk_disable_unprepare() on error in hi6210_i2s_startup() backlight: lm3630a_bl: Put fwnode in error case during ->probe() ASoC: rsnd: tidyup loop on rsnd_adg_clk_query() Input: hil_kbd - fix error return code in hil_dev_connect() perf scripting python: Fix tuple_set_u64() mtd: partitions: redboot: seek fis-index-block in the right node mtd: rawnand: arasan: Ensure proper configuration for the asserted target staging: mmal-vchiq: Fix incorrect static vchiq_instance. char: pcmcia: error out if 'num_bytes_read' is greater than 4 in set_protocol() firmware: stratix10-svc: Fix a resource leak in an error handling path tty: nozomi: Fix the error handling path of 'nozomi_card_init()' leds: class: The -ENOTSUPP should never be seen by user space leds: lm3532: select regmap I2C API leds: lm36274: Put fwnode in error case during ->probe() leds: lm3692x: Put fwnode in any case during ->probe() leds: lm3697: Don't spam logs when probe is deferred leds: lp50xx: Put fwnode in error case during ->probe() scsi: FlashPoint: Rename si_flags field scsi: iscsi: Flush block work before unblock mfd: mp2629: Select MFD_CORE to fix build error mfd: rn5t618: Fix IRQ trigger by changing it to level mode fsi: core: Fix return of error values on failures fsi: scom: Reset the FSI2PIB engine for any error fsi: occ: Don't accept response from un-initialized OCC fsi/sbefifo: Clean up correct FIFO when receiving reset request from SBE fsi/sbefifo: Fix reset timeout visorbus: fix error return code in visorchipset_init() iommu/amd: Fix extended features logging s390/irq: select HAVE_IRQ_EXIT_ON_IRQ_STACK s390: enable HAVE_IOREMAP_PROT s390: appldata depends on PROC_SYSCTL selftests: splice: Adjust for handler fallback removal iommu/dma: Fix IOVA reserve dma ranges ASoC: max98373-sdw: use first_hw_init flag on resume ASoC: rt1308-sdw: use first_hw_init flag on resume ASoC: rt5682-sdw: use first_hw_init flag on resume ASoC: rt700-sdw: use first_hw_init flag on resume ASoC: rt711-sdw: use first_hw_init flag on resume ASoC: rt715-sdw: use first_hw_init flag on resume ASoC: rt5682: fix getting the wrong device id when the suspend_stress_test ASoC: rt5682-sdw: set regcache_cache_only false before reading RT5682_DEVICE_ID ASoC: mediatek: mtk-btcvsd: Fix an error handling path in 'mtk_btcvsd_snd_probe()' usb: gadget: f_fs: Fix setting of device and driver data cross-references usb: dwc2: Don't reset the core after setting turnaround time eeprom: idt_89hpesx: Put fwnode in matching case during ->probe() eeprom: idt_89hpesx: Restore printing the unsupported fwnode name thunderbolt: Bond lanes only when dual_link_port != NULL in alloc_dev_default() iio: adc: at91-sama5d2: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: hx711: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: mxs-lradc: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: ti-ads8688: Fix alignment of buffer in iio_push_to_buffers_with_timestamp() iio: magn: rm3100: Fix alignment of buffer in iio_push_to_buffers_with_timestamp() iio: light: vcnl4000: Fix buffer alignment in iio_push_to_buffers_with_timestamp() ASoC: fsl_spdif: Fix error handler with pm_runtime_enable staging: gdm724x: check for buffer overflow in gdm_lte_multi_sdu_pkt() staging: gdm724x: check for overflow in gdm_lte_netif_rx() staging: rtl8712: fix error handling in r871xu_drv_init staging: rtl8712: fix memory leak in rtl871x_load_fw_cb coresight: core: Fix use of uninitialized pointer staging: mt7621-dts: fix pci address for PCI memory range serial: 8250: Actually allow UPF_MAGIC_MULTIPLIER baud rates iio: light: vcnl4035: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: isl29501: Fix buffer alignment in iio_push_to_buffers_with_timestamp() ASoC: cs42l42: Correct definition of CS42L42_ADC_PDN_MASK of: Fix truncation of memory sizes on 32-bit platforms mtd: rawnand: marvell: add missing clk_disable_unprepare() on error in marvell_nfc_resume() habanalabs: Fix an error handling path in 'hl_pci_probe()' scsi: mpt3sas: Fix error return value in _scsih_expander_add() soundwire: stream: Fix test for DP prepare complete phy: uniphier-pcie: Fix updating phy parameters phy: ti: dm816x: Fix the error handling path in 'dm816x_usb_phy_probe() extcon: sm5502: Drop invalid register write in sm5502_reg_data extcon: max8997: Add missing modalias string powerpc/powernv: Fix machine check reporting of async store errors ASoC: atmel-i2s: Fix usage of capture and playback at the same time configfs: fix memleak in configfs_release_bin_file ASoC: Intel: sof_sdw: add SOF_RT715_DAI_ID_FIX for AlderLake ASoC: fsl_spdif: Fix unexpected interrupt after suspend leds: as3645a: Fix error return code in as3645a_parse_node() leds: ktd2692: Fix an error handling path selftests/ftrace: fix event-no-pid on 1-core machine serial: 8250: 8250_omap: Disable RX interrupt after DMA enable serial: 8250: 8250_omap: Fix possible interrupt storm on K3 SoCs powerpc: Offline CPU in stop_this_cpu() powerpc/papr_scm: Properly handle UUID types and API powerpc/64s: Fix copy-paste data exposure into newly created tasks powerpc/papr_scm: Make 'perf_stats' invisible if perf-stats unavailable ALSA: firewire-lib: Fix 'amdtp_domain_start()' when no AMDTP_OUT_STREAM stream is found serial: mvebu-uart: do not allow changing baudrate when uartclk is not available serial: mvebu-uart: correctly calculate minimal possible baudrate arm64: dts: marvell: armada-37xx: Fix reg for standard variant of UART vfio/pci: Handle concurrent vma faults mm/pmem: avoid inserting hugepage PTE entry with fsdax if hugepage support is disabled mm/huge_memory.c: remove dedicated macro HPAGE_CACHE_INDEX_MASK mm/huge_memory.c: add missing read-only THP checking in transparent_hugepage_enabled() mm/huge_memory.c: don't discard hugepage if other processes are mapping it mm/hugetlb: use helper huge_page_order and pages_per_huge_page mm/hugetlb: remove redundant check in preparing and destroying gigantic page hugetlb: remove prep_compound_huge_page cleanup include/linux/huge_mm.h: remove extern keyword mm/z3fold: fix potential memory leak in z3fold_destroy_pool() mm/z3fold: use release_z3fold_page_locked() to release locked z3fold page lib/math/rational.c: fix divide by zero selftests/vm/pkeys: fix alloc_random_pkey() to make it really, really random selftests/vm/pkeys: handle negative sys_pkey_alloc() return code selftests/vm/pkeys: refill shadow register after implicit kernel write perf llvm: Return -ENOMEM when asprintf() fails csky: fix syscache.c fallthrough warning csky: syscache: Fixup duplicate cache flush exfat: handle wrong stream entry size in exfat_readdir() scsi: fc: Correct RHBA attributes length scsi: target: cxgbit: Unmap DMA buffer before calling target_execute_cmd() mailbox: qcom-ipcc: Fix IPCC mbox channel exhaustion fscrypt: don't ignore minor_hash when hash is 0 fscrypt: fix derivation of SipHash keys on big endian CPUs tpm: Replace WARN_ONCE() with dev_err_once() in tpm_tis_status() erofs: fix error return code in erofs_read_superblock() block: return the correct bvec when checking for gaps io_uring: fix blocking inline submission mmc: block: Disable CMDQ on the ioctl path mmc: vub3000: fix control-request direction media: exynos4-is: remove a now unused integer scsi: core: Retry I/O for Notify (Enable Spinup) Required error crypto: qce - fix error return code in qce_skcipher_async_req_handle() s390: preempt: Fix preempt_count initialization cred: add missing return error code when set_cred_ucounts() failed iommu/dma: Fix compile warning in 32-bit builds powerpc/preempt: Don't touch the idle task's preempt_count during hotplug Linux 5.10.50 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Iec4eab24ea8eb5a6d79739a1aec8432d93a8f82c
2880 lines
74 KiB
C
2880 lines
74 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* linux/drivers/cpufreq/cpufreq.c
|
|
*
|
|
* Copyright (C) 2001 Russell King
|
|
* (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
|
|
* (C) 2013 Viresh Kumar <viresh.kumar@linaro.org>
|
|
*
|
|
* Oct 2005 - Ashok Raj <ashok.raj@intel.com>
|
|
* Added handling for CPU hotplug
|
|
* Feb 2006 - Jacob Shin <jacob.shin@amd.com>
|
|
* Fix handling for CPU hotplug -- affected CPUs
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/cpu.h>
|
|
#include <linux/cpufreq.h>
|
|
#include <linux/cpufreq_times.h>
|
|
#include <linux/cpu_cooling.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/device.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kernel_stat.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/pm_qos.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/suspend.h>
|
|
#include <linux/syscore_ops.h>
|
|
#include <linux/tick.h>
|
|
#include <trace/events/power.h>
|
|
#include <trace/hooks/cpufreq.h>
|
|
|
|
static LIST_HEAD(cpufreq_policy_list);
|
|
|
|
/* Macros to iterate over CPU policies */
|
|
#define for_each_suitable_policy(__policy, __active) \
|
|
list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
|
|
if ((__active) == !policy_is_inactive(__policy))
|
|
|
|
#define for_each_active_policy(__policy) \
|
|
for_each_suitable_policy(__policy, true)
|
|
#define for_each_inactive_policy(__policy) \
|
|
for_each_suitable_policy(__policy, false)
|
|
|
|
#define for_each_policy(__policy) \
|
|
list_for_each_entry(__policy, &cpufreq_policy_list, policy_list)
|
|
|
|
/* Iterate over governors */
|
|
static LIST_HEAD(cpufreq_governor_list);
|
|
#define for_each_governor(__governor) \
|
|
list_for_each_entry(__governor, &cpufreq_governor_list, governor_list)
|
|
|
|
static char default_governor[CPUFREQ_NAME_LEN];
|
|
|
|
/*
|
|
* The "cpufreq driver" - the arch- or hardware-dependent low
|
|
* level driver of CPUFreq support, and its spinlock. This lock
|
|
* also protects the cpufreq_cpu_data array.
|
|
*/
|
|
static struct cpufreq_driver *cpufreq_driver;
|
|
static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
|
|
static DEFINE_RWLOCK(cpufreq_driver_lock);
|
|
|
|
static DEFINE_STATIC_KEY_FALSE(cpufreq_freq_invariance);
|
|
bool cpufreq_supports_freq_invariance(void)
|
|
{
|
|
return static_branch_likely(&cpufreq_freq_invariance);
|
|
}
|
|
|
|
/* Flag to suspend/resume CPUFreq governors */
|
|
static bool cpufreq_suspended;
|
|
|
|
static inline bool has_target(void)
|
|
{
|
|
return cpufreq_driver->target_index || cpufreq_driver->target;
|
|
}
|
|
|
|
/* internal prototypes */
|
|
static unsigned int __cpufreq_get(struct cpufreq_policy *policy);
|
|
static int cpufreq_init_governor(struct cpufreq_policy *policy);
|
|
static void cpufreq_exit_governor(struct cpufreq_policy *policy);
|
|
static void cpufreq_governor_limits(struct cpufreq_policy *policy);
|
|
static int cpufreq_set_policy(struct cpufreq_policy *policy,
|
|
struct cpufreq_governor *new_gov,
|
|
unsigned int new_pol);
|
|
|
|
/*
|
|
* Two notifier lists: the "policy" list is involved in the
|
|
* validation process for a new CPU frequency policy; the
|
|
* "transition" list for kernel code that needs to handle
|
|
* changes to devices when the CPU clock speed changes.
|
|
* The mutex locks both lists.
|
|
*/
|
|
static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
|
|
SRCU_NOTIFIER_HEAD_STATIC(cpufreq_transition_notifier_list);
|
|
|
|
static int off __read_mostly;
|
|
static int cpufreq_disabled(void)
|
|
{
|
|
return off;
|
|
}
|
|
void disable_cpufreq(void)
|
|
{
|
|
off = 1;
|
|
}
|
|
static DEFINE_MUTEX(cpufreq_governor_mutex);
|
|
|
|
bool have_governor_per_policy(void)
|
|
{
|
|
return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY);
|
|
}
|
|
EXPORT_SYMBOL_GPL(have_governor_per_policy);
|
|
|
|
static struct kobject *cpufreq_global_kobject;
|
|
|
|
struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy)
|
|
{
|
|
if (have_governor_per_policy())
|
|
return &policy->kobj;
|
|
else
|
|
return cpufreq_global_kobject;
|
|
}
|
|
EXPORT_SYMBOL_GPL(get_governor_parent_kobj);
|
|
|
|
static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
|
|
{
|
|
struct kernel_cpustat kcpustat;
|
|
u64 cur_wall_time;
|
|
u64 idle_time;
|
|
u64 busy_time;
|
|
|
|
cur_wall_time = jiffies64_to_nsecs(get_jiffies_64());
|
|
|
|
kcpustat_cpu_fetch(&kcpustat, cpu);
|
|
|
|
busy_time = kcpustat.cpustat[CPUTIME_USER];
|
|
busy_time += kcpustat.cpustat[CPUTIME_SYSTEM];
|
|
busy_time += kcpustat.cpustat[CPUTIME_IRQ];
|
|
busy_time += kcpustat.cpustat[CPUTIME_SOFTIRQ];
|
|
busy_time += kcpustat.cpustat[CPUTIME_STEAL];
|
|
busy_time += kcpustat.cpustat[CPUTIME_NICE];
|
|
|
|
idle_time = cur_wall_time - busy_time;
|
|
if (wall)
|
|
*wall = div_u64(cur_wall_time, NSEC_PER_USEC);
|
|
|
|
return div_u64(idle_time, NSEC_PER_USEC);
|
|
}
|
|
|
|
u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
|
|
{
|
|
u64 idle_time = get_cpu_idle_time_us(cpu, io_busy ? wall : NULL);
|
|
|
|
if (idle_time == -1ULL)
|
|
return get_cpu_idle_time_jiffy(cpu, wall);
|
|
else if (!io_busy)
|
|
idle_time += get_cpu_iowait_time_us(cpu, wall);
|
|
|
|
return idle_time;
|
|
}
|
|
EXPORT_SYMBOL_GPL(get_cpu_idle_time);
|
|
|
|
/*
|
|
* This is a generic cpufreq init() routine which can be used by cpufreq
|
|
* drivers of SMP systems. It will do following:
|
|
* - validate & show freq table passed
|
|
* - set policies transition latency
|
|
* - policy->cpus with all possible CPUs
|
|
*/
|
|
void cpufreq_generic_init(struct cpufreq_policy *policy,
|
|
struct cpufreq_frequency_table *table,
|
|
unsigned int transition_latency)
|
|
{
|
|
policy->freq_table = table;
|
|
policy->cpuinfo.transition_latency = transition_latency;
|
|
|
|
/*
|
|
* The driver only supports the SMP configuration where all processors
|
|
* share the clock and voltage and clock.
|
|
*/
|
|
cpumask_setall(policy->cpus);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_generic_init);
|
|
|
|
struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
|
|
|
|
return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw);
|
|
|
|
unsigned int cpufreq_generic_get(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
|
|
|
|
if (!policy || IS_ERR(policy->clk)) {
|
|
pr_err("%s: No %s associated to cpu: %d\n",
|
|
__func__, policy ? "clk" : "policy", cpu);
|
|
return 0;
|
|
}
|
|
|
|
return clk_get_rate(policy->clk) / 1000;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_generic_get);
|
|
|
|
/**
|
|
* cpufreq_cpu_get - Return policy for a CPU and mark it as busy.
|
|
* @cpu: CPU to find the policy for.
|
|
*
|
|
* Call cpufreq_cpu_get_raw() to obtain a cpufreq policy for @cpu and increment
|
|
* the kobject reference counter of that policy. Return a valid policy on
|
|
* success or NULL on failure.
|
|
*
|
|
* The policy returned by this function has to be released with the help of
|
|
* cpufreq_cpu_put() to balance its kobject reference counter properly.
|
|
*/
|
|
struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy = NULL;
|
|
unsigned long flags;
|
|
|
|
if (WARN_ON(cpu >= nr_cpu_ids))
|
|
return NULL;
|
|
|
|
/* get the cpufreq driver */
|
|
read_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
|
|
if (cpufreq_driver) {
|
|
/* get the CPU */
|
|
policy = cpufreq_cpu_get_raw(cpu);
|
|
if (policy)
|
|
kobject_get(&policy->kobj);
|
|
}
|
|
|
|
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
|
|
return policy;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
|
|
|
|
/**
|
|
* cpufreq_cpu_put - Decrement kobject usage counter for cpufreq policy.
|
|
* @policy: cpufreq policy returned by cpufreq_cpu_get().
|
|
*/
|
|
void cpufreq_cpu_put(struct cpufreq_policy *policy)
|
|
{
|
|
kobject_put(&policy->kobj);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
|
|
|
|
/**
|
|
* cpufreq_cpu_release - Unlock a policy and decrement its usage counter.
|
|
* @policy: cpufreq policy returned by cpufreq_cpu_acquire().
|
|
*/
|
|
void cpufreq_cpu_release(struct cpufreq_policy *policy)
|
|
{
|
|
if (WARN_ON(!policy))
|
|
return;
|
|
|
|
lockdep_assert_held(&policy->rwsem);
|
|
|
|
up_write(&policy->rwsem);
|
|
|
|
cpufreq_cpu_put(policy);
|
|
}
|
|
|
|
/**
|
|
* cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.
|
|
* @cpu: CPU to find the policy for.
|
|
*
|
|
* Call cpufreq_cpu_get() to get a reference on the cpufreq policy for @cpu and
|
|
* if the policy returned by it is not NULL, acquire its rwsem for writing.
|
|
* Return the policy if it is active or release it and return NULL otherwise.
|
|
*
|
|
* The policy returned by this function has to be released with the help of
|
|
* cpufreq_cpu_release() in order to release its rwsem and balance its usage
|
|
* counter properly.
|
|
*/
|
|
struct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
|
|
|
|
if (!policy)
|
|
return NULL;
|
|
|
|
down_write(&policy->rwsem);
|
|
|
|
if (policy_is_inactive(policy)) {
|
|
cpufreq_cpu_release(policy);
|
|
return NULL;
|
|
}
|
|
|
|
return policy;
|
|
}
|
|
|
|
/*********************************************************************
|
|
* EXTERNALLY AFFECTING FREQUENCY CHANGES *
|
|
*********************************************************************/
|
|
|
|
/*
|
|
* adjust_jiffies - adjust the system "loops_per_jiffy"
|
|
*
|
|
* This function alters the system "loops_per_jiffy" for the clock
|
|
* speed change. Note that loops_per_jiffy cannot be updated on SMP
|
|
* systems as each CPU might be scaled differently. So, use the arch
|
|
* per-CPU loops_per_jiffy value wherever possible.
|
|
*/
|
|
static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
|
|
{
|
|
#ifndef CONFIG_SMP
|
|
static unsigned long l_p_j_ref;
|
|
static unsigned int l_p_j_ref_freq;
|
|
|
|
if (ci->flags & CPUFREQ_CONST_LOOPS)
|
|
return;
|
|
|
|
if (!l_p_j_ref_freq) {
|
|
l_p_j_ref = loops_per_jiffy;
|
|
l_p_j_ref_freq = ci->old;
|
|
pr_debug("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n",
|
|
l_p_j_ref, l_p_j_ref_freq);
|
|
}
|
|
if (val == CPUFREQ_POSTCHANGE && ci->old != ci->new) {
|
|
loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
|
|
ci->new);
|
|
pr_debug("scaling loops_per_jiffy to %lu for frequency %u kHz\n",
|
|
loops_per_jiffy, ci->new);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/**
|
|
* cpufreq_notify_transition - Notify frequency transition and adjust_jiffies.
|
|
* @policy: cpufreq policy to enable fast frequency switching for.
|
|
* @freqs: contain details of the frequency update.
|
|
* @state: set to CPUFREQ_PRECHANGE or CPUFREQ_POSTCHANGE.
|
|
*
|
|
* This function calls the transition notifiers and the "adjust_jiffies"
|
|
* function. It is called twice on all CPU frequency changes that have
|
|
* external effects.
|
|
*/
|
|
static void cpufreq_notify_transition(struct cpufreq_policy *policy,
|
|
struct cpufreq_freqs *freqs,
|
|
unsigned int state)
|
|
{
|
|
int cpu;
|
|
|
|
BUG_ON(irqs_disabled());
|
|
|
|
if (cpufreq_disabled())
|
|
return;
|
|
|
|
freqs->policy = policy;
|
|
freqs->flags = cpufreq_driver->flags;
|
|
pr_debug("notification %u of frequency transition to %u kHz\n",
|
|
state, freqs->new);
|
|
|
|
switch (state) {
|
|
case CPUFREQ_PRECHANGE:
|
|
/*
|
|
* Detect if the driver reported a value as "old frequency"
|
|
* which is not equal to what the cpufreq core thinks is
|
|
* "old frequency".
|
|
*/
|
|
if (policy->cur && policy->cur != freqs->old) {
|
|
pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",
|
|
freqs->old, policy->cur);
|
|
freqs->old = policy->cur;
|
|
}
|
|
|
|
srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
|
|
CPUFREQ_PRECHANGE, freqs);
|
|
|
|
adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
|
|
break;
|
|
|
|
case CPUFREQ_POSTCHANGE:
|
|
adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
|
|
pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new,
|
|
cpumask_pr_args(policy->cpus));
|
|
|
|
for_each_cpu(cpu, policy->cpus)
|
|
trace_cpu_frequency(freqs->new, cpu);
|
|
|
|
srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
|
|
CPUFREQ_POSTCHANGE, freqs);
|
|
|
|
cpufreq_stats_record_transition(policy, freqs->new);
|
|
cpufreq_times_record_transition(policy, freqs->new);
|
|
policy->cur = freqs->new;
|
|
trace_android_rvh_cpufreq_transition(policy);
|
|
}
|
|
}
|
|
|
|
/* Do post notifications when there are chances that transition has failed */
|
|
static void cpufreq_notify_post_transition(struct cpufreq_policy *policy,
|
|
struct cpufreq_freqs *freqs, int transition_failed)
|
|
{
|
|
cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE);
|
|
if (!transition_failed)
|
|
return;
|
|
|
|
swap(freqs->old, freqs->new);
|
|
cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
|
|
cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE);
|
|
}
|
|
|
|
void cpufreq_freq_transition_begin(struct cpufreq_policy *policy,
|
|
struct cpufreq_freqs *freqs)
|
|
{
|
|
|
|
/*
|
|
* Catch double invocations of _begin() which lead to self-deadlock.
|
|
* ASYNC_NOTIFICATION drivers are left out because the cpufreq core
|
|
* doesn't invoke _begin() on their behalf, and hence the chances of
|
|
* double invocations are very low. Moreover, there are scenarios
|
|
* where these checks can emit false-positive warnings in these
|
|
* drivers; so we avoid that by skipping them altogether.
|
|
*/
|
|
WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION)
|
|
&& current == policy->transition_task);
|
|
|
|
wait:
|
|
wait_event(policy->transition_wait, !policy->transition_ongoing);
|
|
|
|
spin_lock(&policy->transition_lock);
|
|
|
|
if (unlikely(policy->transition_ongoing)) {
|
|
spin_unlock(&policy->transition_lock);
|
|
goto wait;
|
|
}
|
|
|
|
policy->transition_ongoing = true;
|
|
policy->transition_task = current;
|
|
|
|
spin_unlock(&policy->transition_lock);
|
|
|
|
cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_freq_transition_begin);
|
|
|
|
void cpufreq_freq_transition_end(struct cpufreq_policy *policy,
|
|
struct cpufreq_freqs *freqs, int transition_failed)
|
|
{
|
|
if (WARN_ON(!policy->transition_ongoing))
|
|
return;
|
|
|
|
cpufreq_notify_post_transition(policy, freqs, transition_failed);
|
|
|
|
arch_set_freq_scale(policy->related_cpus,
|
|
policy->cur,
|
|
policy->cpuinfo.max_freq);
|
|
|
|
policy->transition_ongoing = false;
|
|
policy->transition_task = NULL;
|
|
|
|
wake_up(&policy->transition_wait);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_freq_transition_end);
|
|
|
|
/*
|
|
* Fast frequency switching status count. Positive means "enabled", negative
|
|
* means "disabled" and 0 means "not decided yet".
|
|
*/
|
|
static int cpufreq_fast_switch_count;
|
|
static DEFINE_MUTEX(cpufreq_fast_switch_lock);
|
|
|
|
static void cpufreq_list_transition_notifiers(void)
|
|
{
|
|
struct notifier_block *nb;
|
|
|
|
pr_info("Registered transition notifiers:\n");
|
|
|
|
mutex_lock(&cpufreq_transition_notifier_list.mutex);
|
|
|
|
for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next)
|
|
pr_info("%pS\n", nb->notifier_call);
|
|
|
|
mutex_unlock(&cpufreq_transition_notifier_list.mutex);
|
|
}
|
|
|
|
/**
|
|
* cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
|
|
* @policy: cpufreq policy to enable fast frequency switching for.
|
|
*
|
|
* Try to enable fast frequency switching for @policy.
|
|
*
|
|
* The attempt will fail if there is at least one transition notifier registered
|
|
* at this point, as fast frequency switching is quite fundamentally at odds
|
|
* with transition notifiers. Thus if successful, it will make registration of
|
|
* transition notifiers fail going forward.
|
|
*/
|
|
void cpufreq_enable_fast_switch(struct cpufreq_policy *policy)
|
|
{
|
|
lockdep_assert_held(&policy->rwsem);
|
|
|
|
if (!policy->fast_switch_possible)
|
|
return;
|
|
|
|
mutex_lock(&cpufreq_fast_switch_lock);
|
|
if (cpufreq_fast_switch_count >= 0) {
|
|
cpufreq_fast_switch_count++;
|
|
policy->fast_switch_enabled = true;
|
|
} else {
|
|
pr_warn("CPU%u: Fast frequency switching not enabled\n",
|
|
policy->cpu);
|
|
cpufreq_list_transition_notifiers();
|
|
}
|
|
mutex_unlock(&cpufreq_fast_switch_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_enable_fast_switch);
|
|
|
|
/**
|
|
* cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
|
|
* @policy: cpufreq policy to disable fast frequency switching for.
|
|
*/
|
|
void cpufreq_disable_fast_switch(struct cpufreq_policy *policy)
|
|
{
|
|
mutex_lock(&cpufreq_fast_switch_lock);
|
|
if (policy->fast_switch_enabled) {
|
|
policy->fast_switch_enabled = false;
|
|
if (!WARN_ON(cpufreq_fast_switch_count <= 0))
|
|
cpufreq_fast_switch_count--;
|
|
}
|
|
mutex_unlock(&cpufreq_fast_switch_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);
|
|
|
|
/**
|
|
* cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
|
|
* one.
|
|
* @policy: associated policy to interrogate
|
|
* @target_freq: target frequency to resolve.
|
|
*
|
|
* The target to driver frequency mapping is cached in the policy.
|
|
*
|
|
* Return: Lowest driver-supported frequency greater than or equal to the
|
|
* given target_freq, subject to policy (min/max) and driver limitations.
|
|
*/
|
|
unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
|
|
unsigned int target_freq)
|
|
{
|
|
target_freq = clamp_val(target_freq, policy->min, policy->max);
|
|
policy->cached_target_freq = target_freq;
|
|
|
|
if (cpufreq_driver->target_index) {
|
|
unsigned int idx;
|
|
|
|
idx = cpufreq_frequency_table_target(policy, target_freq,
|
|
CPUFREQ_RELATION_L);
|
|
policy->cached_resolved_idx = idx;
|
|
return policy->freq_table[idx].frequency;
|
|
}
|
|
|
|
if (cpufreq_driver->resolve_freq)
|
|
return cpufreq_driver->resolve_freq(policy, target_freq);
|
|
|
|
return target_freq;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq);
|
|
|
|
unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy)
|
|
{
|
|
unsigned int latency;
|
|
|
|
if (policy->transition_delay_us)
|
|
return policy->transition_delay_us;
|
|
|
|
latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC;
|
|
if (latency) {
|
|
/*
|
|
* For platforms that can change the frequency very fast (< 10
|
|
* us), the above formula gives a decent transition delay. But
|
|
* for platforms where transition_latency is in milliseconds, it
|
|
* ends up giving unrealistic values.
|
|
*
|
|
* Cap the default transition delay to 10 ms, which seems to be
|
|
* a reasonable amount of time after which we should reevaluate
|
|
* the frequency.
|
|
*/
|
|
return min(latency * LATENCY_MULTIPLIER, (unsigned int)10000);
|
|
}
|
|
|
|
return LATENCY_MULTIPLIER;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_policy_transition_delay_us);
|
|
|
|
/*********************************************************************
|
|
* SYSFS INTERFACE *
|
|
*********************************************************************/
|
|
static ssize_t show_boost(struct kobject *kobj,
|
|
struct kobj_attribute *attr, char *buf)
|
|
{
|
|
return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
|
|
}
|
|
|
|
static ssize_t store_boost(struct kobject *kobj, struct kobj_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
int ret, enable;
|
|
|
|
ret = sscanf(buf, "%d", &enable);
|
|
if (ret != 1 || enable < 0 || enable > 1)
|
|
return -EINVAL;
|
|
|
|
if (cpufreq_boost_trigger_state(enable)) {
|
|
pr_err("%s: Cannot %s BOOST!\n",
|
|
__func__, enable ? "enable" : "disable");
|
|
return -EINVAL;
|
|
}
|
|
|
|
pr_debug("%s: cpufreq BOOST %s\n",
|
|
__func__, enable ? "enabled" : "disabled");
|
|
|
|
return count;
|
|
}
|
|
define_one_global_rw(boost);
|
|
|
|
static struct cpufreq_governor *find_governor(const char *str_governor)
|
|
{
|
|
struct cpufreq_governor *t;
|
|
|
|
for_each_governor(t)
|
|
if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN))
|
|
return t;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static struct cpufreq_governor *get_governor(const char *str_governor)
|
|
{
|
|
struct cpufreq_governor *t;
|
|
|
|
mutex_lock(&cpufreq_governor_mutex);
|
|
t = find_governor(str_governor);
|
|
if (!t)
|
|
goto unlock;
|
|
|
|
if (!try_module_get(t->owner))
|
|
t = NULL;
|
|
|
|
unlock:
|
|
mutex_unlock(&cpufreq_governor_mutex);
|
|
|
|
return t;
|
|
}
|
|
|
|
static unsigned int cpufreq_parse_policy(char *str_governor)
|
|
{
|
|
if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN))
|
|
return CPUFREQ_POLICY_PERFORMANCE;
|
|
|
|
if (!strncasecmp(str_governor, "powersave", CPUFREQ_NAME_LEN))
|
|
return CPUFREQ_POLICY_POWERSAVE;
|
|
|
|
return CPUFREQ_POLICY_UNKNOWN;
|
|
}
|
|
|
|
/**
|
|
* cpufreq_parse_governor - parse a governor string only for has_target()
|
|
* @str_governor: Governor name.
|
|
*/
|
|
static struct cpufreq_governor *cpufreq_parse_governor(char *str_governor)
|
|
{
|
|
struct cpufreq_governor *t;
|
|
|
|
t = get_governor(str_governor);
|
|
if (t)
|
|
return t;
|
|
|
|
if (request_module("cpufreq_%s", str_governor))
|
|
return NULL;
|
|
|
|
return get_governor(str_governor);
|
|
}
|
|
|
|
/*
|
|
* cpufreq_per_cpu_attr_read() / show_##file_name() -
|
|
* print out cpufreq information
|
|
*
|
|
* Write out information from cpufreq_driver->policy[cpu]; object must be
|
|
* "unsigned int".
|
|
*/
|
|
|
|
#define show_one(file_name, object) \
|
|
static ssize_t show_##file_name \
|
|
(struct cpufreq_policy *policy, char *buf) \
|
|
{ \
|
|
return sprintf(buf, "%u\n", policy->object); \
|
|
}
|
|
|
|
static ssize_t show_cpuinfo_max_freq(struct cpufreq_policy *policy, char *buf)
|
|
{
|
|
unsigned int max_freq = policy->cpuinfo.max_freq;
|
|
|
|
trace_android_vh_show_max_freq(policy, &max_freq);
|
|
return sprintf(buf, "%u\n", max_freq);
|
|
}
|
|
|
|
show_one(cpuinfo_min_freq, cpuinfo.min_freq);
|
|
show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
|
|
show_one(scaling_min_freq, min);
|
|
show_one(scaling_max_freq, max);
|
|
|
|
__weak unsigned int arch_freq_get_on_cpu(int cpu)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf)
|
|
{
|
|
ssize_t ret;
|
|
unsigned int freq;
|
|
|
|
freq = arch_freq_get_on_cpu(policy->cpu);
|
|
if (freq)
|
|
ret = sprintf(buf, "%u\n", freq);
|
|
else if (cpufreq_driver->setpolicy && cpufreq_driver->get)
|
|
ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu));
|
|
else
|
|
ret = sprintf(buf, "%u\n", policy->cur);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
|
|
*/
|
|
#define store_one(file_name, object) \
|
|
static ssize_t store_##file_name \
|
|
(struct cpufreq_policy *policy, const char *buf, size_t count) \
|
|
{ \
|
|
unsigned long val; \
|
|
int ret; \
|
|
\
|
|
ret = sscanf(buf, "%lu", &val); \
|
|
if (ret != 1) \
|
|
return -EINVAL; \
|
|
\
|
|
ret = freq_qos_update_request(policy->object##_freq_req, val);\
|
|
return ret >= 0 ? count : ret; \
|
|
}
|
|
|
|
store_one(scaling_min_freq, min);
|
|
store_one(scaling_max_freq, max);
|
|
|
|
/*
|
|
* show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
|
|
*/
|
|
static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
|
|
char *buf)
|
|
{
|
|
unsigned int cur_freq = __cpufreq_get(policy);
|
|
|
|
if (cur_freq)
|
|
return sprintf(buf, "%u\n", cur_freq);
|
|
|
|
return sprintf(buf, "<unknown>\n");
|
|
}
|
|
|
|
/*
|
|
* show_scaling_governor - show the current policy for the specified CPU
|
|
*/
|
|
static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
|
|
{
|
|
if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
|
|
return sprintf(buf, "powersave\n");
|
|
else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
|
|
return sprintf(buf, "performance\n");
|
|
else if (policy->governor)
|
|
return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n",
|
|
policy->governor->name);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/*
|
|
* store_scaling_governor - store policy for the specified CPU
|
|
*/
|
|
static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
|
|
const char *buf, size_t count)
|
|
{
|
|
char str_governor[16];
|
|
int ret;
|
|
|
|
ret = sscanf(buf, "%15s", str_governor);
|
|
if (ret != 1)
|
|
return -EINVAL;
|
|
|
|
if (cpufreq_driver->setpolicy) {
|
|
unsigned int new_pol;
|
|
|
|
new_pol = cpufreq_parse_policy(str_governor);
|
|
if (!new_pol)
|
|
return -EINVAL;
|
|
|
|
ret = cpufreq_set_policy(policy, NULL, new_pol);
|
|
} else {
|
|
struct cpufreq_governor *new_gov;
|
|
|
|
new_gov = cpufreq_parse_governor(str_governor);
|
|
if (!new_gov)
|
|
return -EINVAL;
|
|
|
|
ret = cpufreq_set_policy(policy, new_gov,
|
|
CPUFREQ_POLICY_UNKNOWN);
|
|
|
|
module_put(new_gov->owner);
|
|
}
|
|
|
|
return ret ? ret : count;
|
|
}
|
|
|
|
/*
|
|
* show_scaling_driver - show the cpufreq driver currently loaded
|
|
*/
|
|
static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
|
|
{
|
|
return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
|
|
}
|
|
|
|
/*
|
|
* show_scaling_available_governors - show the available CPUfreq governors
|
|
*/
|
|
static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
|
|
char *buf)
|
|
{
|
|
ssize_t i = 0;
|
|
struct cpufreq_governor *t;
|
|
|
|
if (!has_target()) {
|
|
i += sprintf(buf, "performance powersave");
|
|
goto out;
|
|
}
|
|
|
|
mutex_lock(&cpufreq_governor_mutex);
|
|
for_each_governor(t) {
|
|
if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
|
|
- (CPUFREQ_NAME_LEN + 2)))
|
|
break;
|
|
i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name);
|
|
}
|
|
mutex_unlock(&cpufreq_governor_mutex);
|
|
out:
|
|
i += sprintf(&buf[i], "\n");
|
|
return i;
|
|
}
|
|
|
|
ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf)
|
|
{
|
|
ssize_t i = 0;
|
|
unsigned int cpu;
|
|
|
|
for_each_cpu(cpu, mask) {
|
|
if (i)
|
|
i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
|
|
i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
|
|
if (i >= (PAGE_SIZE - 5))
|
|
break;
|
|
}
|
|
i += sprintf(&buf[i], "\n");
|
|
return i;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_show_cpus);
|
|
|
|
/*
|
|
* show_related_cpus - show the CPUs affected by each transition even if
|
|
* hw coordination is in use
|
|
*/
|
|
static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
|
|
{
|
|
return cpufreq_show_cpus(policy->related_cpus, buf);
|
|
}
|
|
|
|
/*
|
|
* show_affected_cpus - show the CPUs affected by each transition
|
|
*/
|
|
static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
|
|
{
|
|
return cpufreq_show_cpus(policy->cpus, buf);
|
|
}
|
|
|
|
static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
|
|
const char *buf, size_t count)
|
|
{
|
|
unsigned int freq = 0;
|
|
unsigned int ret;
|
|
|
|
if (!policy->governor || !policy->governor->store_setspeed)
|
|
return -EINVAL;
|
|
|
|
ret = sscanf(buf, "%u", &freq);
|
|
if (ret != 1)
|
|
return -EINVAL;
|
|
|
|
policy->governor->store_setspeed(policy, freq);
|
|
|
|
return count;
|
|
}
|
|
|
|
static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
|
|
{
|
|
if (!policy->governor || !policy->governor->show_setspeed)
|
|
return sprintf(buf, "<unsupported>\n");
|
|
|
|
return policy->governor->show_setspeed(policy, buf);
|
|
}
|
|
|
|
/*
|
|
* show_bios_limit - show the current cpufreq HW/BIOS limitation
|
|
*/
|
|
static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
|
|
{
|
|
unsigned int limit;
|
|
int ret;
|
|
ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
|
|
if (!ret)
|
|
return sprintf(buf, "%u\n", limit);
|
|
return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
|
|
}
|
|
|
|
cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
|
|
cpufreq_freq_attr_ro(cpuinfo_min_freq);
|
|
cpufreq_freq_attr_ro(cpuinfo_max_freq);
|
|
cpufreq_freq_attr_ro(cpuinfo_transition_latency);
|
|
cpufreq_freq_attr_ro(scaling_available_governors);
|
|
cpufreq_freq_attr_ro(scaling_driver);
|
|
cpufreq_freq_attr_ro(scaling_cur_freq);
|
|
cpufreq_freq_attr_ro(bios_limit);
|
|
cpufreq_freq_attr_ro(related_cpus);
|
|
cpufreq_freq_attr_ro(affected_cpus);
|
|
cpufreq_freq_attr_rw(scaling_min_freq);
|
|
cpufreq_freq_attr_rw(scaling_max_freq);
|
|
cpufreq_freq_attr_rw(scaling_governor);
|
|
cpufreq_freq_attr_rw(scaling_setspeed);
|
|
|
|
static struct attribute *default_attrs[] = {
|
|
&cpuinfo_min_freq.attr,
|
|
&cpuinfo_max_freq.attr,
|
|
&cpuinfo_transition_latency.attr,
|
|
&scaling_min_freq.attr,
|
|
&scaling_max_freq.attr,
|
|
&affected_cpus.attr,
|
|
&related_cpus.attr,
|
|
&scaling_governor.attr,
|
|
&scaling_driver.attr,
|
|
&scaling_available_governors.attr,
|
|
&scaling_setspeed.attr,
|
|
NULL
|
|
};
|
|
|
|
#define to_policy(k) container_of(k, struct cpufreq_policy, kobj)
|
|
#define to_attr(a) container_of(a, struct freq_attr, attr)
|
|
|
|
static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
|
|
{
|
|
struct cpufreq_policy *policy = to_policy(kobj);
|
|
struct freq_attr *fattr = to_attr(attr);
|
|
ssize_t ret;
|
|
|
|
if (!fattr->show)
|
|
return -EIO;
|
|
|
|
down_read(&policy->rwsem);
|
|
ret = fattr->show(policy, buf);
|
|
up_read(&policy->rwsem);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static ssize_t store(struct kobject *kobj, struct attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct cpufreq_policy *policy = to_policy(kobj);
|
|
struct freq_attr *fattr = to_attr(attr);
|
|
ssize_t ret = -EINVAL;
|
|
|
|
if (!fattr->store)
|
|
return -EIO;
|
|
|
|
/*
|
|
* cpus_read_trylock() is used here to work around a circular lock
|
|
* dependency problem with respect to the cpufreq_register_driver().
|
|
*/
|
|
if (!cpus_read_trylock())
|
|
return -EBUSY;
|
|
|
|
if (cpu_online(policy->cpu)) {
|
|
down_write(&policy->rwsem);
|
|
ret = fattr->store(policy, buf, count);
|
|
up_write(&policy->rwsem);
|
|
}
|
|
|
|
cpus_read_unlock();
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void cpufreq_sysfs_release(struct kobject *kobj)
|
|
{
|
|
struct cpufreq_policy *policy = to_policy(kobj);
|
|
pr_debug("last reference is dropped\n");
|
|
complete(&policy->kobj_unregister);
|
|
}
|
|
|
|
static const struct sysfs_ops sysfs_ops = {
|
|
.show = show,
|
|
.store = store,
|
|
};
|
|
|
|
static struct kobj_type ktype_cpufreq = {
|
|
.sysfs_ops = &sysfs_ops,
|
|
.default_attrs = default_attrs,
|
|
.release = cpufreq_sysfs_release,
|
|
};
|
|
|
|
static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu)
|
|
{
|
|
struct device *dev = get_cpu_device(cpu);
|
|
|
|
if (unlikely(!dev))
|
|
return;
|
|
|
|
if (cpumask_test_and_set_cpu(cpu, policy->real_cpus))
|
|
return;
|
|
|
|
dev_dbg(dev, "%s: Adding symlink\n", __func__);
|
|
if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"))
|
|
dev_err(dev, "cpufreq symlink creation failed\n");
|
|
}
|
|
|
|
static void remove_cpu_dev_symlink(struct cpufreq_policy *policy,
|
|
struct device *dev)
|
|
{
|
|
dev_dbg(dev, "%s: Removing symlink\n", __func__);
|
|
sysfs_remove_link(&dev->kobj, "cpufreq");
|
|
}
|
|
|
|
static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
|
|
{
|
|
struct freq_attr **drv_attr;
|
|
int ret = 0;
|
|
|
|
/* set up files for this cpu device */
|
|
drv_attr = cpufreq_driver->attr;
|
|
while (drv_attr && *drv_attr) {
|
|
ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
|
|
if (ret)
|
|
return ret;
|
|
drv_attr++;
|
|
}
|
|
if (cpufreq_driver->get) {
|
|
ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (cpufreq_driver->bios_limit) {
|
|
ret = sysfs_create_file(&policy->kobj, &bios_limit.attr);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int cpufreq_init_policy(struct cpufreq_policy *policy)
|
|
{
|
|
struct cpufreq_governor *gov = NULL;
|
|
unsigned int pol = CPUFREQ_POLICY_UNKNOWN;
|
|
int ret;
|
|
|
|
if (has_target()) {
|
|
/* Update policy governor to the one used before hotplug. */
|
|
gov = get_governor(policy->last_governor);
|
|
if (gov) {
|
|
pr_debug("Restoring governor %s for cpu %d\n",
|
|
gov->name, policy->cpu);
|
|
} else {
|
|
gov = get_governor(default_governor);
|
|
}
|
|
|
|
if (!gov) {
|
|
gov = cpufreq_default_governor();
|
|
__module_get(gov->owner);
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Use the default policy if there is no last_policy. */
|
|
if (policy->last_policy) {
|
|
pol = policy->last_policy;
|
|
} else {
|
|
pol = cpufreq_parse_policy(default_governor);
|
|
/*
|
|
* In case the default governor is neither "performance"
|
|
* nor "powersave", fall back to the initial policy
|
|
* value set by the driver.
|
|
*/
|
|
if (pol == CPUFREQ_POLICY_UNKNOWN)
|
|
pol = policy->policy;
|
|
}
|
|
if (pol != CPUFREQ_POLICY_PERFORMANCE &&
|
|
pol != CPUFREQ_POLICY_POWERSAVE)
|
|
return -ENODATA;
|
|
}
|
|
|
|
ret = cpufreq_set_policy(policy, gov, pol);
|
|
if (gov)
|
|
module_put(gov->owner);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
|
|
{
|
|
int ret = 0;
|
|
|
|
/* Has this CPU been taken care of already? */
|
|
if (cpumask_test_cpu(cpu, policy->cpus))
|
|
return 0;
|
|
|
|
down_write(&policy->rwsem);
|
|
if (has_target())
|
|
cpufreq_stop_governor(policy);
|
|
|
|
cpumask_set_cpu(cpu, policy->cpus);
|
|
|
|
if (has_target()) {
|
|
ret = cpufreq_start_governor(policy);
|
|
if (ret)
|
|
pr_err("%s: Failed to start governor\n", __func__);
|
|
}
|
|
up_write(&policy->rwsem);
|
|
return ret;
|
|
}
|
|
|
|
void refresh_frequency_limits(struct cpufreq_policy *policy)
|
|
{
|
|
if (!policy_is_inactive(policy)) {
|
|
pr_debug("updating policy for CPU %u\n", policy->cpu);
|
|
|
|
cpufreq_set_policy(policy, policy->governor, policy->policy);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(refresh_frequency_limits);
|
|
|
|
static void handle_update(struct work_struct *work)
|
|
{
|
|
struct cpufreq_policy *policy =
|
|
container_of(work, struct cpufreq_policy, update);
|
|
|
|
pr_debug("handle_update for cpu %u called\n", policy->cpu);
|
|
down_write(&policy->rwsem);
|
|
refresh_frequency_limits(policy);
|
|
up_write(&policy->rwsem);
|
|
}
|
|
|
|
static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq,
|
|
void *data)
|
|
{
|
|
struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min);
|
|
|
|
schedule_work(&policy->update);
|
|
return 0;
|
|
}
|
|
|
|
static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq,
|
|
void *data)
|
|
{
|
|
struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max);
|
|
|
|
schedule_work(&policy->update);
|
|
return 0;
|
|
}
|
|
|
|
static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy)
|
|
{
|
|
struct kobject *kobj;
|
|
struct completion *cmp;
|
|
|
|
down_write(&policy->rwsem);
|
|
cpufreq_stats_free_table(policy);
|
|
kobj = &policy->kobj;
|
|
cmp = &policy->kobj_unregister;
|
|
up_write(&policy->rwsem);
|
|
kobject_put(kobj);
|
|
|
|
/*
|
|
* We need to make sure that the underlying kobj is
|
|
* actually not referenced anymore by anybody before we
|
|
* proceed with unloading.
|
|
*/
|
|
pr_debug("waiting for dropping of refcount\n");
|
|
wait_for_completion(cmp);
|
|
pr_debug("wait complete\n");
|
|
}
|
|
|
|
static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
struct device *dev = get_cpu_device(cpu);
|
|
int ret;
|
|
|
|
if (!dev)
|
|
return NULL;
|
|
|
|
policy = kzalloc(sizeof(*policy), GFP_KERNEL);
|
|
if (!policy)
|
|
return NULL;
|
|
|
|
if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
|
|
goto err_free_policy;
|
|
|
|
if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
|
|
goto err_free_cpumask;
|
|
|
|
if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL))
|
|
goto err_free_rcpumask;
|
|
|
|
ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
|
|
cpufreq_global_kobject, "policy%u", cpu);
|
|
if (ret) {
|
|
dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret);
|
|
/*
|
|
* The entire policy object will be freed below, but the extra
|
|
* memory allocated for the kobject name needs to be freed by
|
|
* releasing the kobject.
|
|
*/
|
|
kobject_put(&policy->kobj);
|
|
goto err_free_real_cpus;
|
|
}
|
|
|
|
freq_constraints_init(&policy->constraints);
|
|
|
|
policy->nb_min.notifier_call = cpufreq_notifier_min;
|
|
policy->nb_max.notifier_call = cpufreq_notifier_max;
|
|
|
|
ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN,
|
|
&policy->nb_min);
|
|
if (ret) {
|
|
dev_err(dev, "Failed to register MIN QoS notifier: %d (%*pbl)\n",
|
|
ret, cpumask_pr_args(policy->cpus));
|
|
goto err_kobj_remove;
|
|
}
|
|
|
|
ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX,
|
|
&policy->nb_max);
|
|
if (ret) {
|
|
dev_err(dev, "Failed to register MAX QoS notifier: %d (%*pbl)\n",
|
|
ret, cpumask_pr_args(policy->cpus));
|
|
goto err_min_qos_notifier;
|
|
}
|
|
|
|
INIT_LIST_HEAD(&policy->policy_list);
|
|
init_rwsem(&policy->rwsem);
|
|
spin_lock_init(&policy->transition_lock);
|
|
init_waitqueue_head(&policy->transition_wait);
|
|
init_completion(&policy->kobj_unregister);
|
|
INIT_WORK(&policy->update, handle_update);
|
|
|
|
policy->cpu = cpu;
|
|
return policy;
|
|
|
|
err_min_qos_notifier:
|
|
freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
|
|
&policy->nb_min);
|
|
err_kobj_remove:
|
|
cpufreq_policy_put_kobj(policy);
|
|
err_free_real_cpus:
|
|
free_cpumask_var(policy->real_cpus);
|
|
err_free_rcpumask:
|
|
free_cpumask_var(policy->related_cpus);
|
|
err_free_cpumask:
|
|
free_cpumask_var(policy->cpus);
|
|
err_free_policy:
|
|
kfree(policy);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static void cpufreq_policy_free(struct cpufreq_policy *policy)
|
|
{
|
|
unsigned long flags;
|
|
int cpu;
|
|
|
|
/* Remove policy from list */
|
|
write_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
list_del(&policy->policy_list);
|
|
|
|
for_each_cpu(cpu, policy->related_cpus)
|
|
per_cpu(cpufreq_cpu_data, cpu) = NULL;
|
|
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
|
|
freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX,
|
|
&policy->nb_max);
|
|
freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
|
|
&policy->nb_min);
|
|
|
|
/* Cancel any pending policy->update work before freeing the policy. */
|
|
cancel_work_sync(&policy->update);
|
|
|
|
if (policy->max_freq_req) {
|
|
/*
|
|
* CPUFREQ_CREATE_POLICY notification is sent only after
|
|
* successfully adding max_freq_req request.
|
|
*/
|
|
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
|
|
CPUFREQ_REMOVE_POLICY, policy);
|
|
freq_qos_remove_request(policy->max_freq_req);
|
|
}
|
|
|
|
freq_qos_remove_request(policy->min_freq_req);
|
|
kfree(policy->min_freq_req);
|
|
|
|
cpufreq_policy_put_kobj(policy);
|
|
free_cpumask_var(policy->real_cpus);
|
|
free_cpumask_var(policy->related_cpus);
|
|
free_cpumask_var(policy->cpus);
|
|
kfree(policy);
|
|
}
|
|
|
|
static int cpufreq_online(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
bool new_policy;
|
|
unsigned long flags;
|
|
unsigned int j;
|
|
int ret;
|
|
|
|
pr_debug("%s: bringing CPU%u online\n", __func__, cpu);
|
|
|
|
/* Check if this CPU already has a policy to manage it */
|
|
policy = per_cpu(cpufreq_cpu_data, cpu);
|
|
if (policy) {
|
|
WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus));
|
|
if (!policy_is_inactive(policy))
|
|
return cpufreq_add_policy_cpu(policy, cpu);
|
|
|
|
/* This is the only online CPU for the policy. Start over. */
|
|
new_policy = false;
|
|
down_write(&policy->rwsem);
|
|
policy->cpu = cpu;
|
|
policy->governor = NULL;
|
|
up_write(&policy->rwsem);
|
|
} else {
|
|
new_policy = true;
|
|
policy = cpufreq_policy_alloc(cpu);
|
|
if (!policy)
|
|
return -ENOMEM;
|
|
}
|
|
|
|
if (!new_policy && cpufreq_driver->online) {
|
|
ret = cpufreq_driver->online(policy);
|
|
if (ret) {
|
|
pr_debug("%s: %d: initialization failed\n", __func__,
|
|
__LINE__);
|
|
goto out_exit_policy;
|
|
}
|
|
|
|
/* Recover policy->cpus using related_cpus */
|
|
cpumask_copy(policy->cpus, policy->related_cpus);
|
|
} else {
|
|
cpumask_copy(policy->cpus, cpumask_of(cpu));
|
|
|
|
/*
|
|
* Call driver. From then on the cpufreq must be able
|
|
* to accept all calls to ->verify and ->setpolicy for this CPU.
|
|
*/
|
|
ret = cpufreq_driver->init(policy);
|
|
if (ret) {
|
|
pr_debug("%s: %d: initialization failed\n", __func__,
|
|
__LINE__);
|
|
goto out_free_policy;
|
|
}
|
|
|
|
/*
|
|
* The initialization has succeeded and the policy is online.
|
|
* If there is a problem with its frequency table, take it
|
|
* offline and drop it.
|
|
*/
|
|
ret = cpufreq_table_validate_and_sort(policy);
|
|
if (ret)
|
|
goto out_offline_policy;
|
|
|
|
/* related_cpus should at least include policy->cpus. */
|
|
cpumask_copy(policy->related_cpus, policy->cpus);
|
|
}
|
|
|
|
down_write(&policy->rwsem);
|
|
/*
|
|
* affected cpus must always be the one, which are online. We aren't
|
|
* managing offline cpus here.
|
|
*/
|
|
cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
|
|
|
|
if (new_policy) {
|
|
for_each_cpu(j, policy->related_cpus) {
|
|
per_cpu(cpufreq_cpu_data, j) = policy;
|
|
add_cpu_dev_symlink(policy, j);
|
|
}
|
|
|
|
policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req),
|
|
GFP_KERNEL);
|
|
if (!policy->min_freq_req)
|
|
goto out_destroy_policy;
|
|
|
|
ret = freq_qos_add_request(&policy->constraints,
|
|
policy->min_freq_req, FREQ_QOS_MIN,
|
|
policy->min);
|
|
if (ret < 0) {
|
|
/*
|
|
* So we don't call freq_qos_remove_request() for an
|
|
* uninitialized request.
|
|
*/
|
|
kfree(policy->min_freq_req);
|
|
policy->min_freq_req = NULL;
|
|
goto out_destroy_policy;
|
|
}
|
|
|
|
/*
|
|
* This must be initialized right here to avoid calling
|
|
* freq_qos_remove_request() on uninitialized request in case
|
|
* of errors.
|
|
*/
|
|
policy->max_freq_req = policy->min_freq_req + 1;
|
|
|
|
ret = freq_qos_add_request(&policy->constraints,
|
|
policy->max_freq_req, FREQ_QOS_MAX,
|
|
policy->max);
|
|
if (ret < 0) {
|
|
policy->max_freq_req = NULL;
|
|
goto out_destroy_policy;
|
|
}
|
|
|
|
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
|
|
CPUFREQ_CREATE_POLICY, policy);
|
|
}
|
|
|
|
if (cpufreq_driver->get && has_target()) {
|
|
policy->cur = cpufreq_driver->get(policy->cpu);
|
|
if (!policy->cur) {
|
|
pr_err("%s: ->get() failed\n", __func__);
|
|
goto out_destroy_policy;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Sometimes boot loaders set CPU frequency to a value outside of
|
|
* frequency table present with cpufreq core. In such cases CPU might be
|
|
* unstable if it has to run on that frequency for long duration of time
|
|
* and so its better to set it to a frequency which is specified in
|
|
* freq-table. This also makes cpufreq stats inconsistent as
|
|
* cpufreq-stats would fail to register because current frequency of CPU
|
|
* isn't found in freq-table.
|
|
*
|
|
* Because we don't want this change to effect boot process badly, we go
|
|
* for the next freq which is >= policy->cur ('cur' must be set by now,
|
|
* otherwise we will end up setting freq to lowest of the table as 'cur'
|
|
* is initialized to zero).
|
|
*
|
|
* We are passing target-freq as "policy->cur - 1" otherwise
|
|
* __cpufreq_driver_target() would simply fail, as policy->cur will be
|
|
* equal to target-freq.
|
|
*/
|
|
if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK)
|
|
&& has_target()) {
|
|
unsigned int old_freq = policy->cur;
|
|
|
|
/* Are we running at unknown frequency ? */
|
|
ret = cpufreq_frequency_table_get_index(policy, old_freq);
|
|
if (ret == -EINVAL) {
|
|
ret = __cpufreq_driver_target(policy, old_freq - 1,
|
|
CPUFREQ_RELATION_L);
|
|
|
|
/*
|
|
* Reaching here after boot in a few seconds may not
|
|
* mean that system will remain stable at "unknown"
|
|
* frequency for longer duration. Hence, a BUG_ON().
|
|
*/
|
|
BUG_ON(ret);
|
|
pr_info("%s: CPU%d: Running at unlisted initial frequency: %u KHz, changing to: %u KHz\n",
|
|
__func__, policy->cpu, old_freq, policy->cur);
|
|
}
|
|
}
|
|
|
|
if (new_policy) {
|
|
ret = cpufreq_add_dev_interface(policy);
|
|
if (ret)
|
|
goto out_destroy_policy;
|
|
|
|
cpufreq_stats_create_table(policy);
|
|
cpufreq_times_create_policy(policy);
|
|
|
|
write_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
list_add(&policy->policy_list, &cpufreq_policy_list);
|
|
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
}
|
|
|
|
ret = cpufreq_init_policy(policy);
|
|
if (ret) {
|
|
pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n",
|
|
__func__, cpu, ret);
|
|
goto out_destroy_policy;
|
|
}
|
|
|
|
up_write(&policy->rwsem);
|
|
|
|
kobject_uevent(&policy->kobj, KOBJ_ADD);
|
|
|
|
/* Callback for handling stuff after policy is ready */
|
|
if (cpufreq_driver->ready)
|
|
cpufreq_driver->ready(policy);
|
|
|
|
if (cpufreq_thermal_control_enabled(cpufreq_driver))
|
|
policy->cdev = of_cpufreq_cooling_register(policy);
|
|
|
|
pr_debug("initialization complete\n");
|
|
|
|
return 0;
|
|
|
|
out_destroy_policy:
|
|
for_each_cpu(j, policy->real_cpus)
|
|
remove_cpu_dev_symlink(policy, get_cpu_device(j));
|
|
|
|
up_write(&policy->rwsem);
|
|
|
|
out_offline_policy:
|
|
if (cpufreq_driver->offline)
|
|
cpufreq_driver->offline(policy);
|
|
|
|
out_exit_policy:
|
|
if (cpufreq_driver->exit)
|
|
cpufreq_driver->exit(policy);
|
|
|
|
out_free_policy:
|
|
cpufreq_policy_free(policy);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* cpufreq_add_dev - the cpufreq interface for a CPU device.
|
|
* @dev: CPU device.
|
|
* @sif: Subsystem interface structure pointer (not used)
|
|
*/
|
|
static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
unsigned cpu = dev->id;
|
|
int ret;
|
|
|
|
dev_dbg(dev, "%s: adding CPU%u\n", __func__, cpu);
|
|
|
|
if (cpu_online(cpu)) {
|
|
ret = cpufreq_online(cpu);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
/* Create sysfs link on CPU registration */
|
|
policy = per_cpu(cpufreq_cpu_data, cpu);
|
|
if (policy)
|
|
add_cpu_dev_symlink(policy, cpu);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int cpufreq_offline(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
int ret;
|
|
|
|
pr_debug("%s: unregistering CPU %u\n", __func__, cpu);
|
|
|
|
policy = cpufreq_cpu_get_raw(cpu);
|
|
if (!policy) {
|
|
pr_debug("%s: No cpu_data found\n", __func__);
|
|
return 0;
|
|
}
|
|
|
|
down_write(&policy->rwsem);
|
|
if (has_target())
|
|
cpufreq_stop_governor(policy);
|
|
|
|
cpumask_clear_cpu(cpu, policy->cpus);
|
|
|
|
if (policy_is_inactive(policy)) {
|
|
if (has_target())
|
|
strncpy(policy->last_governor, policy->governor->name,
|
|
CPUFREQ_NAME_LEN);
|
|
else
|
|
policy->last_policy = policy->policy;
|
|
} else if (cpu == policy->cpu) {
|
|
/* Nominate new CPU */
|
|
policy->cpu = cpumask_any(policy->cpus);
|
|
}
|
|
|
|
/* Start governor again for active policy */
|
|
if (!policy_is_inactive(policy)) {
|
|
if (has_target()) {
|
|
ret = cpufreq_start_governor(policy);
|
|
if (ret)
|
|
pr_err("%s: Failed to start governor\n", __func__);
|
|
}
|
|
|
|
goto unlock;
|
|
}
|
|
|
|
if (cpufreq_thermal_control_enabled(cpufreq_driver)) {
|
|
cpufreq_cooling_unregister(policy->cdev);
|
|
policy->cdev = NULL;
|
|
}
|
|
|
|
if (cpufreq_driver->stop_cpu)
|
|
cpufreq_driver->stop_cpu(policy);
|
|
|
|
if (has_target())
|
|
cpufreq_exit_governor(policy);
|
|
|
|
/*
|
|
* Perform the ->offline() during light-weight tear-down, as
|
|
* that allows fast recovery when the CPU comes back.
|
|
*/
|
|
if (cpufreq_driver->offline) {
|
|
cpufreq_driver->offline(policy);
|
|
} else if (cpufreq_driver->exit) {
|
|
cpufreq_driver->exit(policy);
|
|
policy->freq_table = NULL;
|
|
}
|
|
|
|
unlock:
|
|
up_write(&policy->rwsem);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* cpufreq_remove_dev - remove a CPU device
|
|
*
|
|
* Removes the cpufreq interface for a CPU device.
|
|
*/
|
|
static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
|
|
{
|
|
unsigned int cpu = dev->id;
|
|
struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
|
|
|
|
if (!policy)
|
|
return;
|
|
|
|
if (cpu_online(cpu))
|
|
cpufreq_offline(cpu);
|
|
|
|
cpumask_clear_cpu(cpu, policy->real_cpus);
|
|
remove_cpu_dev_symlink(policy, dev);
|
|
|
|
if (cpumask_empty(policy->real_cpus)) {
|
|
/* We did light-weight exit earlier, do full tear down now */
|
|
if (cpufreq_driver->offline)
|
|
cpufreq_driver->exit(policy);
|
|
|
|
cpufreq_policy_free(policy);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're
|
|
* in deep trouble.
|
|
* @policy: policy managing CPUs
|
|
* @new_freq: CPU frequency the CPU actually runs at
|
|
*
|
|
* We adjust to current frequency first, and need to clean up later.
|
|
* So either call to cpufreq_update_policy() or schedule handle_update()).
|
|
*/
|
|
static void cpufreq_out_of_sync(struct cpufreq_policy *policy,
|
|
unsigned int new_freq)
|
|
{
|
|
struct cpufreq_freqs freqs;
|
|
|
|
pr_debug("Warning: CPU frequency out of sync: cpufreq and timing core thinks of %u, is %u kHz\n",
|
|
policy->cur, new_freq);
|
|
|
|
freqs.old = policy->cur;
|
|
freqs.new = new_freq;
|
|
|
|
cpufreq_freq_transition_begin(policy, &freqs);
|
|
cpufreq_freq_transition_end(policy, &freqs, 0);
|
|
}
|
|
|
|
static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, bool update)
|
|
{
|
|
unsigned int new_freq;
|
|
|
|
new_freq = cpufreq_driver->get(policy->cpu);
|
|
if (!new_freq)
|
|
return 0;
|
|
|
|
/*
|
|
* If fast frequency switching is used with the given policy, the check
|
|
* against policy->cur is pointless, so skip it in that case.
|
|
*/
|
|
if (policy->fast_switch_enabled || !has_target())
|
|
return new_freq;
|
|
|
|
if (policy->cur != new_freq) {
|
|
cpufreq_out_of_sync(policy, new_freq);
|
|
if (update)
|
|
schedule_work(&policy->update);
|
|
}
|
|
|
|
return new_freq;
|
|
}
|
|
|
|
/**
|
|
* cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
|
|
* @cpu: CPU number
|
|
*
|
|
* This is the last known freq, without actually getting it from the driver.
|
|
* Return value will be same as what is shown in scaling_cur_freq in sysfs.
|
|
*/
|
|
unsigned int cpufreq_quick_get(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
unsigned int ret_freq = 0;
|
|
unsigned long flags;
|
|
|
|
read_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
|
|
if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) {
|
|
ret_freq = cpufreq_driver->get(cpu);
|
|
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
return ret_freq;
|
|
}
|
|
|
|
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
|
|
policy = cpufreq_cpu_get(cpu);
|
|
if (policy) {
|
|
ret_freq = policy->cur;
|
|
cpufreq_cpu_put(policy);
|
|
}
|
|
|
|
return ret_freq;
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_quick_get);
|
|
|
|
/**
|
|
* cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
|
|
* @cpu: CPU number
|
|
*
|
|
* Just return the max possible frequency for a given CPU.
|
|
*/
|
|
unsigned int cpufreq_quick_get_max(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
|
|
unsigned int ret_freq = 0;
|
|
|
|
if (policy) {
|
|
ret_freq = policy->max;
|
|
cpufreq_cpu_put(policy);
|
|
}
|
|
|
|
return ret_freq;
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_quick_get_max);
|
|
|
|
/**
|
|
* cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
|
|
* @cpu: CPU number
|
|
*
|
|
* The default return value is the max_freq field of cpuinfo.
|
|
*/
|
|
__weak unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
|
|
unsigned int ret_freq = 0;
|
|
|
|
if (policy) {
|
|
ret_freq = policy->cpuinfo.max_freq;
|
|
cpufreq_cpu_put(policy);
|
|
}
|
|
|
|
return ret_freq;
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_get_hw_max_freq);
|
|
|
|
static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
|
|
{
|
|
if (unlikely(policy_is_inactive(policy)))
|
|
return 0;
|
|
|
|
return cpufreq_verify_current_freq(policy, true);
|
|
}
|
|
|
|
/**
|
|
* cpufreq_get - get the current CPU frequency (in kHz)
|
|
* @cpu: CPU number
|
|
*
|
|
* Get the CPU current (static) CPU frequency
|
|
*/
|
|
unsigned int cpufreq_get(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
|
|
unsigned int ret_freq = 0;
|
|
|
|
if (policy) {
|
|
down_read(&policy->rwsem);
|
|
if (cpufreq_driver->get)
|
|
ret_freq = __cpufreq_get(policy);
|
|
up_read(&policy->rwsem);
|
|
|
|
cpufreq_cpu_put(policy);
|
|
}
|
|
|
|
return ret_freq;
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_get);
|
|
|
|
static struct subsys_interface cpufreq_interface = {
|
|
.name = "cpufreq",
|
|
.subsys = &cpu_subsys,
|
|
.add_dev = cpufreq_add_dev,
|
|
.remove_dev = cpufreq_remove_dev,
|
|
};
|
|
|
|
/*
|
|
* In case platform wants some specific frequency to be configured
|
|
* during suspend..
|
|
*/
|
|
int cpufreq_generic_suspend(struct cpufreq_policy *policy)
|
|
{
|
|
int ret;
|
|
|
|
if (!policy->suspend_freq) {
|
|
pr_debug("%s: suspend_freq not defined\n", __func__);
|
|
return 0;
|
|
}
|
|
|
|
pr_debug("%s: Setting suspend-freq: %u\n", __func__,
|
|
policy->suspend_freq);
|
|
|
|
ret = __cpufreq_driver_target(policy, policy->suspend_freq,
|
|
CPUFREQ_RELATION_H);
|
|
if (ret)
|
|
pr_err("%s: unable to set suspend-freq: %u. err: %d\n",
|
|
__func__, policy->suspend_freq, ret);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_generic_suspend);
|
|
|
|
/**
|
|
* cpufreq_suspend() - Suspend CPUFreq governors
|
|
*
|
|
* Called during system wide Suspend/Hibernate cycles for suspending governors
|
|
* as some platforms can't change frequency after this point in suspend cycle.
|
|
* Because some of the devices (like: i2c, regulators, etc) they use for
|
|
* changing frequency are suspended quickly after this point.
|
|
*/
|
|
void cpufreq_suspend(void)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
|
|
if (!cpufreq_driver)
|
|
return;
|
|
|
|
if (!has_target() && !cpufreq_driver->suspend)
|
|
goto suspend;
|
|
|
|
pr_debug("%s: Suspending Governors\n", __func__);
|
|
|
|
for_each_active_policy(policy) {
|
|
if (has_target()) {
|
|
down_write(&policy->rwsem);
|
|
cpufreq_stop_governor(policy);
|
|
up_write(&policy->rwsem);
|
|
}
|
|
|
|
if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy))
|
|
pr_err("%s: Failed to suspend driver: %s\n", __func__,
|
|
cpufreq_driver->name);
|
|
}
|
|
|
|
suspend:
|
|
cpufreq_suspended = true;
|
|
}
|
|
|
|
/**
|
|
* cpufreq_resume() - Resume CPUFreq governors
|
|
*
|
|
* Called during system wide Suspend/Hibernate cycle for resuming governors that
|
|
* are suspended with cpufreq_suspend().
|
|
*/
|
|
void cpufreq_resume(void)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
int ret;
|
|
|
|
if (!cpufreq_driver)
|
|
return;
|
|
|
|
if (unlikely(!cpufreq_suspended))
|
|
return;
|
|
|
|
cpufreq_suspended = false;
|
|
|
|
if (!has_target() && !cpufreq_driver->resume)
|
|
return;
|
|
|
|
pr_debug("%s: Resuming Governors\n", __func__);
|
|
|
|
for_each_active_policy(policy) {
|
|
if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) {
|
|
pr_err("%s: Failed to resume driver: %p\n", __func__,
|
|
policy);
|
|
} else if (has_target()) {
|
|
down_write(&policy->rwsem);
|
|
ret = cpufreq_start_governor(policy);
|
|
up_write(&policy->rwsem);
|
|
|
|
if (ret)
|
|
pr_err("%s: Failed to start governor for policy: %p\n",
|
|
__func__, policy);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* cpufreq_driver_test_flags - Test cpufreq driver's flags against given ones.
|
|
* @flags: Flags to test against the current cpufreq driver's flags.
|
|
*
|
|
* Assumes that the driver is there, so callers must ensure that this is the
|
|
* case.
|
|
*/
|
|
bool cpufreq_driver_test_flags(u16 flags)
|
|
{
|
|
return !!(cpufreq_driver->flags & flags);
|
|
}
|
|
|
|
/**
|
|
* cpufreq_get_current_driver - return current driver's name
|
|
*
|
|
* Return the name string of the currently loaded cpufreq driver
|
|
* or NULL, if none.
|
|
*/
|
|
const char *cpufreq_get_current_driver(void)
|
|
{
|
|
if (cpufreq_driver)
|
|
return cpufreq_driver->name;
|
|
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_get_current_driver);
|
|
|
|
/**
|
|
* cpufreq_get_driver_data - return current driver data
|
|
*
|
|
* Return the private data of the currently loaded cpufreq
|
|
* driver, or NULL if no cpufreq driver is loaded.
|
|
*/
|
|
void *cpufreq_get_driver_data(void)
|
|
{
|
|
if (cpufreq_driver)
|
|
return cpufreq_driver->driver_data;
|
|
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_get_driver_data);
|
|
|
|
/*********************************************************************
|
|
* NOTIFIER LISTS INTERFACE *
|
|
*********************************************************************/
|
|
|
|
/**
|
|
* cpufreq_register_notifier - register a driver with cpufreq
|
|
* @nb: notifier function to register
|
|
* @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
|
|
*
|
|
* Add a driver to one of two lists: either a list of drivers that
|
|
* are notified about clock rate changes (once before and once after
|
|
* the transition), or a list of drivers that are notified about
|
|
* changes in cpufreq policy.
|
|
*
|
|
* This function may sleep, and has the same return conditions as
|
|
* blocking_notifier_chain_register.
|
|
*/
|
|
int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
|
|
{
|
|
int ret;
|
|
|
|
if (cpufreq_disabled())
|
|
return -EINVAL;
|
|
|
|
switch (list) {
|
|
case CPUFREQ_TRANSITION_NOTIFIER:
|
|
mutex_lock(&cpufreq_fast_switch_lock);
|
|
|
|
if (cpufreq_fast_switch_count > 0) {
|
|
mutex_unlock(&cpufreq_fast_switch_lock);
|
|
return -EBUSY;
|
|
}
|
|
ret = srcu_notifier_chain_register(
|
|
&cpufreq_transition_notifier_list, nb);
|
|
if (!ret)
|
|
cpufreq_fast_switch_count--;
|
|
|
|
mutex_unlock(&cpufreq_fast_switch_lock);
|
|
break;
|
|
case CPUFREQ_POLICY_NOTIFIER:
|
|
ret = blocking_notifier_chain_register(
|
|
&cpufreq_policy_notifier_list, nb);
|
|
break;
|
|
default:
|
|
ret = -EINVAL;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_register_notifier);
|
|
|
|
/**
|
|
* cpufreq_unregister_notifier - unregister a driver with cpufreq
|
|
* @nb: notifier block to be unregistered
|
|
* @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
|
|
*
|
|
* Remove a driver from the CPU frequency notifier list.
|
|
*
|
|
* This function may sleep, and has the same return conditions as
|
|
* blocking_notifier_chain_unregister.
|
|
*/
|
|
int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list)
|
|
{
|
|
int ret;
|
|
|
|
if (cpufreq_disabled())
|
|
return -EINVAL;
|
|
|
|
switch (list) {
|
|
case CPUFREQ_TRANSITION_NOTIFIER:
|
|
mutex_lock(&cpufreq_fast_switch_lock);
|
|
|
|
ret = srcu_notifier_chain_unregister(
|
|
&cpufreq_transition_notifier_list, nb);
|
|
if (!ret && !WARN_ON(cpufreq_fast_switch_count >= 0))
|
|
cpufreq_fast_switch_count++;
|
|
|
|
mutex_unlock(&cpufreq_fast_switch_lock);
|
|
break;
|
|
case CPUFREQ_POLICY_NOTIFIER:
|
|
ret = blocking_notifier_chain_unregister(
|
|
&cpufreq_policy_notifier_list, nb);
|
|
break;
|
|
default:
|
|
ret = -EINVAL;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_unregister_notifier);
|
|
|
|
|
|
/*********************************************************************
|
|
* GOVERNORS *
|
|
*********************************************************************/
|
|
|
|
/**
|
|
* cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
|
|
* @policy: cpufreq policy to switch the frequency for.
|
|
* @target_freq: New frequency to set (may be approximate).
|
|
*
|
|
* Carry out a fast frequency switch without sleeping.
|
|
*
|
|
* The driver's ->fast_switch() callback invoked by this function must be
|
|
* suitable for being called from within RCU-sched read-side critical sections
|
|
* and it is expected to select the minimum available frequency greater than or
|
|
* equal to @target_freq (CPUFREQ_RELATION_L).
|
|
*
|
|
* This function must not be called if policy->fast_switch_enabled is unset.
|
|
*
|
|
* Governors calling this function must guarantee that it will never be invoked
|
|
* twice in parallel for the same policy and that it will never be called in
|
|
* parallel with either ->target() or ->target_index() for the same policy.
|
|
*
|
|
* Returns the actual frequency set for the CPU.
|
|
*
|
|
* If 0 is returned by the driver's ->fast_switch() callback to indicate an
|
|
* error condition, the hardware configuration must be preserved.
|
|
*/
|
|
unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
|
|
unsigned int target_freq)
|
|
{
|
|
unsigned int freq;
|
|
int cpu;
|
|
|
|
target_freq = clamp_val(target_freq, policy->min, policy->max);
|
|
freq = cpufreq_driver->fast_switch(policy, target_freq);
|
|
|
|
if (!freq)
|
|
return 0;
|
|
|
|
policy->cur = freq;
|
|
arch_set_freq_scale(policy->related_cpus, freq,
|
|
policy->cpuinfo.max_freq);
|
|
cpufreq_stats_record_transition(policy, freq);
|
|
trace_android_rvh_cpufreq_transition(policy);
|
|
|
|
if (trace_cpu_frequency_enabled()) {
|
|
for_each_cpu(cpu, policy->cpus)
|
|
trace_cpu_frequency(freq, cpu);
|
|
}
|
|
|
|
return freq;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch);
|
|
|
|
/* Must set freqs->new to intermediate frequency */
|
|
static int __target_intermediate(struct cpufreq_policy *policy,
|
|
struct cpufreq_freqs *freqs, int index)
|
|
{
|
|
int ret;
|
|
|
|
freqs->new = cpufreq_driver->get_intermediate(policy, index);
|
|
|
|
/* We don't need to switch to intermediate freq */
|
|
if (!freqs->new)
|
|
return 0;
|
|
|
|
pr_debug("%s: cpu: %d, switching to intermediate freq: oldfreq: %u, intermediate freq: %u\n",
|
|
__func__, policy->cpu, freqs->old, freqs->new);
|
|
|
|
cpufreq_freq_transition_begin(policy, freqs);
|
|
ret = cpufreq_driver->target_intermediate(policy, index);
|
|
cpufreq_freq_transition_end(policy, freqs, ret);
|
|
|
|
if (ret)
|
|
pr_err("%s: Failed to change to intermediate frequency: %d\n",
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int __target_index(struct cpufreq_policy *policy, int index)
|
|
{
|
|
struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0};
|
|
unsigned int intermediate_freq = 0;
|
|
unsigned int newfreq = policy->freq_table[index].frequency;
|
|
int retval = -EINVAL;
|
|
bool notify;
|
|
|
|
if (newfreq == policy->cur)
|
|
return 0;
|
|
|
|
notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION);
|
|
if (notify) {
|
|
/* Handle switching to intermediate frequency */
|
|
if (cpufreq_driver->get_intermediate) {
|
|
retval = __target_intermediate(policy, &freqs, index);
|
|
if (retval)
|
|
return retval;
|
|
|
|
intermediate_freq = freqs.new;
|
|
/* Set old freq to intermediate */
|
|
if (intermediate_freq)
|
|
freqs.old = freqs.new;
|
|
}
|
|
|
|
freqs.new = newfreq;
|
|
pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
|
|
__func__, policy->cpu, freqs.old, freqs.new);
|
|
|
|
cpufreq_freq_transition_begin(policy, &freqs);
|
|
}
|
|
|
|
retval = cpufreq_driver->target_index(policy, index);
|
|
if (retval)
|
|
pr_err("%s: Failed to change cpu frequency: %d\n", __func__,
|
|
retval);
|
|
|
|
if (notify) {
|
|
cpufreq_freq_transition_end(policy, &freqs, retval);
|
|
|
|
/*
|
|
* Failed after setting to intermediate freq? Driver should have
|
|
* reverted back to initial frequency and so should we. Check
|
|
* here for intermediate_freq instead of get_intermediate, in
|
|
* case we haven't switched to intermediate freq at all.
|
|
*/
|
|
if (unlikely(retval && intermediate_freq)) {
|
|
freqs.old = intermediate_freq;
|
|
freqs.new = policy->restore_freq;
|
|
cpufreq_freq_transition_begin(policy, &freqs);
|
|
cpufreq_freq_transition_end(policy, &freqs, 0);
|
|
}
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
int __cpufreq_driver_target(struct cpufreq_policy *policy,
|
|
unsigned int target_freq,
|
|
unsigned int relation)
|
|
{
|
|
unsigned int old_target_freq = target_freq;
|
|
int index;
|
|
|
|
if (cpufreq_disabled())
|
|
return -ENODEV;
|
|
|
|
/* Make sure that target_freq is within supported range */
|
|
target_freq = clamp_val(target_freq, policy->min, policy->max);
|
|
|
|
pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
|
|
policy->cpu, target_freq, relation, old_target_freq);
|
|
|
|
/*
|
|
* This might look like a redundant call as we are checking it again
|
|
* after finding index. But it is left intentionally for cases where
|
|
* exactly same freq is called again and so we can save on few function
|
|
* calls.
|
|
*/
|
|
if (target_freq == policy->cur &&
|
|
!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS))
|
|
return 0;
|
|
|
|
/* Save last value to restore later on errors */
|
|
policy->restore_freq = policy->cur;
|
|
|
|
if (cpufreq_driver->target)
|
|
return cpufreq_driver->target(policy, target_freq, relation);
|
|
|
|
if (!cpufreq_driver->target_index)
|
|
return -EINVAL;
|
|
|
|
index = cpufreq_frequency_table_target(policy, target_freq, relation);
|
|
|
|
return __target_index(policy, index);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
|
|
|
|
int cpufreq_driver_target(struct cpufreq_policy *policy,
|
|
unsigned int target_freq,
|
|
unsigned int relation)
|
|
{
|
|
int ret;
|
|
|
|
down_write(&policy->rwsem);
|
|
|
|
ret = __cpufreq_driver_target(policy, target_freq, relation);
|
|
|
|
up_write(&policy->rwsem);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_driver_target);
|
|
|
|
__weak struct cpufreq_governor *cpufreq_fallback_governor(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static int cpufreq_init_governor(struct cpufreq_policy *policy)
|
|
{
|
|
int ret;
|
|
|
|
/* Don't start any governor operations if we are entering suspend */
|
|
if (cpufreq_suspended)
|
|
return 0;
|
|
/*
|
|
* Governor might not be initiated here if ACPI _PPC changed
|
|
* notification happened, so check it.
|
|
*/
|
|
if (!policy->governor)
|
|
return -EINVAL;
|
|
|
|
/* Platform doesn't want dynamic frequency switching ? */
|
|
if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING &&
|
|
cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) {
|
|
struct cpufreq_governor *gov = cpufreq_fallback_governor();
|
|
|
|
if (gov) {
|
|
pr_warn("Can't use %s governor as dynamic switching is disallowed. Fallback to %s governor\n",
|
|
policy->governor->name, gov->name);
|
|
policy->governor = gov;
|
|
} else {
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
if (!try_module_get(policy->governor->owner))
|
|
return -EINVAL;
|
|
|
|
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
|
|
|
|
if (policy->governor->init) {
|
|
ret = policy->governor->init(policy);
|
|
if (ret) {
|
|
module_put(policy->governor->owner);
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void cpufreq_exit_governor(struct cpufreq_policy *policy)
|
|
{
|
|
if (cpufreq_suspended || !policy->governor)
|
|
return;
|
|
|
|
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
|
|
|
|
if (policy->governor->exit)
|
|
policy->governor->exit(policy);
|
|
|
|
module_put(policy->governor->owner);
|
|
}
|
|
|
|
int cpufreq_start_governor(struct cpufreq_policy *policy)
|
|
{
|
|
int ret;
|
|
|
|
if (cpufreq_suspended)
|
|
return 0;
|
|
|
|
if (!policy->governor)
|
|
return -EINVAL;
|
|
|
|
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
|
|
|
|
if (cpufreq_driver->get)
|
|
cpufreq_verify_current_freq(policy, false);
|
|
|
|
if (policy->governor->start) {
|
|
ret = policy->governor->start(policy);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
if (policy->governor->limits)
|
|
policy->governor->limits(policy);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void cpufreq_stop_governor(struct cpufreq_policy *policy)
|
|
{
|
|
if (cpufreq_suspended || !policy->governor)
|
|
return;
|
|
|
|
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
|
|
|
|
if (policy->governor->stop)
|
|
policy->governor->stop(policy);
|
|
}
|
|
|
|
static void cpufreq_governor_limits(struct cpufreq_policy *policy)
|
|
{
|
|
if (cpufreq_suspended || !policy->governor)
|
|
return;
|
|
|
|
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
|
|
|
|
if (policy->governor->limits)
|
|
policy->governor->limits(policy);
|
|
}
|
|
|
|
int cpufreq_register_governor(struct cpufreq_governor *governor)
|
|
{
|
|
int err;
|
|
|
|
if (!governor)
|
|
return -EINVAL;
|
|
|
|
if (cpufreq_disabled())
|
|
return -ENODEV;
|
|
|
|
mutex_lock(&cpufreq_governor_mutex);
|
|
|
|
err = -EBUSY;
|
|
if (!find_governor(governor->name)) {
|
|
err = 0;
|
|
list_add(&governor->governor_list, &cpufreq_governor_list);
|
|
}
|
|
|
|
mutex_unlock(&cpufreq_governor_mutex);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_register_governor);
|
|
|
|
void cpufreq_unregister_governor(struct cpufreq_governor *governor)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
unsigned long flags;
|
|
|
|
if (!governor)
|
|
return;
|
|
|
|
if (cpufreq_disabled())
|
|
return;
|
|
|
|
/* clear last_governor for all inactive policies */
|
|
read_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
for_each_inactive_policy(policy) {
|
|
if (!strcmp(policy->last_governor, governor->name)) {
|
|
policy->governor = NULL;
|
|
strcpy(policy->last_governor, "\0");
|
|
}
|
|
}
|
|
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
|
|
mutex_lock(&cpufreq_governor_mutex);
|
|
list_del(&governor->governor_list);
|
|
mutex_unlock(&cpufreq_governor_mutex);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
|
|
|
|
|
|
/*********************************************************************
|
|
* POLICY INTERFACE *
|
|
*********************************************************************/
|
|
|
|
/**
|
|
* cpufreq_get_policy - get the current cpufreq_policy
|
|
* @policy: struct cpufreq_policy into which the current cpufreq_policy
|
|
* is written
|
|
* @cpu: CPU to find the policy for
|
|
*
|
|
* Reads the current cpufreq policy.
|
|
*/
|
|
int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *cpu_policy;
|
|
if (!policy)
|
|
return -EINVAL;
|
|
|
|
cpu_policy = cpufreq_cpu_get(cpu);
|
|
if (!cpu_policy)
|
|
return -EINVAL;
|
|
|
|
memcpy(policy, cpu_policy, sizeof(*policy));
|
|
|
|
cpufreq_cpu_put(cpu_policy);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_get_policy);
|
|
|
|
/**
|
|
* cpufreq_set_policy - Modify cpufreq policy parameters.
|
|
* @policy: Policy object to modify.
|
|
* @new_gov: Policy governor pointer.
|
|
* @new_pol: Policy value (for drivers with built-in governors).
|
|
*
|
|
* Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency
|
|
* limits to be set for the policy, update @policy with the verified limits
|
|
* values and either invoke the driver's ->setpolicy() callback (if present) or
|
|
* carry out a governor update for @policy. That is, run the current governor's
|
|
* ->limits() callback (if @new_gov points to the same object as the one in
|
|
* @policy) or replace the governor for @policy with @new_gov.
|
|
*
|
|
* The cpuinfo part of @policy is not updated by this function.
|
|
*/
|
|
static int cpufreq_set_policy(struct cpufreq_policy *policy,
|
|
struct cpufreq_governor *new_gov,
|
|
unsigned int new_pol)
|
|
{
|
|
struct cpufreq_policy_data new_data;
|
|
struct cpufreq_governor *old_gov;
|
|
int ret;
|
|
|
|
memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
|
|
new_data.freq_table = policy->freq_table;
|
|
new_data.cpu = policy->cpu;
|
|
/*
|
|
* PM QoS framework collects all the requests from users and provide us
|
|
* the final aggregated value here.
|
|
*/
|
|
new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN);
|
|
new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX);
|
|
|
|
pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
|
|
new_data.cpu, new_data.min, new_data.max);
|
|
|
|
/*
|
|
* Verify that the CPU speed can be set within these limits and make sure
|
|
* that min <= max.
|
|
*/
|
|
ret = cpufreq_driver->verify(&new_data);
|
|
if (ret)
|
|
return ret;
|
|
|
|
policy->min = new_data.min;
|
|
policy->max = new_data.max;
|
|
trace_cpu_frequency_limits(policy);
|
|
|
|
policy->cached_target_freq = UINT_MAX;
|
|
|
|
pr_debug("new min and max freqs are %u - %u kHz\n",
|
|
policy->min, policy->max);
|
|
|
|
if (cpufreq_driver->setpolicy) {
|
|
policy->policy = new_pol;
|
|
pr_debug("setting range\n");
|
|
return cpufreq_driver->setpolicy(policy);
|
|
}
|
|
|
|
if (new_gov == policy->governor) {
|
|
pr_debug("governor limits update\n");
|
|
cpufreq_governor_limits(policy);
|
|
return 0;
|
|
}
|
|
|
|
pr_debug("governor switch\n");
|
|
|
|
/* save old, working values */
|
|
old_gov = policy->governor;
|
|
/* end old governor */
|
|
if (old_gov) {
|
|
cpufreq_stop_governor(policy);
|
|
cpufreq_exit_governor(policy);
|
|
}
|
|
|
|
/* start new governor */
|
|
policy->governor = new_gov;
|
|
ret = cpufreq_init_governor(policy);
|
|
if (!ret) {
|
|
ret = cpufreq_start_governor(policy);
|
|
if (!ret) {
|
|
pr_debug("governor change\n");
|
|
return 0;
|
|
}
|
|
cpufreq_exit_governor(policy);
|
|
}
|
|
|
|
/* new governor failed, so re-start old one */
|
|
pr_debug("starting governor %s failed\n", policy->governor->name);
|
|
if (old_gov) {
|
|
policy->governor = old_gov;
|
|
if (cpufreq_init_governor(policy))
|
|
policy->governor = NULL;
|
|
else
|
|
cpufreq_start_governor(policy);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_TRACEPOINT_SYMBOL_GPL(cpu_frequency_limits);
|
|
|
|
/**
|
|
* cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
|
|
* @cpu: CPU to re-evaluate the policy for.
|
|
*
|
|
* Update the current frequency for the cpufreq policy of @cpu and use
|
|
* cpufreq_set_policy() to re-apply the min and max limits, which triggers the
|
|
* evaluation of policy notifiers and the cpufreq driver's ->verify() callback
|
|
* for the policy in question, among other things.
|
|
*/
|
|
void cpufreq_update_policy(unsigned int cpu)
|
|
{
|
|
struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
|
|
|
|
if (!policy)
|
|
return;
|
|
|
|
/*
|
|
* BIOS might change freq behind our back
|
|
* -> ask driver for current freq and notify governors about a change
|
|
*/
|
|
if (cpufreq_driver->get && has_target() &&
|
|
(cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
|
|
goto unlock;
|
|
|
|
refresh_frequency_limits(policy);
|
|
|
|
unlock:
|
|
cpufreq_cpu_release(policy);
|
|
}
|
|
EXPORT_SYMBOL(cpufreq_update_policy);
|
|
|
|
/**
|
|
* cpufreq_update_limits - Update policy limits for a given CPU.
|
|
* @cpu: CPU to update the policy limits for.
|
|
*
|
|
* Invoke the driver's ->update_limits callback if present or call
|
|
* cpufreq_update_policy() for @cpu.
|
|
*/
|
|
void cpufreq_update_limits(unsigned int cpu)
|
|
{
|
|
if (cpufreq_driver->update_limits)
|
|
cpufreq_driver->update_limits(cpu);
|
|
else
|
|
cpufreq_update_policy(cpu);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_update_limits);
|
|
|
|
/*********************************************************************
|
|
* BOOST *
|
|
*********************************************************************/
|
|
static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)
|
|
{
|
|
int ret;
|
|
|
|
if (!policy->freq_table)
|
|
return -ENXIO;
|
|
|
|
ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
|
|
if (ret) {
|
|
pr_err("%s: Policy frequency update failed\n", __func__);
|
|
return ret;
|
|
}
|
|
|
|
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int cpufreq_boost_trigger_state(int state)
|
|
{
|
|
struct cpufreq_policy *policy;
|
|
unsigned long flags;
|
|
int ret = 0;
|
|
|
|
if (cpufreq_driver->boost_enabled == state)
|
|
return 0;
|
|
|
|
write_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
cpufreq_driver->boost_enabled = state;
|
|
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
|
|
get_online_cpus();
|
|
for_each_active_policy(policy) {
|
|
ret = cpufreq_driver->set_boost(policy, state);
|
|
if (ret)
|
|
goto err_reset_state;
|
|
}
|
|
put_online_cpus();
|
|
|
|
return 0;
|
|
|
|
err_reset_state:
|
|
put_online_cpus();
|
|
|
|
write_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
cpufreq_driver->boost_enabled = !state;
|
|
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
|
|
pr_err("%s: Cannot %s BOOST\n",
|
|
__func__, state ? "enable" : "disable");
|
|
|
|
return ret;
|
|
}
|
|
|
|
static bool cpufreq_boost_supported(void)
|
|
{
|
|
return cpufreq_driver->set_boost;
|
|
}
|
|
|
|
static int create_boost_sysfs_file(void)
|
|
{
|
|
int ret;
|
|
|
|
ret = sysfs_create_file(cpufreq_global_kobject, &boost.attr);
|
|
if (ret)
|
|
pr_err("%s: cannot register global BOOST sysfs file\n",
|
|
__func__);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void remove_boost_sysfs_file(void)
|
|
{
|
|
if (cpufreq_boost_supported())
|
|
sysfs_remove_file(cpufreq_global_kobject, &boost.attr);
|
|
}
|
|
|
|
int cpufreq_enable_boost_support(void)
|
|
{
|
|
if (!cpufreq_driver)
|
|
return -EINVAL;
|
|
|
|
if (cpufreq_boost_supported())
|
|
return 0;
|
|
|
|
cpufreq_driver->set_boost = cpufreq_boost_set_sw;
|
|
|
|
/* This will get removed on driver unregister */
|
|
return create_boost_sysfs_file();
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_enable_boost_support);
|
|
|
|
int cpufreq_boost_enabled(void)
|
|
{
|
|
return cpufreq_driver->boost_enabled;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_boost_enabled);
|
|
|
|
/*********************************************************************
|
|
* REGISTER / UNREGISTER CPUFREQ DRIVER *
|
|
*********************************************************************/
|
|
static enum cpuhp_state hp_online;
|
|
|
|
static int cpuhp_cpufreq_online(unsigned int cpu)
|
|
{
|
|
cpufreq_online(cpu);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int cpuhp_cpufreq_offline(unsigned int cpu)
|
|
{
|
|
cpufreq_offline(cpu);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* cpufreq_register_driver - register a CPU Frequency driver
|
|
* @driver_data: A struct cpufreq_driver containing the values#
|
|
* submitted by the CPU Frequency driver.
|
|
*
|
|
* Registers a CPU Frequency driver to this core code. This code
|
|
* returns zero on success, -EEXIST when another driver got here first
|
|
* (and isn't unregistered in the meantime).
|
|
*
|
|
*/
|
|
int cpufreq_register_driver(struct cpufreq_driver *driver_data)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
if (cpufreq_disabled())
|
|
return -ENODEV;
|
|
|
|
/*
|
|
* The cpufreq core depends heavily on the availability of device
|
|
* structure, make sure they are available before proceeding further.
|
|
*/
|
|
if (!get_cpu_device(0))
|
|
return -EPROBE_DEFER;
|
|
|
|
if (!driver_data || !driver_data->verify || !driver_data->init ||
|
|
!(driver_data->setpolicy || driver_data->target_index ||
|
|
driver_data->target) ||
|
|
(driver_data->setpolicy && (driver_data->target_index ||
|
|
driver_data->target)) ||
|
|
(!driver_data->get_intermediate != !driver_data->target_intermediate) ||
|
|
(!driver_data->online != !driver_data->offline))
|
|
return -EINVAL;
|
|
|
|
pr_debug("trying to register driver %s\n", driver_data->name);
|
|
|
|
/* Protect against concurrent CPU online/offline. */
|
|
cpus_read_lock();
|
|
|
|
write_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
if (cpufreq_driver) {
|
|
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
ret = -EEXIST;
|
|
goto out;
|
|
}
|
|
cpufreq_driver = driver_data;
|
|
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
|
|
/*
|
|
* Mark support for the scheduler's frequency invariance engine for
|
|
* drivers that implement target(), target_index() or fast_switch().
|
|
*/
|
|
if (!cpufreq_driver->setpolicy) {
|
|
static_branch_enable_cpuslocked(&cpufreq_freq_invariance);
|
|
pr_debug("supports frequency invariance");
|
|
}
|
|
|
|
if (driver_data->setpolicy)
|
|
driver_data->flags |= CPUFREQ_CONST_LOOPS;
|
|
|
|
if (cpufreq_boost_supported()) {
|
|
ret = create_boost_sysfs_file();
|
|
if (ret)
|
|
goto err_null_driver;
|
|
}
|
|
|
|
ret = subsys_interface_register(&cpufreq_interface);
|
|
if (ret)
|
|
goto err_boost_unreg;
|
|
|
|
if (!(cpufreq_driver->flags & CPUFREQ_STICKY) &&
|
|
list_empty(&cpufreq_policy_list)) {
|
|
/* if all ->init() calls failed, unregister */
|
|
ret = -ENODEV;
|
|
pr_debug("%s: No CPU initialized for driver %s\n", __func__,
|
|
driver_data->name);
|
|
goto err_if_unreg;
|
|
}
|
|
|
|
ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
|
|
"cpufreq:online",
|
|
cpuhp_cpufreq_online,
|
|
cpuhp_cpufreq_offline);
|
|
if (ret < 0)
|
|
goto err_if_unreg;
|
|
hp_online = ret;
|
|
ret = 0;
|
|
|
|
pr_debug("driver %s up and running\n", driver_data->name);
|
|
goto out;
|
|
|
|
err_if_unreg:
|
|
subsys_interface_unregister(&cpufreq_interface);
|
|
err_boost_unreg:
|
|
remove_boost_sysfs_file();
|
|
err_null_driver:
|
|
write_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
cpufreq_driver = NULL;
|
|
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
out:
|
|
cpus_read_unlock();
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_register_driver);
|
|
|
|
/*
|
|
* cpufreq_unregister_driver - unregister the current CPUFreq driver
|
|
*
|
|
* Unregister the current CPUFreq driver. Only call this if you have
|
|
* the right to do so, i.e. if you have succeeded in initialising before!
|
|
* Returns zero if successful, and -EINVAL if the cpufreq_driver is
|
|
* currently not initialised.
|
|
*/
|
|
int cpufreq_unregister_driver(struct cpufreq_driver *driver)
|
|
{
|
|
unsigned long flags;
|
|
|
|
if (!cpufreq_driver || (driver != cpufreq_driver))
|
|
return -EINVAL;
|
|
|
|
pr_debug("unregistering driver %s\n", driver->name);
|
|
|
|
/* Protect against concurrent cpu hotplug */
|
|
cpus_read_lock();
|
|
subsys_interface_unregister(&cpufreq_interface);
|
|
remove_boost_sysfs_file();
|
|
static_branch_disable_cpuslocked(&cpufreq_freq_invariance);
|
|
cpuhp_remove_state_nocalls_cpuslocked(hp_online);
|
|
|
|
write_lock_irqsave(&cpufreq_driver_lock, flags);
|
|
|
|
cpufreq_driver = NULL;
|
|
|
|
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
|
cpus_read_unlock();
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
|
|
|
|
static int __init cpufreq_core_init(void)
|
|
{
|
|
struct cpufreq_governor *gov = cpufreq_default_governor();
|
|
|
|
if (cpufreq_disabled())
|
|
return -ENODEV;
|
|
|
|
cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
|
|
BUG_ON(!cpufreq_global_kobject);
|
|
|
|
if (!strlen(default_governor))
|
|
strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN);
|
|
|
|
return 0;
|
|
}
|
|
module_param(off, int, 0444);
|
|
module_param_string(default_governor, default_governor, CPUFREQ_NAME_LEN, 0444);
|
|
core_initcall(cpufreq_core_init);
|