1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:47:35 +00:00

Kernel: Flush data cache before passing a buffer to the VC Mailbox

Otherwise, the message's contents might be in the cache only, so
VideoCore will read stale/garbage data from main memory.

This fixes framebuffer setup on bare metal with the data cache enabled.
This commit is contained in:
Daniel Bertalan 2023-05-16 15:27:50 +02:00 committed by Andrew Kaster
parent 0cbcdb227f
commit 3d383974cd
2 changed files with 24 additions and 0 deletions

View file

@ -125,6 +125,25 @@ inline u64 read_rndrrs()
return value;
}
inline FlatPtr get_cache_line_size()
{
FlatPtr ctr_el0;
asm volatile("mrs %[value], ctr_el0"
: [value] "=r"(ctr_el0));
auto log2_size = (ctr_el0 >> 16) & 0xF;
return 1 << log2_size;
}
inline void flush_data_cache(FlatPtr start, size_t size)
{
auto const cache_size = get_cache_line_size();
for (FlatPtr addr = align_down_to(start, cache_size); addr < start + size; addr += cache_size)
asm volatile("dc civac, %[addr]" ::[addr] "r"(addr)
: "memory");
asm volatile("dsb sy" ::
: "memory");
}
}
namespace Kernel {