Path: blob/main/sys/compat/linuxkpi/common/include/linux/delay.h
39604 views
/*-1* Copyright (c) 2010 Isilon Systems, Inc.2* Copyright (c) 2010 iX Systems, Inc.3* Copyright (c) 2010 Panasas, Inc.4* Copyright (c) 2013-2021 Mellanox Technologies, Ltd.5* Copyright (c) 2014 François Tigeot6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice unmodified, this list of conditions, and the following13* disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR19* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES20* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.21* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,22* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT23* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF27* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28*/29#ifndef _LINUXKPI_LINUX_DELAY_H_30#define _LINUXKPI_LINUX_DELAY_H_3132#include <linux/jiffies.h>33#include <sys/systm.h>3435static inline void36linux_msleep(unsigned int ms)37{38/* guard against invalid values */39if (ms == 0)40ms = 1;41pause_sbt("lnxsleep", mstosbt(ms), 0, C_HARDCLOCK);42}4344#undef msleep45#define msleep(ms) linux_msleep(ms)4647#undef msleep_interruptible48#define msleep_interruptible(ms) linux_msleep_interruptible(ms)4950#define udelay(t) DELAY(t)5152static inline void53mdelay(unsigned long msecs)54{55while (msecs--)56DELAY(1000);57}5859static inline void60ndelay(unsigned long x)61{62DELAY(howmany(x, 1000));63}6465static inline void66usleep_range(unsigned long min, unsigned long max)67{68/* guard against invalid values */69if (min == 0)70min = 1;71pause_sbt("lnxsleep", ustosbt(min), 0, C_HARDCLOCK);72}7374extern unsigned int linux_msleep_interruptible(unsigned int ms);7576static inline void77fsleep(unsigned long us)78{7980if (us < 10)81udelay(us);82else83usleep_range(us, us);84}8586#endif /* _LINUXKPI_LINUX_DELAY_H_ */878889