From de5bd8300eb38c4cb24ea17a72dbcf39b0aa6474 Mon Sep 17 00:00:00 2001
From: Mitchel Humpherys <mitchelh@codeaurora.org>
Date: Fri, 6 Nov 2015 17:04:08 -0800
Subject: [PATCH] lrdp-v2: bitops: Add align function

Aligning addresses is a handy thing to do when working with memory maps,
etc.  Add an `align' function to the bitops module for this purpose.

Change-Id: I582e8c763119d13b718146f4ff837bfa75e9aa01
---
 linux-ramdump-parser-v2/bitops.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/linux-ramdump-parser-v2/bitops.py b/linux-ramdump-parser-v2/bitops.py
index 4f9da69..ab1901a 100644
--- a/linux-ramdump-parser-v2/bitops.py
+++ b/linux-ramdump-parser-v2/bitops.py
@@ -9,6 +9,8 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
+import ctypes
+
 
 def bm(msb, lsb):
     'Creates a bitmask from msb to lsb'
@@ -25,3 +27,10 @@ def is_set(val, bit):
     if (val >> bit) & 0x1:
         return True
     return False
+
+
+def align(x, a):
+    """Round x up to the nearest multiple of a"""
+    # See include/uapi/linux/kernel.h
+    notmask = ctypes.c_uint64(~(a - 1)).value
+    return (x + a - 1) & notmask
-- 
GitLab