aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/emgd/include/io.h
blob: ef268db00931de0075a3772ae4c4dfa03d84cd96 (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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/* -*- pse-c -*-
 *-----------------------------------------------------------------------------
 * Filename: io.h
 * $Revision: 1.4 $
 *-----------------------------------------------------------------------------
 * 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.
 *-----------------------------------------------------------------------------
 */

#include <linux/kernel.h>
#include <asm/io.h>
#include <config.h>
#include <igd_debug.h>


#ifndef _OAL_LINUX_KERNEL_IO_H
#define _OAL_LINUX_KERNEL_IO_H

extern unsigned long _os_read_port8(unsigned long port);
extern void _os_write_port8(unsigned long port, unsigned char value);
extern unsigned long _os_read_port16(unsigned long port);
extern void _os_write_port16(unsigned long port, unsigned short value);
extern unsigned long _os_read_port32(unsigned long port);
extern void _os_write_port32(unsigned long port, unsigned long value);

/*
 * Debug macros rely on the existence of emgd_debug pointer. It is defined
 * in the HAL. If an IAL wishes to use the print routines and is not
 * linked with the HAL it will need to provide an emgd_debug pointer.
 */

#ifndef NULL
#define NULL ((void *)0)
#endif

#ifndef FAR
#define FAR
#endif


/*
 * All files including io.h should define MODULE_NAME to be a bit
 * within the emgd_debug_t data structure. If MODULE_NAME is not defined
 * debug printing will be controlled by the global "debug" bit rather
 * than a per-module bit.
 */
#ifndef MODULE_NAME
#define MODULE_NAME hal.debug
#endif

/*
 * Debug Print Macros use os_get_funcname to get the name of the
 * function they are in. They cannot rely on __func__ alone because
 * the function name may be overridden by the caller.
 *
 * If the caller wants to override the printed function name they may
 * call os_set_funcname prior to each call to EMGD_DEBUG/ERROR/TRACE.
 */
static const char *_os_override_funcname = NULL;

static __inline int os_set_funcname( const char *name )
{
	_os_override_funcname = name;
	return 1;
}

static __inline const char *os_get_funcname( const char *name )
{
	const char *ret;
	ret = (_os_override_funcname)?_os_override_funcname:name;
	_os_override_funcname = NULL;
	return ret;
}



/*
 * EMGD_ERROR()
 * Printing with EMGD_ERROR will be compiled in to all debug drivers and
 * removed from all production drivers. EMGD_ERROR printing is used for
 * driver errors that should not happen under normal operation. As such,
 * these messages cannot be disabled at runtime.
 *
 * All OAL implementations should result in EMGD_ERROR messsages in the
 * following format:
 * <OPTIONAL OS ERROR PREFIX> FUNCTION_NAME Message
 *
 * The FUNCTION_NAME must be obtained by calling
 * os_get_funcname(__func__) to insure that any overridden function names
 * are respected.
 */
#ifndef EMGD_ERROR
#ifdef DEBUG_BUILD_TYPE
#define EMGD_ERROR(...)							\
  do {									\
    printk(KERN_ERR "%s ERROR: ", __FUNCTION__);			\
    printk(__VA_ARGS__);						\
    printk("\n");							\
    /*fflush(stderr);*/							\
  } while(0);
#else
#define EMGD_ERROR(...)  do {} while(0)
#endif
#endif


/* The CONFIG_USE_INFO_PRIORITY macro is #define'd in "config.h" */
#ifdef CONFIG_USE_INFO_PRIORITY
#define EMGD_DEBUG_MSG_PRIORITY KERN_INFO
#else
#define EMGD_DEBUG_MSG_PRIORITY KERN_DEBUG
#endif

/*
 * EMGD_DEBUG()
 * Printing with EMGD_DEBUG will be compiled in to all debug drivers and
 * removed from all production drivers. EMGD_DEBUG printing is used for
 * debug messages that give information useful for debugging problems.
 * EMGD_DEBUG messages can be enabled/disabled at compile time and runtime
 * on a per-module basis.
 *
 * Disabling/Enabling module bits in CONFIG_DEBUG_FLAGS will control the
 *  default printing of debug messages.
 * Disabling/Enabling the bit in emgd_debug->MODULE_NAME will control
 *  the runtime printing of debug messages.
 *
 * All OAL implementations should result in EMGD_DEBUG messsages in the
 * following format:
 * <OPTIONAL OS PREFIX> function_name Message
 *
 * The FUNCTION_NAME must be obtained by calling
 * os_get_funcname(__func__) to insure that any overridden function names
 * are respected.
 */
#ifndef EMGD_DEBUG
#ifdef DEBUG_BUILD_TYPE
#define EMGD_DEBUG(...) if(emgd_debug &&emgd_debug-> MODULE_NAME)	\
  do {													\
    printk(EMGD_DEBUG_MSG_PRIORITY "[EMGD_DEBUG] %s ", __FUNCTION__);	\
    printk(__VA_ARGS__);								\
    printk("\n");										\
    /*fflush(stdout);*/									\
  } while(0);
#else
#define EMGD_DEBUG(...)  do {} while(0)
#endif
#endif

/*
 * EMGD_DEBUG_S()
 * Printing with EMGD_DEBUG_S will be compiled in to all debug drivers and
 * removed from all production drivers. EMGD_DEBUG_S printing is used for
 * debug messages that give information useful for debugging problems in
 * a shortened form (used by the HAL for multi-line prints).
 * EMGD_DEBUG_S messages can be enabled/disabled at compile time and runtime
 * on a per-module basis.
 *
 * Disabling/Enabling module bits in CONFIG_DEBUG_FLAGS will control the
 *  default printing of debug messages.
 * Disabling/Enabling the bit in emgd_debug->MODULE_NAME will control
 *  the runtime printing of debug messages.
 *
 * All OAL implementations should result in EMGD_DEBUG_S messsages in the
 * following format:
 * <OPTIONAL OS PREFIX> Message
 *
 * The FUNCTION_NAME must be obtained by calling
 * os_get_funcname(__func__) to insure that any overridden function names
 * are respected.
 */
#ifndef EMGD_DEBUG_S
#ifdef DEBUG_BUILD_TYPE
#define EMGD_DEBUG_S(...) if(emgd_debug && emgd_debug-> MODULE_NAME) 	\
  do {													\
    printk(EMGD_DEBUG_MSG_PRIORITY __VA_ARGS__);			\
    printk("\n");										\
    /* fflush(stdout);*/								\
  } while(0);
#else
#define EMGD_DEBUG_S(...)     do {} while(0)
#endif
#endif

/*
 * EMGD_TRACE_ENTER
 * Tracing with EMGD_TRACE_ENTER will be compiled in to all debug drivers and
 * removed from all production drivers. EMGD_TRACE_ENTER will print a fixed
 * "Enter" message when entering a function.
 * EMGD_TRACE_ENTER messages can be enabled/disabled at compile time and
 * runtime on a per-module basis. To Enable tracing in a module, the Global
 * emgd_debug->trace bit must be enabled as well as the per-module
 * debug bit.
 *
 * Disabling/Enabling module bits in CONFIG_DEBUG_FLAGS will control the
 *  default printing of debug messages.
 * Disabling/Enabling the bit in emgd_debug->MODULE_NAME will control
 *  the runtime printing of debug messages.
 *
 * All OAL implementations should result in EMGD_TRACE_ENTER messsages in the
 * following format:
 * <OPTIONAL OS PREFIX> function_name ENTER
 */
#ifndef EMGD_TRACE_ENTER
#ifdef DEBUG_BUILD_TYPE
#define EMGD_TRACE_ENTER if(emgd_debug && emgd_debug->hal.trace) EMGD_DEBUG("ENTER")
#else
#define EMGD_TRACE_ENTER
#endif
#endif

/*
 * EMGD_TRACE_EXIT
 * Tracing with EMGD_TRACE_EXIT will be compiled in to all debug drivers and
 * removed from all production drivers. EMGD_TRACE_EXIT will print a fixed
 * "Exit" message when exiting a function without error.
 * EMGD_TRACE_EXIT messages can be enabled/disabled at compile time and
 * runtime on a per-module basis. To Enable tracing in a module, the Global
 * emgd_debug->trace bit must be enabled as well as the per-module
 * debug bit.
 *
 * Disabling/Enabling module bits in CONFIG_DEBUG_FLAGS will control the
 *  default printing of debug messages.
 * Disabling/Enabling the bit in emgd_debug->MODULE_NAME will control
 *  the runtime printing of debug messages.
 *
 * All OAL implementations should result in EMGD_TRACE_EXIT messsages in the
 * following format:
 * <OPTIONAL OS PREFIX> function_name EXIT
 */
#ifndef EMGD_TRACE_EXIT
#ifdef DEBUG_BUILD_TYPE
#define EMGD_TRACE_EXIT if(emgd_debug && emgd_debug->hal.trace) EMGD_DEBUG("EXIT")
#else
#define EMGD_TRACE_EXIT
#endif
#endif

/*
 * EMGD_ERROR_EXIT()
 * Tracing with EMGD_ERROR_EXIT will be compiled in to all debug drivers and
 * removed from all production drivers. EMGD_ERROR_EXIT will print an error
 * as well as a fixed "Exit" message when exiting a function without error.
 * EMGD_ERROR_EXIT messages can be enabled/disabled at compile time and
 * runtime on a per-module basis. To Enable tracing in a module, the Global
 * emgd_debug->trace bit must be enabled as well as the per-module
 * debug bit.
 *
 * Note: Only the Tracing message can be disabled, the error message will
 * still print as with EMGD_ERROR().
 *
 * Disabling/Enabling module bits in CONFIG_DEBUG_FLAGS will control the
 *  default printing of debug messages.
 * Disabling/Enabling the bit in emgd_debug->MODULE_NAME will control
 *  the runtime printing of debug messages.
 *
 * All OAL implementations should result in EMGD_ERROR_EXIT messsages in the
 * following format:
 * <OPTIONAL OS ERROR PREFIX> function_name EXIT Message
 */
#ifndef EMGD_ERROR_EXIT
#ifdef DEBUG_BUILD_TYPE
#define EMGD_ERROR_EXIT													\
	if(emgd_debug && emgd_debug->hal.trace) EMGD_DEBUG("EXIT With Error..."); \
	EMGD_ERROR
#else
#define EMGD_ERROR_EXIT(...)   do {} while(0)
#endif
#endif


/*
 * EMGD_VERBOSE()
 * Verbose printing that is useful only when debugging specific problems
 * or contains lots of text should be implemented in a single function and
 * called from within the EMGD_VERBOSE macro. The default and runtime
 * control of this output can be altered by changing the value of the
 * global emgd_debug->verbose.
 */
#ifndef EMGD_VERBOSE
#ifdef DEBUG_BUILD_TYPE
#define EMGD_VERBOSE(opt, func) if(emgd_debug-> opt) func;
#else
#define EMGD_VERBOSE(opt, func)
#endif
#endif

/*
 * EMGD_ASSERT( Statement, Message, Error Code)
 * EMGD_ASSERT should be used to verify the values of statements that
 * should always be true. EMGD_ASSERT will generate code only in debug drivers
 * and therefore should only be used for things that should never be false
 * in production drivers. For example, testing for null parameters in
 * an internal interface.
 *
 * Usage: EMGD_ASSERT(char_ptr, "Char Pointer is NULL", -IGD_ERROR_INVAL)
 * Usage: EMGD_ASSERT(char_ptr, "Char Pointer is NULL", )
 */
#ifndef EMGD_ASSERT
#ifdef EMGD_DEBUG
#define EMGD_ASSERT(a, m, e) if(!(a)) { EMGD_ERROR_EXIT("ASSERT: " m); return e; }
#else
#define EMGD_ASSERT(a, m, e)
#endif
#endif

/*
 * This macro _may_ be defined by an OAL port to modify the mmio
 * base address prior to use. Commonly this is used to make the base
 * address 0 to remove code for vbios.
 */
#ifdef _EMGD_MMIO
#define EMGD_MMIO(a) _EMGD_MMIO(a)
#else
#define EMGD_MMIO(a) a
#endif



#define EMGD_READ32(addr) *(volatile unsigned int *)(addr)
#define EMGD_WRITE32(value, addr) \
		(*(volatile unsigned long *)(addr) = (value))
/*	EMGD_DEBUG ("EMGD_WRITE32: 0x%p=0x%lx\n", (addr), (value)); \*/

#define EMGD_READ8(addr) *(volatile unsigned char *)(addr)
#define EMGD_WRITE8(value, addr) \
		(*(volatile unsigned char *)(addr) = (value))
/*	EMGD_DEBUG ("EMGD_WRITE8: 0x%p=0x%x\n", (addr), (value));	\*/


/* PORT IO Macros */
#if 0
// user mode.  To be removed.
#define _EMGD_READ_PORT8(port)          _os_read_port8(port)
#define _EMGD_WRITE_PORT8(port, value)  _os_write_port8(port, value)

#define _EMGD_READ_PORT16(port)         _os_read_port16(port)
#define _EMGD_WRITE_PORT16(port, value) _os_write_port16(port, value)

#define _EMGD_READ_PORT32(port)         _os_read_port32(port)
#define _EMGD_WRITE_PORT32(port, value) _os_write_port32(port, value)
#else
// Linux kernel mode port I/O
#define EMGD_READ_PORT8(port)          inb(port)
#define EMGD_WRITE_PORT8(port, value)  outb(port, value)

#define EMGD_READ_PORT16(port)         inw(port)
#define EMGD_WRITE_PORT16(port, value) outw(port, value)

#define EMGD_READ_PORT32(port)         inl(port)
#define EMGD_WRITE_PORT32(port, value) outl(port, value)
#endif

#ifdef DEBUG_MEM
extern unsigned long global_virt_mmadr;
extern unsigned long global_virt_mmadr_offset;

static __inline *(volatile unsigned int *) _EMGD_READ32(unsigned int addr)
{
    if ((addr < 0x10100000) && (addr > 0x10000000)) {
		return *(volatile unsigned int *)(addr+global_virt_mmadr-global_virt_mmadr_offset);
	} else {
		return *(volatile unsigned int *)(addr);
    }
}

static __inline void _EMGD_WRITE32(unsigned int value, unsigned int addr) \
{
	if ((addr < 0x10100000) && (addr > 0x10000000)) {
		*(volatile unsigned int *)(addr+global_virt_mmadr-global_virt_mmadr_offset) = value;
	} else {
		*(volatile unsigned int *)addr = value;
	}
	printf("EMGD_WRITE32: *0x%x = 0x%x\n", addr, value);
}

static __inline *(volatile unsigned char *) _EMGD_READ8(unsigned int addr)
{
    if ((addr < 0x10100000) && (addr > 0x10000000)) {
		return *(volatile unsigned char *)(addr+global_virt_mmadr-global_virt_mmadr_offset);
	} else {
		return *(volatile unsigned char *)addr;
	}
}

static __inline void _EMGD_WRITE8(unsigned char value, unsigned int addr) \
{ 
    if ((addr < 0x10100000) && (addr > 0x10000000)) {
		(*(volatile unsigned char *)(addr+global_virt_mmadr-global_virt_mmadr_offset) = value);
    } else {
		(*(volatile unsigned char *)(addr) = value);
    }
    printf("EMGD_WRITE8: *0x%x = 0x%c\n", addr, value);
}
#endif /* DEBUG_MEM */

#define EMGD_PTR_TO_ULONG(ptr) (ptr)
#define EMGD_ULONG_TO_PTR(ulong) (ulong)

#endif