Commit Graph

642 Commits

Author SHA1 Message Date
Nick Desaulniers 78ef5ad5fb msm: thermal: validate userspace args to prevent buffer overflow.
Prevent a userspace ioctl variable from accessing an array out of
bounds.

BUG: 27243728
Change-Id: I43690364273ace4a22e214bab88c76f0749c6d4f
2019-07-27 22:10:00 +02:00
Siqi Lin 26348f7fa6 msm_thermal: send OFF/ONLINE uevent in hotplug cases
Send the correct uevent after setting a CPU core online or offline.
This allows ueventd to set correct SELinux labels for newly created
sysfs CPU device nodes.

Bug: 28887345
Change-Id: If31b8529b31de9544914e27514aca571039abb60
Signed-off-by: Siqi Lin <siqilin@google.com>
Signed-off-by: Thierry Strudel <tstrudel@google.com>
2019-07-27 22:10:00 +02:00
syphyr e5365819a5 msm_thermal: Handle defer while probing
Change-Id: I0b54c51c1f25e0b352b1d3df9f5091b452c9f82d
2019-07-27 21:45:58 +02:00
Krzysztof Kozlowski 6d4337eb09 thermal: hwmon: Properly report critical temperature in sysfs
commit f37fabb8643eaf8e3b613333a72f683770c85eca upstream.

In the critical sysfs entry the thermal hwmon was returning wrong
temperature to the user-space.  It was reporting the temperature of the
first trip point instead of the temperature of critical trip point.

For example:
	/sys/class/hwmon/hwmon0/temp1_crit:50000
	/sys/class/thermal/thermal_zone0/trip_point_0_temp:50000
	/sys/class/thermal/thermal_zone0/trip_point_0_type:active
	/sys/class/thermal/thermal_zone0/trip_point_3_temp:120000
	/sys/class/thermal/thermal_zone0/trip_point_3_type:critical

Since commit e68b16abd9 ("thermal: add hwmon sysfs I/F") the driver
have been registering a sysfs entry if get_crit_temp() callback was
provided.  However when accessed, it was calling get_trip_temp() instead
of the get_crit_temp().

Fixes: e68b16abd9 ("thermal: add hwmon sysfs I/F")
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
[wt: s/thermal_hwmon.c/thermal_core.c in 3.10]

Signed-off-by: Willy Tarreau <w@1wt.eu>
2019-07-27 21:42:22 +02:00
LuK1337 18aceede84 Merge tag 'LA.BR.1.3.6-03910-8976.0' of https://source.codeaurora.org/quic/la/kernel/msm-3.10 into HEAD
"LA.BR.1.3.6-03910-8976.0"

Change-Id: I16643fc055aa2965fe5903396a8e5158c42cf1bc
2017-05-26 13:28:48 +02:00
LuK1337 fc9499e55a Import latest Samsung release
* Package version: T713XXU2BQCO

Change-Id: I293d9e7f2df458c512d59b7a06f8ca6add610c99
2017-04-18 03:43:52 +02:00
Ram Chandrasekar c6f2a0c27a msm: thermal-dev: Protect IOCTL from race condition
There is a possibility that the thermal ioctl interface can be accessed
simultaneously in a multi-threaded environment. In those cases the
calls to fetch the frequency and voltage table can result in an
undefined behavior due to race condition.

Use mutex to protect the IOCTL interface from multi-thread access race
condition.

Change-Id: I325695f38753a4d4bc732987cf514e8616273aca
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
2017-04-05 11:00:59 +05:30
Linux Build Service Account 14c51e38fe Merge "msm: thermal: Add support to monitor only one tsens for MX restriction" 2016-07-01 06:46:13 -07:00
Linux Build Service Account 31b2c1b467 Merge "msm: thermal: Maintain state in the mitigation device monitor" 2016-07-01 06:46:13 -07:00
Linux Build Service Account e87cc30d9c Merge "msm: thermal: Check clients request just after frequency thread init" 2016-06-15 06:14:13 -07:00
Manaf Meethalavalappu Pallikunhi cfa2582782 msm: thermal: Check clients request just after frequency thread init
KTM frequency mitigation thread initializes during late init call.
Prior to this, client can request frequency mitigation. But request
will not be processed, since frequency mitigation thread won't be
initialized. Notify frequency mitigation thread to aggregate clients
current request immediately after thread initialization.

Change-Id: Id2425041b14554d58f944794e1b5db273f5ded26
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2016-06-02 23:46:01 -07:00
Ram Chandrasekar f1fbc2c40d msm: thermal: Re-evaluate hotplug for unexpected cpu online
Thermal driver don't acquire get_online_cpus() lock before
evaluating to hotplug or online a core. This will introduce
a corner case where thermal determines to keep an offline core
hotplugged but will be brought online by other driver due to race
condition.

Thermal driver after evaluating to hotplug a core will see if it
is online. if it is online, it will proceed to hotplug it, otherwise
it will evaluate for the next core. If another driver initiates to
online a core when thermal is evaluating hotplug status, we will end up
onlining a core when thermal has a request to hotplug. Explained the
scenario below,

1.                             | Driver X initiates cpu 'A' online
2. Thermal gets CPU_UP_PREPARE |
   Notification and allows CPU |
   'A' to be online.           |
3. Thermal driver evaluates    |
   hotplug status and sees cpu |
   'A' being offline and skips |
   to next CPU.                |
4.                             | CPU 'A' online is complete and CPU
                               | online mask is updated.

Fix this corner case, by listening for CPU_ONLINE notification and
initiate a re-evaluation to retry hotplug, if a CPU online was supposed
to be hotplugged by thermal driver.

CRs-Fixed: 928985
Change-Id: Icc6c6bcbc2656c0712550b884b9a9b17e3fea9d1
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
2016-05-31 03:21:01 -07:00
Manaf Meethalavalappu Pallikunhi 053261f7a1 msm: limits: Check user buffer size before copying to local buffer
User input data is passed in from userspace through debugfs interface
of supply lm core to validate supply lm core functionality. Ensure
user buffer size is not greater than expected stack buffer size
to avoid out of bounds array accesses.

Change-Id: I5a93774855241b50895c5e2b3ff939e4c33a0185
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2016-04-14 05:29:13 -07:00
Manaf Meethalavalappu Pallikunhi 98fc659dfd msm: thermal: Add support to monitor only one tsens for MX restriction
Currently VDD MX restriction feature monitors all tsens for low
temperature condition. Some targets which has higher MX restriction
thresholds shows frequent interrupts from multiple sensors causing
power impact.
Add support to monitor only one sensor for VDD MX restriction feature.
Add an optional device tree property "qcom,mx-restriction-sensor_id"
to specify sensor id for monitor. If not defined, monitor all tsens
for VDD MX restriction.

Change-Id: Ib709b00c27f43c2603ac8a08b75f2fbd5800983b
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2016-04-14 03:14:46 -07:00
Manaf Meethalavalappu Pallikunhi 54a36422d8 msm: thermal: Maintain state in the mitigation device monitor
If KTM get a trip threshold trigger notification and if the
temperature stays the same as the recent trip threshold, KTM will
re-activate the recently triggered threshold, resulting in back to
back interrupts. To avoid this add support in KTM to maintain the
recently triggered threshold state and then re-active the threshold
based on the last threshold trip.
This state is updated for mitigation features like VDD MX retention,
CX phase control, VDD restriction, OCR monitor and external clients
like CPR low temperature monitor etc.

CRs-Fixed: 969112 972634
Change-Id: I44c0a93e1507a9f0b8a65e5c2ce5a98962bb335b
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2016-04-14 03:14:08 -07:00
Linux Build Service Account c5a8e57287 Merge "msm: thermal: Add range checking for cluster_id" 2016-03-11 21:49:58 -08:00
Mahesh Sivasubramanian e58a9c878a msm: thermal: Add range checking for cluster_id
The cluster id flag is passed in from the userspace through ioctl
interface. Ensure correctness of cluster id to avoid out of bounds array
accesses.

CRS-fixed: 977508
Change-Id: I778b962d347b90488b983a15087b13e90ad06688
Signed-off-by: Mahesh Sivasubramanian <msivasub@codeaurora.org>
2016-03-11 03:55:47 -08:00
Manaf Meethalavalappu Pallikunhi a981431516 msm: lmh_lite: Pass proper size for dma memory free API call
Use proper size for dma memory free call API while saving lmh sensors
list in lmh hardware driver otherwise it leads to memory leak or
unexpected crash if scm_call error path is executed.

CRs-Fixed: 982320
Change-Id: I31ac79585c8899b44ece745676d9af79fe8bca78
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2016-03-11 03:45:02 -08:00
Manaf Meethalavalappu Pallikunhi 483162e950 msm: thermal: Add support for conditional vdd mx rail restriction
Add support for efuse based conditional vdd MX restriction for
KTM vdd restriction feature. If digital rail is vdd-mx and if
pre-specified efuse data and config data are matching, then
enable vdd mx restriction feature for preset low temperature
thresholds.

Change-Id: I551869a139d263f57712a5dde07277002260f8c2
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2015-11-05 02:16:59 -08:00
Manaf Meethalavalappu Pallikunhi b4ea5dcfb9 msm: thermal: Clean up KTM progressive mitigation exit path
If userspace request to disable progressive mitigation, it removes
threshold settings and clear device mitigation, but it keeps
progressive config list. But request to disable comes more than once
from userspace, it retries above clean up which may leads to crash due
to use after free. Clean up KTM progressive mitigation exit properly.

Change-Id: I2083411361c943612293a403e5f4c6a7cd31e281
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2015-11-03 00:45:47 -08:00
Manaf Meethalavalappu Pallikunhi abe105f868 msm: thermal: Add ftrace to KTM progressive mitigation
Add ftrace events for KTM progressive algorithm mitigation.
Below ftrace events are added to KTM,
thermal_progressive_sampling
thermal_progressive_state
thermal_progressive_mitigate

Change-Id: Iec8a3a62f5655a59901ebaf744233457c22c84a5
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2015-11-03 00:45:25 -08:00
Ram Chandrasekar c4c5c4c7a9 msm: thermal: Add progressive mitigation algo support to KTM
After the interrupt mode is initialized, KTM starts the progressive
algorithm based frequency mitigation for multiple sensors based on
thermal sensor information devicetree configuration. This mitigation
will be disabled when thermal-engine starts and disables the KTM
boot up polling mode mitigation.

By default progressive mitigation is in monitor state. In monitor
state algorithm waits for sensor high threshold trigger. If sensor
temperature reaches high threshold, progressive mitigation algorithm
starts in polling mode. In each polling iteration, if current
temperature is greater than or equal to high threshold, it mitigates
by one level down of supported frequency table from fmax. If current
temperature is less than high threshold in a particular sample,
it reduces mitigation by one level up from previous mitigation state
and at this condition if mitigation is fully cleared, then algorithm
moves from polling mode to monitor mode. In polling mode if the
temperature is less than low threshold then algorithm will clear all
mitigations and will switch to monitor mode.

Add an optional devicetree entry "qcom,ktm-prog-mitigation-config"
to thermal sensor info node which takes cluster id to be mitigated,
high threshold, low threshold and progressive mitigation algo
sampling as input.

Change-Id: Ic609e5beb603c3dec1f7de8f64d1c35516eed057
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2015-10-27 00:16:38 +05:30
Rama Krishna Phani A f6f0714f09 thermal: tsens: Enable valid status bit check
Check if the valid bit is set as part of reading the ADC data from the
status register. The valid bit is used to avoid possibility of reading
invalid ADC data as the controller is updating the readings.

Change-Id: I03832a1ffb6bb47525a5ab9afc28682034a50c69
Signed-off-by: Rama Krishna Phani A <rphani@codeaurora.org>
2015-10-15 04:29:37 -07:00
Ram Chandrasekar 2efbf29d3e msm: limits: Fix error handling to free up memory
Fix error handling to free up allocated memory before
returning back the function call.

CRs-Fixed: 869192
Change-Id: I38c9543baa98a941ee09fd34211fa77445b0e096
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
2015-09-22 05:04:33 -07:00
Manaf Meethalavalappu Pallikunhi f4a69f4f18 msm: thermal: Add support for partial goods CPU
Add support to thermal driver to handle partial
goods.

In this case, it is possible that some physical
CPUs may not be brought online and it can be
decided runtime. This behavior changes the physical
CPU to logical CPU numbering dynamic.

Thermal driver should be capable to map the
temperature sensor with the correct logical CPU number.
This is achieved by creating different mitigation
profiles and associating each physical CPU to one
profile using device tree phandle. Thus thermal driver
identifies the thermal profile associated with the
logical CPU and then determines the mitigation
information. The mitigation profile has a phandle to the
temperature sensor and devicetree properties to
enable or disable various type of mitigation.
A single device can have multiple sensors mapped in
array of phandles or even multiple sensors mapping
to a single sensor.

Partial goods cpu feature will be enabled only if
'qcom,mitigation-profile-enable' DT node is defined
in msm_thermal node.

CRs-Fixed: 756322
Change-Id: If0196a9a3a03c117f67bae3591d1f5050d32b59b
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
Signed-off-by: Manaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
2015-08-11 04:39:24 -07:00
Linux Build Service Account 9fa3ed3697 Merge "thermal: tsens: Update MTC sysfs functionality" 2015-07-04 12:31:43 -07:00
Rama Krishna Phani A 71b8131644 thermal: tsens: Update MTC sysfs functionality
Multi-Zone Temperature Control (MTC) provides an interface to
clients to enable or disable thresholds for supported zone of
sensors and to get log of recent commands. Update the MTC
sysfs functionality.

Change-Id: I171c799ea11f4ec2e86f881555fd2014de803a1e
Signed-off-by: Rama Krishna Phani A <rphani@codeaurora.org>
2015-07-01 11:29:40 +05:30
Linux Build Service Account a295901027 Merge "thermal: tsens: Update sysfs for MTC tsens" 2015-06-29 17:51:53 -07:00
Rama Krishna Phani A 84822db8dd thermal: tsens: Update sysfs for MTC tsens
Multi-Zone Temperature Control (MTC) provides an interface to
clients to enable or disable thresholds for supported zone of sensors
and to get log of recent commands. Upate sysfs nodes to print the values
in the shell.

Change-Id: I74cdfba6cb7c235cb3939b7286771edd2a02a6fa
Signed-off-by: Rama Krishna Phani A <rphani@codeaurora.org>
2015-06-26 17:40:57 +05:30
Linux Build Service Account 6183b23225 Merge "msm: thermal: Support new DT properties to disable KTM feature" 2015-06-25 20:40:28 -07:00
Linux Build Service Account a21d55f195 Merge "msm: lmh_lite: Enable interrupt inside critical section" 2015-06-23 18:39:19 -07:00
Kranthikumar Kurapati cc09709ba8 msm: thermal: Support new DT properties to disable KTM feature
Support new device tree properties to selectively disable a feature in KTM.
Do not generate error if properties for this feature are not defined.

Change-Id: I2891ff25291d62e7de53b192af93081fa16a8d1d
Acked-by: Jim Granitzki <jamesg@qti.qualcomm.com>
Signed-off-by: Kranthikumar Kurapati <kkurap@codeaurora.org>
2015-06-19 09:37:00 +05:30
Ram Chandrasekar a3676ca9e8 msm: lmh_lite: Fix the intensity calculation
Fix the LMH throttling intensity calculation to report
the intensity in percentage.

Change-Id: I64ac5855b4e9b9cb5ef7dde939102a31d2a08e52
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
2015-06-17 21:25:38 -07:00
Ram Chandrasekar 558a57d353 msm: lmh_lite: Enable interrupt inside critical section
Interrupt enable code is outside the critical section and
this can lead to race condition between multiple threads.
This race condition can result in enabling the interrupt,
which is disabled by the interrupt service routine. This
can lead to interrupt storm.

To avoid this, the interrupt enable is done inside critical
section to avoid any race condition.

CRs-Fixed: 850290
Change-Id: Ifeea212601e39b554740d88da0c662e4a9be0d87
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
2015-06-16 10:17:14 -06:00
Linux Build Service Account 887c77f24d Merge "hwmon: qpnp-adc-tm: Add version check for VADC_TM channel" 2015-06-12 07:57:52 -07:00
Rama Krishna Phani A 0199671fcf hwmon: qpnp-adc-tm: Add version check for VADC_TM channel
vph_pwr channel should be supported for VADC_TM for pm8950 2.0.
Add version check to detect the PMIC used and support channel
accordingly.

Change-Id: I6f62604e0050a245acd0f65732ef5b3aca9180ec
Signed-off-by: Rama Krishna Phani A <rphani@codeaurora.org>
2015-06-10 10:15:26 -07:00
Rama Krishna Phani A d78b3def1f thermal: tsens: Add fuse-based correction factors for msm8952
Additional per-sensor offets are being observed after factory
calibration. Fuse-based correction factors are implemented to the
existing 30 / 120 deg C calibration fuses.

Change-Id: I0415932c424da119c03b773e425ef50a02dfc119
Signed-off-by: Rama Krishna Phani A <rphani@codeaurora.org>
2015-06-09 11:03:44 +05:30
Linux Build Service Account 4f44e63219 Merge "msm: thermal: Update KTM thresholds via debugfs interface" 2015-06-04 08:59:25 -07:00
Shiju Mathew 76951e263c msm: thermal: Update KTM thresholds via debugfs interface
Update KTM mitigation threshold and threshold clear
dynamically via debugfs interface. Below is an example
to update mx retention thresholds.

 echo 60 > /sys/kernel/debug/msm_thermal/config/mx/thresh_degc
 echo 50 > /sys/kernel/debug/msm_thermal/config/mx/thresh_clr_degc
 echo 1 > /sys/kernel/debug/msm_thermal/config/mx/update
 echo -n update > /sys/kernel/debug/msm_thermal/config/data

Change-Id: I3dfcff834c9041a1339670b2db5c686d5bfc4cd6
Signed-off-by: Shiju Mathew <shijum@codeaurora.org>
2015-06-03 19:15:08 -04:00
Siddartha Mohanadoss 12a5feba0c thermal: tsens: Add support for MDM9640v2
Add support to read the EEPROM fuse data for calibration
to calculate the gain and offset that is used to compute
the final temperature.

Update the DT document to add missing DT compatible strings
along with the addition for 9x40v2 compatible string support.

Change-Id: Ib39388e1db92b3d18878abf67a28f598ca004f96
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
2015-06-01 11:41:04 -07:00
Jeff Bernard e235534764 msm: thermal: Pass correct size of voltage table to IOCTL
Fix issue in msm_thermal_process_voltage_table_request.
For voltage tables bigger than 16 it is not correclty
passing the partial table size to user space.
The full size is passed instead of the partial size.

For example if reading a table of 18 values the
first read returns 16, and the partial read returns 18
but it should return 2.

Signed-off-by: Jeff Bernard <jbernard@codeaurora.org>
Change-Id: I75943e94341388cca772ee45bc1275fb5d2091d2
2015-05-30 12:10:25 -07:00
Ram Chandrasekar 2e4087cefe msm: lmh_lite: Normalize the intensity reading
Normalize the throttling intensity reading for a LMH sensor
based on the maximum throttling intensity value.

Change-Id: I48567d5c1f027b244a296c96f1ca8ddd5ae4846a
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
2015-05-27 16:21:37 -07:00
Shiju Mathew 91c45404bc msm: thermal: Add kernel boot command to disable KTM
Add support in KTM to parse early kernel boot command.
Below is an example to disable KTM.
 fastboot -c "<existing_kernel_bootcmd> qcomthermal=disable" boot boot.img

Change-Id: I268e652239573ff368f8ccbfdff354eb6c24a90a
Signed-off-by: Shiju Mathew <shijum@codeaurora.org>
2015-05-14 13:33:53 -04:00
Shiju Mathew 78843f5c27 msm: thermal: Add support to disable KTM mitigation via debugfs
This patch will add support in KTM to disable its
temperature monitoring and mitigations from debugfs
interface. Below is the command to disable all
KTM mitigation.

  echo -n disable > /sys/kernel/debug/msm_thermal/config

Change-Id: I46d880bad043897e088bdd156305ce61aa2ea452
Signed-off-by: Shiju Mathew <shijum@codeaurora.org>
2015-05-14 10:38:52 -04:00
Shiju Mathew 9138eeb658 msm: thermal: Add support to read KTM thermal configuration
Add support in KTM to read thermal threshold
configurations through debugfs interface. Below
is the command to read KTM configuration from shell.

       cat /sys/kernel/debug/msm_thermal/config

Change-Id: I3ff937875e8b5136584ab10af75dbed71b1443ac
Signed-off-by: Shiju Mathew <shijum@codeaurora.org>
2015-05-06 13:56:38 -07:00
Linux Build Service Account 10cb7bff34 Merge "thermal: tsens: Create sysfs for MTC tsens" 2015-05-04 00:57:44 -07:00
Linux Build Service Account d664e9ccb8 Merge "msm: thermal: Retry on failure to hotplug" 2015-05-03 04:50:26 -07:00
Linux Build Service Account 6754c37cc7 Merge "msm: thermal: Update scm calls in KTM with non-atomic calls" 2015-05-01 20:27:54 -07:00
Rama Krishna Phani A 6fc2f97aca thermal: tsens: Create sysfs for MTC tsens
Multi-Zone Temperature Control (MTC) provides an interface to
clients to enable or disable thresholds for supported zone of sensors
and to get log of recent commands. Create sysfs nodes to access
MTC tsens.

Change-Id: Id42baef39442a8e30f40e2cd98c50611ed1cdf27
Signed-off-by: Rama Krishna Phani A <rphani@codeaurora.org>
2015-05-01 12:49:55 +05:30
Linux Build Service Account 25da393831 Merge "msm: thermal: Retry hotplug when exiting from suspend" 2015-04-30 23:29:31 -07:00