📄 sysdep.h
字号:
# define cpu_to_le32p(addr) (cpu_to_le32(*(addr)))# define cpu_to_be16p(addr) (cpu_to_be16(*(addr)))# define cpu_to_be32p(addr) (cpu_to_be32(*(addr))) extern inline void cpu_to_le16s(__u16 *a) {*a = cpu_to_le16(*a);} extern inline void cpu_to_le32s(__u16 *a) {*a = cpu_to_le32(*a);} extern inline void cpu_to_be16s(__u16 *a) {*a = cpu_to_be16(*a);} extern inline void cpu_to_be32s(__u16 *a) {*a = cpu_to_be32(*a);}# define le16_to_cpup(x) cpu_to_le16p(x)# define le32_to_cpup(x) cpu_to_le32p(x)# define be16_to_cpup(x) cpu_to_be16p(x)# define be32_to_cpup(x) cpu_to_be32p(x)# define le16_to_cpus(x) cpu_to_le16s(x)# define le32_to_cpus(x) cpu_to_le32s(x)# define be16_to_cpus(x) cpu_to_be16s(x)# define be32_to_cpus(x) cpu_to_be32s(x)#endif#ifdef LINUX_20# define __USE_OLD_REBUILD_HEADER__#endif/* * 2.0 didn't include sema_init, so we make our own - but only if it * looks like semaphore.h got included. */#ifdef LINUX_20# ifdef MUTEX_LOCKED /* Only if semaphore.h included */ extern inline void sema_init (struct semaphore *sem, int val) { sem->count = val; sem->waking = sem->lock = 0; sem->wait = NULL; }# endif#endif /* LINUX_20 *//* * In 2.0, there is no real need for spinlocks, and they weren't really * implemented anyway. * * XXX the _irqsave variant should be defined eventually to do the * right thing. */#ifdef LINUX_20typedef int spinlock_t;# define spin_lock(lock)# define spin_unlock(lock)# define spin_lock_init(lock)# define spin_lock_irqsave(lock,flags) do { \ save_flags(flags); cli(); } while (0);# define spin_unlock_irqrestore(lock,flags) restore_flags(flags);#endif/* * 2.1 stuffed the "flush" method into the middle of the file_operations * structure. The FOP_NO_FLUSH symbol is for drivers that do not implement * flush (most of them), it can be inserted in initializers for all 2.x * kernel versions. */#ifdef LINUX_20# define FOP_NO_FLUSH /* nothing */# define TAG_LLSEEK lseek# define TAG_POLL select#else# define FOP_NO_FLUSH NULL,# define TAG_LLSEEK llseek# define TAG_POLL poll#endif/* * fasync changed in 2.2. */#ifdef LINUX_20/* typedef struct inode *fasync_file; */# define fasync_file struct inode *#else typedef int fasync_file;#endif/* kill_fasync had less arguments, and a different indirection in the first */#ifndef LINUX_24# define kill_fasync(ptrptr,sig,band) kill_fasync(*(ptrptr),(sig))#endif/* other things that are virtualized: define the new functions for the old k */#ifdef LINUX_20# define in_interrupt() (intr_count!=0)# define mdelay(x) udelay((x)*1000)# define signal_pending(current) ((current)->signal & ~(current)->blocked)#endif#ifdef LINUX_PCI_H /* only if PCI stuff is being used */# ifdef LINUX_20# include "pci-compat.h" /* a whole set of replacement functions */# else# define pci_release_device(d) /* placeholder, used in 2.0 to free stuff */# endif#endif/* * Some task state stuff */#ifndef set_current_state# define set_current_state(s) current->state = (s);#endif#ifdef LINUX_20extern inline void schedule_timeout(int timeout){ current->timeout = jiffies + timeout; current->state = TASK_INTERRUPTIBLE; schedule(); current->timeout = 0;}extern inline long sleep_on_timeout(wait_queue_head_t *q, signed long timeout){ signed long early = 0; current->timeout = jiffies + timeout; sleep_on (q); if (current->timeout > 0) { early = current->timeout - jiffies; current->timeout = 0; } return early;}extern inline long interruptible_sleep_on_timeout(wait_queue_head_t *q, signed long timeout){ signed long early = 0; current->timeout = jiffies + timeout; interruptible_sleep_on (q); if (current->timeout > 0) { early = current->timeout - jiffies; current->timeout = 0; } return early;}#endif /* LINUX_20 *//* * Schedule_task was a late 2.4 addition. */#ifndef LINUX_24extern inline int schedule_task(struct tq_struct *task){ queue_task(task, &tq_scheduler); return 1;}#endif/* * Timing issues */#ifdef LINUX_20# define get_fast_time do_gettimeofday#endif#ifdef _LINUX_DELAY_H /* only if linux/delay.h is included */# ifndef mdelay /* linux-2.0 */# ifndef MAX_UDELAY_MS# define MAX_UDELAY_MS 5# endif# define mdelay(n) (\ (__builtin_constant_p(n) && (n)<=MAX_UDELAY_MS) ? udelay((n)*1000) : \ ({unsigned long msec=(n); while (msec--) udelay(1000);}))# endif /* mdelay */#endif /* _LINUX_DELAY_H *//* * No del_timer_sync before 2.4 */#ifndef LINUX_24# define del_timer_sync(timer) del_timer(timer) /* and hope */#endif/* * mod_timer wasn't present in 2.0 */#ifdef LINUX_20static inline int mod_timer(struct timer_list *timer, unsigned long expires){ int pending = del_timer(timer); if (pending) { timer->expires = expires; add_timer(timer); } return pending;}#endif/* * Various changes in mmap and friends. */#ifndef NOPAGE_SIGBUS# define NOPAGE_SIGBUS NULL /* return value of the nopage memory method */# define NOPAGE_OOM NULL /* No real equivalent in older kernels */#endif#ifndef VM_RESERVED /* Added 2.4.0-test10 */# define VM_RESERVED 0#endif#ifdef LINUX_24 /* use "vm_pgoff" to get an offset */#define VMA_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)#else /* use "vm_offset" */#define VMA_OFFSET(vma) ((vma)->vm_offset)#endif#ifdef MAP_NR#define virt_to_page(page) (mem_map + MAP_NR(page))#endif#ifndef get_page# define get_page(p) atomic_inc(&(p)->count)#endif/* * No DMA lock in 2.0. */#ifdef LINUX_20static inline unsigned long claim_dma_lock(void){ unsigned long flags; save_flags(flags); cli(); return flags;}static inline void release_dma_lock(unsigned long flags){ restore_flags(flags);}#endif/* * I/O memory was not managed by ealier kernels, define them as success */#if 0 /* FIXME: what is the right way to do request_mem_region? */#ifndef LINUX_24# define check_mem_region(start, len) 0# define request_mem_region(start, len, name) 0# define release_mem_region(start, len) 0 /* * Also, request_ and release_ region used to return void. Return 0 instead */# define request_region(s, l, n) ({request_region((s),(l),(n));0;})# define release_region(s, l) ({release_region((s),(l));0;})#endif /* not LINUX_24 */#endif/* * Block layer stuff. */#ifndef LINUX_24/* BLK_DEFAULT_QUEUE for use with these macros only!!!! */#define BLK_DEFAULT_QUEUE(major) blk_dev[(major)].request_fn#define blk_init_queue(where,request_fn) where = request_fn;#define blk_cleanup_queue(where) where = NULL;/* No QUEUE_EMPTY in older kernels */#ifndef QUEUE_EMPTY /* Driver can redefine it too */# define QUEUE_EMPTY (CURRENT != NULL)#endif#ifdef RO_IOCTLSstatic inline int blk_ioctl(kdev_t dev, unsigned int cmd, unsigned long arg){ int err; switch (cmd) { case BLKRAGET: /* return the readahead value */ if (!arg) return -EINVAL; err = ! access_ok(VERIFY_WRITE, arg, sizeof(long)); if (err) return -EFAULT; PUT_USER(read_ahead[MAJOR(dev)],(long *) arg); return 0; case BLKRASET: /* set the readahead value */ if (!capable(CAP_SYS_ADMIN)) return -EACCES; if (arg > 0xff) return -EINVAL; /* limit it */ read_ahead[MAJOR(dev)] = arg; return 0; case BLKFLSBUF: /* flush */ if (! capable(CAP_SYS_ADMIN)) return -EACCES; /* only root */ fsync_dev(dev); invalidate_buffers(dev); return 0; RO_IOCTLS(dev, arg); } return -ENOTTY;}#endif /* RO_IOCTLS */#ifdef LINUX_EXTENDED_PARTITION /* defined in genhd.h */static inline void register_disk(struct gendisk *gdev, kdev_t dev, unsigned minors, struct file_operations *ops, long size){ if (! gdev) return; resetup_one_dev(gdev, MINOR(dev) >> gdev->minor_shift);}#endif /* LINUX_EXTENDED_PARTITION */#else /* it is Linux 2.4 */#define HAVE_BLKPG_H#endif /* LINUX_24 */#ifdef LINUX_20 /* physical and virtual addresses had the same value */# define __pa(a) (a)# define __va(a) (a)#endif/* * Network driver compatibility *//* * 2.0 dev_kfree_skb had an extra arg. The following is a little dangerous * in that it assumes that FREE_WRITE is always wanted. Very few 2.0 drivers * use FREE_READ, but the number is *not* zero... * * Also: implement the non-checking versions of a couple skb functions - * but they still check in 2.0. */#ifdef LINUX_20# define dev_kfree_skb(skb) dev_kfree_skb((skb), FREE_WRITE);# define __skb_push(skb, len) skb_push((skb), (len))# define __skb_put(skb, len) skb_put((skb), (len))#endif/* * Softnet changes in 2.4 */#ifndef LINUX_24# ifdef _LINUX_NETDEVICE_H /* only if netdevice.h was included */# define netif_start_queue(dev) clear_bit(0, (void *) &(dev)->tbusy);# define netif_stop_queue(dev) set_bit(0, (void *) &(dev)->tbusy);static inline void netif_wake_queue(struct device *dev){ clear_bit(0, (void *) &(dev)->tbusy); mark_bh(NET_BH);}/* struct device became struct net_device */# define net_device device# endif /* netdevice.h */#endif /* ! LINUX_24 *//* * Memory barrier stuff, define what's missing from older kernel versions */#ifdef switch_to /* this is always a macro, defined in <asm/sysstem.h> */# ifndef set_mb# define set_mb(var, value) do {(var) = (value); mb();} while 0# endif# ifndef set_rmb# define set_rmb(var, value) do {(var) = (value); rmb();} while 0# endif# ifndef set_wmb# define set_wmb(var, value) do {(var) = (value); wmb();} while 0# endif/* The hw barriers are defined as sw barriers. A correct thing if this specific kernel/platform is supported but has no specific instruction */# ifndef mb# define mb barrier# endif# ifndef rmb# define rmb barrier# endif# ifndef wmb# define wmb barrier# endif#endif /* switch to (i.e. <asm/system.h>) */#endif /* _SYSDEP_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -