[go: nahoru, domu]

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