4019a0d63645fe53380caec301679a68f9979e87
[sfrench/cifs-2.6.git] / drivers / staging / unisys / include / timskmod.h
1 /* timskmod.h
2  *
3  * Copyright (C) 2010 - 2013 UNISYS CORPORATION
4  * All rights reserved.
5  *
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.
10  *
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
15  * details.
16  */
17
18 #ifndef __TIMSKMOD_H__
19 #define __TIMSKMOD_H__
20
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>
27 #include <linux/fs.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>
39 #include <asm/irq.h>
40 #include <linux/io.h>
41 #include <asm/dma.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/aio.h>
50 #include <linux/workqueue.h>
51 #include <linux/kthread.h>
52 #include <linux/seq_file.h>
53 #include <linux/mm.h>
54
55 /* #define DEBUG */
56 #ifndef BOOL
57 #define BOOL    int
58 #endif
59 #define FALSE   0
60 #define TRUE    1
61 #if !defined SUCCESS
62 #define SUCCESS 0
63 #endif
64 #define MIN(a, b)     (((a) < (b)) ? (a) : (b))
65 #define MAX(a, b)     (((a) > (b)) ? (a) : (b))
66 #define STRUCTSEQUAL(x, y) (memcmp(&x, &y, sizeof(x)) == 0)
67 #ifndef HOSTADDRESS
68 #define HOSTADDRESS unsigned long long
69 #endif
70
71 /** Try to evaulate the provided expression, and do a RETINT(x) iff
72  *  the expression evaluates to < 0.
73  */
74 #define ASSERT(cond)                                           \
75         do { if (!(cond))                                      \
76                         HUHDRV("ASSERT failed - %s",           \
77                                __stringify(cond));             \
78         } while (0)
79
80 #define sizeofmember(TYPE, MEMBER) (sizeof(((TYPE *)0)->MEMBER))
81 /** "Covered quotient" function */
82 #define COVQ(v, d)  (((v) + (d) - 1) / (d))
83 #define SWAPPOINTERS(p1, p2)                            \
84         do {                                            \
85                 void *SWAPPOINTERS_TEMP = (void *)p1;   \
86                 (void *)(p1) = (void *)(p2);            \
87                 (void *)(p2) = SWAPPOINTERS_TEMP;       \
88         } while (0)
89
90 #define PRINTKDRV(fmt, args...) LOGINF(fmt, ## args)
91 #define TBDDRV(fmt, args...)    LOGERR(fmt, ## args)
92 #define HUHDRV(fmt, args...)    LOGERR(fmt, ## args)
93 #define ERRDRV(fmt, args...)    LOGERR(fmt, ## args)
94 #define WARNDRV(fmt, args...)   LOGWRN(fmt, ## args)
95 #define SECUREDRV(fmt, args...) LOGWRN(fmt, ## args)
96 #define INFODRV(fmt, args...)   LOGINF(fmt, ## args)
97 #define DEBUGDRV(fmt, args...)  DBGINF(fmt, ## args)
98
99 #define PRINTKDEV(devname, fmt, args...)  LOGINFDEV(devname, fmt, ## args)
100 #define TBDDEV(devname, fmt, args...)     LOGERRDEV(devname, fmt, ## args)
101 #define HUHDEV(devname, fmt, args...)     LOGERRDEV(devname, fmt, ## args)
102 #define ERRDEV(devname, fmt, args...)     LOGERRDEV(devname, fmt, ## args)
103 #define ERRDEVX(devno, fmt, args...)      LOGERRDEVX(devno, fmt, ## args)
104 #define WARNDEV(devname, fmt, args...)    LOGWRNDEV(devname, fmt, ## args)
105 #define SECUREDEV(devname, fmt, args...)  LOGWRNDEV(devname, fmt, ## args)
106 #define INFODEV(devname, fmt, args...)    LOGINFDEV(devname, fmt, ## args)
107 #define INFODEVX(devno, fmt, args...)     LOGINFDEVX(devno, fmt, ## args)
108 #define DEBUGDEV(devname, fmt, args...)   DBGINFDEV(devname, fmt, ## args)
109
110 /** Verifies the consistency of your PRIVATEDEVICEDATA structure using
111  *  conventional "signature" fields:
112  *  <p>
113  *  - sig1 should contain the size of the structure
114  *  - sig2 should contain a pointer to the beginning of the structure
115  */
116 #define DDLOOKSVALID(dd)                                 \
117                 ((dd != NULL)                             &&    \
118                  ((dd)->sig1 == sizeof(PRIVATEDEVICEDATA)) &&   \
119                  ((dd)->sig2 == dd))
120
121 /** Verifies the consistency of your PRIVATEFILEDATA structure using
122  *  conventional "signature" fields:
123  *  <p>
124  *  - sig1 should contain the size of the structure
125  *  - sig2 should contain a pointer to the beginning of the structure
126  */
127 #define FDLOOKSVALID(fd)                               \
128         ((fd != NULL)                           &&     \
129          ((fd)->sig1 == sizeof(PRIVATEFILEDATA)) &&    \
130          ((fd)->sig2 == fd))
131
132 /** Sleep for an indicated number of seconds (for use in kernel mode).
133  *  x - the number of seconds to sleep.
134  */
135 #define SLEEP(x)                                             \
136         do { __set_current_state(TASK_INTERRUPTIBLE);        \
137                 schedule_timeout((x)*HZ);                    \
138         } while (0)
139
140 /** Sleep for an indicated number of jiffies (for use in kernel mode).
141  *  x - the number of jiffies to sleep.
142  */
143 #define SLEEPJIFFIES(x)                                             \
144         do { __set_current_state(TASK_INTERRUPTIBLE);               \
145                 schedule_timeout(x);                                \
146         } while (0)
147
148 static inline struct cdev *cdev_alloc_init(struct module *owner,
149                                            const struct file_operations *fops)
150 {
151         struct cdev *cdev = NULL;
152
153         cdev = cdev_alloc();
154         if (!cdev)
155                 return NULL;
156         cdev->ops = fops;
157         cdev->owner = owner;
158
159         /* Note that the memory allocated for cdev will be deallocated
160          * when the usage count drops to 0, because it is controlled
161          * by a kobject of type ktype_cdev_dynamic.  (This
162          * deallocation could very well happen outside of our kernel
163          * module, like via the cdev_put in __fput() for example.)
164          */
165         return cdev;
166 }
167
168 extern int unisys_spar_platform;
169
170 #endif