Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding fix #1519

Merged
merged 2 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/arch/arm/mm/core_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,17 @@ int core_va2pa_helper(void *va, paddr_t *pa)
if (!va_is_in_map(map, (vaddr_t)va))
return -1;

*pa = ((uintptr_t)va & (map->region_size - 1)) |
((map->pa + (uintptr_t)va - map->va) & ~(map->region_size - 1));
*pa = map->pa + (vaddr_t)va - map->va;

return 0;
}

static void *map_pa2va(struct tee_mmap_region *map, paddr_t pa)
{
if (!pa_is_in_map(map, pa))
return NULL;
return (void *)((pa & (map->region_size - 1)) |
((map->va + pa - map->pa) & ~((vaddr_t)map->region_size - 1)));

return (void *)(map->va + pa - map->pa);
}

/*
Expand Down
5 changes: 3 additions & 2 deletions lib/libutils/ext/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

/* Round up the even multiple of size, size has to be a multiple of 2 */
#define ROUNDUP(v, size) (((v) + ((size) - 1)) & ~((size) - 1))
#define ROUNDUP(v, size) (((v) + ((__typeof__(v))(size) - 1)) & \
~((__typeof__(v))(size) - 1))

/* Round down the even multiple of size, size has to be a multiple of 2 */
#define ROUNDDOWN(v, size) ((v) & ~((size) - 1))
#define ROUNDDOWN(v, size) ((v) & ~((__typeof__(v))(size) - 1))

/* x has to be of an unsigned type */
#define IS_POWER_OF_TWO(x) (((x) != 0) && (((x) & (~(x) + 1)) == (x)))
Expand Down