https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=293381

            Bug ID: 293381
           Summary: linuxkpi: Possible incorrect bus_dmasync_op_t mapping
                    for DMA_BIDIRECTIONAL
           Product: Base System
           Version: 15.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Created attachment 268296
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=268296&action=edit
Illustrative patch

In dma_sync_single_for_cpu(), for DMA_BIDIRECTIONAL, the code currently
performs BUS_DMASYNC_POSTREAD followed by BUS_DMASYNC_PREREAD. I suspect it
should simply be BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE.

Reason: dma_sync_single_for_cpu() transfers the ownership of the DMA area to
the CPU. Since DMA_BIDIRECTIONAL indicates the area can be used for both Device
-> Main Memory and Main Memory -> Device transfers, we must assume the previous
device's access was bidirectional. Because the device might have both read from
and written to this area, both POST operations are necessary before the CPU
accesses it.

Furthermore, since the ownership of the DMA area is being transferred to the
CPU, the device will no longer access it. Therefore, I believe the PREREAD
operation is unnecessary. PREREAD should instead be used when ownership is
transferred back to the device.

So, for dma_sync_single_for_device(), I suspect it should use
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE to prepare the buffer for potential
bidirectional access by the hardware.

PS: I noticed this logic was introduced in https://reviews.freebsd.org/D32255.
this DR conclusion seemed a bit unclear, and the current mapping was ultimately
adopted. Given that context, I just wanted to bring this up to see if it might
be an oversight.
Please kindly correct me if my understanding is wrong.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to