[OpenBIOS] [PATCH 04/15] SPARC32: implement dvma_map_in() for DMA IOVA to phys translation

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


Rather than have dvma_alloc() store the result of the physical translation
in the specified location, use the fact that we now have contiguous physical
DMA memory to implement dvma_map_in() to perform the translation separately.

This allows us to remove the pointer to the physical address parameter to
dvma_alloc() and instead perform the translation in esp.c by calling
dvma_map_in() separately.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 drivers/esp.c             |  3 ++-
 drivers/iommu.c           | 17 ++++++++++++++---
 include/drivers/drivers.h |  3 ++-
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/esp.c b/drivers/esp.c
index a4d6ef4..44b2096 100644
--- a/drivers/esp.c
+++ b/drivers/esp.c
@@ -490,7 +490,8 @@ ob_esp_init(unsigned int slot, uint64_t base, unsigned long espoffset,
         return -1;
     }
 
-    esp->buffer = (void *)dvma_alloc(BUFSIZE, &esp->buffer_dvma);
+    esp->buffer = (void *)dvma_alloc(BUFSIZE);
+    esp->buffer_dvma = dvma_map_in(esp->buffer);
     if (!esp->buffer || !esp->buffer_dvma) {
         DPRINTF("Can't get a DVMA buffer\n");
         return -1;
diff --git a/drivers/iommu.c b/drivers/iommu.c
index 0bf742f..b8ec09e 100644
--- a/drivers/iommu.c
+++ b/drivers/iommu.c
@@ -43,7 +43,7 @@ iommu_invalidate(struct iommu_regs *iregs)
  * BTW, we were not going to give away anonymous storage, were we not?
  */
 void *
-dvma_alloc(int size, unsigned int *pphys)
+dvma_alloc(int size)
 {
     void *va;
     unsigned int pa, iova;
@@ -78,11 +78,22 @@ dvma_alloc(int size, unsigned int *pphys)
         mpa += PAGE_SIZE;
     }
 
-    *pphys = iova;
-
     return va;
 }
 
+unsigned int
+dvma_map_in(unsigned char *va)
+{
+    /* Convert from VA to IOVA */
+    unsigned int pa, iova;
+    struct iommu *t = &ciommu;
+
+    pa = va2pa((unsigned int)va);
+    iova = t->plow + (pa - t->pphys);
+
+    return iova;
+}
+
 #define DVMA_SIZE 0x4000
 
 /*
diff --git a/include/drivers/drivers.h b/include/drivers/drivers.h
index 59ee436..85a8db0 100644
--- a/include/drivers/drivers.h
+++ b/include/drivers/drivers.h
@@ -73,7 +73,8 @@ void ss5_init(uint64_t base);
 
 /* drivers/iommu.c */
 void ob_init_iommu(uint64_t base);
-void *dvma_alloc(int size, unsigned int *pphys);
+void *dvma_alloc(int size);
+unsigned int dvma_map_in(unsigned char *va);
 
 /* drivers/sbus.c */
 extern uint16_t graphic_depth;
-- 
2.11.0




More information about the OpenBIOS mailing list