1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-20 11:11:24 +00:00

Merge LinuxKPI changes from DragonflyBSD:

- Redefine DIV_ROUND_UP as a function macro taking two arguments
  instead of none.
- Implement more Linux kernel functions related to various forms
  of DELAY() and basic mathematical operations.

Sponsored by:	Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2015-10-19 12:44:41 +00:00
parent e490164bee
commit 2ca3cc5132
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=289580
2 changed files with 59 additions and 6 deletions

View File

@ -2,7 +2,8 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
* Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
* Copyright (c) 2014 François Tigeot
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,6 +32,7 @@
#define _LINUX_DELAY_H_
#include <linux/jiffies.h>
#include <sys/systm.h>
static inline void
linux_msleep(int ms)
@ -41,4 +43,25 @@ linux_msleep(int ms)
#undef msleep
#define msleep linux_msleep
#define udelay(t) DELAY(t)
static inline void
mdelay(unsigned long msecs)
{
while (msecs--)
DELAY(1000);
}
static inline void
ndelay(unsigned long x)
{
DELAY(howmany(x, 1000));
}
static inline void
usleep_range(unsigned long min, unsigned long max)
{
DELAY(min);
}
#endif /* _LINUX_DELAY_H_ */

View File

@ -2,7 +2,8 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
* Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
* Copyright (c) 2014-2015 François Tigeot
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -69,7 +70,8 @@
#define ALIGN(x, y) roundup2((x), (y))
#undef PTR_ALIGN
#define PTR_ALIGN(p, a) ((__typeof(p))ALIGN((uintptr_t)(p), (a)))
#define DIV_ROUND_UP howmany
#define DIV_ROUND_UP(x, n) howmany(x, n)
#define DIV_ROUND_UP_ULL(x, n) DIV_ROUND_UP((unsigned long long)(x), (n))
#define FIELD_SIZEOF(t, f) sizeof(((t *)0)->f)
#define printk(X...) printf(X)
@ -90,9 +92,6 @@
({ if (0) log(LOG_DEBUG, pr_fmt(fmt), ##__VA_ARGS__); 0; })
#endif
#define udelay(t) DELAY(t)
#define usleep_range(min,max) DELAY(min)
#ifndef pr_fmt
#define pr_fmt(fmt) fmt
#endif
@ -164,9 +163,16 @@
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b,c))
#define min_t(type, _x, _y) ((type)(_x) < (type)(_y) ? (type)(_x) : (type)(_y))
#define max_t(type, _x, _y) ((type)(_x) > (type)(_y) ? (type)(_x) : (type)(_y))
#define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
#define clamp(x, lo, hi) min( max(x,lo), hi)
/*
* This looks more complex than it should be. But we need to
* get the type for the ~ right in round_down (it needs to be
@ -184,4 +190,28 @@ typedef struct pm_message {
int event;
} pm_message_t;
/* Swap values of a and b */
#define swap(a, b) do { \
typeof(a) _swap_tmp = a; \
a = b; \
b = _swap_tmp; \
} while (0)
#define DIV_ROUND_CLOSEST(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
static inline uintmax_t
mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor)
{
uintmax_t q = (x / divisor);
uintmax_t r = (x % divisor);
return ((q * multiplier) + ((r * multiplier) / divisor));
}
static inline int64_t
abs64(int64_t x)
{
return (x < 0 ? -x : x);
}
#endif /* _LINUX_KERNEL_H_ */