mirror of https://gitee.com/openkylin/qemu.git
xen: Clean up map cache API naming
The map cache is a Xen thing, so its API should make this clear. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
parent
6dbd588a41
commit
e41d7c691a
18
exec.c
18
exec.c
|
@ -3020,7 +3020,7 @@ void qemu_ram_free(ram_addr_t addr)
|
||||||
munmap(block->host, block->length);
|
munmap(block->host, block->length);
|
||||||
#else
|
#else
|
||||||
if (xen_mapcache_enabled()) {
|
if (xen_mapcache_enabled()) {
|
||||||
qemu_invalidate_entry(block->host);
|
xen_invalidate_map_cache_entry(block->host);
|
||||||
} else {
|
} else {
|
||||||
qemu_vfree(block->host);
|
qemu_vfree(block->host);
|
||||||
}
|
}
|
||||||
|
@ -3118,9 +3118,10 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
|
||||||
* In that case just map until the end of the page.
|
* In that case just map until the end of the page.
|
||||||
*/
|
*/
|
||||||
if (block->offset == 0) {
|
if (block->offset == 0) {
|
||||||
return qemu_map_cache(addr, 0, 0);
|
return xen_map_cache(addr, 0, 0);
|
||||||
} else if (block->host == NULL) {
|
} else if (block->host == NULL) {
|
||||||
block->host = qemu_map_cache(block->offset, block->length, 1);
|
block->host =
|
||||||
|
xen_map_cache(block->offset, block->length, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return block->host + (addr - block->offset);
|
return block->host + (addr - block->offset);
|
||||||
|
@ -3148,9 +3149,10 @@ void *qemu_safe_ram_ptr(ram_addr_t addr)
|
||||||
* In that case just map until the end of the page.
|
* In that case just map until the end of the page.
|
||||||
*/
|
*/
|
||||||
if (block->offset == 0) {
|
if (block->offset == 0) {
|
||||||
return qemu_map_cache(addr, 0, 0);
|
return xen_map_cache(addr, 0, 0);
|
||||||
} else if (block->host == NULL) {
|
} else if (block->host == NULL) {
|
||||||
block->host = qemu_map_cache(block->offset, block->length, 1);
|
block->host =
|
||||||
|
xen_map_cache(block->offset, block->length, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return block->host + (addr - block->offset);
|
return block->host + (addr - block->offset);
|
||||||
|
@ -3168,7 +3170,7 @@ void *qemu_safe_ram_ptr(ram_addr_t addr)
|
||||||
void *qemu_ram_ptr_length(target_phys_addr_t addr, target_phys_addr_t *size)
|
void *qemu_ram_ptr_length(target_phys_addr_t addr, target_phys_addr_t *size)
|
||||||
{
|
{
|
||||||
if (xen_mapcache_enabled())
|
if (xen_mapcache_enabled())
|
||||||
return qemu_map_cache(addr, *size, 1);
|
return xen_map_cache(addr, *size, 1);
|
||||||
else {
|
else {
|
||||||
RAMBlock *block;
|
RAMBlock *block;
|
||||||
|
|
||||||
|
@ -3199,7 +3201,7 @@ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr)
|
||||||
uint8_t *host = ptr;
|
uint8_t *host = ptr;
|
||||||
|
|
||||||
if (xen_mapcache_enabled()) {
|
if (xen_mapcache_enabled()) {
|
||||||
*ram_addr = qemu_ram_addr_from_mapcache(ptr);
|
*ram_addr = xen_ram_addr_from_mapcache(ptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4114,7 +4116,7 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (xen_mapcache_enabled()) {
|
if (xen_mapcache_enabled()) {
|
||||||
qemu_invalidate_entry(buffer);
|
xen_invalidate_map_cache_entry(buffer);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,9 +399,9 @@ disable xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: %#
|
||||||
disable xen_client_set_memory(uint64_t start_addr, unsigned long size, unsigned long phys_offset, bool log_dirty) "%#"PRIx64" size %#lx, offset %#lx, log_dirty %i"
|
disable xen_client_set_memory(uint64_t start_addr, unsigned long size, unsigned long phys_offset, bool log_dirty) "%#"PRIx64" size %#lx, offset %#lx, log_dirty %i"
|
||||||
|
|
||||||
# xen-mapcache.c
|
# xen-mapcache.c
|
||||||
disable qemu_map_cache(uint64_t phys_addr) "want %#"PRIx64""
|
disable xen_map_cache(uint64_t phys_addr) "want %#"PRIx64""
|
||||||
disable qemu_remap_bucket(uint64_t index) "index %#"PRIx64""
|
disable xen_remap_bucket(uint64_t index) "index %#"PRIx64""
|
||||||
disable qemu_map_cache_return(void* ptr) "%p"
|
disable xen_map_cache_return(void* ptr) "%p"
|
||||||
disable xen_map_block(uint64_t phys_addr, uint64_t size) "%#"PRIx64", size %#"PRIx64""
|
disable xen_map_block(uint64_t phys_addr, uint64_t size) "%#"PRIx64", size %#"PRIx64""
|
||||||
disable xen_unmap_block(void* addr, unsigned long size) "%p, size %#lx"
|
disable xen_unmap_block(void* addr, unsigned long size) "%p, size %#lx"
|
||||||
|
|
||||||
|
|
|
@ -644,7 +644,7 @@ static void handle_ioreq(ioreq_t *req)
|
||||||
case IOREQ_TYPE_TIMEOFFSET:
|
case IOREQ_TYPE_TIMEOFFSET:
|
||||||
break;
|
break;
|
||||||
case IOREQ_TYPE_INVALIDATE:
|
case IOREQ_TYPE_INVALIDATE:
|
||||||
qemu_invalidate_map_cache();
|
xen_invalidate_map_cache();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
hw_error("Invalid ioreq type 0x%x\n", req->type);
|
hw_error("Invalid ioreq type 0x%x\n", req->type);
|
||||||
|
@ -852,7 +852,7 @@ int xen_hvm_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init RAM management */
|
/* Init RAM management */
|
||||||
qemu_map_cache_init();
|
xen_map_cache_init();
|
||||||
xen_ram_init(ram_size);
|
xen_ram_init(ram_size);
|
||||||
|
|
||||||
qemu_add_vm_change_state_handler(xen_vm_change_state_handler, state);
|
qemu_add_vm_change_state_handler(xen_vm_change_state_handler, state);
|
||||||
|
|
|
@ -13,24 +13,25 @@
|
||||||
#include "cpu-common.h"
|
#include "cpu-common.h"
|
||||||
#include "xen-mapcache.h"
|
#include "xen-mapcache.h"
|
||||||
|
|
||||||
void qemu_map_cache_init(void)
|
void xen_map_cache_init(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, uint8_t lock)
|
uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
|
||||||
|
uint8_t lock)
|
||||||
{
|
{
|
||||||
return qemu_get_ram_ptr(phys_addr);
|
return qemu_get_ram_ptr(phys_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)
|
ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_invalidate_map_cache(void)
|
void xen_invalidate_map_cache(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_invalidate_entry(uint8_t *buffer)
|
void xen_invalidate_map_cache_entry(uint8_t *buffer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,9 @@
|
||||||
#endif
|
#endif
|
||||||
#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
|
#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
|
||||||
|
|
||||||
|
#define mapcache_lock() ((void)0)
|
||||||
|
#define mapcache_unlock() ((void)0)
|
||||||
|
|
||||||
typedef struct MapCacheEntry {
|
typedef struct MapCacheEntry {
|
||||||
target_phys_addr_t paddr_index;
|
target_phys_addr_t paddr_index;
|
||||||
uint8_t *vaddr_base;
|
uint8_t *vaddr_base;
|
||||||
|
@ -79,7 +82,7 @@ static inline int test_bits(int nr, int size, const unsigned long *addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_map_cache_init(void)
|
void xen_map_cache_init(void)
|
||||||
{
|
{
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
struct rlimit rlimit_as;
|
struct rlimit rlimit_as;
|
||||||
|
@ -106,13 +109,14 @@ void qemu_map_cache_init(void)
|
||||||
|
|
||||||
size = mapcache->nr_buckets * sizeof (MapCacheEntry);
|
size = mapcache->nr_buckets * sizeof (MapCacheEntry);
|
||||||
size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1);
|
size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1);
|
||||||
DPRINTF("qemu_map_cache_init, nr_buckets = %lx size %lu\n", mapcache->nr_buckets, size);
|
DPRINTF("%s, nr_buckets = %lx size %lu\n", __func__,
|
||||||
|
mapcache->nr_buckets, size);
|
||||||
mapcache->entry = qemu_mallocz(size);
|
mapcache->entry = qemu_mallocz(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qemu_remap_bucket(MapCacheEntry *entry,
|
static void xen_remap_bucket(MapCacheEntry *entry,
|
||||||
target_phys_addr_t size,
|
target_phys_addr_t size,
|
||||||
target_phys_addr_t address_index)
|
target_phys_addr_t address_index)
|
||||||
{
|
{
|
||||||
uint8_t *vaddr_base;
|
uint8_t *vaddr_base;
|
||||||
xen_pfn_t *pfns;
|
xen_pfn_t *pfns;
|
||||||
|
@ -120,7 +124,7 @@ static void qemu_remap_bucket(MapCacheEntry *entry,
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
target_phys_addr_t nb_pfn = size >> XC_PAGE_SHIFT;
|
target_phys_addr_t nb_pfn = size >> XC_PAGE_SHIFT;
|
||||||
|
|
||||||
trace_qemu_remap_bucket(address_index);
|
trace_xen_remap_bucket(address_index);
|
||||||
|
|
||||||
pfns = qemu_mallocz(nb_pfn * sizeof (xen_pfn_t));
|
pfns = qemu_mallocz(nb_pfn * sizeof (xen_pfn_t));
|
||||||
err = qemu_mallocz(nb_pfn * sizeof (int));
|
err = qemu_mallocz(nb_pfn * sizeof (int));
|
||||||
|
@ -164,17 +168,18 @@ static void qemu_remap_bucket(MapCacheEntry *entry,
|
||||||
qemu_free(err);
|
qemu_free(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, uint8_t lock)
|
uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
|
||||||
|
uint8_t lock)
|
||||||
{
|
{
|
||||||
MapCacheEntry *entry, *pentry = NULL;
|
MapCacheEntry *entry, *pentry = NULL;
|
||||||
target_phys_addr_t address_index = phys_addr >> MCACHE_BUCKET_SHIFT;
|
target_phys_addr_t address_index = phys_addr >> MCACHE_BUCKET_SHIFT;
|
||||||
target_phys_addr_t address_offset = phys_addr & (MCACHE_BUCKET_SIZE - 1);
|
target_phys_addr_t address_offset = phys_addr & (MCACHE_BUCKET_SIZE - 1);
|
||||||
target_phys_addr_t __size = size;
|
target_phys_addr_t __size = size;
|
||||||
|
|
||||||
trace_qemu_map_cache(phys_addr);
|
trace_xen_map_cache(phys_addr);
|
||||||
|
|
||||||
if (address_index == mapcache->last_address_index && !lock && !__size) {
|
if (address_index == mapcache->last_address_index && !lock && !__size) {
|
||||||
trace_qemu_map_cache_return(mapcache->last_address_vaddr + address_offset);
|
trace_xen_map_cache_return(mapcache->last_address_vaddr + address_offset);
|
||||||
return mapcache->last_address_vaddr + address_offset;
|
return mapcache->last_address_vaddr + address_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,20 +203,20 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, u
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
entry = qemu_mallocz(sizeof (MapCacheEntry));
|
entry = qemu_mallocz(sizeof (MapCacheEntry));
|
||||||
pentry->next = entry;
|
pentry->next = entry;
|
||||||
qemu_remap_bucket(entry, __size, address_index);
|
xen_remap_bucket(entry, __size, address_index);
|
||||||
} else if (!entry->lock) {
|
} else if (!entry->lock) {
|
||||||
if (!entry->vaddr_base || entry->paddr_index != address_index ||
|
if (!entry->vaddr_base || entry->paddr_index != address_index ||
|
||||||
entry->size != __size ||
|
entry->size != __size ||
|
||||||
!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT,
|
!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT,
|
||||||
entry->valid_mapping)) {
|
entry->valid_mapping)) {
|
||||||
qemu_remap_bucket(entry, __size, address_index);
|
xen_remap_bucket(entry, __size, address_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT,
|
if(!test_bits(address_offset >> XC_PAGE_SHIFT, size >> XC_PAGE_SHIFT,
|
||||||
entry->valid_mapping)) {
|
entry->valid_mapping)) {
|
||||||
mapcache->last_address_index = -1;
|
mapcache->last_address_index = -1;
|
||||||
trace_qemu_map_cache_return(NULL);
|
trace_xen_map_cache_return(NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,11 +231,11 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, u
|
||||||
QTAILQ_INSERT_HEAD(&mapcache->locked_entries, reventry, next);
|
QTAILQ_INSERT_HEAD(&mapcache->locked_entries, reventry, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
trace_qemu_map_cache_return(mapcache->last_address_vaddr + address_offset);
|
trace_xen_map_cache_return(mapcache->last_address_vaddr + address_offset);
|
||||||
return mapcache->last_address_vaddr + address_offset;
|
return mapcache->last_address_vaddr + address_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)
|
ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
|
||||||
{
|
{
|
||||||
MapCacheEntry *entry = NULL, *pentry = NULL;
|
MapCacheEntry *entry = NULL, *pentry = NULL;
|
||||||
MapCacheRev *reventry;
|
MapCacheRev *reventry;
|
||||||
|
@ -247,7 +252,7 @@ ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
fprintf(stderr, "qemu_ram_addr_from_mapcache, could not find %p\n", ptr);
|
fprintf(stderr, "%s, could not find %p\n", __func__, ptr);
|
||||||
QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {
|
QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {
|
||||||
DPRINTF(" "TARGET_FMT_plx" -> %p is present\n", reventry->paddr_index,
|
DPRINTF(" "TARGET_FMT_plx" -> %p is present\n", reventry->paddr_index,
|
||||||
reventry->vaddr_req);
|
reventry->vaddr_req);
|
||||||
|
@ -269,7 +274,7 @@ ram_addr_t qemu_ram_addr_from_mapcache(void *ptr)
|
||||||
((unsigned long) ptr - (unsigned long) entry->vaddr_base);
|
((unsigned long) ptr - (unsigned long) entry->vaddr_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_invalidate_entry(uint8_t *buffer)
|
void xen_invalidate_map_cache_entry(uint8_t *buffer)
|
||||||
{
|
{
|
||||||
MapCacheEntry *entry = NULL, *pentry = NULL;
|
MapCacheEntry *entry = NULL, *pentry = NULL;
|
||||||
MapCacheRev *reventry;
|
MapCacheRev *reventry;
|
||||||
|
@ -290,7 +295,7 @@ void qemu_invalidate_entry(uint8_t *buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
DPRINTF("qemu_invalidate_entry, could not find %p\n", buffer);
|
DPRINTF("%s, could not find %p\n", __func__, buffer);
|
||||||
QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {
|
QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {
|
||||||
DPRINTF(" "TARGET_FMT_plx" -> %p is present\n", reventry->paddr_index, reventry->vaddr_req);
|
DPRINTF(" "TARGET_FMT_plx" -> %p is present\n", reventry->paddr_index, reventry->vaddr_req);
|
||||||
}
|
}
|
||||||
|
@ -322,7 +327,7 @@ void qemu_invalidate_entry(uint8_t *buffer)
|
||||||
qemu_free(entry);
|
qemu_free(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_invalidate_map_cache(void)
|
void xen_invalidate_map_cache(void)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
MapCacheRev *reventry;
|
MapCacheRev *reventry;
|
||||||
|
|
|
@ -9,13 +9,11 @@
|
||||||
#ifndef XEN_MAPCACHE_H
|
#ifndef XEN_MAPCACHE_H
|
||||||
#define XEN_MAPCACHE_H
|
#define XEN_MAPCACHE_H
|
||||||
|
|
||||||
void qemu_map_cache_init(void);
|
void xen_map_cache_init(void);
|
||||||
uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, uint8_t lock);
|
uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
|
||||||
ram_addr_t qemu_ram_addr_from_mapcache(void *ptr);
|
uint8_t lock);
|
||||||
void qemu_invalidate_entry(uint8_t *buffer);
|
ram_addr_t xen_ram_addr_from_mapcache(void *ptr);
|
||||||
void qemu_invalidate_map_cache(void);
|
void xen_invalidate_map_cache_entry(uint8_t *buffer);
|
||||||
|
void xen_invalidate_map_cache(void);
|
||||||
#define mapcache_lock() ((void)0)
|
|
||||||
#define mapcache_unlock() ((void)0)
|
|
||||||
|
|
||||||
#endif /* !XEN_MAPCACHE_H */
|
#endif /* !XEN_MAPCACHE_H */
|
||||||
|
|
Loading…
Reference in New Issue