From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [PATCH v2 10/21] arm: socfpga: Add secure register access helper functions for SoC 64bits
Date: Sun, 23 Feb 2020 15:02:44 +0100 [thread overview]
Message-ID: <c12d93eb-7e57-e808-8175-e8c454efa3ea@denx.de> (raw)
In-Reply-To: <BN7PR11MB2659849A8A43552FE77125A3A2120@BN7PR11MB2659.namprd11.prod.outlook.com>
On 2/21/20 8:06 PM, Ang, Chee Hong wrote:
>> On 2/21/20 7:01 PM, Ang, Chee Hong wrote:
>>>> On 2/20/20 6:54 PM, Ang, Chee Hong wrote:
>>>>>> On 2/20/20 3:02 AM, Ang, Chee Hong wrote:
>>>>>> [...]
>>>>>>>>> +#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_ATF)
>>>>>>>>> +u32 socfpga_secure_reg_read32(phys_addr_t reg_addr); void
>>>>>>>>> +socfpga_secure_reg_write32(u32 val, phys_addr_t reg_addr); void
>>>>>>>>> +socfpga_secure_reg_update32(phys_addr_t reg_addr, u32 mask, u32
>>>>>>>>> +val); #else
>>>>>>>>> +#define socfpga_secure_reg_read32 readl
>>>>>>>>> +#define socfpga_secure_reg_write32 writel
>>>>>>>>> +#define socfpga_secure_reg_update32 clrsetbits_le32
>>>>>>>>> +#endif
>>>>>>>>
>>>>>>>> I think I don't understand how this is supposed to work. Would
>>>>>>>> every place in U- Boot have to be patched to call these functions now ?
>>>>>>>
>>>>>>> Not every register access need this. Only those accessing
>>>>>>> registers in secure zone such as 'System Manager' registers need to call
>> this.
>>>>>>> It's basically determine whether the driver should issue SMC/PSCI
>>>>>>> call if it's running in EL2 (non-secure) or access the registers
>>>>>>> directly by simply using
>>>>>> readl/writel and etc if it's running in EL3 (secure).
>>>>>>> Accessing those registers in secure zone in non-secure mode (EL2)
>>>>>>> will cause
>>>>>> SError exception.
>>>>>>> So we can determine this behaviour in compile time:
>>>>>>> SPL always running in EL3. So it just simply fallback to use
>>>>>> readl/writel/clrsetbits_le32.
>>>>>>>
>>>>>>> For U-Boot proper (SSBL), there are 2 scenarios:
>>>>>>> 1) If CONFIG_SPL_ATF is defined, it means ATF is supported. It
>>>>>>> implies that U-Boot proper will be running in EL2 (non-secure),
>>>>>>> then it will use
>>>>>> SMC/PSCI calls to access the secure registers.
>>>>>>>
>>>>>>> 2) CONFIG_SPL_ATF is not defined, no ATF support. U-Boot proper
>>>>>>> will be running in EL3 which will fall back to simply using the
>>>>>>> direct access functions
>>>>>> (readl/writel and etc).
>>>>>>
>>>>>> I would expect the standard IO accessors would or should handle this stuff ?
>>>>> Standard IO accessors are just general memory read/write functions
>>>>> designed to be compatible with general hardware platforms. Not all
>>>>> platforms have secure/non-secure hardware zones. I don't think they
>>>>> should
>>>> handle this.
>>>>>
>>>>> If it's running in EL3 (secure mode) the standard I/O accessors will
>>>>> work just fine because
>>>>> EL3 can access to all secure/non-secure zones. In the header file,
>>>>> you can see the secure I/O accessors will be replaced by the
>>>>> standard I/O accessors if it's built for SPL and U-Boot proper
>>>>> without ATF. Because both are
>>>> running in EL3 (secure).
>>>>>
>>>>> If ATF is enabled, SPL will be still running in EL3 but U-Boot
>>>>> proper will be running in
>>>>> EL2 (non-secure). If any code accessing those secure zones without
>>>>> going through ATF (making SMC/PSCI calls to EL3), it will trigger 'SError'
>>>> exceptions and crash the U-Boot.
>>>>
>>>> Hmmm, if U-Boot is running in EL2 (non-secure), why would it ever
>>>> access secure zones in the first place ?
>>> SPL and U-Boot reuse the same drivers code. It runs without issue in
>>> SPL (EL3) but it crashes if running the same driver code in EL2 which access
>> some secure zone registers.
>>> The System Manager (secure zone) contains some register which control
>>> the behaviours of EMAC/SDMMC and etc. Clock manager driver rely on
>>> those registers in System Manager as well for retrieving clock
>>> information. These clock/EMAC/SDMMC drivers access the System Manager
>> (secure zone).
>>
>> Maybe those registers should only be configured by the secure OS, so maybe
>> those drivers should be fixed ?
>>
>>>> And if that's really necessary, should the ATF really provide
>>>> secure-mode register access primitives or should it provide some more high-
>> level interface instead ?
>>> I see your point. I should have mentioned to you that these
>>> secure-mode register access provided by ATF actually do more stuffs than just
>> primitive accessors.
>>
>> So socfpga_secure_reg_read32 does not just read a register ? Then the naming
>> is misleading . And documentation is missing.
>>
>>> ATF only allow certain secure registers required by the non-secure driver to be
>> accessed.
>>> It will check the secure register address and block access if the
>>> register address is not allowed to be accessed by non-secure world (EL2).
>>
>> Why don't you configure those secure registers in the secure mode then ?
>> It seems like that's the purpose of those registers being secure only.
>>
>>> So these secure register access provided by ATF is not just simple
>>> accessor/delegate which simply allow access to any secure zone from non-
>> secure world without any restrictions.
>>> I would say the secure register access provided by ATF is a
>>> 'middle-level' interface not just some primitive accessors.
>>>
>>> Currently, we have like 20+ secure registers allowed access by drivers
>>> running in non-secure mode (U-Boot proper / Linux).
>>> I don't think we want to define and maintain those high level
>>> interfaces for each of those secure register accesses in ATF and U-Boot.
>>
>> See above.
> OK. Then these secure access register should be set up in SPL (EL3).
> U-Boot drivers shouldn't access them at all because the driver may be running
> in SPL(EL3) and in U-Boot proper (EL2) too.
> I can take a look at those drivers accessing secure registers and try
> to move/decouple those secure access from U-Boot drivers to SPL (EL3) then we no
> longer need those secure register access functions.
I think that would be great, no ?
> I am not sure doing this will impact the functionality of the U-Boot driver
> running in EL2 or not.
> I can refactor those drivers and try it out.
Thanks!
next prev parent reply other threads:[~2020-02-23 14:02 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-19 12:25 [PATCH v2 00/21] Enable ARM Trusted Firmware for U-Boot chee.hong.ang at intel.com
2020-02-19 12:25 ` [PATCH v2 01/21] configs: agilex: Remove CONFIG_OF_EMBED chee.hong.ang at intel.com
2020-02-19 17:10 ` Marek Vasut
2020-02-20 2:12 ` Ang, Chee Hong
2020-02-20 16:44 ` Marek Vasut
2020-02-20 17:04 ` Westergreen, Dalon
2020-02-21 16:24 ` Marek Vasut
2020-02-21 18:15 ` Ang, Chee Hong
2020-02-23 13:55 ` Marek Vasut
2020-02-24 2:26 ` Ang, Chee Hong
2020-02-25 17:55 ` Marek Vasut
2020-02-25 18:26 ` Westergreen, Dalon
2020-02-25 18:42 ` Marek Vasut
2020-02-25 18:56 ` Westergreen, Dalon
2020-02-19 12:25 ` [PATCH v2 02/21] arm: socfpga: add fit source file for pack itb with ATF chee.hong.ang at intel.com
2020-02-19 12:25 ` [PATCH v2 03/21] arm: socfpga: Add function for checking description from FIT image chee.hong.ang at intel.com
2020-02-19 17:11 ` Marek Vasut
2020-02-19 17:31 ` Dalon L Westergreen
2020-02-19 17:32 ` Marek Vasut
2020-02-19 12:25 ` [PATCH v2 04/21] arm: socfpga: Load FIT image with ATF support chee.hong.ang at intel.com
2020-02-19 12:25 ` [PATCH v2 05/21] arm: socfpga: Override 'lowlevel_init' to support ATF chee.hong.ang at intel.com
2020-02-19 17:13 ` Marek Vasut
2020-02-20 2:27 ` Ang, Chee Hong
2020-02-20 16:44 ` Marek Vasut
2020-02-20 19:05 ` Ang, Chee Hong
2020-02-21 16:26 ` Marek Vasut
2020-02-21 18:35 ` Ang, Chee Hong
2020-02-21 18:46 ` Ang, Chee Hong
2020-02-23 13:59 ` Marek Vasut
2020-02-19 12:25 ` [PATCH v2 06/21] configs: socfpga: Enable FIT image loading with ATF support chee.hong.ang at intel.com
2020-02-19 17:14 ` Marek Vasut
2020-02-20 2:15 ` Ang, Chee Hong
2020-02-20 16:45 ` Marek Vasut
2020-02-20 20:00 ` Simon Goldschmidt
2020-02-20 22:20 ` Westergreen, Dalon
2020-02-19 12:25 ` [PATCH v2 07/21] arm: socfpga: Disable "spin-table" method for booting Linux chee.hong.ang at intel.com
2020-02-19 12:25 ` [PATCH v2 08/21] arm: socfpga: Add SMC helper function for Intel SOCFPGA (64bits) chee.hong.ang at intel.com
2020-02-19 17:15 ` Marek Vasut
2020-02-20 1:32 ` Ang, Chee Hong
2020-02-19 12:25 ` [PATCH v2 09/21] arm: socfpga: Define SMC function identifiers for PSCI SiP services chee.hong.ang at intel.com
2020-02-19 17:18 ` Marek Vasut
2020-02-20 1:42 ` Ang, Chee Hong
2020-02-20 16:46 ` Marek Vasut
2020-02-19 12:25 ` [PATCH v2 10/21] arm: socfpga: Add secure register access helper functions for SoC 64bits chee.hong.ang at intel.com
2020-02-19 17:20 ` Marek Vasut
2020-02-20 2:02 ` Ang, Chee Hong
2020-02-20 16:47 ` Marek Vasut
2020-02-20 17:54 ` Ang, Chee Hong
2020-02-21 16:31 ` Marek Vasut
2020-02-21 18:01 ` Ang, Chee Hong
2020-02-21 18:07 ` Marek Vasut
2020-02-21 19:06 ` Ang, Chee Hong
2020-02-23 14:02 ` Marek Vasut [this message]
2020-02-24 2:21 ` Ang, Chee Hong
2020-02-25 17:54 ` Marek Vasut
2020-02-26 0:44 ` Ang, Chee Hong
2020-02-28 2:53 ` Ang, Chee Hong
2020-02-28 7:46 ` Simon Goldschmidt
2020-02-28 8:53 ` Ang, Chee Hong
2020-02-19 12:25 ` [PATCH v2 11/21] arm: socfpga: Secure register access for clock manager (SoC 64bits) chee.hong.ang at intel.com
2020-02-19 17:21 ` Marek Vasut
2020-02-20 2:32 ` Ang, Chee Hong
2020-02-20 16:48 ` Marek Vasut
2020-02-20 18:20 ` Ang, Chee Hong
2020-02-22 5:30 ` Ang, Chee Hong
2020-02-22 7:31 ` Simon Goldschmidt
2020-02-22 9:59 ` Ang, Chee Hong
2020-02-24 9:11 ` Ang, Chee Hong
2020-02-24 9:16 ` Simon Goldschmidt
2020-02-24 10:52 ` Ang, Chee Hong
2020-02-19 12:25 ` [PATCH v2 12/21] arm: socfpga: Secure register access in PHY mode setup chee.hong.ang at intel.com
2020-02-22 5:35 ` Ang, Chee Hong
2020-02-23 14:13 ` Marek Vasut
2020-02-19 12:25 ` [PATCH v2 13/21] arm: socfpga: Secure register access for reading PLL frequency chee.hong.ang at intel.com
2020-02-22 5:40 ` Ang, Chee Hong
2020-02-22 10:05 ` Ang, Chee Hong
2020-02-23 14:14 ` Marek Vasut
2020-02-24 2:06 ` Ang, Chee Hong
2020-02-24 7:15 ` Ang, Chee Hong
2020-02-24 9:13 ` Ang, Chee Hong
2020-02-19 12:25 ` [PATCH v2 14/21] mmc: dwmmc: socfpga: Secure register access in MMC driver chee.hong.ang at intel.com
2020-02-22 5:47 ` Ang, Chee Hong
2020-02-19 12:25 ` [PATCH v2 15/21] net: designware: socfpga: Secure register access in MAC driver chee.hong.ang at intel.com
2020-02-22 5:52 ` Ang, Chee Hong
2020-02-19 12:25 ` [PATCH v2 16/21] arm: socfpga: Secure register access in Reset Manager driver chee.hong.ang at intel.com
2020-02-22 5:59 ` Ang, Chee Hong
2020-02-19 12:25 ` [PATCH v2 17/21] arm: socfpga: stratix10: Initialize timer in SPL chee.hong.ang at intel.com
2020-02-19 12:25 ` [PATCH v2 18/21] arm: socfpga: Bridge reset invokes SMC service calls in EL2 chee.hong.ang at intel.com
2020-02-19 12:25 ` [PATCH v2 19/21] arm: socfpga: stratix10: Add ATF support to FPGA reconfig driver chee.hong.ang at intel.com
2020-02-19 12:25 ` [PATCH v2 20/21] arm: socfpga: mailbox: Add 'SYSTEM_RESET' PSCI support to mbox_reset_cold() chee.hong.ang at intel.com
2020-02-19 12:25 ` [PATCH v2 21/21] configs: socfpga: Add defconfig for Agilex and Stratix 10 without ATF support chee.hong.ang at intel.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c12d93eb-7e57-e808-8175-e8c454efa3ea@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.