x86: Add a function to find the size of an mrccache record
authorSimon Glass <sjg@chromium.org>
Wed, 25 Sep 2019 14:57:04 +0000 (08:57 -0600)
committerBin Meng <bmeng.cn@gmail.com>
Fri, 11 Oct 2019 09:37:19 +0000 (17:37 +0800)
Move the code to determine the size of a cache record into a function so
we can use it elsewhere in this file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/x86/lib/mrccache.c

index be107627b8000b8a677c7ea122d1772e94bf1fb6..33bb52039bda590624dfe4b7e6a553f744bb5173 100644 (file)
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static uint mrc_block_size(uint data_size)
+{
+       uint mrc_size = sizeof(struct mrc_data_container) + data_size;
+
+       return ALIGN(mrc_size, MRC_DATA_ALIGN);
+}
+
 static struct mrc_data_container *next_mrc_block(
        struct mrc_data_container *cache)
 {
        /* MRC data blocks are aligned within the region */
-       u32 mrc_size = sizeof(*cache) + cache->data_size;
        u8 *region_ptr = (u8 *)cache;
 
-       if (mrc_size & (MRC_DATA_ALIGN - 1UL)) {
-               mrc_size &= ~(MRC_DATA_ALIGN - 1UL);
-               mrc_size += MRC_DATA_ALIGN;
-       }
-
-       region_ptr += mrc_size;
+       region_ptr += mrc_block_size(cache->data_size);
 
        return (struct mrc_data_container *)region_ptr;
 }