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

update to track the latest coreuser spec changes #614

Merged
merged 4 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions loader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ pub enum IniType {
pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) -> ! {
#[cfg(all(feature = "cramium-soc", not(feature = "verilator-only")))]
let perclk_freq = crate::platform::early_init(); // sets up PLLs so we're not running at 16MHz...
// need to make this "official" for NTO, the feature flag combo below works around some simulation config
// conflicts.
#[cfg(all(feature = "verilator-only", not(feature = "cramium-mpw")))]
platform::coreuser_config();

#[cfg(not(all(feature = "cramium-soc", not(feature = "verilator-only"))))]
let perclk_freq = 0;

Expand Down
32 changes: 32 additions & 0 deletions loader/src/platform/cramium/cramium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1975,3 +1975,35 @@ pub unsafe fn init_clock_asic_c(freq_hz: u32, duty_sram: u32) -> u32 {

100_000_000 // bodge for now
}

#[cfg(all(feature = "verilator-only", not(feature = "cramium-mpw")))]
pub fn coreuser_config() {
// configure coruser signals. Specific to NTO.
use utra::coreuser::*;
crate::println!("coreuser setup...");
let mut coreuser = CSR::new(utra::coreuser::HW_COREUSER_BASE as *mut u32);
// set to 0 so we can safely mask it later on
coreuser.wo(USERVALUE, 0);
coreuser.rmwf(utra::coreuser::USERVALUE_DEFAULT, 3);
let trusted_asids = [(1, 0), (2, 0), (3, 1), (4, 2), (1, 0), (1, 0), (1, 0), (1, 0)];
let asid_fields = [
(utra::coreuser::MAP_LO_LUT0, utra::coreuser::USERVALUE_USER0),
(utra::coreuser::MAP_LO_LUT1, utra::coreuser::USERVALUE_USER1),
(utra::coreuser::MAP_LO_LUT2, utra::coreuser::USERVALUE_USER2),
(utra::coreuser::MAP_LO_LUT3, utra::coreuser::USERVALUE_USER3),
(utra::coreuser::MAP_HI_LUT4, utra::coreuser::USERVALUE_USER4),
(utra::coreuser::MAP_HI_LUT5, utra::coreuser::USERVALUE_USER5),
(utra::coreuser::MAP_HI_LUT6, utra::coreuser::USERVALUE_USER6),
(utra::coreuser::MAP_HI_LUT7, utra::coreuser::USERVALUE_USER7),
];
for (&(asid, value), (map_field, uservalue_field)) in trusted_asids.iter().zip(asid_fields) {
coreuser.rmwf(map_field, asid);
coreuser.rmwf(uservalue_field, value);
}
coreuser.rmwf(CONTROL_INVERT_PRIV, 1);
coreuser.rmwf(CONTROL_ENABLE, 1);

// turn off updates
coreuser.wo(utra::coreuser::PROTECT, 1);
crate::println!("coreuser locked!");
}
4 changes: 2 additions & 2 deletions loader/src/platform/cramium/link-soc.x
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ SECTIONS
. = ALIGN(4);
_edata = .;
} > REGION_DATA AT > REGION_RODATA

/*
.fonts : ALIGN(65536)
{
KEEP(*(.fontdata));
} > FONTS

*/
.bss (NOLOAD) :
{
_sbss = .;
Expand Down
73 changes: 36 additions & 37 deletions utralib/cramium/core.svd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor>
<name>SOC</name>
<description><![CDATA[Litex SoC 2025-01-01 15:33:54]]></description>
<description><![CDATA[Litex SoC 2025-01-11 17:47:31]]></description>

<addressUnitBits>8</addressUnitBits>
<width>32</width>
Expand Down Expand Up @@ -282,38 +282,14 @@ register to disable individual events.]]></description>
<bitRange>[0:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[When set to `1`, mappings are enabled. When `0`, the `CoreUser` value is fixed
to an 8-bit `1` value]]></description>
to 0b0001_0000, and the `vex_mm` bit is set to '`1`.]]></description>
</field>
<field>
<name>use8bit</name>
<name>invert_priv</name>
<msb>1</msb>
<bitRange>[1:1]</bitRange>
<lsb>1</lsb>
<description><![CDATA[When set to `1`, use the 8-bit version of ASID for `CoreUser`. When `0`, map
`CoreUser value to 1 bit]]></description>
</field>
<field>
<name>shift</name>
<msb>4</msb>
<bitRange>[4:2]</bitRange>
<lsb>2</lsb>
<description><![CDATA[Sets the bit-shift for the 1-bit mapping of `CoreUser`. This field refers
directly to the bit position, and defaults to bit `0`]]></description>
</field>
<field>
<name>privilege</name>
<msb>5</msb>
<bitRange>[5:5]</bitRange>
<lsb>5</lsb>
<description><![CDATA[When set to `1`, requires the current privilege state to match that specified in
`set_privilege.mpp`]]></description>
</field>
<field>
<name>mpp</name>
<msb>7</msb>
<bitRange>[7:6]</bitRange>
<lsb>6</lsb>
<description><![CDATA[Value of `mpp` bit from `mstatus` that must match for code to be trusted]]></description>
<description><![CDATA[When set to `1` inverts the sense of the privilege bit]]></description>
</field>
</fields>
</register>
Expand All @@ -330,6 +306,13 @@ directly to the bit position, and defaults to bit `0`]]></description>
<lsb>0</lsb>
<description><![CDATA[Computed value of the `CoreUser` signal as passed on to the SoC. For debugging.]]></description>
</field>
<field>
<name>mm</name>
<msb>8</msb>
<bitRange>[8:8]</bitRange>
<lsb>8</lsb>
<description><![CDATA[Computed value of the `mm` signal passed on to the SoC.]]></description>
</field>
</fields>
</register>
<register>
Expand All @@ -343,28 +326,28 @@ directly to the bit position, and defaults to bit `0`]]></description>
<msb>7</msb>
<bitRange>[7:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[Value of `CoreUser` ASID bit 0]]></description>
<description><![CDATA[Mapping of `CoreUser` ASID to coreuser dense conding bit 0]]></description>
</field>
<field>
<name>lut1</name>
<msb>15</msb>
<bitRange>[15:8]</bitRange>
<lsb>8</lsb>
<description><![CDATA[Value of `CoreUser` ASID bit 0]]></description>
<description><![CDATA[Mapping of `CoreUser` ASID to coreuser dense conding bit 0]]></description>
</field>
<field>
<name>lut2</name>
<msb>23</msb>
<bitRange>[23:16]</bitRange>
<lsb>16</lsb>
<description><![CDATA[Value of `CoreUser` ASID bit 0]]></description>
<description><![CDATA[Mapping of `CoreUser` ASID to coreuser dense conding bit 0]]></description>
</field>
<field>
<name>lut3</name>
<msb>31</msb>
<bitRange>[31:24]</bitRange>
<lsb>24</lsb>
<description><![CDATA[Value of `CoreUser` ASID bit 0]]></description>
<description><![CDATA[Mapping of `CoreUser` ASID to coreuser dense conding bit 0]]></description>
</field>
</fields>
</register>
Expand All @@ -379,28 +362,28 @@ directly to the bit position, and defaults to bit `0`]]></description>
<msb>7</msb>
<bitRange>[7:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[Value of `CoreUser` ASID bit 0]]></description>
<description><![CDATA[Mapping of `CoreUser` ASID to coreuser dense coding bit 1]]></description>
</field>
<field>
<name>lut5</name>
<msb>15</msb>
<bitRange>[15:8]</bitRange>
<lsb>8</lsb>
<description><![CDATA[Value of `CoreUser` ASID bit 0]]></description>
<description><![CDATA[Mapping of `CoreUser` ASID to coreuser dense coding bit 1]]></description>
</field>
<field>
<name>lut6</name>
<msb>23</msb>
<bitRange>[23:16]</bitRange>
<lsb>16</lsb>
<description><![CDATA[Value of `CoreUser` ASID bit 0]]></description>
<description><![CDATA[Mapping of `CoreUser` ASID to coreuser dense coding bit 1]]></description>
</field>
<field>
<name>lut7</name>
<msb>31</msb>
<bitRange>[31:24]</bitRange>
<lsb>24</lsb>
<description><![CDATA[Value of `CoreUser` ASID bit 0]]></description>
<description><![CDATA[Mapping of `CoreUser` ASID to coreuser dense coding bit 1]]></description>
</field>
</fields>
</register>
Expand Down Expand Up @@ -475,10 +458,26 @@ directly to the bit position, and defaults to bit `0`]]></description>
</field>
</fields>
</register>
<register>
<name>PROTECT</name>
<description><![CDATA[Writing `1` to this bit prevents any further updates to CoreUser configuration
status. Can only be reversed with a system reset.]]></description>
<addressOffset>0x0014</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>protect</name>
<msb>0</msb>
<bitRange>[0:0]</bitRange>
<lsb>0</lsb>
</field>
</fields>
</register>
</registers>
<addressBlock>
<offset>0</offset>
<size>0x14</size>
<size>0x18</size>
<usage>registers</usage>
</addressBlock>
</peripheral>
Expand Down
15 changes: 11 additions & 4 deletions utralib/cramium/daric.svd
Original file line number Diff line number Diff line change
Expand Up @@ -10653,11 +10653,18 @@ position to clear the flag]]></description>
<size>32</size>
<fields>
<field>
<name>cr_wkupmask</name>
<msb>9</msb>
<bitRange>[9:0]</bitRange>
<name>inten</name>
<msb>7</msb>
<bitRange>[7:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[cr_wkupmask read/write control register]]></description>
<description><![CDATA[inten read/write control register]]></description>
</field>
<field>
<name>wkupmask</name>
<msb>17</msb>
<bitRange>[17:8]</bitRange>
<lsb>8</lsb>
<description><![CDATA[wkupmask read/write control register]]></description>
</field>
</fields>
</register>
Expand Down
Loading
Loading