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.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-05-13 20:56:50 +02:00
parent 91bbcc0cb6
commit 19e1c41bbf
4 changed files with 64 additions and 1 deletions

View file

@ -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> 2011-05-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/boot/mips/yeeloong/fwstart.S: Add explicit set mips3 * grub-core/boot/mips/yeeloong/fwstart.S: Add explicit set mips3

View file

@ -20,6 +20,8 @@
#include <grub/dl.h> #include <grub/dl.h>
#include <grub/pci.h> #include <grub/pci.h>
#include <grub/mm.h> #include <grub/mm.h>
#include <grub/mm_private.h>
#include <grub/cache.h>
GRUB_MOD_LICENSE ("GPLv3+"); GRUB_MOD_LICENSE ("GPLv3+");
@ -28,12 +30,19 @@ GRUB_MOD_LICENSE ("GPLv3+");
struct grub_pci_dma_chunk * struct grub_pci_dma_chunk *
grub_memalign_dma32 (grub_size_t align, grub_size_t size) 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 void
grub_dma_free (struct grub_pci_dma_chunk *ch) 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); grub_free (ch);
} }
/* #endif */ /* #endif */

View file

@ -8,3 +8,38 @@ FUNCTION (grub_cpu_flush_cache)
FUNCTION (grub_arch_sync_caches) FUNCTION (grub_arch_sync_caches)
#include "cache_flush.S" #include "cache_flush.S"
j $ra 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

View 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); void EXPORT_FUNC(grub_arch_sync_caches) (void *address, grub_size_t len);
#endif #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 */ #endif /* ! GRUB_CACHE_HEADER */