riscv-non-isa / riscv-iommu

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

How to understand the unsupport in c model about command illegal ? #379

Closed baimengwei closed 1 month ago

baimengwei commented 1 month ago

https://github.com/riscv-non-isa/riscv-iommu/blob/main/src/iommu_in_memory_queues.adoc#command-queue-cq

A command is unsupported if it is defined but not implemented as determined by the IOMMU capabilities register.

In the c model, if a iofence.c command is send, but the g_reg_file.fctl.wsi == 0 && command.iofence.wsi == 1 is meet the condition, the command will be illegal. However, it is not involved in a judgement about IOMMU capabilities register.

        case IOFENCE:
            if ( command.iofence.reserved != 0 || command.iofence.reserved1 != 0 )
                goto command_illegal;
            // The wired-signaled-interrupt (WSI) bit when set to 1
            // causes a wired-interrupt from the command
            // queue to be generated on completion of IOFENCE.C. This
            // bit is reserved if the IOMMU supports MSI.
            if ( g_reg_file.fctl.wsi == 0 && command.iofence.wsi == 1)
                goto command_illegal;

https://github.com/riscv-non-isa/riscv-iommu/blob/main/iommu_ref_model/libiommu/src/iommu_command_queue.c#L160

If a iodir command is send, but command illegal judgement is not involved in ddtp.iommu_mode, which might cause a unexpect condition. This is also not involved in a judgement about IOMMU capabilities register. And c model use a g_max_devid_mask to instead.

            switch ( command.any.func3 ) {
                case INVAL_DDT:
                    // The PID operand is reserved for the
                    // IODIR.INVAL_DDT command.
                    if ( command.iodir.pid != 0 ) goto command_illegal;
                    // When DV operand is 1, the value of the DID operand must not
                    // be wider than that supported by the ddtp.iommu_mode.
                    if ( command.iodir.dv &&
                         (command.iodir.did & ~g_max_devid_mask) ) {
                        goto command_illegal;
                    }

https://github.com/riscv-non-isa/riscv-iommu/blob/main/iommu_ref_model/libiommu/src/iommu_command_queue.c#L114

So. Is the ftcl should not involved in judgement? Or is the ddtp.iommu_mode should involved in judgement?

Thanks.

ved-rivos commented 1 month ago

The ability to support wire-signaled-interrupts is determined by the WARL field - fctl.WSI. If the IOMMU does not support wire-signaled-interrupts then this bit is hardwired to 0.

The DID field of the IODIR command must not be wider than that supported by the IOMMU. It is not about the current mode. When the IOMMU mode is changed, the IOMMU does not invalidate the DDT or PDT cache. However, invalidating the DDT or PDT cache can be performed using IODIR as long as the device ID width is a supported device ID width.

ved-rivos commented 1 month ago

A command is unsupported if it is defined but not implemented as determined by the IOMMU capabilities register.

This statement is about the command itself. The first statement of that paragraph applies to commands that are implemented: "A command is determined to be illegal if it uses a reserved encoding or if a reserved bit is set to 1."

baimengwei commented 1 month ago

Get it. Thanks a lot.