B FCode Memory Allocation





To get general-purpose memory, use buffer: or alloc-mem. Use free-mem to de-allocate memory obtained with alloc-mem.

To map in portions of your SBus device for ordinary access use " map-in" $call-parent as in:

---------------------------------------------------------------------
my-address offset my-space size " map-in" $call-parent ( virt ) ---------------------------------------------------------------------

To later map out those portions of your device, use " map-out" $call-parent as in:

-----------------------------------------
( virt ) size " map-out" $call-parent -----------------------------------------

To use a region of system memory for DMA (for example, for both direct CPU access and DMA access from a device), first define the following mapping and allocation routines, then follow the steps below to ensure data coherency.

-------------------------------------------------------------------------
: dma-alloc ( size -- virt ) " dma-alloc" $call-parent ; : dma-free ( virt size -- ) " dma-free" $call-parent ; : dma-map-in ( virt size cache? -- devaddr ) " dma-map-in" $call-parent ; : dma-map-out ( virt devaddr size -- ) " dma-map-out" $call-parent ; : dma-sync ( virt devaddr size -- ) \ Correct even if "dma-sync" missing " dma-sync" ['] $call-parent catch if 2drop 3drop then ; -------------------------------------------------------------------------
    1. Allocate the DMA region with:
      a. dma-alloc
      b. dma-map-in
    2. CPU accesses the region using virt from dma-alloc, then perform
    dma-sync.
    3. Start DMA operation, using devaddr from dma-map-in.
      a. Wait for DMA complete status.
      b. Repeat DMA as needed, then perform dma-sync
    4. Repeat Steps 2 and 3 as needed
    5. Deallocate the region when completed, with:
      a. dma-map-out
      b. dma-free