Skip to content

Conversation

@jsuhaas22
Copy link
Contributor

@jsuhaas22 jsuhaas22 commented Dec 16, 2025

This PR firewalls DTHEv2 module, which is used in AM62L SoC.

SA2UL is already firewall'ed, and the code for doing that is in SA2UL's driver. Therefore this PR first makes that code block a generic ti_sci function, and then calls it in SA2UL and DTHEv2.

@github-actions
Copy link

FYI @glneo

start_address = RNG_BASE;
end_address = RNG_BASE + RNG_REG_SIZE - 1;
permissions[num_perm++] = (FW_BIG_ARM_PRIVID << 16) | FW_SECURE_ONLY;
#if defined(PLATFORM_FLAVOR_am62x) || \

Choose a reason for hiding this comment

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

@jsuhaas22 I don't see the Platform checks being used in earlier sa2ul.c file while setting permissions. Can you please confirm this will not create an issue for Jacinto/am64 platforms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shiva-ti I wrote this code a few months back. Since then, the #ifdefined block in SA2UL was removed in commit 7c90e11. But since the function is a new and separate one in ti_sci.c, nothing was caught during the rebase.

I have removed that part now, and tested it on AM62L and AM62x.

Copy link
Contributor

@Pratham-T Pratham-T left a comment

Choose a reason for hiding this comment

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

Hi @jsuhaas22, some comments below.

Comment on lines 525 to 577
int ti_sci_init_rng_fwl(uint16_t fwl_id, uint16_t sec_accel_region)
{
uint16_t rng_region = RNG_TI_SCI_FW_RGN_ID;
uint8_t owner_index = OPTEE_HOST_ID;
uint8_t owner_privid = 0;
uint16_t owner_permission_bits = 0;
uint32_t control = 0;
uint32_t permissions[FWL_MAX_PRIVID_SLOTS] = { };
uint32_t num_perm = 0;
uint64_t start_address = 0;
uint64_t end_address = 0;
int ret = 0;

/* Try to claim Security Accelerator firewall for ourselves */
ret = ti_sci_change_fwl_owner(fwl_id, sec_accel_region, owner_index,
&owner_privid, &owner_permission_bits);
if (ret) {
/*
* This is not fatal, it just means we are on an HS device
* where the DMSC already owns the accelerator. On GP we need
* to do additional setup for access permissions below.
*/
DMSG("Could not change Security Accelerator firewall owner");
} else {
IMSG("Fixing Security Accelerator firewall owner in GP device");

/* Get current firewall configuration */
ret = ti_sci_get_fwl_region(fwl_id, sec_accel_region, 1,
&control, permissions,
&start_address, &end_address);
if (ret) {
EMSG("Could not get firewall region information");
return TEE_ERROR_GENERIC;
}

/* Modify firewall to allow all others access*/
control = FW_BACKGROUND_REGION | FW_ENABLE_REGION;
permissions[0] = (FW_WILDCARD_PRIVID << 16) | FW_NON_SECURE;
ret = ti_sci_set_fwl_region(fwl_id, sec_accel_region, 1,
control, permissions,
0x0, UINT32_MAX);
if (ret) {
EMSG("Could not set firewall region information");
return TEE_ERROR_GENERIC;
}
}
/* Claim the TRNG firewall for ourselves */
ret = ti_sci_change_fwl_owner(fwl_id, rng_region, owner_index,
&owner_privid, &owner_permission_bits);
if (ret) {
EMSG("Could not change TRNG firewall owner");
return TEE_ERROR_GENERIC;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually unnecessary for AM62L. The eip76 TRNG block is outside the DTHEv2 block and has a separate firewall ID. So the code acquiring security accelerator region is essentially doing nothing in HS devices and is configuring 2 regions in the TRNG firewall in GP devices as you are using the same fwl ID for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done @Pratham-T

return 0;
}

int ti_sci_init_rng_fwl(uint16_t fwl_id, uint16_t sec_accel_region)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very specific to rng devices and does not look fit to keep in ti_sci.c, which has only ti_sci API calls. Can this be moved in some crypto specific common file and be refactored to address my other comment as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jsuhaas22 jsuhaas22 force-pushed the ti-fwl-dthev2-rng branch 4 times, most recently from fd18f46 to cd2cec7 Compare December 19, 2025 06:47
* Texas Instruments Crypto Operations
*
* Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com/
* Suhaas Joshi <s-joshi@ti.com>
Copy link
Contributor

Choose a reason for hiding this comment

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

Bold of you to take existing code, move it to a different file, and claim it as your own..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I usually see only one name in the copyright section, so I assumed whoever creates the file should put theirs there. Sorry, fixed.

#include "ti_crypto.h"

TEE_Result ti_crypto_init_rng_fwl(uint16_t fwl_id, uint16_t fwl_region)

Copy link
Contributor

Choose a reason for hiding this comment

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

Random newline.

ret = ti_sci_change_fwl_owner(fwl_id, fwl_region, owner_index,
&owner_privid, &owner_permission_bits);
if (ret) {
#if !defined(PLATFORM_FLAVOR_am62lx)
Copy link
Contributor

Choose a reason for hiding this comment

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

This wasn't in the original. Do only the refactor in its own commit, all other changes go in follow up commits. That makes it easier to see what you are changing vs just moving around.

@jsuhaas22 jsuhaas22 force-pushed the ti-fwl-dthev2-rng branch 2 times, most recently from 063a414 to bb20bba Compare December 23, 2025 05:42
@glneo
Copy link
Contributor

glneo commented Dec 30, 2025

First commit looks better, thanks.

For the second, the original intention of fetching the current configuration is that we should be modifying that, not completely replacing it. But yes, currently we do overwrite all the returned setting so fetching first doesn't really do anything.

Anyway, for the series, Reviewed-by: Andrew Davis <afd@ti.com>

@jenswi-linaro
Copy link
Contributor

@Pratham-T do you have any more comments?

Copy link
Contributor

@Pratham-T Pratham-T left a comment

Choose a reason for hiding this comment

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

LGTM.

Reviewed-by: T Pratham <t-pratham@ti.com>

Comment on lines 9 to 10
#include <platform_config.h>
#include <drivers/ti_sci.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking: could you swap thee 2 lines above (alphabetical order)?
And add <trace.h>.

uint32_t num_perm = 0;
uint64_t start_address = 0;
uint64_t end_address = 0;
TEE_Result ret = TEE_SUCCESS;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TEE_Result ret = TEE_SUCCESS;
int ret = 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have done this, but why? We are assigning TEE error codes to this variable throughout the function, so isn't TEE_RESULT more appropriate?

return TEE_ERROR_GENERIC;
}

return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer explicit return TEE_SUCCESS, for consistency.

* ti_crypto_init_rng_fwl() - Initialize RNG firewall in SA2UL/DTHEv2
*
* Sets the firewall for the RNG region in SA2UL/DTHEv2 to allow access by only
* the secure world.

This comment was marked as resolved.

*/

#ifndef TI_CRYPTO_H
#define TI_CRYPTO_H
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is exported to drivers, would be better as:

#ifndef DRIVERS_TI_CRYPTO_H
#define DRIVERS_TI_CRYPTO_H

Not a strong opinion, seen the other header files in this directory.

Comment on lines 10 to 14
#include <compiler.h>
#include <stdint.h>
#include <util.h>
#include <io.h>
#include <initcall.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you sort in alphabetical order?
Actually could be replaced with:

Suggested change
#include <compiler.h>
#include <stdint.h>
#include <util.h>
#include <io.h>
#include <initcall.h>
#include <tee_api_types.h>
#include <stdint.h>

static TEE_Result dthev2_init(void)
{
TEE_Result result = TEE_SUCCESS;
int ret = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove ret and use result instead in the lines added below.

@jsuhaas22
Copy link
Contributor Author

Implemented your comments, @etienne-lms

@glneo and @Pratham-T -- since commits 1 and 3 changed, I have removed your "Rewiewed by: "'s, please review again.

EMSG("Could not set firewall region information");
return TEE_ERROR_GENERIC;
EMSG("Failed to enable firewalls for TRNG device");
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

ret is not a TEE_Result value.

Suggested change
return ret;
return TEE_ERROR_GENERIC;

return TEE_ERROR_GENERIC;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to preserve this empty line.

sa2ul_init() contains code to set firewall for SA2UL RNG. However,
almost the same code can also be used to firewall DTHEv2 RNG. Therefore
refactor this code into a separate function in the ti_sci driver.

Signed-off-by: Suhaas Joshi <s-joshi@ti.com>
The ti_crypto_init_rng_fwl() function gets firewall configurations
before setting new ones. This is pointless, since we are not using
the configurations that we get anywhere. Therefore remove these blocks
of code.

Signed-off-by: Suhaas Joshi <s-joshi@ti.com>
Reviewed-by: Andrew Davis <afd@ti.com>
Reviewed-by: T Pratham <t-pratham@ti.com>
Set firewall to protect DTHEv2 RNG from non-secure world.

Signed-off-by: Suhaas Joshi <s-joshi@ti.com>
Comment on lines +10 to +11
#include <tee_api_types.h>
#include <stdint.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are already knee deep, make this alphabetical as well.


result = ti_crypto_init_rng_fwl(DTHEv2_TI_SCI_FW_ID,
DTHEv2_TI_SCI_FW_RGN_ID);
if (result) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check the result with != TEE_SUCCESS

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.

6 participants