target/riscv: add is_virtual parameter to memory access method#1241
target/riscv: add is_virtual parameter to memory access method#1241fkhaidari wants to merge 2 commits intoriscv-collab:riscvfrom
Conversation
|
@JanMatCodasip, @MarekVCodasip could you please take a look? |
|
In this comment, @JanMatCodasip suggested moving the |
9c2d73a to
bebc6e7
Compare
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 |
bebc6e7 to
83af966
Compare
| 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.
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.
@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_memoryshould access non-page crossing memory regions. -
please rename
mmu_enabledtosatp_translation_required.mmu_enabledis 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.
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_modeis 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;83af966 to
427026a
Compare
425b06d to
b71fd53
Compare
|
@JanMatCodasip, @aap-sc, @en-sc, I've revised the implementation of this PR. At first we need to merge #1256 (this commit fixes riscv_mmu). This PR includes mentioned one. Changes in updated version of PR:
|
Fixed riscv_mmu behaviour: buggy check was removed. As a result virt2phys command behaviour was fixed: now it returns translated address even while virt2phys_mode is off. Change-Id: Ie2e6d1057024ab794038d5ed3662ef49a4d71e70 Signed-off-by: Farid Khaydari <f.khaydari@syntacore.com>
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 <f.khaydari@syntacore.com>
b71fd53 to
b078514
Compare
|
@fk-sc If you don't mind, I will get back to this review at a later point - after we finish the discussion under #1256. |
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