@ -22,16 +22,6 @@
# include "trace.h"
//#define MAPCACHE_DEBUG
# ifdef MAPCACHE_DEBUG
# define DPRINTF(fmt, ...) do { \
fprintf ( stderr , " xen_mapcache: " fmt , # # __VA_ARGS__ ) ; \
} while ( 0 )
# else
# define DPRINTF(fmt, ...) do { } while (0)
# endif
# if HOST_LONG_BITS == 32
# define MCACHE_BUCKET_SHIFT 16
# define MCACHE_MAX_SIZE (1UL<<31) /* 2GB Cap */
@ -145,8 +135,7 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
size = mapcache - > nr_buckets * sizeof ( MapCacheEntry ) ;
size = ( size + XC_PAGE_SIZE - 1 ) & ~ ( XC_PAGE_SIZE - 1 ) ;
DPRINTF ( " %s, nr_buckets = %lx size %lu \n " , __func__ ,
mapcache - > nr_buckets , size ) ;
trace_xen_map_cache_init ( mapcache - > nr_buckets , size ) ;
mapcache - > entry = g_malloc0 ( size ) ;
}
@ -286,7 +275,9 @@ tryagain:
test_bits ( address_offset > > XC_PAGE_SHIFT ,
test_bit_size > > XC_PAGE_SHIFT ,
mapcache - > last_entry - > valid_mapping ) ) {
trace_xen_map_cache_return ( mapcache - > last_entry - > vaddr_base + address_offset ) ;
trace_xen_map_cache_return (
mapcache - > last_entry - > vaddr_base + address_offset
) ;
return mapcache - > last_entry - > vaddr_base + address_offset ;
}
@ -368,7 +359,9 @@ tryagain:
QTAILQ_INSERT_HEAD ( & mapcache - > locked_entries , reventry , next ) ;
}
trace_xen_map_cache_return ( mapcache - > last_entry - > vaddr_base + address_offset ) ;
trace_xen_map_cache_return (
mapcache - > last_entry - > vaddr_base + address_offset
) ;
return mapcache - > last_entry - > vaddr_base + address_offset ;
}
@ -402,10 +395,10 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
}
}
if ( ! found ) {
fprintf ( stderr , " %s, could not find %p \n " , __func__ , ptr ) ;
trace_xen_ram_addr_from_mapcache_not_found ( ptr ) ;
QTAILQ_FOREACH ( reventry , & mapcache - > locked_entries , next ) {
DPRINTF ( " " HWADDR_FMT_plx " -> %p is present \n " , reventry - > paddr_index ,
reventry - > vaddr_req ) ;
trace_xen_ram_addr_from_mapcache_found ( reventry - > paddr_index ,
reventry - > vaddr_req ) ;
}
abort ( ) ;
return 0 ;
@ -416,7 +409,7 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
entry = entry - > next ;
}
if ( ! entry ) {
DPRINTF ( " Trying to find address %p that is not in the mapcache! \n " , ptr ) ;
trace_xen_ram_addr_from_mapcache_not_in_cache ( ptr ) ;
raddr = 0 ;
} else {
raddr = ( reventry - > paddr_index < < MCACHE_BUCKET_SHIFT ) +
@ -443,9 +436,12 @@ static void xen_invalidate_map_cache_entry_unlocked(uint8_t *buffer)
}
}
if ( ! found ) {
DPRINTF ( " %s, could not find %p \n " , __func__ , buffer ) ;
trace_xen_invalidate_map_cache_entry_unlocked_not_found ( buffer ) ;
QTAILQ_FOREACH ( reventry , & mapcache - > locked_entries , next ) {
DPRINTF ( " " HWADDR_FMT_plx " -> %p is present \n " , reventry - > paddr_index , reventry - > vaddr_req ) ;
trace_xen_invalidate_map_cache_entry_unlocked_found (
reventry - > paddr_index ,
reventry - > vaddr_req
) ;
}
return ;
}
@ -463,7 +459,7 @@ static void xen_invalidate_map_cache_entry_unlocked(uint8_t *buffer)
entry = entry - > next ;
}
if ( ! entry ) {
DPRINTF ( " Trying to unmap address %p that is not in the mapcache! \n " , buffer ) ;
trace_xen_invalidate_map_cache_entry_unlocked_miss ( buffer ) ;
return ;
}
entry - > lock - - ;
@ -502,9 +498,8 @@ void xen_invalidate_map_cache(void)
if ( ! reventry - > dma ) {
continue ;
}
fprintf ( stderr , " Locked DMA mapping while invalidating mapcache! "
" " HWADDR_FMT_plx " -> %p is present \n " ,
reventry - > paddr_index , reventry - > vaddr_req ) ;
trace_xen_invalidate_map_cache ( reventry - > paddr_index ,
reventry - > vaddr_req ) ;
}
for ( i = 0 ; i < mapcache - > nr_buckets ; i + + ) {
@ -562,24 +557,23 @@ static uint8_t *xen_replace_cache_entry_unlocked(hwaddr old_phys_addr,
entry = entry - > next ;
}
if ( ! entry ) {
DPRINTF ( " Trying to update an entry for " HWADDR_FMT_plx \
" that is not in the mapcache! \n " , old_phys_addr ) ;
trace_xen_replace_cache_entry_unlocked ( old_phys_addr ) ;
return NULL ;
}
address_index = new_phys_addr > > MCACHE_BUCKET_SHIFT ;
address_offset = new_phys_addr & ( MCACHE_BUCKET_SIZE - 1 ) ;
fprintf ( stderr , " Replacing a dummy mapcache entry for " HWADDR_FMT_plx \
" with " HWADDR_FMT_plx " \n " , old_phys_addr , new_phys_addr ) ;
trace_xen_replace_cache_entry_dummy ( old_phys_addr , new_phys_addr ) ;
xen_remap_bucket ( entry , entry - > vaddr_base ,
cache_size , address_index , false ) ;
if ( ! test_bits ( address_offset > > XC_PAGE_SHIFT ,
test_bit_size > > XC_PAGE_SHIFT ,
entry - > valid_mapping ) ) {
DPRINTF ( " Unable to update a mapcache entry for " HWADDR_FMT_plx " ! \n " ,
old_phys_addr ) ;
trace_xen_replace_cache_entry_unlocked_could_not_update_entry (
old_phys_addr
) ;
return NULL ;
}