Skip to content

Commit e45b802

Browse files
tomi-fontendre-nordic
authored andcommitted
nrf_security: drivers: cracen: small improvements
- Improve CRACEN memory read/write logging. Now the macro that enables the logging is prefixed with SX_ and some non-word-aligned reads/writes are logged. - Some minor cleanups. Signed-off-by: Tomi Fontanilles <[email protected]>
1 parent 1af0898 commit e45b802

File tree

5 files changed

+49
-30
lines changed

5 files changed

+49
-30
lines changed

subsys/nrf_security/src/drivers/cracen/sicrypto/src/sicrypto.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <cracen/statuscodes.h>
1111
#include "waitqueue.h"
1212

13-
extern struct sx_pk_cnx silex_pk_engine;
14-
1513
void si_task_init(struct sitask *t, char *workmem, size_t workmemsz)
1614
{
1715
assert(t);

subsys/nrf_security/src/drivers/cracen/silexpk/include/silexpk/iomem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#ifndef IOMEM_HEADER_FILE
88
#define IOMEM_HEADER_FILE
99

10+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
11+
#define SX_WARN_UNALIGNED_ADDR(addr) printk("%s: WARNING: unaligned address %p\r\n", __func__, addr)
12+
#else
13+
#define SX_WARN_UNALIGNED_ADDR(addr)
14+
#endif
15+
1016
/** Clear device memory
1117
*
1218
* @param[in] dst Memory to clear.

subsys/nrf_security/src/drivers/cracen/silexpk/target/baremetal_ba414e_with_ik/pk_baremetal.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
#include <zephyr/kernel.h>
1010

11+
#include "../hw/ba414/ba414_status.h"
12+
#include "../hw/ba414/pkhardware_ba414e.h"
1113
#include "../hw/ba414/regs_addr.h"
14+
#include "../hw/ik/ikhardware.h"
15+
#include "../hw/ik/regs_addr.h"
1216
#include <silexpk/core.h>
13-
#include "../hw/ba414/pkhardware_ba414e.h"
17+
#include <silexpk/iomem.h>
1418
#include <cracen/interrupts.h>
1519
#include <cracen/statuscodes.h>
16-
#include "../hw/ba414/ba414_status.h"
17-
#include "../hw/ik/ikhardware.h"
18-
#include "../hw/ik/regs_addr.h"
1920
#include "internal.h"
2021

2122
#include <hal/nrf_cracen.h>
@@ -29,10 +30,6 @@
2930
#define ADDR_BA414EP_CRYPTORAM_BASE CRACEN_ADDR_BA414EP_CRYPTORAM_BASE
3031
#endif
3132

32-
#ifndef SX_PK_MICROCODE_ADDRESS
33-
#define SX_PK_MICROCODE_ADDRESS CRACEN_SX_PK_MICROCODE_ADDRESS
34-
#endif
35-
3633
#ifndef NULL
3734
#define NULL (void *)0
3835
#endif
@@ -50,7 +47,7 @@ struct sx_pk_cnx {
5047
struct sx_pk_blinder *b;
5148
};
5249

53-
struct sx_pk_cnx silex_pk_engine;
50+
static struct sx_pk_cnx silex_pk_engine;
5451

5552
NRF_SECURITY_MUTEX_DEFINE(cracen_mutex_asymmetric);
5653

@@ -107,9 +104,12 @@ void sx_pk_wrreg(struct sx_regs *regs, uint32_t addr, uint32_t v)
107104
{
108105
volatile uint32_t *p = (uint32_t *)(regs->base + addr);
109106

110-
#ifdef INSTRUMENT_MMIO_WITH_PRINTFS
111-
printk("sx_pk_wrreg(addr=0x%x, sum=0x%x, val=0x%x);\r\n", addr, (uint32_t)p, v);
107+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
108+
printk("sx_pk_wrreg(addr=0x%x, p=%p, val=0x%x)\r\n", addr, p, v);
112109
#endif
110+
if ((uintptr_t)p % 4) {
111+
SX_WARN_UNALIGNED_ADDR(p);
112+
}
113113

114114
*p = v;
115115
}
@@ -119,10 +119,17 @@ uint32_t sx_pk_rdreg(struct sx_regs *regs, uint32_t addr)
119119
volatile uint32_t *p = (uint32_t *)(regs->base + addr);
120120
uint32_t v;
121121

122+
123+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
124+
printk("sx_pk_rdreg(addr=0x%x, p=%p)\r\n", addr, p);
125+
#endif
126+
if ((uintptr_t)p % 4) {
127+
SX_WARN_UNALIGNED_ADDR(p);
128+
}
129+
122130
v = *p;
123131

124-
#ifdef INSTRUMENT_MMIO_WITH_PRINTFS
125-
printk("sx_pk_rdreg(addr=0x%x, sum=0x%x);\r\n", addr, (uint32_t)p);
132+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
126133
printk("result = 0x%x\r\n", v);
127134
#endif
128135

subsys/nrf_security/src/drivers/cracen/silexpk/target/hw/ba414/pkhardware_ba414e.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef PKHARDWARE_BA414E_H
99
#define PKHARDWARE_BA414E_H
1010

11+
#include <silexpk/core.h>
1112
#include <stdint.h>
1213

1314
struct sx_pk_cmd_def {

subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src/hw.h

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include <sxsymcrypt/internal.h>
1515
#include <cracen/interrupts.h>
1616

17+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
18+
#include <zephyr/sys/printk.h>
19+
#endif
20+
1721
#ifdef CONFIG_DCACHE
1822
#include <zephyr/cache.h>
1923
#endif
@@ -25,11 +29,8 @@
2529
#ifndef SX_CM_REGS_ADDR
2630
#define SX_CM_REGS_ADDR ((uint32_t)NRF_CRACENCORE)
2731
#endif
28-
#ifndef SX_TRNG_REGS_OFFSET
29-
#define SX_TRNG_REGS_OFFSET 0x1000
30-
#endif
3132
#ifndef SX_TRNG_REGS_ADDR
32-
#define SX_TRNG_REGS_ADDR ((SX_CM_REGS_ADDR) + (SX_TRNG_REGS_OFFSET))
33+
#define SX_TRNG_REGS_ADDR ((uint32_t)&NRF_CRACENCORE->RNGCONTROL)
3334
#endif
3435

3536
struct sxdesc;
@@ -39,8 +40,8 @@ static inline void sx_wrreg(uint32_t addr, uint32_t val)
3940
{
4041
volatile uint32_t *p = (uint32_t *)(SX_CM_REGS_ADDR + addr);
4142

42-
#ifdef INSTRUMENT_MMIO_WITH_PRINTFS
43-
printk("sx_wrregx(addr=%x, sum=%x, val=%d);", addr, p, val);
43+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
44+
printk("sx_wrreg(addr=0x%x, p=%p, val=0x%x)\r\n", addr, p, val);
4445
#endif
4546

4647
wmb(); /* comment for compliance */
@@ -53,8 +54,8 @@ static inline void sx_wr_trng(uint32_t addr, uint32_t val)
5354
{
5455
volatile uint32_t *p = (uint32_t *)(SX_TRNG_REGS_ADDR + addr);
5556

56-
#ifdef INSTRUMENT_MMIO_WITH_PRINTFS
57-
printk("sx_wrregx(addr=%x, sum=%x, val=%d);", addr, p, val);
57+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
58+
printk("sx_wr_trng(addr=0x%x, p=%p, val=0x%x)\r\n", addr, p, val);
5859
#endif
5960

6061
wmb(); /* comment for compliance */
@@ -67,6 +68,9 @@ static inline void sx_wrreg_addr(uint32_t addr, struct sxdesc *p)
6768
{
6869
volatile size_t *d = (volatile size_t *)(SX_CM_REGS_ADDR + addr);
6970

71+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
72+
printk("sx_wrreg_addr(addr=0x%x, d=%p, p=%p)\r\n", addr, d, p);
73+
#endif
7074
wmb(); /* comment for compliance */
7175
*d = (size_t)p;
7276
rmb(); /* comment for compliance */
@@ -78,13 +82,15 @@ static inline uint32_t sx_rdreg(uint32_t addr)
7882
volatile uint32_t *p = (uint32_t *)(SX_CM_REGS_ADDR + addr);
7983
uint32_t v;
8084

85+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
86+
printk("sx_rdreg(addr=0x%x, p=%p)\r\n", addr, p);
87+
#endif
8188
wmb(); /* comment for compliance */
8289
v = *p;
8390
rmb(); /* comment for compliance */
8491

85-
#ifdef INSTRUMENT_MMIO_WITH_PRINTFS
86-
printk("sx_rdregx(addr=0x%x, sum=0x%x);\n", addr, p);
87-
printk("result = 0x%x\n", v);
92+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
93+
printk("result = 0x%x\r\n", v);
8894
#endif
8995

9096
return v;
@@ -96,15 +102,16 @@ static inline uint32_t sx_rd_trng(uint32_t addr)
96102
volatile uint32_t *p = (uint32_t *)(SX_TRNG_REGS_ADDR + addr);
97103
uint32_t v;
98104

105+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
106+
printk("sx_rd_trng(addr=0x%x, p=%p)\r\n", addr, p);
107+
#endif
99108
wmb(); /* comment for compliance */
100109
v = *p;
101110
rmb(); /* comment for compliance */
102111

103-
#ifdef INSTRUMENT_MMIO_WITH_PRINTFS
104-
printk("sx_rdregx(addr=0x%x, sum=0x%x);\n", addr, p);
105-
printk("result = 0x%x\n", v);
112+
#ifdef SX_INSTRUMENT_MMIO_WITH_PRINTFS
113+
printk("result = 0x%x\r\n", v);
106114
#endif
107-
108115
return v;
109116
}
110117

0 commit comments

Comments
 (0)