|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
SRAM (with ECC) control / status / security register layout. More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | r_sram_regs_t |
| Memory layout of the SRAM control window. More... | |
| struct | r_sram_cpscu_regs_t |
| Memory layout of the CPSCU SRAM security window. More... | |
Functions | |
| static volatile r_sram_regs_t * | ra8_sram_regs (void) |
| Get pointer to the (Secure) SRAM control register block. | |
| static volatile r_sram_cpscu_regs_t * | ra8_sram_cpscu_regs (void) |
| Get pointer to the (Secure) CPSCU SRAM security register block. | |
| static volatile uint8_t * | ra8_sram_cr_ptr (volatile r_sram_regs_t *regs, uint8_t bank) |
| Indexed write helper: SRAMCRn slot. | |
| static volatile uint8_t * | ra8_sram_eccrgn_ptr (volatile r_sram_regs_t *regs, uint8_t bank) |
| Indexed write helper: SRAMECCRGNn slot. | |
| static volatile uint64_t * | ra8_sram_bank_data_ptr (uint8_t bank) |
| Per-bank data window helper: pointer to the start of the data alias. | |
| static uint32_t | ra8_sram_bank_size_bytes (uint8_t bank) |
| Per-bank data-region size in bytes. | |
| static uint32_t | ra8_sram_bank_ecc_size_bytes (uint8_t bank) |
| Per-bank ECC syndrome region size in bytes. | |
SRAM (with ECC) control / status / security register layout.
The RA8D2 has a 2 MB on-chip SRAM split into four banks (SRAM0..SRAM3, see HUM Ch 58.1 Table 58.1, p 3527) with optional SEC-DED ECC (64-bit data + 8-bit syndrome).
Three register windows are involved:
| Window | Base (Secure) | Base (Non-Secure) | Notes |
|---|---|---|---|
| CPSCU SRAM | 0x4000_8000 | 0x5000_8000 | Security attribution. |
| SRAM ctl | 0x4000_2000 | 0x5000_2000 | PRCR / WTSC / CRn / EAR. |
| SRAM data | 0x2200_0000 | 0x3200_0000 | The actual SRAM banks. |
The CPSCU window models SRAMSABARn, SRAMSAR and SRAMESAR. The SRAM control window models SRAMPRCR_S/NS, SRAMWTSC, SRAMCRn, SRAMECCRGNn, SRAMESR, SRAMESCLR and SRAMEARnm.
Per HUM Ch 58.2 (p 3527-3537) the control window layout is:
| Offset | Name | Width | Purpose |
|---|---|---|---|
| 0x00 | SRAMPRCR_S | 16 | Secure write-protect (key 0xA5). |
| 0x04 | SRAMPRCR_NS | 16 | Non-secure write-protect. |
| 0x08 | SRAMWTSC | 8 | Wait-state enable. |
| 0x10 | SRAMCR0 | 8 | SRAM0 ECC mode + OAD + E1STSEN. |
| 0x14 | SRAMCR1 | 8 | SRAM1 ECC mode + ... |
| 0x18 | SRAMCR2 | 8 | SRAM2 ECC mode + ... |
| 0x1C | SRAMCR3 | 8 | SRAM3 ECC mode + ... |
| 0x30 | SRAMECCRGN0 | 8 | SRAM0 ECC region size. |
| 0x34 | SRAMECCRGN1 | 8 | SRAM1 ECC region size. |
| 0x38 | SRAMECCRGN2 | 8 | SRAM2 ECC region size. |
| 0x3C | SRAMECCRGN3 | 8 | SRAM3 ECC region size. |
| 0x40 | SRAMESR | 16 | ECC error status (1bit/2bit). |
| 0x48 | SRAMESCLR | 16 | ECC error status clear. |
| 0x50+ | SRAMEAR[n][m] | 32 | ECC error address. |
Per HUM Ch 58.2.1..58.2.3 (p 3527-3530) the CPSCU window layout is:
| Offset | Name | Width | Purpose |
|---|---|---|---|
| 0x010 | SRAMSAR | 32 | Per-bank register security. |
| 0x400 | SRAMSABAR0 | 32 | SRAM0 Secure/NS boundary. |
| 0x404 | SRAMSABAR1 | 32 | SRAM1 Secure/NS boundary. |
| 0x408 | SRAMSABAR2 | 32 | SRAM2 Secure/NS boundary. |
| 0x40C | SRAMSABAR3 | 32 | SRAM3 Secure/NS boundary. |
| 0x510 | SRAMESAR | 32 | ECC region security attribute. |
Per CLAUDE.md the driver never writes these registers via macros – use the ra8_sram_regs() and ra8_sram_cpscu_regs() accessors so the host-side fake can intercept the writes.
Definition in file ra8_sram_regs.h.
| enum ra8_sram_addr_t : uintptr_t |
Memory-mapped base addresses for the SRAM windows.
Per HUM Ch 58.2.4 "SRAMPRCR_S", p 3530 the Secure SRAM-control base is 0x4000_2000 and the Non-Secure alias is 0x5000_2000.
Per HUM Ch 58.2.1 "SRAMSABARn", p 3527 the Secure CPSCU base is 0x4000_8000 and the Non-Secure alias is 0x5000_8000.
Per HUM Ch 58.1 Table 58.1, p 3527 the Secure data base for SRAM0 is 0x2200_0000 and the Non-Secure data alias is 0x3200_0000. The driver targets the Secure aliases on the bare-metal v0.x build (TrustZone partitioning happens later).
Definition at line 94 of file ra8_sram_regs.h.
| enum ra8_sram_bank_count_t : uint8_t |
Number of SRAM banks (SRAM0..SRAM3).
Per HUM Ch 58.1 Table 58.1, p 3527: SRAM0/1/2 are 512 KB each and SRAM3 is 128 KB.
| Enumerator | |
|---|---|
| k_ra8_sram_bank_count | SRAM0, SRAM1, SRAM2, SRAM3. |
Definition at line 153 of file ra8_sram_regs.h.
| enum ra8_sram_bank_offset_t : uint32_t |
Per-bank offsets into the SRAM data alias.
Per HUM Ch 58.1 Table 58.1, p 3527: SRAM0 lives at offset 0, SRAM1 at offset 0x80000, SRAM2 at offset 0x100000, SRAM3 at offset 0x180000. Sizes follow the table column.
Definition at line 112 of file ra8_sram_regs.h.
| enum ra8_sram_cr_bit_t : uint8_t |
SRAMCRn bit positions.
Per HUM Ch 58.2.7 "SRAMCRn", p 3532. Layout:
Definition at line 283 of file ra8_sram_regs.h.
| enum ra8_sram_cr_eccmod_t : uint8_t |
Encoded SRAMCRn.ECCMOD field values (already shifted to [3:2]).
Per HUM Ch 58.2.7, p 3532. 01b is reserved and never written.
| Enumerator | |
|---|---|
| k_ra8_sram_eccmod_disabled | 00b<<2 = 0x00 (ECC off). |
| k_ra8_sram_eccmod_no_check | 10b<<2 = 0x08 (ECC, no check). |
| k_ra8_sram_eccmod_with_chk | 11b<<2 = 0x0C (ECC + checking). |
Definition at line 310 of file ra8_sram_regs.h.
| enum ra8_sram_cr_mask_t : uint8_t |
SRAMCRn bit masks (HUM Ch 58.2.7, p 3532).
Definition at line 295 of file ra8_sram_regs.h.
| enum ra8_sram_cr_self_test_t : uint8_t |
SRAMCRn values used by the ECC decoder self-test sequence.
Per HUM Ch 58.3.4 "ECC Decoder Testing", p 3539, the test flowchart writes three specific bytes to SRAMCRn:
| Enumerator | |
|---|---|
| k_ra8_sram_cr_self_test_phase_write | ECCMOD=10, all others 0. |
| k_ra8_sram_cr_self_test_phase_bypass | TSTBYP=1, ECCMOD=00. |
| k_ra8_sram_cr_self_test_phase_verify | ECCMOD=11, E1STSEN=1. |
Definition at line 332 of file ra8_sram_regs.h.
| enum ra8_sram_ear_pair_t : uint8_t |
Number of error-address registers per bank (1-bit + 2-bit).
Per HUM Ch 58.2.14 "SRAMEARnm", p 3537: m=0 captures the offset of the first 1-bit ECC error in bank n; m=1 captures the first 2-bit error. The pair count is therefore 2.
| Enumerator | |
|---|---|
| k_ra8_sram_ear_pair_count | [bank][1-bit, 2-bit]. |
| k_ra8_sram_ear_slot_1bit | SRAMEARn0 – first 1-bit error. |
| k_ra8_sram_ear_slot_2bit | SRAMEARn1 – first 2-bit error. |
Definition at line 166 of file ra8_sram_regs.h.
| enum ra8_sram_ecc_region_off_t : uint32_t |
Per-bank offsets into the SRAM ECC syndrome alias.
Per HUM Ch 58.1 Table 58.1, p 3527: each bank's ECC syndrome bytes live at the bank-specific window listed below. Direct access is only meaningful when SRAMCRn.TSTBYP=1; otherwise the ECC engine intercepts the access and the read/write is invalid.
Definition at line 131 of file ra8_sram_regs.h.
| enum ra8_sram_ecc_word_t : uint8_t |
Granularity of ECC-protected SRAM accesses.
Per HUM Ch 58.3.2 "Correction of ECC Errors", p 3538: ECC syndrome is computed per 64-bit word. Initial-fill writes must be 8-byte aligned and 64 bits wide so the syndrome lines up correctly. Per HUM Ch 58.4.2 "Notes on Using Error Checking of SRAM", p 3541: the SRAM is read in 8-byte units, so the safe zero-init stride is 8.
| Enumerator | |
|---|---|
| k_ra8_sram_ecc_word_bytes | 64-bit ECC word width (bytes). |
| k_ra8_sram_ecc_word_shift | log2(word bytes), for size>>shift loops. |
Definition at line 183 of file ra8_sram_regs.h.
| enum ra8_sram_eccrgn_value_t : uint8_t |
SRAMECCRGNn.ECCRGN field encodings.
Per HUM Ch 58.2.8..58.2.11, p 3533-3535. For SRAM0..SRAM2 the granularity is 128 KB (1=128, 2=256, 3=384, 4=512). SRAM3 is the 128 KB bank so only 0 and 1 are legal there.
Definition at line 352 of file ra8_sram_regs.h.
| enum ra8_sram_esar_bit_t : uint32_t |
SRAMESAR bit positions.
Per HUM Ch 58.2.3 "SRAMESAR : SRAM ECC region Security Attribute Register", p 3529. Only bit 0 (SRAMESA) is defined.
| Enumerator | |
|---|---|
| k_ra8_sram_esar_bit_esa | SRAMESA – ECC region Non-Secure. |
| k_ra8_sram_esar_writable | Union of defined bits. |
Definition at line 424 of file ra8_sram_regs.h.
| enum ra8_sram_esr_bit_t : uint16_t |
SRAMESR / SRAMESCLR bit positions for each bank.
Per HUM Ch 58.2.12 "SRAMESR : SRAM Error Status Register", p 3535 and HUM Ch 58.2.13 "SRAMESCLR", p 3536. Pattern is ERR{n}{0|1} / CLR{n}{0|1} where 0=1-bit and 1=2-bit.
The SRAMESCLR layout is bit-for-bit identical so the same shifts are reused for both registers.
Definition at line 378 of file ra8_sram_regs.h.
| enum ra8_sram_fill_pattern_t : uint64_t |
Fill word for the deterministic zero-init pass.
Per HUM Ch 58.3.2, p 3538: any 64-bit pattern produces a valid syndrome when written under ECC-no-check. Zero is chosen because it matches the post-reset state of every bank's user-visible store and is the cheapest immediate to encode.
| Enumerator | |
|---|---|
| k_ra8_sram_zero_init_word | Default fill pattern. |
Definition at line 198 of file ra8_sram_regs.h.
| enum ra8_sram_iclk_threshold_t : uint32_t |
ICLK frequency thresholds where SRAMWTSC.WTEN must flip to 1.
Per HUM Ch 58.3.7 "Wait State", p 3540:
The driver multiplies the configured maximum by 2 to get the threshold; these values are kept here for documentation and unit tests that exercise the auto-wait helper.
Definition at line 259 of file ra8_sram_regs.h.
| enum ra8_sram_indexed_t : uint8_t |
Stride / base offsets for sparse SRAMCR / SRAMECCRGN slots.
| Enumerator | |
|---|---|
| k_ra8_sram_cr_base_off | SRAMCR0 byte offset. |
| k_ra8_sram_eccrgn_base_off | SRAMECCRGN0 byte offset. |
| k_ra8_sram_sparse_stride | Stride between sparse slots. |
Definition at line 474 of file ra8_sram_regs.h.
| enum ra8_sram_pad_t : uint16_t |
Reserved-byte gap sizes used inside the SRAM control register block and CPSCU window.
Names every padding gap so the struct definitions do not depend on raw integer literals. Cross-checked against HUM Ch 58.2.
Definition at line 462 of file ra8_sram_regs.h.
| enum ra8_sram_prcr_key_t : uint16_t |
SRAMPRCR_S/NS half-word values for unlock / lock.
Per HUM Ch 58.2.4 "SRAMPRCR_S : SRAM Protection Control Register for Secure", p 3530, the upper 8 bits KW[7:0] must be 0xA5 for the PR write-enable bit to take effect. 0xA501 enables subsequent writes to SRAMWTSC / SRAMCRn / SRAMECCRGNn; 0xA500 locks them again.
Definition at line 218 of file ra8_sram_regs.h.
| enum ra8_sram_sabar_limit_t : uint32_t |
Boundary-address limits per bank for SRAMSABARn.
Per HUM Ch 58.2.1 "SRAMSABARn", p 3527-3528. Each value is the absolute Secure offset where the bank ends – writing a boundary larger than this saturates the whole bank to "Secure". The b12..b0 bits of the boundary must be zero (4 KB granularity).
Definition at line 439 of file ra8_sram_regs.h.
| enum ra8_sram_sar_bit_t : uint32_t |
SRAMSAR bit positions.
Per HUM Ch 58.2.2 "SRAMSAR : SRAM Security Attribution Register", p 3528. Bits 0..3 cover SRAM0..SRAM3 register security; bit 8 covers SRAMWTSC security.
Definition at line 406 of file ra8_sram_regs.h.
| enum ra8_sram_wtsc_mask_t : uint8_t |
SRAMWTSC bit masks.
Per HUM Ch 58.2.6 "SRAMWTSC : SRAM Wait State Control Register", p 3531. WTEN=1 inserts one wait state into SRAM read access cycles and is required when ICLK > half the maximum frequency.
| Enumerator | |
|---|---|
| k_ra8_sram_wtsc_wten | Insert one wait state on SRAM access. |
| k_ra8_sram_wtsc_msk | All R/W bits in SRAMWTSC. |
Definition at line 239 of file ra8_sram_regs.h.
|
inlinestatic |
Per-bank data window helper: pointer to the start of the data alias.
| [in] | bank | Bank index 0..3 (caller must validate). |
Per HUM Ch 58.1 Table 58.1, p 3527. SRAM0 starts at the data base, subsequent banks step in 0x80000-byte increments (SRAM3 reuses the same step but only owns the first 0x20000 bytes of its slot).
Definition at line 629 of file ra8_sram_regs.h.
References k_ra8_sram_bank012_size, and k_ra8_sram_data_base_addr.
Referenced by internal_zero_fill_bank(), and ra8_sram_self_test().
|
inlinestatic |
Per-bank ECC syndrome region size in bytes.
| [in] | bank | Bank index 0..3. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 669 of file ra8_sram_regs.h.
References k_ra8_sram_ecc_bank012_sz, and k_ra8_sram_ecc_bank3_sz.
Referenced by ra8_sram_get_bank_info().
|
inlinestatic |
Per-bank data-region size in bytes.
| [in] | bank | Bank index 0..3. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 649 of file ra8_sram_regs.h.
References k_ra8_sram_bank012_size, and k_ra8_sram_bank3_size.
Referenced by internal_zero_fill_bank(), ra8_sram_get_bank_info(), and ra8_sram_self_test().
|
inlinestatic |
Get pointer to the (Secure) CPSCU SRAM security register block.
The CPSCU window is shared with other modules (SRAM is one of several security-attribution clients). This accessor only exposes the SRAM-related slice; do not dereference it for non-SRAM registers.
Definition at line 581 of file ra8_sram_regs.h.
References k_ra8_sram_cpscu_base_addr.
Referenced by internal_apply_security(), ra8_sram_set_boundary(), ra8_sram_set_ecc_security(), and ra8_sram_set_security().
|
inlinestatic |
Indexed write helper: SRAMCRn slot.
| [in] | regs | Result of ra8_sram_regs(). |
| [in] | bank | Bank index 0..3 (caller must validate). |
The HUM lays out SRAMCR0..3 with a 4-byte stride, so the SRAMCR member of r_sram_regs_t cannot be a packed uint8_t[4]. This helper hides the cast and stride math.
Definition at line 597 of file ra8_sram_regs.h.
References k_ra8_sram_cr_base_off, and k_ra8_sram_sparse_stride.
Referenced by internal_write_cr_locked().
|
inlinestatic |
Indexed write helper: SRAMECCRGNn slot.
| [in] | regs | Result of ra8_sram_regs(). |
| [in] | bank | Bank index 0..3 (caller must validate). |
Definition at line 611 of file ra8_sram_regs.h.
References k_ra8_sram_eccrgn_base_off, and k_ra8_sram_sparse_stride.
Referenced by internal_write_eccrgn_locked().
|
inlinestatic |
Get pointer to the (Secure) SRAM control register block.
On the bare-metal target this is real MMIO. Under RA8_OFF_TARGET the same address is backed by host RAM via tests/mocks/src/ra8_fake_mmap.c, so the same accessor works on host tests without a separate mock header.
Definition at line 566 of file ra8_sram_regs.h.
References k_ra8_sram_base_addr.
Referenced by internal_write_cr_locked(), internal_write_eccrgn_locked(), internal_write_wtsc_locked(), ra8_sram_clear_address(), ra8_sram_clear_status(), ra8_sram_get_status(), ra8_sram_init(), and ra8_sram_self_test().