* Re: [PATCH v3 13/33] docs: infiniband: convert docs to ReST and rename to *.rst
From: Jason Gunthorpe @ 2019-06-25 13:24 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: Linux Doc Mailing List, Mauro Carvalho Chehab,
linux-kernel@vger.kernel.org, Jonathan Corbet, Doug Ledford,
linux-rdma@vger.kernel.org
In-Reply-To: <09036fdb89c4bec94cb92d25398c026afdb134e7.1560045490.git.mchehab+samsung@kernel.org>
On Sat, Jun 08, 2019 at 11:27:03PM -0300, Mauro Carvalho Chehab wrote:
> The InfiniBand docs are plain text with no markups.
> So, all we needed to do were to add the title markups and
> some markup sequences in order to properly parse tables,
> lists and literal blocks.
>
> At its new index.rst, let's add a :orphan: while this is not linked to
> the main index.rst file, in order to avoid build warnings.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
> ---
> .../{core_locking.txt => core_locking.rst} | 64 ++++++-----
> Documentation/infiniband/index.rst | 23 ++++
> .../infiniband/{ipoib.txt => ipoib.rst} | 24 ++--
> .../infiniband/{opa_vnic.txt => opa_vnic.rst} | 108 +++++++++---------
> .../infiniband/{sysfs.txt => sysfs.rst} | 4 +-
> .../{tag_matching.txt => tag_matching.rst} | 5 +
> .../infiniband/{user_mad.txt => user_mad.rst} | 33 ++++--
> .../{user_verbs.txt => user_verbs.rst} | 12 +-
> drivers/infiniband/core/user_mad.c | 2 +-
> drivers/infiniband/ulp/ipoib/Kconfig | 2 +-
> 10 files changed, 174 insertions(+), 103 deletions(-)
> rename Documentation/infiniband/{core_locking.txt => core_locking.rst} (78%)
> create mode 100644 Documentation/infiniband/index.rst
> rename Documentation/infiniband/{ipoib.txt => ipoib.rst} (90%)
> rename Documentation/infiniband/{opa_vnic.txt => opa_vnic.rst} (63%)
> rename Documentation/infiniband/{sysfs.txt => sysfs.rst} (69%)
> rename Documentation/infiniband/{tag_matching.txt => tag_matching.rst} (98%)
> rename Documentation/infiniband/{user_mad.txt => user_mad.rst} (90%)
> rename Documentation/infiniband/{user_verbs.txt => user_verbs.rst} (93%)
Applied to for-next, thanks
Jason
^ permalink raw reply
* Re: [PATCH 0/3] Clean up crypto documentation
From: Gary R Hook @ 2019-06-25 13:33 UTC (permalink / raw)
To: Jonathan Corbet, Joe Perches
Cc: Hook, Gary, herbert@gondor.apana.org.au,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-crypto@vger.kernel.org, davem@davemloft.net
In-Reply-To: <20190624143748.7fcfe623@lwn.net>
On 6/24/19 3:37 PM, Jonathan Corbet wrote:
> On Mon, 24 Jun 2019 13:29:42 -0700
> Joe Perches <joe@perches.com> wrote:
>
>>> Finally, would you prefer a v2 of the patch set? Happy to do
>>> whatever is preferred, of course.
>>
>> Whatever Jonathan decides is fine with me.
>> Mine was just a plea to avoid unnecessarily
>> making the source text harder to read as
>> that's what I mostly use.
>
> Usually Herbert seems to take crypto docs, so it's not necessarily up to
> me :)
>
> I don't see much that's objectionable here. But...
>
>> I don't know if this extension is valid yet, but
>> I believe just using <function_name>() is more
>> readable as text than ``<function_name>`` or
>> :c:func:`<function_name>`
>
> It's been "valid" since I wrote it...it's just not upstream yet :) I
> expect it to be in 5.3, though. So the best way to refer to a kernel
> function, going forward, is just function() with no markup needed.
So I'm unclear:
1) would you prefer I wait on your 5.3 change being fully committed,
2) add your change to my local tree and use it, then submit an update
patchset that depends upon it, or
3) re-submit now (using the current method) with suggested changes?
I'm thinking that this will go in after the referenced patch, so (2) is
the preferred choice?
grh
^ permalink raw reply
* Re: [PATCH v1 04/22] docs: thermal: convert to ReST
From: Zhang Rui @ 2019-06-25 13:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Linux Doc Mailing List
Cc: Mauro Carvalho Chehab, linux-kernel, Jonathan Corbet,
Amit Daniel Kachhap, Viresh Kumar, Javi Merino, Kukjin Kim,
Krzysztof Kozlowski, Eduardo Valentin, Daniel Lezcano, linux-pm,
linux-arm-kernel, linux-samsung-soc, Arjan van de Ven
In-Reply-To: <23fafb70bfc9bd8b7f306f2502617d8f8794eae5.1560891322.git.mchehab+samsung@kernel.org>
On 二, 2019-06-18 at 18:05 -0300, Mauro Carvalho Chehab wrote:
> Rename the thermal documentation files to ReST, add an
> index for them and adjust in order to produce a nice html
> output via the Sphinx build system.
>
> At its new index.rst, let's add a :orphan: while this is not linked
> to
> the main index.rst file, in order to avoid build warnings.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Acked-by: Zhang Rui <rui.zhang@intel.com>
should I apply this patch or you have a separate tree for all these
changes?
thanks,
rui
> ---
> ...pu-cooling-api.txt => cpu-cooling-api.rst} | 39 +-
> .../{exynos_thermal => exynos_thermal.rst} | 47 +-
> ...emulation => exynos_thermal_emulation.rst} | 66 +--
> Documentation/thermal/index.rst | 18 +
> ...el_powerclamp.txt => intel_powerclamp.rst} | 177 +++----
> .../{nouveau_thermal => nouveau_thermal.rst} | 54 +-
> ...ower_allocator.txt => power_allocator.rst} | 140 ++---
> .../thermal/{sysfs-api.txt => sysfs-api.rst} | 490 ++++++++++++--
> ----
> ...hermal => x86_pkg_temperature_thermal.rst} | 28 +-
> MAINTAINERS | 2 +-
> include/linux/thermal.h | 4 +-
> 11 files changed, 665 insertions(+), 400 deletions(-)
> rename Documentation/thermal/{cpu-cooling-api.txt => cpu-cooling-
> api.rst} (82%)
> rename Documentation/thermal/{exynos_thermal => exynos_thermal.rst}
> (67%)
> rename Documentation/thermal/{exynos_thermal_emulation =>
> exynos_thermal_emulation.rst} (36%)
> create mode 100644 Documentation/thermal/index.rst
> rename Documentation/thermal/{intel_powerclamp.txt =>
> intel_powerclamp.rst} (76%)
> rename Documentation/thermal/{nouveau_thermal =>
> nouveau_thermal.rst} (64%)
> rename Documentation/thermal/{power_allocator.txt =>
> power_allocator.rst} (74%)
> rename Documentation/thermal/{sysfs-api.txt => sysfs-api.rst} (66%)
> rename Documentation/thermal/{x86_pkg_temperature_thermal =>
> x86_pkg_temperature_thermal.rst} (80%)
>
> diff --git a/Documentation/thermal/cpu-cooling-api.txt
> b/Documentation/thermal/cpu-cooling-api.rst
> similarity index 82%
> rename from Documentation/thermal/cpu-cooling-api.txt
> rename to Documentation/thermal/cpu-cooling-api.rst
> index 7df567eaea1a..645d914c45a6 100644
> --- a/Documentation/thermal/cpu-cooling-api.txt
> +++ b/Documentation/thermal/cpu-cooling-api.rst
> @@ -1,5 +1,6 @@
> +=======================
> CPU cooling APIs How To
> -===================================
> +=======================
>
> Written by Amit Daniel Kachhap <amit.kachhap@linaro.org>
>
> @@ -8,40 +9,54 @@ Updated: 6 Jan 2015
> Copyright (c) 2012 Samsung Electronics Co., Ltd(http://www.samsung.
> com)
>
> 0. Introduction
> +===============
>
> The generic cpu cooling(freq clipping) provides
> registration/unregistration APIs
> to the caller. The binding of the cooling devices to the trip point
> is left for
> the user. The registration APIs returns the cooling device pointer.
>
> 1. cpu cooling APIs
> +===================
>
> 1.1 cpufreq registration/unregistration APIs
> -1.1.1 struct thermal_cooling_device *cpufreq_cooling_register(
> - struct cpumask *clip_cpus)
> +--------------------------------------------
> +
> + ::
> +
> + struct thermal_cooling_device
> + *cpufreq_cooling_register(struct cpumask *clip_cpus)
>
> This interface function registers the cpufreq cooling device
> with the name
> "thermal-cpufreq-%x". This api can support multiple instances of
> cpufreq
> cooling devices.
>
> - clip_cpus: cpumask of cpus where the frequency constraints will
> happen.
> + clip_cpus:
> + cpumask of cpus where the frequency constraints will happen.
>
> -1.1.2 struct thermal_cooling_device *of_cpufreq_cooling_register(
> - struct cpufreq_policy
> *policy)
> + ::
> +
> + struct thermal_cooling_device
> + *of_cpufreq_cooling_register(struct cpufreq_policy *policy)
>
> This interface function registers the cpufreq cooling device
> with
> the name "thermal-cpufreq-%x" linking it with a device tree
> node, in
> order to bind it via the thermal DT code. This api can support
> multiple
> instances of cpufreq cooling devices.
>
> - policy: CPUFreq policy.
> + policy:
> + CPUFreq policy.
>
> -1.1.3 void cpufreq_cooling_unregister(struct thermal_cooling_device
> *cdev)
> +
> + ::
> +
> + void cpufreq_cooling_unregister(struct
> thermal_cooling_device *cdev)
>
> This interface function unregisters the "thermal-cpufreq-%x"
> cooling device.
>
> cdev: Cooling device pointer which has to be unregistered.
>
> 2. Power models
> +===============
>
> The power API registration functions provide a simple power model
> for
> CPUs. The current power is calculated as dynamic power (static
> power isn't
> @@ -65,9 +80,9 @@ For a given processor implementation the primary
> factors are:
> variation. In pathological cases this variation can be
> significant,
> but typically it is of a much lesser impact than the factors
> above.
>
> -A high level dynamic power consumption model may then be represented
> as:
> +A high level dynamic power consumption model may then be represented
> as::
>
> -Pdyn = f(run) * Voltage^2 * Frequency * Utilisation
> + Pdyn = f(run) * Voltage^2 * Frequency * Utilisation
>
> f(run) here represents the described execution behaviour and its
> result has a units of Watts/Hz/Volt^2 (this often expressed in
> @@ -80,9 +95,9 @@ factors. Therefore, in initial implementation that
> contribution is
> represented as a constant coefficient. This is a simplification
> consistent with the relative contribution to overall power
> variation.
>
> -In this simplified representation our model becomes:
> +In this simplified representation our model becomes::
>
> -Pdyn = Capacitance * Voltage^2 * Frequency * Utilisation
> + Pdyn = Capacitance * Voltage^2 * Frequency * Utilisation
>
> Where `capacitance` is a constant that represents an indicative
> running time dynamic power coefficient in fundamental units of
> diff --git a/Documentation/thermal/exynos_thermal
> b/Documentation/thermal/exynos_thermal.rst
> similarity index 67%
> rename from Documentation/thermal/exynos_thermal
> rename to Documentation/thermal/exynos_thermal.rst
> index 9010c4416967..5bd556566c70 100644
> --- a/Documentation/thermal/exynos_thermal
> +++ b/Documentation/thermal/exynos_thermal.rst
> @@ -1,8 +1,11 @@
> +========================
> Kernel driver exynos_tmu
> -=================
> +========================
>
> Supported chips:
> +
> * ARM SAMSUNG EXYNOS4, EXYNOS5 series of SoC
> +
> Datasheet: Not publicly available
>
> Authors: Donggeun Kim <dg77.kim@samsung.com>
> @@ -19,32 +22,39 @@ Temperature can be taken from the temperature
> code.
> There are three equations converting from temperature to temperature
> code.
>
> The three equations are:
> - 1. Two point trimming
> + 1. Two point trimming::
> +
> Tc = (T - 25) * (TI2 - TI1) / (85 - 25) + TI1
>
> - 2. One point trimming
> + 2. One point trimming::
> +
> Tc = T + TI1 - 25
>
> - 3. No trimming
> + 3. No trimming::
> +
> Tc = T + 50
>
> - Tc: Temperature code, T: Temperature,
> - TI1: Trimming info for 25 degree Celsius (stored at TRIMINFO
> register)
> + Tc:
> + Temperature code, T: Temperature,
> + TI1:
> + Trimming info for 25 degree Celsius (stored at TRIMINFO
> register)
> Temperature code measured at 25 degree Celsius which is
> unchanged
> - TI2: Trimming info for 85 degree Celsius (stored at TRIMINFO
> register)
> + TI2:
> + Trimming info for 85 degree Celsius (stored at TRIMINFO
> register)
> Temperature code measured at 85 degree Celsius which is
> unchanged
>
> TMU(Thermal Management Unit) in EXYNOS4/5 generates interrupt
> when temperature exceeds pre-defined levels.
> The maximum number of configurable threshold is five.
> -The threshold levels are defined as follows:
> +The threshold levels are defined as follows::
> +
> Level_0: current temperature > trigger_level_0 + threshold
> Level_1: current temperature > trigger_level_1 + threshold
> Level_2: current temperature > trigger_level_2 + threshold
> Level_3: current temperature > trigger_level_3 + threshold
>
> - The threshold and each trigger_level are set
> - through the corresponding registers.
> +The threshold and each trigger_level are set
> +through the corresponding registers.
>
> When an interrupt occurs, this driver notify kernel thermal
> framework
> with the function exynos_report_trigger.
> @@ -54,24 +64,27 @@ it can be used to synchronize the cooling action.
> TMU driver description:
> -----------------------
>
> -The exynos thermal driver is structured as,
> +The exynos thermal driver is structured as::
>
> Kernel Core thermal
> framework
> (thermal_core.c, step_wise.c,
> cpu_cooling.c)
> ^
> |
> |
> -TMU configuration data -------> TMU Driver <------> Exynos Core
> thermal wrapper
> -(exynos_tmu_data.c) (exynos_tmu.c) (exynos_th
> ermal_common.c)
> -(exynos_tmu_data.h) (exynos_tmu.h) (exynos_th
> ermal_common.h)
> + TMU configuration data -----> TMU Driver <----> Exynos Core
> thermal wrapper
> + (exynos_tmu_data.c) (exynos_tmu.c) (exynos_
> thermal_common.c)
> + (exynos_tmu_data.h) (exynos_tmu.h) (exynos_
> thermal_common.h)
>
> -a) TMU configuration data: This consist of TMU register
> offsets/bitfields
> +a) TMU configuration data:
> + This consist of TMU register offsets/bitfields
> described through structure exynos_tmu_registers.
> Also several
> other platform data (struct
> exynos_tmu_platform_data) members
> are used to configure the TMU.
> -b) TMU driver: This component initialises the TMU controller and
> sets different
> +b) TMU driver:
> + This component initialises the TMU controller and
> sets different
> thresholds. It invokes core thermal implementation
> with the call
> exynos_report_trigger.
> -c) Exynos Core thermal wrapper: This provides 3 wrapper function to
> use the
> +c) Exynos Core thermal wrapper:
> + This provides 3 wrapper function to use the
> Kernel core thermal framework. They are
> exynos_unregister_thermal,
> exynos_register_thermal and exynos_report_trigger.
> diff --git a/Documentation/thermal/exynos_thermal_emulation
> b/Documentation/thermal/exynos_thermal_emulation.rst
> similarity index 36%
> rename from Documentation/thermal/exynos_thermal_emulation
> rename to Documentation/thermal/exynos_thermal_emulation.rst
> index b15efec6ca28..c21d10838bc5 100644
> --- a/Documentation/thermal/exynos_thermal_emulation
> +++ b/Documentation/thermal/exynos_thermal_emulation.rst
> @@ -1,5 +1,6 @@
> -EXYNOS EMULATION MODE
> -========================
> +=====================
> +Exynos Emulation Mode
> +=====================
>
> Copyright (C) 2012 Samsung Electronics
>
> @@ -8,46 +9,53 @@ Written by Jonghwa Lee <jonghwa3.lee@samsung.com>
> Description
> -----------
>
> -Exynos 4x12 (4212, 4412) and 5 series provide emulation mode for
> thermal management unit.
> -Thermal emulation mode supports software debug for TMU's operation.
> User can set temperature
> -manually with software code and TMU will read current temperature
> from user value not from
> -sensor's value.
> +Exynos 4x12 (4212, 4412) and 5 series provide emulation mode for
> thermal
> +management unit. Thermal emulation mode supports software debug for
> +TMU's operation. User can set temperature manually with software
> code
> +and TMU will read current temperature from user value not from
> sensor's
> +value.
>
> -Enabling CONFIG_THERMAL_EMULATION option will make this support
> available.
> -When it's enabled, sysfs node will be created as
> +Enabling CONFIG_THERMAL_EMULATION option will make this support
> +available. When it's enabled, sysfs node will be created as
> /sys/devices/virtual/thermal/thermal_zone'zone id'/emul_temp.
>
> -The sysfs node, 'emul_node', will contain value 0 for the initial
> state. When you input any
> -temperature you want to update to sysfs node, it automatically
> enable emulation mode and
> -current temperature will be changed into it.
> -(Exynos also supports user changeable delay time which would be used
> to delay of
> - changing temperature. However, this node only uses same delay of
> real sensing time, 938us.)
> +The sysfs node, 'emul_node', will contain value 0 for the initial
> state.
> +When you input any temperature you want to update to sysfs node, it
> +automatically enable emulation mode and current temperature will be
> +changed into it.
>
> -Exynos emulation mode requires synchronous of value changing and
> enabling. It means when you
> -want to update the any value of delay or next temperature, then you
> have to enable emulation
> -mode at the same time. (Or you have to keep the mode enabling.) If
> you don't, it fails to
> -change the value to updated one and just use last succeessful value
> repeatedly. That's why
> -this node gives users the right to change termerpature only. Just
> one interface makes it more
> -simply to use.
> +(Exynos also supports user changeable delay time which would be used
> to
> +delay of changing temperature. However, this node only uses same
> delay
> +of real sensing time, 938us.)
> +
> +Exynos emulation mode requires synchronous of value changing and
> +enabling. It means when you want to update the any value of delay or
> +next temperature, then you have to enable emulation mode at the same
> +time. (Or you have to keep the mode enabling.) If you don't, it
> fails to
> +change the value to updated one and just use last succeessful value
> +repeatedly. That's why this node gives users the right to change
> +termerpature only. Just one interface makes it more simply to use.
>
> Disabling emulation mode only requires writing value 0 to sysfs
> node.
>
> +::
>
> -TEMP 120 |
> +
> + TEMP 120 |
> |
> 100 |
> |
> 80 |
> - | +-----------
> - 60 | | |
> - | +-------------| |
> + | +-----------
> + 60 | | |
> + | +-------------| |
> 40 | | | |
> - | | | |
> - 20 | | | +-
> ---------
> - | | | |
> |
> + | | | |
> + 20 | | | +----
> ------
> + | | | |
> |
> 0
> |______________|_____________|__________|__________|_________
> - A A A
> A TIME
> + A A A
> A TIME
> |<----->| |<----->| |<----->|
> |
> | 938us | | | | |
> |
> -emulation : 0 50 | 70 | 20 |
> 0
> -current temp : sensor 50 70 20
> sensor
> + emulation : 0 50 | 70 | 20 |
> 0
> + current temp: sensor 50 70 20
> sensor
> diff --git a/Documentation/thermal/index.rst
> b/Documentation/thermal/index.rst
> new file mode 100644
> index 000000000000..8c1c00146cad
> --- /dev/null
> +++ b/Documentation/thermal/index.rst
> @@ -0,0 +1,18 @@
> +:orphan:
> +
> +=======
> +Thermal
> +=======
> +
> +.. toctree::
> + :maxdepth: 1
> +
> + cpu-cooling-api
> + sysfs-api
> + power_allocator
> +
> + exynos_thermal
> + exynos_thermal_emulation
> + intel_powerclamp
> + nouveau_thermal
> + x86_pkg_temperature_thermal
> diff --git a/Documentation/thermal/intel_powerclamp.txt
> b/Documentation/thermal/intel_powerclamp.rst
> similarity index 76%
> rename from Documentation/thermal/intel_powerclamp.txt
> rename to Documentation/thermal/intel_powerclamp.rst
> index b5df21168fbc..3f6dfb0b3ea6 100644
> --- a/Documentation/thermal/intel_powerclamp.txt
> +++ b/Documentation/thermal/intel_powerclamp.rst
> @@ -1,10 +1,13 @@
> - =======================
> - INTEL POWERCLAMP DRIVER
> - =======================
> -By: Arjan van de Ven <arjan@linux.intel.com>
> - Jacob Pan <jacob.jun.pan@linux.intel.com>
> +=======================
> +Intel Powerclamp Driver
> +=======================
> +
> +By:
> + - Arjan van de Ven <arjan@linux.intel.com>
> + - Jacob Pan <jacob.jun.pan@linux.intel.com>
> +
> +.. Contents:
>
> -Contents:
> (*) Introduction
> - Goals and Objectives
>
> @@ -23,7 +26,6 @@ Contents:
> - Generic Thermal Layer (sysfs)
> - Kernel APIs (TBD)
>
> -============
> INTRODUCTION
> ============
>
> @@ -47,7 +49,6 @@ scalability, and user experience. In many cases,
> clear advantage is
> shown over taking the CPU offline or modulating the CPU clock.
>
>
> -===================
> THEORY OF OPERATION
> ===================
>
> @@ -57,11 +58,12 @@ Idle Injection
> On modern Intel processors (Nehalem or later), package level C-state
> residency is available in MSRs, thus also available to the kernel.
>
> -These MSRs are:
> - #define MSR_PKG_C2_RESIDENCY 0x60D
> - #define MSR_PKG_C3_RESIDENCY 0x3F8
> - #define MSR_PKG_C6_RESIDENCY 0x3F9
> - #define MSR_PKG_C7_RESIDENCY 0x3FA
> +These MSRs are::
> +
> + #define MSR_PKG_C2_RESIDENCY 0x60D
> + #define MSR_PKG_C3_RESIDENCY 0x3F8
> + #define MSR_PKG_C6_RESIDENCY 0x3F9
> + #define MSR_PKG_C7_RESIDENCY 0x3FA
>
> If the kernel can also inject idle time to the system, then a
> closed-loop control system can be established that manages package
> @@ -96,19 +98,21 @@ are not masked. Tests show that the extra wakeups
> from scheduler tick
> have a dramatic impact on the effectiveness of the powerclamp driver
> on large scale systems (Westmere system with 80 processors).
>
> -CPU0
> - ____________ ____________
> -kidle_inject/0 | sleep | mwait | sleep |
> - _________| |________| |_______
> - duration
> -CPU1
> - ____________ ____________
> -kidle_inject/1 | sleep | mwait | sleep |
> - _________| |________| |_______
> - ^
> - |
> - |
> - roundup(jiffies, interval)
> +::
> +
> + CPU0
> + ____________ ____________
> + kidle_inject/0 | sleep | mwait | sleep |
> + _________| |________| |_______
> + duration
> + CPU1
> + ____________ ____________
> + kidle_inject/1 | sleep | mwait | sleep |
> + _________| |________| |_______
> + ^
> + |
> + |
> + roundup(jiffies, interval)
>
> Only one CPU is allowed to collect statistics and update global
> control parameters. This CPU is referred to as the controlling CPU
> in
> @@ -148,7 +152,7 @@ b) determine the amount of compensation needed at
> each target ratio
>
> Compensation to each target ratio consists of two parts:
>
> - a) steady state error compensation
> + a) steady state error compensation
> This is to offset the error occurring when the system can
> enter idle without extra wakeups (such as external
> interrupts).
>
> @@ -158,41 +162,42 @@ Compensation to each target ratio consists of
> two parts:
> slowing down CPU activities.
>
> A debugfs file is provided for the user to examine compensation
> -progress and results, such as on a Westmere system.
> -[jacob@nex01 ~]$ cat
> -/sys/kernel/debug/intel_powerclamp/powerclamp_calib
> -controlling cpu: 0
> -pct confidence steady dynamic (compensation)
> -0 0 0 0
> -1 1 0 0
> -2 1 1 0
> -3 3 1 0
> -4 3 1 0
> -5 3 1 0
> -6 3 1 0
> -7 3 1 0
> -8 3 1 0
> -...
> -30 3 2 0
> -31 3 2 0
> -32 3 1 0
> -33 3 2 0
> -34 3 1 0
> -35 3 2 0
> -36 3 1 0
> -37 3 2 0
> -38 3 1 0
> -39 3 2 0
> -40 3 3 0
> -41 3 1 0
> -42 3 2 0
> -43 3 1 0
> -44 3 1 0
> -45 3 2 0
> -46 3 3 0
> -47 3 0 0
> -48 3 2 0
> -49 3 3 0
> +progress and results, such as on a Westmere system::
> +
> + [jacob@nex01 ~]$ cat
> + /sys/kernel/debug/intel_powerclamp/powerclamp_calib
> + controlling cpu: 0
> + pct confidence steady dynamic (compensation)
> + 0 0 0 0
> + 1 1 0 0
> + 2 1 1 0
> + 3 3 1 0
> + 4 3 1 0
> + 5 3 1 0
> + 6 3 1 0
> + 7 3 1 0
> + 8 3 1 0
> + ...
> + 30 3 2 0
> + 31 3 2 0
> + 32 3 1 0
> + 33 3 2 0
> + 34 3 1 0
> + 35 3 2 0
> + 36 3 1 0
> + 37 3 2 0
> + 38 3 1 0
> + 39 3 2 0
> + 40 3 3 0
> + 41 3 1 0
> + 42 3 2 0
> + 43 3 1 0
> + 44 3 1 0
> + 45 3 2 0
> + 46 3 3 0
> + 47 3 0 0
> + 48 3 2 0
> + 49 3 3 0
>
> Calibration occurs during runtime. No offline method is available.
> Steady state compensation is used only when confidence levels of all
> @@ -217,9 +222,8 @@ keeps track of clamping kernel threads, even
> after they are migrated
> to other CPUs, after a CPU offline event.
>
>
> -=====================
> Performance Analysis
> -=====================
> +====================
> This section describes the general performance data collected on
> multiple systems, including Westmere (80P) and Ivy Bridge (4P, 8P).
>
> @@ -257,16 +261,15 @@ achieve up to 40% better performance per watt.
> (measured by a spin
> counter summed over per CPU counting threads spawned for all running
> CPUs).
>
> -====================
> Usage and Interfaces
> ====================
> The powerclamp driver is registered to the generic thermal layer as
> a
> -cooling device. Currently, it’s not bound to any thermal zones.
> +cooling device. Currently, it’s not bound to any thermal zones::
>
> -jacob@chromoly:/sys/class/thermal/cooling_device14$ grep . *
> -cur_state:0
> -max_state:50
> -type:intel_powerclamp
> + jacob@chromoly:/sys/class/thermal/cooling_device14$ grep . *
> + cur_state:0
> + max_state:50
> + type:intel_powerclamp
>
> cur_state allows user to set the desired idle percentage. Writing 0
> to
> cur_state will stop idle injection. Writing a value between 1 and
> @@ -278,9 +281,9 @@ cur_state returns value -1 instead of 0 which is
> to avoid confusing
> 100% busy state with the disabled state.
>
> Example usage:
> -- To inject 25% idle time
> -$ sudo sh -c "echo 25 >
> /sys/class/thermal/cooling_device80/cur_state
> -"
> +- To inject 25% idle time::
> +
> + $ sudo sh -c "echo 25 >
> /sys/class/thermal/cooling_device80/cur_state
>
> If the system is not busy and has more than 25% idle time already,
> then the powerclamp driver will not start idle injection. Using Top
> @@ -292,23 +295,23 @@ idle time is accounted as normal idle in that
> common code path is
> taken as the idle task.
>
> In this example, 24.1% idle is shown. This helps the system admin or
> -user determine the cause of slowdown, when a powerclamp driver is in
> action.
> +user determine the cause of slowdown, when a powerclamp driver is in
> action::
>
>
> -Tasks: 197 total, 1 running, 196 sleeping, 0 stopped, 0 zombie
> -Cpu(s): 71.2%us, 4.7%sy, 0.0%ni,
> 24.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
> -Mem: 3943228k total, 1689632k used, 2253596k free, 74960k
> buffers
> -Swap: 4087804k total, 0k used, 4087804k free, 945336k
> cached
> + Tasks: 197 total, 1 running, 196 sleeping, 0 stopped, 0
> zombie
> + Cpu(s): 71.2%us, 4.7%sy, 0.0%ni,
> 24.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
> + Mem: 3943228k total, 1689632k used, 2253596k free, 74960k
> buffers
> + Swap: 4087804k total, 0k used, 4087804k free, 945336k
> cached
>
> - PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> - 3352 jacob 20 0 262m 644 428 S 286 0.0 0:17.16 spin
> - 3341 root -51 0 0 0 0 D 25 0.0 0:01.62
> kidle_inject/0
> - 3344 root -51 0 0 0 0 D 25 0.0 0:01.60
> kidle_inject/3
> - 3342 root -51 0 0 0 0 D 25 0.0 0:01.61
> kidle_inject/1
> - 3343 root -51 0 0 0 0 D 25 0.0 0:01.60
> kidle_inject/2
> - 2935 jacob 20 0 696m 125m 35m S 5 3.3 0:31.11 firefox
> - 1546 root 20 0 158m 20m 6640 S 3 0.5 0:26.97 Xorg
> - 2100 jacob 20 0 1223m 88m 30m S 3 2.3 0:23.68 compiz
> + PID USER PR NI VIRT RES SHR S %CPU
> %MEM TIME+ COMMAND
> + 3352 jacob 20 0 262m 644 428 S 286 0.0 0:17.16 spin
> + 3341 root -51 0 0 0 0 D 25 0.0 0:01.62
> kidle_inject/0
> + 3344 root -51 0 0 0 0 D 25 0.0 0:01.60
> kidle_inject/3
> + 3342 root -51 0 0 0 0 D 25 0.0 0:01.61
> kidle_inject/1
> + 3343 root -51 0 0 0 0 D 25 0.0 0:01.60
> kidle_inject/2
> + 2935 jacob 20 0 696m 125m 35m S 5 3.3 0:31.11
> firefox
> + 1546 root 20 0 158m 20m 6640 S 3 0.5 0:26.97 Xorg
> + 2100 jacob 20 0 1223m 88m 30m S 3 2.3 0:23.68
> compiz
>
> Tests have shown that by using the powerclamp driver as a cooling
> device, a PID based userspace thermal controller can manage to
> diff --git a/Documentation/thermal/nouveau_thermal
> b/Documentation/thermal/nouveau_thermal.rst
> similarity index 64%
> rename from Documentation/thermal/nouveau_thermal
> rename to Documentation/thermal/nouveau_thermal.rst
> index 6e17a11efcb0..37255fd6735d 100644
> --- a/Documentation/thermal/nouveau_thermal
> +++ b/Documentation/thermal/nouveau_thermal.rst
> @@ -1,13 +1,15 @@
> +=====================
> Kernel driver nouveau
> -===================
> +=====================
>
> Supported chips:
> +
> * NV43+
>
> Authors: Martin Peres (mupuf) <martin.peres@free.fr>
>
> Description
> ----------
> +-----------
>
> This driver allows to read the GPU core temperature, drive the GPU
> fan and
> set temperature alarms.
> @@ -19,20 +21,25 @@ interface is likely not to work. This document
> may then not cover your situation
> entirely.
>
> Temperature management
> ---------------------
> +----------------------
>
> Temperature is exposed under as a read-only HWMON attribute
> temp1_input.
>
> In order to protect the GPU from overheating, Nouveau supports 4
> configurable
> temperature thresholds:
>
> - * Fan_boost: Fan speed is set to 100% when reaching this
> temperature;
> - * Downclock: The GPU will be downclocked to reduce its power
> dissipation;
> - * Critical: The GPU is put on hold to further lower power
> dissipation;
> - * Shutdown: Shut the computer down to protect your GPU.
> + * Fan_boost:
> + Fan speed is set to 100% when reaching this temperature;
> + * Downclock:
> + The GPU will be downclocked to reduce its power dissipation;
> + * Critical:
> + The GPU is put on hold to further lower power dissipation;
> + * Shutdown:
> + Shut the computer down to protect your GPU.
>
> -WARNING: Some of these thresholds may not be used by Nouveau
> depending
> -on your chipset.
> +WARNING:
> + Some of these thresholds may not be used by Nouveau
> depending
> + on your chipset.
>
> The default value for these thresholds comes from the GPU's vbios.
> These
> thresholds can be configured thanks to the following HWMON
> attributes:
> @@ -46,19 +53,24 @@ NOTE: Remember that the values are stored as
> milli degrees Celsius. Don't forget
> to multiply!
>
> Fan management
> -------------
> +--------------
>
> Not all cards have a drivable fan. If you do, then the following
> HWMON
> attributes should be available:
>
> - * pwm1_enable: Current fan management mode (NONE, MANUAL or AUTO);
> - * pwm1: Current PWM value (power percentage);
> - * pwm1_min: The minimum PWM speed allowed;
> - * pwm1_max: The maximum PWM speed allowed (bypassed when hitting
> Fan_boost);
> + * pwm1_enable:
> + Current fan management mode (NONE, MANUAL or AUTO);
> + * pwm1:
> + Current PWM value (power percentage);
> + * pwm1_min:
> + The minimum PWM speed allowed;
> + * pwm1_max:
> + The maximum PWM speed allowed (bypassed when hitting
> Fan_boost);
>
> You may also have the following attribute:
>
> - * fan1_input: Speed in RPM of your fan.
> + * fan1_input:
> + Speed in RPM of your fan.
>
> Your fan can be driven in different modes:
>
> @@ -66,14 +78,16 @@ Your fan can be driven in different modes:
> * 1: The fan can be driven in manual (use pwm1 to change the
> speed);
> * 2; The fan is driven automatically depending on the temperature.
>
> -NOTE: Be sure to use the manual mode if you want to drive the fan
> speed manually
> +NOTE:
> + Be sure to use the manual mode if you want to drive the fan speed
> manually
>
> -NOTE2: When operating in manual mode outside the vbios-defined
> -[PWM_min, PWM_max] range, the reported fan speed (RPM) may not be
> accurate
> -depending on your hardware.
> +NOTE2:
> + When operating in manual mode outside the vbios-defined
> + [PWM_min, PWM_max] range, the reported fan speed (RPM) may not be
> accurate
> + depending on your hardware.
>
> Bug reports
> ----------
> +-----------
>
> Thermal management on Nouveau is new and may not work on all cards.
> If you have
> inquiries, please ping mupuf on IRC (#nouveau, freenode).
> diff --git a/Documentation/thermal/power_allocator.txt
> b/Documentation/thermal/power_allocator.rst
> similarity index 74%
> rename from Documentation/thermal/power_allocator.txt
> rename to Documentation/thermal/power_allocator.rst
> index 9fb0ff06dca9..67b6a3297238 100644
> --- a/Documentation/thermal/power_allocator.txt
> +++ b/Documentation/thermal/power_allocator.rst
> @@ -1,3 +1,4 @@
> +=================================
> Power allocator governor tunables
> =================================
>
> @@ -25,36 +26,36 @@ temperature as the control input and power as the
> controlled output:
> P_max = k_p * e + k_i * err_integral + k_d * diff_err +
> sustainable_power
>
> where
> - e = desired_temperature - current_temperature
> - err_integral is the sum of previous errors
> - diff_err = e - previous_error
> + - e = desired_temperature - current_temperature
> + - err_integral is the sum of previous errors
> + - diff_err = e - previous_error
>
> -It is similar to the one depicted below:
> +It is similar to the one depicted below::
>
> - k_d
> - |
> -current_temp |
> - | v
> - | +----------+ +---+
> - | +----->| diff_err |-->| X |------+
> - | | +----------+ +---+ |
> - | | | tdp ac
> tor
> - | | k_i | | get_reque
> sted_power()
> - | | | | | |
> |
> - | | | | | |
> | ...
> - v | v v v v
> v
> - +---+ | +-------+ +---+ +---+ +---+ +-----
> -----+
> - | S |-------+----->| sum e |----->| X |--->| S |-->| S |
> -->|power |
> - +---+ | +-------+ +---+ +---+ +---
> + |allocation|
> - ^ | ^ +-----
> -----+
> - | | | |
> |
> - | | +---
> + | | |
> - | +------->| X |-------------------
> + v v
> - | +---+ granted
> performance
> -desired_temperature ^
> - |
> - |
> - k_po/k_pu
> + k_d
> + |
> + current_temp |
> + | v
> + | +----------+ +---+
> + | +----->| diff_err |-->| X |------+
> + | | +----------+ +---+ |
> + | | | tdp ac
> tor
> + | | k_i | | get_reque
> sted_power()
> + | | | | | |
> |
> + | | | | | |
> | ...
> + v | v v v v
> v
> + +---+ | +-------+ +---+ +---+ +---+ +-----
> -----+
> + | S |-----+----->| sum e |----->| X |--->| S |-->| S |
> -->|power |
> + +---+ | +-------+ +---+ +---+ +---
> + |allocation|
> + ^ | ^ +-----
> -----+
> + | | | |
> |
> + | | +---
> + | | |
> + | +------->| X |-------------------
> + v v
> + | +---+ granted
> performance
> + desired_temperature ^
> + |
> + |
> + k_po/k_pu
>
> Sustainable power
> -----------------
> @@ -73,7 +74,7 @@ is typically 2000mW, while on a 10" tablet is
> around 4500mW (may vary
> depending on screen size).
>
> If you are using device tree, do add it as a property of the
> -thermal-zone. For example:
> +thermal-zone. For example::
>
> thermal-zones {
> soc_thermal {
> @@ -85,7 +86,7 @@ thermal-zone. For example:
> Instead, if the thermal zone is registered from the platform code,
> pass a
> `thermal_zone_params` that has a `sustainable_power`. If no
> `thermal_zone_params` were being passed, then something like below
> -will suffice:
> +will suffice::
>
> static const struct thermal_zone_params tz_params = {
> .sustainable_power = 3500,
> @@ -112,18 +113,18 @@ available capacity at a low temperature. On
> the other hand, a high
> value of `k_pu` will result in the governor granting very high power
> while temperature is low, and may lead to temperature overshooting.
>
> -The default value for `k_pu` is:
> +The default value for `k_pu` is::
>
> 2 * sustainable_power / (desired_temperature - switch_on_temp)
>
> This means that at `switch_on_temp` the output of the controller's
> proportional term will be 2 * `sustainable_power`. The default
> value
> -for `k_po` is:
> +for `k_po` is::
>
> sustainable_power / (desired_temperature - switch_on_temp)
>
> Focusing on the proportional and feed forward values of the PID
> -controller equation we have:
> +controller equation we have::
>
> P_max = k_p * e + sustainable_power
>
> @@ -134,21 +135,23 @@ is the desired one, then the proportional
> component is zero and
> thermal equilibrium under constant load. `sustainable_power` is
> only
> an estimate, which is the reason for closed-loop control such as
> this.
>
> -Expanding `k_pu` we get:
> +Expanding `k_pu` we get::
> +
> P_max = 2 * sustainable_power * (T_set - T) / (T_set - T_on) +
> - sustainable_power
> + sustainable_power
>
> -where
> - T_set is the desired temperature
> - T is the current temperature
> - T_on is the switch on temperature
> +where:
> +
> + - T_set is the desired temperature
> + - T is the current temperature
> + - T_on is the switch on temperature
>
> When the current temperature is the switch_on temperature, the above
> -formula becomes:
> +formula becomes::
>
> P_max = 2 * sustainable_power * (T_set - T_on) / (T_set - T_on)
> +
> - sustainable_power = 2 * sustainable_power +
> sustainable_power =
> - 3 * sustainable_power
> + sustainable_power = 2 * sustainable_power +
> sustainable_power =
> + 3 * sustainable_power
>
> Therefore, the proportional term alone linearly decreases power from
> 3 * `sustainable_power` to `sustainable_power` as the temperature
> @@ -178,11 +181,18 @@ Cooling device power API
> Cooling devices controlled by this governor must supply the
> additional
> "power" API in their `cooling_device_ops`. It consists on three
> ops:
>
> -1. int get_requested_power(struct thermal_cooling_device *cdev,
> - struct thermal_zone_device *tz, u32 *power);
> -@cdev: The `struct thermal_cooling_device` pointer
> -@tz: thermal zone in which we are currently operating
> -@power: pointer in which to store the calculated power
> +1. ::
> +
> + int get_requested_power(struct thermal_cooling_device *cdev,
> + struct thermal_zone_device *tz, u32
> *power);
> +
> +
> +@cdev:
> + The `struct thermal_cooling_device` pointer
> +@tz:
> + thermal zone in which we are currently operating
> +@power:
> + pointer in which to store the calculated power
>
> `get_requested_power()` calculates the power requested by the device
> in milliwatts and stores it in @power . It should return 0 on
> @@ -190,23 +200,37 @@ success, -E* on failure. This is currently
> used by the power
> allocator governor to calculate how much power to give to each
> cooling
> device.
>
> -2. int state2power(struct thermal_cooling_device *cdev, struct
> - thermal_zone_device *tz, unsigned long state, u32 *power);
> -@cdev: The `struct thermal_cooling_device` pointer
> -@tz: thermal zone in which we are currently operating
> -@state: A cooling device state
> -@power: pointer in which to store the equivalent power
> +2. ::
> +
> + int state2power(struct thermal_cooling_device *cdev, struct
> + thermal_zone_device *tz, unsigned long
> state,
> + u32 *power);
> +
> +@cdev:
> + The `struct thermal_cooling_device` pointer
> +@tz:
> + thermal zone in which we are currently operating
> +@state:
> + A cooling device state
> +@power:
> + pointer in which to store the equivalent power
>
> Convert cooling device state @state into power consumption in
> milliwatts and store it in @power. It should return 0 on success,
> -E*
> on failure. This is currently used by thermal core to calculate the
> maximum power that an actor can consume.
>
> -3. int power2state(struct thermal_cooling_device *cdev, u32 power,
> - unsigned long *state);
> -@cdev: The `struct thermal_cooling_device` pointer
> -@power: power in milliwatts
> -@state: pointer in which to store the resulting state
> +3. ::
> +
> + int power2state(struct thermal_cooling_device *cdev, u32
> power,
> + unsigned long *state);
> +
> +@cdev:
> + The `struct thermal_cooling_device` pointer
> +@power:
> + power in milliwatts
> +@state:
> + pointer in which to store the resulting state
>
> Calculate a cooling device state that would make the device consume
> at
> most @power mW and store it in @state. It should return 0 on
> success,
> diff --git a/Documentation/thermal/sysfs-api.txt
> b/Documentation/thermal/sysfs-api.rst
> similarity index 66%
> rename from Documentation/thermal/sysfs-api.txt
> rename to Documentation/thermal/sysfs-api.rst
> index c3fa500df92c..e4930761d3e5 100644
> --- a/Documentation/thermal/sysfs-api.txt
> +++ b/Documentation/thermal/sysfs-api.rst
> @@ -1,3 +1,4 @@
> +===================================
> Generic Thermal Sysfs driver How To
> ===================================
>
> @@ -9,6 +10,7 @@ Copyright (c) 2008 Intel Corporation
>
>
> 0. Introduction
> +===============
>
> The generic thermal sysfs provides a set of interfaces for thermal
> zone
> devices (sensors) and thermal cooling devices (fan, processor...) to
> register
> @@ -25,59 +27,90 @@ An intelligent thermal management application can
> make decisions based on
> inputs from thermal zone attributes (the current temperature and
> trip point
> temperature) and throttle appropriate devices.
>
> -[0-*] denotes any positive number starting from 0
> -[1-*] denotes any positive number starting from 1
> +- `[0-*]` denotes any positive number starting from 0
> +- `[1-*]` denotes any positive number starting from 1
>
> 1. thermal sysfs driver interface functions
> +===========================================
>
> 1.1 thermal zone device interface
> -1.1.1 struct thermal_zone_device *thermal_zone_device_register(char
> *type,
> - int trips, int mask, void *devdata,
> - struct thermal_zone_device_ops *ops,
> - const struct thermal_zone_params *tzp,
> - int passive_delay, int polling_delay))
> +---------------------------------
> +
> + ::
> +
> + struct thermal_zone_device
> + *thermal_zone_device_register(char *type,
> + int trips, int mask, void
> *devdata,
> + struct thermal_zone_device_ops
> *ops,
> + const struct
> thermal_zone_params *tzp,
> + int passive_delay, int
> polling_delay))
>
> This interface function adds a new thermal zone device (sensor)
> to
> - /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind
> all the
> + /sys/class/thermal folder as `thermal_zone[0-*]`. It tries to
> bind all the
> thermal cooling devices registered at the same time.
>
> - type: the thermal zone type.
> - trips: the total number of trip points this thermal zone
> supports.
> - mask: Bit string: If 'n'th bit is set, then trip point 'n' is
> writeable.
> - devdata: device private data
> - ops: thermal zone device call-backs.
> - .bind: bind the thermal zone device with a thermal cooling
> device.
> - .unbind: unbind the thermal zone device with a thermal
> cooling device.
> - .get_temp: get the current temperature of the thermal zone.
> - .set_trips: set the trip points window. Whenever the current
> temperature
> + type:
> + the thermal zone type.
> + trips:
> + the total number of trip points this thermal zone supports.
> + mask:
> + Bit string: If 'n'th bit is set, then trip point 'n' is
> writeable.
> + devdata:
> + device private data
> + ops:
> + thermal zone device call-backs.
> +
> + .bind:
> + bind the thermal zone device with a thermal cooling
> device.
> + .unbind:
> + unbind the thermal zone device with a thermal
> cooling device.
> + .get_temp:
> + get the current temperature of the thermal zone.
> + .set_trips:
> + set the trip points window. Whenever the current
> temperature
> is updated, the trip points immediately below
> and above the
> current temperature are found.
> - .get_mode: get the current mode (enabled/disabled) of the
> thermal zone.
> - - "enabled" means the kernel thermal management is
> enabled.
> - - "disabled" will prevent kernel thermal driver action
> upon trip points
> - so that user applications can take charge of thermal
> management.
> - .set_mode: set the mode (enabled/disabled) of the thermal
> zone.
> - .get_trip_type: get the type of certain trip point.
> - .get_trip_temp: get the temperature above which the certain
> trip point
> + .get_mode:
> + get the current mode (enabled/disabled) of the
> thermal zone.
> +
> + - "enabled" means the kernel thermal
> management is
> + enabled.
> + - "disabled" will prevent kernel thermal
> driver action
> + upon trip points so that user applications
> can take
> + charge of thermal management.
> + .set_mode:
> + set the mode (enabled/disabled) of the thermal zone.
> + .get_trip_type:
> + get the type of certain trip point.
> + .get_trip_temp:
> + get the temperature above which the certain
> trip point
> will be fired.
> - .set_emul_temp: set the emulation temperature which helps in
> debugging
> + .set_emul_temp:
> + set the emulation temperature which helps in
> debugging
> different threshold temperature points.
> - tzp: thermal zone platform parameters.
> - passive_delay: number of milliseconds to wait between polls when
> + tzp:
> + thermal zone platform parameters.
> + passive_delay:
> + number of milliseconds to wait between polls when
> performing passive cooling.
> - polling_delay: number of milliseconds to wait between polls when
> checking
> + polling_delay:
> + number of milliseconds to wait between polls when checking
> whether trip points have been crossed (0 for interrupt
> driven systems).
>
> + ::
>
> -1.1.2 void thermal_zone_device_unregister(struct thermal_zone_device
> *tz)
> + void thermal_zone_device_unregister(struct
> thermal_zone_device *tz)
>
> This interface function removes the thermal zone device.
> It deletes the corresponding entry from /sys/class/thermal
> folder and
> unbinds all the thermal cooling devices it uses.
>
> -1.1.3 struct thermal_zone_device *thermal_zone_of_sensor_register(
> - struct device *dev, int sensor_id, void *data,
> - const struct thermal_zone_of_device_ops *ops)
> + ::
> +
> + struct thermal_zone_device
> + *thermal_zone_of_sensor_register(struct device *dev, int
> sensor_id,
> + void *data,
> + const struct
> thermal_zone_of_device_ops *ops)
>
> This interface adds a new sensor to a DT thermal zone.
> This function will search the list of thermal zones
> described in
> @@ -87,25 +120,33 @@ temperature) and throttle appropriate devices.
> thermal zone device.
>
> The parameters for this interface are:
> - dev: Device node of sensor containing valid
> node pointer in
> +
> + dev:
> + Device node of sensor containing valid node
> pointer in
> dev->of_node.
> - sensor_id: a sensor identifier, in case the sensor IP
> has more
> + sensor_id:
> + a sensor identifier, in case the sensor IP
> has more
> than one sensors
> - data: a private pointer (owned by the caller)
> that will be
> + data:
> + a private pointer (owned by the caller) that
> will be
> passed back, when a temperature reading is
> needed.
> - ops: struct thermal_zone_of_device_ops *.
> + ops:
> + `struct thermal_zone_of_device_ops *`.
>
> - get_temp: a pointer to a function
> that reads the
> + ============== ============================
> ===========
> + get_temp a pointer to a function that
> reads the
> sensor temperature. This is
> mandatory
> callback provided by sensor
> driver.
> - set_trips: a pointer to a function that
> sets a
> + set_trips a pointer to a function
> that sets a
> temperature window. When
> this window is
> left the driver must inform
> the thermal
> core via
> thermal_zone_device_update.
> - get_trend: a pointer to a function
> that reads the
> + get_trend a pointer to a function
> that reads the
> sensor temperature trend.
> - set_emul_temp: a pointer to a
> function that sets
> + set_emul_temp a pointer to a function
> that sets
> sensor emulated temperature.
> + ============== ============================
> ===========
> +
> The thermal zone temperature is provided by the get_temp()
> function
> pointer of thermal_zone_of_device_ops. When called, it will
> have the private pointer @data back.
> @@ -114,8 +155,10 @@ temperature) and throttle appropriate devices.
> handle. Caller should check the return handle with IS_ERR()
> for finding
> whether success or not.
>
> -1.1.4 void thermal_zone_of_sensor_unregister(struct device *dev,
> - struct thermal_zone_device *tzd)
> + ::
> +
> + void thermal_zone_of_sensor_unregister(struct device
> *dev,
> + struct
> thermal_zone_device *tzd)
>
> This interface unregisters a sensor from a DT thermal zone
> which was
> successfully added by interface
> thermal_zone_of_sensor_register().
> @@ -124,21 +167,29 @@ temperature) and throttle appropriate devices.
> interface. It will also silent the zone by remove the
> .get_temp() and
> get_trend() thermal zone device callbacks.
>
> -1.1.5 struct thermal_zone_device
> *devm_thermal_zone_of_sensor_register(
> - struct device *dev, int sensor_id,
> - void *data, const struct thermal_zone_of_device_ops
> *ops)
> + ::
> +
> + struct thermal_zone_device
> + *devm_thermal_zone_of_sensor_register(struct device *dev,
> + int sensor_id,
> + void *data,
> + const struct
> thermal_zone_of_device_ops *ops)
>
> This interface is resource managed version of
> thermal_zone_of_sensor_register().
> +
> All details of thermal_zone_of_sensor_register() described
> in
> section 1.1.3 is applicable here.
> +
> The benefit of using this interface to register sensor is
> that it
> is not require to explicitly call
> thermal_zone_of_sensor_unregister()
> in error path or during driver unbinding as this is done by
> driver
> resource manager.
>
> -1.1.6 void devm_thermal_zone_of_sensor_unregister(struct device
> *dev,
> - struct thermal_zone_device *tzd)
> + ::
> +
> + void devm_thermal_zone_of_sensor_unregister(struct
> device *dev,
> + struct
> thermal_zone_device *tzd)
>
> This interface is resource managed version of
> thermal_zone_of_sensor_unregister().
> @@ -147,123 +198,186 @@ temperature) and throttle appropriate
> devices.
> Normally this function will not need to be called and the
> resource
> management code will ensure that the resource is freed.
>
> -1.1.7 int thermal_zone_get_slope(struct thermal_zone_device *tz)
> + ::
> +
> + int thermal_zone_get_slope(struct
> thermal_zone_device *tz)
>
> This interface is used to read the slope attribute value
> for the thermal zone device, which might be useful for
> platform
> drivers for temperature calculations.
>
> -1.1.8 int thermal_zone_get_offset(struct thermal_zone_device *tz)
> + ::
> +
> + int thermal_zone_get_offset(struct
> thermal_zone_device *tz)
>
> This interface is used to read the offset attribute value
> for the thermal zone device, which might be useful for
> platform
> drivers for temperature calculations.
>
> 1.2 thermal cooling device interface
> -1.2.1 struct thermal_cooling_device
> *thermal_cooling_device_register(char *name,
> - void *devdata, struct thermal_cooling_device_ops *)
> +------------------------------------
> +
> +
> + ::
> +
> + struct thermal_cooling_device
> + *thermal_cooling_device_register(char *name,
> + void *devdata, struct
> thermal_cooling_device_ops *)
>
> This interface function adds a new thermal cooling device
> (fan/processor/...)
> - to /sys/class/thermal/ folder as cooling_device[0-*]. It tries
> to bind itself
> + to /sys/class/thermal/ folder as `cooling_device[0-*]`. It tries
> to bind itself
> to all the thermal zone devices registered at the same time.
> - name: the cooling device name.
> - devdata: device private data.
> - ops: thermal cooling devices call-backs.
> - .get_max_state: get the Maximum throttle state of the
> cooling device.
> - .get_cur_state: get the Currently requested throttle state
> of the cooling device.
> - .set_cur_state: set the Current throttle state of the
> cooling device.
> -
> -1.2.2 void thermal_cooling_device_unregister(struct
> thermal_cooling_device *cdev)
> +
> + name:
> + the cooling device name.
> + devdata:
> + device private data.
> + ops:
> + thermal cooling devices call-backs.
> +
> + .get_max_state:
> + get the Maximum throttle state of the cooling
> device.
> + .get_cur_state:
> + get the Currently requested throttle state of the
> + cooling device.
> + .set_cur_state:
> + set the Current throttle state of the cooling
> device.
> +
> + ::
> +
> + void thermal_cooling_device_unregister(struct
> thermal_cooling_device *cdev)
>
> This interface function removes the thermal cooling device.
> It deletes the corresponding entry from /sys/class/thermal
> folder and
> unbinds itself from all the thermal zone devices using it.
>
> 1.3 interface for binding a thermal zone device with a thermal
> cooling device
> -1.3.1 int thermal_zone_bind_cooling_device(struct
> thermal_zone_device *tz,
> - int trip, struct thermal_cooling_device *cdev,
> - unsigned long upper, unsigned long lower, unsigned int
> weight);
> +------------------------------------------------------------------
> -----------
> +
> + ::
> +
> + int thermal_zone_bind_cooling_device(struct
> thermal_zone_device *tz,
> + int trip, struct thermal_cooling_device *cdev,
> + unsigned long upper, unsigned long lower, unsigned
> int weight);
>
> This interface function binds a thermal cooling device to a
> particular trip
> point of a thermal zone device.
> +
> This function is usually called in the thermal zone device .bind
> callback.
> - tz: the thermal zone device
> - cdev: thermal cooling device
> - trip: indicates which trip point in this thermal zone the
> cooling device
> - is associated with.
> - upper:the Maximum cooling state for this trip point.
> - THERMAL_NO_LIMIT means no upper limit,
> +
> + tz:
> + the thermal zone device
> + cdev:
> + thermal cooling device
> + trip:
> + indicates which trip point in this thermal zone the
> cooling device
> + is associated with.
> + upper:
> + the Maximum cooling state for this trip point.
> + THERMAL_NO_LIMIT means no upper limit,
> and the cooling device can be in max_state.
> - lower:the Minimum cooling state can be used for this trip point.
> - THERMAL_NO_LIMIT means no lower limit,
> + lower:
> + the Minimum cooling state can be used for this trip point.
> + THERMAL_NO_LIMIT means no lower limit,
> and the cooling device can be in cooling state 0.
> - weight: the influence of this cooling device in this thermal
> - zone. See 1.4.1 below for more information.
> + weight:
> + the influence of this cooling device in this thermal
> + zone. See 1.4.1 below for more information.
>
> -1.3.2 int thermal_zone_unbind_cooling_device(struct
> thermal_zone_device *tz,
> - int trip, struct thermal_cooling_device *cdev);
> + ::
> +
> + int thermal_zone_unbind_cooling_device(struct
> thermal_zone_device *tz,
> + int trip, struct
> thermal_cooling_device *cdev);
>
> This interface function unbinds a thermal cooling device from a
> particular
> trip point of a thermal zone device. This function is usually
> called in
> the thermal zone device .unbind callback.
> - tz: the thermal zone device
> - cdev: thermal cooling device
> - trip: indicates which trip point in this thermal zone the
> cooling device
> - is associated with.
> +
> + tz:
> + the thermal zone device
> + cdev:
> + thermal cooling device
> + trip:
> + indicates which trip point in this thermal zone the cooling
> device
> + is associated with.
>
> 1.4 Thermal Zone Parameters
> -1.4.1 struct thermal_bind_params
> +---------------------------
> +
> + ::
> +
> + struct thermal_bind_params
> +
> This structure defines the following parameters that are used to
> bind
> a zone with a cooling device for a particular trip point.
> - .cdev: The cooling device pointer
> - .weight: The 'influence' of a particular cooling device on this
> - zone. This is relative to the rest of the cooling
> - devices. For example, if all cooling devices have a
> - weight of 1, then they all contribute the same. You can
> - use percentages if you want, but it's not mandatory. A
> - weight of 0 means that this cooling device doesn't
> - contribute to the cooling of this zone unless all
> cooling
> - devices have a weight of 0. If all weights are 0, then
> - they all contribute the same.
> - .trip_mask:This is a bit mask that gives the binding relation
> between
> - this thermal zone and cdev, for a particular trip
> point.
> - If nth bit is set, then the cdev and thermal zone are
> bound
> - for trip point n.
> - .binding_limits: This is an array of cooling state limits. Must
> have
> - exactly 2 * thermal_zone.number_of_trip_points.
> It is an
> - array consisting of tuples <lower-state upper-
> state> of
> - state limits. Each trip will be associated with
> one state
> - limit tuple when binding. A NULL pointer means
> - <THERMAL_NO_LIMITS THERMAL_NO_LIMITS> on all
> trips.
> - These limits are used when binding a cdev to a
> trip point.
> - .match: This call back returns success(0) if the 'tz and cdev'
> need to
> +
> + .cdev:
> + The cooling device pointer
> + .weight:
> + The 'influence' of a particular cooling device on this
> + zone. This is relative to the rest of the cooling
> + devices. For example, if all cooling devices have a
> + weight of 1, then they all contribute the same. You can
> + use percentages if you want, but it's not mandatory. A
> + weight of 0 means that this cooling device doesn't
> + contribute to the cooling of this zone unless all
> cooling
> + devices have a weight of 0. If all weights are 0, then
> + they all contribute the same.
> + .trip_mask:
> + This is a bit mask that gives the binding relation
> between
> + this thermal zone and cdev, for a particular trip
> point.
> + If nth bit is set, then the cdev and thermal zone are
> bound
> + for trip point n.
> + .binding_limits:
> + This is an array of cooling state limits. Must
> have
> + exactly 2 * thermal_zone.number_of_trip_points.
> It is an
> + array consisting of tuples <lower-state upper-
> state> of
> + state limits. Each trip will be associated with
> one state
> + limit tuple when binding. A NULL pointer means
> + <THERMAL_NO_LIMITS THERMAL_NO_LIMITS> on all
> trips.
> + These limits are used when binding a cdev to a
> trip point.
> + .match:
> + This call back returns success(0) if the 'tz and cdev'
> need to
> be bound, as per platform data.
> -1.4.2 struct thermal_zone_params
> +
> + ::
> +
> + struct thermal_zone_params
> +
> This structure defines the platform level parameters for a
> thermal zone.
> This data, for each thermal zone should come from the platform
> layer.
> This is an optional feature where some platforms can choose not
> to
> provide this data.
> - .governor_name: Name of the thermal governor used for this zone
> - .no_hwmon: a boolean to indicate if the thermal to hwmon sysfs
> interface
> - is required. when no_hwmon == false, a hwmon sysfs
> interface
> - will be created. when no_hwmon == true, nothing will
> be done.
> - In case the thermal_zone_params is NULL, the hwmon
> interface
> - will be created (for backward compatibility).
> - .num_tbps: Number of thermal_bind_params entries for this zone
> - .tbp: thermal_bind_params entries
> +
> + .governor_name:
> + Name of the thermal governor used for this zone
> + .no_hwmon:
> + a boolean to indicate if the thermal to hwmon sysfs
> interface
> + is required. when no_hwmon == false, a hwmon sysfs
> interface
> + will be created. when no_hwmon == true, nothing will
> be done.
> + In case the thermal_zone_params is NULL, the hwmon
> interface
> + will be created (for backward compatibility).
> + .num_tbps:
> + Number of thermal_bind_params entries for this zone
> + .tbp:
> + thermal_bind_params entries
>
> 2. sysfs attributes structure
> +=============================
>
> +== ================
> RO read only value
> WO write only value
> RW read/write value
> +== ================
>
> Thermal sysfs attributes will be represented under
> /sys/class/thermal.
> Hwmon sysfs I/F extension is also available under /sys/class/hwmon
> if hwmon is compiled in or built as a module.
>
> -Thermal zone device sys I/F, created once it's registered:
> -/sys/class/thermal/thermal_zone[0-*]:
> +Thermal zone device sys I/F, created once it's registered::
> +
> + /sys/class/thermal/thermal_zone[0-*]:
> |---type: Type of the thermal zone
> |---temp: Current temperature
> |---mode: Working mode of the thermal
> zone
> @@ -282,8 +396,9 @@ Thermal zone device sys I/F, created once it's
> registered:
> |---slope: Slope constant applied as linear
> extrapolation
> |---offset: Offset constant applied as linear
> extrapolation
>
> -Thermal cooling device sys I/F, created once it's registered:
> -/sys/class/thermal/cooling_device[0-*]:
> +Thermal cooling device sys I/F, created once it's registered::
> +
> + /sys/class/thermal/cooling_device[0-*]:
> |---type: Type of the cooling
> device(processor/fan/...)
> |---max_state: Maximum cooling state of the
> cooling device
> |---cur_state: Current cooling state of the
> cooling device
> @@ -299,11 +414,13 @@ the relationship between a thermal zone and its
> associated cooling device.
> They are created/removed for each successful execution of
> thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device.
>
> -/sys/class/thermal/thermal_zone[0-*]:
> +::
> +
> + /sys/class/thermal/thermal_zone[0-*]:
> |---cdev[0-*]: [0-*]th cooling device in current
> thermal zone
> |---cdev[0-*]_trip_point: Trip point that cdev[0-*] is
> associated with
> |---cdev[0-*]_weight: Influence of the cooling device in
> - this thermal zone
> + this thermal zone
>
> Besides the thermal zone device sysfs I/F and cooling device sysfs
> I/F,
> the generic thermal driver also creates a hwmon sysfs I/F for each
> _type_
> @@ -311,16 +428,17 @@ of thermal zone device. E.g. the generic
> thermal driver registers one hwmon
> class device and build the associated hwmon sysfs I/F for all the
> registered
> ACPI thermal zones.
>
> -/sys/class/hwmon/hwmon[0-*]:
> +::
> +
> + /sys/class/hwmon/hwmon[0-*]:
> |---name: The type of the thermal zone
> devices
> |---temp[1-*]_input: The current temperature of thermal
> zone [1-*]
> |---temp[1-*]_critical: The critical trip point of
> thermal zone [1-*]
>
> Please read Documentation/hwmon/sysfs-interface.rst for additional
> information.
>
> -***************************
> -* Thermal zone attributes *
> -***************************
> +Thermal zone attributes
> +-----------------------
>
> type
> Strings which represent the thermal zone type.
> @@ -340,54 +458,67 @@ mode
> This file gives information about the algorithm that is
> currently
> managing the thermal zone. It can be either default kernel
> based
> algorithm or user space application.
> - enabled = enable Kernel Thermal management.
> - disabled = Preventing kernel thermal zone driver
> actions upon
> +
> + enabled
> + enable Kernel Thermal management.
> + disabled
> + Preventing kernel thermal zone driver
> actions upon
> trip points so that user application can
> take full
> charge of the thermal management.
> +
> RW, Optional
>
> policy
> One of the various thermal governors used for a particular
> zone.
> +
> RW, Required
>
> available_policies
> Available thermal governors which can be used for a
> particular zone.
> +
> RO, Required
>
> -trip_point_[0-*]_temp
> +`trip_point_[0-*]_temp`
> The temperature above which trip point will be fired.
> +
> Unit: millidegree Celsius
> +
> RO, Optional
>
> -trip_point_[0-*]_type
> +`trip_point_[0-*]_type`
> Strings which indicate the type of the trip point.
> - E.g. it can be one of critical, hot, passive, active[0-*]
> for ACPI
> +
> + E.g. it can be one of critical, hot, passive, `active[0-*]`
> for ACPI
> thermal zone.
> +
> RO, Optional
>
> -trip_point_[0-*]_hyst
> +`trip_point_[0-*]_hyst`
> The hysteresis value for a trip point, represented as an
> integer
> Unit: Celsius
> RW, Optional
>
> -cdev[0-*]
> +`cdev[0-*]`
> Sysfs link to the thermal cooling device node where the sys
> I/F
> for cooling device throttling control represents.
> +
> RO, Optional
>
> -cdev[0-*]_trip_point
> - The trip point in this thermal zone which cdev[0-*] is
> associated
> +`cdev[0-*]_trip_point`
> + The trip point in this thermal zone which `cdev[0-*]` is
> associated
> with; -1 means the cooling device is not associated with any
> trip
> point.
> +
> RO, Optional
>
> -cdev[0-*]_weight
> - The influence of cdev[0-*] in this thermal zone. This value
> - is relative to the rest of cooling devices in the thermal
> - zone. For example, if a cooling device has a weight double
> - than that of other, it's twice as effective in cooling the
> - thermal zone.
> - RW, Optional
> +`cdev[0-*]_weight`
> + The influence of `cdev[0-*]` in this thermal zone. This
> value
> + is relative to the rest of cooling devices in the thermal
> + zone. For example, if a cooling device has a weight double
> + than that of other, it's twice as effective in cooling the
> + thermal zone.
> +
> + RW, Optional
>
> passive
> Attribute is only present for zones in which the passive
> cooling
> @@ -395,8 +526,11 @@ passive
> and can be set to a temperature (in millidegrees) to enable
> a
> passive trip point for the zone. Activation is done by
> polling with
> an interval of 1 second.
> +
> Unit: millidegrees Celsius
> +
> Valid values: 0 (disabled) or greater than 1000
> +
> RW, Optional
>
> emul_temp
> @@ -407,17 +541,21 @@ emul_temp
> threshold and its associated cooling action. This is write
> only node
> and writing 0 on this node should disable emulation.
> Unit: millidegree Celsius
> +
> WO, Optional
>
> - WARNING: Be careful while enabling this option on
> production systems,
> - because userland can easily disable the thermal policy by
> simply
> - flooding this sysfs node with low temperature values.
> + WARNING:
> + Be careful while enabling this option on production
> systems,
> + because userland can easily disable the thermal policy
> by simply
> + flooding this sysfs node with low temperature values.
>
> sustainable_power
> An estimate of the sustained power that can be dissipated by
> the thermal zone. Used by the power allocator governor. For
> - more information see
> Documentation/thermal/power_allocator.txt
> + more information see
> Documentation/thermal/power_allocator.rst
> +
> Unit: milliwatts
> +
> RW, Optional
>
> k_po
> @@ -425,7 +563,8 @@ k_po
> controller during temperature overshoot. Temperature
> overshoot
> is when the current temperature is above the "desired
> temperature" trip point. For more information see
> - Documentation/thermal/power_allocator.txt
> + Documentation/thermal/power_allocator.rst
> +
> RW, Optional
>
> k_pu
> @@ -433,20 +572,23 @@ k_pu
> controller during temperature undershoot. Temperature
> undershoot
> is when the current temperature is below the "desired
> temperature" trip point. For more information see
> - Documentation/thermal/power_allocator.txt
> + Documentation/thermal/power_allocator.rst
> +
> RW, Optional
>
> k_i
> The integral term of the power allocator governor's PID
> controller. This term allows the PID controller to
> compensate
> for long term drift. For more information see
> - Documentation/thermal/power_allocator.txt
> + Documentation/thermal/power_allocator.rst
> +
> RW, Optional
>
> k_d
> The derivative term of the power allocator governor's PID
> controller. For more information see
> - Documentation/thermal/power_allocator.txt
> + Documentation/thermal/power_allocator.rst
> +
> RW, Optional
>
> integral_cutoff
> @@ -456,8 +598,10 @@ integral_cutoff
> example, if integral_cutoff is 0, then the integral term
> only
> accumulates error when temperature is above the desired
> temperature trip point. For more information see
> - Documentation/thermal/power_allocator.txt
> + Documentation/thermal/power_allocator.rst
> +
> Unit: millidegree Celsius
> +
> RW, Optional
>
> slope
> @@ -465,6 +609,7 @@ slope
> to determine a hotspot temperature based off the sensor's
> raw readings. It is up to the device driver to determine
> the usage of these values.
> +
> RW, Optional
>
> offset
> @@ -472,28 +617,33 @@ offset
> to determine a hotspot temperature based off the sensor's
> raw readings. It is up to the device driver to determine
> the usage of these values.
> +
> RW, Optional
>
> -*****************************
> -* Cooling device attributes *
> -*****************************
> +Cooling device attributes
> +-------------------------
>
> type
> String which represents the type of device, e.g:
> +
> - for generic ACPI: should be "Fan", "Processor" or "LCD"
> - for memory controller device on intel_menlow platform:
> should be "Memory controller".
> +
> RO, Required
>
> max_state
> The maximum permissible cooling state of this cooling
> device.
> +
> RO, Required
>
> cur_state
> The current cooling state of this cooling device.
> The value can any integer numbers between 0 and max_state:
> +
> - cur_state == 0 means no cooling
> - cur_state == max_state means the maximum cooling.
> +
> RW, Required
>
> stats/reset
> @@ -508,9 +658,11 @@ stats/time_in_state_ms:
> units here is 10mS (similar to other time exported in
> /proc).
> RO, Required
>
> +
> stats/total_trans:
> A single positive value showing the total number of times
> the state of a
> cooling device is changed.
> +
> RO, Required
>
> stats/trans_table:
> @@ -522,6 +674,7 @@ stats/trans_table:
> RO, Required
>
> 3. A simple implementation
> +==========================
>
> ACPI thermal zone may support multiple trip points like critical,
> hot,
> passive, active. If an ACPI thermal zone supports critical, passive,
> @@ -532,11 +685,10 @@ thermal_cooling_device. Both are considered to
> have the same
> effectiveness in cooling the thermal zone.
>
> If the processor is listed in _PSL method, and the fan is listed in
> _AL0
> -method, the sys I/F structure will be built like this:
> +method, the sys I/F structure will be built like this::
>
> -/sys/class/thermal:
> -
> -|thermal_zone1:
> + /sys/class/thermal:
> + |thermal_zone1:
> |---type: acpitz
> |---temp: 37000
> |---mode: enabled
> @@ -557,24 +709,24 @@ method, the sys I/F structure will be built
> like this:
> |---cdev1_trip_point: 2 /* cdev1 can be used for
> active[0]*/
> |---cdev1_weight: 1024
>
> -|cooling_device0:
> + |cooling_device0:
> |---type: Processor
> |---max_state: 8
> |---cur_state: 0
>
> -|cooling_device3:
> + |cooling_device3:
> |---type: Fan
> |---max_state: 2
> |---cur_state: 0
>
> -/sys/class/hwmon:
> -
> -|hwmon0:
> + /sys/class/hwmon:
> + |hwmon0:
> |---name: acpitz
> |---temp1_input: 37000
> |---temp1_crit: 100000
>
> 4. Event Notification
> +=====================
>
> The framework includes a simple notification mechanism, in the form
> of a
> netlink event. Netlink socket initialization is done during the
> _init_
> @@ -587,21 +739,28 @@ event will be one of:{THERMAL_AUX0,
> THERMAL_AUX1, THERMAL_CRITICAL,
> THERMAL_DEV_FAULT}. Notification can be sent when the current
> temperature
> crosses any of the configured thresholds.
>
> -5. Export Symbol APIs:
> +5. Export Symbol APIs
> +=====================
> +
> +5.1. get_tz_trend
> +-----------------
>
> -5.1: get_tz_trend:
> This function returns the trend of a thermal zone, i.e the rate of
> change
> of temperature of the thermal zone. Ideally, the thermal sensor
> drivers
> are supposed to implement the callback. If they don't, the thermal
> framework calculated the trend by comparing the previous and the
> current
> temperature values.
>
> -5.2:get_thermal_instance:
> +5.2. get_thermal_instance
> +-------------------------
> +
> This function returns the thermal_instance corresponding to a given
> {thermal_zone, cooling_device, trip_point} combination. Returns NULL
> if such an instance does not exist.
>
> -5.3:thermal_notify_framework:
> +5.3. thermal_notify_framework
> +-----------------------------
> +
> This function handles the trip events from sensor drivers. It starts
> throttling the cooling devices according to the policy configured.
> For CRITICAL and HOT trip points, this notifies the respective
> drivers,
> @@ -609,12 +768,15 @@ and does actual throttling for other trip
> points i.e ACTIVE and PASSIVE.
> The throttling policy is based on the configured platform data; if
> no
> platform data is provided, this uses the step_wise throttling
> policy.
>
> -5.4:thermal_cdev_update:
> +5.4. thermal_cdev_update
> +------------------------
> +
> This function serves as an arbitrator to set the state of a cooling
> device. It sets the cooling device to the deepest cooling state if
> possible.
>
> -6. thermal_emergency_poweroff:
> +6. thermal_emergency_poweroff
> +=============================
>
> On an event of critical trip temperature crossing. Thermal framework
> allows the system to shutdown gracefully by calling
> orderly_poweroff().
> diff --git a/Documentation/thermal/x86_pkg_temperature_thermal
> b/Documentation/thermal/x86_pkg_temperature_thermal.rst
> similarity index 80%
> rename from Documentation/thermal/x86_pkg_temperature_thermal
> rename to Documentation/thermal/x86_pkg_temperature_thermal.rst
> index 17a3a4c0a0ca..f134dbd3f5a9 100644
> --- a/Documentation/thermal/x86_pkg_temperature_thermal
> +++ b/Documentation/thermal/x86_pkg_temperature_thermal.rst
> @@ -1,19 +1,23 @@
> +===================================
> Kernel driver: x86_pkg_temp_thermal
> -===================
> +===================================
>
> Supported chips:
> +
> * x86: with package level thermal management
> +
> (Verify using: CPUID.06H:EAX[bit 6] =1)
>
> Authors: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>
> Reference
> ----
> +---------
> +
> Intel® 64 and IA-32 Architectures Software Developer’s Manual (Jan,
> 2013):
> Chapter 14.6: PACKAGE LEVEL THERMAL MANAGEMENT
>
> Description
> ----------
> +-----------
>
> This driver register CPU digital temperature package level sensor as
> a thermal
> zone with maximum two user mode configurable trip points. Number of
> trip points
> @@ -25,23 +29,27 @@ take any action to control temperature.
> Threshold management
> --------------------
> Each package will register as a thermal zone under
> /sys/class/thermal.
> -Example:
> -/sys/class/thermal/thermal_zone1
> +
> +Example::
> +
> + /sys/class/thermal/thermal_zone1
>
> This contains two trip points:
> +
> - trip_point_0_temp
> - trip_point_1_temp
>
> User can set any temperature between 0 to TJ-Max temperature.
> Temperature units
> -are in milli-degree Celsius. Refer to "Documentation/thermal/sysfs-
> api.txt" for
> +are in milli-degree Celsius. Refer to "Documentation/thermal/sysfs-
> api.rst" for
> thermal sys-fs details.
>
> Any value other than 0 in these trip points, can trigger thermal
> notifications.
> Setting 0, stops sending thermal notifications.
>
> -Thermal notifications: To get kobject-uevent notifications, set the
> thermal zone
> -policy to "user_space". For example: echo -n "user_space" > policy
> -
> -
> +Thermal notifications:
> +To get kobject-uevent notifications, set the thermal zone
> +policy to "user_space".
>
> +For example::
>
> + echo -n "user_space" > policy
> diff --git a/MAINTAINERS b/MAINTAINERS
> index d9e214f68e52..b2254bc8e495 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -15687,7 +15687,7 @@ M: Viresh Kumar <viresh.kumar@linaro.o
> rg>
> M: Javi Merino <javi.merino@kernel.org>
> L: linux-pm@vger.kernel.org
> S: Supported
> -F: Documentation/thermal/cpu-cooling-api.txt
> +F: Documentation/thermal/cpu-cooling-api.rst
> F: drivers/thermal/cpu_cooling.c
> F: include/linux/cpu_cooling.h
>
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 15a4ca5d7099..681047f8cc05 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -251,7 +251,7 @@ struct thermal_bind_params {
> * platform characterization. This value is relative to the
> * rest of the weights so a cooling device whose weight is
> * double that of another cooling device is twice as
> - * effective. See Documentation/thermal/sysfs-api.txt for
> more
> + * effective. See Documentation/thermal/sysfs-api.rst for
> more
> * information.
> */
> int weight;
> @@ -259,7 +259,7 @@ struct thermal_bind_params {
> /*
> * This is a bit mask that gives the binding relation
> between this
> * thermal zone and cdev, for a particular trip point.
> - * See Documentation/thermal/sysfs-api.txt for more
> information.
> + * See Documentation/thermal/sysfs-api.rst for more
> information.
> */
> int trip_mask;
>
^ permalink raw reply
* Re: [PATCH 0/3] Clean up crypto documentation
From: Jonathan Corbet @ 2019-06-25 13:52 UTC (permalink / raw)
To: Gary R Hook
Cc: Joe Perches, Hook, Gary, herbert@gondor.apana.org.au,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-crypto@vger.kernel.org, davem@davemloft.net
In-Reply-To: <d0803cdf-e4d8-102a-d67f-d3a32a4dfff0@amd.com>
On Tue, 25 Jun 2019 13:33:27 +0000
Gary R Hook <ghook@amd.com> wrote:
> > It's been "valid" since I wrote it...it's just not upstream yet :) I
> > expect it to be in 5.3, though. So the best way to refer to a kernel
> > function, going forward, is just function() with no markup needed.
>
> So I'm unclear:
>
> 1) would you prefer I wait on your 5.3 change being fully committed,
> 2) add your change to my local tree and use it, then submit an update
> patchset that depends upon it, or
> 3) re-submit now (using the current method) with suggested changes?
I would just not mark up function() at all, and the right thing will
happen to it in the very near future.
Thanks,
jon
^ permalink raw reply
* Re: [PATCH v1 04/22] docs: thermal: convert to ReST
From: Zhang Rui @ 2019-06-25 14:21 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: Linux Doc Mailing List, Mauro Carvalho Chehab, linux-kernel,
Jonathan Corbet, Amit Daniel Kachhap, Viresh Kumar, Javi Merino,
Kukjin Kim, Krzysztof Kozlowski, Eduardo Valentin, Daniel Lezcano,
linux-pm, linux-arm-kernel, linux-samsung-soc, Arjan van de Ven
In-Reply-To: <20190625105334.19ae5d12@coco.lan>
On 二, 2019-06-25 at 10:53 -0300, Mauro Carvalho Chehab wrote:
> Em Tue, 25 Jun 2019 21:40:11 +0800
> Zhang Rui <rui.zhang@intel.com> escreveu:
>
> >
> > On 二, 2019-06-18 at 18:05 -0300, Mauro Carvalho Chehab wrote:
> > >
> > > Rename the thermal documentation files to ReST, add an
> > > index for them and adjust in order to produce a nice html
> > > output via the Sphinx build system.
> > >
> > > At its new index.rst, let's add a :orphan: while this is not
> > > linked
> > > to
> > > the main index.rst file, in order to avoid build warnings.
> > >
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
> > >
> > Acked-by: Zhang Rui <rui.zhang@intel.com>
> >
> > should I apply this patch or you have a separate tree for all these
> > changes?
> Feel free to apply it directly to your tree. The patches on this
> series are pretty much independent.
>
okay, queued for 5.3-rc1.
thanks,
rui
> >
> >
> > thanks,
> > rui
> > >
> > > ---
> > > ...pu-cooling-api.txt => cpu-cooling-api.rst} | 39 +-
> > > .../{exynos_thermal => exynos_thermal.rst} | 47 +-
> > > ...emulation => exynos_thermal_emulation.rst} | 66 +--
> > > Documentation/thermal/index.rst | 18 +
> > > ...el_powerclamp.txt => intel_powerclamp.rst} | 177 +++----
> > > .../{nouveau_thermal => nouveau_thermal.rst} | 54 +-
> > > ...ower_allocator.txt => power_allocator.rst} | 140 ++---
> > > .../thermal/{sysfs-api.txt => sysfs-api.rst} | 490
> > > ++++++++++++--
> > > ----
> > > ...hermal => x86_pkg_temperature_thermal.rst} | 28 +-
> > > MAINTAINERS | 2 +-
> > > include/linux/thermal.h | 4 +-
> > > 11 files changed, 665 insertions(+), 400 deletions(-)
> > > rename Documentation/thermal/{cpu-cooling-api.txt => cpu-
> > > cooling-
> > > api.rst} (82%)
> > > rename Documentation/thermal/{exynos_thermal =>
> > > exynos_thermal.rst}
> > > (67%)
> > > rename Documentation/thermal/{exynos_thermal_emulation =>
> > > exynos_thermal_emulation.rst} (36%)
> > > create mode 100644 Documentation/thermal/index.rst
> > > rename Documentation/thermal/{intel_powerclamp.txt =>
> > > intel_powerclamp.rst} (76%)
> > > rename Documentation/thermal/{nouveau_thermal =>
> > > nouveau_thermal.rst} (64%)
> > > rename Documentation/thermal/{power_allocator.txt =>
> > > power_allocator.rst} (74%)
> > > rename Documentation/thermal/{sysfs-api.txt => sysfs-api.rst}
> > > (66%)
> > > rename Documentation/thermal/{x86_pkg_temperature_thermal =>
> > > x86_pkg_temperature_thermal.rst} (80%)
> > >
> > > diff --git a/Documentation/thermal/cpu-cooling-api.txt
> > > b/Documentation/thermal/cpu-cooling-api.rst
> > > similarity index 82%
> > > rename from Documentation/thermal/cpu-cooling-api.txt
> > > rename to Documentation/thermal/cpu-cooling-api.rst
> > > index 7df567eaea1a..645d914c45a6 100644
> > > --- a/Documentation/thermal/cpu-cooling-api.txt
> > > +++ b/Documentation/thermal/cpu-cooling-api.rst
> > > @@ -1,5 +1,6 @@
> > > +=======================
> > > CPU cooling APIs How To
> > > -===================================
> > > +=======================
> > >
> > > Written by Amit Daniel Kachhap <amit.kachhap@linaro.org>
> > >
> > > @@ -8,40 +9,54 @@ Updated: 6 Jan 2015
> > > Copyright (c) 2012 Samsung Electronics Co., Ltd(http://www.sams
> > > ung.
> > > com)
> > >
> > > 0. Introduction
> > > +===============
> > >
> > > The generic cpu cooling(freq clipping) provides
> > > registration/unregistration APIs
> > > to the caller. The binding of the cooling devices to the trip
> > > point
> > > is left for
> > > the user. The registration APIs returns the cooling device
> > > pointer.
> > >
> > > 1. cpu cooling APIs
> > > +===================
> > >
> > > 1.1 cpufreq registration/unregistration APIs
> > > -1.1.1 struct thermal_cooling_device *cpufreq_cooling_register(
> > > - struct cpumask *clip_cpus)
> > > +--------------------------------------------
> > > +
> > > + ::
> > > +
> > > + struct thermal_cooling_device
> > > + *cpufreq_cooling_register(struct cpumask *clip_cpus)
> > >
> > > This interface function registers the cpufreq cooling device
> > > with the name
> > > "thermal-cpufreq-%x". This api can support multiple
> > > instances of
> > > cpufreq
> > > cooling devices.
> > >
> > > - clip_cpus: cpumask of cpus where the frequency constraints
> > > will
> > > happen.
> > > + clip_cpus:
> > > + cpumask of cpus where the frequency constraints will
> > > happen.
> > >
> > > -1.1.2 struct thermal_cooling_device
> > > *of_cpufreq_cooling_register(
> > > - struct cpufreq_policy
> > > *policy)
> > > + ::
> > > +
> > > + struct thermal_cooling_device
> > > + *of_cpufreq_cooling_register(struct cpufreq_policy
> > > *policy)
> > >
> > > This interface function registers the cpufreq cooling device
> > > with
> > > the name "thermal-cpufreq-%x" linking it with a device tree
> > > node, in
> > > order to bind it via the thermal DT code. This api can
> > > support
> > > multiple
> > > instances of cpufreq cooling devices.
> > >
> > > - policy: CPUFreq policy.
> > > + policy:
> > > + CPUFreq policy.
> > >
> > > -1.1.3 void cpufreq_cooling_unregister(struct
> > > thermal_cooling_device
> > > *cdev)
> > > +
> > > + ::
> > > +
> > > + void cpufreq_cooling_unregister(struct
> > > thermal_cooling_device *cdev)
> > >
> > > This interface function unregisters the "thermal-cpufreq-%x"
> > > cooling device.
> > >
> > > cdev: Cooling device pointer which has to be unregistered.
> > >
> > > 2. Power models
> > > +===============
> > >
> > > The power API registration functions provide a simple power
> > > model
> > > for
> > > CPUs. The current power is calculated as dynamic power (static
> > > power isn't
> > > @@ -65,9 +80,9 @@ For a given processor implementation the
> > > primary
> > > factors are:
> > > variation. In pathological cases this variation can be
> > > significant,
> > > but typically it is of a much lesser impact than the factors
> > > above.
> > >
> > > -A high level dynamic power consumption model may then be
> > > represented
> > > as:
> > > +A high level dynamic power consumption model may then be
> > > represented
> > > as::
> > >
> > > -Pdyn = f(run) * Voltage^2 * Frequency * Utilisation
> > > + Pdyn = f(run) * Voltage^2 * Frequency * Utilisation
> > >
> > > f(run) here represents the described execution behaviour and its
> > > result has a units of Watts/Hz/Volt^2 (this often expressed in
> > > @@ -80,9 +95,9 @@ factors. Therefore, in initial implementation
> > > that
> > > contribution is
> > > represented as a constant coefficient. This is a simplification
> > > consistent with the relative contribution to overall power
> > > variation.
> > >
> > > -In this simplified representation our model becomes:
> > > +In this simplified representation our model becomes::
> > >
> > > -Pdyn = Capacitance * Voltage^2 * Frequency * Utilisation
> > > + Pdyn = Capacitance * Voltage^2 * Frequency * Utilisation
> > >
> > > Where `capacitance` is a constant that represents an indicative
> > > running time dynamic power coefficient in fundamental units of
> > > diff --git a/Documentation/thermal/exynos_thermal
> > > b/Documentation/thermal/exynos_thermal.rst
> > > similarity index 67%
> > > rename from Documentation/thermal/exynos_thermal
> > > rename to Documentation/thermal/exynos_thermal.rst
> > > index 9010c4416967..5bd556566c70 100644
> > > --- a/Documentation/thermal/exynos_thermal
> > > +++ b/Documentation/thermal/exynos_thermal.rst
> > > @@ -1,8 +1,11 @@
> > > +========================
> > > Kernel driver exynos_tmu
> > > -=================
> > > +========================
> > >
> > > Supported chips:
> > > +
> > > * ARM SAMSUNG EXYNOS4, EXYNOS5 series of SoC
> > > +
> > > Datasheet: Not publicly available
> > >
> > > Authors: Donggeun Kim <dg77.kim@samsung.com>
> > > @@ -19,32 +22,39 @@ Temperature can be taken from the temperature
> > > code.
> > > There are three equations converting from temperature to
> > > temperature
> > > code.
> > >
> > > The three equations are:
> > > - 1. Two point trimming
> > > + 1. Two point trimming::
> > > +
> > > Tc = (T - 25) * (TI2 - TI1) / (85 - 25) + TI1
> > >
> > > - 2. One point trimming
> > > + 2. One point trimming::
> > > +
> > > Tc = T + TI1 - 25
> > >
> > > - 3. No trimming
> > > + 3. No trimming::
> > > +
> > > Tc = T + 50
> > >
> > > - Tc: Temperature code, T: Temperature,
> > > - TI1: Trimming info for 25 degree Celsius (stored at TRIMINFO
> > > register)
> > > + Tc:
> > > + Temperature code, T: Temperature,
> > > + TI1:
> > > + Trimming info for 25 degree Celsius (stored at TRIMINFO
> > > register)
> > > Temperature code measured at 25 degree Celsius which is
> > > unchanged
> > > - TI2: Trimming info for 85 degree Celsius (stored at TRIMINFO
> > > register)
> > > + TI2:
> > > + Trimming info for 85 degree Celsius (stored at TRIMINFO
> > > register)
> > > Temperature code measured at 85 degree Celsius which is
> > > unchanged
> > >
> > > TMU(Thermal Management Unit) in EXYNOS4/5 generates interrupt
> > > when temperature exceeds pre-defined levels.
> > > The maximum number of configurable threshold is five.
> > > -The threshold levels are defined as follows:
> > > +The threshold levels are defined as follows::
> > > +
> > > Level_0: current temperature > trigger_level_0 + threshold
> > > Level_1: current temperature > trigger_level_1 + threshold
> > > Level_2: current temperature > trigger_level_2 + threshold
> > > Level_3: current temperature > trigger_level_3 + threshold
> > >
> > > - The threshold and each trigger_level are set
> > > - through the corresponding registers.
> > > +The threshold and each trigger_level are set
> > > +through the corresponding registers.
> > >
> > > When an interrupt occurs, this driver notify kernel thermal
> > > framework
> > > with the function exynos_report_trigger.
> > > @@ -54,24 +64,27 @@ it can be used to synchronize the cooling
> > > action.
> > > TMU driver description:
> > > -----------------------
> > >
> > > -The exynos thermal driver is structured as,
> > > +The exynos thermal driver is structured as::
> > >
> > > Kernel Core thermal
> > > framework
> > > (thermal_core.c, step_wise.c,
> > > cpu_cooling.c)
> > >
> > > ^
> > >
> > > |
> > >
> > > |
> > > -TMU configuration data -------> TMU Driver <------> Exynos Core
> > > thermal wrapper
> > > -(exynos_tmu_data.c) (exynos_tmu.c) (exyno
> > > s_th
> > > ermal_common.c)
> > > -(exynos_tmu_data.h) (exynos_tmu.h) (exyno
> > > s_th
> > > ermal_common.h)
> > > + TMU configuration data -----> TMU Driver <----> Exynos Core
> > > thermal wrapper
> > > + (exynos_tmu_data.c) (exynos_tmu.c) (exy
> > > nos_
> > > thermal_common.c)
> > > + (exynos_tmu_data.h) (exynos_tmu.h) (exy
> > > nos_
> > > thermal_common.h)
> > >
> > > -a) TMU configuration data: This consist of TMU register
> > > offsets/bitfields
> > > +a) TMU configuration data:
> > > + This consist of TMU register offsets/bitfields
> > > described through structure
> > > exynos_tmu_registers.
> > > Also several
> > > other platform data (struct
> > > exynos_tmu_platform_data) members
> > > are used to configure the TMU.
> > > -b) TMU driver: This component initialises the TMU controller and
> > > sets different
> > > +b) TMU driver:
> > > + This component initialises the TMU controller
> > > and
> > > sets different
> > > thresholds. It invokes core thermal
> > > implementation
> > > with the call
> > > exynos_report_trigger.
> > > -c) Exynos Core thermal wrapper: This provides 3 wrapper function
> > > to
> > > use the
> > > +c) Exynos Core thermal wrapper:
> > > + This provides 3 wrapper function to use the
> > > Kernel core thermal framework. They are
> > > exynos_unregister_thermal,
> > > exynos_register_thermal and
> > > exynos_report_trigger.
> > > diff --git a/Documentation/thermal/exynos_thermal_emulation
> > > b/Documentation/thermal/exynos_thermal_emulation.rst
> > > similarity index 36%
> > > rename from Documentation/thermal/exynos_thermal_emulation
> > > rename to Documentation/thermal/exynos_thermal_emulation.rst
> > > index b15efec6ca28..c21d10838bc5 100644
> > > --- a/Documentation/thermal/exynos_thermal_emulation
> > > +++ b/Documentation/thermal/exynos_thermal_emulation.rst
> > > @@ -1,5 +1,6 @@
> > > -EXYNOS EMULATION MODE
> > > -========================
> > > +=====================
> > > +Exynos Emulation Mode
> > > +=====================
> > >
> > > Copyright (C) 2012 Samsung Electronics
> > >
> > > @@ -8,46 +9,53 @@ Written by Jonghwa Lee <jonghwa3.lee@samsung.co
> > > m>
> > > Description
> > > -----------
> > >
> > > -Exynos 4x12 (4212, 4412) and 5 series provide emulation mode for
> > > thermal management unit.
> > > -Thermal emulation mode supports software debug for TMU's
> > > operation.
> > > User can set temperature
> > > -manually with software code and TMU will read current
> > > temperature
> > > from user value not from
> > > -sensor's value.
> > > +Exynos 4x12 (4212, 4412) and 5 series provide emulation mode for
> > > thermal
> > > +management unit. Thermal emulation mode supports software debug
> > > for
> > > +TMU's operation. User can set temperature manually with software
> > > code
> > > +and TMU will read current temperature from user value not from
> > > sensor's
> > > +value.
> > >
> > > -Enabling CONFIG_THERMAL_EMULATION option will make this support
> > > available.
> > > -When it's enabled, sysfs node will be created as
> > > +Enabling CONFIG_THERMAL_EMULATION option will make this support
> > > +available. When it's enabled, sysfs node will be created as
> > > /sys/devices/virtual/thermal/thermal_zone'zone id'/emul_temp.
> > >
> > > -The sysfs node, 'emul_node', will contain value 0 for the
> > > initial
> > > state. When you input any
> > > -temperature you want to update to sysfs node, it automatically
> > > enable emulation mode and
> > > -current temperature will be changed into it.
> > > -(Exynos also supports user changeable delay time which would be
> > > used
> > > to delay of
> > > - changing temperature. However, this node only uses same delay
> > > of
> > > real sensing time, 938us.)
> > > +The sysfs node, 'emul_node', will contain value 0 for the
> > > initial
> > > state.
> > > +When you input any temperature you want to update to sysfs node,
> > > it
> > > +automatically enable emulation mode and current temperature will
> > > be
> > > +changed into it.
> > >
> > > -Exynos emulation mode requires synchronous of value changing and
> > > enabling. It means when you
> > > -want to update the any value of delay or next temperature, then
> > > you
> > > have to enable emulation
> > > -mode at the same time. (Or you have to keep the mode enabling.)
> > > If
> > > you don't, it fails to
> > > -change the value to updated one and just use last succeessful
> > > value
> > > repeatedly. That's why
> > > -this node gives users the right to change termerpature only.
> > > Just
> > > one interface makes it more
> > > -simply to use.
> > > +(Exynos also supports user changeable delay time which would be
> > > used
> > > to
> > > +delay of changing temperature. However, this node only uses same
> > > delay
> > > +of real sensing time, 938us.)
> > > +
> > > +Exynos emulation mode requires synchronous of value changing and
> > > +enabling. It means when you want to update the any value of
> > > delay or
> > > +next temperature, then you have to enable emulation mode at the
> > > same
> > > +time. (Or you have to keep the mode enabling.) If you don't, it
> > > fails to
> > > +change the value to updated one and just use last succeessful
> > > value
> > > +repeatedly. That's why this node gives users the right to change
> > > +termerpature only. Just one interface makes it more simply to
> > > use.
> > >
> > > Disabling emulation mode only requires writing value 0 to sysfs
> > > node.
> > >
> > > +::
> > >
> > > -TEMP 120 |
> > > +
> > > + TEMP 120 |
> > > |
> > > 100 |
> > > |
> > > 80 |
> > > - | +-----------
> > > - 60 | | |
> > > - | +-------------| |
> > > + | +-----------
> > > + 60 | | |
> > > + | +-------------| |
> > > 40 | | | |
> > > - | | |
> > > |
> > > - 20 | | |
> > > +-
> > > ---------
> > > - | | |
> > > |
> > > |
> > > + | | | |
> > > + 20 | | | +
> > > ----
> > > ------
> > > + | | | |
> > >
> > > |
> > > 0
> > > >
> > > > ______________|_____________|__________|__________|_________
> > > - A A A
> > >
> > > A TIME
> > > + A A A
> > >
> > > A TIME
> > > |<----->| |<----->| |<----->|
> > >
> > > |
> > > | 938us | | | | |
> > >
> > > |
> > > -emulation : 0 50 | 70 | 20 |
> > >
> > > 0
> > > -current temp : sensor 50 70 20
> > >
> > > sensor
> > > + emulation : 0 50 | 70 | 20 |
> > >
> > > 0
> > > + current temp: sensor 50 70 20
> > >
> > > sensor
> > > diff --git a/Documentation/thermal/index.rst
> > > b/Documentation/thermal/index.rst
> > > new file mode 100644
> > > index 000000000000..8c1c00146cad
> > > --- /dev/null
> > > +++ b/Documentation/thermal/index.rst
> > > @@ -0,0 +1,18 @@
> > > +:orphan:
> > > +
> > > +=======
> > > +Thermal
> > > +=======
> > > +
> > > +.. toctree::
> > > + :maxdepth: 1
> > > +
> > > + cpu-cooling-api
> > > + sysfs-api
> > > + power_allocator
> > > +
> > > + exynos_thermal
> > > + exynos_thermal_emulation
> > > + intel_powerclamp
> > > + nouveau_thermal
> > > + x86_pkg_temperature_thermal
> > > diff --git a/Documentation/thermal/intel_powerclamp.txt
> > > b/Documentation/thermal/intel_powerclamp.rst
> > > similarity index 76%
> > > rename from Documentation/thermal/intel_powerclamp.txt
> > > rename to Documentation/thermal/intel_powerclamp.rst
> > > index b5df21168fbc..3f6dfb0b3ea6 100644
> > > --- a/Documentation/thermal/intel_powerclamp.txt
> > > +++ b/Documentation/thermal/intel_powerclamp.rst
> > > @@ -1,10 +1,13 @@
> > > - =======================
> > > - INTEL POWERCLAMP DRIVER
> > > - =======================
> > > -By: Arjan van de Ven <arjan@linux.intel.com>
> > > - Jacob Pan <jacob.jun.pan@linux.intel.com>
> > > +=======================
> > > +Intel Powerclamp Driver
> > > +=======================
> > > +
> > > +By:
> > > + - Arjan van de Ven <arjan@linux.intel.com>
> > > + - Jacob Pan <jacob.jun.pan@linux.intel.com>
> > > +
> > > +.. Contents:
> > >
> > > -Contents:
> > > (*) Introduction
> > > - Goals and Objectives
> > >
> > > @@ -23,7 +26,6 @@ Contents:
> > > - Generic Thermal Layer (sysfs)
> > > - Kernel APIs (TBD)
> > >
> > > -============
> > > INTRODUCTION
> > > ============
> > >
> > > @@ -47,7 +49,6 @@ scalability, and user experience. In many
> > > cases,
> > > clear advantage is
> > > shown over taking the CPU offline or modulating the CPU clock.
> > >
> > >
> > > -===================
> > > THEORY OF OPERATION
> > > ===================
> > >
> > > @@ -57,11 +58,12 @@ Idle Injection
> > > On modern Intel processors (Nehalem or later), package level C-
> > > state
> > > residency is available in MSRs, thus also available to the
> > > kernel.
> > >
> > > -These MSRs are:
> > > - #define MSR_PKG_C2_RESIDENCY 0x60D
> > > - #define MSR_PKG_C3_RESIDENCY 0x3F8
> > > - #define MSR_PKG_C6_RESIDENCY 0x3F9
> > > - #define MSR_PKG_C7_RESIDENCY 0x3FA
> > > +These MSRs are::
> > > +
> > > + #define MSR_PKG_C2_RESIDENCY 0x60D
> > > + #define MSR_PKG_C3_RESIDENCY 0x3F8
> > > + #define MSR_PKG_C6_RESIDENCY 0x3F9
> > > + #define MSR_PKG_C7_RESIDENCY 0x3FA
> > >
> > > If the kernel can also inject idle time to the system, then a
> > > closed-loop control system can be established that manages
> > > package
> > > @@ -96,19 +98,21 @@ are not masked. Tests show that the extra
> > > wakeups
> > > from scheduler tick
> > > have a dramatic impact on the effectiveness of the powerclamp
> > > driver
> > > on large scale systems (Westmere system with 80 processors).
> > >
> > > -CPU0
> > > - ____________ ____________
> > > -kidle_inject/0 | sleep | mwait | sleep |
> > > - _________| |________| |_______
> > > - duration
> > > -CPU1
> > > - ____________ ____________
> > > -kidle_inject/1 | sleep | mwait | sleep |
> > > - _________| |________| |_______
> > > - ^
> > > - |
> > > - |
> > > - roundup(jiffies, interval)
> > > +::
> > > +
> > > + CPU0
> > > + ____________ ____________
> > > + kidle_inject/0 | sleep | mwait | sleep |
> > > + _________| |________| |_______
> > > + duration
> > > + CPU1
> > > + ____________ ____________
> > > + kidle_inject/1 | sleep | mwait | sleep |
> > > + _________| |________| |_______
> > > + ^
> > > + |
> > > + |
> > > + roundup(jiffies, interval)
> > >
> > > Only one CPU is allowed to collect statistics and update global
> > > control parameters. This CPU is referred to as the controlling
> > > CPU
> > > in
> > > @@ -148,7 +152,7 @@ b) determine the amount of compensation
> > > needed at
> > > each target ratio
> > >
> > > Compensation to each target ratio consists of two parts:
> > >
> > > - a) steady state error compensation
> > > + a) steady state error compensation
> > > This is to offset the error occurring when the system
> > > can
> > > enter idle without extra wakeups (such as external
> > > interrupts).
> > >
> > > @@ -158,41 +162,42 @@ Compensation to each target ratio consists
> > > of
> > > two parts:
> > > slowing down CPU activities.
> > >
> > > A debugfs file is provided for the user to examine compensation
> > > -progress and results, such as on a Westmere system.
> > > -[jacob@nex01 ~]$ cat
> > > -/sys/kernel/debug/intel_powerclamp/powerclamp_calib
> > > -controlling cpu: 0
> > > -pct confidence steady dynamic (compensation)
> > > -0 0 0 0
> > > -1 1 0 0
> > > -2 1 1 0
> > > -3 3 1 0
> > > -4 3 1 0
> > > -5 3 1 0
> > > -6 3 1 0
> > > -7 3 1 0
> > > -8 3 1 0
> > > -...
> > > -30 3 2 0
> > > -31 3 2 0
> > > -32 3 1 0
> > > -33 3 2 0
> > > -34 3 1 0
> > > -35 3 2 0
> > > -36 3 1 0
> > > -37 3 2 0
> > > -38 3 1 0
> > > -39 3 2 0
> > > -40 3 3 0
> > > -41 3 1 0
> > > -42 3 2 0
> > > -43 3 1 0
> > > -44 3 1 0
> > > -45 3 2 0
> > > -46 3 3 0
> > > -47 3 0 0
> > > -48 3 2 0
> > > -49 3 3 0
> > > +progress and results, such as on a Westmere system::
> > > +
> > > + [jacob@nex01 ~]$ cat
> > > + /sys/kernel/debug/intel_powerclamp/powerclamp_calib
> > > + controlling cpu: 0
> > > + pct confidence steady dynamic (compensation)
> > > + 0 0 0 0
> > > + 1 1 0 0
> > > + 2 1 1 0
> > > + 3 3 1 0
> > > + 4 3 1 0
> > > + 5 3 1 0
> > > + 6 3 1 0
> > > + 7 3 1 0
> > > + 8 3 1 0
> > > + ...
> > > + 30 3 2 0
> > > + 31 3 2 0
> > > + 32 3 1 0
> > > + 33 3 2 0
> > > + 34 3 1 0
> > > + 35 3 2 0
> > > + 36 3 1 0
> > > + 37 3 2 0
> > > + 38 3 1 0
> > > + 39 3 2 0
> > > + 40 3 3 0
> > > + 41 3 1 0
> > > + 42 3 2 0
> > > + 43 3 1 0
> > > + 44 3 1 0
> > > + 45 3 2 0
> > > + 46 3 3 0
> > > + 47 3 0 0
> > > + 48 3 2 0
> > > + 49 3 3 0
> > >
> > > Calibration occurs during runtime. No offline method is
> > > available.
> > > Steady state compensation is used only when confidence levels of
> > > all
> > > @@ -217,9 +222,8 @@ keeps track of clamping kernel threads, even
> > > after they are migrated
> > > to other CPUs, after a CPU offline event.
> > >
> > >
> > > -=====================
> > > Performance Analysis
> > > -=====================
> > > +====================
> > > This section describes the general performance data collected on
> > > multiple systems, including Westmere (80P) and Ivy Bridge (4P,
> > > 8P).
> > >
> > > @@ -257,16 +261,15 @@ achieve up to 40% better performance per
> > > watt.
> > > (measured by a spin
> > > counter summed over per CPU counting threads spawned for all
> > > running
> > > CPUs).
> > >
> > > -====================
> > > Usage and Interfaces
> > > ====================
> > > The powerclamp driver is registered to the generic thermal layer
> > > as
> > > a
> > > -cooling device. Currently, it’s not bound to any thermal zones.
> > > +cooling device. Currently, it’s not bound to any thermal zones::
> > >
> > > -jacob@chromoly:/sys/class/thermal/cooling_device14$ grep . *
> > > -cur_state:0
> > > -max_state:50
> > > -type:intel_powerclamp
> > > + jacob@chromoly:/sys/class/thermal/cooling_device14$ grep . *
> > > + cur_state:0
> > > + max_state:50
> > > + type:intel_powerclamp
> > >
> > > cur_state allows user to set the desired idle percentage.
> > > Writing 0
> > > to
> > > cur_state will stop idle injection. Writing a value between 1
> > > and
> > > @@ -278,9 +281,9 @@ cur_state returns value -1 instead of 0 which
> > > is
> > > to avoid confusing
> > > 100% busy state with the disabled state.
> > >
> > > Example usage:
> > > -- To inject 25% idle time
> > > -$ sudo sh -c "echo 25 >
> > > /sys/class/thermal/cooling_device80/cur_state
> > > -"
> > > +- To inject 25% idle time::
> > > +
> > > + $ sudo sh -c "echo 25 >
> > > /sys/class/thermal/cooling_device80/cur_state
> > >
> > > If the system is not busy and has more than 25% idle time
> > > already,
> > > then the powerclamp driver will not start idle injection. Using
> > > Top
> > > @@ -292,23 +295,23 @@ idle time is accounted as normal idle in
> > > that
> > > common code path is
> > > taken as the idle task.
> > >
> > > In this example, 24.1% idle is shown. This helps the system
> > > admin or
> > > -user determine the cause of slowdown, when a powerclamp driver
> > > is in
> > > action.
> > > +user determine the cause of slowdown, when a powerclamp driver
> > > is in
> > > action::
> > >
> > >
> > > -Tasks: 197 total, 1 running, 196 sleeping, 0 stopped, 0
> > > zombie
> > > -Cpu(s): 71.2%us, 4.7%sy, 0.0%ni,
> > > 24.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
> > > -Mem: 3943228k total, 1689632k used, 2253596k free, 74960k
> > > buffers
> > > -Swap: 4087804k total, 0k used, 4087804k free, 945336k
> > > cached
> > > + Tasks: 197 total, 1 running, 196 sleeping, 0 stopped, 0
> > > zombie
> > > + Cpu(s): 71.2%us, 4.7%sy, 0.0%ni,
> > > 24.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
> > > + Mem: 3943228k total, 1689632k used, 2253596k
> > > free, 74960k
> > > buffers
> > > + Swap: 4087804k total, 0k used, 4087804k
> > > free, 945336k
> > > cached
> > >
> > > - PID USER PR NI VIRT RES SHR S %CPU
> > > %MEM TIME+ COMMAND
> > > - 3352 jacob 20 0 262m 644 428 S 286 0.0 0:17.16
> > > spin
> > > - 3341 root -51 0 0 0 0 D 25 0.0 0:01.62
> > > kidle_inject/0
> > > - 3344 root -51 0 0 0 0 D 25 0.0 0:01.60
> > > kidle_inject/3
> > > - 3342 root -51 0 0 0 0 D 25 0.0 0:01.61
> > > kidle_inject/1
> > > - 3343 root -51 0 0 0 0 D 25 0.0 0:01.60
> > > kidle_inject/2
> > > - 2935 jacob 20 0 696m 125m 35m S 5 3.3 0:31.11
> > > firefox
> > > - 1546 root 20 0 158m 20m 6640 S 3 0.5 0:26.97
> > > Xorg
> > > - 2100 jacob 20 0 1223m 88m 30m S 3 2.3 0:23.68
> > > compiz
> > > + PID USER PR NI VIRT RES SHR S %CPU
> > > %MEM TIME+ COMMAND
> > > + 3352 jacob 20 0 262m 644 428 S 286 0.0 0:17.16
> > > spin
> > > + 3341 root -51 0 0 0 0 D 25 0.0 0:01.62
> > > kidle_inject/0
> > > + 3344 root -51 0 0 0 0 D 25 0.0 0:01.60
> > > kidle_inject/3
> > > + 3342 root -51 0 0 0 0 D 25 0.0 0:01.61
> > > kidle_inject/1
> > > + 3343 root -51 0 0 0 0 D 25 0.0 0:01.60
> > > kidle_inject/2
> > > + 2935 jacob 20 0 696m 125m 35m S 5 3.3 0:31.11
> > > firefox
> > > + 1546 root 20 0 158m 20m 6640 S 3 0.5 0:26.97
> > > Xorg
> > > + 2100 jacob 20 0 1223m 88m 30m S 3 2.3 0:23.68
> > > compiz
> > >
> > > Tests have shown that by using the powerclamp driver as a
> > > cooling
> > > device, a PID based userspace thermal controller can manage to
> > > diff --git a/Documentation/thermal/nouveau_thermal
> > > b/Documentation/thermal/nouveau_thermal.rst
> > > similarity index 64%
> > > rename from Documentation/thermal/nouveau_thermal
> > > rename to Documentation/thermal/nouveau_thermal.rst
> > > index 6e17a11efcb0..37255fd6735d 100644
> > > --- a/Documentation/thermal/nouveau_thermal
> > > +++ b/Documentation/thermal/nouveau_thermal.rst
> > > @@ -1,13 +1,15 @@
> > > +=====================
> > > Kernel driver nouveau
> > > -===================
> > > +=====================
> > >
> > > Supported chips:
> > > +
> > > * NV43+
> > >
> > > Authors: Martin Peres (mupuf) <martin.peres@free.fr>
> > >
> > > Description
> > > ----------
> > > +-----------
> > >
> > > This driver allows to read the GPU core temperature, drive the
> > > GPU
> > > fan and
> > > set temperature alarms.
> > > @@ -19,20 +21,25 @@ interface is likely not to work. This
> > > document
> > > may then not cover your situation
> > > entirely.
> > >
> > > Temperature management
> > > ---------------------
> > > +----------------------
> > >
> > > Temperature is exposed under as a read-only HWMON attribute
> > > temp1_input.
> > >
> > > In order to protect the GPU from overheating, Nouveau supports 4
> > > configurable
> > > temperature thresholds:
> > >
> > > - * Fan_boost: Fan speed is set to 100% when reaching this
> > > temperature;
> > > - * Downclock: The GPU will be downclocked to reduce its power
> > > dissipation;
> > > - * Critical: The GPU is put on hold to further lower power
> > > dissipation;
> > > - * Shutdown: Shut the computer down to protect your GPU.
> > > + * Fan_boost:
> > > + Fan speed is set to 100% when reaching this temperature;
> > > + * Downclock:
> > > + The GPU will be downclocked to reduce its power
> > > dissipation;
> > > + * Critical:
> > > + The GPU is put on hold to further lower power
> > > dissipation;
> > > + * Shutdown:
> > > + Shut the computer down to protect your GPU.
> > >
> > > -WARNING: Some of these thresholds may not be used by Nouveau
> > > depending
> > > -on your chipset.
> > > +WARNING:
> > > + Some of these thresholds may not be used by Nouveau
> > > depending
> > > + on your chipset.
> > >
> > > The default value for these thresholds comes from the GPU's
> > > vbios.
> > > These
> > > thresholds can be configured thanks to the following HWMON
> > > attributes:
> > > @@ -46,19 +53,24 @@ NOTE: Remember that the values are stored as
> > > milli degrees Celsius. Don't forget
> > > to multiply!
> > >
> > > Fan management
> > > -------------
> > > +--------------
> > >
> > > Not all cards have a drivable fan. If you do, then the following
> > > HWMON
> > > attributes should be available:
> > >
> > > - * pwm1_enable: Current fan management mode (NONE, MANUAL or
> > > AUTO);
> > > - * pwm1: Current PWM value (power percentage);
> > > - * pwm1_min: The minimum PWM speed allowed;
> > > - * pwm1_max: The maximum PWM speed allowed (bypassed when
> > > hitting
> > > Fan_boost);
> > > + * pwm1_enable:
> > > + Current fan management mode (NONE, MANUAL or AUTO);
> > > + * pwm1:
> > > + Current PWM value (power percentage);
> > > + * pwm1_min:
> > > + The minimum PWM speed allowed;
> > > + * pwm1_max:
> > > + The maximum PWM speed allowed (bypassed when hitting
> > > Fan_boost);
> > >
> > > You may also have the following attribute:
> > >
> > > - * fan1_input: Speed in RPM of your fan.
> > > + * fan1_input:
> > > + Speed in RPM of your fan.
> > >
> > > Your fan can be driven in different modes:
> > >
> > > @@ -66,14 +78,16 @@ Your fan can be driven in different modes:
> > > * 1: The fan can be driven in manual (use pwm1 to change the
> > > speed);
> > > * 2; The fan is driven automatically depending on the
> > > temperature.
> > >
> > > -NOTE: Be sure to use the manual mode if you want to drive the
> > > fan
> > > speed manually
> > > +NOTE:
> > > + Be sure to use the manual mode if you want to drive the fan
> > > speed
> > > manually
> > >
> > > -NOTE2: When operating in manual mode outside the vbios-defined
> > > -[PWM_min, PWM_max] range, the reported fan speed (RPM) may not
> > > be
> > > accurate
> > > -depending on your hardware.
> > > +NOTE2:
> > > + When operating in manual mode outside the vbios-defined
> > > + [PWM_min, PWM_max] range, the reported fan speed (RPM) may not
> > > be
> > > accurate
> > > + depending on your hardware.
> > >
> > > Bug reports
> > > ----------
> > > +-----------
> > >
> > > Thermal management on Nouveau is new and may not work on all
> > > cards.
> > > If you have
> > > inquiries, please ping mupuf on IRC (#nouveau, freenode).
> > > diff --git a/Documentation/thermal/power_allocator.txt
> > > b/Documentation/thermal/power_allocator.rst
> > > similarity index 74%
> > > rename from Documentation/thermal/power_allocator.txt
> > > rename to Documentation/thermal/power_allocator.rst
> > > index 9fb0ff06dca9..67b6a3297238 100644
> > > --- a/Documentation/thermal/power_allocator.txt
> > > +++ b/Documentation/thermal/power_allocator.rst
> > > @@ -1,3 +1,4 @@
> > > +=================================
> > > Power allocator governor tunables
> > > =================================
> > >
> > > @@ -25,36 +26,36 @@ temperature as the control input and power as
> > > the
> > > controlled output:
> > > P_max = k_p * e + k_i * err_integral + k_d * diff_err +
> > > sustainable_power
> > >
> > > where
> > > - e = desired_temperature - current_temperature
> > > - err_integral is the sum of previous errors
> > > - diff_err = e - previous_error
> > > + - e = desired_temperature - current_temperature
> > > + - err_integral is the sum of previous errors
> > > + - diff_err = e - previous_error
> > >
> > > -It is similar to the one depicted below:
> > > +It is similar to the one depicted below::
> > >
> > > - k_d
> > > - |
> > > -current_temp |
> > > - | v
> > > - | +----------+ +---+
> > > - | +----->| diff_err |-->| X |------+
> > > - | | +----------+ +---+ |
> > > - | | | tdp
> > > ac
> > > tor
> > > - | | k_i | | get_r
> > > eque
> > > sted_power()
> > > - | | | | |
> > > |
> > > |
> > > - | | | | |
> > > |
> > > | ...
> > > - v | v v v
> > > v
> > > v
> > > - +---+ | +-------+ +---+ +---+ +---+ +-
> > > ----
> > > -----+
> > > - | S |-------+----->| sum e |----->| X |--->| S |-->| S |
> > > -->|power |
> > > - +---+ | +-------+ +---+ +---+ +---
> > > + |allocation|
> > > - ^ | ^ +-
> > > ----
> > > -----+
> > > - | | |
> > > |
> > > |
> > > - | | +---
> > > + | | |
> > > - | +------->| X |-------------------
> > > + v v
> > > - | +---
> > > + granted
> > > performance
> > > -desired_temperature ^
> > > - |
> > > - |
> > > - k_po/k_pu
> > > + k_d
> > > + |
> > > + current_temp |
> > > + | v
> > > + | +----------+ +---+
> > > + | +----->| diff_err |-->| X |------+
> > > + | | +----------+ +---+ |
> > > + | | | tdp
> > > ac
> > > tor
> > > + | | k_i | | get_r
> > > eque
> > > sted_power()
> > > + | | | | |
> > > |
> > > |
> > > + | | | | |
> > > |
> > > | ...
> > > + v | v v v
> > > v
> > > v
> > > + +---+ | +-------+ +---+ +---+ +---+ +-
> > > ----
> > > -----+
> > > + | S |-----+----->| sum e |----->| X |--->| S |-->| S |
> > > -->|power |
> > > + +---+ | +-------+ +---+ +---+ +---
> > > + |allocation|
> > > + ^ | ^ +-
> > > ----
> > > -----+
> > > + | | |
> > > |
> > > |
> > > + | | +---
> > > + | | |
> > > + | +------->| X |-------------------
> > > + v v
> > > + | +---
> > > + granted
> > > performance
> > > + desired_temperature ^
> > > + |
> > > + |
> > > + k_po/k_pu
> > >
> > > Sustainable power
> > > -----------------
> > > @@ -73,7 +74,7 @@ is typically 2000mW, while on a 10" tablet is
> > > around 4500mW (may vary
> > > depending on screen size).
> > >
> > > If you are using device tree, do add it as a property of the
> > > -thermal-zone. For example:
> > > +thermal-zone. For example::
> > >
> > > thermal-zones {
> > > soc_thermal {
> > > @@ -85,7 +86,7 @@ thermal-zone. For example:
> > > Instead, if the thermal zone is registered from the platform
> > > code,
> > > pass a
> > > `thermal_zone_params` that has a `sustainable_power`. If no
> > > `thermal_zone_params` were being passed, then something like
> > > below
> > > -will suffice:
> > > +will suffice::
> > >
> > > static const struct thermal_zone_params tz_params = {
> > > .sustainable_power = 3500,
> > > @@ -112,18 +113,18 @@ available capacity at a low
> > > temperature. On
> > > the other hand, a high
> > > value of `k_pu` will result in the governor granting very high
> > > power
> > > while temperature is low, and may lead to temperature
> > > overshooting.
> > >
> > > -The default value for `k_pu` is:
> > > +The default value for `k_pu` is::
> > >
> > > 2 * sustainable_power / (desired_temperature -
> > > switch_on_temp)
> > >
> > > This means that at `switch_on_temp` the output of the
> > > controller's
> > > proportional term will be 2 * `sustainable_power`. The default
> > > value
> > > -for `k_po` is:
> > > +for `k_po` is::
> > >
> > > sustainable_power / (desired_temperature - switch_on_temp)
> > >
> > > Focusing on the proportional and feed forward values of the PID
> > > -controller equation we have:
> > > +controller equation we have::
> > >
> > > P_max = k_p * e + sustainable_power
> > >
> > > @@ -134,21 +135,23 @@ is the desired one, then the proportional
> > > component is zero and
> > > thermal equilibrium under constant load. `sustainable_power` is
> > > only
> > > an estimate, which is the reason for closed-loop control such as
> > > this.
> > >
> > > -Expanding `k_pu` we get:
> > > +Expanding `k_pu` we get::
> > > +
> > > P_max = 2 * sustainable_power * (T_set - T) / (T_set - T_on)
> > > +
> > > - sustainable_power
> > > + sustainable_power
> > >
> > > -where
> > > - T_set is the desired temperature
> > > - T is the current temperature
> > > - T_on is the switch on temperature
> > > +where:
> > > +
> > > + - T_set is the desired temperature
> > > + - T is the current temperature
> > > + - T_on is the switch on temperature
> > >
> > > When the current temperature is the switch_on temperature, the
> > > above
> > > -formula becomes:
> > > +formula becomes::
> > >
> > > P_max = 2 * sustainable_power * (T_set - T_on) / (T_set -
> > > T_on)
> > > +
> > > - sustainable_power = 2 * sustainable_power +
> > > sustainable_power =
> > > - 3 * sustainable_power
> > > + sustainable_power = 2 * sustainable_power +
> > > sustainable_power =
> > > + 3 * sustainable_power
> > >
> > > Therefore, the proportional term alone linearly decreases power
> > > from
> > > 3 * `sustainable_power` to `sustainable_power` as the
> > > temperature
> > > @@ -178,11 +181,18 @@ Cooling device power API
> > > Cooling devices controlled by this governor must supply the
> > > additional
> > > "power" API in their `cooling_device_ops`. It consists on three
> > > ops:
> > >
> > > -1. int get_requested_power(struct thermal_cooling_device *cdev,
> > > - struct thermal_zone_device *tz, u32 *power);
> > > -@cdev: The `struct thermal_cooling_device` pointer
> > > -@tz: thermal zone in which we are currently operating
> > > -@power: pointer in which to store the calculated power
> > > +1. ::
> > > +
> > > + int get_requested_power(struct thermal_cooling_device *cdev,
> > > + struct thermal_zone_device *tz, u32
> > > *power);
> > > +
> > > +
> > > +@cdev:
> > > + The `struct thermal_cooling_device` pointer
> > > +@tz:
> > > + thermal zone in which we are currently operating
> > > +@power:
> > > + pointer in which to store the calculated power
> > >
> > > `get_requested_power()` calculates the power requested by the
> > > device
> > > in milliwatts and stores it in @power . It should return 0 on
> > > @@ -190,23 +200,37 @@ success, -E* on failure. This is currently
> > > used by the power
> > > allocator governor to calculate how much power to give to each
> > > cooling
> > > device.
> > >
> > > -2. int state2power(struct thermal_cooling_device *cdev, struct
> > > - thermal_zone_device *tz, unsigned long state, u32
> > > *power);
> > > -@cdev: The `struct thermal_cooling_device` pointer
> > > -@tz: thermal zone in which we are currently operating
> > > -@state: A cooling device state
> > > -@power: pointer in which to store the equivalent power
> > > +2. ::
> > > +
> > > + int state2power(struct thermal_cooling_device *cdev,
> > > struct
> > > + thermal_zone_device *tz, unsigned long
> > > state,
> > > + u32 *power);
> > > +
> > > +@cdev:
> > > + The `struct thermal_cooling_device` pointer
> > > +@tz:
> > > + thermal zone in which we are currently operating
> > > +@state:
> > > + A cooling device state
> > > +@power:
> > > + pointer in which to store the equivalent power
> > >
> > > Convert cooling device state @state into power consumption in
> > > milliwatts and store it in @power. It should return 0 on
> > > success,
> > > -E*
> > > on failure. This is currently used by thermal core to calculate
> > > the
> > > maximum power that an actor can consume.
> > >
> > > -3. int power2state(struct thermal_cooling_device *cdev, u32
> > > power,
> > > - unsigned long *state);
> > > -@cdev: The `struct thermal_cooling_device` pointer
> > > -@power: power in milliwatts
> > > -@state: pointer in which to store the resulting state
> > > +3. ::
> > > +
> > > + int power2state(struct thermal_cooling_device *cdev, u32
> > > power,
> > > + unsigned long *state);
> > > +
> > > +@cdev:
> > > + The `struct thermal_cooling_device` pointer
> > > +@power:
> > > + power in milliwatts
> > > +@state:
> > > + pointer in which to store the resulting state
> > >
> > > Calculate a cooling device state that would make the device
> > > consume
> > > at
> > > most @power mW and store it in @state. It should return 0 on
> > > success,
> > > diff --git a/Documentation/thermal/sysfs-api.txt
> > > b/Documentation/thermal/sysfs-api.rst
> > > similarity index 66%
> > > rename from Documentation/thermal/sysfs-api.txt
> > > rename to Documentation/thermal/sysfs-api.rst
> > > index c3fa500df92c..e4930761d3e5 100644
> > > --- a/Documentation/thermal/sysfs-api.txt
> > > +++ b/Documentation/thermal/sysfs-api.rst
> > > @@ -1,3 +1,4 @@
> > > +===================================
> > > Generic Thermal Sysfs driver How To
> > > ===================================
> > >
> > > @@ -9,6 +10,7 @@ Copyright (c) 2008 Intel Corporation
> > >
> > >
> > > 0. Introduction
> > > +===============
> > >
> > > The generic thermal sysfs provides a set of interfaces for
> > > thermal
> > > zone
> > > devices (sensors) and thermal cooling devices (fan,
> > > processor...) to
> > > register
> > > @@ -25,59 +27,90 @@ An intelligent thermal management application
> > > can
> > > make decisions based on
> > > inputs from thermal zone attributes (the current temperature and
> > > trip point
> > > temperature) and throttle appropriate devices.
> > >
> > > -[0-*] denotes any positive number starting from 0
> > > -[1-*] denotes any positive number starting from 1
> > > +- `[0-*]` denotes any positive number starting from 0
> > > +- `[1-*]` denotes any positive number starting from 1
> > >
> > > 1. thermal sysfs driver interface functions
> > > +===========================================
> > >
> > > 1.1 thermal zone device interface
> > > -1.1.1 struct thermal_zone_device
> > > *thermal_zone_device_register(char
> > > *type,
> > > - int trips, int mask, void *devdata,
> > > - struct thermal_zone_device_ops *ops,
> > > - const struct thermal_zone_params *tzp,
> > > - int passive_delay, int polling_delay))
> > > +---------------------------------
> > > +
> > > + ::
> > > +
> > > + struct thermal_zone_device
> > > + *thermal_zone_device_register(char *type,
> > > + int trips, int mask, void
> > > *devdata,
> > > + struct
> > > thermal_zone_device_ops
> > > *ops,
> > > + const struct
> > > thermal_zone_params *tzp,
> > > + int passive_delay, int
> > > polling_delay))
> > >
> > > This interface function adds a new thermal zone device
> > > (sensor)
> > > to
> > > - /sys/class/thermal folder as thermal_zone[0-*]. It tries to
> > > bind
> > > all the
> > > + /sys/class/thermal folder as `thermal_zone[0-*]`. It tries
> > > to
> > > bind all the
> > > thermal cooling devices registered at the same time.
> > >
> > > - type: the thermal zone type.
> > > - trips: the total number of trip points this thermal zone
> > > supports.
> > > - mask: Bit string: If 'n'th bit is set, then trip point 'n'
> > > is
> > > writeable.
> > > - devdata: device private data
> > > - ops: thermal zone device call-backs.
> > > - .bind: bind the thermal zone device with a thermal
> > > cooling
> > > device.
> > > - .unbind: unbind the thermal zone device with a thermal
> > > cooling device.
> > > - .get_temp: get the current temperature of the thermal
> > > zone.
> > > - .set_trips: set the trip points window. Whenever the
> > > current
> > > temperature
> > > + type:
> > > + the thermal zone type.
> > > + trips:
> > > + the total number of trip points this thermal zone
> > > supports.
> > > + mask:
> > > + Bit string: If 'n'th bit is set, then trip point 'n' is
> > > writeable.
> > > + devdata:
> > > + device private data
> > > + ops:
> > > + thermal zone device call-backs.
> > > +
> > > + .bind:
> > > + bind the thermal zone device with a thermal
> > > cooling
> > > device.
> > > + .unbind:
> > > + unbind the thermal zone device with a thermal
> > > cooling device.
> > > + .get_temp:
> > > + get the current temperature of the thermal zone.
> > > + .set_trips:
> > > + set the trip points window. Whenever the
> > > current
> > > temperature
> > > is updated, the trip points immediately
> > > below
> > > and above the
> > > current temperature are found.
> > > - .get_mode: get the current mode (enabled/disabled) of
> > > the
> > > thermal zone.
> > > - - "enabled" means the kernel thermal management is
> > > enabled.
> > > - - "disabled" will prevent kernel thermal driver
> > > action
> > > upon trip points
> > > - so that user applications can take charge of
> > > thermal
> > > management.
> > > - .set_mode: set the mode (enabled/disabled) of the
> > > thermal
> > > zone.
> > > - .get_trip_type: get the type of certain trip point.
> > > - .get_trip_temp: get the temperature above which the
> > > certain
> > > trip point
> > > + .get_mode:
> > > + get the current mode (enabled/disabled) of
> > > the
> > > thermal zone.
> > > +
> > > + - "enabled" means the kernel thermal
> > > management is
> > > + enabled.
> > > + - "disabled" will prevent kernel thermal
> > > driver action
> > > + upon trip points so that user
> > > applications
> > > can take
> > > + charge of thermal management.
> > > + .set_mode:
> > > + set the mode (enabled/disabled) of the thermal
> > > zone.
> > > + .get_trip_type:
> > > + get the type of certain trip point.
> > > + .get_trip_temp:
> > > + get the temperature above which the
> > > certain
> > > trip point
> > > will be fired.
> > > - .set_emul_temp: set the emulation temperature which
> > > helps in
> > > debugging
> > > + .set_emul_temp:
> > > + set the emulation temperature which
> > > helps in
> > > debugging
> > > different threshold temperature points.
> > > - tzp: thermal zone platform parameters.
> > > - passive_delay: number of milliseconds to wait between polls
> > > when
> > > + tzp:
> > > + thermal zone platform parameters.
> > > + passive_delay:
> > > + number of milliseconds to wait between polls when
> > > performing passive cooling.
> > > - polling_delay: number of milliseconds to wait between polls
> > > when
> > > checking
> > > + polling_delay:
> > > + number of milliseconds to wait between polls when
> > > checking
> > > whether trip points have been crossed (0 for interrupt
> > > driven systems).
> > >
> > > + ::
> > >
> > > -1.1.2 void thermal_zone_device_unregister(struct
> > > thermal_zone_device
> > > *tz)
> > > + void thermal_zone_device_unregister(struct
> > > thermal_zone_device *tz)
> > >
> > > This interface function removes the thermal zone device.
> > > It deletes the corresponding entry from /sys/class/thermal
> > > folder and
> > > unbinds all the thermal cooling devices it uses.
> > >
> > > -1.1.3 struct thermal_zone_device
> > > *thermal_zone_of_sensor_register(
> > > - struct device *dev, int sensor_id, void *data,
> > > - const struct thermal_zone_of_device_ops *ops)
> > > + ::
> > > +
> > > + struct thermal_zone_device
> > > + *thermal_zone_of_sensor_register(struct device *dev,
> > > int
> > > sensor_id,
> > > + void *data,
> > > + const struct
> > > thermal_zone_of_device_ops *ops)
> > >
> > > This interface adds a new sensor to a DT thermal zone.
> > > This function will search the list of thermal zones
> > > described in
> > > @@ -87,25 +120,33 @@ temperature) and throttle appropriate
> > > devices.
> > > thermal zone device.
> > >
> > > The parameters for this interface are:
> > > - dev: Device node of sensor containing
> > > valid
> > > node pointer in
> > > +
> > > + dev:
> > > + Device node of sensor containing valid
> > > node
> > > pointer in
> > > dev->of_node.
> > > - sensor_id: a sensor identifier, in case the
> > > sensor IP
> > > has more
> > > + sensor_id:
> > > + a sensor identifier, in case the sensor
> > > IP
> > > has more
> > > than one sensors
> > > - data: a private pointer (owned by the
> > > caller)
> > > that will be
> > > + data:
> > > + a private pointer (owned by the caller)
> > > that
> > > will be
> > > passed back, when a temperature reading
> > > is
> > > needed.
> > > - ops: struct thermal_zone_of_device_ops *.
> > > + ops:
> > > + `struct thermal_zone_of_device_ops *`.
> > >
> > > - get_temp: a pointer to a function
> > > that reads the
> > > + ============== ========================
> > > ====
> > > ===========
> > > + get_temp a pointer to a function
> > > that
> > > reads the
> > > sensor temperature. This
> > > is
> > > mandatory
> > > callback provided by
> > > sensor
> > > driver.
> > > - set_trips: a pointer to a function
> > > that
> > > sets a
> > > + set_trips a pointer to a function
> > > that sets a
> > > temperature window. When
> > > this window is
> > > left the driver must
> > > inform
> > > the thermal
> > > core via
> > > thermal_zone_device_update.
> > > - get_trend: a pointer to a
> > > function
> > > that reads the
> > > + get_trend a pointer to a
> > > function
> > > that reads the
> > > sensor temperature
> > > trend.
> > > - set_emul_temp: a pointer to a
> > > function that sets
> > > + set_emul_temp a pointer to a
> > > function
> > > that sets
> > > sensor emulated
> > > temperature.
> > > + ============== ========================
> > > ====
> > > ===========
> > > +
> > > The thermal zone temperature is provided by the
> > > get_temp()
> > > function
> > > pointer of thermal_zone_of_device_ops. When called, it
> > > will
> > > have the private pointer @data back.
> > > @@ -114,8 +155,10 @@ temperature) and throttle appropriate
> > > devices.
> > > handle. Caller should check the return handle with
> > > IS_ERR()
> > > for finding
> > > whether success or not.
> > >
> > > -1.1.4 void thermal_zone_of_sensor_unregister(struct device *dev,
> > > - struct thermal_zone_device *tzd)
> > > + ::
> > > +
> > > + void thermal_zone_of_sensor_unregister(struct device
> > > *dev,
> > > + struct
> > > thermal_zone_device *tzd)
> > >
> > > This interface unregisters a sensor from a DT thermal
> > > zone
> > > which was
> > > successfully added by interface
> > > thermal_zone_of_sensor_register().
> > > @@ -124,21 +167,29 @@ temperature) and throttle appropriate
> > > devices.
> > > interface. It will also silent the zone by remove the
> > > .get_temp() and
> > > get_trend() thermal zone device callbacks.
> > >
> > > -1.1.5 struct thermal_zone_device
> > > *devm_thermal_zone_of_sensor_register(
> > > - struct device *dev, int sensor_id,
> > > - void *data, const struct
> > > thermal_zone_of_device_ops
> > > *ops)
> > > + ::
> > > +
> > > + struct thermal_zone_device
> > > + *devm_thermal_zone_of_sensor_register(struct device
> > > *dev,
> > > + int sensor_id,
> > > + void *data,
> > > + const struct
> > > thermal_zone_of_device_ops *ops)
> > >
> > > This interface is resource managed version of
> > > thermal_zone_of_sensor_register().
> > > +
> > > All details of thermal_zone_of_sensor_register()
> > > described
> > > in
> > > section 1.1.3 is applicable here.
> > > +
> > > The benefit of using this interface to register sensor
> > > is
> > > that it
> > > is not require to explicitly call
> > > thermal_zone_of_sensor_unregister()
> > > in error path or during driver unbinding as this is done
> > > by
> > > driver
> > > resource manager.
> > >
> > > -1.1.6 void devm_thermal_zone_of_sensor_unregister(struct device
> > > *dev,
> > > - struct thermal_zone_device *tzd)
> > > + ::
> > > +
> > > + void
> > > devm_thermal_zone_of_sensor_unregister(struct
> > > device *dev,
> > > + struct
> > > thermal_zone_device *tzd)
> > >
> > > This interface is resource managed version of
> > > thermal_zone_of_sensor_unregister().
> > > @@ -147,123 +198,186 @@ temperature) and throttle appropriate
> > > devices.
> > > Normally this function will not need to be called and
> > > the
> > > resource
> > > management code will ensure that the resource is freed.
> > >
> > > -1.1.7 int thermal_zone_get_slope(struct thermal_zone_device *tz)
> > > + ::
> > > +
> > > + int thermal_zone_get_slope(struct
> > > thermal_zone_device *tz)
> > >
> > > This interface is used to read the slope attribute value
> > > for the thermal zone device, which might be useful for
> > > platform
> > > drivers for temperature calculations.
> > >
> > > -1.1.8 int thermal_zone_get_offset(struct thermal_zone_device
> > > *tz)
> > > + ::
> > > +
> > > + int thermal_zone_get_offset(struct
> > > thermal_zone_device *tz)
> > >
> > > This interface is used to read the offset attribute
> > > value
> > > for the thermal zone device, which might be useful for
> > > platform
> > > drivers for temperature calculations.
> > >
> > > 1.2 thermal cooling device interface
> > > -1.2.1 struct thermal_cooling_device
> > > *thermal_cooling_device_register(char *name,
> > > - void *devdata, struct thermal_cooling_device_ops
> > > *)
> > > +------------------------------------
> > > +
> > > +
> > > + ::
> > > +
> > > + struct thermal_cooling_device
> > > + *thermal_cooling_device_register(char *name,
> > > + void *devdata, struct
> > > thermal_cooling_device_ops *)
> > >
> > > This interface function adds a new thermal cooling device
> > > (fan/processor/...)
> > > - to /sys/class/thermal/ folder as cooling_device[0-*]. It
> > > tries
> > > to bind itself
> > > + to /sys/class/thermal/ folder as `cooling_device[0-*]`. It
> > > tries
> > > to bind itself
> > > to all the thermal zone devices registered at the same time.
> > > - name: the cooling device name.
> > > - devdata: device private data.
> > > - ops: thermal cooling devices call-backs.
> > > - .get_max_state: get the Maximum throttle state of the
> > > cooling device.
> > > - .get_cur_state: get the Currently requested throttle
> > > state
> > > of the cooling device.
> > > - .set_cur_state: set the Current throttle state of the
> > > cooling device.
> > > -
> > > -1.2.2 void thermal_cooling_device_unregister(struct
> > > thermal_cooling_device *cdev)
> > > +
> > > + name:
> > > + the cooling device name.
> > > + devdata:
> > > + device private data.
> > > + ops:
> > > + thermal cooling devices call-backs.
> > > +
> > > + .get_max_state:
> > > + get the Maximum throttle state of the cooling
> > > device.
> > > + .get_cur_state:
> > > + get the Currently requested throttle state of
> > > the
> > > + cooling device.
> > > + .set_cur_state:
> > > + set the Current throttle state of the cooling
> > > device.
> > > +
> > > + ::
> > > +
> > > + void thermal_cooling_device_unregister(struct
> > > thermal_cooling_device *cdev)
> > >
> > > This interface function removes the thermal cooling device.
> > > It deletes the corresponding entry from /sys/class/thermal
> > > folder and
> > > unbinds itself from all the thermal zone devices using it.
> > >
> > > 1.3 interface for binding a thermal zone device with a thermal
> > > cooling device
> > > -1.3.1 int thermal_zone_bind_cooling_device(struct
> > > thermal_zone_device *tz,
> > > - int trip, struct thermal_cooling_device *cdev,
> > > - unsigned long upper, unsigned long lower, unsigned int
> > > weight);
> > > +--------------------------------------------------------------
> > > ----
> > > -----------
> > > +
> > > + ::
> > > +
> > > + int thermal_zone_bind_cooling_device(struct
> > > thermal_zone_device *tz,
> > > + int trip, struct thermal_cooling_device *cdev,
> > > + unsigned long upper, unsigned long lower,
> > > unsigned
> > > int weight);
> > >
> > > This interface function binds a thermal cooling device to a
> > > particular trip
> > > point of a thermal zone device.
> > > +
> > > This function is usually called in the thermal zone device
> > > .bind
> > > callback.
> > > - tz: the thermal zone device
> > > - cdev: thermal cooling device
> > > - trip: indicates which trip point in this thermal zone the
> > > cooling device
> > > - is associated with.
> > > - upper:the Maximum cooling state for this trip point.
> > > - THERMAL_NO_LIMIT means no upper limit,
> > > +
> > > + tz:
> > > + the thermal zone device
> > > + cdev:
> > > + thermal cooling device
> > > + trip:
> > > + indicates which trip point in this thermal zone the
> > > cooling device
> > > + is associated with.
> > > + upper:
> > > + the Maximum cooling state for this trip point.
> > > + THERMAL_NO_LIMIT means no upper limit,
> > > and the cooling device can be in max_state.
> > > - lower:the Minimum cooling state can be used for this trip
> > > point.
> > > - THERMAL_NO_LIMIT means no lower limit,
> > > + lower:
> > > + the Minimum cooling state can be used for this trip
> > > point.
> > > + THERMAL_NO_LIMIT means no lower limit,
> > > and the cooling device can be in cooling state 0.
> > > - weight: the influence of this cooling device in this thermal
> > > - zone. See 1.4.1 below for more information.
> > > + weight:
> > > + the influence of this cooling device in this thermal
> > > + zone. See 1.4.1 below for more information.
> > >
> > > -1.3.2 int thermal_zone_unbind_cooling_device(struct
> > > thermal_zone_device *tz,
> > > - int trip, struct thermal_cooling_device *cdev);
> > > + ::
> > > +
> > > + int thermal_zone_unbind_cooling_device(struct
> > > thermal_zone_device *tz,
> > > + int trip, struct
> > > thermal_cooling_device *cdev);
> > >
> > > This interface function unbinds a thermal cooling device
> > > from a
> > > particular
> > > trip point of a thermal zone device. This function is
> > > usually
> > > called in
> > > the thermal zone device .unbind callback.
> > > - tz: the thermal zone device
> > > - cdev: thermal cooling device
> > > - trip: indicates which trip point in this thermal zone the
> > > cooling device
> > > - is associated with.
> > > +
> > > + tz:
> > > + the thermal zone device
> > > + cdev:
> > > + thermal cooling device
> > > + trip:
> > > + indicates which trip point in this thermal zone the
> > > cooling
> > > device
> > > + is associated with.
> > >
> > > 1.4 Thermal Zone Parameters
> > > -1.4.1 struct thermal_bind_params
> > > +---------------------------
> > > +
> > > + ::
> > > +
> > > + struct thermal_bind_params
> > > +
> > > This structure defines the following parameters that are
> > > used to
> > > bind
> > > a zone with a cooling device for a particular trip point.
> > > - .cdev: The cooling device pointer
> > > - .weight: The 'influence' of a particular cooling device on
> > > this
> > > - zone. This is relative to the rest of the cooling
> > > - devices. For example, if all cooling devices have a
> > > - weight of 1, then they all contribute the same. You
> > > can
> > > - use percentages if you want, but it's not
> > > mandatory. A
> > > - weight of 0 means that this cooling device doesn't
> > > - contribute to the cooling of this zone unless all
> > > cooling
> > > - devices have a weight of 0. If all weights are 0,
> > > then
> > > - they all contribute the same.
> > > - .trip_mask:This is a bit mask that gives the binding
> > > relation
> > > between
> > > - this thermal zone and cdev, for a particular trip
> > > point.
> > > - If nth bit is set, then the cdev and thermal zone
> > > are
> > > bound
> > > - for trip point n.
> > > - .binding_limits: This is an array of cooling state limits.
> > > Must
> > > have
> > > - exactly 2 *
> > > thermal_zone.number_of_trip_points.
> > > It is an
> > > - array consisting of tuples <lower-state
> > > upper-
> > > state> of
> > > - state limits. Each trip will be associated
> > > with
> > > one state
> > > - limit tuple when binding. A NULL pointer
> > > means
> > > - <THERMAL_NO_LIMITS THERMAL_NO_LIMITS> on
> > > all
> > > trips.
> > > - These limits are used when binding a cdev
> > > to a
> > > trip point.
> > > - .match: This call back returns success(0) if the 'tz and
> > > cdev'
> > > need to
> > > +
> > > + .cdev:
> > > + The cooling device pointer
> > > + .weight:
> > > + The 'influence' of a particular cooling device on
> > > this
> > > + zone. This is relative to the rest of the cooling
> > > + devices. For example, if all cooling devices have a
> > > + weight of 1, then they all contribute the same. You
> > > can
> > > + use percentages if you want, but it's not
> > > mandatory. A
> > > + weight of 0 means that this cooling device doesn't
> > > + contribute to the cooling of this zone unless all
> > > cooling
> > > + devices have a weight of 0. If all weights are 0,
> > > then
> > > + they all contribute the same.
> > > + .trip_mask:
> > > + This is a bit mask that gives the binding
> > > relation
> > > between
> > > + this thermal zone and cdev, for a particular trip
> > > point.
> > > + If nth bit is set, then the cdev and thermal zone
> > > are
> > > bound
> > > + for trip point n.
> > > + .binding_limits:
> > > + This is an array of cooling state limits.
> > > Must
> > > have
> > > + exactly 2 *
> > > thermal_zone.number_of_trip_points.
> > > It is an
> > > + array consisting of tuples <lower-state
> > > upper-
> > > state> of
> > > + state limits. Each trip will be associated
> > > with
> > > one state
> > > + limit tuple when binding. A NULL pointer
> > > means
> > > + <THERMAL_NO_LIMITS THERMAL_NO_LIMITS> on
> > > all
> > > trips.
> > > + These limits are used when binding a cdev
> > > to a
> > > trip point.
> > > + .match:
> > > + This call back returns success(0) if the 'tz and
> > > cdev'
> > > need to
> > > be bound, as per platform data.
> > > -1.4.2 struct thermal_zone_params
> > > +
> > > + ::
> > > +
> > > + struct thermal_zone_params
> > > +
> > > This structure defines the platform level parameters for a
> > > thermal zone.
> > > This data, for each thermal zone should come from the
> > > platform
> > > layer.
> > > This is an optional feature where some platforms can choose
> > > not
> > > to
> > > provide this data.
> > > - .governor_name: Name of the thermal governor used for this
> > > zone
> > > - .no_hwmon: a boolean to indicate if the thermal to hwmon
> > > sysfs
> > > interface
> > > - is required. when no_hwmon == false, a hwmon
> > > sysfs
> > > interface
> > > - will be created. when no_hwmon == true, nothing
> > > will
> > > be done.
> > > - In case the thermal_zone_params is NULL, the
> > > hwmon
> > > interface
> > > - will be created (for backward compatibility).
> > > - .num_tbps: Number of thermal_bind_params entries for this
> > > zone
> > > - .tbp: thermal_bind_params entries
> > > +
> > > + .governor_name:
> > > + Name of the thermal governor used for this zone
> > > + .no_hwmon:
> > > + a boolean to indicate if the thermal to hwmon
> > > sysfs
> > > interface
> > > + is required. when no_hwmon == false, a hwmon
> > > sysfs
> > > interface
> > > + will be created. when no_hwmon == true, nothing
> > > will
> > > be done.
> > > + In case the thermal_zone_params is NULL, the
> > > hwmon
> > > interface
> > > + will be created (for backward compatibility).
> > > + .num_tbps:
> > > + Number of thermal_bind_params entries for this
> > > zone
> > > + .tbp:
> > > + thermal_bind_params entries
> > >
> > > 2. sysfs attributes structure
> > > +=============================
> > >
> > > +== ================
> > > RO read only value
> > > WO write only value
> > > RW read/write value
> > > +== ================
> > >
> > > Thermal sysfs attributes will be represented under
> > > /sys/class/thermal.
> > > Hwmon sysfs I/F extension is also available under
> > > /sys/class/hwmon
> > > if hwmon is compiled in or built as a module.
> > >
> > > -Thermal zone device sys I/F, created once it's registered:
> > > -/sys/class/thermal/thermal_zone[0-*]:
> > > +Thermal zone device sys I/F, created once it's registered::
> > > +
> > > + /sys/class/thermal/thermal_zone[0-*]:
> > > |---type: Type of the thermal zone
> > > |---temp: Current temperature
> > > |---mode: Working mode of the thermal
> > > zone
> > > @@ -282,8 +396,9 @@ Thermal zone device sys I/F, created once
> > > it's
> > > registered:
> > > |---slope: Slope constant applied as linear
> > > extrapolation
> > > |---offset: Offset constant applied as
> > > linear
> > > extrapolation
> > >
> > > -Thermal cooling device sys I/F, created once it's registered:
> > > -/sys/class/thermal/cooling_device[0-*]:
> > > +Thermal cooling device sys I/F, created once it's registered::
> > > +
> > > + /sys/class/thermal/cooling_device[0-*]:
> > > |---type: Type of the cooling
> > > device(processor/fan/...)
> > > |---max_state: Maximum cooling state of the
> > > cooling device
> > > |---cur_state: Current cooling state of the
> > > cooling device
> > > @@ -299,11 +414,13 @@ the relationship between a thermal zone and
> > > its
> > > associated cooling device.
> > > They are created/removed for each successful execution of
> > > thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_dev
> > > ice.
> > >
> > > -/sys/class/thermal/thermal_zone[0-*]:
> > > +::
> > > +
> > > + /sys/class/thermal/thermal_zone[0-*]:
> > > |---cdev[0-*]: [0-*]th cooling device in
> > > current
> > > thermal zone
> > > |---cdev[0-*]_trip_point: Trip point that cdev[0-*]
> > > is
> > > associated with
> > > |---cdev[0-*]_weight: Influence of the cooling device
> > > in
> > > - this thermal zone
> > > + this thermal zone
> > >
> > > Besides the thermal zone device sysfs I/F and cooling device
> > > sysfs
> > > I/F,
> > > the generic thermal driver also creates a hwmon sysfs I/F for
> > > each
> > > _type_
> > > @@ -311,16 +428,17 @@ of thermal zone device. E.g. the generic
> > > thermal driver registers one hwmon
> > > class device and build the associated hwmon sysfs I/F for all
> > > the
> > > registered
> > > ACPI thermal zones.
> > >
> > > -/sys/class/hwmon/hwmon[0-*]:
> > > +::
> > > +
> > > + /sys/class/hwmon/hwmon[0-*]:
> > > |---name: The type of the thermal
> > > zone
> > > devices
> > > |---temp[1-*]_input: The current temperature of
> > > thermal
> > > zone [1-*]
> > > |---temp[1-*]_critical: The critical trip point of
> > > thermal zone [1-*]
> > >
> > > Please read Documentation/hwmon/sysfs-interface.rst for
> > > additional
> > > information.
> > >
> > > -***************************
> > > -* Thermal zone attributes *
> > > -***************************
> > > +Thermal zone attributes
> > > +-----------------------
> > >
> > > type
> > > Strings which represent the thermal zone type.
> > > @@ -340,54 +458,67 @@ mode
> > > This file gives information about the algorithm that is
> > > currently
> > > managing the thermal zone. It can be either default
> > > kernel
> > > based
> > > algorithm or user space application.
> > > - enabled = enable Kernel Thermal
> > > management.
> > > - disabled = Preventing kernel thermal zone driver
> > > actions upon
> > > +
> > > + enabled
> > > + enable Kernel Thermal management.
> > > + disabled
> > > + Preventing kernel thermal zone driver
> > > actions upon
> > > trip points so that user application
> > > can
> > > take full
> > > charge of the thermal management.
> > > +
> > > RW, Optional
> > >
> > > policy
> > > One of the various thermal governors used for a
> > > particular
> > > zone.
> > > +
> > > RW, Required
> > >
> > > available_policies
> > > Available thermal governors which can be used for a
> > > particular zone.
> > > +
> > > RO, Required
> > >
> > > -trip_point_[0-*]_temp
> > > +`trip_point_[0-*]_temp`
> > > The temperature above which trip point will be fired.
> > > +
> > > Unit: millidegree Celsius
> > > +
> > > RO, Optional
> > >
> > > -trip_point_[0-*]_type
> > > +`trip_point_[0-*]_type`
> > > Strings which indicate the type of the trip point.
> > > - E.g. it can be one of critical, hot, passive, active[0-
> > > *]
> > > for ACPI
> > > +
> > > + E.g. it can be one of critical, hot, passive, `active[0-
> > > *]`
> > > for ACPI
> > > thermal zone.
> > > +
> > > RO, Optional
> > >
> > > -trip_point_[0-*]_hyst
> > > +`trip_point_[0-*]_hyst`
> > > The hysteresis value for a trip point, represented as an
> > > integer
> > > Unit: Celsius
> > > RW, Optional
> > >
> > > -cdev[0-*]
> > > +`cdev[0-*]`
> > > Sysfs link to the thermal cooling device node where the
> > > sys
> > > I/F
> > > for cooling device throttling control represents.
> > > +
> > > RO, Optional
> > >
> > > -cdev[0-*]_trip_point
> > > - The trip point in this thermal zone which cdev[0-*] is
> > > associated
> > > +`cdev[0-*]_trip_point`
> > > + The trip point in this thermal zone which `cdev[0-*]` is
> > > associated
> > > with; -1 means the cooling device is not associated with
> > > any
> > > trip
> > > point.
> > > +
> > > RO, Optional
> > >
> > > -cdev[0-*]_weight
> > > - The influence of cdev[0-*] in this thermal zone. This
> > > value
> > > - is relative to the rest of cooling devices in the
> > > thermal
> > > - zone. For example, if a cooling device has a weight
> > > double
> > > - than that of other, it's twice as effective in cooling
> > > the
> > > - thermal zone.
> > > - RW, Optional
> > > +`cdev[0-*]_weight`
> > > + The influence of `cdev[0-*]` in this thermal zone. This
> > > value
> > > + is relative to the rest of cooling devices in the
> > > thermal
> > > + zone. For example, if a cooling device has a weight
> > > double
> > > + than that of other, it's twice as effective in cooling
> > > the
> > > + thermal zone.
> > > +
> > > + RW, Optional
> > >
> > > passive
> > > Attribute is only present for zones in which the passive
> > > cooling
> > > @@ -395,8 +526,11 @@ passive
> > > and can be set to a temperature (in millidegrees) to
> > > enable
> > > a
> > > passive trip point for the zone. Activation is done by
> > > polling with
> > > an interval of 1 second.
> > > +
> > > Unit: millidegrees Celsius
> > > +
> > > Valid values: 0 (disabled) or greater than 1000
> > > +
> > > RW, Optional
> > >
> > > emul_temp
> > > @@ -407,17 +541,21 @@ emul_temp
> > > threshold and its associated cooling action. This is
> > > write
> > > only node
> > > and writing 0 on this node should disable emulation.
> > > Unit: millidegree Celsius
> > > +
> > > WO, Optional
> > >
> > > - WARNING: Be careful while enabling this option on
> > > production systems,
> > > - because userland can easily disable the thermal policy
> > > by
> > > simply
> > > - flooding this sysfs node with low temperature values.
> > > + WARNING:
> > > + Be careful while enabling this option on production
> > > systems,
> > > + because userland can easily disable the thermal
> > > policy
> > > by simply
> > > + flooding this sysfs node with low temperature
> > > values.
> > >
> > > sustainable_power
> > > An estimate of the sustained power that can be
> > > dissipated by
> > > the thermal zone. Used by the power allocator governor.
> > > For
> > > - more information see
> > > Documentation/thermal/power_allocator.txt
> > > + more information see
> > > Documentation/thermal/power_allocator.rst
> > > +
> > > Unit: milliwatts
> > > +
> > > RW, Optional
> > >
> > > k_po
> > > @@ -425,7 +563,8 @@ k_po
> > > controller during temperature overshoot. Temperature
> > > overshoot
> > > is when the current temperature is above the "desired
> > > temperature" trip point. For more information see
> > > - Documentation/thermal/power_allocator.txt
> > > + Documentation/thermal/power_allocator.rst
> > > +
> > > RW, Optional
> > >
> > > k_pu
> > > @@ -433,20 +572,23 @@ k_pu
> > > controller during temperature undershoot. Temperature
> > > undershoot
> > > is when the current temperature is below the "desired
> > > temperature" trip point. For more information see
> > > - Documentation/thermal/power_allocator.txt
> > > + Documentation/thermal/power_allocator.rst
> > > +
> > > RW, Optional
> > >
> > > k_i
> > > The integral term of the power allocator governor's PID
> > > controller. This term allows the PID controller to
> > > compensate
> > > for long term drift. For more information see
> > > - Documentation/thermal/power_allocator.txt
> > > + Documentation/thermal/power_allocator.rst
> > > +
> > > RW, Optional
> > >
> > > k_d
> > > The derivative term of the power allocator governor's
> > > PID
> > > controller. For more information see
> > > - Documentation/thermal/power_allocator.txt
> > > + Documentation/thermal/power_allocator.rst
> > > +
> > > RW, Optional
> > >
> > > integral_cutoff
> > > @@ -456,8 +598,10 @@ integral_cutoff
> > > example, if integral_cutoff is 0, then the integral term
> > > only
> > > accumulates error when temperature is above the desired
> > > temperature trip point. For more information see
> > > - Documentation/thermal/power_allocator.txt
> > > + Documentation/thermal/power_allocator.rst
> > > +
> > > Unit: millidegree Celsius
> > > +
> > > RW, Optional
> > >
> > > slope
> > > @@ -465,6 +609,7 @@ slope
> > > to determine a hotspot temperature based off the
> > > sensor's
> > > raw readings. It is up to the device driver to determine
> > > the usage of these values.
> > > +
> > > RW, Optional
> > >
> > > offset
> > > @@ -472,28 +617,33 @@ offset
> > > to determine a hotspot temperature based off the
> > > sensor's
> > > raw readings. It is up to the device driver to determine
> > > the usage of these values.
> > > +
> > > RW, Optional
> > >
> > > -*****************************
> > > -* Cooling device attributes *
> > > -*****************************
> > > +Cooling device attributes
> > > +-------------------------
> > >
> > > type
> > > String which represents the type of device, e.g:
> > > +
> > > - for generic ACPI: should be "Fan", "Processor" or
> > > "LCD"
> > > - for memory controller device on intel_menlow platform:
> > > should be "Memory controller".
> > > +
> > > RO, Required
> > >
> > > max_state
> > > The maximum permissible cooling state of this cooling
> > > device.
> > > +
> > > RO, Required
> > >
> > > cur_state
> > > The current cooling state of this cooling device.
> > > The value can any integer numbers between 0 and
> > > max_state:
> > > +
> > > - cur_state == 0 means no cooling
> > > - cur_state == max_state means the maximum cooling.
> > > +
> > > RW, Required
> > >
> > > stats/reset
> > > @@ -508,9 +658,11 @@ stats/time_in_state_ms:
> > > units here is 10mS (similar to other time exported in
> > > /proc).
> > > RO, Required
> > >
> > > +
> > > stats/total_trans:
> > > A single positive value showing the total number of
> > > times
> > > the state of a
> > > cooling device is changed.
> > > +
> > > RO, Required
> > >
> > > stats/trans_table:
> > > @@ -522,6 +674,7 @@ stats/trans_table:
> > > RO, Required
> > >
> > > 3. A simple implementation
> > > +==========================
> > >
> > > ACPI thermal zone may support multiple trip points like
> > > critical,
> > > hot,
> > > passive, active. If an ACPI thermal zone supports critical,
> > > passive,
> > > @@ -532,11 +685,10 @@ thermal_cooling_device. Both are considered
> > > to
> > > have the same
> > > effectiveness in cooling the thermal zone.
> > >
> > > If the processor is listed in _PSL method, and the fan is listed
> > > in
> > > _AL0
> > > -method, the sys I/F structure will be built like this:
> > > +method, the sys I/F structure will be built like this::
> > >
> > > -/sys/class/thermal:
> > > -
> > > -|thermal_zone1:
> > > + /sys/class/thermal:
> > > + |thermal_zone1:
> > > |---type: acpitz
> > > |---temp: 37000
> > > |---mode: enabled
> > > @@ -557,24 +709,24 @@ method, the sys I/F structure will be built
> > > like this:
> > > |---cdev1_trip_point: 2 /* cdev1 can be used
> > > for
> > > active[0]*/
> > > |---cdev1_weight: 1024
> > >
> > > -|cooling_device0:
> > > + |cooling_device0:
> > > |---type: Processor
> > > |---max_state: 8
> > > |---cur_state: 0
> > >
> > > -|cooling_device3:
> > > + |cooling_device3:
> > > |---type: Fan
> > > |---max_state: 2
> > > |---cur_state: 0
> > >
> > > -/sys/class/hwmon:
> > > -
> > > -|hwmon0:
> > > + /sys/class/hwmon:
> > > + |hwmon0:
> > > |---name: acpitz
> > > |---temp1_input: 37000
> > > |---temp1_crit: 100000
> > >
> > > 4. Event Notification
> > > +=====================
> > >
> > > The framework includes a simple notification mechanism, in the
> > > form
> > > of a
> > > netlink event. Netlink socket initialization is done during the
> > > _init_
> > > @@ -587,21 +739,28 @@ event will be one of:{THERMAL_AUX0,
> > > THERMAL_AUX1, THERMAL_CRITICAL,
> > > THERMAL_DEV_FAULT}. Notification can be sent when the current
> > > temperature
> > > crosses any of the configured thresholds.
> > >
> > > -5. Export Symbol APIs:
> > > +5. Export Symbol APIs
> > > +=====================
> > > +
> > > +5.1. get_tz_trend
> > > +-----------------
> > >
> > > -5.1: get_tz_trend:
> > > This function returns the trend of a thermal zone, i.e the rate
> > > of
> > > change
> > > of temperature of the thermal zone. Ideally, the thermal sensor
> > > drivers
> > > are supposed to implement the callback. If they don't, the
> > > thermal
> > > framework calculated the trend by comparing the previous and the
> > > current
> > > temperature values.
> > >
> > > -5.2:get_thermal_instance:
> > > +5.2. get_thermal_instance
> > > +-------------------------
> > > +
> > > This function returns the thermal_instance corresponding to a
> > > given
> > > {thermal_zone, cooling_device, trip_point} combination. Returns
> > > NULL
> > > if such an instance does not exist.
> > >
> > > -5.3:thermal_notify_framework:
> > > +5.3. thermal_notify_framework
> > > +-----------------------------
> > > +
> > > This function handles the trip events from sensor drivers. It
> > > starts
> > > throttling the cooling devices according to the policy
> > > configured.
> > > For CRITICAL and HOT trip points, this notifies the respective
> > > drivers,
> > > @@ -609,12 +768,15 @@ and does actual throttling for other trip
> > > points i.e ACTIVE and PASSIVE.
> > > The throttling policy is based on the configured platform data;
> > > if
> > > no
> > > platform data is provided, this uses the step_wise throttling
> > > policy.
> > >
> > > -5.4:thermal_cdev_update:
> > > +5.4. thermal_cdev_update
> > > +------------------------
> > > +
> > > This function serves as an arbitrator to set the state of a
> > > cooling
> > > device. It sets the cooling device to the deepest cooling state
> > > if
> > > possible.
> > >
> > > -6. thermal_emergency_poweroff:
> > > +6. thermal_emergency_poweroff
> > > +=============================
> > >
> > > On an event of critical trip temperature crossing. Thermal
> > > framework
> > > allows the system to shutdown gracefully by calling
> > > orderly_poweroff().
> > > diff --git a/Documentation/thermal/x86_pkg_temperature_thermal
> > > b/Documentation/thermal/x86_pkg_temperature_thermal.rst
> > > similarity index 80%
> > > rename from Documentation/thermal/x86_pkg_temperature_thermal
> > > rename to Documentation/thermal/x86_pkg_temperature_thermal.rst
> > > index 17a3a4c0a0ca..f134dbd3f5a9 100644
> > > --- a/Documentation/thermal/x86_pkg_temperature_thermal
> > > +++ b/Documentation/thermal/x86_pkg_temperature_thermal.rst
> > > @@ -1,19 +1,23 @@
> > > +===================================
> > > Kernel driver: x86_pkg_temp_thermal
> > > -===================
> > > +===================================
> > >
> > > Supported chips:
> > > +
> > > * x86: with package level thermal management
> > > +
> > > (Verify using: CPUID.06H:EAX[bit 6] =1)
> > >
> > > Authors: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.co
> > > m>
> > >
> > > Reference
> > > ----
> > > +---------
> > > +
> > > Intel® 64 and IA-32 Architectures Software Developer’s Manual
> > > (Jan,
> > > 2013):
> > > Chapter 14.6: PACKAGE LEVEL THERMAL MANAGEMENT
> > >
> > > Description
> > > ----------
> > > +-----------
> > >
> > > This driver register CPU digital temperature package level
> > > sensor as
> > > a thermal
> > > zone with maximum two user mode configurable trip points. Number
> > > of
> > > trip points
> > > @@ -25,23 +29,27 @@ take any action to control temperature.
> > > Threshold management
> > > --------------------
> > > Each package will register as a thermal zone under
> > > /sys/class/thermal.
> > > -Example:
> > > -/sys/class/thermal/thermal_zone1
> > > +
> > > +Example::
> > > +
> > > + /sys/class/thermal/thermal_zone1
> > >
> > > This contains two trip points:
> > > +
> > > - trip_point_0_temp
> > > - trip_point_1_temp
> > >
> > > User can set any temperature between 0 to TJ-Max temperature.
> > > Temperature units
> > > -are in milli-degree Celsius. Refer to
> > > "Documentation/thermal/sysfs-
> > > api.txt" for
> > > +are in milli-degree Celsius. Refer to
> > > "Documentation/thermal/sysfs-
> > > api.rst" for
> > > thermal sys-fs details.
> > >
> > > Any value other than 0 in these trip points, can trigger thermal
> > > notifications.
> > > Setting 0, stops sending thermal notifications.
> > >
> > > -Thermal notifications: To get kobject-uevent notifications, set
> > > the
> > > thermal zone
> > > -policy to "user_space". For example: echo -n "user_space" >
> > > policy
> > > -
> > > -
> > > +Thermal notifications:
> > > +To get kobject-uevent notifications, set the thermal zone
> > > +policy to "user_space".
> > >
> > > +For example::
> > >
> > > + echo -n "user_space" > policy
> > > diff --git a/MAINTAINERS b/MAINTAINERS
> > > index d9e214f68e52..b2254bc8e495 100644
> > > --- a/MAINTAINERS
> > > +++ b/MAINTAINERS
> > > @@ -15687,7 +15687,7 @@ M: Viresh Kumar <viresh.kumar@lina
> > > ro.o
> > > rg>
> > > M: Javi Merino <javi.merino@kernel.org>
> > > L: linux-pm@vger.kernel.org
> > > S: Supported
> > > -F: Documentation/thermal/cpu-cooling-api.txt
> > > +F: Documentation/thermal/cpu-cooling-api.rst
> > > F: drivers/thermal/cpu_cooling.c
> > > F: include/linux/cpu_cooling.h
> > >
> > > diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> > > index 15a4ca5d7099..681047f8cc05 100644
> > > --- a/include/linux/thermal.h
> > > +++ b/include/linux/thermal.h
> > > @@ -251,7 +251,7 @@ struct thermal_bind_params {
> > > * platform characterization. This value is relative to
> > > the
> > > * rest of the weights so a cooling device whose weight
> > > is
> > > * double that of another cooling device is twice as
> > > - * effective. See Documentation/thermal/sysfs-api.txt
> > > for
> > > more
> > > + * effective. See Documentation/thermal/sysfs-api.rst
> > > for
> > > more
> > > * information.
> > > */
> > > int weight;
> > > @@ -259,7 +259,7 @@ struct thermal_bind_params {
> > > /*
> > > * This is a bit mask that gives the binding relation
> > > between this
> > > * thermal zone and cdev, for a particular trip point.
> > > - * See Documentation/thermal/sysfs-api.txt for more
> > > information.
> > > + * See Documentation/thermal/sysfs-api.rst for more
> > > information.
> > > */
> > > int trip_mask;
> > >
>
>
> Thanks,
> Mauro
^ permalink raw reply
* Re: [PATCH next] softirq: enable MAX_SOFTIRQ_TIME tuning with sysctl max_softirq_time_usecs
From: Zhiqiang Liu @ 2019-06-25 14:46 UTC (permalink / raw)
To: Thomas Gleixner
Cc: corbet, mcgrof, Kees Cook, akpm, manfred, jwilk, dvyukov,
feng.tang, sunilmut, quentin.perret, linux, alex.popov, linux-doc,
linux-kernel, linux-fsdevel, wangxiaogang (F), Zhoukang (A),
Mingfangsen, tedheadster, Eric Dumazet
In-Reply-To: <alpine.DEB.2.21.1906241141370.32342@nanos.tec.linutronix.de>
Dear Thomas,
On 2019/6/24 17:45, Thomas Gleixner wrote:
> Zhiqiang,
>
> On Mon, 24 Jun 2019, Zhiqiang Liu wrote:
>>
>> Thanks again for your detailed advice.
>> As your said, the max_softirq_time_usecs setting without explaining the
>> relationship with CONFIG_HZ will give a false sense of controlability. And
>> the time accuracy of jiffies will result in a certain difference between the
>> max_softirq_time_usecs set value and the actual value, which is in one jiffies
>> range.
>>
>> I will add these infomation in the sysctl documentation and changelog in v2 patch.
>
> Please make the sysctl milliseconds based. That's the closest approximation
> of useful units for this. This still has the same issues as explained
> before but it's not off by 3 orders of magitude anymore.
>
I have a doubt about _msecs_to_jiffies funcs, especially when input m is equal to 0.
For different HZ setttings, different _msecs_to_jiffies funcs will be chosen for
msecs_to_jiffies func. However, the performance of different _msecs_to_jiffies is
inconsistent with input m is equal to 0.
If HZ satisfies the condition: HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ), the return
value of _msecs_to_jiffies func with m=0 is different with different HZ setting.
------------------------------------
| HZ | MSEC_PER_SEC / HZ | return |
------------------------------------
|1000| 1 | 0 |
|500 | 2 | 1 |
|200 | 5 | 1 |
|100 | 10 | 1 |
------------------------------------
Why only the return value of HZ=1000 is equal to 0 with m=0 ?
Codes are given as follows,
#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
static inline unsigned long _msecs_to_jiffies(const unsigned int m)
{
return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
}
#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
static inline unsigned long _msecs_to_jiffies(const unsigned int m)
{
if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
return MAX_JIFFY_OFFSET;
return m * (HZ / MSEC_PER_SEC);
}
#else
static inline unsigned long _msecs_to_jiffies(const unsigned int m)
{
if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
return MAX_JIFFY_OFFSET;
return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32) >> MSEC_TO_HZ_SHR32;
}
> Thanks,
>
> tglx
>
^ permalink raw reply
* Re: [PATCH 0/3] Clean up crypto documentation
From: Gary R Hook @ 2019-06-25 15:29 UTC (permalink / raw)
To: Jonathan Corbet
Cc: Joe Perches, Hook, Gary, herbert@gondor.apana.org.au,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-crypto@vger.kernel.org, davem@davemloft.net
In-Reply-To: <20190625075250.3a912863@lwn.net>
On 6/25/19 8:52 AM, Jonathan Corbet wrote:
> On Tue, 25 Jun 2019 13:33:27 +0000
> Gary R Hook <ghook@amd.com> wrote:
>
>>> It's been "valid" since I wrote it...it's just not upstream yet :) I
>>> expect it to be in 5.3, though. So the best way to refer to a kernel
>>> function, going forward, is just function() with no markup needed.
>>
>> So I'm unclear:
>>
>> 1) would you prefer I wait on your 5.3 change being fully committed,
>> 2) add your change to my local tree and use it, then submit an update
>> patchset that depends upon it, or
>> 3) re-submit now (using the current method) with suggested changes?
>
> I would just not mark up function() at all, and the right thing will
> happen to it in the very near future.
Done.
I applied your two patches (locally) to verify the result, and it looks
good to me. In the interim, I think it's NBD.
Thanks much.
grh
^ permalink raw reply
* Re: [PATCH v13 04/13] mfd: Add Ingenic TCU driver
From: Paul Burton @ 2019-06-25 17:30 UTC (permalink / raw)
To: Paul Cercueil
Cc: Daniel Lezcano, Thomas Gleixner, Ralf Baechle, James Hogan,
Jonathan Corbet, Michael Turquette, Stephen Boyd, Jason Cooper,
Marc Zyngier, Lee Jones, Mathieu Malaterre, od@zcrc.me,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mips@vger.kernel.org, linux-doc@vger.kernel.org,
linux-clk@vger.kernel.org, Artur Rojek
In-Reply-To: <20190624225759.18299-5-paul@crapouillou.net>
Hi Paul,
On Tue, Jun 25, 2019 at 12:57:50AM +0200, Paul Cercueil wrote:
> +static const struct of_device_id ingenic_tcu_of_match[] = {
> + { .compatible = "ingenic,jz4740-tcu", .data = &jz4740_soc_info, },
> + { .compatible = "ingenic,jz4725b-tcu", .data = &jz4725b_soc_info, },
> + { .compatible = "ingenic,jz4770-tcu", .data = &jz4740_soc_info, },
> + { }
> +};
Nit: why not order these numerically? ie. 25b, 40, 70.
> +static struct regmap * __init ingenic_tcu_create_regmap(struct device_node *np)
> +{
> + struct resource res;
> + void __iomem *base;
> + struct regmap *map;
> +
> + if (!of_match_node(ingenic_tcu_of_match, np))
> + return ERR_PTR(-EINVAL);
> +
> + base = of_io_request_and_map(np, 0, "TCU");
> + if (IS_ERR(base))
> + return ERR_PTR(PTR_ERR(base));
This is equivalent to:
return ERR_CAST(base);
Apart from those:
Reviewed-by: Paul Burton <paul.burton@mips.com>
Thanks,
Paul
^ permalink raw reply
* Re: [PATCH v4 00/14] ima: introduce IMA Digest Lists extension
From: Mimi Zohar @ 2019-06-25 17:35 UTC (permalink / raw)
To: Roberto Sassu, dmitry.kasatkin, mjg59, Rob Landley
Cc: linux-integrity, linux-security-module, linux-fsdevel, linux-doc,
linux-kernel, silviu.vlasceanu
In-Reply-To: <88d368e6-5b3c-0206-23a0-dc3e0aa385f0@huawei.com>
[Cc'ing Rob Landley]
On Tue, 2019-06-25 at 14:57 +0200, Roberto Sassu wrote:
> Mimi, do you have any thoughts on this version?
I need to look closer, but when I first looked these changes seemed to
be really invasive. Let's first work on getting the CPIO xattr
support upstreamed. Rob Landley said he was going to review and test
them. Do you have any documentation on how to set up a test
environment? I'd really appreciate if others would also help with
reviewing the CPIO patches.
thanks!
Mimi
^ permalink raw reply
* Re: [PATCH v13 04/13] mfd: Add Ingenic TCU driver
From: Paul Cercueil @ 2019-06-25 17:47 UTC (permalink / raw)
To: Paul Burton
Cc: Daniel Lezcano, Thomas Gleixner, Ralf Baechle, James Hogan,
Jonathan Corbet, Michael Turquette, Stephen Boyd, Jason Cooper,
Marc Zyngier, Lee Jones, Mathieu Malaterre, od, devicetree,
linux-kernel, linux-mips, linux-doc, linux-clk, Artur Rojek
In-Reply-To: <20190625173026.dbvx44iwywnijjql@pburton-laptop>
Le mar. 25 juin 2019 à 19:30, Paul Burton <paul.burton@mips.com> a
écrit :
> Hi Paul,
>
> On Tue, Jun 25, 2019 at 12:57:50AM +0200, Paul Cercueil wrote:
>> +static const struct of_device_id ingenic_tcu_of_match[] = {
>> + { .compatible = "ingenic,jz4740-tcu", .data = &jz4740_soc_info, },
>> + { .compatible = "ingenic,jz4725b-tcu", .data = &jz4725b_soc_info,
>> },
>> + { .compatible = "ingenic,jz4770-tcu", .data = &jz4740_soc_info, },
>> + { }
>> +};
>
> Nit: why not order these numerically? ie. 25b, 40, 70.
They are in chronological order - the jz4725b is newer than the jz4740.
>> +static struct regmap * __init ingenic_tcu_create_regmap(struct
>> device_node *np)
>> +{
>> + struct resource res;
>> + void __iomem *base;
>> + struct regmap *map;
>> +
>> + if (!of_match_node(ingenic_tcu_of_match, np))
>> + return ERR_PTR(-EINVAL);
>> +
>> + base = of_io_request_and_map(np, 0, "TCU");
>> + if (IS_ERR(base))
>> + return ERR_PTR(PTR_ERR(base));
>
> This is equivalent to:
>
> return ERR_CAST(base);
Alright - I'll fix it in a following patch if this V13 gets merged,
or in the V14 patchset.
> Apart from those:
>
> Reviewed-by: Paul Burton <paul.burton@mips.com>
>
> Thanks,
> Paul
^ permalink raw reply
* [PATCH v6 0/2] fTPM: firmware TPM running in TEE
From: Sasha Levin @ 2019-06-25 19:52 UTC (permalink / raw)
To: peterhuewe, jarkko.sakkinen, jgg
Cc: corbet, linux-kernel, linux-doc, linux-integrity, linux-kernel,
thiruan, bryankel, tee-dev, ilias.apalodimas, sumit.garg,
Sasha Levin
Changes in v6:
- Address comments from Ilias Apalodimas
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driver
Documentation/security/tpm/index.rst | 1 +
Documentation/security/tpm/tpm_ftpm_tee.rst | 31 ++
drivers/char/tpm/Kconfig | 5 +
drivers/char/tpm/Makefile | 1 +
drivers/char/tpm/tpm_ftpm_tee.c | 356 ++++++++++++++++++++
drivers/char/tpm/tpm_ftpm_tee.h | 40 +++
6 files changed, 434 insertions(+)
create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst
create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c
create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
--
2.20.1
^ permalink raw reply
* [PATCH v6 2/2] fTPM: add documentation for ftpm driver
From: Sasha Levin @ 2019-06-25 19:52 UTC (permalink / raw)
To: peterhuewe, jarkko.sakkinen, jgg
Cc: corbet, linux-kernel, linux-doc, linux-integrity, linux-kernel,
thiruan, bryankel, tee-dev, ilias.apalodimas, sumit.garg,
Sasha Levin
In-Reply-To: <20190625195209.13663-1-sashal@kernel.org>
This patch adds basic documentation to describe the new fTPM driver.
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Documentation/security/tpm/index.rst | 1 +
Documentation/security/tpm/tpm_ftpm_tee.rst | 31 +++++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst
diff --git a/Documentation/security/tpm/index.rst b/Documentation/security/tpm/index.rst
index af77a7bbb070..15783668644f 100644
--- a/Documentation/security/tpm/index.rst
+++ b/Documentation/security/tpm/index.rst
@@ -4,4 +4,5 @@ Trusted Platform Module documentation
.. toctree::
+ tpm_ftpm_tee
tpm_vtpm_proxy
diff --git a/Documentation/security/tpm/tpm_ftpm_tee.rst b/Documentation/security/tpm/tpm_ftpm_tee.rst
new file mode 100644
index 000000000000..29c2f8b5ed10
--- /dev/null
+++ b/Documentation/security/tpm/tpm_ftpm_tee.rst
@@ -0,0 +1,31 @@
+=============================================
+Firmware TPM Driver
+=============================================
+
+| Authors:
+| Thirupathaiah Annapureddy <thiruan@microsoft.com>
+| Sasha Levin <sashal@kernel.org>
+
+This document describes the firmware Trusted Platform Module (fTPM)
+device driver.
+
+Introduction
+============
+
+This driver is a shim for a firmware implemented in ARM's TrustZone
+environment. The driver allows programs to interact with the TPM in the same
+way the would interact with a hardware TPM.
+
+Design
+======
+
+The driver acts as a thin layer that passes commands to and from a TPM
+implemented in firmware. The driver itself doesn't contain much logic and is
+used more like a dumb pipe between firmware and kernel/userspace.
+
+The firmware itself is based on the following paper:
+https://www.microsoft.com/en-us/research/wp-content/uploads/2017/06/ftpm1.pdf
+
+When the driver is loaded it will expose ``/dev/tpmX`` character devices to
+userspace which will enable userspace to communicate with the firmware tpm
+through this device.
--
2.20.1
^ permalink raw reply related
* [PATCH v6 1/2] fTPM: firmware TPM running in TEE
From: Sasha Levin @ 2019-06-25 19:52 UTC (permalink / raw)
To: peterhuewe, jarkko.sakkinen, jgg
Cc: corbet, linux-kernel, linux-doc, linux-integrity, linux-kernel,
thiruan, bryankel, tee-dev, ilias.apalodimas, sumit.garg,
Sasha Levin
In-Reply-To: <20190625195209.13663-1-sashal@kernel.org>
This patch adds support for a software-only implementation of a TPM
running in TEE.
There is extensive documentation of the design here:
https://www.microsoft.com/en-us/research/publication/ftpm-software-implementation-tpm-chip/ .
As well as reference code for the firmware available here:
https://github.com/Microsoft/ms-tpm-20-ref/tree/master/Samples/ARM32-FirmwareTPM
Tested-by: Thirupathaiah Annapureddy <thiruan@microsoft.com>
Signed-off-by: Thirupathaiah Annapureddy <thiruan@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/char/tpm/Kconfig | 5 +
drivers/char/tpm/Makefile | 1 +
drivers/char/tpm/tpm_ftpm_tee.c | 356 ++++++++++++++++++++++++++++++++
drivers/char/tpm/tpm_ftpm_tee.h | 40 ++++
4 files changed, 402 insertions(+)
create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c
create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index 88a3c06fc153..facee3bb5607 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -164,6 +164,11 @@ config TCG_VTPM_PROXY
/dev/vtpmX and a server-side file descriptor on which the vTPM
can receive commands.
+config TCG_FTPM_TEE
+ tristate "TEE based fTPM Interface"
+ depends on TEE && OPTEE
+ ---help---
+ This driver proxies for fTPM running in TEE
source "drivers/char/tpm/st33zp24/Kconfig"
endif # TCG_TPM
diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index a01c4cab902a..c354cdff9c62 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -33,3 +33,4 @@ obj-$(CONFIG_TCG_TIS_ST33ZP24) += st33zp24/
obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o
obj-$(CONFIG_TCG_CRB) += tpm_crb.o
obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o
+obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o
diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
new file mode 100644
index 000000000000..0312c10767bd
--- /dev/null
+++ b/drivers/char/tpm/tpm_ftpm_tee.c
@@ -0,0 +1,356 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) Microsoft Corporation
+ *
+ * Implements a firmware TPM as described here:
+ * https://www.microsoft.com/en-us/research/publication/ftpm-software-implementation-tpm-chip/
+ *
+ * A reference implementation is available here:
+ * https://github.com/microsoft/ms-tpm-20-ref/tree/master/Samples/ARM32-FirmwareTPM/optee_ta/fTPM
+ */
+
+#include <linux/acpi.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/tee_drv.h>
+#include <linux/tpm.h>
+#include <linux/uuid.h>
+
+#include "tpm.h"
+#include "tpm_ftpm_tee.h"
+
+#define DRIVER_NAME "ftpm-tee"
+
+/*
+ * TA_FTPM_UUID: BC50D971-D4C9-42C4-82CB-343FB7F37896
+ *
+ * Randomly generated, and must correspond to the GUID on the TA side.
+ * Defined here in the reference implementation:
+ * https://github.com/microsoft/ms-tpm-20-ref/blob/master/Samples/ARM32-FirmwareTPM/optee_ta/fTPM/include/fTPM.h#L42
+ */
+
+static const uuid_t ftpm_ta_uuid =
+ UUID_INIT(0xBC50D971, 0xD4C9, 0x42C4,
+ 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x96);
+
+/**
+ * ftpm_tee_tpm_op_recv - retrieve fTPM response.
+ *
+ * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h.
+ * @buf: the buffer to store data.
+ * @count: the number of bytes to read.
+ *
+ * Return:
+ * In case of success the number of bytes received.
+ * On failure, -errno.
+ */
+static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count)
+{
+ struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent);
+ size_t len;
+
+ len = pvt_data->resp_len;
+ if (count < len) {
+ dev_err(&chip->dev,
+ "%s:Invalid size in recv: count=%zd, resp_len=%zd\n",
+ __func__, count, len);
+ return -EIO;
+ }
+
+ memcpy(buf, pvt_data->resp_buf, len);
+ pvt_data->resp_len = 0;
+
+ return len;
+}
+
+/**
+ * ftpm_tee_tpm_op_send - send TPM commands through the TEE shared memory.
+ *
+ * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h
+ * @buf: the buffer to send.
+ * @len: the number of bytes to send.
+ *
+ * Return:
+ * In case of success, returns 0.
+ * On failure, -errno
+ */
+static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len)
+{
+ struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent);
+ size_t resp_len;
+ int rc;
+ u8 *temp_buf;
+ struct tpm_header *resp_header;
+ struct tee_ioctl_invoke_arg transceive_args;
+ struct tee_param command_params[4];
+ struct tee_shm *shm = pvt_data->shm;
+
+ if (len > MAX_COMMAND_SIZE) {
+ dev_err(&chip->dev,
+ "%s:len=%zd exceeds MAX_COMMAND_SIZE supported by fTPM TA\n",
+ __func__, len);
+ return -EIO;
+ }
+
+ memset(&transceive_args, 0, sizeof(transceive_args));
+ memset(command_params, 0, sizeof(command_params));
+ pvt_data->resp_len = 0;
+
+ /* Invoke FTPM_OPTEE_TA_SUBMIT_COMMAND function of fTPM TA */
+ transceive_args = (struct tee_ioctl_invoke_arg) {
+ .func = FTPM_OPTEE_TA_SUBMIT_COMMAND,
+ .session = pvt_data->session,
+ .num_params = 4,
+ };
+
+ /* Fill FTPM_OPTEE_TA_SUBMIT_COMMAND parameters */
+ command_params[0] = (struct tee_param) {
+ .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT,
+ .u.memref = {
+ .shm = shm,
+ .size = len,
+ .shm_offs = 0,
+ },
+ };
+
+ temp_buf = tee_shm_get_va(shm, 0);
+ if (IS_ERR(temp_buf)) {
+ dev_err(&chip->dev, "%s:tee_shm_get_va failed for transmit\n",
+ __func__);
+ return PTR_ERR(temp_buf);
+ }
+ memset(temp_buf, 0, (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE));
+
+ memcpy(temp_buf, buf, len);
+
+ command_params[1] = (struct tee_param) {
+ .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT,
+ .u.memref = {
+ .shm = shm,
+ .size = MAX_RESPONSE_SIZE,
+ .shm_offs = MAX_COMMAND_SIZE,
+ },
+ };
+
+ rc = tee_client_invoke_func(pvt_data->ctx, &transceive_args,
+ command_params);
+ if ((rc < 0) || (transceive_args.ret != 0)) {
+ dev_err(&chip->dev, "%s:SUBMIT_COMMAND invoke error: 0x%x\n",
+ __func__, transceive_args.ret);
+ return (rc < 0) ? rc : transceive_args.ret;
+ }
+
+ temp_buf = tee_shm_get_va(shm, command_params[1].u.memref.shm_offs);
+ if (IS_ERR(temp_buf)) {
+ dev_err(&chip->dev, "%s:tee_shm_get_va failed for receive\n",
+ __func__);
+ return PTR_ERR(temp_buf);
+ }
+
+ resp_header = (struct tpm_header *)temp_buf;
+ resp_len = be32_to_cpu(resp_header->length);
+
+ /* sanity check resp_len */
+ if (resp_len < TPM_HEADER_SIZE) {
+ dev_err(&chip->dev, "%s:tpm response header too small\n",
+ __func__);
+ return -EIO;
+ }
+ if (resp_len > MAX_RESPONSE_SIZE) {
+ dev_err(&chip->dev,
+ "%s:resp_len=%zd exceeds MAX_RESPONSE_SIZE\n",
+ __func__, resp_len);
+ return -EIO;
+ }
+
+ /* sanity checks look good, cache the response */
+ memcpy(pvt_data->resp_buf, temp_buf, resp_len);
+ pvt_data->resp_len = resp_len;
+
+ return 0;
+}
+
+static void ftpm_tee_tpm_op_cancel(struct tpm_chip *chip)
+{
+ /* not supported */
+}
+
+static u8 ftpm_tee_tpm_op_status(struct tpm_chip *chip)
+{
+ return 0;
+}
+
+static bool ftpm_tee_tpm_req_canceled(struct tpm_chip *chip, u8 status)
+{
+ return 0;
+}
+
+static const struct tpm_class_ops ftpm_tee_tpm_ops = {
+ .flags = TPM_OPS_AUTO_STARTUP,
+ .recv = ftpm_tee_tpm_op_recv,
+ .send = ftpm_tee_tpm_op_send,
+ .cancel = ftpm_tee_tpm_op_cancel,
+ .status = ftpm_tee_tpm_op_status,
+ .req_complete_mask = 0,
+ .req_complete_val = 0,
+ .req_canceled = ftpm_tee_tpm_req_canceled,
+};
+
+/*
+ * Check whether this driver supports the fTPM TA in the TEE instance
+ * represented by the params (ver/data) to this function.
+ */
+static int ftpm_tee_match(struct tee_ioctl_version_data *ver, const void *data)
+{
+ /*
+ * Currently this driver only support GP Complaint OPTEE based fTPM TA
+ */
+ if ((ver->impl_id == TEE_IMPL_ID_OPTEE) &&
+ (ver->gen_caps & TEE_GEN_CAP_GP))
+ return 1;
+ else
+ return 0;
+}
+
+/**
+ * ftpm_tee_probe - initialize the fTPM
+ * @pdev: the platform_device description.
+ *
+ * Return:
+ * On success, 0. On failure, -errno.
+ */
+static int ftpm_tee_probe(struct platform_device *pdev)
+{
+ int rc;
+ struct tpm_chip *chip;
+ struct device *dev = &pdev->dev;
+ struct ftpm_tee_private *pvt_data = NULL;
+ struct tee_ioctl_open_session_arg sess_arg;
+
+ pvt_data = devm_kzalloc(dev, sizeof(struct ftpm_tee_private),
+ GFP_KERNEL);
+ if (!pvt_data)
+ return -ENOMEM;
+
+ dev_set_drvdata(dev, pvt_data);
+
+ /* Open context with TEE driver */
+ pvt_data->ctx = tee_client_open_context(NULL, ftpm_tee_match, NULL,
+ NULL);
+ if (IS_ERR(pvt_data->ctx)) {
+ if (ERR_PTR(pvt_data->ctx) == -ENOENT)
+ return -EPROBE_DEFER;
+ dev_err(dev, "%s:tee_client_open_context failed\n", __func__);
+ return ERR_PTR(pvt_data->ctx);
+ }
+
+ /* Open a session with fTPM TA */
+ memset(&sess_arg, 0, sizeof(sess_arg));
+ memcpy(sess_arg.uuid, ftpm_ta_uuid.b, TEE_IOCTL_UUID_LEN);
+ sess_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC;
+ sess_arg.num_params = 0;
+
+ rc = tee_client_open_session(pvt_data->ctx, &sess_arg, NULL);
+ if ((rc < 0) || (sess_arg.ret != 0)) {
+ dev_err(dev, "%s:tee_client_open_session failed, err=%x\n",
+ __func__, sess_arg.ret);
+ rc = -EINVAL;
+ goto out_tee_session;
+ }
+ pvt_data->session = sess_arg.session;
+
+ /* Allocate dynamic shared memory with fTPM TA */
+ pvt_data->shm = tee_shm_alloc(pvt_data->ctx,
+ (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE),
+ TEE_SHM_MAPPED | TEE_SHM_DMA_BUF);
+ if (IS_ERR(pvt_data->shm)) {
+ dev_err(dev, "%s:tee_shm_alloc failed\n", __func__);
+ rc = -ENOMEM;
+ goto out_shm_alloc;
+ }
+
+ /* Allocate new struct tpm_chip instance */
+ chip = tpm_chip_alloc(dev, &ftpm_tee_tpm_ops);
+ if (IS_ERR(chip)) {
+ dev_err(dev, "%s:tpm_chip_alloc failed\n", __func__);
+ rc = PTR_ERR(chip);
+ goto out_chip_alloc;
+ }
+
+ pvt_data->chip = chip;
+ pvt_data->chip->flags |= TPM_CHIP_FLAG_TPM2;
+
+ /* Create a character device for the fTPM */
+ rc = tpm_chip_register(pvt_data->chip);
+ if (rc) {
+ dev_err(dev, "%s:tpm_chip_register failed with rc=%d\n",
+ __func__, rc);
+ goto out_chip;
+ }
+
+ return 0;
+
+out_chip:
+ put_device(&pvt_data->chip->dev);
+out_chip_alloc:
+ tee_shm_free(pvt_data->shm);
+out_shm_alloc:
+ tee_client_close_session(pvt_data->ctx, pvt_data->session);
+out_tee_session:
+ tee_client_close_context(pvt_data->ctx);
+
+ return rc;
+}
+
+/**
+ * ftpm_tee_remove - remove the TPM device
+ * @pdev: the platform_device description.
+ *
+ * Return:
+ * 0 in case of success.
+ */
+static int ftpm_tee_remove(struct platform_device *pdev)
+{
+ struct ftpm_tee_private *pvt_data = dev_get_drvdata(&pdev->dev);
+
+ /* Release the chip */
+ tpm_chip_unregister(pvt_data->chip);
+
+ /* frees chip */
+ put_device(&pvt_data->chip->dev);
+
+ /* Free the shared memory pool */
+ tee_shm_free(pvt_data->shm);
+
+ /* close the existing session with fTPM TA*/
+ tee_client_close_session(pvt_data->ctx, pvt_data->session);
+
+ /* close the context with TEE driver */
+ tee_client_close_context(pvt_data->ctx);
+
+ /* memory allocated with devm_kzalloc() is freed automatically */
+
+ return 0;
+}
+
+static const struct of_device_id of_ftpm_tee_ids[] = {
+ { .compatible = "microsoft,ftpm" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, of_ftpm_tee_ids);
+
+static struct platform_driver ftpm_tee_driver = {
+ .driver = {
+ .name = DRIVER_NAME,
+ .of_match_table = of_match_ptr(of_ftpm_tee_ids),
+ },
+ .probe = ftpm_tee_probe,
+ .remove = ftpm_tee_remove,
+};
+
+module_platform_driver(ftpm_tee_driver);
+
+MODULE_AUTHOR("Thirupathaiah Annapureddy <thiruan@microsoft.com>");
+MODULE_DESCRIPTION("TPM Driver for fTPM TA in TEE");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/char/tpm/tpm_ftpm_tee.h b/drivers/char/tpm/tpm_ftpm_tee.h
new file mode 100644
index 000000000000..b09ee7be4545
--- /dev/null
+++ b/drivers/char/tpm/tpm_ftpm_tee.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) Microsoft Corporation
+ */
+
+#ifndef __TPM_FTPM_TEE_H__
+#define __TPM_FTPM_TEE_H__
+
+#include <linux/tee_drv.h>
+#include <linux/tpm.h>
+#include <linux/uuid.h>
+
+/* The TAFs ID implemented in this TA */
+#define FTPM_OPTEE_TA_SUBMIT_COMMAND (0)
+#define FTPM_OPTEE_TA_EMULATE_PPI (1)
+
+/* max. buffer size supported by fTPM */
+#define MAX_COMMAND_SIZE 4096
+#define MAX_RESPONSE_SIZE 4096
+
+/**
+ * struct ftpm_tee_private - fTPM's private data
+ * @chip: struct tpm_chip instance registered with tpm framework.
+ * @state: internal state
+ * @session: fTPM TA session identifier.
+ * @resp_len: cached response buffer length.
+ * @resp_buf: cached response buffer.
+ * @ctx: TEE context handler.
+ * @shm: Memory pool shared with fTPM TA in TEE.
+ */
+struct ftpm_tee_private {
+ struct tpm_chip *chip;
+ u32 session;
+ size_t resp_len;
+ u8 resp_buf[MAX_RESPONSE_SIZE];
+ struct tee_context *ctx;
+ struct tee_shm *shm;
+};
+
+#endif /* __TPM_FTPM_TEE_H__ */
--
2.20.1
^ permalink raw reply related
* Re: [PATCH v6 2/2] fTPM: add documentation for ftpm driver
From: Randy Dunlap @ 2019-06-25 19:59 UTC (permalink / raw)
To: Sasha Levin, peterhuewe, jarkko.sakkinen, jgg
Cc: corbet, linux-kernel, linux-doc, linux-integrity, linux-kernel,
thiruan, bryankel, tee-dev, ilias.apalodimas, sumit.garg
In-Reply-To: <20190625195209.13663-3-sashal@kernel.org>
On 6/25/19 12:52 PM, Sasha Levin wrote:
> This patch adds basic documentation to describe the new fTPM driver.
>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> Documentation/security/tpm/index.rst | 1 +
> Documentation/security/tpm/tpm_ftpm_tee.rst | 31 +++++++++++++++++++++
> 2 files changed, 32 insertions(+)
> create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst
>
> diff --git a/Documentation/security/tpm/index.rst b/Documentation/security/tpm/index.rst
> index af77a7bbb070..15783668644f 100644
> --- a/Documentation/security/tpm/index.rst
> +++ b/Documentation/security/tpm/index.rst
> @@ -4,4 +4,5 @@ Trusted Platform Module documentation
>
> .. toctree::
>
> + tpm_ftpm_tee
> tpm_vtpm_proxy
> diff --git a/Documentation/security/tpm/tpm_ftpm_tee.rst b/Documentation/security/tpm/tpm_ftpm_tee.rst
> new file mode 100644
> index 000000000000..29c2f8b5ed10
> --- /dev/null
> +++ b/Documentation/security/tpm/tpm_ftpm_tee.rst
> @@ -0,0 +1,31 @@
> +=============================================
> +Firmware TPM Driver
> +=============================================
> +
> +| Authors:
> +| Thirupathaiah Annapureddy <thiruan@microsoft.com>
> +| Sasha Levin <sashal@kernel.org>
> +
> +This document describes the firmware Trusted Platform Module (fTPM)
> +device driver.
> +
> +Introduction
> +============
> +
> +This driver is a shim for a firmware implemented in ARM's TrustZone
for firmware
> +environment. The driver allows programs to interact with the TPM in the same
> +way the would interact with a hardware TPM.
they
> +
> +Design
> +======
> +
> +The driver acts as a thin layer that passes commands to and from a TPM
> +implemented in firmware. The driver itself doesn't contain much logic and is
> +used more like a dumb pipe between firmware and kernel/userspace.
> +
> +The firmware itself is based on the following paper:
> +https://www.microsoft.com/en-us/research/wp-content/uploads/2017/06/ftpm1.pdf
> +
> +When the driver is loaded it will expose ``/dev/tpmX`` character devices to
> +userspace which will enable userspace to communicate with the firmware tpm
TPM
> +through this device.
>
Oh, that's the same comments that I made on 2019-06-18:
https://marc.info/?l=linux-integrity&m=156087157019368&w=2
--
~Randy
^ permalink raw reply
* Re: [PATCH v6 1/2] fTPM: firmware TPM running in TEE
From: Randy Dunlap @ 2019-06-25 20:01 UTC (permalink / raw)
To: Sasha Levin, peterhuewe, jarkko.sakkinen, jgg
Cc: corbet, linux-kernel, linux-doc, linux-integrity, linux-kernel,
thiruan, bryankel, tee-dev, ilias.apalodimas, sumit.garg
In-Reply-To: <20190625195209.13663-2-sashal@kernel.org>
Hi,
On 6/25/19 12:52 PM, Sasha Levin wrote:
> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
> index 88a3c06fc153..facee3bb5607 100644
> --- a/drivers/char/tpm/Kconfig
> +++ b/drivers/char/tpm/Kconfig
> @@ -164,6 +164,11 @@ config TCG_VTPM_PROXY
> /dev/vtpmX and a server-side file descriptor on which the vTPM
> can receive commands.
>
> +config TCG_FTPM_TEE
> + tristate "TEE based fTPM Interface"
> + depends on TEE && OPTEE
> + ---help---
> + This driver proxies for fTPM running in TEE
acronym overload. For the help text, I would at least s/fTPM/firmware TPM/.
Also, end that sentence with a '.'.
>
> source "drivers/char/tpm/st33zp24/Kconfig"
> endif # TCG_TPM
--
~Randy
^ permalink raw reply
* Re: [PATCH v6 2/2] fTPM: add documentation for ftpm driver
From: Sasha Levin @ 2019-06-25 20:03 UTC (permalink / raw)
To: Randy Dunlap
Cc: peterhuewe, jarkko.sakkinen, jgg, corbet, linux-kernel, linux-doc,
linux-integrity, linux-kernel, thiruan, bryankel, tee-dev,
ilias.apalodimas, sumit.garg
In-Reply-To: <b1f27a59-6759-c325-8db5-b2b0f944420c@infradead.org>
On Tue, Jun 25, 2019 at 12:59:02PM -0700, Randy Dunlap wrote:
>On 6/25/19 12:52 PM, Sasha Levin wrote:
>> This patch adds basic documentation to describe the new fTPM driver.
>>
>> Signed-off-by: Sasha Levin <sashal@kernel.org>
>> ---
>> Documentation/security/tpm/index.rst | 1 +
>> Documentation/security/tpm/tpm_ftpm_tee.rst | 31 +++++++++++++++++++++
>> 2 files changed, 32 insertions(+)
>> create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst
>>
>> diff --git a/Documentation/security/tpm/index.rst b/Documentation/security/tpm/index.rst
>> index af77a7bbb070..15783668644f 100644
>> --- a/Documentation/security/tpm/index.rst
>> +++ b/Documentation/security/tpm/index.rst
>> @@ -4,4 +4,5 @@ Trusted Platform Module documentation
>>
>> .. toctree::
>>
>> + tpm_ftpm_tee
>> tpm_vtpm_proxy
>> diff --git a/Documentation/security/tpm/tpm_ftpm_tee.rst b/Documentation/security/tpm/tpm_ftpm_tee.rst
>> new file mode 100644
>> index 000000000000..29c2f8b5ed10
>> --- /dev/null
>> +++ b/Documentation/security/tpm/tpm_ftpm_tee.rst
>> @@ -0,0 +1,31 @@
>> +=============================================
>> +Firmware TPM Driver
>> +=============================================
>> +
>> +| Authors:
>> +| Thirupathaiah Annapureddy <thiruan@microsoft.com>
>> +| Sasha Levin <sashal@kernel.org>
>> +
>> +This document describes the firmware Trusted Platform Module (fTPM)
>> +device driver.
>> +
>> +Introduction
>> +============
>> +
>> +This driver is a shim for a firmware implemented in ARM's TrustZone
>
> for firmware
>
>> +environment. The driver allows programs to interact with the TPM in the same
>> +way the would interact with a hardware TPM.
>
> they
>
>> +
>> +Design
>> +======
>> +
>> +The driver acts as a thin layer that passes commands to and from a TPM
>> +implemented in firmware. The driver itself doesn't contain much logic and is
>> +used more like a dumb pipe between firmware and kernel/userspace.
>> +
>> +The firmware itself is based on the following paper:
>> +https://www.microsoft.com/en-us/research/wp-content/uploads/2017/06/ftpm1.pdf
>> +
>> +When the driver is loaded it will expose ``/dev/tpmX`` character devices to
>> +userspace which will enable userspace to communicate with the firmware tpm
>
> TPM
>
>> +through this device.
>>
>
>Oh, that's the same comments that I made on 2019-06-18:
>https://marc.info/?l=linux-integrity&m=156087157019368&w=2
Appologies Randy, I've missed it. I'll send a new ver in a moment.
Thanks!
--
Thanks,
Sasha
^ permalink raw reply
* [PATCH v7 0/2] fTPM: firmware TPM running in TEE
From: Sasha Levin @ 2019-06-25 20:13 UTC (permalink / raw)
To: peterhuewe, jarkko.sakkinen, jgg
Cc: corbet, linux-kernel, linux-doc, linux-integrity, linux-kernel,
thiruan, bryankel, tee-dev, ilias.apalodimas, sumit.garg, rdunlap,
Sasha Levin
Changes in v6:
- Address comments from Randy Dunlap
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driver
Documentation/security/tpm/index.rst | 1 +
Documentation/security/tpm/tpm_ftpm_tee.rst | 31 ++
drivers/char/tpm/Kconfig | 5 +
drivers/char/tpm/Makefile | 1 +
drivers/char/tpm/tpm_ftpm_tee.c | 356 ++++++++++++++++++++
drivers/char/tpm/tpm_ftpm_tee.h | 40 +++
6 files changed, 434 insertions(+)
create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst
create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c
create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
--
2.20.1
^ permalink raw reply
* [PATCH v7 1/2] fTPM: firmware TPM running in TEE
From: Sasha Levin @ 2019-06-25 20:13 UTC (permalink / raw)
To: peterhuewe, jarkko.sakkinen, jgg
Cc: corbet, linux-kernel, linux-doc, linux-integrity, linux-kernel,
thiruan, bryankel, tee-dev, ilias.apalodimas, sumit.garg, rdunlap,
Sasha Levin
In-Reply-To: <20190625201341.15865-1-sashal@kernel.org>
This patch adds support for a software-only implementation of a TPM
running in TEE.
There is extensive documentation of the design here:
https://www.microsoft.com/en-us/research/publication/ftpm-software-implementation-tpm-chip/ .
As well as reference code for the firmware available here:
https://github.com/Microsoft/ms-tpm-20-ref/tree/master/Samples/ARM32-FirmwareTPM
Tested-by: Thirupathaiah Annapureddy <thiruan@microsoft.com>
Signed-off-by: Thirupathaiah Annapureddy <thiruan@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/char/tpm/Kconfig | 5 +
drivers/char/tpm/Makefile | 1 +
drivers/char/tpm/tpm_ftpm_tee.c | 356 ++++++++++++++++++++++++++++++++
drivers/char/tpm/tpm_ftpm_tee.h | 40 ++++
4 files changed, 402 insertions(+)
create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c
create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index 88a3c06fc153..17bfbf9f572f 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -164,6 +164,11 @@ config TCG_VTPM_PROXY
/dev/vtpmX and a server-side file descriptor on which the vTPM
can receive commands.
+config TCG_FTPM_TEE
+ tristate "TEE based fTPM Interface"
+ depends on TEE && OPTEE
+ ---help---
+ This driver proxies for firmware TPM running in TEE.
source "drivers/char/tpm/st33zp24/Kconfig"
endif # TCG_TPM
diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index a01c4cab902a..c354cdff9c62 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -33,3 +33,4 @@ obj-$(CONFIG_TCG_TIS_ST33ZP24) += st33zp24/
obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o
obj-$(CONFIG_TCG_CRB) += tpm_crb.o
obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o
+obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o
diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
new file mode 100644
index 000000000000..0312c10767bd
--- /dev/null
+++ b/drivers/char/tpm/tpm_ftpm_tee.c
@@ -0,0 +1,356 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) Microsoft Corporation
+ *
+ * Implements a firmware TPM as described here:
+ * https://www.microsoft.com/en-us/research/publication/ftpm-software-implementation-tpm-chip/
+ *
+ * A reference implementation is available here:
+ * https://github.com/microsoft/ms-tpm-20-ref/tree/master/Samples/ARM32-FirmwareTPM/optee_ta/fTPM
+ */
+
+#include <linux/acpi.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/tee_drv.h>
+#include <linux/tpm.h>
+#include <linux/uuid.h>
+
+#include "tpm.h"
+#include "tpm_ftpm_tee.h"
+
+#define DRIVER_NAME "ftpm-tee"
+
+/*
+ * TA_FTPM_UUID: BC50D971-D4C9-42C4-82CB-343FB7F37896
+ *
+ * Randomly generated, and must correspond to the GUID on the TA side.
+ * Defined here in the reference implementation:
+ * https://github.com/microsoft/ms-tpm-20-ref/blob/master/Samples/ARM32-FirmwareTPM/optee_ta/fTPM/include/fTPM.h#L42
+ */
+
+static const uuid_t ftpm_ta_uuid =
+ UUID_INIT(0xBC50D971, 0xD4C9, 0x42C4,
+ 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x96);
+
+/**
+ * ftpm_tee_tpm_op_recv - retrieve fTPM response.
+ *
+ * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h.
+ * @buf: the buffer to store data.
+ * @count: the number of bytes to read.
+ *
+ * Return:
+ * In case of success the number of bytes received.
+ * On failure, -errno.
+ */
+static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count)
+{
+ struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent);
+ size_t len;
+
+ len = pvt_data->resp_len;
+ if (count < len) {
+ dev_err(&chip->dev,
+ "%s:Invalid size in recv: count=%zd, resp_len=%zd\n",
+ __func__, count, len);
+ return -EIO;
+ }
+
+ memcpy(buf, pvt_data->resp_buf, len);
+ pvt_data->resp_len = 0;
+
+ return len;
+}
+
+/**
+ * ftpm_tee_tpm_op_send - send TPM commands through the TEE shared memory.
+ *
+ * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h
+ * @buf: the buffer to send.
+ * @len: the number of bytes to send.
+ *
+ * Return:
+ * In case of success, returns 0.
+ * On failure, -errno
+ */
+static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len)
+{
+ struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent);
+ size_t resp_len;
+ int rc;
+ u8 *temp_buf;
+ struct tpm_header *resp_header;
+ struct tee_ioctl_invoke_arg transceive_args;
+ struct tee_param command_params[4];
+ struct tee_shm *shm = pvt_data->shm;
+
+ if (len > MAX_COMMAND_SIZE) {
+ dev_err(&chip->dev,
+ "%s:len=%zd exceeds MAX_COMMAND_SIZE supported by fTPM TA\n",
+ __func__, len);
+ return -EIO;
+ }
+
+ memset(&transceive_args, 0, sizeof(transceive_args));
+ memset(command_params, 0, sizeof(command_params));
+ pvt_data->resp_len = 0;
+
+ /* Invoke FTPM_OPTEE_TA_SUBMIT_COMMAND function of fTPM TA */
+ transceive_args = (struct tee_ioctl_invoke_arg) {
+ .func = FTPM_OPTEE_TA_SUBMIT_COMMAND,
+ .session = pvt_data->session,
+ .num_params = 4,
+ };
+
+ /* Fill FTPM_OPTEE_TA_SUBMIT_COMMAND parameters */
+ command_params[0] = (struct tee_param) {
+ .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT,
+ .u.memref = {
+ .shm = shm,
+ .size = len,
+ .shm_offs = 0,
+ },
+ };
+
+ temp_buf = tee_shm_get_va(shm, 0);
+ if (IS_ERR(temp_buf)) {
+ dev_err(&chip->dev, "%s:tee_shm_get_va failed for transmit\n",
+ __func__);
+ return PTR_ERR(temp_buf);
+ }
+ memset(temp_buf, 0, (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE));
+
+ memcpy(temp_buf, buf, len);
+
+ command_params[1] = (struct tee_param) {
+ .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT,
+ .u.memref = {
+ .shm = shm,
+ .size = MAX_RESPONSE_SIZE,
+ .shm_offs = MAX_COMMAND_SIZE,
+ },
+ };
+
+ rc = tee_client_invoke_func(pvt_data->ctx, &transceive_args,
+ command_params);
+ if ((rc < 0) || (transceive_args.ret != 0)) {
+ dev_err(&chip->dev, "%s:SUBMIT_COMMAND invoke error: 0x%x\n",
+ __func__, transceive_args.ret);
+ return (rc < 0) ? rc : transceive_args.ret;
+ }
+
+ temp_buf = tee_shm_get_va(shm, command_params[1].u.memref.shm_offs);
+ if (IS_ERR(temp_buf)) {
+ dev_err(&chip->dev, "%s:tee_shm_get_va failed for receive\n",
+ __func__);
+ return PTR_ERR(temp_buf);
+ }
+
+ resp_header = (struct tpm_header *)temp_buf;
+ resp_len = be32_to_cpu(resp_header->length);
+
+ /* sanity check resp_len */
+ if (resp_len < TPM_HEADER_SIZE) {
+ dev_err(&chip->dev, "%s:tpm response header too small\n",
+ __func__);
+ return -EIO;
+ }
+ if (resp_len > MAX_RESPONSE_SIZE) {
+ dev_err(&chip->dev,
+ "%s:resp_len=%zd exceeds MAX_RESPONSE_SIZE\n",
+ __func__, resp_len);
+ return -EIO;
+ }
+
+ /* sanity checks look good, cache the response */
+ memcpy(pvt_data->resp_buf, temp_buf, resp_len);
+ pvt_data->resp_len = resp_len;
+
+ return 0;
+}
+
+static void ftpm_tee_tpm_op_cancel(struct tpm_chip *chip)
+{
+ /* not supported */
+}
+
+static u8 ftpm_tee_tpm_op_status(struct tpm_chip *chip)
+{
+ return 0;
+}
+
+static bool ftpm_tee_tpm_req_canceled(struct tpm_chip *chip, u8 status)
+{
+ return 0;
+}
+
+static const struct tpm_class_ops ftpm_tee_tpm_ops = {
+ .flags = TPM_OPS_AUTO_STARTUP,
+ .recv = ftpm_tee_tpm_op_recv,
+ .send = ftpm_tee_tpm_op_send,
+ .cancel = ftpm_tee_tpm_op_cancel,
+ .status = ftpm_tee_tpm_op_status,
+ .req_complete_mask = 0,
+ .req_complete_val = 0,
+ .req_canceled = ftpm_tee_tpm_req_canceled,
+};
+
+/*
+ * Check whether this driver supports the fTPM TA in the TEE instance
+ * represented by the params (ver/data) to this function.
+ */
+static int ftpm_tee_match(struct tee_ioctl_version_data *ver, const void *data)
+{
+ /*
+ * Currently this driver only support GP Complaint OPTEE based fTPM TA
+ */
+ if ((ver->impl_id == TEE_IMPL_ID_OPTEE) &&
+ (ver->gen_caps & TEE_GEN_CAP_GP))
+ return 1;
+ else
+ return 0;
+}
+
+/**
+ * ftpm_tee_probe - initialize the fTPM
+ * @pdev: the platform_device description.
+ *
+ * Return:
+ * On success, 0. On failure, -errno.
+ */
+static int ftpm_tee_probe(struct platform_device *pdev)
+{
+ int rc;
+ struct tpm_chip *chip;
+ struct device *dev = &pdev->dev;
+ struct ftpm_tee_private *pvt_data = NULL;
+ struct tee_ioctl_open_session_arg sess_arg;
+
+ pvt_data = devm_kzalloc(dev, sizeof(struct ftpm_tee_private),
+ GFP_KERNEL);
+ if (!pvt_data)
+ return -ENOMEM;
+
+ dev_set_drvdata(dev, pvt_data);
+
+ /* Open context with TEE driver */
+ pvt_data->ctx = tee_client_open_context(NULL, ftpm_tee_match, NULL,
+ NULL);
+ if (IS_ERR(pvt_data->ctx)) {
+ if (ERR_PTR(pvt_data->ctx) == -ENOENT)
+ return -EPROBE_DEFER;
+ dev_err(dev, "%s:tee_client_open_context failed\n", __func__);
+ return ERR_PTR(pvt_data->ctx);
+ }
+
+ /* Open a session with fTPM TA */
+ memset(&sess_arg, 0, sizeof(sess_arg));
+ memcpy(sess_arg.uuid, ftpm_ta_uuid.b, TEE_IOCTL_UUID_LEN);
+ sess_arg.clnt_login = TEE_IOCTL_LOGIN_PUBLIC;
+ sess_arg.num_params = 0;
+
+ rc = tee_client_open_session(pvt_data->ctx, &sess_arg, NULL);
+ if ((rc < 0) || (sess_arg.ret != 0)) {
+ dev_err(dev, "%s:tee_client_open_session failed, err=%x\n",
+ __func__, sess_arg.ret);
+ rc = -EINVAL;
+ goto out_tee_session;
+ }
+ pvt_data->session = sess_arg.session;
+
+ /* Allocate dynamic shared memory with fTPM TA */
+ pvt_data->shm = tee_shm_alloc(pvt_data->ctx,
+ (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE),
+ TEE_SHM_MAPPED | TEE_SHM_DMA_BUF);
+ if (IS_ERR(pvt_data->shm)) {
+ dev_err(dev, "%s:tee_shm_alloc failed\n", __func__);
+ rc = -ENOMEM;
+ goto out_shm_alloc;
+ }
+
+ /* Allocate new struct tpm_chip instance */
+ chip = tpm_chip_alloc(dev, &ftpm_tee_tpm_ops);
+ if (IS_ERR(chip)) {
+ dev_err(dev, "%s:tpm_chip_alloc failed\n", __func__);
+ rc = PTR_ERR(chip);
+ goto out_chip_alloc;
+ }
+
+ pvt_data->chip = chip;
+ pvt_data->chip->flags |= TPM_CHIP_FLAG_TPM2;
+
+ /* Create a character device for the fTPM */
+ rc = tpm_chip_register(pvt_data->chip);
+ if (rc) {
+ dev_err(dev, "%s:tpm_chip_register failed with rc=%d\n",
+ __func__, rc);
+ goto out_chip;
+ }
+
+ return 0;
+
+out_chip:
+ put_device(&pvt_data->chip->dev);
+out_chip_alloc:
+ tee_shm_free(pvt_data->shm);
+out_shm_alloc:
+ tee_client_close_session(pvt_data->ctx, pvt_data->session);
+out_tee_session:
+ tee_client_close_context(pvt_data->ctx);
+
+ return rc;
+}
+
+/**
+ * ftpm_tee_remove - remove the TPM device
+ * @pdev: the platform_device description.
+ *
+ * Return:
+ * 0 in case of success.
+ */
+static int ftpm_tee_remove(struct platform_device *pdev)
+{
+ struct ftpm_tee_private *pvt_data = dev_get_drvdata(&pdev->dev);
+
+ /* Release the chip */
+ tpm_chip_unregister(pvt_data->chip);
+
+ /* frees chip */
+ put_device(&pvt_data->chip->dev);
+
+ /* Free the shared memory pool */
+ tee_shm_free(pvt_data->shm);
+
+ /* close the existing session with fTPM TA*/
+ tee_client_close_session(pvt_data->ctx, pvt_data->session);
+
+ /* close the context with TEE driver */
+ tee_client_close_context(pvt_data->ctx);
+
+ /* memory allocated with devm_kzalloc() is freed automatically */
+
+ return 0;
+}
+
+static const struct of_device_id of_ftpm_tee_ids[] = {
+ { .compatible = "microsoft,ftpm" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, of_ftpm_tee_ids);
+
+static struct platform_driver ftpm_tee_driver = {
+ .driver = {
+ .name = DRIVER_NAME,
+ .of_match_table = of_match_ptr(of_ftpm_tee_ids),
+ },
+ .probe = ftpm_tee_probe,
+ .remove = ftpm_tee_remove,
+};
+
+module_platform_driver(ftpm_tee_driver);
+
+MODULE_AUTHOR("Thirupathaiah Annapureddy <thiruan@microsoft.com>");
+MODULE_DESCRIPTION("TPM Driver for fTPM TA in TEE");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/char/tpm/tpm_ftpm_tee.h b/drivers/char/tpm/tpm_ftpm_tee.h
new file mode 100644
index 000000000000..b09ee7be4545
--- /dev/null
+++ b/drivers/char/tpm/tpm_ftpm_tee.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) Microsoft Corporation
+ */
+
+#ifndef __TPM_FTPM_TEE_H__
+#define __TPM_FTPM_TEE_H__
+
+#include <linux/tee_drv.h>
+#include <linux/tpm.h>
+#include <linux/uuid.h>
+
+/* The TAFs ID implemented in this TA */
+#define FTPM_OPTEE_TA_SUBMIT_COMMAND (0)
+#define FTPM_OPTEE_TA_EMULATE_PPI (1)
+
+/* max. buffer size supported by fTPM */
+#define MAX_COMMAND_SIZE 4096
+#define MAX_RESPONSE_SIZE 4096
+
+/**
+ * struct ftpm_tee_private - fTPM's private data
+ * @chip: struct tpm_chip instance registered with tpm framework.
+ * @state: internal state
+ * @session: fTPM TA session identifier.
+ * @resp_len: cached response buffer length.
+ * @resp_buf: cached response buffer.
+ * @ctx: TEE context handler.
+ * @shm: Memory pool shared with fTPM TA in TEE.
+ */
+struct ftpm_tee_private {
+ struct tpm_chip *chip;
+ u32 session;
+ size_t resp_len;
+ u8 resp_buf[MAX_RESPONSE_SIZE];
+ struct tee_context *ctx;
+ struct tee_shm *shm;
+};
+
+#endif /* __TPM_FTPM_TEE_H__ */
--
2.20.1
^ permalink raw reply related
* [PATCH v7 2/2] fTPM: add documentation for ftpm driver
From: Sasha Levin @ 2019-06-25 20:13 UTC (permalink / raw)
To: peterhuewe, jarkko.sakkinen, jgg
Cc: corbet, linux-kernel, linux-doc, linux-integrity, linux-kernel,
thiruan, bryankel, tee-dev, ilias.apalodimas, sumit.garg, rdunlap,
Sasha Levin
In-Reply-To: <20190625201341.15865-1-sashal@kernel.org>
This patch adds basic documentation to describe the new fTPM driver.
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Documentation/security/tpm/index.rst | 1 +
Documentation/security/tpm/tpm_ftpm_tee.rst | 31 +++++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst
diff --git a/Documentation/security/tpm/index.rst b/Documentation/security/tpm/index.rst
index af77a7bbb070..15783668644f 100644
--- a/Documentation/security/tpm/index.rst
+++ b/Documentation/security/tpm/index.rst
@@ -4,4 +4,5 @@ Trusted Platform Module documentation
.. toctree::
+ tpm_ftpm_tee
tpm_vtpm_proxy
diff --git a/Documentation/security/tpm/tpm_ftpm_tee.rst b/Documentation/security/tpm/tpm_ftpm_tee.rst
new file mode 100644
index 000000000000..48de0dcec0f6
--- /dev/null
+++ b/Documentation/security/tpm/tpm_ftpm_tee.rst
@@ -0,0 +1,31 @@
+=============================================
+Firmware TPM Driver
+=============================================
+
+| Authors:
+| Thirupathaiah Annapureddy <thiruan@microsoft.com>
+| Sasha Levin <sashal@kernel.org>
+
+This document describes the firmware Trusted Platform Module (fTPM)
+device driver.
+
+Introduction
+============
+
+This driver is a shim for firmware implemented in ARM's TrustZone
+environment. The driver allows programs to interact with the TPM in the same
+way they would interact with a hardware TPM.
+
+Design
+======
+
+The driver acts as a thin layer that passes commands to and from a TPM
+implemented in firmware. The driver itself doesn't contain much logic and is
+used more like a dumb pipe between firmware and kernel/userspace.
+
+The firmware itself is based on the following paper:
+https://www.microsoft.com/en-us/research/wp-content/uploads/2017/06/ftpm1.pdf
+
+When the driver is loaded it will expose ``/dev/tpmX`` character devices to
+userspace which will enable userspace to communicate with the firmware TPM
+through this device.
--
2.20.1
^ permalink raw reply related
* Re: [PATCH v5 01/18] kunit: test: add KUnit test runner core
From: Brendan Higgins @ 2019-06-25 20:28 UTC (permalink / raw)
To: Stephen Boyd
Cc: Frank Rowand, Greg KH, Josh Poimboeuf, Kees Cook, Kieran Bingham,
Luis Chamberlain, Peter Zijlstra, Rob Herring, shuah,
Theodore Ts'o, Masahiro Yamada, devicetree, dri-devel,
kunit-dev, open list:DOCUMENTATION, linux-fsdevel, linux-kbuild,
Linux Kernel Mailing List, open list:KERNEL SELFTEST FRAMEWORK,
linux-nvdimm, linux-um, Sasha Levin, Bird, Timothy,
Amir Goldstein, Dan Carpenter, Daniel Vetter, Jeff Dike,
Joel Stanley, Julia Lawall, Kevin Hilman, Knut Omang,
Logan Gunthorpe, Michael Ellerman, Petr Mladek, Randy Dunlap,
Richard Weinberger, David Rientjes, Steven Rostedt, wfg
In-Reply-To: <20190620001526.93426218BE@mail.kernel.org>
On Wed, Jun 19, 2019 at 5:15 PM Stephen Boyd <sboyd@kernel.org> wrote:
>
> Quoting Brendan Higgins (2019-06-17 01:25:56)
> > diff --git a/kunit/test.c b/kunit/test.c
> > new file mode 100644
> > index 0000000000000..d05d254f1521f
> > --- /dev/null
> > +++ b/kunit/test.c
> > @@ -0,0 +1,210 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Base unit test (KUnit) API.
> > + *
> > + * Copyright (C) 2019, Google LLC.
> > + * Author: Brendan Higgins <brendanhiggins@google.com>
> > + */
> > +
> > +#include <linux/sched/debug.h>
> > +#include <kunit/test.h>
> > +
> > +static bool kunit_get_success(struct kunit *test)
> > +{
> > + unsigned long flags;
> > + bool success;
> > +
> > + spin_lock_irqsave(&test->lock, flags);
> > + success = test->success;
> > + spin_unlock_irqrestore(&test->lock, flags);
>
> I still don't understand the locking scheme in this code. Is the
> intention to make getter and setter APIs that are "safe" by adding in a
> spinlock that is held around getting and setting various members in the
> kunit structure?
Yes, your understanding is correct. It is possible for a user to write
a test such that certain elements may be updated in different threads;
this would most likely happen in the case where someone wants to make
an assertion or an expectation in a thread created by a piece of code
under test. Although this should generally be avoided, it is possible,
and there are occasionally good reasons to do so, so it is
functionality that we should support.
Do you think I should add a comment to this effect?
> In what situation is there more than one thread reading or writing the
> kunit struct? Isn't it only a single process that is going to be
As I said above, it is possible that the code under test may spawn a
new thread that may make an expectation or an assertion. It is not a
super common use case, but it is possible.
> operating on this structure? And why do we need to disable irqs? Are we
> expecting to be modifying the unit tests from irq contexts?
There are instances where someone may want to test a driver which has
an interrupt handler in it. I actually have (not the greatest) example
here. Now in these cases, I expect someone to use a mock irqchip or
some other fake mechanism to trigger the interrupt handler and not
actual hardware; technically speaking in this case, it is not going to
be accessed from a "real" irq context; however, the code under test
should think that it is in an irq context; given that, I figured it is
best to just treat it as a real irq context. Does that make sense?
> > +
> > + return success;
> > +}
> > +
> > +static void kunit_set_success(struct kunit *test, bool success)
> > +{
> > + unsigned long flags;
> > +
> > + spin_lock_irqsave(&test->lock, flags);
> > + test->success = success;
> > + spin_unlock_irqrestore(&test->lock, flags);
> > +}
> > +
> > +static int kunit_vprintk_emit(int level, const char *fmt, va_list args)
> > +{
> > + return vprintk_emit(0, level, NULL, 0, fmt, args);
> > +}
> > +
> > +static int kunit_printk_emit(int level, const char *fmt, ...)
> > +{
> > + va_list args;
> > + int ret;
> > +
> > + va_start(args, fmt);
> > + ret = kunit_vprintk_emit(level, fmt, args);
> > + va_end(args);
> > +
> > + return ret;
> > +}
> > +
> > +static void kunit_vprintk(const struct kunit *test,
> > + const char *level,
> > + struct va_format *vaf)
> > +{
> > + kunit_printk_emit(level[1] - '0', "\t# %s: %pV", test->name, vaf);
> > +}
> > +
> > +static bool kunit_has_printed_tap_version;
>
> Can you please move this into function local scope in the function
> below?
Sure, that makes sense.
> > +
> > +static void kunit_print_tap_version(void)
> > +{
> > + if (!kunit_has_printed_tap_version) {
> > + kunit_printk_emit(LOGLEVEL_INFO, "TAP version 14\n");
> > + kunit_has_printed_tap_version = true;
> > + }
> > +}
> > +
> [...]
> > +
> > +static bool kunit_module_has_succeeded(struct kunit_module *module)
> > +{
> > + const struct kunit_case *test_case;
> > + bool success = true;
> > +
> > + for (test_case = module->test_cases; test_case->run_case; test_case++)
> > + if (!test_case->success) {
> > + success = false;
> > + break;
>
> Why not 'return false'?
Also a good point. Will fix.
> > + }
> > +
> > + return success;
>
> And 'return true'?
Will fix.
> > +}
> > +
> > +static size_t kunit_module_counter = 1;
> > +
> > +static void kunit_print_subtest_end(struct kunit_module *module)
> > +{
> > + kunit_print_ok_not_ok(false,
> > + kunit_module_has_succeeded(module),
> > + kunit_module_counter++,
> > + module->name);
> > +}
> > +
> > +static void kunit_print_test_case_ok_not_ok(struct kunit_case *test_case,
> > + size_t test_number)
> > +{
> > + kunit_print_ok_not_ok(true,
> > + test_case->success,
> > + test_number,
> > + test_case->name);
> > +}
> > +
> > +void kunit_init_test(struct kunit *test, const char *name)
> > +{
> > + spin_lock_init(&test->lock);
> > + test->name = name;
> > + test->success = true;
> > +}
> > +
> > +/*
> > + * Performs all logic to run a test case.
> > + */
> > +static void kunit_run_case(struct kunit_module *module,
> > + struct kunit_case *test_case)
> > +{
> > + struct kunit test;
> > + int ret = 0;
> > +
> > + kunit_init_test(&test, test_case->name);
> > +
> > + if (module->init) {
> > + ret = module->init(&test);
> > + if (ret) {
> > + kunit_err(&test, "failed to initialize: %d\n", ret);
> > + kunit_set_success(&test, false);
> > + return;
> > + }
> > + }
> > +
> > + if (!ret)
> > + test_case->run_case(&test);
>
> Do we need this if condition? ret can only be set to non-zero above but
> then we'll exit the function early so it seems unnecessary. Given that,
> ret should probably be moved into the module->init path.
Whoops. Sorry, another instance of how it evolved over time and I
forgot why I did the check. Will fix.
> > +
> > + if (module->exit)
> > + module->exit(&test);
> > +
> > + test_case->success = kunit_get_success(&test);
> > +}
> > +
Thanks!
^ permalink raw reply
* Re: [PATCH] scsi: convert to rst for documenation
From: Jonathan Corbet @ 2019-06-25 21:36 UTC (permalink / raw)
To: Phong Tran
Cc: skhan, martin.petersen, axboe, avri.altman, beanhuo, evgreen,
henrik, jpittman, linux-doc, linux-kernel, linux-kernel-mentees,
linux-scsi
In-Reply-To: <20190622151947.29115-1-tranmanphong@gmail.com>
On Sat, 22 Jun 2019 22:19:47 +0700
Phong Tran <tranmanphong@gmail.com> wrote:
> - Update to the link in documenation
> - Remove trailing white space
> - Adaptation the sphinx doc syntax
>
> Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Thanks for working to improve the documentation! That said, I think this
patch needs a fair amount of work before we are ready to accept it. I'll
only get partway in, but it should be enough to start with.
The first overall thing I would like to point out (and hopefully the SCSI
folks won't fight me too much on this) is that Documentation/scsi is the
wrong place for much of this stuff. We are doing our best to organize the
documentation with the audience in mind. So, for example, documents that
are of interest to system administrators should go into
Documentation/admin-guide. Information for driver developers should go in
Documentation/driver-api. And so on.
[...]
> diff --git a/Documentation/scsi/link_power_management_policy.rst b/Documentation/scsi/link_power_management_policy.rst
> new file mode 100644
> index 000000000000..170f58c94cac
> --- /dev/null
> +++ b/Documentation/scsi/link_power_management_policy.rst
> @@ -0,0 +1,22 @@
> +SCSI Power Management Policy
> +============================
> +
> +This parameter allows the user to set the link (interface) power management.
> +There are 3 possible options:
This isn't your fault, but...*which* parameter allows this? The document
describes the values, but not where they can be set. That makes it less
than fully useful.
> ++-------------------+------------------------------------------------------+
> +| Value | Effect |
> ++===================+======================================================+
> +| min_power | Tell the controller to try to make the link use the |
> +| | least possible power when possible. This may |
> +| | sacrifice some performance due to increased latency |
> +| | when coming out of lower power states. |
> ++-------------------+------------------------------------------------------+
> +| max_performance | Generally, this means no power management. Tell |
> +| | the controller to have performance be a priority |
> +| | over power management. |
> ++-------------------+------------------------------------------------------+
> +| medium_power | Tell the controller to enter a lower power state |
> +| | when possible, but do not enter the lowest power |
> +| | state, thus improving latency over min_power setting.|
> ++-------------------+------------------------------------------------------+
[...]
> diff --git a/Documentation/scsi/scsi-changer.txt b/Documentation/scsi/scsi-changer.rst
> similarity index 71%
> rename from Documentation/scsi/scsi-changer.txt
> rename to Documentation/scsi/scsi-changer.rst
> index ade046ea7c17..a4923873c77b 100644
> --- a/Documentation/scsi/scsi-changer.txt
> +++ b/Documentation/scsi/scsi-changer.rst
> @@ -1,4 +1,3 @@
> -
> README for the SCSI media changer driver
> ========================================
>
> @@ -10,7 +9,7 @@ common small CD-ROM changers, neither one-lun-per-slot SCSI changers
> nor IDE drives.
>
> Userland tools available from here:
> - http://linux.bytesex.org/misc/changer.html
> + http://linux.bytesex.org/misc/changer.html
>
>
> General Information
> @@ -28,15 +27,17 @@ The SCSI changer model is complex, compared to - for example - IDE-CD
> changers. But it allows to handle nearly all possible cases. It knows
> 4 different types of changer elements:
>
> +::
Two notes:
- You can put the double colon on the line above ("...elements::") and
don't need to make a separate line for it.
- But, more to the point, please avoid the temptation to use a literal
block for something that doesn't actually require that treatment. This
should be reworked as an RST definition list.
> media transport - this one shuffles around the media, i.e. the
> transport arm. Also known as "picker".
> storage - a slot which can hold a media.
> import/export - the same as above, but is accessible from outside,
> i.e. there the operator (you !) can use this to
> fill in and remove media from the changer.
> - Sometimes named "mailslot".
> + Sometimes named "mailslot".
> data transfer - this is the device which reads/writes, i.e. the
> - CD-ROM / Tape / whatever drive.
> + CD-ROM / Tape / whatever drive.
[...]
> diff --git a/Documentation/scsi/scsi-generic.txt b/Documentation/scsi/scsi-generic.rst
> similarity index 70%
> rename from Documentation/scsi/scsi-generic.txt
> rename to Documentation/scsi/scsi-generic.rst
> index 51be20a6a14d..8356810160f0 100644
> --- a/Documentation/scsi/scsi-generic.txt
> +++ b/Documentation/scsi/scsi-generic.rst
> @@ -1,8 +1,10 @@
> - Notes on Linux SCSI Generic (sg) driver
> - ---------------------------------------
> - 20020126
> +=======================================
> +Notes on Linux SCSI Generic (sg) driver
> +=======================================
> +20020126
> +
> Introduction
> -============
> +------------
> The SCSI Generic driver (sg) is one of the four "high level" SCSI device
> drivers along with sd, st and sr (disk, tape and CDROM respectively). Sg
> is more generalized (but lower level) than its siblings and tends to be
> @@ -16,20 +18,20 @@ and examples.
>
>
> Major versions of the sg driver
> -===============================
> +-------------------------------
> There are three major versions of sg found in the linux kernel (lk):
> - - sg version 1 (original) from 1992 to early 1999 (lk 2.2.5) .
> - It is based in the sg_header interface structure.
> + - sg version 1 (original) from 1992 to early 1999 (lk 2.2.5) .
> + It is based in the sg_header interface structure.
> - sg version 2 from lk 2.2.6 in the 2.2 series. It is based on
> - an extended version of the sg_header interface structure.
> + an extended version of the sg_header interface structure.
> - sg version 3 found in the lk 2.4 series (and the lk 2.5 series).
> - It adds the sg_io_hdr interface structure.
> + It adds the sg_io_hdr interface structure.
Perhaps we don't *really* need to preserve information about what versions
were around in the 1990's?
> Sg driver documentation
> -=======================
> +-----------------------
> The most recent documentation of the sg driver is kept at the Linux
> -Documentation Project's (LDP) site:
> +Documentation Project's (LDP) site:
> http://www.tldp.org/HOWTO/SCSI-Generic-HOWTO
That document claims to have been last updated in 2002. Is there really
nothing more recent than that?
> This describes the sg version 3 driver found in the lk 2.4 series.
...and it's unclear to me that users of the 5.x kernel are much concerned
with what was found in 2.4.
That is the problem with this document in general. I suspect that about
the only useful information left in it is the location of the sg3_utils
source. I honestly don't think that it helps the documentation that much
to carry forward ancient information to the RST format.
Of course, doing this right by deleting obsolete information and updating
the documents to reflect current reality is a *lot* more work. Probably
far more than you were thinking of signing up for. If you were willing to
work on this, there may be somebody from the SCSI community who would be in
a position to help you with it.
Unfortunately, the SCSI community probably did not see this patch because
you didn't copy the linux-scsi list. I'll fix that now, but they will not
have seen your original patch. You should be sure to include them on
future postings.
I would like to make a suggestion, in addition to all of the above: rather
than trying to do a mass conversion in a single 4000-line patch, start with
a single file and post a patch doing just that one, being sure to include
the linux-scsi list. That will give everybody something more workable to
start with.
Thanks,
jon
^ permalink raw reply
* Re: [PATCH v5 01/18] kunit: test: add KUnit test runner core
From: Luis Chamberlain @ 2019-06-25 21:44 UTC (permalink / raw)
To: Brendan Higgins
Cc: Stephen Boyd, Frank Rowand, Greg KH, Josh Poimboeuf, Kees Cook,
Kieran Bingham, Peter Zijlstra, Rob Herring, shuah,
Theodore Ts'o, Masahiro Yamada, devicetree, dri-devel,
kunit-dev, open list:DOCUMENTATION, linux-fsdevel, linux-kbuild,
Linux Kernel Mailing List, open list:KERNEL SELFTEST FRAMEWORK,
linux-nvdimm, linux-um, Sasha Levin, Bird, Timothy,
Amir Goldstein, Dan Carpenter, Daniel Vetter, Jeff Dike,
Joel Stanley, Julia Lawall, Kevin Hilman, Knut Omang,
Logan Gunthorpe, Michael Ellerman, Petr Mladek, Randy Dunlap,
Richard Weinberger, David Rientjes, Steven Rostedt, wfg
In-Reply-To: <CAFd5g46Jhxsz6_VXHEVYvTeDRwwzgKpr=aUWLL5b3S4kUukb8g@mail.gmail.com>
On Tue, Jun 25, 2019 at 01:28:25PM -0700, Brendan Higgins wrote:
> On Wed, Jun 19, 2019 at 5:15 PM Stephen Boyd <sboyd@kernel.org> wrote:
> >
> > Quoting Brendan Higgins (2019-06-17 01:25:56)
> > > diff --git a/kunit/test.c b/kunit/test.c
> > > new file mode 100644
> > > index 0000000000000..d05d254f1521f
> > > --- /dev/null
> > > +++ b/kunit/test.c
> > > @@ -0,0 +1,210 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * Base unit test (KUnit) API.
> > > + *
> > > + * Copyright (C) 2019, Google LLC.
> > > + * Author: Brendan Higgins <brendanhiggins@google.com>
> > > + */
> > > +
> > > +#include <linux/sched/debug.h>
> > > +#include <kunit/test.h>
> > > +
> > > +static bool kunit_get_success(struct kunit *test)
> > > +{
> > > + unsigned long flags;
> > > + bool success;
> > > +
> > > + spin_lock_irqsave(&test->lock, flags);
> > > + success = test->success;
> > > + spin_unlock_irqrestore(&test->lock, flags);
> >
> > I still don't understand the locking scheme in this code. Is the
> > intention to make getter and setter APIs that are "safe" by adding in a
> > spinlock that is held around getting and setting various members in the
> > kunit structure?
>
> Yes, your understanding is correct. It is possible for a user to write
> a test such that certain elements may be updated in different threads;
> this would most likely happen in the case where someone wants to make
> an assertion or an expectation in a thread created by a piece of code
> under test. Although this should generally be avoided, it is possible,
> and there are occasionally good reasons to do so, so it is
> functionality that we should support.
>
> Do you think I should add a comment to this effect?
>
> > In what situation is there more than one thread reading or writing the
> > kunit struct? Isn't it only a single process that is going to be
>
> As I said above, it is possible that the code under test may spawn a
> new thread that may make an expectation or an assertion. It is not a
> super common use case, but it is possible.
I wonder if it is worth to have then different types of tests based on
locking requirements. One with no locking, since it seems you imply
most tests would fall under this category, then locking, and another
with IRQ context.
If no locking is done at all for all tests which do not require locking,
is there any gains at run time? I'm sure it might be minimum but
curious.
> > operating on this structure? And why do we need to disable irqs? Are we
> > expecting to be modifying the unit tests from irq contexts?
>
> There are instances where someone may want to test a driver which has
> an interrupt handler in it. I actually have (not the greatest) example
> here. Now in these cases, I expect someone to use a mock irqchip or
> some other fake mechanism to trigger the interrupt handler and not
> actual hardware; technically speaking in this case, it is not going to
> be accessed from a "real" irq context; however, the code under test
> should think that it is in an irq context; given that, I figured it is
> best to just treat it as a real irq context. Does that make sense?
Since its a new architecture and since you seem to imply most tests
don't require locking or even IRQs disabled, I think its worth to
consider the impact of adding such extreme locking requirements for
an initial ramp up.
Luis
^ permalink raw reply
* Re: [PATCH v13 05/13] clk: ingenic: Add driver for the TCU clocks
From: Stephen Boyd @ 2019-06-25 22:09 UTC (permalink / raw)
To: Daniel Lezcano, James Hogan, Jason Cooper, Jonathan Corbet,
Lee Jones, Marc Zyngier, Michael Turquette, Paul Burton,
Paul Cercueil, Ralf Baechle, Thomas Gleixner
Cc: Mathieu Malaterre, od, devicetree, linux-kernel, linux-mips,
linux-doc, linux-clk, Paul Cercueil, Artur Rojek
In-Reply-To: <20190624225759.18299-6-paul@crapouillou.net>
Quoting Paul Cercueil (2019-06-24 15:57:51)
> diff --git a/drivers/clk/ingenic/tcu.c b/drivers/clk/ingenic/tcu.c
> new file mode 100644
> index 000000000000..6d667c4a2bd5
> --- /dev/null
> +++ b/drivers/clk/ingenic/tcu.c
> @@ -0,0 +1,473 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * JZ47xx SoCs TCU clocks driver
> + * Copyright (C) 2019 Paul Cercueil <paul@crapouillou.net>
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/clk-provider.h>
> +#include <linux/clockchips.h>
> +#include <linux/mfd/ingenic-tcu.h>
> +#include <linux/regmap.h>
> +#include <linux/slab.h>
> +#include <linux/syscore_ops.h>
> +
> +#include <dt-bindings/clock/ingenic,tcu.h>
> +
[...]
> +
> +static const struct ingenic_soc_info jz4740_soc_info = {
> + .num_channels = 8,
> + .has_ost = false,
> + .has_tcu_clk = true,
> +};
> +
> +static const struct ingenic_soc_info jz4725b_soc_info = {
> + .num_channels = 6,
> + .has_ost = true,
> + .has_tcu_clk = true,
> +};
> +
> +static const struct ingenic_soc_info jz4770_soc_info = {
> + .num_channels = 8,
> + .has_ost = true,
> + .has_tcu_clk = false,
> +};
> +
> +static const struct of_device_id ingenic_tcu_of_match[] __initconst = {
> + { .compatible = "ingenic,jz4740-tcu", .data = &jz4740_soc_info, },
> + { .compatible = "ingenic,jz4725b-tcu", .data = &jz4725b_soc_info, },
> + { .compatible = "ingenic,jz4770-tcu", .data = &jz4770_soc_info, },
> + { }
> +};
> +
> +static int __init ingenic_tcu_probe(struct device_node *np)
> +{
> + const struct of_device_id *id = of_match_node(ingenic_tcu_of_match, np);
> + struct ingenic_tcu *tcu;
> + struct regmap *map;
> + unsigned int i;
> + int ret;
> +
> + map = ingenic_tcu_get_regmap(np);
> + if (IS_ERR(map))
> + return PTR_ERR(map);
> +
> + tcu = kzalloc(sizeof(*tcu), GFP_KERNEL);
> + if (!tcu)
> + return -ENOMEM;
> +
> + tcu->map = map;
> + tcu->soc_info = id->data;
> +
> + if (tcu->soc_info->has_tcu_clk) {
> + tcu->clk = of_clk_get_by_name(np, "tcu");
Do you need to get the clk by name? Or can that clk be "known" to the
TCU somehow so we can already have a direct clk pointer?
> + if (IS_ERR(tcu->clk)) {
> + ret = PTR_ERR(tcu->clk);
> + pr_crit("Cannot get TCU clock\n");
> + goto err_free_tcu;
> + }
> +
> + ret = clk_prepare_enable(tcu->clk);
> + if (ret) {
> + pr_crit("Unable to enable TCU clock\n");
> + goto err_put_clk;
> + }
> + }
> +
> + tcu->clocks = kzalloc(sizeof(*tcu->clocks) +
> + sizeof(*tcu->clocks->hws) * TCU_CLK_COUNT,
> + GFP_KERNEL);
> + if (!tcu->clocks) {
> + ret = -ENOMEM;
> + goto err_clk_disable;
> + }
> +
> + tcu->clocks->num = TCU_CLK_COUNT;
> +
> + for (i = 0; i < tcu->soc_info->num_channels; i++) {
> + ret = ingenic_tcu_register_clock(tcu, i, TCU_PARENT_EXT,
> + &ingenic_tcu_clk_info[i],
> + tcu->clocks);
> + if (ret) {
> + pr_crit("cannot register clock %i\n", i);
> + goto err_unregister_timer_clocks;
> + }
> + }
> +
> + /*
> + * We set EXT as the default parent clock for all the TCU clocks
> + * except for the watchdog one, where we set the RTC clock as the
> + * parent. Since the EXT and PCLK are much faster than the RTC clock,
> + * the watchdog would kick after a maximum time of 5s, and we might
> + * want a slower kicking time.
> + */
> + ret = ingenic_tcu_register_clock(tcu, TCU_CLK_WDT, TCU_PARENT_RTC,
> + &ingenic_tcu_watchdog_clk_info,
> + tcu->clocks);
> + if (ret) {
> + pr_crit("cannot register watchdog clock\n");
> + goto err_unregister_timer_clocks;
> + }
> +
> + if (tcu->soc_info->has_ost) {
> + ret = ingenic_tcu_register_clock(tcu, TCU_CLK_OST,
> + TCU_PARENT_EXT,
> + &ingenic_tcu_ost_clk_info,
> + tcu->clocks);
> + if (ret) {
> + pr_crit("cannot register ost clock\n");
> + goto err_unregister_watchdog_clock;
> + }
> + }
> +
> + ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, tcu->clocks);
> + if (ret) {
> + pr_crit("cannot add OF clock provider\n");
> + goto err_unregister_ost_clock;
> + }
> +
> + ingenic_tcu = tcu;
> +
> + return 0;
> +
> +err_unregister_ost_clock:
> + if (tcu->soc_info->has_ost)
> + clk_hw_unregister(tcu->clocks->hws[i + 1]);
> +err_unregister_watchdog_clock:
> + clk_hw_unregister(tcu->clocks->hws[i]);
> +err_unregister_timer_clocks:
> + for (i = 0; i < tcu->clocks->num; i++)
> + if (tcu->clocks->hws[i])
> + clk_hw_unregister(tcu->clocks->hws[i]);
> + kfree(tcu->clocks);
> +err_clk_disable:
> + if (tcu->soc_info->has_tcu_clk)
> + clk_disable_unprepare(tcu->clk);
> +err_put_clk:
> + if (tcu->soc_info->has_tcu_clk)
> + clk_put(tcu->clk);
> +err_free_tcu:
> + kfree(tcu);
> + return ret;
Too bad this isn't a device with devm!
> +}
> +
> +static int __maybe_unused tcu_pm_suspend(void)
> +{
> + struct ingenic_tcu *tcu = ingenic_tcu;
> +
> + if (tcu->clk)
> + clk_disable(tcu->clk);
Do you need to unprepare? Or it just isn't possible because this is
called from syscore and thus we can't sleep?
> +
> + return 0;
> +}
> +
> +static void __maybe_unused tcu_pm_resume(void)
> +{
> + struct ingenic_tcu *tcu = ingenic_tcu;
> +
> + if (tcu->clk)
> + clk_enable(tcu->clk);
> +}
> +
> +static struct syscore_ops __maybe_unused tcu_pm_ops = {
> + .suspend = tcu_pm_suspend,
> + .resume = tcu_pm_resume,
> +};
> +
> +static void __init ingenic_tcu_init(struct device_node *np)
> +{
> + int ret = ingenic_tcu_probe(np);
> +
> + if (ret)
> + pr_crit("Failed to initialize TCU clocks: %i\n", ret);
Should be %d instead of %i? Applies to all this file.
> +
> + if (IS_ENABLED(CONFIG_PM_SLEEP))
> + register_syscore_ops(&tcu_pm_ops);
> +}
^ permalink raw reply
* Re: [PATCH v5 06/18] kbuild: enable building KUnit
From: Luis Chamberlain @ 2019-06-25 22:13 UTC (permalink / raw)
To: Brendan Higgins
Cc: frowand.list, gregkh, jpoimboe, keescook, kieran.bingham, peterz,
robh, sboyd, shuah, tytso, yamada.masahiro, devicetree, dri-devel,
kunit-dev, linux-doc, linux-fsdevel, linux-kbuild, linux-kernel,
linux-kselftest, linux-nvdimm, linux-um, Alexander.Levin,
Tim.Bird, amir73il, dan.carpenter, daniel, jdike, joel,
julia.lawall, khilman, knut.omang, logang, mpe, pmladek, rdunlap,
richard, rientjes, rostedt, wfg
In-Reply-To: <20190617082613.109131-7-brendanhiggins@google.com>
On Mon, Jun 17, 2019 at 01:26:01AM -0700, Brendan Higgins wrote:
> diff --git a/Kconfig b/Kconfig
> index 48a80beab6853..10428501edb78 100644
> --- a/Kconfig
> +++ b/Kconfig
> @@ -30,3 +30,5 @@ source "crypto/Kconfig"
> source "lib/Kconfig"
>
> source "lib/Kconfig.debug"
> +
> +source "kunit/Kconfig"
This patch would break compilation as kunit/Kconfig is not introduced. This
would would also break bisectability on this commit. This change should
either be folded in to the next patch, or just be a separate patch after
the next one.
Luis
^ permalink raw reply
* Re: [PATCH v5 01/18] kunit: test: add KUnit test runner core
From: Brendan Higgins @ 2019-06-25 22:14 UTC (permalink / raw)
To: Luis Chamberlain
Cc: Stephen Boyd, Frank Rowand, Greg KH, Josh Poimboeuf, Kees Cook,
Kieran Bingham, Peter Zijlstra, Rob Herring, shuah,
Theodore Ts'o, Masahiro Yamada, devicetree, dri-devel,
kunit-dev, open list:DOCUMENTATION, linux-fsdevel, linux-kbuild,
Linux Kernel Mailing List, open list:KERNEL SELFTEST FRAMEWORK,
linux-nvdimm, linux-um, Sasha Levin, Bird, Timothy,
Amir Goldstein, Dan Carpenter, Daniel Vetter, Jeff Dike,
Joel Stanley, Julia Lawall, Kevin Hilman, Knut Omang,
Logan Gunthorpe, Michael Ellerman, Petr Mladek, Randy Dunlap,
Richard Weinberger, David Rientjes, Steven Rostedt, wfg
In-Reply-To: <20190625214427.GN19023@42.do-not-panic.com>
On Tue, Jun 25, 2019 at 2:44 PM Luis Chamberlain <mcgrof@kernel.org> wrote:
>
> On Tue, Jun 25, 2019 at 01:28:25PM -0700, Brendan Higgins wrote:
> > On Wed, Jun 19, 2019 at 5:15 PM Stephen Boyd <sboyd@kernel.org> wrote:
> > >
> > > Quoting Brendan Higgins (2019-06-17 01:25:56)
> > > > diff --git a/kunit/test.c b/kunit/test.c
> > > > new file mode 100644
> > > > index 0000000000000..d05d254f1521f
> > > > --- /dev/null
> > > > +++ b/kunit/test.c
> > > > @@ -0,0 +1,210 @@
> > > > +// SPDX-License-Identifier: GPL-2.0
> > > > +/*
> > > > + * Base unit test (KUnit) API.
> > > > + *
> > > > + * Copyright (C) 2019, Google LLC.
> > > > + * Author: Brendan Higgins <brendanhiggins@google.com>
> > > > + */
> > > > +
> > > > +#include <linux/sched/debug.h>
> > > > +#include <kunit/test.h>
> > > > +
> > > > +static bool kunit_get_success(struct kunit *test)
> > > > +{
> > > > + unsigned long flags;
> > > > + bool success;
> > > > +
> > > > + spin_lock_irqsave(&test->lock, flags);
> > > > + success = test->success;
> > > > + spin_unlock_irqrestore(&test->lock, flags);
> > >
> > > I still don't understand the locking scheme in this code. Is the
> > > intention to make getter and setter APIs that are "safe" by adding in a
> > > spinlock that is held around getting and setting various members in the
> > > kunit structure?
> >
> > Yes, your understanding is correct. It is possible for a user to write
> > a test such that certain elements may be updated in different threads;
> > this would most likely happen in the case where someone wants to make
> > an assertion or an expectation in a thread created by a piece of code
> > under test. Although this should generally be avoided, it is possible,
> > and there are occasionally good reasons to do so, so it is
> > functionality that we should support.
> >
> > Do you think I should add a comment to this effect?
> >
> > > In what situation is there more than one thread reading or writing the
> > > kunit struct? Isn't it only a single process that is going to be
> >
> > As I said above, it is possible that the code under test may spawn a
> > new thread that may make an expectation or an assertion. It is not a
> > super common use case, but it is possible.
>
> I wonder if it is worth to have then different types of tests based on
> locking requirements. One with no locking, since it seems you imply
> most tests would fall under this category, then locking, and another
> with IRQ context.
>
> If no locking is done at all for all tests which do not require locking,
> is there any gains at run time? I'm sure it might be minimum but
> curious.
Yeah, I don't think it is worth it.
I don't think we need to be squeezing every ounce of performance out
of unit tests, since they are inherently a cost and are not intended
to be run in a production deployed kernel as part of normal production
usage.
> > > operating on this structure? And why do we need to disable irqs? Are we
> > > expecting to be modifying the unit tests from irq contexts?
> >
> > There are instances where someone may want to test a driver which has
> > an interrupt handler in it. I actually have (not the greatest) example
> > here. Now in these cases, I expect someone to use a mock irqchip or
> > some other fake mechanism to trigger the interrupt handler and not
> > actual hardware; technically speaking in this case, it is not going to
> > be accessed from a "real" irq context; however, the code under test
> > should think that it is in an irq context; given that, I figured it is
> > best to just treat it as a real irq context. Does that make sense?
>
> Since its a new architecture and since you seem to imply most tests
> don't require locking or even IRQs disabled, I think its worth to
> consider the impact of adding such extreme locking requirements for
> an initial ramp up.
Fair enough, I can see the point of not wanting to use irq disabled
until we get someone complaining about it, but I think making it
thread safe is reasonable. It means there is one less thing to confuse
a KUnit user and the only penalty paid is some very minor performance.
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox