anchor.diff:  
   0 VALUE phb-debug?
   
  +1000 CONSTANT tce-ps		\ Default TCE page size is 4K
  +tce-ps 1- CONSTANT tce-mask
   
   ." Populating " pwd cr
   
  
positive.code: 0 VALUE dma-window-size         \ Size of the window
  
  0 VALUE bm-handle               \ Bitmap allocator handle
  0 VALUE my-virt
  0 VALUE my-size
  0 VALUE dev-addr
  0 VALUE tmp-dev-addr
  
  \ Read helper variables (LIOBN, DMA window base and size) from the
  \ "ibm,dma-window" property. This property can be either located
  
negative.code:     0 TO dma-window-size
  ;
  
  \ grub does not align allocated addresses to the size so when mapping,
  \ we might need to ask bm-alloc for an extra IOMMU page
  : dma-align ( size virt -- aligned-size ) tce-mask and + tce-ps #aligned ;
  : dma-trunc ( addr -- addr&~fff ) tce-mask not and ;
  
  : dma-map-in  ( virt size cachable? -- devaddr )
     phb-debug? IF cr ." dma-map-in called: " .s cr THEN
     (init-dma-window-vars)
     drop
     over dma-align                     ( virt size ) \ size is aligned now
     tuck                               ( size virt size )
     bm-handle swap bm-alloc            ( size virt dev-addr ) \ dev-addr is aligned
     dup 0 < IF
         ." Bitmap allocation Failed "
         3drop
         0 EXIT
     THEN
  
     swap                               ( size dev-addr virt )
     2dup tce-mask and or >r            \ add page offset to the return value
  
     dma-trunc 3 OR                     \ Truncate and add read and write perm
     rot                                ( dev-addr virt size r: dev-addr )
     0
     ?DO
         2dup dma-window-liobn -rot     ( dev-addr virt liobn dev-addr virt r: dev-addr )
         hv-put-tce ABORT" H_PUT_TCE failed"
         tce-ps + swap tce-ps + swap    ( dev-addr' virt' r: dev-addr )
     tce-ps +LOOP
     (clear-dma-window-vars)
     2drop
     r>
  ;
  
  : dma-map-out  ( virt devaddr size -- )
     phb-debug? IF cr ." dma-map-out called: " .s cr THEN
     (init-dma-window-vars)
     rot drop                            ( devaddr size )
     over dma-align
     swap dma-trunc swap                 ( devaddr-trunc size-extended )
     2dup bm-handle -rot bm-free
     0
     ?DO
         dup 0 dma-window-liobn -rot
         hv-put-tce ABORT" H_PUT_TCE failed"
         tce-ps +
     tce-ps +LOOP
     drop
     (clear-dma-window-vars)
  ;
  
  