Sync L3 headers in sc-dev
Merge of these CLs from Widevine sc-dev: modified: libwvdrmengine/level3/include/clear_cache_function.h Add cache flush assembly for arm64 L3 to Android header | http://go/wvgerrit/124828 Address compilation errors | http://go/wvgerrit/113083 modified: libwvdrmengine/level3/include/level3_file_system_android.h Update Widevine Copyright header for android | http://go/wvgerrit/108084 Bug: 184866351 Test: Header changes for clearing cache is verified by one of the partners on their arm64 target; https: //b.corp.google.com/issues/175432203#comment13 Change-Id: I0ac8f339f65d02abb3080020fbc715b9c0db85b2
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <linux/membarrier.h>
|
||||
#include <sys/syscall.h>
|
||||
@@ -71,17 +73,19 @@ void clear_cache_function(void *page, size_t len) {
|
||||
// So, instead, we will define USED_BUILTIN_CLEAR_CACHE if both conditions
|
||||
// are true, and use "#ifndef USED_BUILTIN_CLEAR_CACHE" instead of #else.
|
||||
#ifdef __has_builtin
|
||||
#if __has_builtin(__builtin___clear_cache)
|
||||
#pragma message "(info): clear_cache_function is using __builtin___clear_cache."
|
||||
#define USED_BUILTIN_CLEAR_CACHE
|
||||
# if __has_builtin(__builtin___clear_cache)
|
||||
# pragma message "(info): clear_cache_function is using __builtin___clear_cache."
|
||||
# define USED_BUILTIN_CLEAR_CACHE
|
||||
char *begin = static_cast<char *>(page);
|
||||
char *end = begin + len;
|
||||
__builtin___clear_cache(begin, end);
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef USED_BUILTIN_CLEAR_CACHE
|
||||
#if __arm__
|
||||
#pragma message "(info): clear_cache_function is using arm asm."
|
||||
# if defined(__arm__)
|
||||
# pragma message "(info): clear_cache_function is using arm asm."
|
||||
# define USED_ARM_ASM_CLEAR_CACHE
|
||||
// ARM Cache Flush System Call:
|
||||
char *begin = static_cast<char *>(page);
|
||||
char *end = begin + len;
|
||||
@@ -97,25 +101,49 @@ void clear_cache_function(void *page, size_t len) {
|
||||
:
|
||||
: "r"(begin), "r"(end), "r"(syscall)
|
||||
: "r0", "r1", "r7");
|
||||
#elif __mips__
|
||||
#pragma message "(info): clear_cache_function is using mips asm."
|
||||
# elif defined(__aarch64__)
|
||||
# pragma message "(info): clear_cache_function is using arm64 asm."
|
||||
# define USED_ARM_ASM_CLEAR_CACHE
|
||||
uint64_t begin = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(page));
|
||||
uint64_t end = begin + len;
|
||||
register uint64_t ctr_el0;
|
||||
__asm __volatile("mrs %0, ctr_el0" : "=r"(ctr_el0));
|
||||
// register CTR_EL0 [19:16] contains dcache line size
|
||||
const size_t dcache_line_size = 4 << ((ctr_el0 >> 16) & 0xF);
|
||||
register uint64_t addr;
|
||||
for (addr = begin; addr < end; addr += dcache_line_size) {
|
||||
__asm __volatile("dc cvau, %0" ::"r"(addr));
|
||||
}
|
||||
__asm __volatile("dsb ish");
|
||||
// register CTR_EL0 [3:0] contains icache line size
|
||||
const size_t icache_line_size = 4 << (ctr_el0 & 0xF);
|
||||
for (addr = begin; addr < end; addr += icache_line_size) {
|
||||
__asm __volatile("ic ivau, %0" ::"r"(addr));
|
||||
}
|
||||
__asm __volatile("dsb ish");
|
||||
__asm __volatile("isb sy");
|
||||
# elif __mips__
|
||||
# pragma message "(info): clear_cache_function is using mips asm."
|
||||
int result = syscall(__NR_cacheflush, page, len, ICACHE);
|
||||
if (result) {
|
||||
fprintf(stderr, "cacheflush failed!: errno=%d %s\n", errno,
|
||||
strerror(errno));
|
||||
exit(-1); // TODO(fredgc): figure out more graceful error handling.
|
||||
}
|
||||
#else
|
||||
#pragma message "(info): clear_cache_function is not doing anything."
|
||||
# else
|
||||
# pragma message "(info): clear_cache_function is not doing anything."
|
||||
// TODO(fredgc): silence warning about unused variables.
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__arm__) || defined(__aarch64__)
|
||||
# if !defined(USED_BUILTIN_CLEAR_CACHE) && !defined(USED_ARM_ASM_CLEAR_CACHE)
|
||||
# error "clear cache function unavailable, which is required for ARM."
|
||||
# endif
|
||||
# pragma message "(info): inserting membarrier_function calls."
|
||||
membarrier_function(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE);
|
||||
membarrier_function(MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE);
|
||||
#endif // defined(__arm__) || defined(__aarch64__)
|
||||
}
|
||||
|
||||
} // namespace wvoec3
|
||||
} // namespace wvoec3
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
/*********************************************************************
|
||||
* level3_file_system_android.h
|
||||
|
||||
Reference in New Issue
Block a user