aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/emgd/emgd/video/overlay/cmn/igd_ovl.c
blob: 823e69a9093ae1e4378078ac535e073d77267cbb (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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/* -*- pse-c -*-
 *-----------------------------------------------------------------------------
 * Filename: igd_ovl.c
 * $Revision: 1.22 $
 *-----------------------------------------------------------------------------
 * 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:
 *  
 *-----------------------------------------------------------------------------
 */

#define MODULE_NAME hal.overlay

#include <context.h>
#include <memory.h>
#include <dsp.h>
#include <io.h>

#include <igd_mode.h>
#include <igd_gmm.h>
#include <igd_ovl.h>
#include <igd_errno.h>
#include <igd_pwr.h>
#include <igd_render.h>
#include <igd_blend.h>

#include <general.h>
#include <mode_access.h>
#include <dispatch.h>
#include <intelpci.h>

#include "ovl_dispatch.h"
#include "ovl_virt.h"

void _overlay_shutdown(igd_context_t *context);


extern ovl_dispatch_t ovl_dispatch_plb[];
extern ovl_dispatch_t ovl_dispatch_tnc[];

static dispatch_table_t ovl_dispatch_list[] = {

#ifdef CONFIG_PLB
	{PCI_DEVICE_ID_VGA_PLB, &ovl_dispatch_plb},
#endif
#ifdef CONFIG_TNC
	{PCI_DEVICE_ID_VGA_TNC, &ovl_dispatch_tnc},
#endif

	{0, NULL}
};

ovl_context_t ovl_context[1];

/* Description: Turns off video plane that was turned by fw/EFI. To be called by
 * alter_ovl if needed.
 *
 * Notes:Upon video splash being turned on, in order to reset it, need to call
 * secondary ovl dispatch function to turn off the right registers
 */
void igd_reset_fw_ovl(igd_display_context_t *display)
{
	ovl_dispatch_t	*ovl_dispatch = (ovl_dispatch_t *)ovl_context->dispatch;
	ovl_dispatch[OVL_SECONDARY].alter_ovl(display,
								NULL, NULL, NULL, NULL, IGD_OVL_ALTER_OFF);
}

static int ovl_get_display(igd_display_context_t *display,
	igd_display_context_t *(ovl_displays[]),
	unsigned long flags)
{
	igd_display_context_t *primary, *secondary;
	unsigned long dc;

	display->context->mod_dispatch.dsp_get_dc(&dc, &primary, &secondary);

	/* This is a special case  to enable Dual Overlay */
	if(flags & IGD_OVL_FORCE_USE_DISP) {

		/* Use the passed in Display Handle */
		if(display == primary) {

			ovl_displays[OVL_PRIMARY]   = display;
			ovl_displays[OVL_SECONDARY] = NULL;

		} else if(display == secondary) {

			ovl_displays[OVL_PRIMARY]   = NULL;
			ovl_displays[OVL_SECONDARY] = display;
		}

		return 0;
	}

	if (dc & IGD_DISPLAY_CONFIG_CLONE) {
		/* CLONE or Vertical Extended
		 * Primary Overlay uses the display from the primary pipe.
		 * Secondary Overlay uses the display from the secondary pipe. */
		ovl_displays[OVL_PRIMARY]   = primary;
		ovl_displays[OVL_SECONDARY] = secondary;
	} else {
		/* Single, Twin, Extended */

		if (display == primary) {
			ovl_displays[OVL_PRIMARY]   = display;
			ovl_displays[OVL_SECONDARY] = NULL;
		} else {
			ovl_displays[OVL_PRIMARY]   = NULL;
			ovl_displays[OVL_SECONDARY] = display;
		}
	}

	return 0;
}

static int igd_alter_ovl2(igd_display_h display_h,
	igd_surface_t       *src_surf,
	igd_rect_t          *src_rect,
	igd_rect_t          *dest_rect,
	igd_ovl_info_t      *ovl_info,
	unsigned int         flags)
{
	igd_display_context_t *display =
		(igd_display_context_t *)display_h;
	ovl_dispatch_t    *ovl_dispatch =
		(ovl_dispatch_t *)ovl_context->dispatch;
	int cur_ovl, ret = 0;
	unsigned long dc;
	igd_display_context_t *primary, *secondary;

	EMGD_TRACE_ENTER;

	if(flags == IGD_FW_VIDEO_OFF)
	{
		igd_reset_fw_ovl(display);
		return IGD_SUCCESS;
	}

	/* Determine which display this overlay belongs to */
	display->context->mod_dispatch.dsp_get_dc(&dc, &primary, &secondary);
	if(display == primary) {
		cur_ovl = 0;
	} else if (display == secondary) {
		cur_ovl = 1;
	} else {
		/* shouldn't get here. */
		EMGD_TRACE_EXIT;
		return  -IGD_ERROR_INVAL;
	}

        
	/* Is the overlay is being turned off? */
	if ((flags & IGD_OVL_ALTER_ON) == IGD_OVL_ALTER_OFF) {
				
		/* Call family dependent overlay 
		 * function to alter the overlay. */
		ret = ovl_dispatch[cur_ovl].alter_ovl(display, 
						  src_surf, 
						  src_rect, 
						  dest_rect,
						  ovl_info, 
						  flags);
		
		EMGD_TRACE_EXIT;
		return ret;
	}
	
	/* Call family dependent overlay function 
	 * to alter the overlay. */
	ret = ovl_dispatch[cur_ovl].alter_ovl(display, 
                                                      src_surf,
                                                      src_rect, 
                                                      dest_rect,
                                                      ovl_info, 
					      flags);

	if (ret != IGD_SUCCESS) {
		/* Turn the overlay off when there is an error */
		ovl_dispatch[cur_ovl].alter_ovl(display,
						NULL, NULL, NULL, NULL, 
						IGD_OVL_ALTER_OFF);
	}

	EMGD_TRACE_EXIT;
	return ret;
}


static int igd_query_ovl(igd_display_h display_h,
	unsigned int flags)
{
	igd_display_context_t *display =
		(igd_display_context_t *)display_h;
	ovl_dispatch_t    *ovl_dispatch =
		(ovl_dispatch_t *)ovl_context->dispatch;
	int           cur_ovl;
	igd_display_context_t *(ovl_displays[OVL_MAX_HW]); /* Array of pointers */
	int ret = FALSE;

	ovl_get_display(display, ovl_displays, flags);

	/* This is a bit of a short circuit (since the hardware dependent functions
	 * are not being called), but to determine if the hardware overlay is on,
	 * just check the state of the ovl_context. */
	if (flags == IGD_OVL_QUERY_IS_ON) {
		if (ovl_context->state == OVL_STATE_ON) {
			return TRUE;
		} else {
			return FALSE;
		}
	}

	for (cur_ovl = 0; cur_ovl < OVL_MAX_HW; cur_ovl++) {
		if (ovl_displays[cur_ovl] != NULL) {
			ret = ovl_dispatch[cur_ovl].query_ovl(
				(igd_display_h)(ovl_displays[cur_ovl]), 
				(flags & IGD_OVL_QUERY_MASK));
			if (ret == FALSE) {
				/* Can only return TRUE (event has occured and capability
				 * is available) if it is TRUE for all displays */
				return FALSE;
			}
		}
	}

	return ret;
}
static int igd_query_max_size_ovl(igd_display_h display_h,
	unsigned long pf,
	unsigned int *max_width,
	unsigned int *max_height)
{
	igd_display_context_t *display =
		(igd_display_context_t *)display_h;
	ovl_dispatch_t    *ovl_dispatch =
		(ovl_dispatch_t *)ovl_context->dispatch;
	int           cur_ovl;
	igd_display_context_t *(ovl_displays[OVL_MAX_HW]); /* Array of pointers */
	unsigned int tmp_max_width, tmp_max_height;
	int ret = -IGD_ERROR_INVAL;

	*max_width =  0x10000000;
	*max_height = 0x10000000;

	/* pass a dummy flag */
	ovl_get_display(display, ovl_displays, 0);

	for (cur_ovl = 0; cur_ovl < OVL_MAX_HW; cur_ovl++) {
		if (ovl_displays[cur_ovl] != NULL) {
			ret = ovl_dispatch[cur_ovl].query_max_size_ovl(
				(igd_display_h)(ovl_displays[cur_ovl]), pf,
				&tmp_max_width, &tmp_max_height);
			if (ret != IGD_SUCCESS) {
				/* Can only return IGD_SUCCESS (no error)
				 * if there is no error for all displays */
				return ret;
			}
			if (tmp_max_width < *max_width) {
				*max_width = tmp_max_width;
			}
			if (tmp_max_height < *max_height) {
				*max_height = tmp_max_height;
			}
		}
	}

	return ret;
}

/*----------------------------------------------------------------------
 * Function: igd_get_ovl_init_params(ovl_um_context_t *ovl_um_context)
 * Description:
 *
 * Notes in Usage:
 * the user mode caller fills in the primary and secondary display handles.
 *
 *----------------------------------------------------------------------*/
int igd_get_ovl_init_params(igd_driver_h driver_handle,
			    ovl_um_context_t *ovl_um_context)
{
	igd_context_t *context = (igd_context_t *)driver_handle;
	igd_display_context_t *primary, *secondary;
	unsigned long dc;

	context->mod_dispatch.dsp_get_dc(&dc, &primary, &secondary);
	ovl_um_context->dc = dc;
	ovl_um_context->primary = primary;
	ovl_um_context->secondary = secondary;
    ovl_um_context->chiptype = 0; 

    return IGD_SUCCESS;
}



int ovl_full_init(igd_context_t *context,
			igd_param_t *params,
			ovl_context_t *ovl_context)
{
	unsigned long tmp_reg_size;
	unsigned long region_type = IGD_GMM_REGION_TYPE_OVLREG;
	void *virt;

	if(context->device_context.did == PCI_DEVICE_ID_VGA_TNC){
		/* Atom E6xx needs the overlay update register offset 
		 * to be a 64K aligned address. */
		region_type = IGD_GMM_REGION_TYPE_OVLREG64;
	}

	/* Allocate a 4K page aligned region from
	 * memory manager for overlay register update memory */

	tmp_reg_size = 4096;
	GMM_SET_DEBUG_NAME("Overlay Register Buffer");	
	if(context->dispatch.gmm_alloc_region(
		   &(ovl_context->reg_update_offset),
		   &tmp_reg_size,
		   IGD_GMM_REGION_TYPE_OVLREG,
		   0)){

		EMGD_ERROR_EXIT("Memory allocation for "
			"Overlay Register Update failed");

		ovl_context->reg_allocated = 0;

		return -IGD_ERROR_NOMEM;
	}
	ovl_context->reg_allocated = 1;


	/* Get the register update physical address in RAM */
	if(context->dispatch.gmm_virt_to_phys(
		   ovl_context->reg_update_offset,
		   &ovl_context->reg_update_phys)) {

		EMGD_ERROR_EXIT("Virtual to Physical Address translation failed");
		return -IGD_ERROR_NOMEM;
	}

	/*
	 * TODO: Verify that phys_to_virt returns a valid address for
	 * agp memory
	 */
	virt = phys_to_virt(ovl_context->reg_update_phys);

	/* Clear the register update page */
	OS_MEMSET(virt, 0, tmp_reg_size);


	/* Get overlay's dispatch table */
	ovl_context->dispatch = (ovl_dispatch_t (*)[])dispatch_acquire(context,
		ovl_dispatch_list);
	if(!ovl_context->dispatch) {
		EMGD_ERROR_EXIT("Unsupported Device");
		return -IGD_ERROR_NODEV;
	}


	/* Hook up the IGD dispatch table entries for overlay
	 * Alter has a common function, query can call the family function
	 * directly */
	context->dispatch.get_ovl_init_params = igd_get_ovl_init_params;
	context->dispatch.alter_ovl = NULL; 
	context->dispatch.alter_ovl2 = igd_alter_ovl2;
	context->dispatch.query_ovl = igd_query_ovl;
	context->dispatch.query_max_size_ovl = igd_query_max_size_ovl;

	/* Hook up optional inter-module functions */
	context->mod_dispatch.overlay_shutdown = _overlay_shutdown;

	/* Initialize any OS / Chipst general HAL params for overlay */
	if(params->display_flags & IGD_DISPLAY_FB_BLEND_OVL){
		ovl_context->fb_blend_ovl = 1;
	}

	EMGD_TRACE_EXIT;
	return IGD_SUCCESS;
}

void _overlay_shutdown(igd_context_t *context)
{

	EMGD_TRACE_ENTER;

	if (ovl_context->reg_allocated) {
		context->dispatch.gmm_free(ovl_context->reg_update_offset);
		ovl_context->reg_update_offset = 0;
		ovl_context->reg_allocated = 0;
	}

	EMGD_TRACE_EXIT;

	return;
}

/*----------------------------------------------------------------------
 * Function: igd_overlay_pwr()
 * Description:
 *  igd_overlay_pwr will only be called from power module .
 *  It shuts down / powers up overlay output based on the power
 *  state transition requested.
 *
 * Notes in Usage:
 *
 *----------------------------------------------------------------------*/
int igd_overlay_pwr(
	igd_driver_h driver_handle,
	int power_state)
{
	igd_context_t *context = (igd_context_t *)driver_handle;
	igd_display_context_t *primary, *secondary;

	/* NOTE: The overlay will not be turned on by this method, but will be
	 * turned on with the next call to alter_ovl */

	/* Turn off the overlay for every display.  Most of the displays will
	 * likely not have the overlay off, but there should be no harm it turning
	 * it off for a display which does not have the overlay. */

	EMGD_TRACE_ENTER;
	if(power_state != IGD_POWERSTATE_D0){
		context->mod_dispatch.dsp_get_dc(NULL, &primary, &secondary);

		if(primary) {
			/* Turn the overlay off. */
			igd_alter_ovl2((igd_display_h)primary,
				 NULL, NULL, NULL, NULL, IGD_OVL_ALTER_OFF);
		}
		if(secondary) {
			igd_alter_ovl2((igd_display_h)secondary,
				 NULL, NULL, NULL, NULL, IGD_OVL_ALTER_OFF);
		}
	}
	
	EMGD_TRACE_EXIT;
	return IGD_SUCCESS;
}