Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soc: nordic: Add LRCCONF management #79067

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adamkondraciuk
Copy link
Contributor

Due to the possibility of simultaneous accesess to LRCCONF registers, additional management is required.

adamkondraciuk added a commit to adamkondraciuk/sdk-zephyr that referenced this pull request Sep 26, 2024
Due to the possibility of simultaneous accesess to LRCCONF registers,
additional management is required.

Upstream PR: zephyrproject-rtos/zephyr#79067

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
adamkondraciuk added a commit to adamkondraciuk/sdk-zephyr that referenced this pull request Sep 26, 2024
Due to the possibility of simultaneous accesess to LRCCONF registers,
additional management is required.

Upstream PR: zephyrproject-rtos/zephyr#79067

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
/**
* @brief Request or release lrcconf main power domain
*/
void clock_request_lrcconf_poweron_main(struct clock_lrcconf_sink *sink);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove also the struct clock_lrcconf_sink definition. There is no need to keep it as it can be replaced with just sys_snode_t.

@@ -8,7 +8,7 @@
#include "clock_control_nrf2_common.h"
#include <zephyr/devicetree.h>
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
#include <hal/nrf_lrcconf.h>
#include <soc/nordic/common/soc_lrcconf.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <soc/nordic/common/soc_lrcconf.h>
#include <soc_lrcconf.h>

Comment on lines 11 to 12
sys_slist_t poweron_main_list;
sys_slist_t poweron_active_list;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be static.

@@ -3,6 +3,7 @@

if(CONFIG_ARM)
zephyr_library_sources(soc.c)
zephyr_library_sources(../common/soc_lrcconf.c)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it added only for ARM cores?
I think that instead of the above entry, the following should be added in soc/nordic/common/CMakeLists.txt (so that nRF92 could also use it):

zephyr_library_sources_ifdef(NRF_PLATFORM_HALTIUM soc_lrcconf.c)

#include "pm_s2ram.h"

#if !IS_ENABLED(CONFIG_SOC_NRF54H20_CPURAD)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if !IS_ENABLED(CONFIG_SOC_NRF54H20_CPURAD)
#if !defined(CONFIG_SOC_NRF54H20_CPURAD)

IS_ENABLED should only be used in C expressions. See:

* Note: Use of IS_ENABLED in a <tt>\#if</tt> statement is discouraged
* as it doesn't provide any benefit vs plain <tt>\#if defined()</tt>

Comment on lines 64 to 69
sys_snode_t *node;
#if IS_ENABLED(CONFIG_PM) || IS_ENABLED(CONFIG_POWEROFF)
node = pm_sys_node_id_get();
#else
node = &soc_node;
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a leftover from some previous approach. node is not used by the code below.

/**
* @brief Perform a power off.
*
* This function performs a power off of the core.
*/
void nrf_poweroff(void);

/**
* @brief Pepare to the idle state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "Pepare"

/**
* @brief Pepare to the idle state.
*
* This function applies required PM configuration must be performed before the idle state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence seems to need rephrasing.

adamkondraciuk added a commit to adamkondraciuk/sdk-zephyr that referenced this pull request Sep 27, 2024
Due to the possibility of simultaneous accesess to LRCCONF registers,
additional management is required.

Upstream PR: zephyrproject-rtos/zephyr#79067

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
do_suspend_to_ram();
#endif
}

void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
{
#if !defined(CONFIG_SOC_NRF54H20_CPURAD)
if (state == PM_STATE_SUSPEND_TO_IDLE) {
soc_lrcconf_poweron_release(&pm_node, NRF_LRCCONF_POWER_DOMAIN_0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only releases the poweron request when PM_STATE_SUSPEND_TO_IDLE was used to call k_cpu_idle() via the pm subsystem, but if the pm subsystem decided against suspending the system it will call k_cpu_idle() here instead and then not call the release.
This can happen if the is no suspend-to-idle state defined in devicetree or it has a minimum residency time that isn't met, e.g. a k_msleep(10) for with this pm configuration https://github.com/nrfconnect/sdk-nrf/blob/84492d6d9264745050a018d01f4f333b285864c1/tests/benchmarks/multicore/idle/boards/nrf54h20dk_nrf54h20_cpuapp_s2ram.overlay#L12C39-L12C39

This is still way better than losing power, but needs to be followed up to have all paths covered eventually

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a mechanism to supply an exit hook on arm cores

config ARM_ON_EXIT_CPU_IDLE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is this mechanism but it is quite ugly and requires special header with a macro. It was added as a workaround for PAN where code need to be executed immediately after WFI (so function cannot be used). I have #71667 which adds function hook symmetric to on_enter hook but PR stuck.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe your PR would have a clean usecase now and it could be argued for again to avoid that assembly mess?

*
* @return The pointer to the node assigned to PM module.
*/
sys_snode_t *pm_sys_node_id_get(void);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does not seem to be needed anymore. It looks a bit like a hack actually.

@@ -28,6 +28,7 @@ config SOC_NRF54H20_CPUAPP
select NRFS_HAS_VBUS_DETECTOR_SERVICE
select HAS_PM
select HAS_POWEROFF
select ARM_ON_ENTER_CPU_IDLE_HOOK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be selected only when actually needed, so if PM || POWEROFF?

adamkondraciuk added a commit to adamkondraciuk/sdk-zephyr that referenced this pull request Sep 27, 2024
Due to the possibility of simultaneous accesess to LRCCONF registers,
additional management is required.

Upstream PR: zephyrproject-rtos/zephyr#79067

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
static sys_slist_t poweron_main_list;
static sys_slist_t poweron_active_list;

void soc_lrcconf_poweron_request(sys_snode_t *node, nrf_lrcconf_power_domain_mask_t domain)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why simple reference counter is not used here? I only see that the difference is that you keep list of clients (but its not used anywhere) and allow to have non-symmetric requests (second request from the same client is not counted) but it can potentially cause some issues. Reference counter would be simpler and use less resources.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least right now there is non-symmetric requests so it couldn't be dropped

do_suspend_to_ram();
#endif
}

void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
{
#if !defined(CONFIG_SOC_NRF54H20_CPURAD)
if (state == PM_STATE_SUSPEND_TO_IDLE) {
soc_lrcconf_poweron_release(&pm_node, NRF_LRCCONF_POWER_DOMAIN_0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is this mechanism but it is quite ugly and requires special header with a macro. It was added as a workaround for PAN where code need to be executed immediately after WFI (so function cannot be used). I have #71667 which adds function hook symmetric to on_enter hook but PR stuck.

Due to the possibility of simultaneous accesess to LRCCONF registers,
additional management is required.

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
adamkondraciuk added a commit to adamkondraciuk/sdk-zephyr that referenced this pull request Sep 27, 2024
Due to the possibility of simultaneous accesess to LRCCONF registers,
additional management is required.

Upstream PR: zephyrproject-rtos/zephyr#79067

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants