aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/emgd/emgd/include/sched.h
blob: 65112f5c0a657be97492e9a071fc204dcd2d360c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* -*- pse-c -*-
 *-----------------------------------------------------------------------------
 * Filename: sched.h
 * $Revision: 1.6 $
 *-----------------------------------------------------------------------------
 * Copyright © 2002-2010, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *-----------------------------------------------------------------------------
 * Description:
 *  This file contains Linux User-space implementations for the OAL io.h
 *  abstractions.
 *-----------------------------------------------------------------------------
 */

#ifndef _OAL_LINUX_USER_SCHED_H
#define _OAL_LINUX_USER_SCHED_H

#include <config.h>
#include <linux/semaphore.h>

#include <linux/sched.h>

typedef unsigned long os_alarm_t;

static __inline os_alarm_t _linux_kernel_set_alarm(unsigned long t)
{
  return (msecs_to_jiffies(t) + jiffies);
}

static __inline int _linux_kernel_test_alarm(os_alarm_t t)
{
  return (jiffies >= t) ? 1 : 0;
}

#define OS_SET_ALARM(t) _linux_kernel_set_alarm(t)
#define OS_TEST_ALARM(t) _linux_kernel_test_alarm(t)


/*----------------------------------------------------------------------------
 *  Function: OS_INIT_INTERRUPT
 *  
 *  Description:
 *  This function establishes the communication for sending requests for interrupt
 *            
 *  int OS_INIT_INTERRUPT( did, mmadr )
 *---------------------------------------------------------------------------*/
#ifdef CONFIG_INTERRUPT
#define OS_INIT_INTERRUPT(did, mmadr) _OS_INIT_INTERRUPT(did, mmadr)
#else
#define OS_INIT_INTERRUPT(did, mmadr) 0
#endif



/*----------------------------------------------------------------------------
 * Function: OS_SCHEDULE
 *
 * Description:
 *  This function can be called with the caller wished to give up processor
 *  control until the next available timeslice. This will allow other OS tasks
 *  to run before returning to the current context. This function should be
 *  used with caution and observation of reentrant coding principals.
 *
 *  void OS_SCHEDULE( void );
 *---------------------------------------------------------------------------*/

#define OS_SCHEDULE() schedule_timeout(1)

#if 0
// Implement _OS_SLEEP at a wait-loop
#define _OS_SLEEP(usec) {					\
    unsigned long j_timeout = usecs_to_jiffies(usec);		\
    unsigned long j_start = jiffies;				\
    unsigned long j_current;					\
    do {							\
      j_current = jiffies;					\
    }while((j_current - j_start) < j_timeout);			\
  }
#else
// Implement _OS_SLEEP as a true sleep

/* We could also try TASK_UNINTERRUPTIBLE here */
/*----------------------------------------------------------------------------
 * Function: OS_SLEEP
 *
 * Parameters:
 *  time_val: Unsigned long time value in Micro-seconds (1/1000000 of a second)
 *            for the task to sleep.
 *
 * Description:
 *  This function causes the caller to delay further processing
 *  for the number of micro-seconds ( 1/1000000 or a second ) requested.
 *  This function should only be used with small time values
 *  ( < 1/100 of a second ) as lengthy sleeps could degrade the kernel
 *  response time.
 *
 *  void OS_SLEEP( unsigned long time_val );
 *---------------------------------------------------------------------------*/

#define OS_SLEEP(usec) {									\
    __set_current_state(TASK_KILLABLE);						\
    schedule_timeout(usecs_to_jiffies(usec)); }
#endif

/*----------------------------------------------------------------------------
 * Function: OS_UISLEEP
 *
 * Parameters:
 *  time_val: Unsigned long time value in Micro-seconds (1/1000000 of a second)
 *            for the task to sleep.
 *
 * Description:
 *  This function causes the caller to delay further processing
 *  for the number of micro-seconds ( 1/1000000 or a second ) requested.
 *  This sleep is uninterrruptable.
 *  This function should only be used with small time values
 *  ( < 1/100 of a second ) as lengthy sleeps could degrade the kernel
 *  response time.
 *
 *  void OS_UISLEEP( unsigned long time_val );
 *---------------------------------------------------------------------------*/

/* un interuuptable sleep */
#define OS_UISLEEP(usec) {					\
    __set_current_state(TASK_UNINTERRUPTIBLE);			\
    schedule_timeout(usecs_to_jiffies(usec)); 			\
}

#ifndef OS_PTHREAD_CREATE
typedef int os_pthread_t;
// This function is not being used.
// #define OS_PTHREAD_CREATE(t, a, f, p) (-1)
#endif

#ifndef OS_PTHREAD_JOIN
// This function is not being used.
// #define OS_PTHREAD_JOIN(t, p) (0)
#endif

/*
 * Note, the POSIX pthread implementation does not take the thread as a
 * parameter but it makes porting easier.
 */
#define UNREFERENCED_PARAMETER(parm) ((parm)=(parm))

#ifndef OS_PTHREAD_EXIT
// This function is not being used.
// #define OS_PTHREAD_EXIT(t, r)
#endif

#ifndef OS_PTHREAD_MUTEX_INIT
typedef struct semaphore os_pthread_mutex_t;
#define OS_PTHREAD_MUTEX_INIT(m, a) init_MUTEX(m)
#endif


#ifndef OS_PTHREAD_MUTEX_LOCK
// TO-DO Should this just be down?
#define OS_PTHREAD_MUTEX_LOCK(m) down_interruptible(m)
#endif

#ifndef OS_PTHREAD_MUTEX_UNLOCK
#define OS_PTHREAD_MUTEX_UNLOCK(m) up(m)
#endif

#ifndef OS_PTHREAD_COND_INIT
typedef int os_pthread_cond_t;
// This function is not being used.
// #define OS_PTHREAD_COND_INIT(m, a) 0
#endif

#ifndef OS_PTHREAD_COND_WAIT
// This function is not being used.
// #define OS_PTHREAD_COND_WAIT(c, m) 0
#endif

#ifndef OS_PTHREAD_COND_SIGNAL
// This function is not being used.
// #define OS_PTHREAD_COND_SIGNAL(c) 0
#endif


#endif