blob: 1cae854df15953b020fbdefb5b29387711d40d51 [file] [log] [blame]
developer8d16ac22021-05-26 15:32:12 +08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
4 *
5 * OS-dependent definitions for NAND Mapped-block Management (NMBM)
6 *
7 * Author: Weijie Gao <weijie.gao@mediatek.com>
8 */
9
10#ifndef _NMBM_OS_H_
11#define _NMBM_OS_H_
12
13#include <linux/kernel.h>
14#include <linux/limits.h>
15#include <linux/string.h>
16#include <linux/errno.h>
17#include <linux/types.h>
18#include <linux/crc32.h>
19#include <linux/log2.h>
20#include <asm/div64.h>
21
22static inline uint32_t nmbm_crc32(uint32_t crcval, const void *buf, size_t size)
23{
24 uint chksz;
25 const unsigned char *p = buf;
26
27 while (size) {
28 if (size > UINT_MAX)
29 chksz = UINT_MAX;
30 else
31 chksz = (uint)size;
32
33 crcval = crc32_le(crcval, p, chksz);
34 size -= chksz;
35 p += chksz;
36 }
37
38 return crcval;
39}
40
41static inline uint32_t nmbm_lldiv(uint64_t dividend, uint32_t divisor)
42{
43#if BITS_PER_LONG == 64
44 return dividend / divisor;
45#else
46 do_div(dividend, divisor);
47 return dividend;
48#endif
49}
50
51#define WATCHDOG_RESET()
52
53#ifdef CONFIG_NMBM_LOG_LEVEL_DEBUG
54#define NMBM_DEFAULT_LOG_LEVEL 0
55#elif defined(NMBM_LOG_LEVEL_INFO)
56#define NMBM_DEFAULT_LOG_LEVEL 1
57#elif defined(NMBM_LOG_LEVEL_WARN)
58#define NMBM_DEFAULT_LOG_LEVEL 2
59#elif defined(NMBM_LOG_LEVEL_ERR)
60#define NMBM_DEFAULT_LOG_LEVEL 3
61#elif defined(NMBM_LOG_LEVEL_EMERG)
62#define NMBM_DEFAULT_LOG_LEVEL 4
63#elif defined(NMBM_LOG_LEVEL_NONE)
64#define NMBM_DEFAULT_LOG_LEVEL 5
65#else
66#define NMBM_DEFAULT_LOG_LEVEL 1
67#endif
68
69#endif /* _NMBM_OS_H_ */