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

CSR Improvements and Cleanup #339

Merged
merged 2 commits into from
Jan 13, 2020
Merged

CSR Improvements and Cleanup #339

merged 2 commits into from
Jan 13, 2020

Conversation

gsomlo
Copy link
Collaborator

@gsomlo gsomlo commented Jan 12, 2020

Reimplement CSR accessors to be flexible w.r.t. alignment (i.e., CPU word width) and csr_data_width.

Implement additional accessors (targeted mainly at CSRs with total width > 64 bits) which transfer
arrays of standard C uintX_t types (8, 16, 32, and 64 bit uints supported).

Use CSR array accessors to clean up sdram initialization (@enjoy-digital, please test write leveling,
and all the other stuff that's not available on nexys4ddr, trellis, or ecp5versa before pulling).

This replaces PR #324 (which also contains a patch to the bios main() function testing the correctness
of all new accessors). I didn't want the actual test patch to be applied, but did want it to remain available publicly, hence this new PR.

Copy link
Collaborator

@mithro mithro left a comment

Choose a reason for hiding this comment

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

Just a random thought. Could we add a "check CSRs access work" type function which checks the endian / width match the functions? Should just be checking the scratch register at

self._scratch = CSRStorage(32, reset=0x12345678, description="""
?

Copy link
Collaborator

@mithro mithro left a comment

Choose a reason for hiding this comment

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

I just got off a 12h flight so please ignore me if I'm not making sense...

* NOTE: The same optimization considerations apply here as with _csr_rd_buf()
* above.
*/
#define _csr_wr_buf(a, uintX_t, buf, cnt) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any reason this whole thing should be a macro? It looks like you just use sizeof(type uintX_t)?

I would expect that if this was an inline function then it would end up as the same ASM?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's also buf[i], which is of type uintX_t. I'd have to have some sort of switch statement and a bunch of casts to each actual width (X), and make buf a void *. I figured the loss of legibility wasn't worth it, but if there's a nice elegant way to still do an inline function instead of a macro that'd be awesome!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

... but at least I might be able to avoid passing uintX_t to the macro, and use sizeof(buf[0]) instead... I'll take another look after I get some sleep, and force-push a cleaned-up version if it still makes sense in the morning :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

force-pushed a simplified pair of macros, without the uintX_t parameter, which is implicit in the type of buf[0] (tested, and working same as before). I think we're stuck with the macros, since implementing the casts implied by the type of buf[0] manually would be much less readable, IMHO.

@gsomlo
Copy link
Collaborator Author

gsomlo commented Jan 12, 2020 via email

Implement CSR accessors for all standard integer types and
combinations of subregister alignments (32 or 64 bit) and
sizes (i.e., csr_data_width 8, 16, or 32).

Rename accessors to better reflect the size of the register
being accessed, and correspondingly update the generation
of "csr.h" in "export.py".

Additionally, provide read/write accessors that superimpose arrays
of standard unsigned C types over a CSR register (which may itself
be spread across multiple subregisters).

Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>
Revert to treating SDRAM_DFII_PIX_[RD|WR]DATA CSRs as arrays
of bytes, but use the new uintX_t array accessors for improved
legibility, and to avoid unnecessary byteswapping.

Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>
@enjoy-digital enjoy-digital merged commit f818755 into enjoy-digital:master Jan 13, 2020
@enjoy-digital
Copy link
Owner

@gsomlo: i've been able to test write leveling with it and don't see regression, so i'm merging. Thanks again.

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.

4 participants