std1.0.0-beta-7 SafeC docs

std :: dma

Struct std::DmaBuffer

#include <std/dma.h> source

struct DmaBuffer {
    &unsigned char virt;
    unsigned long phys;
    unsigned long size;
    int owner;
}

Fields

§&unsigned char virtsource

virtual address (CPU view)

§unsigned long physsource

physical address (device view, 0 if identity-mapped)

§unsigned long sizesource

buffer size in bytes

§int ownersource

0 = CPU owns, 1 = device owns

Methods

§void to_device()source · definition

Mark buffer as owned by device (flush CPU cache → DRAM before transfer).

§void to_cpu()source · definition

Mark buffer as owned by CPU (invalidate cache after DMA completes).

§int cpu_accessible() constsource · definition

Is the buffer currently safe to access from the CPU?

§unsigned long phys_at(unsigned long offset) constsource · definition

Return physical address of byte at offset.

§static struct DmaBuffer wrap([]unsigned char virt, unsigned long phys)source · definition

Initialise a DmaBuffer wrapping an existing allocation (all of virt). phys = 0 means physical == virtual (identity-mapped / non-MMU systems).