Commit | Line | Data |
---|---|---|
9d9baadd KC |
1 | /* timskmod.h |
2 | * | |
f6d0c1e6 | 3 | * Copyright (C) 2010 - 2013 UNISYS CORPORATION |
9d9baadd KC |
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> | |
9d9baadd KC |
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> | |
9d9baadd KC |
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 | |
9d9baadd KC |
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 | ||
9d9baadd KC |
70 | /** Try to evaulate the provided expression, and do a RETINT(x) iff |
71 | * the expression evaluates to < 0. | |
9d9baadd | 72 | */ |
9d9baadd KC |
73 | #define ASSERT(cond) \ |
74 | do { if (!(cond)) \ | |
75 | HUHDRV("ASSERT failed - %s", \ | |
76 | __stringify(cond)); \ | |
77 | } while (0) | |
78 | ||
79 | #define sizeofmember(TYPE, MEMBER) (sizeof(((TYPE *)0)->MEMBER)) | |
80 | /** "Covered quotient" function */ | |
81 | #define COVQ(v, d) (((v) + (d) - 1) / (d)) | |
82 | #define SWAPPOINTERS(p1, p2) \ | |
83 | do { \ | |
84 | void *SWAPPOINTERS_TEMP = (void *)p1; \ | |
85 | (void *)(p1) = (void *)(p2); \ | |
86 | (void *)(p2) = SWAPPOINTERS_TEMP; \ | |
87 | } while (0) | |
88 | ||
9d9baadd KC |
89 | #define PRINTKDRV(fmt, args...) LOGINF(fmt, ## args) |
90 | #define TBDDRV(fmt, args...) LOGERR(fmt, ## args) | |
91 | #define HUHDRV(fmt, args...) LOGERR(fmt, ## args) | |
92 | #define ERRDRV(fmt, args...) LOGERR(fmt, ## args) | |
93 | #define WARNDRV(fmt, args...) LOGWRN(fmt, ## args) | |
94 | #define SECUREDRV(fmt, args...) LOGWRN(fmt, ## args) | |
95 | #define INFODRV(fmt, args...) LOGINF(fmt, ## args) | |
96 | #define DEBUGDRV(fmt, args...) DBGINF(fmt, ## args) | |
97 | ||
98 | #define PRINTKDEV(devname, fmt, args...) LOGINFDEV(devname, fmt, ## args) | |
99 | #define TBDDEV(devname, fmt, args...) LOGERRDEV(devname, fmt, ## args) | |
100 | #define HUHDEV(devname, fmt, args...) LOGERRDEV(devname, fmt, ## args) | |
101 | #define ERRDEV(devname, fmt, args...) LOGERRDEV(devname, fmt, ## args) | |
102 | #define ERRDEVX(devno, fmt, args...) LOGERRDEVX(devno, fmt, ## args) | |
103 | #define WARNDEV(devname, fmt, args...) LOGWRNDEV(devname, fmt, ## args) | |
104 | #define SECUREDEV(devname, fmt, args...) LOGWRNDEV(devname, fmt, ## args) | |
105 | #define INFODEV(devname, fmt, args...) LOGINFDEV(devname, fmt, ## args) | |
106 | #define INFODEVX(devno, fmt, args...) LOGINFDEVX(devno, fmt, ## args) | |
107 | #define DEBUGDEV(devname, fmt, args...) DBGINFDEV(devname, fmt, ## args) | |
108 | ||
9d9baadd KC |
109 | /** Verifies the consistency of your PRIVATEDEVICEDATA structure using |
110 | * conventional "signature" fields: | |
111 | * <p> | |
112 | * - sig1 should contain the size of the structure | |
113 | * - sig2 should contain a pointer to the beginning of the structure | |
114 | */ | |
115 | #define DDLOOKSVALID(dd) \ | |
116 | ((dd != NULL) && \ | |
117 | ((dd)->sig1 == sizeof(PRIVATEDEVICEDATA)) && \ | |
118 | ((dd)->sig2 == dd)) | |
119 | ||
120 | /** Verifies the consistency of your PRIVATEFILEDATA structure using | |
121 | * conventional "signature" fields: | |
122 | * <p> | |
123 | * - sig1 should contain the size of the structure | |
124 | * - sig2 should contain a pointer to the beginning of the structure | |
125 | */ | |
126 | #define FDLOOKSVALID(fd) \ | |
127 | ((fd != NULL) && \ | |
128 | ((fd)->sig1 == sizeof(PRIVATEFILEDATA)) && \ | |
129 | ((fd)->sig2 == fd)) | |
130 | ||
9d9baadd | 131 | /** Sleep for an indicated number of seconds (for use in kernel mode). |
e9945457 | 132 | * x - the number of seconds to sleep. |
9d9baadd KC |
133 | */ |
134 | #define SLEEP(x) \ | |
2be90fef | 135 | do { __set_current_state(TASK_INTERRUPTIBLE); \ |
9d9baadd KC |
136 | schedule_timeout((x)*HZ); \ |
137 | } while (0) | |
138 | ||
139 | /** Sleep for an indicated number of jiffies (for use in kernel mode). | |
e9945457 | 140 | * x - the number of jiffies to sleep. |
9d9baadd KC |
141 | */ |
142 | #define SLEEPJIFFIES(x) \ | |
2be90fef | 143 | do { __set_current_state(TASK_INTERRUPTIBLE); \ |
9d9baadd KC |
144 | schedule_timeout(x); \ |
145 | } while (0) | |
146 | ||
9d9baadd KC |
147 | static inline struct cdev *cdev_alloc_init(struct module *owner, |
148 | const struct file_operations *fops) | |
149 | { | |
150 | struct cdev *cdev = NULL; | |
e5700df5 | 151 | |
9d9baadd KC |
152 | cdev = cdev_alloc(); |
153 | if (!cdev) | |
154 | return NULL; | |
155 | cdev->ops = fops; | |
156 | cdev->owner = owner; | |
157 | ||
158 | /* Note that the memory allocated for cdev will be deallocated | |
159 | * when the usage count drops to 0, because it is controlled | |
160 | * by a kobject of type ktype_cdev_dynamic. (This | |
161 | * deallocation could very well happen outside of our kernel | |
162 | * module, like via the cdev_put in __fput() for example.) | |
163 | */ | |
164 | return cdev; | |
165 | } | |
166 | ||
e3f3b1f2 | 167 | extern int unisys_spar_platform; |
9d9baadd KC |
168 | |
169 | #endif |