[OpenBIOS] [PATCH 07/15] SPARC32: implement dma-* words

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Mon May 21 23:33:14 CEST 2018


Use Forth wrappers around the existing C functions to implement all the dma-* words
in the root package.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 arch/sparc32/openbios.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 arch/sparc32/tree.fs    | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/arch/sparc32/openbios.c b/arch/sparc32/openbios.c
index dd31c23..3ec8fd7 100644
--- a/arch/sparc32/openbios.c
+++ b/arch/sparc32/openbios.c
@@ -806,6 +806,43 @@ static void init_memory(void)
     PUSH(virt + MEMORY_SIZE);
 }
 
+/* ( size -- virt ) */
+static void
+dma_alloc(void)
+{
+    ucell size = POP();
+    unsigned long *va;
+
+    va = dvma_alloc(size);
+
+    PUSH(pointer2cell(va));
+}
+
+/* ( virt devaddr size -- ) */
+static void
+dma_sync(void)
+{
+    ucell size = POP();
+    POP();
+    ucell virt = POP();
+
+    dvma_sync(cell2pointer(virt), size);
+}
+
+/* ( virt size cacheable? -- devaddr ) */
+static void
+dma_map_in(void)
+{
+    unsigned int iova;
+
+    POP();
+    POP();
+    ucell virt = POP();
+
+    iova = dvma_map_in(cell2pointer(virt));
+    PUSH((ucell)iova);
+}
+
 static void
 arch_init( void )
 {
@@ -839,6 +876,14 @@ arch_init( void )
 	modules_init();
         ob_init_mmu();
         ob_init_iommu(hwdef->iommu_base);
+
+        bind_func("(sparc32-dma-alloc)", dma_alloc);
+        feval("['] (sparc32-dma-alloc) to (dma-alloc)");
+        bind_func("(sparc32-dma-sync)", dma_sync);
+        feval("['] (sparc32-dma-sync) to (dma-sync)");
+        bind_func("(sparc32-dma-map-in)", dma_map_in);
+        feval("['] (sparc32-dma-map-in) to (dma-map-in)");
+
 #ifdef CONFIG_DRIVER_OBIO
         mem_size = fw_cfg_read_i32(FW_CFG_RAM_SIZE);
 	ob_obio_init(hwdef->slavio_base, hwdef->fd_offset,
@@ -916,7 +961,7 @@ arch_init( void )
 	
 	bind_func("platform-boot", boot );
 	bind_func("(arch-go)", setup_romvec );
-	
+
 	/* Set up other properties */
         push_str("/chosen");
         fword("find-device");
diff --git a/arch/sparc32/tree.fs b/arch/sparc32/tree.fs
index c82bb17..fc95636 100644
--- a/arch/sparc32/tree.fs
+++ b/arch/sparc32/tree.fs
@@ -1,5 +1,21 @@
 include config.fs
 
+\ ---------
+\ DMA words
+\ ---------
+
+: sparc32-dma-free  ( virt size -- )
+  2drop
+;
+
+: sparc32-dma-map-out  ( virt devaddr size -- )
+  (dma-sync)
+;
+
+['] sparc32-dma-free to (dma-free)
+['] sparc32-dma-map-out to (dma-map-out)
+
+
 " /" find-device
   2 encode-int " #address-cells" property
   1 encode-int " #size-cells" property
@@ -10,6 +26,26 @@ include config.fs
   : encode-unit encode-unit-sbus ;
   : decode-unit decode-unit-sbus ;
 
+  : dma-sync
+    (dma-sync)
+  ;
+
+  : dma-alloc
+    (dma-alloc)
+  ;
+
+  : dma-free
+    (dma-free)
+  ;
+
+  : dma-map-in
+    (dma-map-in)
+  ;
+
+  : dma-map-out
+    (dma-map-out)
+  ;
+
 new-device
   " memory" device-name
   external
-- 
2.11.0




More information about the OpenBIOS mailing list