blob: 4019a0d63645fe53380caec301679a68f9979e87 [file] [log] [blame]
Ken Cox9d9baad2014-03-04 07:58:05 -06001/* timskmod.h
2 *
Benjamin Romerf6d0c1e2014-04-23 14:58:34 -04003 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
Ken Cox9d9baad2014-03-04 07:58:05 -06004 * 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>
Ken Cox9d9baad2014-03-04 07:58:05 -060034#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
Ken Cox9d9baad2014-03-04 07:58:05 -060064#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
Ken Cox9d9baad2014-03-04 07:58:05 -060071/** Try to evaulate the provided expression, and do a RETINT(x) iff
72 * the expression evaluates to < 0.
Ken Cox9d9baad2014-03-04 07:58:05 -060073 */
Ken Cox9d9baad2014-03-04 07:58:05 -060074#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
Ken Cox9d9baad2014-03-04 07:58:05 -060090#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
Ken Cox9d9baad2014-03-04 07:58:05 -0600110/** 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
Ken Cox9d9baad2014-03-04 07:58:05 -0600132/** Sleep for an indicated number of seconds (for use in kernel mode).
Benjamin Romere9945452014-10-03 14:09:19 -0400133 * x - the number of seconds to sleep.
Ken Cox9d9baad2014-03-04 07:58:05 -0600134 */
135#define SLEEP(x) \
Davidlohr Bueso2be90fe2015-01-26 02:15:02 -0800136 do { __set_current_state(TASK_INTERRUPTIBLE); \
Ken Cox9d9baad2014-03-04 07:58:05 -0600137 schedule_timeout((x)*HZ); \
138 } while (0)
139
140/** Sleep for an indicated number of jiffies (for use in kernel mode).
Benjamin Romere9945452014-10-03 14:09:19 -0400141 * x - the number of jiffies to sleep.
Ken Cox9d9baad2014-03-04 07:58:05 -0600142 */
143#define SLEEPJIFFIES(x) \
Davidlohr Bueso2be90fe2015-01-26 02:15:02 -0800144 do { __set_current_state(TASK_INTERRUPTIBLE); \
Ken Cox9d9baad2014-03-04 07:58:05 -0600145 schedule_timeout(x); \
146 } while (0)
147
Ken Cox9d9baad2014-03-04 07:58:05 -0600148static inline struct cdev *cdev_alloc_init(struct module *owner,
149 const struct file_operations *fops)
150{
151 struct cdev *cdev = NULL;
Benjamin Romere5700df2014-08-05 14:57:46 -0400152
Ken Cox9d9baad2014-03-04 07:58:05 -0600153 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
Benjamin Romere3f3b1f2014-09-30 12:07:50 -0400168extern int unisys_spar_platform;
Ken Cox9d9baad2014-03-04 07:58:05 -0600169
170#endif