[1/2] memory: tegra: Add SID override programming for MC clients

Message ID 20231107052824.29418-1-amhetre@nvidia.com
State New
Headers
Series [1/2] memory: tegra: Add SID override programming for MC clients |

Commit Message

Ashish Mhetre Nov. 7, 2023, 5:28 a.m. UTC
  For some devices the bootloader/firmware may set up the device in
bypass. Memory clients like display needs kernel to program SID after
resume because bootloader/firmware programs the SID of display device to
bypass. In order to make sure that kernel IOMMU mappings for these
devices work after resume, add SID override programming support for all
memory clients on memory controller resume.

This partially reverts 'commit ef86b2c2807f ("memory: tegra: Remove
clients SID override programming")'

Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
---
 drivers/memory/tegra/tegra186.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Comments

kernel test robot Nov. 7, 2023, 9:16 a.m. UTC | #1
Hi Ashish,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tegra/for-next]
[also build test WARNING on linus/master v6.6 next-20231107]
[cannot apply to tegra-drm/drm/tegra/for-next]
[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/Ashish-Mhetre/memory-tegra-Skip-SID-programming-if-SID-registers-aren-t-set/20231107-133149
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git for-next
patch link:    https://lore.kernel.org/r/20231107052824.29418-1-amhetre%40nvidia.com
patch subject: [PATCH 1/2] memory: tegra: Add SID override programming for MC clients
config: arm64-defconfig (https://download.01.org/0day-ci/archive/20231107/202311071607.IzbwSn2f-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231107/202311071607.IzbwSn2f-lkp@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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311071607.IzbwSn2f-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/memory/tegra/tegra186.c: In function 'tegra186_mc_resume':
   drivers/memory/tegra/tegra186.c:78:17: error: implicit declaration of function 'tegra186_mc_client_sid_override' [-Werror=implicit-function-declaration]
      78 |                 tegra186_mc_client_sid_override(mc, client, client->sid);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/memory/tegra/tegra186.c: At top level:
>> drivers/memory/tegra/tegra186.c:85:13: warning: conflicting types for 'tegra186_mc_client_sid_override'; have 'void(struct tegra_mc *, const struct tegra_mc_client *, unsigned int)'
      85 | static void tegra186_mc_client_sid_override(struct tegra_mc *mc,
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/memory/tegra/tegra186.c:85:13: error: static declaration of 'tegra186_mc_client_sid_override' follows non-static declaration
   drivers/memory/tegra/tegra186.c:78:17: note: previous implicit declaration of 'tegra186_mc_client_sid_override' with type 'void(struct tegra_mc *, const struct tegra_mc_client *, unsigned int)'
      78 |                 tegra186_mc_client_sid_override(mc, client, client->sid);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +85 drivers/memory/tegra/tegra186.c

7355c7b9ae0d45 Thierry Reding 2021-06-02   70  
142620fbbbbba0 Ashish Mhetre  2023-11-07   71  static int tegra186_mc_resume(struct tegra_mc *mc)
142620fbbbbba0 Ashish Mhetre  2023-11-07   72  {
142620fbbbbba0 Ashish Mhetre  2023-11-07   73  	unsigned int i;
142620fbbbbba0 Ashish Mhetre  2023-11-07   74  
142620fbbbbba0 Ashish Mhetre  2023-11-07   75  	for (i = 0; i < mc->soc->num_clients; i++) {
142620fbbbbba0 Ashish Mhetre  2023-11-07   76  		const struct tegra_mc_client *client = &mc->soc->clients[i];
142620fbbbbba0 Ashish Mhetre  2023-11-07   77  
142620fbbbbba0 Ashish Mhetre  2023-11-07  @78  		tegra186_mc_client_sid_override(mc, client, client->sid);
142620fbbbbba0 Ashish Mhetre  2023-11-07   79  	}
142620fbbbbba0 Ashish Mhetre  2023-11-07   80  
142620fbbbbba0 Ashish Mhetre  2023-11-07   81  	return 0;
142620fbbbbba0 Ashish Mhetre  2023-11-07   82  }
142620fbbbbba0 Ashish Mhetre  2023-11-07   83  
eaf89f1cd38cf7 Arnd Bergmann  2021-07-22   84  #if IS_ENABLED(CONFIG_IOMMU_API)
393d66fd2cacba Thierry Reding 2021-06-03  @85  static void tegra186_mc_client_sid_override(struct tegra_mc *mc,
393d66fd2cacba Thierry Reding 2021-06-03   86  					    const struct tegra_mc_client *client,
393d66fd2cacba Thierry Reding 2021-06-03   87  					    unsigned int sid)
393d66fd2cacba Thierry Reding 2021-06-03   88  {
393d66fd2cacba Thierry Reding 2021-06-03   89  	u32 value, old;
393d66fd2cacba Thierry Reding 2021-06-03   90  
393d66fd2cacba Thierry Reding 2021-06-03   91  	value = readl(mc->regs + client->regs.sid.security);
393d66fd2cacba Thierry Reding 2021-06-03   92  	if ((value & MC_SID_STREAMID_SECURITY_OVERRIDE) == 0) {
393d66fd2cacba Thierry Reding 2021-06-03   93  		/*
393d66fd2cacba Thierry Reding 2021-06-03   94  		 * If the secure firmware has locked this down the override
393d66fd2cacba Thierry Reding 2021-06-03   95  		 * for this memory client, there's nothing we can do here.
393d66fd2cacba Thierry Reding 2021-06-03   96  		 */
393d66fd2cacba Thierry Reding 2021-06-03   97  		if (value & MC_SID_STREAMID_SECURITY_WRITE_ACCESS_DISABLED)
393d66fd2cacba Thierry Reding 2021-06-03   98  			return;
393d66fd2cacba Thierry Reding 2021-06-03   99  
393d66fd2cacba Thierry Reding 2021-06-03  100  		/*
393d66fd2cacba Thierry Reding 2021-06-03  101  		 * Otherwise, try to set the override itself. Typically the
393d66fd2cacba Thierry Reding 2021-06-03  102  		 * secure firmware will never have set this configuration.
393d66fd2cacba Thierry Reding 2021-06-03  103  		 * Instead, it will either have disabled write access to
393d66fd2cacba Thierry Reding 2021-06-03  104  		 * this field, or it will already have set an explicit
393d66fd2cacba Thierry Reding 2021-06-03  105  		 * override itself.
393d66fd2cacba Thierry Reding 2021-06-03  106  		 */
393d66fd2cacba Thierry Reding 2021-06-03  107  		WARN_ON((value & MC_SID_STREAMID_SECURITY_OVERRIDE) == 0);
393d66fd2cacba Thierry Reding 2021-06-03  108  
393d66fd2cacba Thierry Reding 2021-06-03  109  		value |= MC_SID_STREAMID_SECURITY_OVERRIDE;
393d66fd2cacba Thierry Reding 2021-06-03  110  		writel(value, mc->regs + client->regs.sid.security);
393d66fd2cacba Thierry Reding 2021-06-03  111  	}
393d66fd2cacba Thierry Reding 2021-06-03  112  
393d66fd2cacba Thierry Reding 2021-06-03  113  	value = readl(mc->regs + client->regs.sid.override);
393d66fd2cacba Thierry Reding 2021-06-03  114  	old = value & MC_SID_STREAMID_OVERRIDE_MASK;
393d66fd2cacba Thierry Reding 2021-06-03  115  
393d66fd2cacba Thierry Reding 2021-06-03  116  	if (old != sid) {
393d66fd2cacba Thierry Reding 2021-06-03  117  		dev_dbg(mc->dev, "overriding SID %x for %s with %x\n", old,
393d66fd2cacba Thierry Reding 2021-06-03  118  			client->name, sid);
393d66fd2cacba Thierry Reding 2021-06-03  119  		writel(sid, mc->regs + client->regs.sid.override);
393d66fd2cacba Thierry Reding 2021-06-03  120  	}
393d66fd2cacba Thierry Reding 2021-06-03  121  }
eaf89f1cd38cf7 Arnd Bergmann  2021-07-22  122  #endif
393d66fd2cacba Thierry Reding 2021-06-03  123
  
Ashish Mhetre Nov. 7, 2023, 11:40 a.m. UTC | #2
On 11/7/2023 2:46 PM, kernel test robot wrote:
> External email: Use caution opening links or attachments
>
>
> Hi Ashish,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on tegra/for-next]
> [also build test WARNING on linus/master v6.6 next-20231107]
> [cannot apply to tegra-drm/drm/tegra/for-next]
> [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/Ashish-Mhetre/memory-tegra-Skip-SID-programming-if-SID-registers-aren-t-set/20231107-133149
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git for-next
> patch link:    https://lore.kernel.org/r/20231107052824.29418-1-amhetre%40nvidia.com
> patch subject: [PATCH 1/2] memory: tegra: Add SID override programming for MC clients
> config: arm64-defconfig (https://download.01.org/0day-ci/archive/20231107/202311071607.IzbwSn2f-lkp@intel.com/config)
> compiler: aarch64-linux-gcc (GCC) 13.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231107/202311071607.IzbwSn2f-lkp@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 <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202311071607.IzbwSn2f-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
>     drivers/memory/tegra/tegra186.c: In function 'tegra186_mc_resume':
>     drivers/memory/tegra/tegra186.c:78:17: error: implicit declaration of function 'tegra186_mc_client_sid_override' [-Werror=implicit-function-declaration]
>        78 |                 tegra186_mc_client_sid_override(mc, client, client->sid);
>           |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     drivers/memory/tegra/tegra186.c: At top level:
>>> drivers/memory/tegra/tegra186.c:85:13: warning: conflicting types for 'tegra186_mc_client_sid_override'; have 'void(struct tegra_mc *, const struct tegra_mc_client *, unsigned int)'
>        85 | static void tegra186_mc_client_sid_override(struct tegra_mc *mc,
>           |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     drivers/memory/tegra/tegra186.c:85:13: error: static declaration of 'tegra186_mc_client_sid_override' follows non-static declaration
>     drivers/memory/tegra/tegra186.c:78:17: note: previous implicit declaration of 'tegra186_mc_client_sid_override' with type 'void(struct tegra_mc *, const struct tegra_mc_client *, unsigned int)'
>        78 |                 tegra186_mc_client_sid_override(mc, client, client->sid);
>           |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     cc1: some warnings being treated as errors
>
Fixed all of the warnings and errors in V2 of this series.
V1 wasn't applied properly in our testing because of which these build
errors weren't caught. Sorry for sending V1 with build issues. Please
use V2 of this series for the reviews.

Thanks and Regards,
Ashish Mhetre

> vim +85 drivers/memory/tegra/tegra186.c
>
> 7355c7b9ae0d45 Thierry Reding 2021-06-02   70
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   71  static int tegra186_mc_resume(struct tegra_mc *mc)
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   72  {
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   73   unsigned int i;
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   74
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   75   for (i = 0; i < mc->soc->num_clients; i++) {
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   76           const struct tegra_mc_client *client = &mc->soc->clients[i];
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   77
> 142620fbbbbba0 Ashish Mhetre  2023-11-07  @78           tegra186_mc_client_sid_override(mc, client, client->sid);
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   79   }
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   80
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   81   return 0;
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   82  }
> 142620fbbbbba0 Ashish Mhetre  2023-11-07   83
> eaf89f1cd38cf7 Arnd Bergmann  2021-07-22   84  #if IS_ENABLED(CONFIG_IOMMU_API)
> 393d66fd2cacba Thierry Reding 2021-06-03  @85  static void tegra186_mc_client_sid_override(struct tegra_mc *mc,
> 393d66fd2cacba Thierry Reding 2021-06-03   86                                       const struct tegra_mc_client *client,
> 393d66fd2cacba Thierry Reding 2021-06-03   87                                       unsigned int sid)
> 393d66fd2cacba Thierry Reding 2021-06-03   88  {
> 393d66fd2cacba Thierry Reding 2021-06-03   89   u32 value, old;
> 393d66fd2cacba Thierry Reding 2021-06-03   90
> 393d66fd2cacba Thierry Reding 2021-06-03   91   value = readl(mc->regs + client->regs.sid.security);
> 393d66fd2cacba Thierry Reding 2021-06-03   92   if ((value & MC_SID_STREAMID_SECURITY_OVERRIDE) == 0) {
> 393d66fd2cacba Thierry Reding 2021-06-03   93           /*
> 393d66fd2cacba Thierry Reding 2021-06-03   94            * If the secure firmware has locked this down the override
> 393d66fd2cacba Thierry Reding 2021-06-03   95            * for this memory client, there's nothing we can do here.
> 393d66fd2cacba Thierry Reding 2021-06-03   96            */
> 393d66fd2cacba Thierry Reding 2021-06-03   97           if (value & MC_SID_STREAMID_SECURITY_WRITE_ACCESS_DISABLED)
> 393d66fd2cacba Thierry Reding 2021-06-03   98                   return;
> 393d66fd2cacba Thierry Reding 2021-06-03   99
> 393d66fd2cacba Thierry Reding 2021-06-03  100           /*
> 393d66fd2cacba Thierry Reding 2021-06-03  101            * Otherwise, try to set the override itself. Typically the
> 393d66fd2cacba Thierry Reding 2021-06-03  102            * secure firmware will never have set this configuration.
> 393d66fd2cacba Thierry Reding 2021-06-03  103            * Instead, it will either have disabled write access to
> 393d66fd2cacba Thierry Reding 2021-06-03  104            * this field, or it will already have set an explicit
> 393d66fd2cacba Thierry Reding 2021-06-03  105            * override itself.
> 393d66fd2cacba Thierry Reding 2021-06-03  106            */
> 393d66fd2cacba Thierry Reding 2021-06-03  107           WARN_ON((value & MC_SID_STREAMID_SECURITY_OVERRIDE) == 0);
> 393d66fd2cacba Thierry Reding 2021-06-03  108
> 393d66fd2cacba Thierry Reding 2021-06-03  109           value |= MC_SID_STREAMID_SECURITY_OVERRIDE;
> 393d66fd2cacba Thierry Reding 2021-06-03  110           writel(value, mc->regs + client->regs.sid.security);
> 393d66fd2cacba Thierry Reding 2021-06-03  111   }
> 393d66fd2cacba Thierry Reding 2021-06-03  112
> 393d66fd2cacba Thierry Reding 2021-06-03  113   value = readl(mc->regs + client->regs.sid.override);
> 393d66fd2cacba Thierry Reding 2021-06-03  114   old = value & MC_SID_STREAMID_OVERRIDE_MASK;
> 393d66fd2cacba Thierry Reding 2021-06-03  115
> 393d66fd2cacba Thierry Reding 2021-06-03  116   if (old != sid) {
> 393d66fd2cacba Thierry Reding 2021-06-03  117           dev_dbg(mc->dev, "overriding SID %x for %s with %x\n", old,
> 393d66fd2cacba Thierry Reding 2021-06-03  118                   client->name, sid);
> 393d66fd2cacba Thierry Reding 2021-06-03  119           writel(sid, mc->regs + client->regs.sid.override);
> 393d66fd2cacba Thierry Reding 2021-06-03  120   }
> 393d66fd2cacba Thierry Reding 2021-06-03  121  }
> eaf89f1cd38cf7 Arnd Bergmann  2021-07-22  122  #endif
> 393d66fd2cacba Thierry Reding 2021-06-03  123
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
  
Krzysztof Kozlowski Nov. 7, 2023, 11:42 a.m. UTC | #3
On 07/11/2023 12:40, Ashish Mhetre wrote:
> 
> On 11/7/2023 2:46 PM, kernel test robot wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> Hi Ashish,
>>
>> kernel test robot noticed the following build warnings:
>>
>> [auto build test WARNING on tegra/for-next]
>> [also build test WARNING on linus/master v6.6 next-20231107]
>> [cannot apply to tegra-drm/drm/tegra/for-next]
>> [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/Ashish-Mhetre/memory-tegra-Skip-SID-programming-if-SID-registers-aren-t-set/20231107-133149
>> base:   https://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git for-next
>> patch link:    https://lore.kernel.org/r/20231107052824.29418-1-amhetre%40nvidia.com
>> patch subject: [PATCH 1/2] memory: tegra: Add SID override programming for MC clients
>> config: arm64-defconfig (https://download.01.org/0day-ci/archive/20231107/202311071607.IzbwSn2f-lkp@intel.com/config)
>> compiler: aarch64-linux-gcc (GCC) 13.2.0
>> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231107/202311071607.IzbwSn2f-lkp@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 <lkp@intel.com>
>> | Closes: https://lore.kernel.org/oe-kbuild-all/202311071607.IzbwSn2f-lkp@intel.com/
>>
>> All warnings (new ones prefixed by >>):
>>
>>     drivers/memory/tegra/tegra186.c: In function 'tegra186_mc_resume':
>>     drivers/memory/tegra/tegra186.c:78:17: error: implicit declaration of function 'tegra186_mc_client_sid_override' [-Werror=implicit-function-declaration]
>>        78 |                 tegra186_mc_client_sid_override(mc, client, client->sid);
>>           |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>     drivers/memory/tegra/tegra186.c: At top level:
>>>> drivers/memory/tegra/tegra186.c:85:13: warning: conflicting types for 'tegra186_mc_client_sid_override'; have 'void(struct tegra_mc *, const struct tegra_mc_client *, unsigned int)'
>>        85 | static void tegra186_mc_client_sid_override(struct tegra_mc *mc,
>>           |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>     drivers/memory/tegra/tegra186.c:85:13: error: static declaration of 'tegra186_mc_client_sid_override' follows non-static declaration
>>     drivers/memory/tegra/tegra186.c:78:17: note: previous implicit declaration of 'tegra186_mc_client_sid_override' with type 'void(struct tegra_mc *, const struct tegra_mc_client *, unsigned int)'
>>        78 |                 tegra186_mc_client_sid_override(mc, client, client->sid);
>>           |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>     cc1: some warnings being treated as errors
>>
> Fixed all of the warnings and errors in V2 of this series.
> V1 wasn't applied properly in our testing because of which these build

I would suggest to test what you develop, not apply it somewhere else.
Unless you develop on entirely different tree, but then this is the problem.

> errors weren't caught. Sorry for sending V1 with build issues. Please
> use V2 of this series for the reviews.

One version per day. Anyway you could wait till merge window finishes.
Nothing is going to happen with your patch now.


Best regards,
Krzysztof
  

Patch

diff --git a/drivers/memory/tegra/tegra186.c b/drivers/memory/tegra/tegra186.c
index 533f85a4b2bd..bd8cecc3cde2 100644
--- a/drivers/memory/tegra/tegra186.c
+++ b/drivers/memory/tegra/tegra186.c
@@ -68,6 +68,19 @@  static void tegra186_mc_remove(struct tegra_mc *mc)
 	of_platform_depopulate(mc->dev);
 }
 
+static int tegra186_mc_resume(struct tegra_mc *mc)
+{
+	unsigned int i;
+
+	for (i = 0; i < mc->soc->num_clients; i++) {
+		const struct tegra_mc_client *client = &mc->soc->clients[i];
+
+		tegra186_mc_client_sid_override(mc, client, client->sid);
+	}
+
+	return 0;
+}
+
 #if IS_ENABLED(CONFIG_IOMMU_API)
 static void tegra186_mc_client_sid_override(struct tegra_mc *mc,
 					    const struct tegra_mc_client *client,
@@ -139,6 +152,7 @@  static int tegra186_mc_probe_device(struct tegra_mc *mc, struct device *dev)
 const struct tegra_mc_ops tegra186_mc_ops = {
 	.probe = tegra186_mc_probe,
 	.remove = tegra186_mc_remove,
+	.resume = tegra186_mc_resume,
 	.probe_device = tegra186_mc_probe_device,
 	.handle_irq = tegra30_mc_handle_irq,
 };