Add a type-considerate ALIGN[_UP] macro to libcflat, and apply it to /lib code that can make use of it. This will be used to fix PAGE_ALIGN on arm, which can be used on phys_addr_t addresses, which may exceed 32 bits. Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx> --- lib/alloc.c | 4 +--- lib/asm-generic/page.h | 9 ++++++--- lib/libcflat.h | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/alloc.c b/lib/alloc.c index 5d55e285dcd1d..1abe4961ae9dd 100644 --- a/lib/alloc.c +++ b/lib/alloc.c @@ -7,8 +7,6 @@ #include "asm/spinlock.h" #include "asm/io.h" -#define ALIGN_UP_MASK(x, mask) (((x) + (mask)) & ~(mask)) -#define ALIGN_UP(x, a) ALIGN_UP_MASK(x, (typeof(x))(a) - 1) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) @@ -70,7 +68,7 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size, spin_lock(&lock); - addr = ALIGN_UP(base, align); + addr = ALIGN(base, align); size += addr - base; if ((top_safe - base) < size) { diff --git a/lib/asm-generic/page.h b/lib/asm-generic/page.h index 559938fcf0b3f..8602752002f71 100644 --- a/lib/asm-generic/page.h +++ b/lib/asm-generic/page.h @@ -16,13 +16,16 @@ #define PAGE_SIZE (1 << PAGE_SHIFT) #endif #define PAGE_MASK (~(PAGE_SIZE-1)) -#define PAGE_ALIGN(addr) (((addr) + (PAGE_SIZE-1)) & PAGE_MASK) #ifndef __ASSEMBLY__ + +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) + #define __va(x) ((void *)((unsigned long) (x))) #define __pa(x) ((unsigned long) (x)) #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) #define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) -#endif -#endif +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_GENERIC_PAGE_H_ */ diff --git a/lib/libcflat.h b/lib/libcflat.h index a43eba0329f8e..7db29a4f4f3cb 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -30,6 +30,10 @@ #define xstr(s) xxstr(s) #define xxstr(s) #s +#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define __ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1) +#define ALIGN(x, a) __ALIGN((x), (a)) + typedef uint8_t u8; typedef int8_t s8; typedef uint16_t u16; -- 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html