refactor(lib): define GRANULE_SHIFT as parameter

GRANULE_SHIFT is defined as build time parameter instead of
GRANULE_SIZE. This makes it possible to derive GRANULE_SIZE and
GRANULE_MASK from a single value.

Change-Id: I8e6a7aa148aade9921b062702b24111d96107dbf
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/cmake/CommonConfigs.cmake b/cmake/CommonConfigs.cmake
index b8709ac..7e1e9a4 100644
--- a/cmake/CommonConfigs.cmake
+++ b/cmake/CommonConfigs.cmake
@@ -16,10 +16,10 @@
 # The RMM is mapped with 4K pages, and all RMM APIs use the same granularity.
 #
 arm_config_option(
-    NAME GRANULE_SIZE
-    HELP "Granule Size used by RMM"
+    NAME GRANULE_SHIFT
+    HELP "The shift value of granule size. i.e: GRANULE_SIZE == 1 << GRANULE_SHIFT"
     TYPE STRING
-    DEFAULT 4096)
+    DEFAULT 12)
 
 #
 # RMM_MAX_GRANULES. Maximum number of granules supported.
@@ -69,12 +69,12 @@
 target_compile_definitions(rmm-common
     INTERFACE "MAX_CPUS=${MAX_CPUS}U")
 
-if(NOT(GRANULE_SIZE EQUAL 4096))
-    message(FATAL_ERROR "GRANULE_SIZE is not initialized correctly")
+if(NOT(GRANULE_SHIFT EQUAL 12))
+    message(FATAL_ERROR "GRANULE_SHIFT is not initialized correctly")
 endif()
 
 target_compile_definitions(rmm-common
-    INTERFACE "GRANULE_SIZE=UL(${GRANULE_SIZE})")
+    INTERFACE "GRANULE_SHIFT=U(${GRANULE_SHIFT})")
 
 if (RMM_MAX_GRANULES EQUAL 0x0)
     message (FATAL_ERROR "RMM_MAX_GRANULES not configured")
diff --git a/docs/getting_started/build-options.rst b/docs/getting_started/build-options.rst
index b863cd5..d4fe338 100644
--- a/docs/getting_started/build-options.rst
+++ b/docs/getting_started/build-options.rst
@@ -229,7 +229,7 @@
    RMM_ARCH			,aarch64 | fake_host	,aarch64		,"Target Architecture for RMM build"
    RMM_MAX_SIZE			,			,0x0			,"Maximum size for RMM image"
    MAX_CPUS			,			,16			,"Maximum number of CPUs supported by RMM"
-   GRANULE_SIZE			,			,4096			,"Granule Size used by RMM"
+   GRANULE_SHIFT		,			,12			,"Granule Shift used by RMM"
    RMM_DOCS			,ON | OFF		,OFF			,"RMM Documentation build"
    CMAKE_BUILD_TYPE		,Debug | Release	,Release		,"CMake Build type"
    CMAKE_CONFIGURATION_TYPES	,Debug & Release	,Debug & Release	,"Multi-generator configuration types"
diff --git a/lib/common/include/utils_def.h b/lib/common/include/utils_def.h
index 267f8b1..5569675 100644
--- a/lib/common/include/utils_def.h
+++ b/lib/common/include/utils_def.h
@@ -135,8 +135,9 @@
 			(((uintptr_t)_addr >= (uintptr_t)&_array[0]) && \
 			 ((((uintptr_t)_addr - (uintptr_t)&_array[0]) % \
 						sizeof(_array[0])) == UL(0)))
-#define GRANULE_SHIFT	(U(12))
-#define GRANULE_MASK	(~0xfffUL)
+
+#define GRANULE_SIZE	(UL(1) << GRANULE_SHIFT)
+#define GRANULE_MASK	(~(GRANULE_SIZE - 1U))
 
 #define HAS_MPAM 0
 
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
index 14cdd37..51352d6 100644
--- a/runtime/CMakeLists.txt
+++ b/runtime/CMakeLists.txt
@@ -85,7 +85,7 @@
         PROPERTIES COMPILE_DEFINITIONS "__LINKER__")
 
     set_property(TARGET rmm-runtime-lds APPEND
-        PROPERTY COMPILE_DEFINITIONS "GRANULE_SIZE=UL(${GRANULE_SIZE})")
+        PROPERTY COMPILE_DEFINITIONS "GRANULE_SHIFT=U(${GRANULE_SHIFT})")
 
     set_property(TARGET rmm-runtime-lds APPEND
         PROPERTY COMPILE_DEFINITIONS "MAX_CPUS=UL(${MAX_CPUS})")