1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
/*
* EFI Boot Guard
*
* Copyright (c) Siemens AG, 2023
*
* Author: Michael Adler <michael.adler@siemens.com>
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
/* Utility functions taken from the Linux kernel */
#define le16_to_cpu __le16_to_cpu
#define le32_to_cpu __le32_to_cpu
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
static inline uint16_t __get_unaligned_le16(const uint8_t *p)
{
return p[0] | p[1] << 8;
}
static inline uint16_t get_unaligned_le16(const void *p)
{
return __get_unaligned_le16((const uint8_t *)p);
}
static inline u32 __get_unaligned_le32(const u8 *p)
{
return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
}
static inline u32 get_unaligned_le32(const void *p)
{
return __get_unaligned_le32(p);
}
/**
* is_power_of_2() - check if a value is a power of two
* @n: the value to check
*
* Determine whether some value is a power of two, where zero is
* *not* considered a power of two.
* Return: true if @n is a power of 2, otherwise false.
*/
static inline __attribute__((const))
bool is_power_of_2(unsigned long n)
{
return (n != 0 && ((n & (n - 1)) == 0));
}
|