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

[membkdr] Provide a tile adapter to access internal rows #26006

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Razer6
Copy link
Member

@Razer6 Razer6 commented Jan 24, 2025

This PR adds a custom row adapter that is being used by the memory backdoor util to access and manipulate rows of data. Integrators might are using SRAM primitives with a different internal organization than Width x Depth. They can provide a custom row adapter to the memory backdoor utility to for the needs of their memory prims.

@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch 15 times, most recently from 61b80e2 to f22c654 Compare January 28, 2025 11:37
@Razer6 Razer6 requested a review from rswarbrick January 28, 2025 11:38
@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch 5 times, most recently from 2f22457 to 4c7e9aa Compare January 28, 2025 13:19
@Razer6 Razer6 requested a review from vogelpi January 28, 2025 13:36
@Razer6 Razer6 marked this pull request as ready for review January 28, 2025 13:36
@Razer6 Razer6 requested a review from a team as a code owner January 28, 2025 13:36
@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch 2 times, most recently from d071b91 to 408d8dc Compare January 28, 2025 15:14
hw/dv/sv/mem_bkdr_util/mem_bkdr_util.sv Outdated Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util.sv Outdated Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util.sv Outdated Show resolved Hide resolved
hw/ip/otbn/dv/uvm/env/otbn_env_pkg.sv Outdated Show resolved Hide resolved
hw/ip/otbn/dv/uvm/tb.sv Outdated Show resolved Hide resolved
hw/ip/rom_ctrl/dv/tb.sv Outdated Show resolved Hide resolved
@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch 2 times, most recently from 036b6a6 to 6f4b47a Compare January 28, 2025 18:05
@Razer6 Razer6 requested a review from alees24 January 28, 2025 18:59
@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch 3 times, most recently from cbafd0f to 58a72db Compare January 29, 2025 15:34
@Razer6
Copy link
Member Author

Razer6 commented Jan 29, 2025

At the moment I am not sure why I get a Null error here

@Razer6
Copy link
Member Author

Razer6 commented Jan 29, 2025

@rswarbrick I am not sure how to fix that. Can you help me on that?
The constructor has the following statement:

   if (row_adapter != null) begin
      this.row_adapter = row_adapter;
    end else begin
      this.row_adapter = new();
    end

And later on, the row adapter is used like:

this.width                  = (n_bits / depth) - this.row_adapter.get_num_extra_bits();

However, this causes the following error (line 132 is the line from above when calling get_num_extra_bits()) :

Error-[NOA] Null object access
                ../src/lowrisc_dv_mem_bkdr_util_0/mem_bkdr_util.sv, 132
                  The object at dereference depth 1 is being used before it was
                  constructed/allocated.
                  Please make sure that the object is allocated before using it.

@rswarbrick
Copy link
Contributor

Hmm, that seems really odd to me: I'm not sure what's going on. Can I suggest debugging by adding some print statements inside the if/else block (possibly using %p to show the value of this.row_adapter at the end of it?

@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch 3 times, most recently from 5f63639 to b88d6b9 Compare January 30, 2025 22:04
@Razer6
Copy link
Member Author

Razer6 commented Jan 30, 2025

Hmm, that seems really odd to me: I'm not sure what's going on. Can I suggest debugging by adding some print statements inside the if/else block (possibly using %p to show the value of this.row_adapter at the end of it?

Stupid me! After the if/else, the default assignment from the parameter to the member variable was still there. This overwrote the previously allocated object with null again. @rswarbrick Fixed now, please take a look.

@rswarbrick
Copy link
Contributor

Ha! I didn't notice it either :-) I'll have a proper look now.

hw/dv/sv/mem_bkdr_util/mem_bkdr_util.sv Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util.sv Outdated Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util.sv Outdated Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util_row_adapter.sv Outdated Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util_row_adapter.sv Outdated Show resolved Hide resolved
@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch 2 times, most recently from 4708c15 to bc91835 Compare January 31, 2025 12:09
hw/dv/sv/mem_bkdr_util/mem_bkdr_util_row_adapter.sv Outdated Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util.sv Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util.sv Outdated Show resolved Hide resolved
if (!check_addr_valid(addr)) return 'x;
index = addr >> addr_lsb;
ram_tile = index / tile_depth;
res = uvm_hdl_read($sformatf("%0s[%0d]", get_full_path(ram_tile), index), data);
res = uvm_hdl_read($sformatf("%0s[%0d]", get_full_path(ram_tile), index), encoded_row);
data = row_adapter.decode_row(encoded_row);
Copy link
Contributor

Choose a reason for hiding this comment

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

Now I've understood a bit more, I'm not sure this is quite right. I think this is returning several words of data packed together? But the read function is supposed to return just one word, isn't it?

Don't we need to extract just one lane here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on how the functions and variables are currently named, I agree with @rswarbrick. This code seems to decode a row and assign that to data. @Razer6: Doesn't this function need to select a word from the decoded row based on addr?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the later function read8 (which calls read) needs a proper access function to select the right word?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. I think what confused me is the short description of this function ("Read the entire word at the given address."). I suggest we change word to memory row, because it may contain more than one word with parity bits, depending on the memory architecture. Does that make sense?

res = uvm_hdl_deposit($sformatf("%0s[%0d]", get_full_path(ram_tile), index), data);
index = addr >> addr_lsb;
ram_tile = index / tile_depth;
encoded_row = row_adapter.encode_row(data);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this has the same problem as the read function above. If we've got multiple words in the row, won't this need to do a read-modify-write?

hw/dv/sv/mem_bkdr_util/mem_bkdr_util_row_adapter.sv Outdated Show resolved Hide resolved
@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch 2 times, most recently from 9e4a0a6 to f5dc3a5 Compare February 3, 2025 09:25
hw/dv/sv/mem_bkdr_util/mem_bkdr_util_row_adapter.sv Outdated Show resolved Hide resolved
hw/dv/sv/mem_bkdr_util/mem_bkdr_util_row_adapter.sv Outdated Show resolved Hide resolved
if (!check_addr_valid(addr)) return 'x;
index = addr >> addr_lsb;
ram_tile = index / tile_depth;
res = uvm_hdl_read($sformatf("%0s[%0d]", get_full_path(ram_tile), index), data);
res = uvm_hdl_read($sformatf("%0s[%0d]", get_full_path(ram_tile), index), encoded_row);
data = row_adapter.decode_row(encoded_row);
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on how the functions and variables are currently named, I agree with @rswarbrick. This code seems to decode a row and assign that to data. @Razer6: Doesn't this function need to select a word from the decoded row based on addr?

@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch from f5dc3a5 to a5bdde7 Compare February 3, 2025 14:46
@Razer6 Razer6 force-pushed the bkdor-tile-adapter branch from a5bdde7 to ac2cc08 Compare February 3, 2025 15:14
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