summaryrefslogtreecommitdiff
path: root/src/omap_driver.h
blob: 8277e2562f07689f75cd584b44e67f80ebc117be (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
/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */

/*
 * Copyright © 2011 Texas Instruments, Inc
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Authors:
 *    Ian Elliott <ianelliottus@yahoo.com>
 *    Rob Clark <rob@ti.com>
 */

#ifndef __OMAP_DRV_H__
#define __OMAP_DRV_H__

/* All drivers need the following headers: */
#include "xf86.h"
#include "xf86_OSproc.h"

/* XXX - Perhaps, the following header files will only be used temporarily
 * (i.e. so we can use fbdevHW, SW cursor, etc):
 * XXX - figure out what can be removed..
 */
#include "micmap.h"
#include "xf86cmap.h"
/* for visuals */
#include "fb.h"
#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
#include "xf86Resources.h"
#include "xf86RAC.h"
#endif
#include "xf86xv.h"
#include "xf86Crtc.h"
#include "xf86RandR12.h"
#include "xf86drm.h"
#include "drm_fourcc.h"
#include "dri2.h"
#ifdef XSERVER_PLATFORM_BUS
#include "xf86platformBus.h"
#endif

#include <omap_drm.h>
#include <omap_drmif.h>

#include <errno.h>

#include "compat-api.h"
#include "omap_exa.h"


#define OMAP_VERSION		1000	/* Apparently not used by X server */
#define OMAP_NAME			"OMAP"	/* Name used to prefix messages */
#define OMAP_DRIVER_NAME	"omap"	/* Driver name as used in config file */
#define OMAP_MAJOR_VERSION	0
#define OMAP_MINOR_VERSION	83
#define OMAP_PATCHLEVEL		0

/**
 * This controls whether debug statements (and function "trace" enter/exit)
 * messages are sent to the log file (TRUE) or are ignored (FALSE).
 */
extern _X_EXPORT Bool omapDebug;


/* Various logging/debug macros for use in the X driver and the external
 * sub-modules:
 */
#define TRACE_ENTER() \
		do { if (omapDebug) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%s:%d: Entering\n",\
				__FUNCTION__, __LINE__); } while (0)
#define TRACE_EXIT() \
		do { if (omapDebug) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%s:%d: Exiting\n",\
				__FUNCTION__, __LINE__); } while (0)
#define DEBUG_MSG(fmt, ...) \
		do { if (omapDebug) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%s:%d " fmt "\n",\
				__FUNCTION__, __LINE__, ##__VA_ARGS__); } while (0)
#define INFO_MSG(fmt, ...) \
		do { xf86DrvMsg(pScrn->scrnIndex, X_INFO, fmt "\n",\
				##__VA_ARGS__); } while (0)
#define CONFIG_MSG(fmt, ...) \
		do { xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, fmt "\n",\
				##__VA_ARGS__); } while (0)
#define WARNING_MSG(fmt, ...) \
		do { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "WARNING: " fmt "\n",\
				##__VA_ARGS__); } while (0)
#define ERROR_MSG(fmt, ...) \
		do { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "ERROR: " fmt "\n",\
				##__VA_ARGS__); } while (0)
#define EARLY_ERROR_MSG(fmt, ...) \
		do { xf86Msg(X_ERROR, "ERROR: " fmt "\n",\
				##__VA_ARGS__); } while (0)


/* Forward declarations: */
struct _OMAPRec;

extern unsigned int
OMAPCalculateStride(unsigned int fbWidth, unsigned int bitsPerPixel);
extern unsigned int
OMAPCalculateTiledStride(unsigned int width, unsigned int bitsPerPixel);
unsigned int OMAPTiledFlags(unsigned int bitsPerPixel);



/** The driver's Screen-specific, "private" data structure. */
typedef struct _OMAPRec
{
	/** Chipset id */
	int					chipset;

	/**
	 * Pointer to a structure used to communicate and coordinate with an
	 * external EXA library (if loaded).
	 */
	OMAPEXAPtr			pOMAPEXA;

	/** various user-configurable options: */
	Bool				dri;
	Bool				HWCursor;
	Bool				NoAccel;

	/** File descriptor of the connection with the DRM. */
	int					drmFD;

	char 				*deviceName;

	/** DRM device instance */
	struct omap_device	*dev;

	/** Scan-out buffer. */
	struct omap_bo		*scanout;
	int					scanout_w, scanout_h;
	Bool				scanout_rotate;

	/** Does kernel support rotation? */
	Bool				rotation_supported;

	/** Pointer to the options for this screen. */
	OptionInfoPtr		pOptionInfo;

	/** Save (wrap) the original pScreen functions. */
	CloseScreenProcPtr				SavedCloseScreen;
	CreateScreenResourcesProcPtr	SavedCreateScreenResources;
	ScreenBlockHandlerProcPtr		SavedBlockHandler;

	/** Pointer to the entity structure for this screen. */
	EntityInfoPtr		pEntityInfo;

	XF86VideoAdaptorPtr textureAdaptor;

	/** Pending page flips we are waiting for: */
	int					pending_page_flips;

} OMAPRec, *OMAPPtr;

/*
 * Misc utility macros:
 */

/* do we support video? */
static inline Bool has_video(OMAPPtr pOMAP)
{
	return pOMAP->pOMAPEXA &&
			pOMAP->pOMAPEXA->GetFormats &&
			pOMAP->pOMAPEXA->PutTextureImage;
}

static inline Bool has_dmm(OMAPPtr pOMAP)
{
	return pOMAP->chipset >= 0x4430 || pOMAP->chipset == 0x0752;
}

static inline Bool has_rotation(OMAPPtr pOMAP)
{
#if XF86_CRTC_VERSION >= 4
	return has_dmm(pOMAP) && pOMAP->rotation_supported;
#else
	return FALSE;
#endif
}

/** Return a pointer to the driver's private structure. */
#define OMAPPTR(p) ((OMAPPtr)((p)->driverPrivate))
#define OMAPPTR_FROM_SCREEN(pScreen) \
	((OMAPPtr)(xf86Screens[(pScreen)->myNum])->driverPrivate);

#define wrap(priv, real, mem, func) {\
    priv->Saved##mem = real->mem; \
    real->mem = func; \
}

#define unwrap(priv, real, mem) {\
    real->mem = priv->Saved##mem; \
}

#define swap(priv, real, mem) {\
    void *tmp = priv->Saved##mem; \
    priv->Saved##mem = real->mem; \
    real->mem = tmp; \
}

#define exchange(a, b) {\
	typeof(a) tmp = a; \
	a = b; \
	b = tmp; \
}

#ifndef ARRAY_SIZE
#  define ARRAY_SIZE(a)  (sizeof(a) / sizeof(a[0]))
#endif
#define ALIGN(val, align)	(((val) + (align) - 1) & ~((align) - 1))


/**
 * drmmode functions..
 */
Bool drmmode_pre_init(ScrnInfoPtr pScrn, int fd, int cpp);
void drmmode_screen_init(ScrnInfoPtr pScrn);
void drmmode_screen_fini(ScrnInfoPtr pScrn);
void drmmode_adjust_frame(ScrnInfoPtr pScrn, int x, int y);
void drmmode_remove_fb(ScrnInfoPtr pScrn);
Bool drmmode_page_flip(DrawablePtr pDraw, PixmapPtr back, void *priv);
void drmmode_wait_for_event(ScrnInfoPtr pScrn);
Bool drmmode_cursor_init(ScreenPtr pScreen);
Bool drmmode_is_rotated(ScrnInfoPtr pScrn);
Bool drmmode_reallocate_scanout(ScrnInfoPtr pScrn, Bool redraw,
		xf86CrtcPtr crtc);


/**
 * DRI2 functions..
 */
typedef struct _OMAPDRISwapCmd OMAPDRISwapCmd;
Bool OMAPDRI2ScreenInit(ScreenPtr pScreen);
void OMAPDRI2CloseScreen(ScreenPtr pScreen);
void OMAPDRI2SwapComplete(OMAPDRISwapCmd *cmd);

/**
 * XV functions..
 */
Bool OMAPVideoScreenInit(ScreenPtr pScreen);
void OMAPVideoCloseScreen(ScreenPtr pScreen);

/**
 * EXA util functions.. move to EXA core?
 */

typedef int (*OMAPPutTextureImageProc)(
		PixmapPtr pSrcPix, BoxPtr pSrcBox,
		PixmapPtr pOsdPix, BoxPtr pOsdBox,
		PixmapPtr pDstPix, BoxPtr pDstBox,
		void *closure);

Bool OMAPVidCopyArea(DrawablePtr pSrcDraw, BoxPtr pSrcBox,
		DrawablePtr pOsdDraw, BoxPtr pOsdBox,
		DrawablePtr pDstDraw, BoxPtr pDstBox,
		OMAPPutTextureImageProc PutTextureImage, void *closure,
		RegionPtr clipBoxes);

#endif /* __OMAP_DRV_H__ */