riscv-non-isa / riscv-iommu

RISC-V IOMMU Specification
https://jira.riscv.org/browse/RVG-55
Creative Commons Attribution 4.0 International
72 stars 14 forks source link

Question about cqen flag in detecting the state of command queue #368

Closed viktoryou closed 1 week ago

viktoryou commented 1 week ago

In the code of the model, cqcsr.cqen is not used in checking the state of command queue. Is that correct?

From the spec,

When cqen is changed from 1 to 0, the command queue may stay active (with busy asserted) until the commands already fetched from the command-queue are being processed and/or there are outstanding implicit loads from the command-queue. When the command-queue turns off the cqon bit reads 0.

Should the fetch of new commands stop since cqen is changed from 1 to 0, or the fetch would be always active until the command queue becomes empty(seems like the behavior of the model)?

ved-rivos commented 1 week ago

Should the fetch of new commands stop since cqen is changed from 1 to 0, or the fetch would be always active until the command queue becomes empty(seems like the behavior of the model)?

When cqen is set to 0, the cqon goes to 0. The command queue is no longer active and will stop fetching any more commands. An implementation may observe the cqen write in between two commands i.e. complete the commands that have been already fetched and then mark itself as off by setting cqon to 0. When cqon is 0, the model does not fetch commands anymore. In the reference model, this turning off of cqon occurs instantaneously since the model cannot observe a cqen write while a command is in progress. However for making this concept more explicit we could add cqen into this. Added this in #369 to illustrate the concept.

  if ( (g_reg_file.cqcsr.cqon == 0) || 
+      (g_reg_file.cqcsr.cqen == 0) ||
       (g_reg_file.cqcsr.cqmf != 0) ||

Waiting till its empty is also an acceptable behavior but not a desirable behavior.

ved-rivos commented 1 week ago

The model was however missing the case where there might be a IOFENCE pending and the cqon clearing should be delayed. This is updated in #370 .