-
Notifications
You must be signed in to change notification settings - Fork 347
target/riscv: add is_virtual parameter to memory access method #1241
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
base: riscv
Are you sure you want to change the base?
Conversation
@JanMatCodasip, @MarekVCodasip could you please take a look? |
In this comment, @JanMatCodasip suggested moving the |
I do not feel strongly about this one. Please feel free to use and submit whatever variant in your opinion leads to cleaner, more understandable code. My concern was that |
@JanMatCodasip, I’ve decided to keep |
@@ -3425,7 +3425,7 @@ static int riscv_rw_memory(struct target *target, const riscv_mem_access_args_t | |||
|
|||
RISCV_INFO(r); | |||
if (!mmu_enabled) | |||
return r->access_memory(target, args); | |||
return r->access_memory(target, args, /* is_virtual */ true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please double-check this line.
If mmu_enabled
is false, shouldn't is_virtual
be false as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fk-sc can we discuss this design once again?
-
I don't like the suggested approach because riscv_rw_memory should always operate on virtual addresses by design. The decision on how the actual address translation is performed should be decided by lower level functions - that is I would expect for
r->access_memory()
to be called withis_virutual = true
. The fact that in some execution context virtual address is equal to physical is irrelevant at this level of abstraction. -
if there is a necessity to provide additional layer to simplify page-crossing translations - we can do it here and establish a contract that
r->access_memory
should access non-page crossing memory regions. -
please rename
mmu_enabled
tosatp_translation_required
.mmu_enabled
is too broad term that can confuse the reader (it definitely confuses me)
@JanMatCodasip sorry for the mess, most likely we @fk-sc , @en-sc and me should have yet another round of internal discussion related to the above bulllets. Please consider this MR as a draft for now. You inputs are as always are very welcome, so please do share concerns/questions/suggestions regarding the matter (if you have any)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem at all. Thank you for letting me know.
aap-sc: [...] riscv_rw_memory should always operate on virtual addresses by design.
Sounds good to me.
In that case, if you like, you can also make the code more clear by doing this:
- rename
riscv_rw_memory()
toriscv_rw_virt_memory()
- create
riscv_rw_phys_memory()
(a thin wrapper overr->access_memory(args, /* is_virtual = */ false)
)
aap-sc: if there is a necessity to provide additional layer to simplify page-crossing translations - we can do it here and establish a contract that r->access_memory should access non-page crossing memory regions.
- The algorithm for breaking the memory access into the page-sized chunks, which is already in riscv_rw_memory(), looks all right to me. Or do you see any gap or need for change there, which I might have missed?
- Do I understand correctly that the only case when we need to manually break the memory transfer to page-sized pieces is when
virt2phys_mode
is set toSW
?
aap-sc: please rename mmu_enabled to satp_translation_required. mmu_enabled is too broad term that can confuse the reader
I agree that mmu_enabled
is not a clear name. It could also be called manual_satp_translation_needed
. The word "manual" is IMO important here as it means that OpenOCD must do the translation work (as opposed to the hardware).
Furthermore, I am concerned about the riscv_mmu()
itself. If virt2phys
mode is set to HW
, then riscv_mmu()
returns False, which looks incorrect. As a result:
- The
riscv_virt2phys()
function (and the TCL commandvirt2phys
) will return 1:1 mapping instead of correctly translated addresses. - The
target_alloc_working_area_try()
will allocate the work area in the physical address range (-work-area-phys
) instead of virtual (-work-area-virt
).
Should the initial check in riscv_mmu() be fixed this way?
if (riscv_virt2phys_mode_is_off(target))
return ERROR_OK;
Added is_virtual parameter to memory access method. This change is required to support hw translation appropriately. Updated repeat_read documentation according to new behaviour Change-Id: I6970b4dd9d57ff5c032a6c435358003e9a66d21c Signed-off-by: Farid Khaydari <[email protected]>
Added is_virtual parameter to memory access method. This change is required to support hw translation appropriately.
Updated repeat_read documentation according to new behaviour. It is provide physical access now