Skip to content

drivers: qcom: RNG and WDT Driver Consolidation#7855

Open
thariaruchamy-bit wants to merge 4 commits into
OP-TEE:masterfrom
thariaruchamy-bit:optee-upstream
Open

drivers: qcom: RNG and WDT Driver Consolidation#7855
thariaruchamy-bit wants to merge 4 commits into
OP-TEE:masterfrom
thariaruchamy-bit:optee-upstream

Conversation

@thariaruchamy-bit

Copy link
Copy Markdown

This pull request consolidates and refactors QCOM RNG and WDT drivers
with unified naming conventions and improved configuration management.

RNG Driver Consolidation

Refactor PRNG driver into generic RNG implementation:

  • Rename prng.c to qcom-rng.c for platform-agnostic naming
  • Move driver source inclusion to parent qcom/sub.mk with CFG_QCOM_RNG flag
  • Simplify driver by using generic RNG naming conventions

Platform configuration updates:

  • Update from CFG_QCOM_PRNG to unified CFG_QCOM_RNG
  • Configure RNG_REG_BASE for PRNG variant
  • Enable CFG_HWRNG_PTA configuration for ipq52xx
  • When HWRNG_PTA is enabled:
    • Disable CFG_WITH_SOFTWARE_PRNG to prevent fallback
    • Force enable CFG_QCOM_RNG to use hardware RNG driver
    • Configure HWRNG quality to 1024 bits entropy
    • Set HWRNG rate to 0 (unlimited)

Secure Watchdog Driver

Add secure watchdog driver for Bobcat family:

QCOM platforms manage secure watchdog via driver_init() without framework
registration. This is sufficient as QCOM currently does not require HLOS
control over the secure watchdog. The implementation maintains separation
between secure and non-secure world watchdog management.

Implementation details:

  • Maps WDT_TMR_BASE into secure I/O memory
  • Configures bark timeout (6s) and bite timeout (22s) using 32 KHz clock
  • Registers qcom_sec_wdog_bark_handler() for WDT_BARK_INT_ID
  • Bark handler pets watchdog by writing to WDT_RESET_REG register

Platform enablement for Bobcat family:

  • CFG_QCOM_SEC_WDOG enabled in bobcat/arch.mk for all Bobcat targets
  • Per-target hardware addresses defined in target-specific configs:
    • ipq96xx/ipq54xx: base=0x0F411000, bark_int=0x36
    • ipq52xx: base=0x0B117000, bark_int=0x23

@github-actions

Copy link
Copy Markdown

FYI @ldts @b49020 @zelvam95

Comment thread core/drivers/qcom/rng/qcom-rng.c Outdated
Comment thread core/drivers/qcom/wdt/wdt.c Outdated
@thariaruchamy-bit thariaruchamy-bit force-pushed the optee-upstream branch 2 times, most recently from 3dd88b6 to 24ab177 Compare June 25, 2026 07:11
@zelvam95

Copy link
Copy Markdown
Contributor

Based on above + earlier elaborate review here qualcomm-linux/optee_os#15

Reviewed-by: Selvam Sathappan Periakaruppan <speriaka@qti.qualcomm.com>

@thariaruchamy-bit

Copy link
Copy Markdown
Author

@b49020 @ldts Gentle remainder to share any other feedback.

Comment thread core/arch/arm/plat-qcom/bobcat/qcom-arch.mk
Harikrishna added 4 commits June 26, 2026 12:53
- Rename prng.c to qcom-rng.c for platform-agnostic naming
- Move driver source inclusion to parent qcom/sub.mk with
  CFG_QCOM_RNG flag
- Simplify driver by using generic RNG naming conventions

Change-Id: I5b262d5038e10aca7f6b4e8ee93847006b1b0a9f
Signed-off-by: Harikrishna <hart@qti.qualcomm.com>
Reviewed-by: Selvam Sathappan Periakaruppan <speriaka@qti.qualcomm.com>
- Update from CFG_QCOM_PRNG to unified CFG_QCOM_RNG
- Configure RNG_REG_BASE for PRNG variant
- Enable CFG_HWRNG_PTA configuration for ipq52xx
- When HWRNG_PTA is enabled:
   - Disable CFG_WITH_SOFTWARE_PRNG to prevent fallback
   - Force enable CFG_QCOM_RNG to use hardware QRNG driver
   - Configure HWRNG quality to 1024 bits entropy
   - Set HWRNG rate to 0 (unlimited)

Signed-off-by: Harikrishna <hart@qti.qualcomm.com>
Reviewed-by: Selvam Sathappan Periakaruppan <speriaka@qti.qualcomm.com>
QCOM platforms manage secure watchdog via driver_init() without
framework registration. This is sufficient as QCOM currently
does not require HLOS control over the secure watchdog. The
implementation maintains separation between secure and
non-secure world watchdog management.

Key implementation details:
- Maps APSS_WDT_TMR2_BASE into secure I/O memory
- Configures bark timeout (6s) and bite timeout (22s)
  using a 32 KHz watchdog clock, converting milliseconds
  to hardware ticks
- Registers qcom_sec_wdog_bark_handler() for
  SEC_WDOG_BARK_INT_ID via interrupt_create_handler()
- Bark handler pets the watchdog by writing to
  WDOG_RESET register

Signed-off-by: Harikrishna <hart@qti.qualcomm.com>
Reviewed-by: Selvam Sathappan Periakaruppan <speriaka@qti.qualcomm.com>
- CFG_QCOM_SEC_WDOG enabled in bobcat/arch.mk for
all Bobcat targets
- Per-target hardware addresses
  (WDT_TMR_BASE, WDT_BARK_INT_ID,
  WDT_RESET_REG_OFFSET)
  defined in target-specific target_config.h files:
  - ipq96xx/ipq54xx: base=0x0F411000, bark_int=0x36
  - ipq52xx: base=0x0B117000, bark_int=0x23

Signed-off-by: Harikrishna <hart@qti.qualcomm.com>
Reviewed-by: Selvam Sathappan Periakaruppan <speriaka@qti.qualcomm.com>
}

static TEE_Result qcom_prng_init(void)
static TEE_Result rng_init(void)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather rename the API as qcom_rng_init().

#

global-incdirs-y += .
srcs-$(CFG_QCOM_RNG) += qcom-rng.c

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this sub.mk really needed as you include the file in outside sub.mk directly?

#include <rng_support.h>

#define SEC_PRNG_REG_SIZE 0x1000
#define RNG_REG_SIZE 0x1000

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather rename all the macros with a QCOM_ prefix

} prng = {
.pa = SEC_PRNG_REG_BASE,
} rng = {
.pa = RNG_REG_BASE,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will break build after this individual commit, change the targets to define the new macro: QCOM_RNG_REG_BASE in this commit only.

CFG_QCOM_RAMBLUR_TA_WINDOW_ID ?= 2

$(call force,CFG_QCOM_PRNG,y)
$(call force,CFG_QCOM_RNG,y)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These changes should be folded in prior commit as the driver was already enabled for hoya platforms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't write commit descriptions as all the bullet point, rather than write small paras to summarize.

static uint32_t ms_to_ticks_wdt(uint32_t ms)
{
return (uint32_t)(((uint64_t)ms * WDT_CLK_HZ) / 1000U);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather create a macro for this

return TEE_SUCCESS;
}

driver_init(wdt_init);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use qcom_ prefixes for the APIs and macros.

Comment thread core/drivers/qcom/sub.mk

srcs-$(CFG_QCOM_RAMBLUR_PIMEM_V3) += ramblur/ramblur_pimem_v3.c
srcs-$(CFG_QCOM_RNG) += rng/qcom-rng.c
srcs-$(CFG_QCOM_SEC_WDOG) += wdt/wdt.c

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rename file as qcom-wdt.c

#define RNG_REG_BASE UL(0x4C5000)

#define WDT_TMR_BASE UL(0x0B117000)
#define WDT_RESET_REG_OFFSET UL(0x4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this offset macro move to the driver itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants