[OpenBIOS] [PATCH 09/15] PPC: implement dma-* words

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


Implement the dma-* words in the root node using Forth, except for dma-alloc
and dma-sync which require C to use the in-built aligned memory allocator and
I-cache and D-cache flushing.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 arch/ppc/qemu/init.c  | 35 +++++++++++++++++++++++++++++++++++
 arch/ppc/qemu/tree.fs | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c
index 8524750..74a4c6b 100644
--- a/arch/ppc/qemu/init.c
+++ b/arch/ppc/qemu/init.c
@@ -751,6 +751,35 @@ static void adler32(void)
     RET(s2 << 16 | s1);
 }
 
+/* ( size -- virt ) */
+static void
+dma_alloc(void)
+{
+    ucell size = POP();
+    ucell addr;
+    int ret;
+
+    ret = ofmem_posix_memalign((void *)&addr, size, PAGE_SIZE);
+
+    if (ret) {
+        PUSH(0);
+    } else {
+        PUSH(addr);
+    }
+}
+
+/* ( virt devaddr size -- ) */
+static void
+dma_sync(void)
+{
+    ucell size = POP();
+    POP();
+    ucell virt = POP();
+
+    flush_dcache_range(cell2pointer(virt), cell2pointer(virt + size));
+    flush_icache_range(cell2pointer(virt), cell2pointer(virt + size));
+}
+
 void
 arch_of_init(void)
 {
@@ -768,6 +797,12 @@ arch_of_init(void)
     openbios_init();
     modules_init();
     setup_timers();
+
+    bind_func("ppc-dma-alloc", dma_alloc);
+    feval("['] ppc-dma-alloc to (dma-alloc)");
+    bind_func("ppc-dma-sync", dma_sync);
+    feval("['] ppc-dma-sync to (dma-sync)");
+
 #ifdef CONFIG_DRIVER_PCI
     ob_pci_init();
 #endif
diff --git a/arch/ppc/qemu/tree.fs b/arch/ppc/qemu/tree.fs
index 5b6bbc6..481acd9 100644
--- a/arch/ppc/qemu/tree.fs
+++ b/arch/ppc/qemu/tree.fs
@@ -7,6 +7,26 @@
 
 include config.fs
 
+\ ---------
+\ DMA words
+\ ---------
+
+: ppc-dma-free  ( virt size -- )
+  2drop
+;
+
+: ppc-dma-map-in  ( virt size cacheable? -- devaddr )
+  2drop
+;
+
+: ppc-dma-map-out  ( virt devaddr size -- )
+  (dma-sync)
+;
+
+['] ppc-dma-free to (dma-free)
+['] ppc-dma-map-in to (dma-map-in)
+['] ppc-dma-map-out to (dma-map-out)
+
 \ -------------------------------------------------------------
 \ device-tree
 \ -------------------------------------------------------------
@@ -18,6 +38,26 @@ include config.fs
 1 encode-int " #size-cells" property
 h# 05f5e100 encode-int " clock-frequency" property
 
+	: 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
 	" cpus" device-name
 	1 encode-int " #address-cells" property
-- 
2.11.0




More information about the OpenBIOS mailing list