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/workqueue.h>
50 #include <linux/kthread.h>
51 #include <linux/seq_file.h>
52 #include <linux/mm.h>
53
54 /* #define DEBUG */
55 #ifndef BOOL
56 #define BOOL int
57 #endif
58 #define FALSE 0
59 #define TRUE 1
60 #if !defined SUCCESS
61 #define SUCCESS 0
62 #endif
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)
66 #ifndef HOSTADDRESS
67 #define HOSTADDRESS unsigned long long
68 #endif
69
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) \
74 do { \
75 void *SWAPPOINTERS_TEMP = (void *)p1; \
76 (void *)(p1) = (void *)(p2); \
77 (void *)(p2) = SWAPPOINTERS_TEMP; \
78 } while (0)
79
80 #define WARNDRV(fmt, args...) LOGWRN(fmt, ## args)
81 #define SECUREDRV(fmt, args...) LOGWRN(fmt, ## args)
82
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)
92
93 /** Verifies the consistency of your PRIVATEDEVICEDATA structure using
94 * conventional "signature" fields:
95 * <p>
96 * - sig1 should contain the size of the structure
97 * - sig2 should contain a pointer to the beginning of the structure
98 */
99 #define DDLOOKSVALID(dd) \
100 ((dd != NULL) && \
101 ((dd)->sig1 == sizeof(PRIVATEDEVICEDATA)) && \
102 ((dd)->sig2 == dd))
103
104 /** Verifies the consistency of your PRIVATEFILEDATA structure using
105 * conventional "signature" fields:
106 * <p>
107 * - sig1 should contain the size of the structure
108 * - sig2 should contain a pointer to the beginning of the structure
109 */
110 #define FDLOOKSVALID(fd) \
111 ((fd != NULL) && \
112 ((fd)->sig1 == sizeof(PRIVATEFILEDATA)) && \
113 ((fd)->sig2 == fd))
114
115 /** Sleep for an indicated number of seconds (for use in kernel mode).
116 * x - the number of seconds to sleep.
117 */
118 #define SLEEP(x) \
119 do { __set_current_state(TASK_INTERRUPTIBLE); \
120 schedule_timeout((x)*HZ); \
121 } while (0)
122
123 /** Sleep for an indicated number of jiffies (for use in kernel mode).
124 * x - the number of jiffies to sleep.
125 */
126 #define SLEEPJIFFIES(x) \
127 do { __set_current_state(TASK_INTERRUPTIBLE); \
128 schedule_timeout(x); \
129 } while (0)
130
cdev_alloc_init(struct module * owner,const struct file_operations * fops)131 static inline struct cdev *cdev_alloc_init(struct module *owner,
132 const struct file_operations *fops)
133 {
134 struct cdev *cdev = NULL;
135
136 cdev = cdev_alloc();
137 if (!cdev)
138 return NULL;
139 cdev->ops = fops;
140 cdev->owner = owner;
141
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.)
147 */
148 return cdev;
149 }
150
151 extern int unisys_spar_platform;
152
153 #endif
154