Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v4 1/2] ACPI/PPTT: Add support for ACPI 6.3 thread flag
From: Will Deacon @ 2019-08-12 11:59 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: lorenzo.pieralisi@arm.com, rric@kernel.org,
	catalin.marinas@arm.com, rjw@rjwysocki.net, Jeremy Linton,
	linux-acpi@vger.kernel.org, Robert Richter, sudeep.holla@arm.com,
	linux-arm-kernel@lists.infradead.org, lenb@kernel.org
In-Reply-To: <CAJZ5v0imn0X=M38LJcwe76gfLafWGU+MgyGd=NuKAeDtNZ+1DQ@mail.gmail.com>

On Mon, Aug 12, 2019 at 11:06:07AM +0200, Rafael J. Wysocki wrote:
> On Fri, Aug 9, 2019 at 12:25 AM Robert Richter <rrichter@marvell.com> wrote:
> >
> > On 08.08.19 15:40:06, Jeremy Linton wrote:
> > > ACPI 6.3 adds a flag to the CPU node to indicate whether
> > > the given PE is a thread. Add a function to return that
> > > information for a given linux logical CPU.
> > >
> > > Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
> > > Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
> > > ---
> > >  drivers/acpi/pptt.c  | 53 +++++++++++++++++++++++++++++++++++++++++++-
> > >  include/linux/acpi.h |  5 +++++
> > >  2 files changed, 57 insertions(+), 1 deletion(-)
> >
> > Reviewed-by: Robert Richter <rrichter@marvell.com>
> 
> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> and please push it through ARM64 along with the second patch.

Thanks. I'll push these into -next shortly.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: [PATCH v3 2/2] drivers/perf: Add CCPI2 PMU support in ThunderX2 UNCORE driver.
From: Mark Rutland @ 2019-08-12 12:01 UTC (permalink / raw)
  To: Ganapatrao Kulkarni
  Cc: corbet@lwn.net, Jan Glauber, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, Robert Richter, gklkml16@gmail.com,
	Jayachandran Chandrasekharan Nair, will@kernel.org,
	linux-arm-kernel@lists.infradead.org
In-Reply-To: <1563873380-2003-3-git-send-email-gkulkarni@marvell.com>

On Tue, Jul 23, 2019 at 09:16:28AM +0000, Ganapatrao Kulkarni wrote:
> CCPI2 is a low-latency high-bandwidth serial interface for connecting
> ThunderX2 processors. This patch adds support to capture CCPI2 perf events.

It would be worth pointing out in the commit message how the CCPI2
counters differ from the others. I realise you have that in the body of
patch 1, but it's critical information when reviewing this patch...

> 
> Signed-off-by: Ganapatrao Kulkarni <gkulkarni@marvell.com>
> ---
>  drivers/perf/thunderx2_pmu.c | 248 ++++++++++++++++++++++++++++++-----
>  1 file changed, 214 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c
> index 43d76c85da56..a4e1273eafa3 100644
> --- a/drivers/perf/thunderx2_pmu.c
> +++ b/drivers/perf/thunderx2_pmu.c
> @@ -17,22 +17,31 @@
>   */
>  
>  #define TX2_PMU_MAX_COUNTERS		4

Shouldn't this be 8 now?

[...]

>  /*
> - * pmu on each socket has 2 uncore devices(dmc and l3c),
> - * each device has 4 counters.
> + * pmu on each socket has 3 uncore devices(dmc, l3ci and ccpi2),
> + * dmc and l3c has 4 counters and ccpi2 8.
>   */

How about:

/*
 * Each socket has 3 uncore device associated with a PMU. The DMC and
 * L3C have 4 32-bit counters, and the CCPI2 has 8 64-bit counters.
 */

>  struct tx2_uncore_pmu {
>  	struct hlist_node hpnode;
> @@ -69,12 +86,14 @@ struct tx2_uncore_pmu {
>  	int node;
>  	int cpu;
>  	u32 max_counters;
> +	u32 counters_mask;
>  	u32 prorate_factor;
>  	u32 max_events;
> +	u32 events_mask;
>  	u64 hrtimer_interval;
>  	void __iomem *base;
>  	DECLARE_BITMAP(active_counters, TX2_PMU_MAX_COUNTERS);

This bitmap isn't big enough for the 4 new counters.

> -	struct perf_event *events[TX2_PMU_MAX_COUNTERS];
> +	struct perf_event **events;

As above, can't we bump TX2_PMU_MAX_COUNTERS to 8 rather than making
this a dynamic allocation?

[...]

>  static inline u32 reg_readl(unsigned long addr)
>  {
>  	return readl((void __iomem *)addr);
>  }
>  
> +static inline u32 reg_readq(unsigned long addr)
> +{
> +	return readq((void __iomem *)addr);
> +}

Presumably reg_readq() should return a u64.

[...]

> +static void uncore_start_event_ccpi2(struct perf_event *event, int flags)
> +{
> +	u32 emask;
> +	struct hw_perf_event *hwc = &event->hw;
> +	struct tx2_uncore_pmu *tx2_pmu;
> +
> +	tx2_pmu = pmu_to_tx2_pmu(event->pmu);
> +	emask = tx2_pmu->events_mask;
> +
> +	/* Bit [09:00] to set event id, set level and type to 1 */
> +	reg_writel((3 << 10) |

Do you mean that bits [11:10] are level and type?

What exactly are 'level' and 'type'?

Can we give those bits mnemonics?

> +			GET_EVENTID(event, emask), hwc->config_base);
> +	/* reset[4], enable[0] and start[1] counters */

Rather than using magic numbers everywhere, please give these mnemonics,
e.g.

#define CCPI2_PERF_CTL_ENABLE	BIT(0)
#define CCPI2_PERF_CTL_START	BIT(1)
#define CCPI2_PERF_CTL_RESET	BIT(4)

> +	reg_writel(0x13, hwc->event_base + CCPI2_PERF_CTL);

... and then you can OR them in here:

	ctl = CCPI2_PERF_CTL_ENABLE |
	      CCPI2_PERF_CTL_START |
	      CCPI2_PERF_CTL_RESET;
	reg_writel(ctl, hwc->event_base + CCPI2_PERF_CTL);

[...]

> @@ -456,8 +603,9 @@ static void tx2_uncore_event_start(struct perf_event *event, int flags)
>  	tx2_pmu->start_event(event, flags);
>  	perf_event_update_userpage(event);
>  
> -	/* Start timer for first event */
> -	if (bitmap_weight(tx2_pmu->active_counters,
> +	/* Start timer for first non ccpi2 event */
> +	if (tx2_pmu->type != PMU_TYPE_CCPI2 &&
> +			bitmap_weight(tx2_pmu->active_counters,
>  				tx2_pmu->max_counters) == 1) {
>  		hrtimer_start(&tx2_pmu->hrtimer,
>  			ns_to_ktime(tx2_pmu->hrtimer_interval),

This would be easier to read as two statements:

	/* No hrtimer needed with 64-bit counters */
	if (tx2_pmu->type == PMU_TYPE_CCPI2)
		return;
	
	/* Start timer for first event */
	if (bitmap_weight(tx2_pmu->active_counters,
	    tx2_pmu->max_counters) != 1) {
	    	...
	}

> @@ -495,7 +643,8 @@ static int tx2_uncore_event_add(struct perf_event *event, int flags)
>  	if (hwc->idx < 0)
>  		return -EAGAIN;
>  
> -	tx2_pmu->events[hwc->idx] = event;
> +	if (tx2_pmu->events)
> +		tx2_pmu->events[hwc->idx] = event;

So this is NULL for CCPI2?

I guess we don't strictly need the if we don't have a hrtimer to update
event counts, but this makes the code more complicated than it needs to
be.

[...]

> @@ -580,8 +732,12 @@ static int tx2_uncore_pmu_add_dev(struct tx2_uncore_pmu *tx2_pmu)
>  			cpu_online_mask);
>  
>  	tx2_pmu->cpu = cpu;
> -	hrtimer_init(&tx2_pmu->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
> -	tx2_pmu->hrtimer.function = tx2_hrtimer_callback;
> +	/* CCPI2 counters are 64 bit counters, no overflow  */
> +	if (tx2_pmu->type != PMU_TYPE_CCPI2) {
> +		hrtimer_init(&tx2_pmu->hrtimer,
> +				CLOCK_MONOTONIC, HRTIMER_MODE_REL);
> +		tx2_pmu->hrtimer.function = tx2_hrtimer_callback;
> +	}

Hmmm... this means that tx2_pmu->hrtimer.function is NULL for the CCPI2
PMU. I think it would be best to check that when (re)programming the
counters rather than the PMU type. For example, in
tx2_uncore_event_start() we could have:

	if (!tx2_pmu->hrtimer.function)
		return;
	if (bitmap_weight(tx2_pmu->active_counters,
	    tx2_pmu->max_counters) != 1) {
	    	...
	}

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: [PATCH v4 0/7] Allwinner H6 SPDIF support
From: Clément Péron @ 2019-08-12 12:10 UTC (permalink / raw)
  To: Mark Brown
  Cc: Mark Rutland, devicetree, Linux-ALSA, Maxime Ripard, linux-kernel,
	linux-sunxi, Takashi Iwai, Liam Girdwood, Chen-Yu Tsai,
	Rob Herring, Jagan Teki, Jaroslav Kysela, linux-arm-kernel
In-Reply-To: <20190812110103.GD4592@sirena.co.uk>

Hi Mark,

On Mon, 12 Aug 2019 at 13:01, Mark Brown <broonie@kernel.org> wrote:
>
> On Sat, Aug 10, 2019 at 10:45:23AM +0200, Clément Péron wrote:
>
> > Hi,
>
> Please don't top post, reply in line with needed context.  This allows
> readers to readily follow the flow of conversation and understand what
> you are talking about and also helps ensure that everything in the
> discussion is being addressed.
>
> > Sorry, I just discovered that the ASoC patches have been merged into
> > the broonie and linus tree in 5.3.
>
> > I'm still quite new in the sending of patches to the Kernel but
> > souldn't be a ack or a mail sent to warn the sender when the series
> > are accepted?
>
> Not every maintainer will send those, I do but you might find they've
> gone into your spam folder if you're using gmail.

Thank you very much for the answer,
Regards,
Clément

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: [PATCH 0/7] media: cedrus: Improvements/cleanup
From: Hans Verkuil @ 2019-08-12 12:12 UTC (permalink / raw)
  To: Jernej Skrabec, paul.kocialkowski, maxime.ripard
  Cc: devel, gregkh, linux-kernel, wens, mchehab, linux-arm-kernel,
	linux-media
In-Reply-To: <20190530211516.1891-1-jernej.skrabec@siol.net>

On 5/30/19 11:15 PM, Jernej Skrabec wrote:
> Here is first batch of random Cedrus improvements/cleanups. Only patch 2
> has a change which raises a question about H264 controls.
> 
> Changes were tested on H3 SoC using modified ffmpeg and Kodi.
> 
> Please take a look.

This has been sitting in patchwork for quite some time. I've updated the
status of the various patches and most needed extra work.

It seems that patches 4/7 and 5/7 are OK. Maxime, can you please confirm
that these two are still valid? They apply cleanly on the latest master
at least, but since they are a bit old I prefer to have confirmation that
it's OK to merge them.

Regards,

	Hans

> 
> Best regards,
> Jernej
> 
> Jernej Skrabec (7):
>   media: cedrus: Disable engine after each slice decoding
>   media: cedrus: Fix H264 default reference index count
>   media: cedrus: Fix decoding for some H264 videos
>   media: cedrus: Remove dst_bufs from context
>   media: cedrus: Don't set chroma size for scale & rotation
>   media: cedrus: Add infra for extra buffers connected to capture
>     buffers
>   media: cedrus: Improve H264 memory efficiency
> 
>  drivers/staging/media/sunxi/cedrus/cedrus.h   |  12 +-
>  .../staging/media/sunxi/cedrus/cedrus_h264.c  | 115 ++++++++----------
>  .../staging/media/sunxi/cedrus/cedrus_hw.c    |   4 +-
>  .../staging/media/sunxi/cedrus/cedrus_video.c |  25 ++--
>  4 files changed, 68 insertions(+), 88 deletions(-)
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* [PATCH v5 00/10] implement poweroff for mt6323 / bpi-r2
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Frank Wunderlich

mainline-driver does not support mt6323

this series makes some cleanup to mt6397-rtc-driver, adds mt6323 and
implement power-controller on it.

tested on bananapi-r2

Original Patch from Josef Friedl

changes since v4:
	- relative path in part 1+2
	- drop change of copyright-year in part 5
changes since v3:
	- moved SOB in 2/10 and 9/10
	- moved part 5 to 6 to be near driver-change
	- changehistory of patches below ---

changes since v2:
	- Splitted some parts and rebased on 5.3-rc2:

	v2.1 dt-bindings: add powercontroller – try to make better subject
	v2.2 separate rtc-mt6397.txt (suggested by Alexandre Belloni)
	     add missing commit-message (suggested by Matthias Brugger)
	v2.3 fix alloc after IRQ (suggested by Alexandre Belloni)
	     new compatible (splitting suggested by Alexandre Belloni)
	     needed due to different rtc-base/size see #7
	v2.4 simplifications (Define-res-macros)
	     add mt6323 rtc+pwrc
	v2.5 add poweroff-driver (no change)
	v2.6 MAINTAINERS (no change)
	v2.7 DTS-Changes (no change)


Josef Friedl (10):
  dt-bindings: add powercontroller
  dt-bindings: add missing mt6397 rtc
  rtc: mt6397: move some common definitions into rtc.h
  rtc: mt6397: improvements of rtc driver
  mfd: mt6323: some improvements of mt6397-core
  rtc: mt6397: add compatible for mt6323
  mfd: mt6323: add mt6323 rtc+pwrc
  power: reset: add driver for mt6323 poweroff
  MAINTAINERS: add Mediatek shutdown drivers
  arm: dts: mt6323: add keys, power-controller, rtc and codec

 .../devicetree/bindings/mfd/mt6397.txt        |  20 +++-
 .../bindings/power/reset/mt6323-poweroff.txt  |  20 ++++
 .../devicetree/bindings/rtc/rtc-mt6397.txt    |  29 +++++
 MAINTAINERS                                   |   7 ++
 arch/arm/boot/dts/mt6323.dtsi                 |  27 +++++
 drivers/mfd/mt6397-core.c                     |  38 +++++--
 drivers/power/reset/Kconfig                   |  10 ++
 drivers/power/reset/Makefile                  |   1 +
 drivers/power/reset/mt6323-poweroff.c         |  97 ++++++++++++++++
 drivers/rtc/rtc-mt6397.c                      | 107 ++++--------------
 include/linux/mfd/mt6397/core.h               |   2 +
 include/linux/mfd/mt6397/rtc.h                |  71 ++++++++++++
 12 files changed, 327 insertions(+), 102 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
 create mode 100644 drivers/power/reset/mt6323-poweroff.c
 create mode 100644 include/linux/mfd/mt6397/rtc.h

-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* [PATCH v5 01/10] dt-bindings: add powercontroller
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

add mt6323-rtc and mt6323-pwrc to mt6397 mfd DT bindings
an example is shown in mt6323-poweroff.txt

Suggested-by: Frank Wunderlich <frank-w@public-files.de>
Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
---
changes since v4: use relative path
changes since v3: none
changes since v2: separated rtc-mt6397.txt to part 2
---
 .../devicetree/bindings/mfd/mt6397.txt        | 20 +++++++++++++------
 .../bindings/power/reset/mt6323-poweroff.txt  | 20 +++++++++++++++++++
 2 files changed, 34 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt

diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt b/Documentation/devicetree/bindings/mfd/mt6397.txt
index 0ebd08af777d..063f5fe1cace 100644
--- a/Documentation/devicetree/bindings/mfd/mt6397.txt
+++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
@@ -8,11 +8,12 @@ MT6397/MT6323 is a multifunction device with the following sub modules:
 - Clock
 - LED
 - Keys
+- Power controller
 
 It is interfaced to host controller using SPI interface by a proprietary hardware
 called PMIC wrapper or pwrap. MT6397/MT6323 MFD is a child device of pwrap.
 See the following for pwarp node definitions:
-Documentation/devicetree/bindings/soc/mediatek/pwrap.txt
+../../bindings/soc/mediatek/pwrap.txt
 
 This document describes the binding for MFD device and its sub module.
 
@@ -22,14 +23,16 @@ compatible: "mediatek,mt6397" or "mediatek,mt6323"
 Optional subnodes:
 
 - rtc
-	Required properties:
+	Required properties: Should be one of follows
+		- compatible: "mediatek,mt6323-rtc"
 		- compatible: "mediatek,mt6397-rtc"
+	For details, see ../../bindings/rtc/rtc-mt6397.txt
 - regulators
 	Required properties:
 		- compatible: "mediatek,mt6397-regulator"
-	see Documentation/devicetree/bindings/regulator/mt6397-regulator.txt
+	see ../../bindings/regulator/mt6397-regulator.txt
 		- compatible: "mediatek,mt6323-regulator"
-	see Documentation/devicetree/bindings/regulator/mt6323-regulator.txt
+	see ../../bindings/regulator/mt6323-regulator.txt
 - codec
 	Required properties:
 		- compatible: "mediatek,mt6397-codec"
@@ -39,12 +42,17 @@ Optional subnodes:
 - led
 	Required properties:
 		- compatible: "mediatek,mt6323-led"
-	see Documentation/devicetree/bindings/leds/leds-mt6323.txt
+	see ../../bindings/leds/leds-mt6323.txt
 
 - keys
 	Required properties:
 		- compatible: "mediatek,mt6397-keys" or "mediatek,mt6323-keys"
-	see Documentation/devicetree/bindings/input/mtk-pmic-keys.txt
+	see ../../bindings/input/mtk-pmic-keys.txt
+
+- power-controller
+	Required properties:
+		- compatible: "mediatek,mt6323-pwrc"
+	For details, see ../../bindings/power/reset/mt6323-poweroff.txt
 
 Example:
 	pwrap: pwrap@1000f000 {
diff --git a/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt b/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
new file mode 100644
index 000000000000..933f0c48e887
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
@@ -0,0 +1,20 @@
+Device Tree Bindings for Power Controller on MediaTek PMIC
+
+The power controller which could be found on PMIC is responsible for externally
+powering off or on the remote MediaTek SoC through the circuit BBPU.
+
+Required properties:
+- compatible: Should be one of follows
+       "mediatek,mt6323-pwrc": for MT6323 PMIC
+
+Example:
+
+       pmic {
+               compatible = "mediatek,mt6323";
+
+               ...
+
+               power-controller {
+                       compatible = "mediatek,mt6323-pwrc";
+               };
+       }
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 02/10] dt-bindings: add missing mt6397 rtc
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

add missing devicetree-binding document for mt6397 rtc
in later patch driver is extended with mt6323 chip

Suggested-By: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
changes since v4: use relative path
changes since v3: moved SOB
changes since v2: splitted rtc-mt6397.txt from first patch
---
 .../devicetree/bindings/rtc/rtc-mt6397.txt    | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mt6397.txt

diff --git a/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt b/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
new file mode 100644
index 000000000000..4d2d8317e16b
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
@@ -0,0 +1,29 @@
+Device-Tree bindings for MediaTek PMIC based RTC
+
+MediaTek PMIC based RTC is an independent function of MediaTek PMIC that works
+as a type of multi-function device (MFD). The RTC can be configured and set up
+with PMIC wrapper bus which is a common resource shared with the other
+functions found on the same PMIC.
+
+For MediaTek PMIC MFD bindings, see:
+../../bindings/mfd/mt6397.txt
+
+For MediaTek PMIC wrapper bus bindings, see:
+../../bindings/soc/mediatek/pwrap.txt
+
+Required properties:
+- compatible: Should be one of follows
+       "mediatek,mt6323-rtc": for MT6323 PMIC
+       "mediatek,mt6397-rtc": for MT6397 PMIC
+
+Example:
+
+       pmic {
+               compatible = "mediatek,mt6323";
+
+               ...
+
+               rtc {
+                       compatible = "mediatek,mt6323-rtc";
+               };
+       };
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 04/10] rtc: mt6397: improvements of rtc driver
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

- use regmap_read_poll_timeout to drop while-loop
- use devm-api to drop remove-callback

Suggested-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
changes since v4: none
changes since v3: none
changes since v2:
- fix allocation after irq-request
- compatible for mt6323 in separate commit => part 5
---
 drivers/rtc/rtc-mt6397.c | 51 +++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 32 deletions(-)

diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index c08ee5edf865..9370b7fc9f81 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -4,16 +4,19 @@
 * Author: Tianping.Fang <tianping.fang@mediatek.com>
 */
 
-#include <linux/delay.h>
-#include <linux/init.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/mt6397/core.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/rtc.h>
 #include <linux/mfd/mt6397/rtc.h>
+#include <linux/mod_devicetable.h>
 
 static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
 {
-	unsigned long timeout = jiffies + HZ;
 	int ret;
 	u32 data;
 
@@ -21,19 +24,13 @@ static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
 	if (ret < 0)
 		return ret;
 
-	while (1) {
-		ret = regmap_read(rtc->regmap, rtc->addr_base + RTC_BBPU,
-				  &data);
-		if (ret < 0)
-			break;
-		if (!(data & RTC_BBPU_CBUSY))
-			break;
-		if (time_after(jiffies, timeout)) {
-			ret = -ETIMEDOUT;
-			break;
-		}
-		cpu_relax();
-	}
+	ret = regmap_read_poll_timeout(rtc->regmap,
+					rtc->addr_base + RTC_BBPU, data,
+					!(data & RTC_BBPU_CBUSY),
+					MTK_RTC_POLL_DELAY_US,
+					MTK_RTC_POLL_TIMEOUT);
+	if (ret < 0)
+		dev_err(rtc->dev, "failed to write WRTGE: %d\n", ret);
 
 	return ret;
 }
@@ -266,19 +263,19 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 		return rtc->irq;
 
 	rtc->regmap = mt6397_chip->regmap;
-	rtc->dev = &pdev->dev;
 	mutex_init(&rtc->lock);
 
 	platform_set_drvdata(pdev, rtc);
 
-	rtc->rtc_dev = devm_rtc_allocate_device(rtc->dev);
+	rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(rtc->rtc_dev))
 		return PTR_ERR(rtc->rtc_dev);
 
-	ret = request_threaded_irq(rtc->irq, NULL,
-				   mtk_rtc_irq_handler_thread,
-				   IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
-				   "mt6397-rtc", rtc);
+	ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
+					mtk_rtc_irq_handler_thread,
+					IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
+					"mt6397-rtc", rtc);
+
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
 			rtc->irq, ret);
@@ -302,15 +299,6 @@ static int mtk_rtc_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int mtk_rtc_remove(struct platform_device *pdev)
-{
-	struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
-
-	free_irq(rtc->irq, rtc);
-
-	return 0;
-}
-
 #ifdef CONFIG_PM_SLEEP
 static int mt6397_rtc_suspend(struct device *dev)
 {
@@ -349,7 +337,6 @@ static struct platform_driver mtk_rtc_driver = {
 		.pm = &mt6397_pm_ops,
 	},
 	.probe	= mtk_rtc_probe,
-	.remove = mtk_rtc_remove,
 };
 
 module_platform_driver(mtk_rtc_driver);
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 03/10] rtc: mt6397: move some common definitions into rtc.h
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

move code to separate header-file to reuse definitions later
in poweroff-driver (drivers/power/reset/mt6323-poweroff.c)

Suggested-by: Frank Wunderlich <frank-w@public-files.de>
Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
changes since v4: none
changes since v3: none
changes since v2: add missing commit-message
---
 drivers/rtc/rtc-mt6397.c       | 55 +-------------------------
 include/linux/mfd/mt6397/rtc.h | 71 ++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 54 deletions(-)
 create mode 100644 include/linux/mfd/mt6397/rtc.h

diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index b46ed4dc7015..c08ee5edf865 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -9,60 +9,7 @@
 #include <linux/module.h>
 #include <linux/regmap.h>
 #include <linux/rtc.h>
-#include <linux/irqdomain.h>
-#include <linux/platform_device.h>
-#include <linux/of_address.h>
-#include <linux/of_irq.h>
-#include <linux/io.h>
-#include <linux/mfd/mt6397/core.h>
-
-#define RTC_BBPU		0x0000
-#define RTC_BBPU_CBUSY		BIT(6)
-
-#define RTC_WRTGR		0x003c
-
-#define RTC_IRQ_STA		0x0002
-#define RTC_IRQ_STA_AL		BIT(0)
-#define RTC_IRQ_STA_LP		BIT(3)
-
-#define RTC_IRQ_EN		0x0004
-#define RTC_IRQ_EN_AL		BIT(0)
-#define RTC_IRQ_EN_ONESHOT	BIT(2)
-#define RTC_IRQ_EN_LP		BIT(3)
-#define RTC_IRQ_EN_ONESHOT_AL	(RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
-
-#define RTC_AL_MASK		0x0008
-#define RTC_AL_MASK_DOW		BIT(4)
-
-#define RTC_TC_SEC		0x000a
-/* Min, Hour, Dom... register offset to RTC_TC_SEC */
-#define RTC_OFFSET_SEC		0
-#define RTC_OFFSET_MIN		1
-#define RTC_OFFSET_HOUR		2
-#define RTC_OFFSET_DOM		3
-#define RTC_OFFSET_DOW		4
-#define RTC_OFFSET_MTH		5
-#define RTC_OFFSET_YEAR		6
-#define RTC_OFFSET_COUNT	7
-
-#define RTC_AL_SEC		0x0018
-
-#define RTC_PDN2		0x002e
-#define RTC_PDN2_PWRON_ALARM	BIT(4)
-
-#define RTC_MIN_YEAR		1968
-#define RTC_BASE_YEAR		1900
-#define RTC_NUM_YEARS		128
-#define RTC_MIN_YEAR_OFFSET	(RTC_MIN_YEAR - RTC_BASE_YEAR)
-
-struct mt6397_rtc {
-	struct device		*dev;
-	struct rtc_device	*rtc_dev;
-	struct mutex		lock;
-	struct regmap		*regmap;
-	int			irq;
-	u32			addr_base;
-};
+#include <linux/mfd/mt6397/rtc.h>
 
 static int mtk_rtc_write_trigger(struct mt6397_rtc *rtc)
 {
diff --git a/include/linux/mfd/mt6397/rtc.h b/include/linux/mfd/mt6397/rtc.h
new file mode 100644
index 000000000000..b702c29e8c74
--- /dev/null
+++ b/include/linux/mfd/mt6397/rtc.h
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2014-2018 MediaTek Inc.
+ *
+ * Author: Tianping.Fang <tianping.fang@mediatek.com>
+ *        Sean Wang <sean.wang@mediatek.com>
+ */
+
+#ifndef _LINUX_MFD_MT6397_RTC_H_
+#define _LINUX_MFD_MT6397_RTC_H_
+
+#include <linux/jiffies.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/rtc.h>
+
+#define RTC_BBPU               0x0000
+#define RTC_BBPU_CBUSY         BIT(6)
+#define RTC_BBPU_KEY            (0x43 << 8)
+
+#define RTC_WRTGR              0x003c
+
+#define RTC_IRQ_STA            0x0002
+#define RTC_IRQ_STA_AL         BIT(0)
+#define RTC_IRQ_STA_LP         BIT(3)
+
+#define RTC_IRQ_EN             0x0004
+#define RTC_IRQ_EN_AL          BIT(0)
+#define RTC_IRQ_EN_ONESHOT     BIT(2)
+#define RTC_IRQ_EN_LP          BIT(3)
+#define RTC_IRQ_EN_ONESHOT_AL  (RTC_IRQ_EN_ONESHOT | RTC_IRQ_EN_AL)
+
+#define RTC_AL_MASK            0x0008
+#define RTC_AL_MASK_DOW                BIT(4)
+
+#define RTC_TC_SEC             0x000a
+/* Min, Hour, Dom... register offset to RTC_TC_SEC */
+#define RTC_OFFSET_SEC         0
+#define RTC_OFFSET_MIN         1
+#define RTC_OFFSET_HOUR                2
+#define RTC_OFFSET_DOM         3
+#define RTC_OFFSET_DOW         4
+#define RTC_OFFSET_MTH         5
+#define RTC_OFFSET_YEAR                6
+#define RTC_OFFSET_COUNT       7
+
+#define RTC_AL_SEC             0x0018
+
+#define RTC_PDN2               0x002e
+#define RTC_PDN2_PWRON_ALARM   BIT(4)
+
+#define RTC_MIN_YEAR           1968
+#define RTC_BASE_YEAR          1900
+#define RTC_NUM_YEARS          128
+#define RTC_MIN_YEAR_OFFSET    (RTC_MIN_YEAR - RTC_BASE_YEAR)
+
+#define MTK_RTC_POLL_DELAY_US  10
+#define MTK_RTC_POLL_TIMEOUT   (jiffies_to_usecs(HZ))
+
+struct mt6397_rtc {
+	struct device           *dev;
+	struct rtc_device       *rtc_dev;
+
+	/* Protect register access from multiple tasks */
+	struct mutex            lock;
+	struct regmap           *regmap;
+	int                     irq;
+	u32                     addr_base;
+};
+
+#endif /* _LINUX_MFD_MT6397_RTC_H_ */
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 05/10] mfd: mt6323: some improvements of mt6397-core
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

simplyfications (resource definitions my DEFINE_RES_* macros)

Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
---
changes since v4: do not touch year of copyright
changes since v3: moved part 6 forward to let compatible and driver be together
changes since v2: splitted v2 part 4 into 6+7
---
 drivers/mfd/mt6397-core.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index 337bcccdb914..c9a81087fa55 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -5,6 +5,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/ioport.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
@@ -23,16 +24,8 @@
 #define MT6397_CID_CODE		0x97
 
 static const struct resource mt6397_rtc_resources[] = {
-	{
-		.start = MT6397_RTC_BASE,
-		.end   = MT6397_RTC_BASE + MT6397_RTC_SIZE,
-		.flags = IORESOURCE_MEM,
-	},
-	{
-		.start = MT6397_IRQ_RTC,
-		.end   = MT6397_IRQ_RTC,
-		.flags = IORESOURCE_IRQ,
-	},
+	DEFINE_RES_MEM(MT6397_RTC_BASE, MT6397_RTC_SIZE),
+	DEFINE_RES_IRQ(MT6397_IRQ_RTC),
 };
 
 static const struct resource mt6323_keys_resources[] = {
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 06/10] rtc: mt6397: add compatible for mt6323
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

use mt6397 rtc driver also for mt6323 but with different
base/size see "mfd: mt6323: add mt6323 rtc+pwrc"

Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
changes since v4: none
changes since v3: moved (was part 5)
changes since v2: splitted this from v2.3 suggested-by Alexandre Belloni
---
 drivers/rtc/rtc-mt6397.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
index 9370b7fc9f81..21cd9cc8b4c7 100644
--- a/drivers/rtc/rtc-mt6397.c
+++ b/drivers/rtc/rtc-mt6397.c
@@ -325,6 +325,7 @@ static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_rtc_suspend,
 			mt6397_rtc_resume);
 
 static const struct of_device_id mt6397_rtc_of_match[] = {
+	{ .compatible = "mediatek,mt6323-rtc", },
 	{ .compatible = "mediatek,mt6397-rtc", },
 	{ }
 };
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 07/10] mfd: mt6323: add mt6323 rtc+pwrc
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

add entry for rtc and power-controller to mt6323

Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
---
changes since v4: none
changes since v3: none
changes since v2: only splitting, second part of v2 part 4
---
 drivers/mfd/mt6397-core.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/mfd/mt6397-core.c b/drivers/mfd/mt6397-core.c
index c9a81087fa55..5916978a8feb 100644
--- a/drivers/mfd/mt6397-core.c
+++ b/drivers/mfd/mt6397-core.c
@@ -16,13 +16,24 @@
 #include <linux/mfd/mt6397/registers.h>
 #include <linux/mfd/mt6323/registers.h>
 
+#define MT6323_RTC_BASE		0x8000
+#define MT6323_RTC_SIZE		0x40
+
 #define MT6397_RTC_BASE		0xe000
 #define MT6397_RTC_SIZE		0x3e
 
+#define MT6323_PWRC_BASE	0x8000
+#define MT6323_PWRC_SIZE	0x40
+
 #define MT6323_CID_CODE		0x23
 #define MT6391_CID_CODE		0x91
 #define MT6397_CID_CODE		0x97
 
+static const struct resource mt6323_rtc_resources[] = {
+	DEFINE_RES_MEM(MT6323_RTC_BASE, MT6323_RTC_SIZE),
+	DEFINE_RES_IRQ(MT6323_IRQ_STATUS_RTC),
+};
+
 static const struct resource mt6397_rtc_resources[] = {
 	DEFINE_RES_MEM(MT6397_RTC_BASE, MT6397_RTC_SIZE),
 	DEFINE_RES_IRQ(MT6397_IRQ_RTC),
@@ -38,8 +49,17 @@ static const struct resource mt6397_keys_resources[] = {
 	DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
 };
 
+static const struct resource mt6323_pwrc_resources[] = {
+	DEFINE_RES_MEM(MT6323_PWRC_BASE, MT6323_PWRC_SIZE),
+};
+
 static const struct mfd_cell mt6323_devs[] = {
 	{
+		.name = "mt6323-rtc",
+		.num_resources = ARRAY_SIZE(mt6323_rtc_resources),
+		.resources = mt6323_rtc_resources,
+		.of_compatible = "mediatek,mt6323-rtc",
+	}, {
 		.name = "mt6323-regulator",
 		.of_compatible = "mediatek,mt6323-regulator"
 	}, {
@@ -50,6 +70,11 @@ static const struct mfd_cell mt6323_devs[] = {
 		.num_resources = ARRAY_SIZE(mt6323_keys_resources),
 		.resources = mt6323_keys_resources,
 		.of_compatible = "mediatek,mt6323-keys"
+	}, {
+		.name = "mt6323-pwrc",
+		.num_resources = ARRAY_SIZE(mt6323_pwrc_resources),
+		.resources = mt6323_pwrc_resources,
+		.of_compatible = "mediatek,mt6323-pwrc"
 	},
 };
 
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 08/10] power: reset: add driver for mt6323 poweroff
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

add poweroff driver for mt6323 and make Makefile and Kconfig-Entries

Suggested-by: Frank Wunderlich <frank-w@public-files.de>
Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
changes since v4: none
changes since v3: none
changes since v2: none (=v2 part 5)
---
 drivers/power/reset/Kconfig           | 10 +++
 drivers/power/reset/Makefile          |  1 +
 drivers/power/reset/mt6323-poweroff.c | 97 +++++++++++++++++++++++++++
 include/linux/mfd/mt6397/core.h       |  2 +
 4 files changed, 110 insertions(+)
 create mode 100644 drivers/power/reset/mt6323-poweroff.c

diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index a564237278ff..c721939767eb 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -140,6 +140,16 @@ config POWER_RESET_LTC2952
 	  This driver supports an external powerdown trigger and board power
 	  down via the LTC2952. Bindings are made in the device tree.
 
+config POWER_RESET_MT6323
+       bool "MediaTek MT6323 power-off driver"
+       depends on MFD_MT6397
+       help
+         The power-off driver is responsible for externally shutdown down
+         the power of a remote MediaTek SoC MT6323 is connected to through
+         controlling a tiny circuit BBPU inside MT6323 RTC.
+
+         Say Y if you have a board where MT6323 could be found.
+
 config POWER_RESET_QNAP
 	bool "QNAP power-off driver"
 	depends on OF_GPIO && PLAT_ORION
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 85da3198e4e0..da37f8b851dc 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
 obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o
 obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o
 obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o
+obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o
 obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o
 obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o
 obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o
diff --git a/drivers/power/reset/mt6323-poweroff.c b/drivers/power/reset/mt6323-poweroff.c
new file mode 100644
index 000000000000..1caf43d9e46d
--- /dev/null
+++ b/drivers/power/reset/mt6323-poweroff.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Power off through MediaTek PMIC
+ *
+ * Copyright (C) 2018 MediaTek Inc.
+ *
+ * Author: Sean Wang <sean.wang@mediatek.com>
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/mt6397/core.h>
+#include <linux/mfd/mt6397/rtc.h>
+
+struct mt6323_pwrc {
+	struct device *dev;
+	struct regmap *regmap;
+	u32 base;
+};
+
+static struct mt6323_pwrc *mt_pwrc;
+
+static void mt6323_do_pwroff(void)
+{
+	struct mt6323_pwrc *pwrc = mt_pwrc;
+	unsigned int val;
+	int ret;
+
+	regmap_write(pwrc->regmap, pwrc->base + RTC_BBPU, RTC_BBPU_KEY);
+	regmap_write(pwrc->regmap, pwrc->base + RTC_WRTGR, 1);
+
+	ret = regmap_read_poll_timeout(pwrc->regmap,
+					pwrc->base + RTC_BBPU, val,
+					!(val & RTC_BBPU_CBUSY),
+					MTK_RTC_POLL_DELAY_US,
+					MTK_RTC_POLL_TIMEOUT);
+	if (ret)
+		dev_err(pwrc->dev, "failed to write BBPU: %d\n", ret);
+
+	/* Wait some time until system down, otherwise, notice with a warn */
+	mdelay(1000);
+
+	WARN_ONCE(1, "Unable to power off system\n");
+}
+
+static int mt6323_pwrc_probe(struct platform_device *pdev)
+{
+	struct mt6397_chip *mt6397_chip = dev_get_drvdata(pdev->dev.parent);
+	struct mt6323_pwrc *pwrc;
+	struct resource *res;
+
+	pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL);
+	if (!pwrc)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	pwrc->base = res->start;
+	pwrc->regmap = mt6397_chip->regmap;
+	pwrc->dev = &pdev->dev;
+	mt_pwrc = pwrc;
+
+	pm_power_off = &mt6323_do_pwroff;
+
+	return 0;
+}
+
+static int mt6323_pwrc_remove(struct platform_device *pdev)
+{
+	if (pm_power_off == &mt6323_do_pwroff)
+		pm_power_off = NULL;
+
+	return 0;
+}
+
+static const struct of_device_id mt6323_pwrc_dt_match[] = {
+	{ .compatible = "mediatek,mt6323-pwrc" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, mt6323_pwrc_dt_match);
+
+static struct platform_driver mt6323_pwrc_driver = {
+	.probe          = mt6323_pwrc_probe,
+	.remove         = mt6323_pwrc_remove,
+	.driver         = {
+		.name   = "mt6323-pwrc",
+		.of_match_table = mt6323_pwrc_dt_match,
+	},
+};
+
+module_platform_driver(mt6323_pwrc_driver);
+
+MODULE_DESCRIPTION("Poweroff driver for MT6323 PMIC");
+MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/mfd/mt6397/core.h b/include/linux/mfd/mt6397/core.h
index 25a95e72179b..652da61e3711 100644
--- a/include/linux/mfd/mt6397/core.h
+++ b/include/linux/mfd/mt6397/core.h
@@ -7,6 +7,8 @@
 #ifndef __MFD_MT6397_CORE_H__
 #define __MFD_MT6397_CORE_H__
 
+#include <linux/mutex.h>
+
 enum mt6397_irq_numbers {
 	MT6397_IRQ_SPKL_AB = 0,
 	MT6397_IRQ_SPKR_AB,
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 09/10] MAINTAINERS: add Mediatek shutdown drivers
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

add Section in MAINTAINERS file for poweroff driver

Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
changes since v4: none
changes since v3: moved SOB
changes since v2: none (=v2 part 6)
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6426db5198f0..4172a3177633 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10128,6 +10128,13 @@ S:	Maintained
 F:	drivers/net/dsa/mt7530.*
 F:	net/dsa/tag_mtk.c
 
+MEDIATEK BOARD LEVEL SHUTDOWN DRIVERS
+M:	Sean Wang <sean.wang@mediatek.com>
+L:	linux-pm@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/power/reset/mt6323-poweroff.txt
+F:	drivers/power/reset/mt6323-poweroff.c
+
 MEDIATEK JPEG DRIVER
 M:	Rick Chang <rick.chang@mediatek.com>
 M:	Bin Liu <bin.liu@mediatek.com>
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* [PATCH v5 10/10] arm: dts: mt6323: add keys, power-controller, rtc and codec
From: Frank Wunderlich @ 2019-08-12 12:15 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, Allison Randal,
	David S. Miller, devicetree, Eddie Huang, Greg Kroah-Hartman,
	Jonathan Cameron, Kate Stewart, Lee Jones, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-pm, linux-rtc, Mark Rutland,
	Matthias Brugger, Mauro Carvalho Chehab, Nicolas Ferre,
	Richard Fontana, Rob Herring, Sean Wang, Sebastian Reichel,
	Thomas Gleixner, Tianping . Fang
  Cc: Josef Friedl, Frank Wunderlich
In-Reply-To: <20190812121511.4169-1-frank-w@public-files.de>

From: Josef Friedl <josef.friedl@speed.at>

support poweroff and power-related keys on bpi-r2

Suggested-by: Frank Wunderlich <frank-w@public-files.de>
Signed-off-by: Josef Friedl <josef.friedl@speed.at>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
---
changes since v4: none
changes since v3: none
changes since v2: none (=v2 part 7)
---
 arch/arm/boot/dts/mt6323.dtsi | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/arch/arm/boot/dts/mt6323.dtsi b/arch/arm/boot/dts/mt6323.dtsi
index ba397407c1dd..7fda40ab5fe8 100644
--- a/arch/arm/boot/dts/mt6323.dtsi
+++ b/arch/arm/boot/dts/mt6323.dtsi
@@ -238,5 +238,32 @@
 				regulator-enable-ramp-delay = <216>;
 			};
 		};
+
+		mt6323keys: mt6323keys {
+			compatible = "mediatek,mt6323-keys";
+			mediatek,long-press-mode = <1>;
+			power-off-time-sec = <0>;
+
+			power {
+				linux,keycodes = <116>;
+				wakeup-source;
+			};
+
+			home {
+				linux,keycodes = <114>;
+			};
+		};
+
+		codec: mt6397codec {
+			compatible = "mediatek,mt6397-codec";
+		};
+
+		power-controller {
+			compatible = "mediatek,mt6323-pwrc";
+		};
+
+		rtc {
+			compatible = "mediatek,mt6323-rtc";
+		};
 	};
 };
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related

* Re: [PATCH 0/7] media: cedrus: Improvements/cleanup
From: Jernej Škrabec @ 2019-08-12 12:21 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: devel, maxime.ripard, gregkh, linux-kernel, paul.kocialkowski,
	wens, mchehab, linux-arm-kernel, linux-media
In-Reply-To: <274221f1-b2d2-83aa-d84b-e1c572a1b832@xs4all.nl>

Dne ponedeljek, 12. avgust 2019 ob 14:12:21 CEST je Hans Verkuil napisal(a):
> On 5/30/19 11:15 PM, Jernej Skrabec wrote:
> > Here is first batch of random Cedrus improvements/cleanups. Only patch 2
> > has a change which raises a question about H264 controls.
> > 
> > Changes were tested on H3 SoC using modified ffmpeg and Kodi.
> > 
> > Please take a look.
> 
> This has been sitting in patchwork for quite some time. I've updated the
> status of the various patches and most needed extra work.
> 
> It seems that patches 4/7 and 5/7 are OK. Maxime, can you please confirm
> that these two are still valid? They apply cleanly on the latest master
> at least, but since they are a bit old I prefer to have confirmation that
> it's OK to merge them.

I'm not sure about patch 4, IIRC Boris Brezillon also wants to improve that 
area in separate series, but patch 5 should be safe to merge.

Anyway, I didn't post new version because I'm waiting on close-to-be-merged 
H264 and HEVC patch series to be actually merged.

Best regards,
Jernej

> 
> Regards,
> 
> 	Hans
> 
> > Best regards,
> > Jernej
> > 
> > Jernej Skrabec (7):
> >   media: cedrus: Disable engine after each slice decoding
> >   media: cedrus: Fix H264 default reference index count
> >   media: cedrus: Fix decoding for some H264 videos
> >   media: cedrus: Remove dst_bufs from context
> >   media: cedrus: Don't set chroma size for scale & rotation
> >   media: cedrus: Add infra for extra buffers connected to capture
> >   
> >     buffers
> >   
> >   media: cedrus: Improve H264 memory efficiency
> >  
> >  drivers/staging/media/sunxi/cedrus/cedrus.h   |  12 +-
> >  .../staging/media/sunxi/cedrus/cedrus_h264.c  | 115 ++++++++----------
> >  .../staging/media/sunxi/cedrus/cedrus_hw.c    |   4 +-
> >  .../staging/media/sunxi/cedrus/cedrus_video.c |  25 ++--
> >  4 files changed, 68 insertions(+), 88 deletions(-)





_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: [PATCH V4 4/4] dt-bindings: arm: imx: Add the soc binding for i.MX8MQ
From: Shawn Guo @ 2019-08-12 12:30 UTC (permalink / raw)
  To: Anson.Huang
  Cc: mark.rutland, ping.bai, bhaskar.upadhaya, manivannan.sadhasivam,
	leonard.crestez, festevam, andrew.smirnov, Linux-imx,
	u.kleine-koenig, devicetree, pramod.kumar_1, s.hauer,
	j.neuschaefer, robh+dt, vabhav.sharma, daniel.baluta,
	linux-arm-kernel, aisheng.dong, linux-kernel, leoyang.li, kernel,
	l.stach
In-Reply-To: <20190619022145.42398-4-Anson.Huang@nxp.com>

On Wed, Jun 19, 2019 at 10:21:45AM +0800, Anson.Huang@nxp.com wrote:
> From: Anson Huang <Anson.Huang@nxp.com>
> 
> This patch adds the soc & board binding for i.MX8MQ.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Rob Herring <robh@kernel.org>
> ---
> No changes.
> ---
>  Documentation/devicetree/bindings/arm/fsl.yaml | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/arm/fsl.yaml b/Documentation/devicetree/bindings/arm/fsl.yaml
> index b35abb1..f944df8 100644
> --- a/Documentation/devicetree/bindings/arm/fsl.yaml
> +++ b/Documentation/devicetree/bindings/arm/fsl.yaml
> @@ -183,6 +183,12 @@ properties:
>                - fsl,imx8mn-ddr4-evk            # i.MX8MN DDR4 EVK Board
>            - const: fsl,imx8mn
>  
> +      - description: i.MX8MQ based Boards
> +        items:
> +          - enum:
> +              - fsl,imx8mq-evk            # i.MX8MQ EVK Board
> +          - const: fsl,imx8mq
> +

We already have this with e126417ff1b1 (dt-bindings: arm: fsl: Add the
imx8mq boards).

Shawn

>        - description: i.MX8QXP based Boards
>          items:
>            - enum:
> -- 
> 2.7.4
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: [PATCH V4 1/4] dt-bindings: arm: imx: Add the soc binding for i.MX8MN
From: Shawn Guo @ 2019-08-12 12:32 UTC (permalink / raw)
  To: Anson.Huang
  Cc: mark.rutland, ping.bai, bhaskar.upadhaya, manivannan.sadhasivam,
	leonard.crestez, festevam, andrew.smirnov, Linux-imx,
	u.kleine-koenig, devicetree, pramod.kumar_1, s.hauer,
	j.neuschaefer, robh+dt, vabhav.sharma, daniel.baluta,
	linux-arm-kernel, aisheng.dong, linux-kernel, leoyang.li, kernel,
	l.stach
In-Reply-To: <20190619022145.42398-1-Anson.Huang@nxp.com>

On Wed, Jun 19, 2019 at 10:21:42AM +0800, Anson.Huang@nxp.com wrote:
> From: Anson Huang <Anson.Huang@nxp.com>
> 
> This patch adds the soc & board binding for i.MX8MN.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Rob Herring <robh@kernel.org>

Applied 1 ~ 3, thanks.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: [PATCH V3] soc: imx-scu: Add SoC UID(unique identifier) support
From: Shawn Guo @ 2019-08-12 12:35 UTC (permalink / raw)
  To: Anson.Huang
  Cc: aisheng.dong, abel.vesa, s.hauer, linux-kernel, m.felsch,
	Linux-imx, kernel, festevam, linux-arm-kernel
In-Reply-To: <20190702074545.48267-1-Anson.Huang@nxp.com>

On Tue, Jul 02, 2019 at 03:45:45PM +0800, Anson.Huang@nxp.com wrote:
> From: Anson Huang <Anson.Huang@nxp.com>
> 
> Add i.MX SCU SoC's UID(unique identifier) support, user
> can read it from sysfs:
> 
> root@imx8qxpmek:~# cat /sys/devices/soc0/soc_uid
> 7B64280B57AC1898
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>

Applied, thanks.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: [PATCH v3 02/11] kselftest: arm64: adds first test and common utils
From: Amit Kachhap @ 2019-08-12 12:43 UTC (permalink / raw)
  To: Cristian Marussi, linux-kselftest@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, shuah@kernel.org
  Cc: andreyknvl@google.com, Dave P Martin
In-Reply-To: <20190802170300.20662-3-cristian.marussi@arm.com>

Hi Cristian,

On 8/2/19 10:32 PM, Cristian Marussi wrote:
> Added some arm64/signal specific boilerplate and utility code to help
> further testcase development.
>
> A simple testcase and related helpers are also introduced in this commit:
> mangle_pstate_invalid_compat_toggle is a simple mangle testcase which
> messes with the ucontext_t from within the sig_handler, trying to toggle
> PSTATE state bits to switch the system between 32bit/64bit execution state.
> Expects SIGSEGV on test PASS.
>
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> ---
> A few fixes:
> - test_arm64_signals.sh runner script generation has been reviewed in order to
>    be safe against the .gitignore
> - using kselftest.h officially provided defines for tests' return values
> - removed SAFE_WRITE()/dump_uc()
> - looking for si_code==SEGV_ACCERR on SEGV test cases to better understand if
>    the sigfault had been directly triggered by Kernel
> ---
>   tools/testing/selftests/arm64/Makefile        |   2 +-
>   .../testing/selftests/arm64/signal/.gitignore |   6 +
>   tools/testing/selftests/arm64/signal/Makefile |  88 ++++++
>   tools/testing/selftests/arm64/signal/README   |  59 ++++
>   .../arm64/signal/test_arm64_signals.src_shell |  55 ++++
>   .../selftests/arm64/signal/test_signals.c     |  26 ++
>   .../selftests/arm64/signal/test_signals.h     | 137 +++++++++
>   .../arm64/signal/test_signals_utils.c         | 261 ++++++++++++++++++
>   .../arm64/signal/test_signals_utils.h         |  13 +
>   .../arm64/signal/testcases/.gitignore         |   1 +
>   .../mangle_pstate_invalid_compat_toggle.c     |  25 ++
>   .../arm64/signal/testcases/testcases.c        | 150 ++++++++++
>   .../arm64/signal/testcases/testcases.h        |  83 ++++++
>   13 files changed, 905 insertions(+), 1 deletion(-)
>   create mode 100644 tools/testing/selftests/arm64/signal/.gitignore
>   create mode 100644 tools/testing/selftests/arm64/signal/Makefile
>   create mode 100644 tools/testing/selftests/arm64/signal/README
>   create mode 100755 tools/testing/selftests/arm64/signal/test_arm64_signals.src_shell
>   create mode 100644 tools/testing/selftests/arm64/signal/test_signals.c
>   create mode 100644 tools/testing/selftests/arm64/signal/test_signals.h
>   create mode 100644 tools/testing/selftests/arm64/signal/test_signals_utils.c
>   create mode 100644 tools/testing/selftests/arm64/signal/test_signals_utils.h
>   create mode 100644 tools/testing/selftests/arm64/signal/testcases/.gitignore
>   create mode 100644 tools/testing/selftests/arm64/signal/testcases/mangle_pstate_invalid_compat_toggle.c
>   create mode 100644 tools/testing/selftests/arm64/signal/testcases/testcases.c
>   create mode 100644 tools/testing/selftests/arm64/signal/testcases/testcases.h
>
> diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
> index 03a0d4f71218..af59dc74e0dc 100644
> --- a/tools/testing/selftests/arm64/Makefile
> +++ b/tools/testing/selftests/arm64/Makefile
> @@ -6,7 +6,7 @@ ARCH ?= $(shell uname -m)
>   ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
>
>   ifeq ("x$(ARCH)", "xarm64")
> -SUBDIRS :=
> +SUBDIRS := signal
>   else
>   SUBDIRS :=
>   endif
> diff --git a/tools/testing/selftests/arm64/signal/.gitignore b/tools/testing/selftests/arm64/signal/.gitignore
> new file mode 100644
> index 000000000000..434f65c15f03
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/.gitignore
> @@ -0,0 +1,6 @@
> +# Helper script's internal testcases list (TPROGS) is regenerated
> +# each time by Makefile on standalone (non KSFT driven) runs.
> +# Committing such list creates a dependency between testcases
> +# patches such that they are no more easily revertable. Just ignore.
> +test_arm64_signals.src_shell
> +test_arm64_signals.sh
> diff --git a/tools/testing/selftests/arm64/signal/Makefile b/tools/testing/selftests/arm64/signal/Makefile
> new file mode 100644
> index 000000000000..8c8d08be4b0d
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/Makefile
> @@ -0,0 +1,88 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2019 ARM Limited
> +
> +# Supports also standalone invokation out of KSFT-tree
> +# Compile standalone and run on your device with:
> +#
> +#  $ make -C tools/testing/selftests/arm64/signal INSTALL_PATH=<your-dir> install
> +#
> +# Run standalone on device with:
> +#
> +#  $ <your-device-instdir>/test_arm64_signals.sh [-k|-v]
> +#
> +# If INSTALL_PATH= is NOT provided it will default to ./install
> +
> +# A proper top_srcdir is needed both by KSFT(lib.mk)
> +# and standalone builds
> +top_srcdir = ../../../../..
> +
> +CFLAGS += -std=gnu99 -I. -I$(top_srcdir)/tools/testing/selftests/
> +SRCS := $(filter-out testcases/testcases.c,$(wildcard testcases/*.c))
> +PROGS := $(patsubst %.c,%,$(SRCS))
> +
> +# Guessing as best as we can where the Kernel headers
> +# could have been installed depending on ENV config and
> +# type of invocation.
> +ifeq ($(KBUILD_OUTPUT),)
> +khdr_dir = $(top_srcdir)/usr/include
> +else
> +ifeq (0,$(MAKELEVEL))
> +khdr_dir = $(KBUILD_OUTPUT)/usr/include
> +else
> +# the KSFT preferred location when KBUILD_OUTPUT is set
> +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
> +endif
> +endif
> +
> +CFLAGS += -I$(khdr_dir)
> +
> +# Standalone run
> +ifeq (0,$(MAKELEVEL))
> +CC := $(CROSS_COMPILE)gcc
> +RUNNER_SRC = test_arm64_signals.src_shell
> +RUNNER = test_arm64_signals.sh
> +INSTALL_PATH ?= install/
> +
> +all: $(RUNNER)
> +
> +$(RUNNER): $(PROGS)
> +     cp $(RUNNER_SRC) $(RUNNER)
> +     sed -i -e 's#PROGS=.*#PROGS="$(PROGS)"#' $@
> +
> +install: all
> +     mkdir -p $(INSTALL_PATH)/testcases
> +     cp $(PROGS) $(INSTALL_PATH)/testcases
> +     cp $(RUNNER) $(INSTALL_PATH)/
> +
> +.PHONY clean:
> +     rm -f $(PROGS)
> +# KSFT run
> +else
> +# Generated binaries to be installed by top KSFT script
> +TEST_GEN_PROGS := $(notdir $(PROGS))
> +
> +# Get Kernel headers installed and use them.
> +KSFT_KHDR_INSTALL := 1
> +
> +# This include mk will also mangle the TEST_GEN_PROGS list
> +# to account for any OUTPUT target-dirs optionally provided
> +# by the toplevel makefile
> +include ../../lib.mk
> +
> +$(TEST_GEN_PROGS): $(PROGS)
> +     cp $(PROGS) $(OUTPUT)/
> +
> +clean:
> +     $(CLEAN)
> +     rm -f $(PROGS)
> +endif
> +
> +# Common test-unit targets to build common-layout test-cases executables
> +# Needs secondary expansion to properly include the testcase c-file in pre-reqs
> +.SECONDEXPANSION:
> +$(PROGS): test_signals.c test_signals_utils.c testcases/testcases.c $$@.c test_signals.h test_signals_utils.h testcases/testcases.h

I suppose *.h can be removed from the targets here.


> +     @if [ ! -d $(khdr_dir) ]; then \
> +             echo -n "\n!!! WARNING: $(khdr_dir) NOT FOUND."; \
> +             echo "===>  Are you sure Kernel Headers have been installed properly ?\n"; \
> +     fi
> +     $(CC) $(CFLAGS) $^ -o $@
> diff --git a/tools/testing/selftests/arm64/signal/README b/tools/testing/selftests/arm64/signal/README
> new file mode 100644
> index 000000000000..53f005f7910a
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/README
> @@ -0,0 +1,59 @@
> +KSelfTest arm64/signal/
> +=======================
> +
> +Signals Tests
> ++++++++++++++
> +
> +- Tests are built around a common main compilation unit: such shared main
> +  enforces a standard sequence of operations needed to perform a single
> +  signal-test (setup/trigger/run/result/cleanup)
> +
> +- The above mentioned ops are configurable on a test-by-test basis: each test
> +  is described (and configured) using the descriptor signals.h::struct tdescr
> +
> +- Each signal testcase is compiled into its own executable: a separate
> +  executable is used for each test since many tests complete successfully
> +  by receiving some kind of fatal signal from the Kernel, so it's safer
> +  to run each test unit in its own standalone process, so as to start each
> +  test from a clean slate.
> +
> +- New tests can be simply defined in testcases/ dir providing a proper struct
> +  tdescr overriding all the defaults we wish to change (as of now providing a
> +  custom run method is mandatory though)
> +
> +- Signals' test-cases hereafter defined belong currently to two
> +  principal families:
> +
> +  - 'mangle_' tests: a real signal (SIGUSR1) is raised and used as a trigger
> +    and then the test case code messes-up with the sigframe ucontext_t from
> +    inside the sighandler itself.
> +
> +  - 'fake_sigreturn_' tests: a brand new custom artificial sigframe structure
> +    is placed on the stack and a sigreturn syscall is called to simulate a
> +    real signal return. This kind of tests does not use a trigger usually and
> +    they are just fired using some simple included assembly trampoline code.
> +
> + - Most of these tests are successfully passing if the process gets killed by
> +   some fatal signal: usually SIGSEGV or SIGBUS. Since while writing this
> +   kind of tests it is extremely easy in fact to end-up injecting other
> +   unrelated SEGV bugs in the testcases, it becomes extremely tricky to
> +   be really sure that the tests are really addressing what they are meant
> +   to address and they are not instead falling apart due to unplanned bugs
> +   in the test code.
> +   In order to alleviate the misery of the life of such test-developer, a few
> +   helpers are provided:
> +
> +   - a couple of ASSERT_BAD/GOOD_CONTEXT() macros to easily parse a ucontext_t
> +     and verify if it is indeed GOOD or BAD (depending on what we were
> +     expecting), using the same logic/perspective as in the arm64 Kernel signals
> +     routines.
> +
> +   - a sanity mechanism to be used in 'fake_sigreturn_'-alike tests: enabled by
> +     default it takes care to verify that the test-execution had at least
> +     successfully progressed up to the stage of triggering the fake sigreturn
> +     call.
> +
> +  In both cases test results are expected in terms of:
> +   - some fatal signal sent by the Kernel to the test process
> +  or
> +  - analyzing some final regs state
> diff --git a/tools/testing/selftests/arm64/signal/test_arm64_signals.src_shell b/tools/testing/selftests/arm64/signal/test_arm64_signals.src_shell
> new file mode 100755
> index 000000000000..163e941e2997
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/test_arm64_signals.src_shell
> @@ -0,0 +1,55 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2019 ARM Limited
> +
> +ret=0
> +keep_on_fail=0
> +err_out="2> /dev/null"
> +
> +usage() {
> +     echo "Usage: `basename $0` [-v] [-k]"
> +     exit 1
> +}
> +
> +# avoiding getopt to avoid compatibility issues on targets
> +# with limited resources
> +while [ $# -gt 0 ]
> +do
> +     case $1 in
> +             "-k")
> +                     keep_on_fail=1
> +                     ;;
> +             "-v")
> +                     err_out=
> +                     ;;
> +             *)
> +                     usage
> +                     ;;
> +     esac
> +     shift
> +done
> +
> +TPROGS=
> +
> +tot=$(echo $TPROGS | wc -w)
> +
> +# Tests are expected in testcases/ subdir inside the installation path
> +workdir="`dirname $0 2>/dev/null`"
> +[ -n $workdir ] && cd $workdir
> +
> +passed=0
> +run=0
> +for test in $TPROGS
> +do
> +     run=$((run + 1))
> +     eval ./$test $err_out
> +     if [ $? != 0 ]; then
> +             [ $keep_on_fail = 0 ] && echo "===>>> FAILED:: $test <<<===" && ret=1 && break
> +     else
> +             passed=$((passed + 1))
> +     fi
> +done
> +
> +echo "==>> PASSED: $passed/$run on $tot available tests."
> +
> +exit $ret
> diff --git a/tools/testing/selftests/arm64/signal/test_signals.c b/tools/testing/selftests/arm64/signal/test_signals.c
> new file mode 100644
> index 000000000000..3447d7011aec
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/test_signals.c
> @@ -0,0 +1,26 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2019 ARM Limited */
> +
> +#include <kselftest.h>
> +
> +#include "test_signals.h"
> +#include "test_signals_utils.h"
> +
> +struct tdescr *current;
> +extern struct tdescr tde;
> +
> +int main(int argc, char *argv[])
> +{
> +     current = &tde;
> +
> +     ksft_print_msg("%s :: %s - SIG_TRIG:%d  SIG_OK:%d -- current:%p\n",
> +                    current->name, current->descr, current->sig_trig,
> +                    current->sig_ok, current);
> +     if (test_setup(current)) {
> +             if (test_run(current))
> +                     test_result(current);
> +             test_cleanup(current);
> +     }
> +
> +     return current->pass ? KSFT_PASS : KSFT_FAIL;
> +}
> diff --git a/tools/testing/selftests/arm64/signal/test_signals.h b/tools/testing/selftests/arm64/signal/test_signals.h
> new file mode 100644
> index 000000000000..85db3ac44b32
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/test_signals.h
> @@ -0,0 +1,137 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2019 ARM Limited */
> +
> +#ifndef __TEST_SIGNALS_H__
> +#define __TEST_SIGNALS_H__
> +
> +#include <assert.h>
> +#include <stdbool.h>
> +#include <signal.h>
> +#include <ucontext.h>
> +#include <stdint.h>
Headers can be added in alphabetically order.

Thanks,
Amit D
> +
> +/*
> + * Using ARCH specific and sanitized Kernel headers installed by KSFT
> + * framework since we asked for it by setting flag KSFT_KHDR_INSTALL
> + * in our Makefile.
> + */
> +#include <asm/ptrace.h>
> +#include <asm/hwcap.h>
> +
> +/* pasted from include/linux/stringify.h */
> +#define __stringify_1(x...)  #x
> +#define __stringify(x...)    __stringify_1(x)
> +
> +/*
> + * Reads a sysreg using the, possibly provided, S3_ encoding in order to
> + * avoid inject any dependency on the used toolchain regarding possibly
> + * still unsupported ARMv8 extensions.
> + *
> + * Using a standard mnemonic here to indicate the specific sysreg (like SSBS)
> + * would introduce a compile-time dependency on possibly unsupported ARMv8
> + * Extensions: you could end-up failing to build the test depending on the
> + * available toolchain.
> + * This is undesirable since some tests, even if specifically targeted at some
> + * ARMv8 Extensions, can be plausibly run even on hardware lacking the above
> + * optional ARM features. (SSBS bit preservation is an example: Kernel handles
> + * it transparently not caring at all about the effective set of supported
> + * features).
> + * On the other side we will expect to observe different behaviours if the
> + * feature is supported or not: usually getting a SIGILL when trying to use
> + * unsupported features. For this reason we have anyway in place some
> + * preliminary run-time checks about the cpu effectively supported features.
> + *
> + * This helper macro is meant to be used for regs readable at EL0, BUT some
> + * EL1 sysregs are indeed readable too through MRS emulation Kernel-mechanism
> + * if the required reg is included in the supported encoding space:
> + *
> + *  Documentation/arm64/cpu-feature-regsiters.txt
> + *
> + *  "The infrastructure emulates only the following system register space:
> + *           Op0=3, Op1=0, CRn=0, CRm=0,4,5,6,7
> + */
> +#define get_regval(regname, out) \
> +     asm volatile("mrs %0, " __stringify(regname) : "=r" (out) :: "memory")
> +
> +/* Regs encoding and masks naming copied in from sysreg.h */
> +#define SYS_ID_AA64MMFR1_EL1 S3_0_C0_C7_1    /* MRS Emulated */
> +#define SYS_ID_AA64MMFR2_EL1 S3_0_C0_C7_2    /* MRS Emulated */
> +#define ID_AA64MMFR1_PAN_SHIFT       20
> +#define ID_AA64MMFR2_UAO_SHIFT       4
> +
> +/* Local Helpers */
> +#define IS_PAN_SUPPORTED(val) \
> +     (!!((val) & (0xfUL << ID_AA64MMFR1_PAN_SHIFT)))
> +#define IS_UAO_SUPPORTED(val) \
> +     (!!((val) & (0xfUL << ID_AA64MMFR2_UAO_SHIFT)))
> +
> +#define S3_MRS_SSBS_SYSREG           S3_3_C4_C2_6    /* EL0 supported */
> +
> +/*
> + * Feature flags used in tdescr.feats_required to specify
> + * any feature by the test
> + */
> +enum {
> +     FSSBS_BIT,
> +     FPAN_BIT,
> +     FUAO_BIT,
> +     FMAX_END
> +};
> +
> +#define FEAT_SSBS            (1UL << FSSBS_BIT)
> +#define FEAT_PAN             (1UL << FPAN_BIT)
> +#define FEAT_UAO             (1UL << FUAO_BIT)
> +
> +/*
> + * A descriptor used to describe and configure a test case.
> + * Fields with a non-trivial meaning are described inline in the following.
> + */
> +struct tdescr {
> +     /* KEEP THIS FIELD FIRST for easier lookup from assembly */
> +     void            *token;
> +     /* when disabled token based sanity checking is skipped in handler */
> +     bool            sanity_disabled;
> +     /* just a name for the test-case; manadatory field */
> +     char            *name;
> +     char            *descr;
> +     unsigned long   feats_required;
> +     /* bitmask of effectively supported feats: populated at run-time */
> +     unsigned long   feats_supported;
> +     bool            feats_ok;
> +     bool            initialized;
> +     unsigned int    minsigstksz;
> +     /* signum used as a test trigger. Zero if no trigger-signal is used */
> +     int             sig_trig;
> +     /*
> +      * signum considered as a successful test completion.
> +      * Zero when no signal is expected on success
> +      */
> +     int             sig_ok;
> +     /* signum expected on unsupported CPU features. */
> +     int             sig_unsupp;
> +     /* a timeout in second for test completion */
> +     unsigned int    timeout;
> +     bool            triggered;
> +     bool            pass;
> +     /* optional sa_flags for the installed handler */
> +     int             sa_flags;
> +     ucontext_t      saved_uc;
> +
> +     /* a setup function to be called before test starts */
> +     int (*setup)(struct tdescr *td);
> +     void (*cleanup)(struct tdescr *td);
> +
> +     /* an optional function to be used as a trigger for test starting */
> +     int (*trigger)(struct tdescr *td);
> +     /*
> +      * the actual test-core: invoked differently depending on the
> +      * presence of the trigger function above; this is mandatory
> +      */
> +     int (*run)(struct tdescr *td, siginfo_t *si, ucontext_t *uc);
> +
> +     /* an optional function for custom results' processing */
> +     void (*check_result)(struct tdescr *td);
> +
> +     void *priv;
> +};
> +#endif
> diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/tools/testing/selftests/arm64/signal/test_signals_utils.c
> new file mode 100644
> index 000000000000..ac0055f6340b
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c
> @@ -0,0 +1,261 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2019 ARM Limited */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <signal.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <assert.h>
> +#include <sys/auxv.h>
> +#include <linux/auxvec.h>
> +#include <ucontext.h>
> +
> +#include "test_signals.h"
> +#include "test_signals_utils.h"
> +#include "testcases/testcases.h"
> +
> +extern struct tdescr *current;
> +
> +static char *feats_store[FMAX_END] = {
> +     "SSBS",
> +     "PAN",
> +     "UAO"
> +};
> +
> +#define MAX_FEATS_SZ 128
> +static inline char *feats_to_string(unsigned long feats)
> +{
> +     static char feats_string[MAX_FEATS_SZ];
> +
> +     for (int i = 0; i < FMAX_END && feats_store[i][0]; i++) {
> +             if (feats & 1UL << i)
> +                     snprintf(feats_string, MAX_FEATS_SZ - 1, "%s %s ",
> +                              feats_string, feats_store[i]);
> +     }
> +
> +     return feats_string;
> +}
> +
> +static void unblock_signal(int signum)
> +{
> +     sigset_t sset;
> +
> +     sigemptyset(&sset);
> +     sigaddset(&sset, signum);
> +     sigprocmask(SIG_UNBLOCK, &sset, NULL);
> +}
> +
> +static void default_result(struct tdescr *td, bool force_exit)
> +{
> +     if (td->pass)
> +             fprintf(stderr, "==>> completed. PASS(1)\n");
> +     else
> +             fprintf(stdout, "==>> completed. FAIL(0)\n");
> +     if (force_exit)
> +             exit(td->pass ? EXIT_SUCCESS : EXIT_FAILURE);
> +}
> +
> +static inline bool are_feats_ok(struct tdescr *td)
> +{
> +     return td ? td->feats_required == td->feats_supported : 0;
> +}
> +
> +static void default_handler(int signum, siginfo_t *si, void *uc)
> +{
> +     if (current->sig_trig && signum == current->sig_trig) {
> +             fprintf(stderr, "Handling SIG_TRIG\n");
> +             current->triggered = 1;
> +             /* ->run was asserted NON-NULL in test_setup() already */
> +             current->run(current, si, uc);
> +     } else if (signum == SIGILL && !current->initialized) {
> +             /*
> +              * A SIGILL here while still not initialized means we failed
> +              * even to asses the existence of features during init
> +              */
> +             fprintf(stdout,
> +                     "Got SIGILL test_init. Marking ALL features UNSUPPORTED.\n");
> +             current->feats_supported = 0;
> +     } else if (current->sig_ok && signum == current->sig_ok) {
> +             /* it's a bug in the test code when this assert fail */
> +             assert(!current->sig_trig || current->triggered);
> +             fprintf(stderr,
> +                     "SIG_OK -- SP:%p  si_addr@:0x%p  si_code:%d  token@:0x%p  offset:%ld\n",
> +                     ((ucontext_t *)uc)->uc_mcontext.sp,
> +                     si->si_addr, si->si_code, current->token,
> +                     current->token - si->si_addr);
> +             /*
> +              * fake_sigreturn tests, which have sanity_enabled=1, set, at
> +              * the very last time, the token field to the SP address used
> +              * to place the fake sigframe: so token==0 means we never made
> +              * it to the end, segfaulting well-before, and the test is
> +              * possibly broken.
> +              */
> +             if (!current->sanity_disabled && !current->token) {
> +                     fprintf(stdout,
> +                             "current->token ZEROED...test is probably broken!\n");
> +                     assert(0);
> +             }
> +             /*
> +              * Trying to narrow down the SEGV to the ones generated by
> +              * Kernel itself via arm64_notify_segfault()
> +              */
> +             if (current->sig_ok == SIGSEGV && si->si_code != SEGV_ACCERR) {
> +                     fprintf(stdout,
> +                             "si_code != SEGV_ACCERR...test is probably broken!\n");
> +                     assert(0);
> +             }
> +             fprintf(stderr, "Handling SIG_OK\n");
> +             current->pass = 1;
> +             /*
> +              * Some tests can lead to SEGV loops: in such a case we want
> +              * to terminate immediately exiting straight away
> +              */
> +             default_result(current, 1);
> +     } else {
> +             if (signum == current->sig_unsupp && !are_feats_ok(current)) {
> +                     fprintf(stderr, "-- RX SIG_UNSUPP on unsupported feature...OK\n");
> +                     current->pass = 1;
> +             } else if (signum == SIGALRM && current->timeout) {
> +                     fprintf(stderr, "-- Timeout !\n");
> +             } else {
> +                     fprintf(stderr,
> +                             "-- RX UNEXPECTED SIGNAL: %d\n", signum);
> +             }
> +             default_result(current, 1);
> +     }
> +}
> +
> +static int default_setup(struct tdescr *td)
> +{
> +     struct sigaction sa;
> +
> +     sa.sa_sigaction = default_handler;
> +     sa.sa_flags = SA_SIGINFO;
> +     if (td->sa_flags)
> +             sa.sa_flags |= td->sa_flags;
> +     sigemptyset(&sa.sa_mask);
> +     /* uncatchable signals naturally skipped ... */
> +     for (int sig = 1; sig < 32; sig++)
> +             sigaction(sig, &sa, NULL);
> +     /*
> +      * RT Signals default disposition is Term but they cannot be
> +      * generated by the Kernel in response to our tests; so just catch
> +      * them all and report them as UNEXPECTED signals.
> +      */
> +     for (int sig = SIGRTMIN; sig <= SIGRTMAX; sig++)
> +             sigaction(sig, &sa, NULL);
> +
> +     /* just in case...unblock explicitly all we need */
> +     if (td->sig_trig)
> +             unblock_signal(td->sig_trig);
> +     if (td->sig_ok)
> +             unblock_signal(td->sig_ok);
> +     if (td->sig_unsupp)
> +             unblock_signal(td->sig_unsupp);
> +
> +     if (td->timeout) {
> +             unblock_signal(SIGALRM);
> +             alarm(td->timeout);
> +     }
> +     fprintf(stderr, "Registered handlers for all signals.\n");
> +
> +     return 1;
> +}
> +
> +static inline int default_trigger(struct tdescr *td)
> +{
> +     return !raise(td->sig_trig);
> +}
> +
> +static int test_init(struct tdescr *td)
> +{
> +     td->minsigstksz = getauxval(AT_MINSIGSTKSZ);
> +     if (!td->minsigstksz)
> +             td->minsigstksz = MINSIGSTKSZ;
> +     fprintf(stderr, "Detected MINSTKSIGSZ:%d\n", td->minsigstksz);
> +
> +     if (td->feats_required) {
> +             bool feats_ok = false;
> +             td->feats_supported = 0;
> +             /*
> +              * Checking for CPU required features using both the
> +              * auxval and the arm64 MRS Emulation to read sysregs.
> +              */
> +             if (getauxval(AT_HWCAP) & HWCAP_CPUID) {
> +                     uint64_t val = 0;
> +
> +                     if (td->feats_required & FEAT_SSBS) {
> +                             /* Uses HWCAP to check capability */
> +                             if (getauxval(AT_HWCAP) & HWCAP_SSBS)
> +                                     td->feats_supported |= FEAT_SSBS;
> +                     }
> +                     if (td->feats_required & FEAT_PAN) {
> +                             /* Uses MRS emulation to check capability */
> +                             get_regval(SYS_ID_AA64MMFR1_EL1, val);
> +                             if (IS_PAN_SUPPORTED(val))
> +                                     td->feats_supported |= FEAT_PAN;
> +                     }
> +                     if (td->feats_required & FEAT_UAO) {
> +                             /* Uses MRS emulation to check capability */
> +                             get_regval(SYS_ID_AA64MMFR2_EL1 , val);
> +                             if (IS_UAO_SUPPORTED(val))
> +                                     td->feats_supported |= FEAT_UAO;
> +                     }
> +             } else {
> +                     fprintf(stderr,
> +                             "HWCAP_CPUID NOT available. Mark ALL feats UNSUPPORTED.\n");
> +             }
> +             feats_ok = are_feats_ok(td);
> +             fprintf(stderr,
> +                     "Required Features: [%s] %ssupported\n",
> +                     feats_ok ? feats_to_string(td->feats_supported) :
> +                     feats_to_string(td->feats_required ^ td->feats_supported),
> +                     !feats_ok ? "NOT " : "");
> +     }
> +
> +     td->initialized = 1;
> +     return 1;
> +}
> +
> +int test_setup(struct tdescr *td)
> +{
> +     /* assert core invariants symptom of a rotten testcase */
> +     assert(current);
> +     assert(td);
> +     assert(td->name);
> +     assert(td->run);
> +
> +     if (!test_init(td))
> +             return 0;
> +
> +     if (td->setup)
> +             return td->setup(td);
> +     else
> +             return default_setup(td);
> +}
> +
> +int test_run(struct tdescr *td)
> +{
> +     if (td->sig_trig) {
> +             if (td->trigger)
> +                     return td->trigger(td);
> +             else
> +                     return default_trigger(td);
> +     } else {
> +             return td->run(td, NULL, NULL);
> +     }
> +}
> +
> +void test_result(struct tdescr *td)
> +{
> +     if (td->check_result)
> +             td->check_result(td);
> +     default_result(td, 0);
> +}
> +
> +void test_cleanup(struct tdescr *td)
> +{
> +     if (td->cleanup)
> +             td->cleanup(td);
> +}
> diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/tools/testing/selftests/arm64/signal/test_signals_utils.h
> new file mode 100644
> index 000000000000..8658d1a7d4b9
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2019 ARM Limited */
> +
> +#ifndef __TEST_SIGNALS_UTILS_H__
> +#define __TEST_SIGNALS_UTILS_H__
> +
> +#include "test_signals.h"
> +
> +int test_setup(struct tdescr *td);
> +void test_cleanup(struct tdescr *td);
> +int test_run(struct tdescr *td);
> +void test_result(struct tdescr *td);
> +#endif
> diff --git a/tools/testing/selftests/arm64/signal/testcases/.gitignore b/tools/testing/selftests/arm64/signal/testcases/.gitignore
> new file mode 100644
> index 000000000000..8651272e3cfc
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/testcases/.gitignore
> @@ -0,0 +1 @@
> +mangle_pstate_invalid_compat_toggle
> diff --git a/tools/testing/selftests/arm64/signal/testcases/mangle_pstate_invalid_compat_toggle.c b/tools/testing/selftests/arm64/signal/testcases/mangle_pstate_invalid_compat_toggle.c
> new file mode 100644
> index 000000000000..971193e7501b
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/testcases/mangle_pstate_invalid_compat_toggle.c
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2019 ARM Limited */
> +
> +#include "test_signals_utils.h"
> +#include "testcases.h"
> +
> +static int mangle_invalid_pstate_run(struct tdescr *td, siginfo_t *si,
> +                                  ucontext_t *uc)
> +{
> +     ASSERT_GOOD_CONTEXT(uc);
> +
> +     /* This config should trigger a SIGSEGV by Kernel */
> +     uc->uc_mcontext.pstate ^= PSR_MODE32_BIT;
> +
> +     return 1;
> +}
> +
> +struct tdescr tde = {
> +             .sanity_disabled = true,
> +             .name = "MANGLE_PSTATE_INVALID_STATE_TOGGLE",
> +             .descr = "Mangling uc_mcontext with INVALID STATE_TOGGLE",
> +             .sig_trig = SIGUSR1,
> +             .sig_ok = SIGSEGV,
> +             .run = mangle_invalid_pstate_run,
> +};
> diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.c b/tools/testing/selftests/arm64/signal/testcases/testcases.c
> new file mode 100644
> index 000000000000..a59785092e1f
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.c
> @@ -0,0 +1,150 @@
> +#include "testcases.h"
> +
> +struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic,
> +                             size_t resv_sz, size_t *offset)
> +{
> +     size_t offs = 0;
> +     struct _aarch64_ctx *found = NULL;
> +
> +     if (!head || resv_sz < HDR_SZ)
> +             return found;
> +
> +     do {
> +             if (head->magic == magic) {
> +                     found = head;
> +                     break;
> +             }
> +             offs += head->size;
> +             head = GET_RESV_NEXT_HEAD(head);
> +     } while (offs < resv_sz - HDR_SZ);
> +
> +     if (offset)
> +             *offset = offs;
> +
> +     return found;
> +}
> +
> +bool validate_extra_context(struct extra_context *extra, char **err)
> +{
> +     struct _aarch64_ctx *term;
> +
> +     if (!extra || !err)
> +             return false;
> +
> +     fprintf(stderr, "Validating EXTRA...\n");
> +     term = GET_RESV_NEXT_HEAD(extra);
> +     if (!term || term->magic || term->size) {
> +             *err = "UN-Terminated EXTRA context";
> +             return false;
> +     }
> +     if (extra->datap & 0x0fUL)
> +             *err = "Extra DATAP misaligned";
> +     else if (extra->size & 0x0fUL)
> +             *err = "Extra SIZE misaligned";
> +     else if (extra->datap != (uint64_t)term + sizeof(*term))
> +             *err = "Extra DATAP misplaced (not contiguos)";
> +     if (*err)
> +             return false;
> +
> +     return true;
> +}
> +
> +bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
> +{
> +     bool terminated = false;
> +     size_t offs = 0;
> +     int flags = 0;
> +     struct extra_context *extra = NULL;
> +     struct _aarch64_ctx *head =
> +             (struct _aarch64_ctx *)uc->uc_mcontext.__reserved;
> +
> +     if (!err)
> +             return false;
> +     /* Walk till the end terminator verifying __reserved contents */
> +     while (head && !terminated && offs < resv_sz) {
> +             if ((uint64_t)head & 0x0fUL) {
> +                     *err = "Misaligned HEAD";
> +                     return false;
> +             }
> +
> +             switch (head->magic) {
> +                     case 0:
> +                             if (head->size)
> +                                     *err = "Bad size for MAGIC0";
> +                             else
> +                                     terminated = true;
> +                             break;
> +                     case FPSIMD_MAGIC:
> +                             if (flags & FPSIMD_CTX)
> +                                     *err = "Multiple FPSIMD_MAGIC";
> +                             else if (head->size !=
> +                                      sizeof(struct fpsimd_context))
> +                                     *err = "Bad size for fpsimd_context";
> +                             flags |= FPSIMD_CTX;
> +                             break;
> +                     case ESR_MAGIC:
> +                             if (head->size != sizeof(struct esr_context))
> +                                     fprintf(stderr,
> +                                             "Bad size for esr_context is not an error...just ignore.\n");
> +                             break;
> +                     case SVE_MAGIC:
> +                             if (flags & SVE_CTX)
> +                                     *err = "Multiple SVE_MAGIC";
> +                             else if (head->size !=
> +                                      sizeof(struct sve_context))
> +                                     *err = "Bad size for sve_context";
> +                             flags |= SVE_CTX;
> +                             break;
> +                     case EXTRA_MAGIC:
> +                             if (flags & EXTRA_CTX)
> +                                     *err = "Multiple EXTRA_MAGIC";
> +                             else if (head->size !=
> +                                      sizeof(struct extra_context))
> +                                     *err = "Bad size for extra_context";
> +                             flags |= EXTRA_CTX;
> +                             extra = (struct extra_context *)head;
> +                             break;
> +                     case KSFT_BAD_MAGIC:
> +                             /*
> +                              * This is a BAD magic header defined
> +                              * artificially by a testcase and surely
> +                              * unknown to the Kernel parse_user_sigframe().
> +                              * It MUST cause a Kernel induced SEGV
> +                              */
> +                             *err = "BAD MAGIC !";
> +                             break;
> +                     default:
> +                             /*
> +                              * A still unknown Magic: potentially freshly added
> +                              * to the Kernel code and still unknown to the
> +                              * tests.
> +                              */
> +                             fprintf(stdout,
> +                                     "SKIP Unknown MAGIC: 0x%X - Is KSFT arm64/signal up to date ?\n",
> +                                     head->magic);
> +                             break;
> +             }
> +
> +             if (*err)
> +                     return false;
> +
> +             offs += head->size;
> +             if (resv_sz - offs < sizeof(*head)) {
> +                     *err = "HEAD Overrun";
> +                     return false;
> +             }
> +
> +             if (flags & EXTRA_CTX)
> +                     if (!validate_extra_context(extra, err))
> +                             return false;
> +
> +             head = GET_RESV_NEXT_HEAD(head);
> +     }
> +
> +     if (terminated && !(flags & FPSIMD_CTX)) {
> +             *err = "Missing FPSIMD";
> +             return false;
> +     }
> +
> +     return true;
> +}
> diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.h b/tools/testing/selftests/arm64/signal/testcases/testcases.h
> new file mode 100644
> index 000000000000..624717c71b1d
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.h
> @@ -0,0 +1,83 @@
> +#ifndef __TESTCASES_H__
> +#define __TESTCASES_H__
> +
> +#include <stdio.h>
> +#include <stdbool.h>
> +#include <stdint.h>
> +#include <unistd.h>
> +#include <ucontext.h>
> +#include <assert.h>
> +
> +/* Architecture specific sigframe definitions */
> +#include <asm/sigcontext.h>
> +
> +#define FPSIMD_CTX   (1 << 0)
> +#define SVE_CTX              (1 << 1)
> +#define EXTRA_CTX    (1 << 2)
> +
> +#define KSFT_BAD_MAGIC       0xdeadbeef
> +
> +#define HDR_SZ \
> +     sizeof(struct _aarch64_ctx)
> +
> +#define GET_SF_RESV_HEAD(sf) \
> +     (struct _aarch64_ctx *)(&(sf).uc.uc_mcontext.__reserved)
> +
> +#define GET_SF_RESV_SIZE(sf) \
> +     sizeof((sf).uc.uc_mcontext.__reserved)
> +
> +#define GET_UCP_RESV_SIZE(ucp) \
> +     sizeof((ucp)->uc_mcontext.__reserved)
> +
> +#define ASSERT_BAD_CONTEXT(uc) do {                                  \
> +     char *err = NULL;                                               \
> +     assert(!validate_reserved((uc), GET_UCP_RESV_SIZE((uc)), &err));\
> +     if (err)                                                        \
> +             fprintf(stderr,                                         \
> +                     "Using badly built context - ERR: %s\n", err);  \
> +} while(0)
> +
> +#define ASSERT_GOOD_CONTEXT(uc) do {                                  \
> +     char *err = NULL;                                                \
> +     if (!validate_reserved((uc), GET_UCP_RESV_SIZE((uc)), &err)) {   \
> +             if (err)                                                 \
> +                     fprintf(stderr,                                  \
> +                             "Detected BAD context - ERR: %s\n", err);\
> +             assert(0);                                               \
> +     } else {                                                         \
> +             fprintf(stderr, "uc context validated.\n");              \
> +     }                                                                \
> +} while(0)
> +
> +/* head->size accounts both for payload and header _aarch64_ctx size ! */
> +#define GET_RESV_NEXT_HEAD(h) \
> +     (struct _aarch64_ctx *)((char *)(h) + (h)->size)
> +
> +struct fake_sigframe {
> +     siginfo_t       info;
> +     ucontext_t      uc;
> +};
> +
> +
> +bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err);
> +
> +bool validate_extra_context(struct extra_context *extra, char **err);
> +
> +struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic,
> +                             size_t resv_sz, size_t *offset);
> +
> +static inline struct _aarch64_ctx *get_terminator(struct _aarch64_ctx *head,
> +                                               size_t resv_sz,
> +                                               size_t *offset)
> +{
> +     return get_header(head, 0, resv_sz, offset);
> +}
> +
> +static inline void write_terminator_record(struct _aarch64_ctx *tail)
> +{
> +     if (tail) {
> +             tail->magic = 0;
> +             tail->size = 0;
> +     }
> +}
> +#endif
>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: [PATCH v3 19/21] ARM: dts: imx6/7-colibri: switch dr_mode to otg
From: Philippe Schenker @ 2019-08-12 12:53 UTC (permalink / raw)
  To: stefan@agner.ch, Marcel Ziswiler, festevam@gmail.com,
	devicetree@vger.kernel.org, mark.rutland@arm.com,
	Max Krummenacher, shawnguo@kernel.org, michal.vokac@ysoft.com,
	robh+dt@kernel.org
  Cc: linux-imx@nxp.com, s.hauer@pengutronix.de, kernel@pengutronix.de,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
In-Reply-To: <6fdbd56b71c1192c67b2e28accd611ced92de555.camel@toradex.com>

On Fri, 2019-08-09 at 15:50 +0000, Marcel Ziswiler wrote:
> Hi Philippe
> 
> On Wed, 2019-08-07 at 08:26 +0000, Philippe Schenker wrote:
> > In order for the otg ports, that these modules support, it is needed
> > that dr_mode is on otg. Switch to use that feature.
> 
> Isn't further extcon integration required for this to truly work?

Yes, I wasn't aware of that. I will drop this patch as this is a whole
new topic and will hopefully be a whole new patchset soon.

Philippe
> 
> > Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>
> > ---
> > 
> > Changes in v3: None
> > Changes in v2: None
> > 
> >  arch/arm/boot/dts/imx6qdl-colibri.dtsi | 2 +-
> >  arch/arm/boot/dts/imx7-colibri.dtsi    | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm/boot/dts/imx6qdl-colibri.dtsi
> > b/arch/arm/boot/dts/imx6qdl-colibri.dtsi
> > index 9a63debab0b5..6674198346d2 100644
> > --- a/arch/arm/boot/dts/imx6qdl-colibri.dtsi
> > +++ b/arch/arm/boot/dts/imx6qdl-colibri.dtsi
> > @@ -388,7 +388,7 @@
> >  &usbotg {
> >  	pinctrl-names = "default";
> >  	disable-over-current;
> > -	dr_mode = "peripheral";
> > +	dr_mode = "otg";
> >  	status = "disabled";
> >  };
> >  
> > diff --git a/arch/arm/boot/dts/imx7-colibri.dtsi
> > b/arch/arm/boot/dts/imx7-colibri.dtsi
> > index 67f5e0c87fdc..42478f1aa146 100644
> > --- a/arch/arm/boot/dts/imx7-colibri.dtsi
> > +++ b/arch/arm/boot/dts/imx7-colibri.dtsi
> > @@ -320,7 +320,7 @@
> >  };
> >  
> >  &usbotg1 {
> > -	dr_mode = "host";
> > +	dr_mode = "otg";
> >  };
> >  
> >  &usdhc1 {
> 
> Cheers
> 
> Marcel
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: Fwd: [CRON] Broken: ClangBuiltLinux/continuous-integration#895 (master - 2a3984b)
From: Will Deacon @ 2019-08-12 12:54 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Mark Rutland, Stephen Rothwell, pauld, Arnd Bergmann,
	Peter Zijlstra, Catalin Marinas, Will Deacon, linux-next,
	Mark Brown, tglx, dietmar.eggemann, Linux ARM
In-Reply-To: <CAKwvOd=2v0j5=-q9662xiv9ofrKfQm+04KUQAo1pEz+6MZXYMg@mail.gmail.com>

Hi Nick,

On Fri, Aug 09, 2019 at 02:21:21PM -0700, Nick Desaulniers wrote:
> Did anyone report any issue with last night's -next for arm64?
> 
> Some kind of deadlock in online_fair_sched_group.
> 
> [   15.256790] ================================
> [   15.257025] WARNING: inconsistent lock state
> [   15.257243] 5.3.0-rc3-next-20190809 #1 Not tainted
> [   15.257393] --------------------------------
> [   15.257526] inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage.
> [   15.258096] init/1 [HC0[0]:SC0[0]:HE1:SE1] takes:
> [   15.258522] (____ptrval____) (&rq->lock){?.-.}, at:
> online_fair_sched_group+0x78/0xe4
> [   15.259170] {IN-HARDIRQ-W} state was registered at:
> [   15.259658]   lock_acquire+0x1dc/0x228
> [   15.259940]   _raw_spin_lock+0x40/0x54
> [   15.260251]   scheduler_tick+0x50/0xfc
> [   15.260491]   update_process_times+0x80/0x98
> [   15.260677]   tick_periodic+0xd8/0xf0
> [   15.260910]   tick_handle_periodic+0x30/0x94
> [   15.261126]   arch_timer_handler_virt+0x34/0x40
> [   15.261332]   handle_percpu_devid_irq+0x1a8/0x3c4
> [   15.261495]   __handle_domain_irq+0x7c/0xbc
> [   15.261689]   gic_handle_irq+0x48/0xac
> [   15.261881]   el1_irq+0xbc/0x180

Ok, so we take rq_lock() off the back of a timer interrupt in irq context...

> [   15.267928]  dump_backtrace+0x0/0x140
> [   15.268159]  show_stack+0x14/0x1c
> [   15.268341]  dump_stack+0xa8/0x104
> [   15.268482]  mark_lock+0xda0/0xda8
> [   15.268728]  __lock_acquire+0x300/0x858
> [   15.268869]  lock_acquire+0x1dc/0x228
> [   15.269057]  _raw_spin_lock+0x40/0x54

... but also with irqs enabled when handling a syscall. Boom.

> [   15.269201]  online_fair_sched_group+0x78/0xe4
> [   15.269392]  sched_online_group+0x88/0xac
> [   15.269591]  sched_autogroup_create_attach+0xcc/0x12c
> [   15.269765]  ksys_setsid+0xe8/0xec
> [   15.269990]  __arm64_sys_setsid+0xc/0x18
> [   15.270178]  el0_svc_common+0x9c/0x15c
> [   15.270317]  el0_svc_handler+0x5c/0x64
> [   15.270493]  el0_svc+0x8/0xc
> 
> https://travis-ci.com/ClangBuiltLinux/continuous-integration/jobs/223856448
> 
> Guessing related to
> commit 6b8fd01b21f5 ("sched/fair: Use rq_lock/unlock in
> online_fair_sched_group")

Agreed. I think that patch should be using rq_lock_{irqsave,irqrestore}().

Looking at the list archive, it seems that this was already spotted last
week:

  https://lkml.kernel.org/r/dfc8f652-ca98-e30a-546f-e6a2df36e33a@arm.com

Although the proposal there disables irqs unconditionally, which matches
the old behaviour (prior to 6b8fd01b21f5) but feels a bit dodgy given that
the only caller (sched_online_group()) uses the save/restore variants.

Phil -- is there a fix queued for this somewhere?

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* Re: Fwd: [CRON] Broken: ClangBuiltLinux/continuous-integration#895 (master - 2a3984b)
From: Will Deacon @ 2019-08-12 12:55 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Mark Rutland, Stephen Rothwell, pauld, Arnd Bergmann,
	Peter Zijlstra, Catalin Marinas, Will Deacon, linux-next,
	Mark Brown, tglx, dietmar.eggemann, Linux ARM
In-Reply-To: <20190812125414.3zeysojdycfuowyy@willie-the-truck>

On Mon, Aug 12, 2019 at 01:54:14PM +0100, Will Deacon wrote:
> Phil -- is there a fix queued for this somewhere?

Ha, tglx beat me by two minutes. This is now fixed in -tip.

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* [0/2] arm64: E0PD support
From: Mark Brown @ 2019-08-12 12:57 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel

This series adds support for E0PD. We enable E0PD unconditionally where
present and on systems where all the CPUs in the system support E0PD we
will not automatically enable KPTI for KASLR. The integration with KPTI
is safe but not optimal for big.LITTLE systems where only some CPUs
support E0PD since for them it will still use KPTI even on the CPUs that
have E0PD, I've not yet come up with something I like for integrating
support for them with the command line overrides.

	arm64: Add initial support for E0PD
	arm64: Don't use KPTI where we have E0PD

 arch/arm64/Kconfig                     | 14 ++++++++++++++
 arch/arm64/include/asm/cpucaps.h       |  3 ++-
 arch/arm64/include/asm/pgtable-hwdef.h |  2 ++
 arch/arm64/include/asm/sysreg.h        |  1 +
 arch/arm64/kernel/cpufeature.c         | 29 ++++++++++++++++++++++++++++-
 5 files changed, 47 insertions(+), 2 deletions(-)


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply

* [PATCH 1/2] arm64: Add initial support for E0PD
From: Mark Brown @ 2019-08-12 12:57 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon; +Cc: Mark Brown, linux-arm-kernel
In-Reply-To: <20190812125738.17388-1-broonie@kernel.org>

Kernel Page Table Isolation (KPTI) is used to mitigate some speculation
based security issues by ensuring that the kernel is not mapped when
userspace is running but this approach is expensive and is incompatible
with SPE.  E0PD, introduced in the ARMv8.5 extensions, provides an
alternative to this which ensures that accesses from userspace to the
kernel's half of the memory map to always fault with constant time,
preventing timing attacks without requiring constant unmapping and
remapping or preventing legitimate accesses.

This initial patch does not yet integrate with KPTI, this will be dealt
with in followup patches.  Ideally we could ensure that by default we
don't use KPTI on CPUs where E0PD is present.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/Kconfig                     | 14 +++++++++++++
 arch/arm64/include/asm/cpucaps.h       |  3 ++-
 arch/arm64/include/asm/pgtable-hwdef.h |  2 ++
 arch/arm64/include/asm/sysreg.h        |  1 +
 arch/arm64/kernel/cpufeature.c         | 27 ++++++++++++++++++++++++++
 5 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index c6a978b0fb7c..3a6875a5bb99 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1409,6 +1409,20 @@ config ARM64_PTR_AUTH
 
 endmenu
 
+menu "ARMv8.5 architectural features"
+
+config ARM64_E0PD
+	bool "Enable support for E0PD"
+	default y
+	help
+	   E0PD (part of the ARMv8.5 extensions) ensures that EL0
+	   accesses made via TTBR1 always fault in constant time,
+	   providing the same guarantees as KPTI with lower overhead.
+
+	   This option enables E0PD where available.
+
+endmenu
+
 config ARM64_SVE
 	bool "ARM Scalable Vector Extension support"
 	default y
diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
index f19fe4b9acc4..f25388981075 100644
--- a/arch/arm64/include/asm/cpucaps.h
+++ b/arch/arm64/include/asm/cpucaps.h
@@ -52,7 +52,8 @@
 #define ARM64_HAS_IRQ_PRIO_MASKING		42
 #define ARM64_HAS_DCPODP			43
 #define ARM64_WORKAROUND_1463225		44
+#define ARM64_HAS_E0PD				45
 
-#define ARM64_NCAPS				45
+#define ARM64_NCAPS				46
 
 #endif /* __ASM_CPUCAPS_H */
diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h
index 3df60f97da1f..685842e52c3d 100644
--- a/arch/arm64/include/asm/pgtable-hwdef.h
+++ b/arch/arm64/include/asm/pgtable-hwdef.h
@@ -292,6 +292,8 @@
 #define TCR_HD			(UL(1) << 40)
 #define TCR_NFD0		(UL(1) << 53)
 #define TCR_NFD1		(UL(1) << 54)
+#define TCR_E0PD0		(UL(1) << 55)
+#define TCR_E0PD1		(UL(1) << 56)
 
 /*
  * TTBR.
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 1df45c7ffcf7..37a0926536d3 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -652,6 +652,7 @@
 #define ID_AA64MMFR1_VMIDBITS_16	2
 
 /* id_aa64mmfr2 */
+#define ID_AA64MMFR2_E0PD_SHIFT		60
 #define ID_AA64MMFR2_FWB_SHIFT		40
 #define ID_AA64MMFR2_AT_SHIFT		32
 #define ID_AA64MMFR2_LVA_SHIFT		16
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 95201e5ff5e1..4aa1d2026bef 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -211,6 +211,7 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr1[] = {
 };
 
 static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = {
+	ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_E0PD_SHIFT, 4, 0),
 	ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_FWB_SHIFT, 4, 0),
 	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_AT_SHIFT, 4, 0),
 	ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR2_LVA_SHIFT, 4, 0),
@@ -1236,6 +1237,19 @@ static void cpu_enable_address_auth(struct arm64_cpu_capabilities const *cap)
 }
 #endif /* CONFIG_ARM64_PTR_AUTH */
 
+#ifdef CONFIG_ARM64_E0PD
+static void cpu_enable_e0pd(struct arm64_cpu_capabilities const *cap)
+{
+	/*
+	 * The cpu_enable() callback gets called even on CPUs that
+	 * don't detect the feature so we need to verify if we can
+	 * enable.
+	 */
+	if (this_cpu_has_cap(ARM64_HAS_E0PD))
+		sysreg_clear_set(tcr_el1, 0, TCR_E0PD1);
+}
+#endif /* CONFIG_ARM64_E0PD */
+
 #ifdef CONFIG_ARM64_PSEUDO_NMI
 static bool enable_pseudo_nmi;
 
@@ -1551,6 +1565,19 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		.sign = FTR_UNSIGNED,
 		.min_field_value = 1,
 	},
+#endif
+#ifdef CONFIG_ARM64_E0PD
+	{
+		.desc = "E0PD",
+		.capability = ARM64_HAS_E0PD,
+		.type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE,
+		.sys_reg = SYS_ID_AA64MMFR2_EL1,
+		.sign = FTR_UNSIGNED,
+		.field_pos = ID_AA64MMFR2_E0PD_SHIFT,
+		.matches = has_cpuid_feature,
+		.min_field_value = 1,
+		.cpu_enable = cpu_enable_e0pd,
+	},
 #endif
 	{},
 };
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox