]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Flush caches on DMA memory.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 13 May 2011 18:56:50 +0000 (20:56 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 13 May 2011 18:56:50 +0000 (20:56 +0200)
* grub-core/kern/mips/cache.S (grub_arch_sync_dma_caches): New function.
* grub-core/bus/pci.c (grub_memalign_dma32): Flush caches.
(grub_dma_free): Likewise.
* include/grub/cache.h (grub_arch_sync_dma_caches): New declaration.

ChangeLog
grub-core/bus/pci.c
grub-core/kern/mips/cache.S
include/grub/cache.h

index 5b73d8884c4b9df7037a0491458c53801fcc2549..49873303ca5ad92441f0a6203c092858ca1145a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-05-13  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Flush caches on DMA memory.
+
+       * grub-core/kern/mips/cache.S (grub_arch_sync_dma_caches): New function.
+       * grub-core/bus/pci.c (grub_memalign_dma32): Flush caches.
+       (grub_dma_free): Likewise.
+       * include/grub/cache.h (grub_arch_sync_dma_caches): New declaration.
+
 2011-05-13  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/boot/mips/yeeloong/fwstart.S: Add explicit set mips3
index 07d20e3f5db5c97ccecfb1351621142700464d9a..766b6d7f182bcd48be2657d66cc4252fdb0e4bbc 100644 (file)
@@ -20,6 +20,8 @@
 #include <grub/dl.h>
 #include <grub/pci.h>
 #include <grub/mm.h>
+#include <grub/mm_private.h>
+#include <grub/cache.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -28,12 +30,19 @@ GRUB_MOD_LICENSE ("GPLv3+");
 struct grub_pci_dma_chunk *
 grub_memalign_dma32 (grub_size_t align, grub_size_t size)
 {
-  return grub_memalign (align, size);
+  void *ret = grub_memalign (align, size);
+  if (!ret)
+    return 0;
+  grub_arch_sync_dma_caches (ret, size);
+  return ret;
 }
 
+/* FIXME: evil.  */
 void
 grub_dma_free (struct grub_pci_dma_chunk *ch)
 {
+  grub_size_t size = (((struct grub_mm_header *) ch) - 1)->size * GRUB_MM_ALIGN;
+  grub_arch_sync_dma_caches (ch, size);
   grub_free (ch);
 }
 /* #endif */
index 999872f6b53dc57ec2c33e34c52d6dfd227de895..a4aa06fb099c329f60b566804b5f41bf463d8ee7 100644 (file)
@@ -8,3 +8,38 @@ FUNCTION (grub_cpu_flush_cache)
 FUNCTION (grub_arch_sync_caches)
 #include "cache_flush.S"
        j $ra
+
+FUNCTION (grub_arch_sync_dma_caches)
+       move $t2, $a0
+       addu $t3, $a0, $a1
+       srl $t2, $t2, 5
+       sll $t2, $t2, 5
+       addu $t3, $t3, 0x1f
+       srl $t3, $t3, 5
+       sll $t3, $t3, 5
+       move $t0, $t2
+       subu $t1, $t3, $t2
+1:
+       cache 1, 0($t0)
+       addiu $t1, $t1, 0xffff
+       bne $t1, $zero, 1b
+        addiu $t0, $t0, 0x1
+       sync
+       move $t0, $t2
+       subu $t1, $t3, $t2
+2:
+       cache 0, 0($t0)
+       addiu $t1, $t1, 0xffff
+       bne $t1, $zero, 2b
+        addiu $t0, $t0, 0x1
+       sync
+       move $t0, $t2
+       subu $t1, $t3, $t2
+2:
+       cache 23, 0($t0)
+       addiu $t1, $t1, 0xffff
+       bne $t1, $zero, 2b
+        addiu $t0, $t0, 0x1
+       sync
+
+       jr $ra
\ No newline at end of file
index 4f913f5c85c3e74cd9de31342010cea3eab3be39..292830566604cfc72318ddc20a31613dee5a6b9a 100644 (file)
@@ -37,4 +37,14 @@ grub_arch_sync_caches (void *address __attribute__ ((unused)),
 void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len);
 #endif
 
+#ifdef _mips
+void EXPORT_FUNC(grub_arch_sync_dma_caches) (void *address, grub_size_t len);
+#else
+static inline void
+grub_arch_sync_dma_caches (void *address __attribute__ ((unused)),
+                          grub_size_t len __attribute__ ((unused)))
+{
+}
+#endif
+
 #endif /* ! GRUB_CACHE_HEADER */