3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
18 #ifndef __TIMSKMOD_H__
19 #define __TIMSKMOD_H__
21 #include <linux/version.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/device.h>
25 #include <linux/kobject.h>
26 #include <linux/sysfs.h>
28 #include <linux/string.h>
29 #include <linux/sched.h>
30 #include <linux/spinlock.h>
31 #include <linux/slab.h>
32 #include <linux/errno.h>
33 #include <linux/interrupt.h>
34 #include <linux/wait.h>
35 #include <linux/vmalloc.h>
36 #include <linux/proc_fs.h>
37 #include <linux/cdev.h>
38 #include <linux/types.h>
42 #include <linux/uaccess.h>
43 #include <linux/list.h>
44 #include <linux/poll.h>
45 /* #define EXPORT_SYMTAB */
46 #include <linux/module.h>
47 #include <linux/moduleparam.h>
48 #include <linux/fcntl.h>
49 #include <linux/workqueue.h>
50 #include <linux/kthread.h>
51 #include <linux/seq_file.h>
63 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
64 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
65 #define STRUCTSEQUAL(x, y) (memcmp(&x, &y, sizeof(x)) == 0)
67 #define HOSTADDRESS unsigned long long
70 #define sizeofmember(TYPE, MEMBER) (sizeof(((TYPE *)0)->MEMBER))
71 /** "Covered quotient" function */
72 #define COVQ(v, d) (((v) + (d) - 1) / (d))
73 #define SWAPPOINTERS(p1, p2) \
75 void *SWAPPOINTERS_TEMP = (void *)p1; \
76 (void *)(p1) = (void *)(p2); \
77 (void *)(p2) = SWAPPOINTERS_TEMP; \
80 #define WARNDRV(fmt, args...) LOGWRN(fmt, ## args)
81 #define SECUREDRV(fmt, args...) LOGWRN(fmt, ## args)
83 #define PRINTKDEV(devname, fmt, args...) LOGINFDEV(devname, fmt, ## args)
84 #define TBDDEV(devname, fmt, args...) LOGERRDEV(devname, fmt, ## args)
85 #define HUHDEV(devname, fmt, args...) LOGERRDEV(devname, fmt, ## args)
86 #define ERRDEV(devname, fmt, args...) LOGERRDEV(devname, fmt, ## args)
87 #define ERRDEVX(devno, fmt, args...) LOGERRDEVX(devno, fmt, ## args)
88 #define WARNDEV(devname, fmt, args...) LOGWRNDEV(devname, fmt, ## args)
89 #define SECUREDEV(devname, fmt, args...) LOGWRNDEV(devname, fmt, ## args)
90 #define INFODEV(devname, fmt, args...) LOGINFDEV(devname, fmt, ## args)
91 #define INFODEVX(devno, fmt, args...) LOGINFDEVX(devno, fmt, ## args)
93 /** Verifies the consistency of your PRIVATEDEVICEDATA structure using
94 * conventional "signature" fields:
96 * - sig1 should contain the size of the structure
97 * - sig2 should contain a pointer to the beginning of the structure
99 #define DDLOOKSVALID(dd) \
101 ((dd)->sig1 == sizeof(PRIVATEDEVICEDATA)) && \
104 /** Verifies the consistency of your PRIVATEFILEDATA structure using
105 * conventional "signature" fields:
107 * - sig1 should contain the size of the structure
108 * - sig2 should contain a pointer to the beginning of the structure
110 #define FDLOOKSVALID(fd) \
112 ((fd)->sig1 == sizeof(PRIVATEFILEDATA)) && \
115 /** Sleep for an indicated number of seconds (for use in kernel mode).
116 * x - the number of seconds to sleep.
119 do { __set_current_state(TASK_INTERRUPTIBLE); \
120 schedule_timeout((x)*HZ); \
123 /** Sleep for an indicated number of jiffies (for use in kernel mode).
124 * x - the number of jiffies to sleep.
126 #define SLEEPJIFFIES(x) \
127 do { __set_current_state(TASK_INTERRUPTIBLE); \
128 schedule_timeout(x); \
131 static inline struct cdev *cdev_alloc_init(struct module *owner,
132 const struct file_operations *fops)
134 struct cdev *cdev = NULL;
142 /* Note that the memory allocated for cdev will be deallocated
143 * when the usage count drops to 0, because it is controlled
144 * by a kobject of type ktype_cdev_dynamic. (This
145 * deallocation could very well happen outside of our kernel
146 * module, like via the cdev_put in __fput() for example.)
151 extern int unisys_spar_platform;