[PATCH] drm/bridge: icn6211: Convert to use maple tree register cache

2023-09-30 Thread Mark Brown
The maple tree register cache is based on a much more modern data structure
than the rbtree cache and makes optimisation choices which are probably
more appropriate for modern systems than those made by the rbtree cache.

Signed-off-by: Mark Brown 
---
 drivers/gpu/drm/bridge/chipone-icn6211.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/chipone-icn6211.c 
b/drivers/gpu/drm/bridge/chipone-icn6211.c
index d205e755e524..82d23e4df09e 100644
--- a/drivers/gpu/drm/bridge/chipone-icn6211.c
+++ b/drivers/gpu/drm/bridge/chipone-icn6211.c
@@ -197,7 +197,7 @@ static const struct regmap_config chipone_regmap_config = {
.val_bits = 8,
.rd_table = _dsi_readable_table,
.wr_table = _dsi_writeable_table,
-   .cache_type = REGCACHE_RBTREE,
+   .cache_type = REGCACHE_MAPLE,
.max_register = MIPI_ATE_STATUS(1),
 };
 

---
base-commit: 6465e260f48790807eef06b583b38ca9789b6072
change-id: 20230929-drm-chipone-maple-1d5e37ce5ed0

Best regards,
-- 
Mark Brown 



[PATCH] drm/bridge: tc358767: Convert to use maple tree register cache

2023-09-30 Thread Mark Brown
The maple tree register cache is based on a much more modern data structure
than the rbtree cache and makes optimisation choices which are probably
more appropriate for modern systems than those made by the rbtree cache.

Signed-off-by: Mark Brown 
---
 drivers/gpu/drm/bridge/tc358767.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/tc358767.c 
b/drivers/gpu/drm/bridge/tc358767.c
index b45bffab7c81..ef2e373606ba 100644
--- a/drivers/gpu/drm/bridge/tc358767.c
+++ b/drivers/gpu/drm/bridge/tc358767.c
@@ -2005,7 +2005,7 @@ static const struct regmap_config tc_regmap_config = {
.val_bits = 32,
.reg_stride = 4,
.max_register = PLL_DBG,
-   .cache_type = REGCACHE_RBTREE,
+   .cache_type = REGCACHE_MAPLE,
.readable_reg = tc_readable_reg,
.volatile_table = _volatile_table,
.writeable_reg = tc_writeable_reg,

---
base-commit: 6465e260f48790807eef06b583b38ca9789b6072
change-id: 20230929-drm-tc358767-maple-db143f667958

Best regards,
-- 
Mark Brown 



[PATCH] drm/rockchip: vop2: Convert to use maple tree register cache

2023-09-30 Thread Mark Brown
The maple tree register cache is based on a much more modern data structure
than the rbtree cache and makes optimisation choices which are probably
more appropriate for modern systems than those made by the rbtree cache.

Signed-off-by: Mark Brown 
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
index 583df4d22f7e..9f4470171cf4 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
@@ -2641,7 +2641,7 @@ static const struct regmap_config vop2_regmap_config = {
.max_register   = 0x3000,
.name   = "vop2",
.volatile_table = _volatile_table,
-   .cache_type = REGCACHE_RBTREE,
+   .cache_type = REGCACHE_MAPLE,
 };
 
 static int vop2_bind(struct device *dev, struct device *master, void *data)

---
base-commit: 6465e260f48790807eef06b583b38ca9789b6072
change-id: 20230929-drm-rockchip-maple-f6253d6a422e

Best regards,
-- 
Mark Brown 



[PATCH] drm/bridge: dpc3433: Convert to use maple tree register cache

2023-09-30 Thread Mark Brown
The maple tree register cache is based on a much more modern data structure
than the rbtree cache and makes optimisation choices which are probably
more appropriate for modern systems than those made by the rbtree cache.

Signed-off-by: Mark Brown 
---
 drivers/gpu/drm/bridge/ti-dlpc3433.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/ti-dlpc3433.c 
b/drivers/gpu/drm/bridge/ti-dlpc3433.c
index b65632ec7e7d..ca3348109bcd 100644
--- a/drivers/gpu/drm/bridge/ti-dlpc3433.c
+++ b/drivers/gpu/drm/bridge/ti-dlpc3433.c
@@ -100,7 +100,7 @@ static struct regmap_config dlpc_regmap_config = {
.max_register   = WR_DSI_PORT_EN,
.writeable_noinc_reg= dlpc_writeable_noinc_reg,
.volatile_table = _volatile_table,
-   .cache_type = REGCACHE_RBTREE,
+   .cache_type = REGCACHE_MAPLE,
.name   = "dlpc3433",
 };
 

---
base-commit: 6465e260f48790807eef06b583b38ca9789b6072
change-id: 20230929-drm-dlpc3433-maple-7e76ba8e59be

Best regards,
-- 
Mark Brown 



[PATCH] iosys-map: fix kernel-doc typos

2023-09-30 Thread Randy Dunlap
Correct spelling of "beginning".

Signed-off-by: Randy Dunlap 
Cc: Thomas Zimmermann 
Cc: dri-devel@lists.freedesktop.org
---
 include/linux/iosys-map.h |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -- a/include/linux/iosys-map.h b/include/linux/iosys-map.h
--- a/include/linux/iosys-map.h
+++ b/include/linux/iosys-map.h
@@ -426,7 +426,7 @@ static inline void iosys_map_memset(stru
  * iosys_map_rd_field - Read a member from a struct in the iosys_map
  *
  * @map__: The iosys_map structure
- * @struct_offset__:   Offset from the beggining of the map, where the struct
+ * @struct_offset__:   Offset from the beginning of the map, where the struct
  * is located
  * @struct_type__: The struct describing the layout of the mapping
  * @field__:   Member of the struct to read
@@ -494,7 +494,7 @@ static inline void iosys_map_memset(stru
  * iosys_map_wr_field - Write to a member of a struct in the iosys_map
  *
  * @map__: The iosys_map structure
- * @struct_offset__:   Offset from the beggining of the map, where the struct
+ * @struct_offset__:   Offset from the beginning of the map, where the struct
  * is located
  * @struct_type__: The struct describing the layout of the mapping
  * @field__:   Member of the struct to read


Re: [PATCH v4 07/10] drm/sched: Start submission before TDR in drm_sched_start

2023-09-30 Thread Luben Tuikov
On 2023-09-29 17:53, Luben Tuikov wrote:
> Hi,
> 
> On 2023-09-19 01:01, Matthew Brost wrote:
>> If the TDR is set to a very small value it can fire before the
>> submission is started in the function drm_sched_start. The submission is
>> expected to running when the TDR fires, fix this ordering so this
>> expectation is always met.
>>
>> Signed-off-by: Matthew Brost 
>> ---
>>  drivers/gpu/drm/scheduler/sched_main.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
>> b/drivers/gpu/drm/scheduler/sched_main.c
>> index 09ef07b9e9d5..a5cc9b6c2faa 100644
>> --- a/drivers/gpu/drm/scheduler/sched_main.c
>> +++ b/drivers/gpu/drm/scheduler/sched_main.c
>> @@ -684,10 +684,10 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, 
>> bool full_recovery)
>>  drm_sched_job_done(s_job, -ECANCELED);
>>  }
>>  
>> +drm_sched_submit_start(sched);
>> +
>>  if (full_recovery)
>>  drm_sched_start_timeout_unlocked(sched);
>> -
>> -drm_sched_submit_start(sched);
>>  }
>>  EXPORT_SYMBOL(drm_sched_start);
> 
> No.
> 
> A timeout timer should be started before we submit anything down to the 
> hardware.
> See Message-ID: ,
> and Message-ID: <8e5eab14-9e55-42c9-b6ea-02fcc5912...@amd.com>.
> 
> You shouldn't start TDR at an arbitrarily late time after job
> submission to the hardware. To close this, the timer is started
> before jobs are submitted to the hardware.
> 
> One possibility is to increase the timeout timer value.

If we went with this general change as we see here and in the subsequent 
patch--starting
the TDR _after_ submitting jobs for execution to the hardware--this is what 
generally happens,
1. submit one or many jobs for execution;
2. one or many jobs may execute, complete, hang, etc.;
3. at some arbitrary time in the future, start TDR.
Which means that the timeout doesn't necessarily track the time allotted for a 
job to finish
executing in the hardware. It ends up larger than intended.
-- 
Regards,
Luben



[Bug 201957] amdgpu: ring gfx timeout

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=201957

--- Comment #96 from KC (kco...@gmail.com) ---
The default is now -1.
https://unix.stackexchange.com/questions/756281/kernel-6-5-2-seems-to-have-amdgpu-crash-on-no-retry-page-fault
https://www.kernel.org/doc/html/v6.5/gpu/amdgpu/module-parameters.html

I set it to zero and I haven't had a single crash since (Fedora 39 beta,
Linux 6.5.5).
This one parameter change made my system entirely unusable (it would crash
very quickly after booting).


On Sat, Sep 30, 2023 at 9:35 PM  wrote:

> https://bugzilla.kernel.org/show_bug.cgi?id=201957
>
> --- Comment #95 from aspi...@gmail.com ---
> (In reply to KC from comment #94)
>
> Did you have it set to 1 previously? If not, I'm not sure if that was the
> silver bullet, because it looks like it defaults to 0.
> https://dri.freedesktop.org/docs/drm/gpu/amdgpu.html
>
> mcbp (int)
>
> It is used to enable mid command buffer preemption. (0 = disabled
> (default), 1
> = enabled)
>
> --
> You may reply to this email to add a comment.
>
> You are receiving this mail because:
> You are on the CC list for the bug.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 201957] amdgpu: ring gfx timeout

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=201957

--- Comment #95 from aspi...@gmail.com ---
(In reply to KC from comment #94)

Did you have it set to 1 previously? If not, I'm not sure if that was the
silver bullet, because it looks like it defaults to 0.
https://dri.freedesktop.org/docs/drm/gpu/amdgpu.html

mcbp (int)

It is used to enable mid command buffer preemption. (0 = disabled (default), 1
= enabled)

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 201957] amdgpu: ring gfx timeout

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=201957

--- Comment #94 from KC (kco...@gmail.com) ---
In my case the fix was adding amdgpu.mcbp=0 to the kernel parameters.

On Sat, Sep 30, 2023 at 8:57 PM  wrote:

> https://bugzilla.kernel.org/show_bug.cgi?id=201957
>
> aspi...@gmail.com changed:
>
>What|Removed |Added
>
> 
>  CC||aspi...@gmail.com
>
> --- Comment #93 from aspi...@gmail.com ---
> I have also been having this issue. It started occurring recently (last 2-3
> months). No other changes.
>
> Mostly lockups while gaming (yuzu), one lockup because of chrome.
>
> I was able to fix this issue by switching from HDMI to DP or DVI.
>
> --
> You may reply to this email to add a comment.
>
> You are receiving this mail because:
> You are on the CC list for the bug.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 201957] amdgpu: ring gfx timeout

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=201957

aspi...@gmail.com changed:

   What|Removed |Added

 CC||aspi...@gmail.com

--- Comment #93 from aspi...@gmail.com ---
I have also been having this issue. It started occurring recently (last 2-3
months). No other changes.

Mostly lockups while gaming (yuzu), one lockup because of chrome.

I was able to fix this issue by switching from HDMI to DP or DVI.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

Re: [PATCH 01/15] cdrom: Remove now superfluous sentinel element from ctl_table array

2023-09-30 Thread Phillip Potter
On Fri, Sep 29, 2023 at 02:17:30PM +0200, Joel Granados wrote:
> On Thu, Sep 28, 2023 at 03:36:55PM +0200, Greg Kroah-Hartman wrote:
> > On Thu, Sep 28, 2023 at 03:21:26PM +0200, Joel Granados via B4 Relay wrote:
> > > From: Joel Granados 
> > > 
> > > This commit comes at the tail end of a greater effort to remove the
> > > empty elements at the end of the ctl_table arrays (sentinels) which
> > > will reduce the overall build time size of the kernel and run time
> > > memory bloat by ~64 bytes per sentinel (further information Link :
> > > https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > > 
> > > Remove sentinel element from cdrom_table
> > > 
> > > Signed-off-by: Joel Granados 
> > > ---
> > >  drivers/cdrom/cdrom.c | 3 +--
> > >  1 file changed, 1 insertion(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
> > > index cc2839805983..451907ade389 100644
> > > --- a/drivers/cdrom/cdrom.c
> > > +++ b/drivers/cdrom/cdrom.c
> > > @@ -3654,8 +3654,7 @@ static struct ctl_table cdrom_table[] = {
> > >   .maxlen = sizeof(int),
> > >   .mode   = 0644,
> > >   .proc_handler   = cdrom_sysctl_handler
> > > - },
> > > - { }
> > > + }
> > 
> > You should have the final entry as "}," so as to make any future
> > additions to the list to only contain that entry, that's long been the
> > kernel style for lists like this.
> Will send a V2 with this included. Thx.
> 
> > 
> > So your patches will just remove one line, not 2 and add 1, making it a
> > smaller diff.
> indeed.
> 
> > 
> > thanks,
> > 
> > greg k-h
> 
> -- 
> 
> Joel Granados

Hi Joel,

Thank you for your patch. I look forward to seeing V2, and will be happy
to review it.

Regards,
Phil


Re: [PATCH 1/3] drm/tests: Fix kunit_release_action ctx argument

2023-09-30 Thread Maira Canal

Hi Arthur,

On 9/27/23 19:52, Arthur Grillo wrote:



On 27/09/23 19:47, Maira Canal wrote:

Hi Arthur,

On 9/20/23 03:11, Arthur Grillo wrote:

The kunit_action_platform_driver_unregister is added with
_platform_driver as ctx, but the kunit_release_action is called
pdev as ctx. Fix that by replacing it with _platform_driver.

Fixes: 4f2b0b583baa ("drm/tests: helpers: Switch to kunit actions")
Signed-off-by: Arthur Grillo 


Reviewed-by: Maíra Canal 

Do you need me to apply this patch to drm-misc-fixes?


Yes, please do, if possible.


Applied to drm-misc/drm-misc-fixes!

Thanks,
- Maíra



Thanks,
~Arthur Grillo



Best Regards,
- Maíra


---
   drivers/gpu/drm/tests/drm_kunit_helpers.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c 
b/drivers/gpu/drm/tests/drm_kunit_helpers.c
index 3d624ff2f651..3150dbc647ee 100644
--- a/drivers/gpu/drm/tests/drm_kunit_helpers.c
+++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c
@@ -118,7 +118,7 @@ void drm_kunit_helper_free_device(struct kunit *test, 
struct device *dev)
 kunit_release_action(test,
kunit_action_platform_driver_unregister,
- pdev);
+ _platform_driver);
   }
   EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device);
  


Re: [PATCH RESEND v3 0/2] Add KUnit tests for drm_fb_blit()

2023-09-30 Thread Maira Canal

Hi Arthur,

On 9/18/23 20:51, Arthur Grillo wrote:

This patchset tests the drm_fb_blit() function.

As this function can be used with already tested formats, the first
patch adds calls to drm_fb_blit() on the tests of supported formats.

Some supported formats were not yet covered by the existing tests
because they are only supported by drm_fb_blit(). The second patch
adds those format conversion tests.

Signed-off-by: Arthur Grillo 


Applied to drm-misc/drm-misc-next!

Thanks,
- Maíra


---
Changes in v3:
- Fix memset sizes to avoid out-of-bound access
- Link to v2: 
https://lore.kernel.org/r/20230905-final-gsoc-v2-0-b52e8cb06...@riseup.net

Changes in v2:
- Split the patch into two (Maíra Canal)
- Link to v1: 
https://lore.kernel.org/r/20230901-final-gsoc-v1-1-e310c7685...@riseup.net

---
Arthur Grillo (2):
   drm/tests: Add calls to drm_fb_blit() on supported format conversion 
tests
   drm/tests: Add new format conversion tests to better cover drm_fb_blit()

  drivers/gpu/drm/tests/drm_format_helper_test.c | 285 +
  1 file changed, 285 insertions(+)
---
base-commit: 37454bcbb68601c326b58ac45f508067047d791f
change-id: 20230901-final-gsoc-395a84443c8f

Best regards,


Re: ti-sn65dsi86 linux driver using dsi clock source for pll

2023-09-30 Thread Douglas Cooper
Hi Doug

That’s really good feedback. Thanks so much for taking the time to outline 
that. I’ll keep investigating and dig into those areas you mentioned.

I should have mentioned I’m also using the chip in conjunction with a full size 
dp connector which appears to be supported. Also, besides the pll not locking 
I’m seeing an issue with the chip reporting there is no display connected when 
it reads the SN_HPD_DISABLE_REG in the ti_sn_bridge_detect function. This seems 
bizarre considering it reports accurately when I remove the module and i2cget 
the value. I was thinking this could be a false negative if the driver is 
actively trying to configure it and it’s failing.

Doug C.
On Sep 29, 2023 at 7:25 PM -0400, Doug Anderson , wrote:
> Hi,
>
>
> On Fri, Sep 29, 2023 at 2:50 PM Laurent Pinchart
>  wrote:
> >
> > Hi Doug,
> >
> > CC'ing the dri-devel mailing list and Douglas Anderson.
> >
> > On Fri, Sep 29, 2023 at 03:36:52PM -0400, Douglas Cooper wrote:
> > > Hello,
> > >
> > > I've been trying to get the ti-sn65dsi86 to work with the dsi bus as the 
> > > clk
> > > source (refclk grounded) and have concluded that the pll is not getting 
> > > locked.
> > > Assuming the hardware is sound, have you ever seen this topology evaluated
> > > before? I'm questioning if that was a use case considered in the driver
> > > development. I will continue to actively investigate this.
> >
> > I don't think I've tested this mode, sorry. Maybe other people on the
> > list have some experience with this.
>
> I wouldn't suggest using this mode unless you have no choice.
>
> From my recollection we tried to use this mode on the very first
> prototype board of sdm845-cheza. It turned out to be _very_ limiting
> and it couldn't properly meet the timing requirements of the panel we
> were using. I think someone hacked things up temporarily by
> underdriving the panel at a much lower refresh rate and we eventually
> got it working, but we quickly abandoned trying to use ti-sn65dsi86 in
> this mode and threw away all of those old prototype boards.
>
> Since then, I've _tried_ to keep the code in ti-sn65dsi86 supporting
> this mode alive, but I'm not super confident in it.
>
> One thing that sticks out in particular in my mind is a bit of code in
> ti_sn65dsi86_resume(). You can see there that we don't call
> ti_sn65dsi86_enable_comms() if there's no reference clock. I believe
> that I added this code more out of guessing than anything else, since
> I don't recall this being well documented in the manual and, when the
> code was added, the early prototypes of cheza were long, long gone. I
> believe (?) I guessed this by seeing that I couldn't do things like
> AUX channel transfers without configuring the PLL and the PLL was
> based on the reference clock. Ah, here ya go. I documented my thought
> process in commit b137406d9679 ("drm/bridge: ti-sn65dsi86: If refclk,
> DP AUX can happen w/out pre-enable"). Though looking at it now, it
> seems odd that the code waiting for the PLL to lock doesn't happen
> until ti_sn_link_training(). Hmmm...
>
> If you have tested and see that things work differently than I
> guessed, feel free to send up a patch!
>
> One thing to note is that if, indeed, you need a reference clock
> before you can do AUX transactions then it's going to be really hard
> to make this work together with the generic "edp-panel". Specifically
> you'd need to turn on the MIPI source clock _before_ you can read the
> EDID of the panel, but without the EDID you won't really know what
> MIPI clock you should use. :-/
>
> -Doug


[PATCH] add kernel docs for dc_dmub_caps

2023-09-30 Thread Sagar Vashnav
Add kernel documentation for the dc_dmub_caps structure.

Signed-off-by: Sagar Vashnav 
---
 drivers/gpu/drm/amd/display/dc/dc.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/dc/dc.h 
b/drivers/gpu/drm/amd/display/dc/dc.h
index 8125839..14b4c50 100644
--- a/drivers/gpu/drm/amd/display/dc/dc.h
+++ b/drivers/gpu/drm/amd/display/dc/dc.h
@@ -208,6 +208,16 @@ struct dc_color_caps {
struct mpc_color_caps mpc;
 };
 
+/**
+ * struct dc_dmub_caps - DMUB (Display Microcontroller Unit) capabilities
+ * @psr: support for PSR (Power Saving State Residency)
+ * @mclk_sw: support for MCLK_SW (Memory Clock Switch)
+ * @subvp_psr: support for SUBVP PSR (Sub-Viewport Power Saving State 
Residency)
+ * @gecc_enable: GECC (Global Error Correcting Code) enablement.
+ *
+ * This structure describes the capabilities of the Display Microcontroller 
Unit (DMUB).
+ * It specifies whether certain features like PSR and MCLK_SW are supported.
+ */
 struct dc_dmub_caps {
bool psr;
bool mclk_sw;
-- 
2.34.1



Re: [PATCH v2] drm: rcar-du: turn rcar_du_group_get() into void and remove its return value check

2023-09-30 Thread Laurent Pinchart
Hi Alexandra,

On Wed, Sep 27, 2023 at 01:44:38PM +0300, Alexandra Diupina wrote:
> rcar_du_group_get() never returns a negative
> error code (always returns 0), so change the comment
> about returned value, turn function into void (return
> code of rcar_du_group_get has been redundant for a
> long time, so perhaps it's just not required) and
> remove redundant error path handling in rcar_du_crtc_get()
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.

Using tools to find issues is fine in principle, but not even
compile-testing the resulting patch before submitting it is not.

> Fixes: 0bb63534fdf3 ("drm: rcar-du: Perform the initial CRTC setup from 
> rcar_du_crtc_get()")
> Signed-off-by: Alexandra Diupina 
> ---
> v2: rcar_du_group_get() is turned into void and its return 
> value check is removed in rcar_du_crtc_get()
>  drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c  | 6 +-
>  drivers/gpu/drm/renesas/rcar-du/rcar_du_group.c | 5 +
>  2 files changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c 
> b/drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c
> index 7e175dbfd892..2be7c6e64d72 100644
> --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c
> +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_crtc.c
> @@ -565,17 +565,13 @@ static int rcar_du_crtc_get(struct rcar_du_crtc *rcrtc)
>   if (ret < 0)
>   goto error_clock;
>  
> - ret = rcar_du_group_get(rcrtc->group);
> - if (ret < 0)
> - goto error_group;
> + rcar_du_group_get(rcrtc->group);
>  
>   rcar_du_crtc_setup(rcrtc);
>   rcrtc->initialized = true;
>  
>   return 0;
>  
> -error_group:
> - clk_disable_unprepare(rcrtc->extclock);
>  error_clock:
>   clk_disable_unprepare(rcrtc->clock);
>   return ret;
> diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_group.c 
> b/drivers/gpu/drm/renesas/rcar-du/rcar_du_group.c
> index 2ccd2581f544..7113025dabff 100644
> --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_group.c
> +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_group.c
> @@ -199,10 +199,8 @@ static void rcar_du_group_setup(struct rcar_du_group 
> *rgrp)
>   * before accessing any hardware registers.
>   *
>   * This function must be called with the DRM mode_config lock held.
> - *
> - * Return 0 in case of success or a negative error code otherwise.
>   */
> -int rcar_du_group_get(struct rcar_du_group *rgrp)
> +void rcar_du_group_get(struct rcar_du_group *rgrp)
>  {
>   if (rgrp->use_count)
>   goto done;
> @@ -211,7 +209,6 @@ int rcar_du_group_get(struct rcar_du_group *rgrp)
>  
>  done:
>   rgrp->use_count++;
> - return 0;
>  }
>  
>  /*

-- 
Regards,

Laurent Pinchart


[Bug 216806] [Raven Ridge] console disappears after framebuffer device loads

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=216806

--- Comment #7 from Balazs Vinarz (viniba...@gmail.com) ---
It turned out with the latest kernel the amd_iommu=off did the trick.
https://gitlab.freedesktop.org/drm/amd/-/issues/2884

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[PATCH] dt-bindings: display: fsl, imx6-hdmi: Change to 'unevaluatedProperties: false'

2023-09-30 Thread Fabio Estevam
From: Fabio Estevam 

fsl,imx6-hdmi.yaml makes a reference to synopsys,dw-hdmi.yaml.

The 'interrupts'and 'reg' properties are described in synopsys,dw-hdmi.yaml,
so use 'unevaluatedProperties: false' so that these two properties can
be accepted. 

This fixes the following schema warnings:

hdmi@12: 'interrupts', 'reg' do not match any of the regexes: 
'pinctrl-[0-9]+'
from schema $id: http://devicetree.org/schemas/display/imx/fsl,imx6-hdmi.yaml#

Signed-off-by: Fabio Estevam 
---
 .../devicetree/bindings/display/imx/fsl,imx6-hdmi.yaml  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/display/imx/fsl,imx6-hdmi.yaml 
b/Documentation/devicetree/bindings/display/imx/fsl,imx6-hdmi.yaml
index af7fe9c4d196..7979cf07f119 100644
--- a/Documentation/devicetree/bindings/display/imx/fsl,imx6-hdmi.yaml
+++ b/Documentation/devicetree/bindings/display/imx/fsl,imx6-hdmi.yaml
@@ -87,7 +87,7 @@ required:
   - interrupts
   - ports
 
-additionalProperties: false
+unevaluatedProperties: false
 
 examples:
   - |
-- 
2.34.1



[Bug 216806] [Raven Ridge] console disappears after framebuffer device loads

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=216806

Artem S. Tashkinov (a...@gmx.com) changed:

   What|Removed |Added

 Status|NEEDINFO|CLOSED
 Resolution|--- |ANSWERED

--- Comment #6 from Artem S. Tashkinov (a...@gmx.com) ---
Please repost here:

https://gitlab.freedesktop.org/drm/amd/-/issues

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 201957] amdgpu: ring gfx timeout

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=201957

Artem S. Tashkinov (a...@gmx.com) changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |ANSWERED

--- Comment #92 from Artem S. Tashkinov (a...@gmx.com) ---
AMDGPU development is on its own bug tracker:

https://gitlab.freedesktop.org/drm/amd/-/issues

If you're still affected, check for existing bug reports and if there are none,
please repost over there.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 217958] Crashes if I boot the computer with the second display connected to HDMI output

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=217958

Artem S. Tashkinov (a...@gmx.com) changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |ANSWERED

--- Comment #1 from Artem S. Tashkinov (a...@gmx.com) ---
This bug reports belongs to https://gitlab.freedesktop.org/drm/amd/-/issues

Please repost.

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

Re: [PATCH 06/15] platform/x86/amd/pmf: Add support to get inputs from other subsystems

2023-09-30 Thread Shyam Sundar S K



On 9/26/2023 10:38 PM, Ilpo Järvinen wrote:
> On Fri, 22 Sep 2023, Shyam Sundar S K wrote:
> 
>> PMF driver sends changing inputs from each subystem to TA for evaluating
>> the conditions in the policy binary.
>>
>> Add initial support of plumbing in the PMF driver for Smart PC to get
>> information from other subsystems in the kernel.
>>
>> Signed-off-by: Shyam Sundar S K 
>> ---
>>  drivers/platform/x86/amd/pmf/Makefile |   2 +-
>>  drivers/platform/x86/amd/pmf/pmf.h|  18 
>>  drivers/platform/x86/amd/pmf/spc.c| 118 ++
>>  drivers/platform/x86/amd/pmf/tee-if.c |   3 +
>>  4 files changed, 140 insertions(+), 1 deletion(-)
>>  create mode 100644 drivers/platform/x86/amd/pmf/spc.c
>>
>> diff --git a/drivers/platform/x86/amd/pmf/Makefile 
>> b/drivers/platform/x86/amd/pmf/Makefile
>> index d2746ee7369f..6b26e48ce8ad 100644
>> --- a/drivers/platform/x86/amd/pmf/Makefile
>> +++ b/drivers/platform/x86/amd/pmf/Makefile
>> @@ -7,4 +7,4 @@
>>  obj-$(CONFIG_AMD_PMF) += amd-pmf.o
>>  amd-pmf-objs := core.o acpi.o sps.o \
>>  auto-mode.o cnqf.o \
>> -tee-if.o
>> +tee-if.o spc.o
>> diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
>> b/drivers/platform/x86/amd/pmf/pmf.h
>> index 81acf2a37366..e64b4d285624 100644
>> --- a/drivers/platform/x86/amd/pmf/pmf.h
>> +++ b/drivers/platform/x86/amd/pmf/pmf.h
>> @@ -146,6 +146,21 @@ struct smu_pmf_metrics {
>>  u16 infra_gfx_maxfreq; /* in MHz */
>>  u16 skin_temp; /* in centi-Celsius */
>>  u16 device_state;
>> +u16 curtemp; /* in centi-Celsius */
>> +u16 filter_alpha_value;
>> +u16 avg_gfx_clkfrequency;
>> +u16 avg_fclk_frequency;
>> +u16 avg_gfx_activity;
>> +u16 avg_socclk_frequency;
>> +u16 avg_vclk_frequency;
>> +u16 avg_vcn_activity;
>> +u16 avg_dram_reads;
>> +u16 avg_dram_writes;
>> +u16 avg_socket_power;
>> +u16 avg_core_power[2];
>> +u16 avg_core_c0residency[16];
>> +u16 spare1;
>> +u32 metrics_counter;
>>  } __packed;
>>  
>>  enum amd_stt_skin_temp {
>> @@ -592,4 +607,7 @@ extern const struct attribute_group 
>> cnqf_feature_attribute_group;
>>  int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev);
>>  void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev);
>>  int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev);
>> +
>> +/* Smart PC - TA interfaces */
>> +void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct 
>> ta_pmf_enact_table *in);
>>  #endif /* PMF_H */
>> diff --git a/drivers/platform/x86/amd/pmf/spc.c 
>> b/drivers/platform/x86/amd/pmf/spc.c
>> new file mode 100644
>> index ..08159cd5f853
>> --- /dev/null
>> +++ b/drivers/platform/x86/amd/pmf/spc.c
>> @@ -0,0 +1,118 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * AMD Platform Management Framework Driver - Smart PC Capabilities
>> + *
>> + * Copyright (c) 2023, Advanced Micro Devices, Inc.
>> + * All Rights Reserved.
>> + *
>> + * Authors: Shyam Sundar S K 
>> + *  Patil Rajesh Reddy 
>> + */
>> +
>> +#include 
>> +#include 
>> +#include "pmf.h"
>> +
>> +static void amd_pmf_get_smu_info(struct amd_pmf_dev *dev, struct 
>> ta_pmf_enact_table *in)
>> +{
>> +u16 max, avg = 0;
>> +int i;
>> +
>> +memset(dev->buf, 0, sizeof(dev->m_table));
>> +amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, 0, 7, NULL);
>> +memcpy(>m_table, dev->buf, sizeof(dev->m_table));
>> +
>> +in->ev_info.socket_power = dev->m_table.apu_power + 
>> dev->m_table.dgpu_power;
>> +in->ev_info.skin_temperature = dev->m_table.skin_temp;
>> +
>> +/* get the avg C0 residency of all the cores */
>> +for (i = 0; i < ARRAY_SIZE(dev->m_table.avg_core_c0residency); i++)
>> +avg += dev->m_table.avg_core_c0residency[i];
> 
> Is this safe from overflow?

Yes I think. Can you elaborate a bit more please if there a overflow
and I am missing it?

Thanks,
Shyam

> 
>> +
>> +/* get the max C0 residency of all the cores */
>> +max = dev->m_table.avg_core_c0residency[0];
>> +for (i = 1; i < ARRAY_SIZE(dev->m_table.avg_core_c0residency); i++) {
>> +if (dev->m_table.avg_core_c0residency[i] > max)
>> +max = dev->m_table.avg_core_c0residency[i];
>> +}
>> +
>> +in->ev_info.avg_c0residency = avg / 
>> ARRAY_SIZE(dev->m_table.avg_core_c0residency);
>> +in->ev_info.max_c0residency = max;
>> +in->ev_info.gfx_busy = dev->m_table.avg_gfx_activity;
>> +}
>> +
>> +static const char * const pmf_battery_supply_name[] = {
>> +"BATT",
>> +"BAT0",
>> +};
>> +
>> +static int get_battery_prop(enum power_supply_property prop)
>> +{
>> +union power_supply_propval value;
>> +struct power_supply *psy;
>> +int i, ret = -EINVAL;
>> +
>> +for (i = 0; i < ARRAY_SIZE(pmf_battery_supply_name); i++) {
>> +psy = power_supply_get_by_name(pmf_battery_supply_name[i]);
>> +if (!psy)
>> +continue;
>> +
>> +ret = 

[PATCH v2 15/16] platform/x86/amd/pmf: Add PMF-AMDSFH interface for HPD

2023-09-30 Thread Shyam Sundar S K
From: Basavaraj Natikar 

AMDSFH has information about the User presence information via the Human
Presence Detection (HPD) sensor which is part of the AMD sensor fusion hub.
Add PMF and AMDSFH interface to get this information.

Co-developed-by: Shyam Sundar S K 
Signed-off-by: Shyam Sundar S K 
Signed-off-by: Basavaraj Natikar 
---
 drivers/hid/amd-sfh-hid/amd_sfh_common.h  |  5 
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c | 11 
 .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c| 28 +++
 drivers/platform/x86/amd/pmf/Kconfig  |  1 +
 drivers/platform/x86/amd/pmf/spc.c| 21 ++
 include/linux/amd-pmf-io.h| 20 -
 6 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_common.h 
b/drivers/hid/amd-sfh-hid/amd_sfh_common.h
index 2643bb14fee2..cd57037bf217 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_common.h
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_common.h
@@ -37,6 +37,10 @@ struct amd_mp2_sensor_info {
dma_addr_t dma_address;
 };
 
+struct sfh_dev_status {
+   bool is_hpd_present;
+};
+
 struct amd_mp2_dev {
struct pci_dev *pdev;
struct amdtp_cl_data *cl_data;
@@ -47,6 +51,7 @@ struct amd_mp2_dev {
struct amd_input_data in_data;
/* mp2 active control status */
u32 mp2_acs;
+   struct sfh_dev_status dev_en;
 };
 
 struct amd_mp2_ops {
diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c 
b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c
index e9c6413af24a..3dc652d41d7d 100644
--- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c
+++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c
@@ -73,6 +73,12 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev 
*privdata)
int i, status;
 
for (i = 0; i < cl_data->num_hid_devices; i++) {
+   switch (cl_data->sensor_idx[i]) {
+   case HPD_IDX:
+   privdata->dev_en.is_hpd_present = false;
+   break;
+   }
+
if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
privdata->mp2_ops->stop(privdata, 
cl_data->sensor_idx[i]);
status = amd_sfh_wait_for_response
@@ -178,6 +184,11 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev 
*privdata)
rc = amdtp_hid_probe(i, cl_data);
if (rc)
goto cleanup;
+   switch (cl_data->sensor_idx[i]) {
+   case HPD_IDX:
+   privdata->dev_en.is_hpd_present = true;
+   break;
+   }
}
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], 
get_sensor_name(cl_data->sensor_idx[i]),
diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c 
b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c
index 4f81ef2d4f56..7637da0dec6f 100644
--- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c
+++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c
@@ -7,11 +7,14 @@
  *
  * Author: Basavaraj Natikar 
  */
+#include 
 #include 
 #include 
 
 #include "amd_sfh_interface.h"
 
+static struct amd_mp2_dev *emp2;
+
 static int amd_sfh_wait_response(struct amd_mp2_dev *mp2, u8 sid, u32 cmd_id)
 {
struct sfh_cmd_response cmd_resp;
@@ -76,4 +79,29 @@ static struct amd_mp2_ops amd_sfh_ops = {
 void sfh_interface_init(struct amd_mp2_dev *mp2)
 {
mp2->mp2_ops = _sfh_ops;
+   emp2 = mp2;
+}
+
+static int amd_sfh_hpd_info(u8 *user_present)
+{
+   if (emp2 && emp2->dev_en.is_hpd_present) {
+   struct hpd_status hpdstatus;
+
+   hpdstatus.val = readl(emp2->mmio + AMD_C2P_MSG(4));
+   *user_present = hpdstatus.shpd.presence;
+   return 0;
+   }
+   return -ENODEV;
+}
+
+int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op)
+{
+   if (sfh_info) {
+   switch (op) {
+   case MT_HPD:
+   return amd_sfh_hpd_info(_info->user_present);
+   }
+   }
+   return -EINVAL;
 }
+EXPORT_SYMBOL_GPL(amd_get_sfh_info);
diff --git a/drivers/platform/x86/amd/pmf/Kconfig 
b/drivers/platform/x86/amd/pmf/Kconfig
index 0cd08f9ab51b..ca4f7d5a11b2 100644
--- a/drivers/platform/x86/amd/pmf/Kconfig
+++ b/drivers/platform/x86/amd/pmf/Kconfig
@@ -11,6 +11,7 @@ config AMD_PMF
select ACPI_PLATFORM_PROFILE
depends on AMDTEE
depends on DRM_AMDGPU
+   depends on AMD_SFH_HID
help
  This driver provides support for the AMD Platform Management 
Framework.
  The goal is to enhance end user experience by making AMD PCs smarter,
diff --git a/drivers/platform/x86/amd/pmf/spc.c 
b/drivers/platform/x86/amd/pmf/spc.c
index 40872afb99e5..4fd1953167ed 100644
--- 

[PATCH v2 16/16] platform/x86/amd/pmf: Add PMF-AMDSFH interface for ALS

2023-09-30 Thread Shyam Sundar S K
From: Basavaraj Natikar 

AMDSFH has information about the Ambient light via the Ambient
Light Sensor (ALS) which is part of the AMD sensor fusion hub.
Add PMF and AMDSFH interface to get this information.

make amd_sfh_float_to_int() as non-static function so that this can
be called outside of the current file.

Co-developed-by: Shyam Sundar S K 
Signed-off-by: Shyam Sundar S K 
Signed-off-by: Basavaraj Natikar 
---
 drivers/hid/amd-sfh-hid/amd_sfh_common.h  |  1 +
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c |  2 +-
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c |  6 ++
 .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c| 20 +++
 .../amd-sfh-hid/sfh1_1/amd_sfh_interface.h|  1 +
 drivers/platform/x86/amd/pmf/spc.c|  7 +++
 include/linux/amd-pmf-io.h|  2 ++
 7 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_common.h 
b/drivers/hid/amd-sfh-hid/amd_sfh_common.h
index cd57037bf217..a1950bc6e6ce 100644
--- a/drivers/hid/amd-sfh-hid/amd_sfh_common.h
+++ b/drivers/hid/amd-sfh-hid/amd_sfh_common.h
@@ -39,6 +39,7 @@ struct amd_mp2_sensor_info {
 
 struct sfh_dev_status {
bool is_hpd_present;
+   bool is_als_present;
 };
 
 struct amd_mp2_dev {
diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c 
b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c
index 47a87b28e00e..dbc8c6943ca1 100644
--- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c
+++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c
@@ -132,7 +132,7 @@ static void get_common_inputs(struct common_input_property 
*common, int report_i
common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM;
 }
 
-static int amd_sfh_float_to_int(u32 flt32_val)
+int amd_sfh_float_to_int(u32 flt32_val)
 {
int fraction, shift, mantissa, sign, exp, zeropre;
 
diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c 
b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c
index 3dc652d41d7d..f2890d329459 100644
--- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c
+++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c
@@ -77,6 +77,9 @@ static int amd_sfh_hid_client_deinit(struct amd_mp2_dev 
*privdata)
case HPD_IDX:
privdata->dev_en.is_hpd_present = false;
break;
+   case ALS_IDX:
+   privdata->dev_en.is_als_present = false;
+   break;
}
 
if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
@@ -188,6 +191,9 @@ static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev 
*privdata)
case HPD_IDX:
privdata->dev_en.is_hpd_present = true;
break;
+   case ALS_IDX:
+   privdata->dev_en.is_als_present = true;
+   break;
}
}
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",
diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c 
b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c
index 7637da0dec6f..48a7a450e029 100644
--- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c
+++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.c
@@ -94,12 +94,32 @@ static int amd_sfh_hpd_info(u8 *user_present)
return -ENODEV;
 }
 
+static int amd_sfh_als_info(u32 *ambient_light)
+{
+   if (emp2 && emp2->dev_en.is_als_present) {
+   struct sfh_als_data als_data;
+   void __iomem *sensoraddr;
+
+   sensoraddr = emp2->vsbase +
+   (ALS_IDX * SENSOR_DATA_MEM_SIZE_DEFAULT) +
+   OFFSET_SENSOR_DATA_DEFAULT;
+   memcpy_fromio(_data, sensoraddr, sizeof(struct 
sfh_als_data));
+   *ambient_light = amd_sfh_float_to_int(als_data.lux);
+
+   return 0;
+   }
+
+   return -ENODEV;
+}
+
 int amd_get_sfh_info(struct amd_sfh_info *sfh_info, enum sfh_message_type op)
 {
if (sfh_info) {
switch (op) {
case MT_HPD:
return amd_sfh_hpd_info(_info->user_present);
+   case MT_ALS:
+   return amd_sfh_als_info(_info->ambient_light);
}
}
return -EINVAL;
diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h 
b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h
index 9d31d5b510eb..7ecddad430e4 100644
--- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h
+++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_interface.h
@@ -149,6 +149,7 @@ struct hpd_status {
};
 };
 
+int amd_sfh_float_to_int(u32 flt32_val);
 void sfh_interface_init(struct amd_mp2_dev *mp2);
 void amd_sfh1_1_set_desc_ops(struct amd_mp2_ops *mp2_ops);
 #endif
diff --git a/drivers/platform/x86/amd/pmf/spc.c 
b/drivers/platform/x86/amd/pmf/spc.c
index 4fd1953167ed..10c35291e7ae 100644
--- 

[PATCH v2 14/16] HID: amd_sfh: rename float_to_int() to amd_sfh_float_to_int()

2023-09-30 Thread Shyam Sundar S K
From: Basavaraj Natikar 

Current amd_sfh driver has float_to_int() to convert units from
float to int. This is fine until this function gets called outside of
the current scope of file.

Add a prefix "amd_sfh" to float_to_int() so that function represents
the driver name. This function will be called by multiple callers in the
next patch.

Co-developed-by: Shyam Sundar S K 
Signed-off-by: Shyam Sundar S K 
Signed-off-by: Basavaraj Natikar 
---
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c | 22 +--
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c 
b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c
index 06bdcf072d10..47a87b28e00e 100644
--- a/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c
+++ b/drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c
@@ -132,7 +132,7 @@ static void get_common_inputs(struct common_input_property 
*common, int report_i
common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM;
 }
 
-static int float_to_int(u32 flt32_val)
+static int amd_sfh_float_to_int(u32 flt32_val)
 {
int fraction, shift, mantissa, sign, exp, zeropre;
 
@@ -200,9 +200,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, 
int report_id,
 OFFSET_SENSOR_DATA_DEFAULT;
memcpy_fromio(_data, sensoraddr, sizeof(struct 
sfh_accel_data));
get_common_inputs(_input.common_property, report_id);
-   acc_input.in_accel_x_value = 
float_to_int(accel_data.acceldata.x) / 100;
-   acc_input.in_accel_y_value = 
float_to_int(accel_data.acceldata.y) / 100;
-   acc_input.in_accel_z_value = 
float_to_int(accel_data.acceldata.z) / 100;
+   acc_input.in_accel_x_value = 
amd_sfh_float_to_int(accel_data.acceldata.x) / 100;
+   acc_input.in_accel_y_value = 
amd_sfh_float_to_int(accel_data.acceldata.y) / 100;
+   acc_input.in_accel_z_value = 
amd_sfh_float_to_int(accel_data.acceldata.z) / 100;
memcpy(input_report, _input, sizeof(acc_input));
report_size = sizeof(acc_input);
break;
@@ -211,9 +211,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, 
int report_id,
 OFFSET_SENSOR_DATA_DEFAULT;
memcpy_fromio(_data, sensoraddr, sizeof(struct 
sfh_gyro_data));
get_common_inputs(_input.common_property, report_id);
-   gyro_input.in_angel_x_value = 
float_to_int(gyro_data.gyrodata.x) / 1000;
-   gyro_input.in_angel_y_value = 
float_to_int(gyro_data.gyrodata.y) / 1000;
-   gyro_input.in_angel_z_value = 
float_to_int(gyro_data.gyrodata.z) / 1000;
+   gyro_input.in_angel_x_value = 
amd_sfh_float_to_int(gyro_data.gyrodata.x) / 1000;
+   gyro_input.in_angel_y_value = 
amd_sfh_float_to_int(gyro_data.gyrodata.y) / 1000;
+   gyro_input.in_angel_z_value = 
amd_sfh_float_to_int(gyro_data.gyrodata.z) / 1000;
memcpy(input_report, _input, sizeof(gyro_input));
report_size = sizeof(gyro_input);
break;
@@ -222,9 +222,9 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, 
int report_id,
 OFFSET_SENSOR_DATA_DEFAULT;
memcpy_fromio(_data, sensoraddr, sizeof(struct 
sfh_mag_data));
get_common_inputs(_input.common_property, report_id);
-   magno_input.in_magno_x = float_to_int(mag_data.magdata.x) / 100;
-   magno_input.in_magno_y = float_to_int(mag_data.magdata.y) / 100;
-   magno_input.in_magno_z = float_to_int(mag_data.magdata.z) / 100;
+   magno_input.in_magno_x = 
amd_sfh_float_to_int(mag_data.magdata.x) / 100;
+   magno_input.in_magno_y = 
amd_sfh_float_to_int(mag_data.magdata.y) / 100;
+   magno_input.in_magno_z = 
amd_sfh_float_to_int(mag_data.magdata.z) / 100;
magno_input.in_magno_accuracy = mag_data.accuracy / 100;
memcpy(input_report, _input, sizeof(magno_input));
report_size = sizeof(magno_input);
@@ -234,7 +234,7 @@ static u8 get_input_rep(u8 current_index, int sensor_idx, 
int report_id,
 OFFSET_SENSOR_DATA_DEFAULT;
memcpy_fromio(_data, sensoraddr, sizeof(struct 
sfh_als_data));
get_common_inputs(_input.common_property, report_id);
-   als_input.illuminance_value = float_to_int(als_data.lux);
+   als_input.illuminance_value = 
amd_sfh_float_to_int(als_data.lux);
report_size = sizeof(als_input);
memcpy(input_report, _input, sizeof(als_input));
break;
-- 
2.25.1



[PATCH v2 12/16] platform/x86/amd/pmf: Add PMF-AMDGPU get interface

2023-09-30 Thread Shyam Sundar S K
In order to provide GPU inputs to TA for the Smart PC solution to work, we
need to have interface between the PMF driver and the AMDGPU driver.

Add the initial code path for get interface from AMDGPU.

Co-developed-by: Mario Limonciello 
Signed-off-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/gpu/drm/amd/amdgpu/Makefile |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c | 136 
 drivers/platform/x86/amd/pmf/Kconfig|   1 +
 drivers/platform/x86/amd/pmf/core.c |   1 +
 drivers/platform/x86/amd/pmf/pmf.h  |   3 +
 drivers/platform/x86/amd/pmf/spc.c  |  13 +++
 drivers/platform/x86/amd/pmf/tee-if.c   |  28 +
 include/linux/amd-pmf-io.h  |  35 ++
 9 files changed, 220 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c
 create mode 100644 include/linux/amd-pmf-io.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 384b798a9bad..7fafccefbd7a 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -86,6 +86,8 @@ amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
 
 amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o
 
+amdgpu-$(CONFIG_AMD_PMF) += amdgpu_pmf.o
+
 # add asic specific block
 amdgpu-$(CONFIG_DRM_AMDGPU_CIK)+= cik.o cik_ih.o \
dce_v8_0.o gfx_v7_0.o cik_sdma.o uvd_v4_2.o vce_v2_0.o
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index dc2d53081e80..475f3e248f35 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c
new file mode 100644
index ..45a079c028d3
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2023 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+
+ * * Author: Shyam Sundar S K 
+ */
+
+#include 
+#include "amdgpu.h"
+
+int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf)
+{
+   struct drm_device *drm_dev = pci_get_drvdata(pmf->gpu_dev);
+   struct drm_mode_config *mode_config = _dev->mode_config;
+   struct amdgpu_device *adev = drm_to_adev(drm_dev);
+   struct drm_connector_list_iter iter;
+   struct drm_connector *connector;
+   int i = 0;
+
+   /* reset the count to zero */
+   pmf->display_count = 0;
+   if (!(adev->flags & AMD_IS_APU)) {
+   DRM_ERROR("PMF-AMDGPU interface not supported\n");
+   return -ENODEV;
+   }
+
+   mutex_lock(_config->mutex);
+   drm_connector_list_iter_begin(drm_dev, );
+   drm_for_each_connector_iter(connector, ) {
+   if (connector->status == connector_status_connected) {
+   pmf->con_status[i] = connector->status;
+   pmf->connector_type[i] = connector->connector_type;
+   pmf->display_count++;
+   }
+   i++;
+
+   if (i > MAX_SUPPORTED)
+   break;
+   }
+   drm_connector_list_iter_end();
+   mutex_unlock(_config->mutex);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(amd_pmf_get_gfx_data);
+
+static int amd_pmf_gpu_get_cur_state(struct thermal_cooling_device 
*cooling_dev,
+unsigned long *state)
+{
+   struct backlight_device *bd;
+
+   if (!acpi_video_backlight_use_native())
+   return -ENODEV;
+
+   bd = backlight_device_get_by_type(BACKLIGHT_RAW);
+   if (!bd)
+   return -ENODEV;
+
+   *state = backlight_get_brightness(bd);
+
+   return 0;
+}
+
+static int amd_pmf_gpu_get_max_state(struct thermal_cooling_device 
*cooling_dev,
+

[PATCH v2 13/16] platform/x86/amd/pmf: Add PMF-AMDGPU set interface

2023-09-30 Thread Shyam Sundar S K
For the Smart PC Solution to fully work, it has to enact to the actions
coming from TA. Add the initial code path for set interface to AMDGPU.

Change amd_pmf_apply_policies() return type, so that it can return
errors when the call to retrieve information from amdgpu fails.

Co-developed-by: Mario Limonciello 
Signed-off-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c | 18 ++
 drivers/platform/x86/amd/pmf/pmf.h  |  2 ++
 drivers/platform/x86/amd/pmf/tee-if.c   | 21 +++--
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c
index 45a079c028d3..803e6bb66914 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c
@@ -61,6 +61,23 @@ int amd_pmf_get_gfx_data(struct amd_gpu_pmf_data *pmf)
 }
 EXPORT_SYMBOL_GPL(amd_pmf_get_gfx_data);
 
+static int amd_pmf_gpu_set_cur_state(struct thermal_cooling_device 
*cooling_dev,
+unsigned long state)
+{
+   struct backlight_device *bd;
+
+   if (!acpi_video_backlight_use_native())
+   return -ENODEV;
+
+   bd = backlight_device_get_by_type(BACKLIGHT_RAW);
+   if (!bd)
+   return -ENODEV;
+
+   backlight_device_set_brightness(bd, state);
+
+   return 0;
+}
+
 static int amd_pmf_gpu_get_cur_state(struct thermal_cooling_device 
*cooling_dev,
 unsigned long *state)
 {
@@ -101,6 +118,7 @@ static int amd_pmf_gpu_get_max_state(struct 
thermal_cooling_device *cooling_dev,
 static const struct thermal_cooling_device_ops bd_cooling_ops = {
.get_max_state = amd_pmf_gpu_get_max_state,
.get_cur_state = amd_pmf_gpu_get_cur_state,
+   .set_cur_state = amd_pmf_gpu_set_cur_state,
 };
 
 int amd_pmf_gpu_init(struct amd_gpu_pmf_data *pmf)
diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index 97cadd080742..59329308ed8e 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -75,6 +75,7 @@
 #define PMF_POLICY_STT_SKINTEMP_APU7
 #define PMF_POLICY_STT_SKINTEMP_HS28
 #define PMF_POLICY_SYSTEM_STATE9
+#define PMF_POLICY_DISPLAY_BRIGHTNESS  12
 #define PMF_POLICY_P3T 38
 
 /* TA macros */
@@ -482,6 +483,7 @@ enum ta_pmf_error_type {
 };
 
 struct pmf_action_table {
+   unsigned long display_brightness;
enum system_state system_state;
unsigned long spl; /* in mW */
unsigned long sppt; /* in mW */
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c 
b/drivers/platform/x86/amd/pmf/tee-if.c
index 9216c2065fd3..d20821c914c7 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -78,9 +78,11 @@ static int amd_pmf_update_uevents(struct amd_pmf_dev *dev, 
u16 event)
return 0;
 }
 
-static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct 
ta_pmf_enact_result *out)
+static int amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct 
ta_pmf_enact_result *out)
 {
+   struct thermal_cooling_device *cdev = dev->gfx_data.cooling_dev;
unsigned long val, event = 0;
+   unsigned long state;
int idx;
 
for (idx = 0; idx < out->actions_count; idx++) {
@@ -160,8 +162,21 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev 
*dev, struct ta_pmf_enact_
dev->prev_data->system_state = 0;
}
break;
+
+   case PMF_POLICY_DISPLAY_BRIGHTNESS:
+   if (!dev->gfx_data.gpu_dev_en)
+   return -ENODEV;
+
+   cdev->ops->get_cur_state(cdev, );
+   if (state != val) {
+   cdev->ops->set_cur_state(cdev, val);
+   dev_dbg(dev->dev, "update DISPLAY_BRIGHTNESS : 
%lu\n", val);
+   }
+   break;
}
}
+
+   return 0;
 }
 
 static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev)
@@ -198,7 +213,9 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev)
amd_pmf_dump_ta_inputs(dev, in);
dev_dbg(dev->dev, "action count:%u result:%x\n", 
out->actions_count,
ta_sm->pmf_result);
-   amd_pmf_apply_policies(dev, out);
+   ret = amd_pmf_apply_policies(dev, out);
+   if (ret)
+   return ret;
}
 
return 0;
-- 
2.25.1



[PATCH v2 10/16] platform/x86/amd/pmf: Add capability to sideload of policy binary

2023-09-30 Thread Shyam Sundar S K
A policy binary is OS agnostic, and the same policies are expected to work
across the OSes.  At times it becomes difficult to debug when the policies
inside the policy binaries starts to misbehave. Add a way to sideload such
policies independently to debug them via a debugfs entry.

Reported-by: kernel test robot 
Closes: 
https://lore.kernel.org/oe-kbuild-all/202309251031.awddkrgs-...@intel.com/
Reviewed-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/pmf.h|  1 +
 drivers/platform/x86/amd/pmf/tee-if.c | 68 +++
 2 files changed, 69 insertions(+)

diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index 2ad5ece47601..b862cd4f902e 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -218,6 +218,7 @@ struct amd_pmf_dev {
bool cnqf_supported;
struct notifier_block pwr_src_notifier;
/* Smart PC solution builder */
+   struct dentry *esbin;
unsigned char *policy_buf;
u32 policy_sz;
struct tee_context *tee_ctx;
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c 
b/drivers/platform/x86/amd/pmf/tee-if.c
index b0711b2f8c8f..01f974b55a6a 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -8,6 +8,7 @@
  * Author: Shyam Sundar S K 
  */
 
+#include 
 #include 
 #include 
 #include "pmf.h"
@@ -16,9 +17,15 @@
 
 /* Policy binary actions sampling frequency (in ms) */
 static int pb_actions_ms = 1000;
+/* Sideload policy binaries to debug policy failures */
+static bool pb_side_load;
+
 #ifdef CONFIG_AMD_PMF_DEBUG
 module_param(pb_actions_ms, int, 0644);
 MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency 
(default = 1000ms)");
+
+module_param(pb_side_load, bool, 0444);
+MODULE_PARM_DESC(pb_side_load, "Sideload policy binaries debug policy 
failures");
 #endif
 
 static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d,
@@ -268,6 +275,61 @@ static int amd_pmf_start_policy_engine(struct amd_pmf_dev 
*dev)
return 0;
 }
 
+#ifdef CONFIG_AMD_PMF_DEBUG
+static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf,
+  size_t length, loff_t *pos)
+{
+   struct amd_pmf_dev *dev = filp->private_data;
+   int ret;
+
+   /* policy binary size cannot exceed POLICY_BUF_MAX_SZ */
+   if (length > POLICY_BUF_MAX_SZ || length == 0)
+   return -EINVAL;
+
+   dev->policy_sz = length;
+   if (copy_from_user(dev->policy_buf, buf, dev->policy_sz))
+   return -EFAULT;
+
+   ret = amd_pmf_start_policy_engine(dev);
+   if (ret)
+   return -EINVAL;
+
+   return length;
+}
+
+static const struct file_operations pb_fops = {
+   .write = amd_pmf_get_pb_data,
+   .open = simple_open,
+};
+
+static int amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry 
*debugfs_root)
+{
+   struct dentry *file = NULL;
+
+   dev->esbin = debugfs_create_dir("pb", debugfs_root);
+   if (IS_ERR(dev->esbin))
+   return -EINVAL;
+
+   file = debugfs_create_file("update_policy", 0644, dev->esbin, dev, 
_fops);
+   if (!file)
+   return -EINVAL;
+
+   return 0;
+}
+
+static void amd_pmf_remove_pb(struct amd_pmf_dev *dev)
+{
+   debugfs_remove_recursive(dev->esbin);
+}
+#else
+static int amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry 
*debugfs_root)
+{
+   return 0;
+}
+
+static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) {}
+#endif
+
 static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev)
 {
dev->policy_buf = kzalloc(dev->policy_sz, GFP_KERNEL);
@@ -280,6 +342,9 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev)
 
memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz);
 
+   if (pb_side_load)
+   amd_pmf_open_pb(dev, dev->dbgfs_dir);
+
return amd_pmf_start_policy_engine(dev);
 }
 
@@ -388,6 +453,9 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev)
 
 void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev)
 {
+   if (pb_side_load)
+   amd_pmf_remove_pb(dev);
+
kfree(dev->prev_data);
kfree(dev->policy_buf);
cancel_delayed_work_sync(>pb_work);
-- 
2.25.1



[PATCH v2 11/16] platform/x86/amd/pmf: dump policy binary data

2023-09-30 Thread Shyam Sundar S K
Sometimes policy binary retrieved from the BIOS maybe incorrect that can
end up in failing to enable the Smart PC solution feature.

Use print_hex_dump_debug() to dump the policy binary in hex, so that we
debug the issues related to the binary even before sending that to TA.

Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/tee-if.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/platform/x86/amd/pmf/tee-if.c 
b/drivers/platform/x86/amd/pmf/tee-if.c
index 01f974b55a6a..d16bdecfd43a 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -290,6 +290,9 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const 
char __user *buf,
if (copy_from_user(dev->policy_buf, buf, dev->policy_sz))
return -EFAULT;
 
+   print_hex_dump_debug("(pb):  ", DUMP_PREFIX_OFFSET, 16, 1, 
dev->policy_buf,
+dev->policy_sz, false);
+
ret = amd_pmf_start_policy_engine(dev);
if (ret)
return -EINVAL;
@@ -341,6 +344,10 @@ static int amd_pmf_get_bios_buffer(struct amd_pmf_dev *dev)
return -ENOMEM;
 
memcpy(dev->policy_buf, dev->policy_base, dev->policy_sz);
+#ifdef CONFIG_AMD_PMF_DEBUG
+   print_hex_dump_debug("(pb):  ", DUMP_PREFIX_OFFSET, 16, 1, 
dev->policy_buf,
+dev->policy_sz, false);
+#endif
 
if (pb_side_load)
amd_pmf_open_pb(dev, dev->dbgfs_dir);
-- 
2.25.1



[PATCH v2 09/16] platform/x86/amd/pmf: Add facility to dump TA inputs

2023-09-30 Thread Shyam Sundar S K
PMF driver sends constant inputs to TA which its gets via the other
subsystems in the kernel. To debug certain TA issues knowing what inputs
being sent to TA becomes critical. Add debug facility to the driver which
can isolate Smart PC and TA related issues.

Also, make source_as_str() as non-static function as this helper is
required outside of sps.c file.

Reviewed-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/pmf.h|  3 +++
 drivers/platform/x86/amd/pmf/spc.c| 37 +++
 drivers/platform/x86/amd/pmf/sps.c|  2 +-
 drivers/platform/x86/amd/pmf/tee-if.c |  1 +
 4 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index 34778192432e..2ad5ece47601 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -595,6 +595,7 @@ int apmf_get_static_slider_granular(struct amd_pmf_dev 
*pdev,
 bool is_pprof_balanced(struct amd_pmf_dev *pmf);
 int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev);
 
+const char *source_as_str(unsigned int state);
 
 int apmf_update_fan_idx(struct amd_pmf_dev *pdev, bool manual, u32 idx);
 int amd_pmf_set_sps_power_limits(struct amd_pmf_dev *pmf);
@@ -625,4 +626,6 @@ int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev);
 
 /* Smart PC - TA interfaces */
 void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct 
ta_pmf_enact_table *in);
+void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table 
*in);
+
 #endif /* PMF_H */
diff --git a/drivers/platform/x86/amd/pmf/spc.c 
b/drivers/platform/x86/amd/pmf/spc.c
index 3113bde051d9..3aee78629cce 100644
--- a/drivers/platform/x86/amd/pmf/spc.c
+++ b/drivers/platform/x86/amd/pmf/spc.c
@@ -14,6 +14,43 @@
 #include 
 #include "pmf.h"
 
+#ifdef CONFIG_AMD_PMF_DEBUG
+static const char *ta_slider_as_str(unsigned int state)
+{
+   switch (state) {
+   case TA_BEST_PERFORMANCE:
+   return "PERFORMANCE";
+   case TA_BETTER_PERFORMANCE:
+   return "BALANCED";
+   case TA_BEST_BATTERY:
+   return "POWER_SAVER";
+   default:
+   return "Unknown TA Slider State";
+   }
+}
+
+void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table 
*in)
+{
+   dev_dbg(dev->dev, " TA inputs START \n");
+   dev_dbg(dev->dev, "Slider State : %s\n", 
ta_slider_as_str(in->ev_info.power_slider));
+   dev_dbg(dev->dev, "Power Source : %s\n", 
source_as_str(in->ev_info.power_source));
+   dev_dbg(dev->dev, "Battery Percentage : %u\n", 
in->ev_info.bat_percentage);
+   dev_dbg(dev->dev, "Designed Battery Capacity : %u\n", 
in->ev_info.bat_design);
+   dev_dbg(dev->dev, "Fully Charged Capacity : %u\n", 
in->ev_info.full_charge_capacity);
+   dev_dbg(dev->dev, "Drain Rate : %d\n", in->ev_info.drain_rate);
+   dev_dbg(dev->dev, "Socket Power : %u\n", in->ev_info.socket_power);
+   dev_dbg(dev->dev, "Skin Temperature : %u\n", 
in->ev_info.skin_temperature);
+   dev_dbg(dev->dev, "Avg C0 Residency : %u\n", 
in->ev_info.avg_c0residency);
+   dev_dbg(dev->dev, "Max C0 Residency : %u\n", 
in->ev_info.max_c0residency);
+   dev_dbg(dev->dev, "GFX Busy : %u\n", in->ev_info.gfx_busy);
+   dev_dbg(dev->dev, "Connected Display Count : %u\n", 
in->ev_info.monitor_count);
+   dev_dbg(dev->dev, "LID State : %s\n", in->ev_info.lid_state ? "Close" : 
"Open");
+   dev_dbg(dev->dev, " TA inputs END \n");
+}
+#else
+void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table 
*in) {}
+#endif
+
 static void amd_pmf_get_smu_info(struct amd_pmf_dev *dev, struct 
ta_pmf_enact_table *in)
 {
u16 max, avg = 0;
diff --git a/drivers/platform/x86/amd/pmf/sps.c 
b/drivers/platform/x86/amd/pmf/sps.c
index a70e67749be3..13e36b52dfe8 100644
--- a/drivers/platform/x86/amd/pmf/sps.c
+++ b/drivers/platform/x86/amd/pmf/sps.c
@@ -27,7 +27,7 @@ static const char *slider_as_str(unsigned int state)
}
 }
 
-static const char *source_as_str(unsigned int state)
+const char *source_as_str(unsigned int state)
 {
switch (state) {
case POWER_SOURCE_AC:
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c 
b/drivers/platform/x86/amd/pmf/tee-if.c
index 961011530c1b..b0711b2f8c8f 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -187,6 +187,7 @@ static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev)
}
 
if (ta_sm->pmf_result == TA_PMF_TYPE_SUCCESS && out->actions_count) {
+   amd_pmf_dump_ta_inputs(dev, in);
dev_dbg(dev->dev, "action count:%u result:%x\n", 
out->actions_count,
ta_sm->pmf_result);
amd_pmf_apply_policies(dev, out);
-- 
2.25.1



[PATCH v2 08/16] platform/x86/amd/pmf: Add support to update system state

2023-09-30 Thread Shyam Sundar S K
PMF driver based on the output actions from the TA can request to update
the system states like entering s0i3, lock screen etc. by generating
an uevent. Based on the udev rules set in the userspace the event id
matching the uevent shall get updated accordingly using the systemctl.

Sample udev rules under Documentation/admin-guide/pmf.rst.

Reported-by: kernel test robot 
Closes: 
https://lore.kernel.org/oe-kbuild-all/202309260515.5xbr6n0g-...@intel.com/
Signed-off-by: Shyam Sundar S K 
---
 Documentation/admin-guide/index.rst   |  1 +
 Documentation/admin-guide/pmf.rst | 25 
 drivers/platform/x86/amd/pmf/pmf.h|  9 ++
 drivers/platform/x86/amd/pmf/tee-if.c | 41 ++-
 4 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/admin-guide/pmf.rst

diff --git a/Documentation/admin-guide/index.rst 
b/Documentation/admin-guide/index.rst
index 43ea35613dfc..fb40a1f6f79e 100644
--- a/Documentation/admin-guide/index.rst
+++ b/Documentation/admin-guide/index.rst
@@ -119,6 +119,7 @@ configure specific aspects of kernel behavior to your 
liking.
parport
perf-security
pm/index
+   pmf
pnp
rapidio
ras
diff --git a/Documentation/admin-guide/pmf.rst 
b/Documentation/admin-guide/pmf.rst
new file mode 100644
index ..90072add511e
--- /dev/null
+++ b/Documentation/admin-guide/pmf.rst
@@ -0,0 +1,25 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Set udev rules for PMF Smart PC Builder
+---
+
+AMD PMF(Platform Management Framework) Smart PC Solution builder has to set 
the system states
+like S0i3, Screen lock, hibernate etc, based on the output actions provided by 
the PMF
+TA (Trusted Application).
+
+In order for this to work the PMF driver generates a uevent for userspace to 
react to. Below are
+sample udev rules that can facilitate this experience when a machine has PMF 
Smart PC solution builder
+enabled.
+
+Please add the following line(s) to
+``/etc/udev/rules.d/99-local.rules``::
+
+DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="1", 
RUN+="/usr/bin/systemctl suspend"
+DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="2", 
RUN+="/usr/bin/systemctl hibernate"
+DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="3", 
RUN+="/bin/loginctl lock-sessions"
+
+EVENT_ID values:
+1= Put the system to S0i3/S2Idle
+2= Put the system to hibernate
+3= Lock the screen
+
diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index d5e410c41e81..34778192432e 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -73,6 +73,7 @@
 #define PMF_POLICY_STT_MIN 6
 #define PMF_POLICY_STT_SKINTEMP_APU7
 #define PMF_POLICY_STT_SKINTEMP_HS28
+#define PMF_POLICY_SYSTEM_STATE9
 #define PMF_POLICY_P3T 38
 
 /* TA macros */
@@ -439,6 +440,13 @@ struct apmf_dyn_slider_output {
 } __packed;
 
 /* Smart PC - TA internals */
+enum system_state {
+   SYSTEM_STATE__S0i3 = 1,
+   SYSTEM_STATE__S4,
+   SYSTEM_STATE__SCREEN_LOCK,
+   SYSTEM_STATE__MAX
+};
+
 enum ta_slider {
TA_BEST_BATTERY, /* Best Battery */
TA_BETTER_BATTERY, /* Better Battery */
@@ -470,6 +478,7 @@ enum ta_pmf_error_type {
 };
 
 struct pmf_action_table {
+   enum system_state system_state;
unsigned long spl; /* in mW */
unsigned long sppt; /* in mW */
unsigned long sppt_apuonly; /* in mW */
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c 
b/drivers/platform/x86/amd/pmf/tee-if.c
index 315e3d2eacdf..961011530c1b 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -24,6 +24,20 @@ MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions 
sampling frequency (defau
 static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d,
0xb1, 0x2d, 0xc5, 0x29, 0xb1, 
0x3d, 0x85, 0x43);
 
+static const char *amd_pmf_uevent_as_str(unsigned int state)
+{
+   switch (state) {
+   case SYSTEM_STATE__S0i3:
+   return "S0i3";
+   case SYSTEM_STATE__S4:
+   return "S4";
+   case SYSTEM_STATE__SCREEN_LOCK:
+   return "SCREEN_LOCK";
+   default:
+   return "Unknown Smart PC event";
+   }
+}
+
 static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd,
 struct tee_ioctl_invoke_arg *arg,
 struct tee_param *param)
@@ -42,9 +56,23 @@ static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, 
int cmd,
param[0].u.memref.shm_offs = 0;
 }
 
+static int amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event)
+{
+   char *envp[2] = {};
+
+   envp[0] = kasprintf(GFP_KERNEL, 

[PATCH v2 07/16] platform/x86/amd/pmf: Add support update p3t limit

2023-09-30 Thread Shyam Sundar S K
P3T (Peak Package Power Limit) is a metric within the SMU controller
that can influence the power limits. Add support from the driver
to update P3T limits accordingly.

Reviewed-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/pmf.h| 3 +++
 drivers/platform/x86/amd/pmf/tee-if.c | 8 
 2 files changed, 11 insertions(+)

diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index 60b11455dadf..d5e410c41e81 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -49,6 +49,7 @@
 #define GET_STT_MIN_LIMIT  0x1F
 #define GET_STT_LIMIT_APU  0x20
 #define GET_STT_LIMIT_HS2  0x21
+#define SET_P3T0x23 /* P3T: Peak Package Power 
Limit */
 
 /* OS slider update notification */
 #define DC_BEST_PERF   0
@@ -72,6 +73,7 @@
 #define PMF_POLICY_STT_MIN 6
 #define PMF_POLICY_STT_SKINTEMP_APU7
 #define PMF_POLICY_STT_SKINTEMP_HS28
+#define PMF_POLICY_P3T 38
 
 /* TA macros */
 #define PMF_TA_IF_VERSION_MAJOR1
@@ -475,6 +477,7 @@ struct pmf_action_table {
unsigned long stt_minlimit; /* in mW */
unsigned long stt_skintemp_apu; /* in C */
unsigned long stt_skintemp_hs2; /* in C */
+   unsigned long p3t_limit; /* in mW */
 };
 
 /* Input conditions */
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c 
b/drivers/platform/x86/amd/pmf/tee-if.c
index 1fc3b57f8d78..315e3d2eacdf 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -105,6 +105,14 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev 
*dev, struct ta_pmf_enact_
dev->prev_data->stt_skintemp_hs2 = val;
}
break;
+
+   case PMF_POLICY_P3T:
+   if (dev->prev_data->p3t_limit != val) {
+   amd_pmf_send_cmd(dev, SET_P3T, false, val, 
NULL);
+   dev_dbg(dev->dev, "update P3T : %lu\n", val);
+   dev->prev_data->p3t_limit = val;
+   }
+   break;
}
}
 }
-- 
2.25.1



[PATCH v2 06/16] platform/x86/amd/pmf: Add support to get inputs from other subsystems

2023-09-30 Thread Shyam Sundar S K
PMF driver sends changing inputs from each subystem to TA for evaluating
the conditions in the policy binary.

Add initial support of plumbing in the PMF driver for Smart PC to get
information from other subsystems in the kernel.

Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/Makefile |   2 +-
 drivers/platform/x86/amd/pmf/pmf.h|  18 
 drivers/platform/x86/amd/pmf/spc.c| 119 ++
 drivers/platform/x86/amd/pmf/tee-if.c |   3 +
 4 files changed, 141 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/x86/amd/pmf/spc.c

diff --git a/drivers/platform/x86/amd/pmf/Makefile 
b/drivers/platform/x86/amd/pmf/Makefile
index d2746ee7369f..6b26e48ce8ad 100644
--- a/drivers/platform/x86/amd/pmf/Makefile
+++ b/drivers/platform/x86/amd/pmf/Makefile
@@ -7,4 +7,4 @@
 obj-$(CONFIG_AMD_PMF) += amd-pmf.o
 amd-pmf-objs := core.o acpi.o sps.o \
auto-mode.o cnqf.o \
-   tee-if.o
+   tee-if.o spc.o
diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index 6f4b6f4ecee4..60b11455dadf 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -149,6 +149,21 @@ struct smu_pmf_metrics {
u16 infra_gfx_maxfreq; /* in MHz */
u16 skin_temp; /* in centi-Celsius */
u16 device_state;
+   u16 curtemp; /* in centi-Celsius */
+   u16 filter_alpha_value;
+   u16 avg_gfx_clkfrequency;
+   u16 avg_fclk_frequency;
+   u16 avg_gfx_activity;
+   u16 avg_socclk_frequency;
+   u16 avg_vclk_frequency;
+   u16 avg_vcn_activity;
+   u16 avg_dram_reads;
+   u16 avg_dram_writes;
+   u16 avg_socket_power;
+   u16 avg_core_power[2];
+   u16 avg_core_c0residency[16];
+   u16 spare1;
+   u32 metrics_counter;
 } __packed;
 
 enum amd_stt_skin_temp {
@@ -595,4 +610,7 @@ extern const struct attribute_group 
cnqf_feature_attribute_group;
 int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev);
 void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev);
 int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev);
+
+/* Smart PC - TA interfaces */
+void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct 
ta_pmf_enact_table *in);
 #endif /* PMF_H */
diff --git a/drivers/platform/x86/amd/pmf/spc.c 
b/drivers/platform/x86/amd/pmf/spc.c
new file mode 100644
index ..3113bde051d9
--- /dev/null
+++ b/drivers/platform/x86/amd/pmf/spc.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD Platform Management Framework Driver - Smart PC Capabilities
+ *
+ * Copyright (c) 2023, Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Authors: Shyam Sundar S K 
+ *  Patil Rajesh Reddy 
+ */
+
+#include 
+#include 
+#include 
+#include "pmf.h"
+
+static void amd_pmf_get_smu_info(struct amd_pmf_dev *dev, struct 
ta_pmf_enact_table *in)
+{
+   u16 max, avg = 0;
+   int i;
+
+   memset(dev->buf, 0, sizeof(dev->m_table));
+   amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, 0, 7, NULL);
+   memcpy(>m_table, dev->buf, sizeof(dev->m_table));
+
+   in->ev_info.socket_power = dev->m_table.apu_power + 
dev->m_table.dgpu_power;
+   in->ev_info.skin_temperature = dev->m_table.skin_temp;
+
+   /* get the avg C0 residency of all the cores */
+   for (i = 0; i < ARRAY_SIZE(dev->m_table.avg_core_c0residency); i++)
+   avg += dev->m_table.avg_core_c0residency[i];
+
+   /* get the max C0 residency of all the cores */
+   max = dev->m_table.avg_core_c0residency[0];
+   for (i = 1; i < ARRAY_SIZE(dev->m_table.avg_core_c0residency); i++) {
+   if (dev->m_table.avg_core_c0residency[i] > max)
+   max = dev->m_table.avg_core_c0residency[i];
+   }
+
+   in->ev_info.avg_c0residency = avg / 
ARRAY_SIZE(dev->m_table.avg_core_c0residency);
+   in->ev_info.max_c0residency = max;
+   in->ev_info.gfx_busy = dev->m_table.avg_gfx_activity;
+}
+
+static const char * const pmf_battery_supply_name[] = {
+   "BATT",
+   "BAT0",
+};
+
+static int get_battery_prop(enum power_supply_property prop)
+{
+   union power_supply_propval value;
+   struct power_supply *psy;
+   int i, ret = -EINVAL;
+
+   for (i = 0; i < ARRAY_SIZE(pmf_battery_supply_name); i++) {
+   psy = power_supply_get_by_name(pmf_battery_supply_name[i]);
+   if (!psy)
+   continue;
+
+   ret = power_supply_get_property(psy, prop, );
+   if (ret) {
+   power_supply_put(psy);
+   return ret;
+   }
+   }
+
+   return value.intval;
+}
+
+static int amd_pmf_get_battery_info(struct amd_pmf_dev *dev, struct 
ta_pmf_enact_table *in)
+{
+   int val;
+
+   val = get_battery_prop(POWER_SUPPLY_PROP_PRESENT);
+   if (val != 1)
+   return -EINVAL;
+
+   in->ev_info.bat_percentage = 

[PATCH v2 05/16] platform/x86/amd/pmf: change amd_pmf_init_features() call sequence

2023-09-30 Thread Shyam Sundar S K
To sideload pmf policy binaries, the Smart PC Solution Builder provides a
debugfs file called "update_policy"; that gets created under a new debugfs
directory called "pb" and this new directory has to be associated with
existing parent directory for PMF driver called "amd_pmf".

In the current code structure, amd_pmf_dbgfs_register() is called after
amd_pmf_init_features(). This will not help when the Smart PC builder
feature has to be assoicated to the parent directory.

Hence change the order of amd_pmf_dbgfs_register() and call it before
amd_pmf_init_features() so that when the Smart PC init happens, it has the
parent debugfs directory to get itself hooked.

Reviewed-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/amd/pmf/core.c 
b/drivers/platform/x86/amd/pmf/core.c
index 787f25511191..39671d245e96 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -435,9 +435,9 @@ static int amd_pmf_probe(struct platform_device *pdev)
 
apmf_acpi_init(dev);
platform_set_drvdata(pdev, dev);
+   amd_pmf_dbgfs_register(dev);
amd_pmf_init_features(dev);
apmf_install_handler(dev);
-   amd_pmf_dbgfs_register(dev);
 
dev_info(dev->dev, "registered PMF device successfully\n");
 
-- 
2.25.1



[PATCH v2 04/16] platform/x86/amd/pmf: Add support for PMF Policy Binary

2023-09-30 Thread Shyam Sundar S K
PMF Policy binary is a encrypted and signed binary that will be part
of the BIOS. PMF driver via the ACPI interface checks the existence
of Smart PC bit. If the advertised bit is found, PMF driver walks
the acpi namespace to find out the policy binary size and the address
which has to be passed to the TA during the TA init sequence.

The policy binary is comprised of inputs (or the events) and outputs
(or the actions). With the PMF ecosystem, OEMs generate the policy
binary (or could be multiple binaries) that contains a supported set
of inputs and outputs which could be specifically carved out for each
usage segment (or for each user also) that could influence the system
behavior either by enriching the user experience or/and boost/throttle
power limits.

Once the TA init command succeeds, the PMF driver sends the changing
events in the current environment to the TA for a constant sampling
frequency time (the event here could be a lid close or open) and
if the policy binary has corresponding action built within it, the
TA sends the action for it in the subsequent enact command.

If the inputs sent to the TA has no output defined in the policy
binary generated by OEMs, there will be no action to be performed
by the PMF driver.

Example policies:

1) if slider is performance ; set the SPL to 40W
Here PMF driver registers with the platform profile interface and
when the slider position is changed, PMF driver lets the TA know
about this. TA sends back an action to update the Sustained
Power Limit (SPL). PMF driver updates this limit via the PMFW mailbox.

2) if user_away ; then lock the system
Here PMF driver hooks to the AMD SFH driver to know the user presence
and send the inputs to TA and if the condition is met, the TA sends
the action of locking the system. PMF driver generates a uevent and
based on the udev rule in the userland the system gets locked with
systemctl.

The intent here is to provide the OEM's to make a policy to lock the
system when the user is away ; but the userland can make a choice to
ignore it.

and so on.

The OEMs will have an utility to create numerous such policies and
the policies shall be reviewed by AMD before signing and encrypting
them. Policies are shared between operating systems to have seemless user
experience.

Since all this action has to happen via the "amdtee" driver, currently
there is no caller for it in the kernel which can load the amdtee driver.
Without amdtee driver loading onto the system the "tee" calls shall fail
from the PMF driver. Hence an explicit "request_module" has been added
to address this.

Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/Kconfig  |   1 +
 drivers/platform/x86/amd/pmf/acpi.c   |  37 +++
 drivers/platform/x86/amd/pmf/core.c   |  12 +++
 drivers/platform/x86/amd/pmf/pmf.h| 135 
 drivers/platform/x86/amd/pmf/tee-if.c | 141 +-
 5 files changed, 324 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/Kconfig 
b/drivers/platform/x86/amd/pmf/Kconfig
index 3064bc8ea167..437b78c6d1c5 100644
--- a/drivers/platform/x86/amd/pmf/Kconfig
+++ b/drivers/platform/x86/amd/pmf/Kconfig
@@ -9,6 +9,7 @@ config AMD_PMF
depends on POWER_SUPPLY
depends on AMD_NB
select ACPI_PLATFORM_PROFILE
+   depends on AMDTEE
help
  This driver provides support for the AMD Platform Management 
Framework.
  The goal is to enhance end user experience by making AMD PCs smarter,
diff --git a/drivers/platform/x86/amd/pmf/acpi.c 
b/drivers/platform/x86/amd/pmf/acpi.c
index 3fc5e4547d9f..d0512af2cd42 100644
--- a/drivers/platform/x86/amd/pmf/acpi.c
+++ b/drivers/platform/x86/amd/pmf/acpi.c
@@ -286,6 +286,43 @@ int apmf_install_handler(struct amd_pmf_dev *pmf_dev)
return 0;
 }
 
+static acpi_status apmf_walk_resources(struct acpi_resource *res, void *data)
+{
+   struct amd_pmf_dev *dev = data;
+
+   switch (res->type) {
+   case ACPI_RESOURCE_TYPE_ADDRESS64:
+   dev->policy_addr = res->data.address64.address.minimum;
+   dev->policy_sz = res->data.address64.address.address_length;
+   break;
+   case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
+   dev->policy_addr = res->data.fixed_memory32.address;
+   dev->policy_sz = res->data.fixed_memory32.address_length;
+   break;
+   }
+
+   if (!dev->policy_addr || dev->policy_sz > POLICY_BUF_MAX_SZ || 
dev->policy_sz == 0) {
+   pr_err("Incorrect Policy params, possibly a SBIOS bug\n");
+   return AE_ERROR;
+   }
+
+   return AE_OK;
+}
+
+int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev)
+{
+   acpi_handle ahandle = ACPI_HANDLE(pmf_dev->dev);
+   acpi_status status;
+
+   status = acpi_walk_resources(ahandle, METHOD_NAME__CRS, 
apmf_walk_resources, pmf_dev);
+   if (ACPI_FAILURE(status)) {
+   dev_err(pmf_dev->dev, 

[PATCH v2 03/16] platform/x86/amd/pmf: Change return type of amd_pmf_set_dram_addr()

2023-09-30 Thread Shyam Sundar S K
In the current code, the metrics table information was required only
for auto-mode or CnQF at a given time. Hence keeping the return type
of amd_pmf_set_dram_addr() as static made sense.

But with the addition of Smart PC builder feature, the metrics table
information has to be shared by the Smart PC also and this feature
resides outside of core.c.

To make amd_pmf_set_dram_addr() visible outside of core.c make it
as a non-static function and move the allocation of memory for
metrics table from amd_pmf_init_metrics_table() to amd_pmf_set_dram_addr()
as amd_pmf_set_dram_addr() is the common function to set the DRAM
address.

Reviewed-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/core.c | 26 ++
 drivers/platform/x86/amd/pmf/pmf.h  |  1 +
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/core.c 
b/drivers/platform/x86/amd/pmf/core.c
index 68f1389dda3e..678dce4fea08 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -251,29 +251,35 @@ static const struct pci_device_id pmf_pci_ids[] = {
{ }
 };
 
-static void amd_pmf_set_dram_addr(struct amd_pmf_dev *dev)
+int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev)
 {
u64 phys_addr;
u32 hi, low;
 
+   /* Get Metrics Table Address */
+   dev->buf = kzalloc(sizeof(dev->m_table), GFP_KERNEL);
+   if (!dev->buf)
+   return -ENOMEM;
+
phys_addr = virt_to_phys(dev->buf);
hi = phys_addr >> 32;
low = phys_addr & GENMASK(31, 0);
 
amd_pmf_send_cmd(dev, SET_DRAM_ADDR_HIGH, 0, hi, NULL);
amd_pmf_send_cmd(dev, SET_DRAM_ADDR_LOW, 0, low, NULL);
+
+   return 0;
 }
 
 int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev)
 {
-   /* Get Metrics Table Address */
-   dev->buf = kzalloc(sizeof(dev->m_table), GFP_KERNEL);
-   if (!dev->buf)
-   return -ENOMEM;
+   int ret;
 
INIT_DELAYED_WORK(>work_buffer, amd_pmf_get_metrics);
 
-   amd_pmf_set_dram_addr(dev);
+   ret = amd_pmf_set_dram_addr(dev);
+   if (ret)
+   return ret;
 
/*
 * Start collecting the metrics data after a small delay
@@ -287,9 +293,13 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev)
 static int amd_pmf_resume_handler(struct device *dev)
 {
struct amd_pmf_dev *pdev = dev_get_drvdata(dev);
+   int ret;
 
-   if (pdev->buf)
-   amd_pmf_set_dram_addr(pdev);
+   if (pdev->buf) {
+   ret = amd_pmf_set_dram_addr(pdev);
+   if (ret)
+   return ret;
+   }
 
return 0;
 }
diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index e0837799f521..3930b8ed8333 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -421,6 +421,7 @@ int amd_pmf_init_metrics_table(struct amd_pmf_dev *dev);
 int amd_pmf_get_power_source(void);
 int apmf_install_handler(struct amd_pmf_dev *pmf_dev);
 int apmf_os_power_slider_update(struct amd_pmf_dev *dev, u8 flag);
+int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev);
 
 /* SPS Layer */
 int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf);
-- 
2.25.1



[PATCH v2 02/16] platform/x86/amd/pmf: Add support PMF-TA interaction

2023-09-30 Thread Shyam Sundar S K
PMF TA (Trusted Application) loads via the TEE environment into the
AMD ASP.

PMF-TA supports two commands:
1) Init: Initialize the TA with the PMF Smart PC policy binary and
start the policy engine. A policy is a combination of inputs and
outputs, where;
 - the inputs are the changing dynamics of the system like the user
   behaviour, system heuristics etc.
 - the outputs, which are the actions to be set on the system which
   lead to better power management and enhanced user experience.

PMF driver acts as a central manager in this case to supply the
inputs required to the TA (either by getting the information from
the other kernel subsystems or from userland)

2) Enact: Enact the output actions from the TA. The action could be
applying a new thermal limit to boost/throttle the power limits or
change system behavior.

Reviewed-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/pmf.h| 10 +++
 drivers/platform/x86/amd/pmf/tee-if.c | 97 ++-
 2 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index 02460c2a31ea..e0837799f521 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -59,6 +59,9 @@
 #define ARG_NONE 0
 #define AVG_SAMPLE_SIZE 3
 
+/* TA macros */
+#define PMF_TA_IF_VERSION_MAJOR1
+
 /* AMD PMF BIOS interfaces */
 struct apmf_verify_interface {
u16 size;
@@ -184,6 +187,7 @@ struct amd_pmf_dev {
struct tee_shm *fw_shm_pool;
u32 session_id;
void *shbuf;
+   struct delayed_work pb_work;
bool smart_pc_enabled;
 };
 
@@ -395,6 +399,12 @@ struct apmf_dyn_slider_output {
struct apmf_cnqf_power_set ps[APMF_CNQF_MAX];
 } __packed;
 
+/* cmd ids for TA communication */
+enum ta_pmf_command {
+   TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE,
+   TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES,
+};
+
 struct ta_pmf_shared_memory {
int command_id;
int resp_id;
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c 
b/drivers/platform/x86/amd/pmf/tee-if.c
index 4db80ca59a11..1b3985cd7c08 100644
--- a/drivers/platform/x86/amd/pmf/tee-if.c
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -13,9 +13,96 @@
 #include "pmf.h"
 
 #define MAX_TEE_PARAM  4
+
+/* Policy binary actions sampling frequency (in ms) */
+static int pb_actions_ms = 1000;
+#ifdef CONFIG_AMD_PMF_DEBUG
+module_param(pb_actions_ms, int, 0644);
+MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency 
(default = 1000ms)");
+#endif
+
 static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d,
0xb1, 0x2d, 0xc5, 0x29, 0xb1, 
0x3d, 0x85, 0x43);
 
+static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd,
+struct tee_ioctl_invoke_arg *arg,
+struct tee_param *param)
+{
+   memset(arg, 0, sizeof(*arg));
+   memset(param, 0, MAX_TEE_PARAM * sizeof(*param));
+
+   arg->func = cmd;
+   arg->session = dev->session_id;
+   arg->num_params = MAX_TEE_PARAM;
+
+   /* Fill invoke cmd params */
+   param[0].u.memref.size = sizeof(struct ta_pmf_shared_memory);
+   param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT;
+   param[0].u.memref.shm = dev->fw_shm_pool;
+   param[0].u.memref.shm_offs = 0;
+}
+
+static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev)
+{
+   struct ta_pmf_shared_memory *ta_sm = NULL;
+   struct tee_param param[MAX_TEE_PARAM];
+   struct tee_ioctl_invoke_arg arg;
+   int ret = 0;
+
+   if (!dev->tee_ctx)
+   return -ENODEV;
+
+   ta_sm = (struct ta_pmf_shared_memory *)dev->shbuf;
+   memset(ta_sm, 0, sizeof(struct ta_pmf_shared_memory));
+   ta_sm->command_id = TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES;
+   ta_sm->if_version = PMF_TA_IF_VERSION_MAJOR;
+
+   amd_pmf_prepare_args(dev, TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES, 
, param);
+
+   ret = tee_client_invoke_func(dev->tee_ctx, , param);
+   if (ret < 0 || arg.ret != 0) {
+   dev_err(dev->dev, "TEE enact cmd failed. err: %x, ret:%x\n", 
arg.ret, ret);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int amd_pmf_invoke_cmd_init(struct amd_pmf_dev *dev)
+{
+   struct ta_pmf_shared_memory *ta_sm = NULL;
+   struct tee_param param[MAX_TEE_PARAM];
+   struct tee_ioctl_invoke_arg arg;
+   int ret = 0;
+
+   if (!dev->tee_ctx) {
+   dev_err(dev->dev, "Failed to get TEE context\n");
+   return -ENODEV;
+   }
+
+   ta_sm = (struct ta_pmf_shared_memory *)dev->shbuf;
+   ta_sm->command_id = TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE;
+   ta_sm->if_version = PMF_TA_IF_VERSION_MAJOR;
+
+   amd_pmf_prepare_args(dev, TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE, 
, 

[PATCH v2 01/16] platform/x86/amd/pmf: Add PMF TEE interface

2023-09-30 Thread Shyam Sundar S K
AMD PMF driver loads the PMF TA (Trusted Application) into the AMD
ASP's (AMD Security Processor) TEE (Trusted Execution Environment).

PMF Trusted Application is a secured firmware placed under
/lib/firmware/amdtee gets loaded only when the TEE environment is
initialized. Add the initial code path to build these pipes.

Reviewed-by: Mario Limonciello 
Signed-off-by: Shyam Sundar S K 
---
 drivers/platform/x86/amd/pmf/Makefile |   3 +-
 drivers/platform/x86/amd/pmf/core.c   |  11 ++-
 drivers/platform/x86/amd/pmf/pmf.h|  16 
 drivers/platform/x86/amd/pmf/tee-if.c | 112 ++
 4 files changed, 138 insertions(+), 4 deletions(-)
 create mode 100644 drivers/platform/x86/amd/pmf/tee-if.c

diff --git a/drivers/platform/x86/amd/pmf/Makefile 
b/drivers/platform/x86/amd/pmf/Makefile
index fdededf54392..d2746ee7369f 100644
--- a/drivers/platform/x86/amd/pmf/Makefile
+++ b/drivers/platform/x86/amd/pmf/Makefile
@@ -6,4 +6,5 @@
 
 obj-$(CONFIG_AMD_PMF) += amd-pmf.o
 amd-pmf-objs := core.o acpi.o sps.o \
-   auto-mode.o cnqf.o
+   auto-mode.o cnqf.o \
+   tee-if.o
diff --git a/drivers/platform/x86/amd/pmf/core.c 
b/drivers/platform/x86/amd/pmf/core.c
index 78ed3ee22555..68f1389dda3e 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -309,8 +309,11 @@ static void amd_pmf_init_features(struct amd_pmf_dev *dev)
dev_dbg(dev->dev, "SPS enabled and Platform Profiles 
registered\n");
}
 
-   /* Enable Auto Mode */
-   if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) {
+   if (amd_pmf_init_smart_pc(dev)) {
+   /* Enable Smart PC Solution builder */
+   dev_dbg(dev->dev, "Smart PC Solution Enabled\n");
+   } else if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) {
+   /* Enable Auto Mode */
amd_pmf_init_auto_mode(dev);
dev_dbg(dev->dev, "Auto Mode Init done\n");
} else if (is_apmf_func_supported(dev, APMF_FUNC_DYN_SLIDER_AC) ||
@@ -330,7 +333,9 @@ static void amd_pmf_deinit_features(struct amd_pmf_dev *dev)
amd_pmf_deinit_sps(dev);
}
 
-   if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) {
+   if (dev->smart_pc_enabled) {
+   amd_pmf_deinit_smart_pc(dev);
+   } else if (is_apmf_func_supported(dev, APMF_FUNC_AUTO_MODE)) {
amd_pmf_deinit_auto_mode(dev);
} else if (is_apmf_func_supported(dev, APMF_FUNC_DYN_SLIDER_AC) ||
  is_apmf_func_supported(dev, APMF_FUNC_DYN_SLIDER_DC)) 
{
diff --git a/drivers/platform/x86/amd/pmf/pmf.h 
b/drivers/platform/x86/amd/pmf/pmf.h
index deba88e6e4c8..02460c2a31ea 100644
--- a/drivers/platform/x86/amd/pmf/pmf.h
+++ b/drivers/platform/x86/amd/pmf/pmf.h
@@ -179,6 +179,12 @@ struct amd_pmf_dev {
bool cnqf_enabled;
bool cnqf_supported;
struct notifier_block pwr_src_notifier;
+   /* Smart PC solution builder */
+   struct tee_context *tee_ctx;
+   struct tee_shm *fw_shm_pool;
+   u32 session_id;
+   void *shbuf;
+   bool smart_pc_enabled;
 };
 
 struct apmf_sps_prop_granular {
@@ -389,6 +395,13 @@ struct apmf_dyn_slider_output {
struct apmf_cnqf_power_set ps[APMF_CNQF_MAX];
 } __packed;
 
+struct ta_pmf_shared_memory {
+   int command_id;
+   int resp_id;
+   u32 pmf_result;
+   u32 if_version;
+};
+
 /* Core Layer */
 int apmf_acpi_init(struct amd_pmf_dev *pmf_dev);
 void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev);
@@ -433,4 +446,7 @@ void amd_pmf_deinit_cnqf(struct amd_pmf_dev *dev);
 int amd_pmf_trans_cnqf(struct amd_pmf_dev *dev, int socket_power, ktime_t 
time_lapsed_ms);
 extern const struct attribute_group cnqf_feature_attribute_group;
 
+/* Smart PC builder Layer*/
+int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev);
+void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev);
 #endif /* PMF_H */
diff --git a/drivers/platform/x86/amd/pmf/tee-if.c 
b/drivers/platform/x86/amd/pmf/tee-if.c
new file mode 100644
index ..4db80ca59a11
--- /dev/null
+++ b/drivers/platform/x86/amd/pmf/tee-if.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD Platform Management Framework Driver - TEE Interface
+ *
+ * Copyright (c) 2023, Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Author: Shyam Sundar S K 
+ */
+
+#include 
+#include 
+#include "pmf.h"
+
+#define MAX_TEE_PARAM  4
+static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d,
+   0xb1, 0x2d, 0xc5, 0x29, 0xb1, 
0x3d, 0x85, 0x43);
+
+static int amd_pmf_amdtee_ta_match(struct tee_ioctl_version_data *ver, const 
void *data)
+{
+   return ver->impl_id == TEE_IMPL_ID_AMDTEE;
+}
+
+static int amd_pmf_ta_open_session(struct tee_context *ctx, u32 *id)
+{
+   struct tee_ioctl_open_session_arg sess_arg = {};
+   int rc;
+
+   export_uuid(sess_arg.uuid, 

[PATCH v2 00/16] Introduce PMF Smart PC Solution Builder Feature

2023-09-30 Thread Shyam Sundar S K
Smart PC Solutions Builder allows for OEM to define a large number of
custom system states to dynamically switch to. The system states are
referred to as policies, and multiple policies can be loaded onto the
system at any given time, however only one policy can be active at a
given time.

Policy is a combination of PMF input and output capabilities. The inputs
are the incoming information from the other kernel subsystems like LID
state, Sensor info, GPU info etc and the actions are the updating the 
power limits of SMU etc.

The policy binary is signed and encrypted by a special key from AMD. This
policy binary shall have the inputs and outputs which the OEMs can build
for the platform customization that can enhance the user experience and
system behavior.

This series adds the initial support for Smart PC solution to PMF driver.

Note that, on platforms where CnQF and Smart PC is advertised, Smart PC
shall have higher precedence and same applies for Auto Mode.

V1->v2:
-
- Remove __func__ macros
- Remove manual function names inside prints
- Handle tee_shm_get_va() failure
- Remove double _
- Add meaningful prints
- pass amd_pmf_set_dram_addr() failure errors
- Add more information to commit messages
- use right format specifiers
- use devm_ioremap() instead of ioremap()
- address unsigned long vs u32 problems
- Fix lkp reported issues
- Add amd_pmf_remove_pb() to remove the debugfs files created(if any).
- Make amd_pmf_open_pb() as static.
- Add cooling device APIs for controlling amdgpu backlight
- handle amd_pmf_apply_policies() failures
- Split v1 14/15 into 2 patches further
- use linux/units.h for better handling
- add "depends on" AMD_SFH_HID for interaction with SFH
- other cosmetic remarks

Basavaraj Natikar (3):
  HID: amd_sfh: rename float_to_int() to amd_sfh_float_to_int()
  platform/x86/amd/pmf: Add PMF-AMDSFH interface for HPD
  platform/x86/amd/pmf: Add PMF-AMDSFH interface for ALS

Shyam Sundar S K (13):
  platform/x86/amd/pmf: Add PMF TEE interface
  platform/x86/amd/pmf: Add support PMF-TA interaction
  platform/x86/amd/pmf: Change return type of amd_pmf_set_dram_addr()
  platform/x86/amd/pmf: Add support for PMF Policy Binary
  platform/x86/amd/pmf: change amd_pmf_init_features() call sequence
  platform/x86/amd/pmf: Add support to get inputs from other subsystems
  platform/x86/amd/pmf: Add support update p3t limit
  platform/x86/amd/pmf: Add support to update system state
  platform/x86/amd/pmf: Add facility to dump TA inputs
  platform/x86/amd/pmf: Add capability to sideload of policy binary
  platform/x86/amd/pmf: dump policy binary data
  platform/x86/amd/pmf: Add PMF-AMDGPU get interface
  platform/x86/amd/pmf: Add PMF-AMDGPU set interface

 Documentation/admin-guide/index.rst   |   1 +
 Documentation/admin-guide/pmf.rst |  25 +
 drivers/gpu/drm/amd/amdgpu/Makefile   |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c   | 154 ++
 drivers/hid/amd-sfh-hid/amd_sfh_common.h  |   6 +
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c |  22 +-
 drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_init.c |  17 +
 .../amd-sfh-hid/sfh1_1/amd_sfh_interface.c|  48 ++
 .../amd-sfh-hid/sfh1_1/amd_sfh_interface.h|   1 +
 drivers/platform/x86/amd/pmf/Kconfig  |   3 +
 drivers/platform/x86/amd/pmf/Makefile |   3 +-
 drivers/platform/x86/amd/pmf/acpi.c   |  37 ++
 drivers/platform/x86/amd/pmf/core.c   |  52 +-
 drivers/platform/x86/amd/pmf/pmf.h| 201 +++
 drivers/platform/x86/amd/pmf/spc.c| 197 +++
 drivers/platform/x86/amd/pmf/sps.c|   2 +-
 drivers/platform/x86/amd/pmf/tee-if.c | 515 ++
 include/linux/amd-pmf-io.h|  55 ++
 19 files changed, 1317 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/admin-guide/pmf.rst
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_pmf.c
 create mode 100644 drivers/platform/x86/amd/pmf/spc.c
 create mode 100644 drivers/platform/x86/amd/pmf/tee-if.c
 create mode 100644 include/linux/amd-pmf-io.h

-- 
2.25.1



Re: [PATCH v2] drm: rcar-du: turn rcar_du_group_get() into void and remove its return value check

2023-09-30 Thread kernel test robot
Hi Alexandra,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.6-rc3 next-20230929]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Alexandra-Diupina/drm-rcar-du-turn-rcar_du_group_get-into-void-and-remove-its-return-value-check/20230927-184651
base:   linus/master
patch link:
https://lore.kernel.org/r/20230927104438.30628-1-adiupina%40astralinux.ru
patch subject: [PATCH v2] drm: rcar-du: turn rcar_du_group_get() into void and 
remove its return value check
config: arm-allyesconfig 
(https://download.01.org/0day-ci/archive/20230930/202309301402.ur7irqvj-...@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20230930/202309301402.ur7irqvj-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202309301402.ur7irqvj-...@intel.com/

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/renesas/rcar-du/rcar_du_group.c:203:6: error: conflicting 
>> types for 'rcar_du_group_get'; have 'void(struct rcar_du_group *)'
 203 | void rcar_du_group_get(struct rcar_du_group *rgrp)
 |  ^
   In file included from drivers/gpu/drm/renesas/rcar-du/rcar_du_drv.h:20,
from drivers/gpu/drm/renesas/rcar-du/rcar_du_group.c:29:
   drivers/gpu/drm/renesas/rcar-du/rcar_du_group.h:57:5: note: previous 
declaration of 'rcar_du_group_get' with type 'int(struct rcar_du_group *)'
  57 | int rcar_du_group_get(struct rcar_du_group *rgrp);
 | ^


vim +203 drivers/gpu/drm/renesas/rcar-du/rcar_du_group.c

   194  
   195  /*
   196   * rcar_du_group_get - Acquire a reference to the DU channels group
   197   *
   198   * Acquiring the first reference setups core registers. A reference 
must be held
   199   * before accessing any hardware registers.
   200   *
   201   * This function must be called with the DRM mode_config lock held.
   202   */
 > 203  void rcar_du_group_get(struct rcar_du_group *rgrp)
   204  {
   205  if (rgrp->use_count)
   206  goto done;
   207  
   208  rcar_du_group_setup(rgrp);
   209  
   210  done:
   211  rgrp->use_count++;
   212  }
   213  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


[Bug 217958] New: Crashes if I boot the computer with the second display connected to HDMI output

2023-09-30 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=217958

Bug ID: 217958
   Summary: Crashes if I boot the computer with the second display
connected to HDMI output
   Product: Drivers
   Version: 2.5
  Hardware: All
OS: Linux
Status: NEW
  Severity: normal
  Priority: P3
 Component: Video(DRI - non Intel)
  Assignee: drivers_video-...@kernel-bugs.osdl.org
  Reporter: anickn...@gmail.com
Regression: No

If I boot the computer with the second display connected to HDMI output, then I
can see a crash in the logs.
I already have another monitor (same model) connected to DP and it boots fine
only with this monitor.
If I connect the second monitor, to the same HDMI port after then computer is
booted, then the crash is not happening.

The following crashes are from different computer boots.

Kernel 6.X.Y, not tried on 5.X.Y

Video card: Sapphire Radeon™ RX 6600 PULSE, 8GB GDDR6, 128-bit
https://www.sapphiretech.com/en/consumer/pulse-radeon-rx-6600-8g-gddr6
VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Navi 23
[Radeon RX 6600/6600 XT/6600M] (rev c7)
Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21/23 HDMI/DP Audio
Controller


kernel: [ cut here ]
kernel: kernel BUG at mm/migrate.c:654!
kernel: invalid opcode:  [#1] PREEMPT SMP NOPTI
kernel: CPU: 3 PID: 3798 Comm: systemd-sysctl Tainted: P   OE 
6.5.5-arch1-1 #1 d82a0f532dd8cfe67d5795c1738d9c01059a0c62
kernel: Hardware name: Gigabyte Technology Co., Ltd. X570 AORUS MASTER/X570
AORUS MASTER, BIOS F37c 03/23/2023
kernel: RIP: 0010:migrate_folio_extra+0x6c/0x70
kernel: Code: de 48 89 ef e8 05 e3 ff ff 5b 44 89 e0 5d 41 5c 41 5d e9 97 91 9e
00 e8 f2 e2 ff ff 44 89 e0 5b 5d 41 5c 41 5d e9 84 91 9e 00 <0f> 0b 66 90 90 90
90 90 90 90 90 90 90 90 90 90 90 90 90 90 0f 1f
kernel: RSP: 0018:98535db977d0 EFLAGS: 00010282
kernel: RAX: 02008025 RBX: e848cc0c3780 RCX: 0002
kernel: RDX: e848cc0c3780 RSI: e848d0092240 RDI: 8b27d341fdd0
kernel: RBP: 8b27d341fdd0 R08:  R09: 00039120
kernel: R10: e848d0092248 R11:  R12: e848d0092240
kernel: R13: 0002 R14: 98535db97888 R15: 98535db97878
kernel: FS:  7f3c907a3e80() GS:8b468eac()
knlGS:
kernel: CS:  0010 DS:  ES:  CR0: 80050033
kernel: CR2: 55af5c5add40 CR3: 0001441a8000 CR4: 00750ee0
kernel: PKRU: 5554
kernel: Call Trace:
kernel:  
kernel:  ? die+0x36/0x90
kernel:  ? do_trap+0xda/0x100
kernel:  ? migrate_folio_extra+0x6c/0x70
kernel:  ? do_error_trap+0x6a/0x90
kernel:  ? migrate_folio_extra+0x6c/0x70
kernel:  ? exc_invalid_op+0x50/0x70
kernel:  ? migrate_folio_extra+0x6c/0x70
kernel:  ? asm_exc_invalid_op+0x1a/0x20
kernel:  ? migrate_folio_extra+0x6c/0x70
kernel:  move_to_new_folio+0x136/0x150
kernel:  migrate_pages_batch+0x893/0xc10
kernel:  ? __pfx_remove_migration_pte+0x10/0x10
kernel:  migrate_pages+0xb9e/0xd20
kernel:  ? __pfx_alloc_migration_target+0x10/0x10
kernel:  __alloc_contig_migrate_range+0xb1/0x1c0
kernel:  alloc_contig_range+0x14e/0x280
kernel:  ? srso_alias_return_thunk+0x5/0x7f
kernel:  alloc_contig_pages+0x206/0x260
kernel:  alloc_fresh_hugetlb_folio+0xa6/0x230
kernel:  alloc_pool_huge_page+0x80/0x100
kernel:  set_max_huge_pages+0x1a7/0x420
kernel:  hugetlb_sysctl_handler_common+0x10e/0x140
kernel:  ? __pfx_hugetlb_sysctl_handler+0x10/0x10
kernel:  proc_sys_call_handler+0x1c0/0x2e0
kernel:  vfs_write+0x23e/0x420
kernel:  ksys_write+0x6f/0xf0
kernel:  do_syscall_64+0x60/0x90
kernel:  ? srso_alias_return_thunk+0x5/0x7f
kernel:  ? default_llseek+0x70/0xd0
kernel:  ? srso_alias_return_thunk+0x5/0x7f
kernel:  ? ksys_lseek+0x6c/0xb0
kernel:  ? srso_alias_return_thunk+0x5/0x7f
kernel:  ? syscall_exit_to_user_mode+0x2b/0x40
kernel:  ? srso_alias_return_thunk+0x5/0x7f
kernel:  ? do_syscall_64+0x6c/0x90
kernel:  ? srso_alias_return_thunk+0x5/0x7f
kernel:  ? syscall_exit_to_user_mode+0x2b/0x40
kernel:  ? srso_alias_return_thunk+0x5/0x7f
kernel:  ? do_syscall_64+0x6c/0x90
kernel:  ? do_syscall_64+0x6c/0x90
kernel:  ? exc_page_fault+0x7f/0x180
kernel:  entry_SYSCALL_64_after_hwframe+0x6e/0xd8
kernel: RIP: 0033:0x7f3c912a4f84
kernel: Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00
f3 0f 1e fa 80 3d e5 c3 0d 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff
77 54 c3 0f 1f 00 48 83 ec 28 48 89 54 24 18 48
kernel: RSP: 002b:7ffc47790068 EFLAGS: 0202 ORIG_RAX: 0001
kernel: RAX: ffda RBX: 0004 RCX: 7f3c912a4f84
kernel: RDX: 0004 RSI: 7ffc47790140 RDI: 0004
kernel: RBP: 7ffc47790140 R08: 557aa0d30010 R09: 0007
kernel: R10: 557aa0d326a0 R11: 0202 R12: 0004
kernel: R13: 557aa0d302d0 R14: 7f3c91377f20