Move the drivers to a separate sub-directory
[profile/ivi/intel-emgd-kmod.git] / drivers / emgd / state / appcontext / plb / appcontext_plb.c
1 /*
2  *-----------------------------------------------------------------------------
3  * Filename: appcontext_plb.c
4  * $Revision: 1.10 $
5  *-----------------------------------------------------------------------------
6  * Copyright (c) 2002-2010, Intel Corporation.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  *
26  *-----------------------------------------------------------------------------
27  * Description:
28  *  This file inplements the IGD interface for the context module. This
29  *  includes functions that handle hardware context swapping and state
30  *  variable management.
31  *-----------------------------------------------------------------------------
32  */
33
34 #include <io.h>
35
36 #include <igd_appcontext.h>
37 #include <igd_gmm.h>
38 #include <igd_mode.h>
39 #include <igd_render.h>
40 #include <igd_errno.h>
41
42 #include <intelpci.h>
43 #include <memory.h>
44 #include <mode_access.h>
45 #include <context.h>
46 #include <state2d.h>
47 #include <mode.h>
48 #include <dispatch.h>
49 #include <utils.h>
50
51 #include <plb/appcontext.h>
52 #include <plb/instr.h>
53 #include <plb/state3d_plb.h>
54
55 #include "../cmn/appcontext_dispatch.h"
56
57 /*!
58  * @addtogroup state_group
59  * @{
60  */
61
62 /*
63  * Prototype these here because they are only needed by appcontext.c
64  * and putting them in state2d.h would cause a circular dependency.
65  */
66
67 static igd_appcontext_h igd_appcontext_alloc_plb(
68         igd_display_h display_handle,
69         int priority,
70         unsigned int flags);
71 static void igd_appcontext_free_plb(
72         igd_display_h display_h,
73         int priority,
74         igd_appcontext_h appcontext_handle);
75 static int appcontext_init_plb(igd_context_t *context);
76 static void appcontext_shutdown_plb(igd_context_t *context);
77
78 static appcontext_table_t appcontext_table_plb[] = {
79         {0, 0}
80 };
81
82 appcontext_dispatch_t appcontext_dispatch_plb = {
83         appcontext_init_plb,
84         appcontext_shutdown_plb,
85         igd_appcontext_alloc_plb,
86         igd_appcontext_free_plb,
87         appcontext_table_plb
88 };
89
90 /*!
91  *
92  * @param appcontext
93  *
94  * @return 0 on success
95  * @return -IGD_ERROR_NOMEM on failure
96  */
97 static int state2d_init_plb(appcontext_t *appcontext)
98 {
99
100         appcontext->state2d = OS_ALLOC(sizeof(state2d_t));
101         if(!appcontext->state2d) {
102                 return -IGD_ERROR_NOMEM;
103         }
104
105         STATE2D(appcontext)->clip_status = IGD_CLIP_DISABLED;
106         STATE2D(appcontext)->dest_rect.x1 = 0;
107         STATE2D(appcontext)->dest_rect.y1 = 0;
108         STATE2D(appcontext)->dest_rect.x2 = 0;
109         STATE2D(appcontext)->dest_rect.y2 = 0;
110
111         return 0;
112 }
113
114 /*!
115  *
116  * @param appcontext
117  *
118  * @return void
119  */
120 static int state2d_shutdown_plb(appcontext_t *appcontext)
121 {
122         if(appcontext->state2d) {
123                 OS_FREE(appcontext->state2d);
124         }
125
126         appcontext->state2d = NULL;
127
128         return 0;
129 }
130
131 /*!
132  *
133  * @param display_handle
134  * @param priority
135  * @param flags
136  *
137  * @return appcontext_h on success
138  * @return NULL on failure
139  */
140 static igd_appcontext_h igd_appcontext_alloc_plb(
141         igd_display_h display_handle,
142         int priority,
143         unsigned int flags)
144 {
145         appcontext_t *appcontext;
146
147         /* A proper appcontext is not required for Poulsbo
148          * as a result, we'll allocate it and have it set to NULL
149          */
150         appcontext = OS_ALLOC(sizeof(appcontext_t));
151         if (!appcontext) {
152                 EMGD_ERROR ("OS_ALLOC appcontext failed\n");
153                 return NULL;
154         }
155
156         OS_MEMSET(appcontext, 0, sizeof(appcontext_t));
157         appcontext->state2d = NULL;
158
159         if (flags & IGD_CONTEXT_STATE_2D) {
160                 if (state2d_init_plb(appcontext)) {
161                         igd_appcontext_free_plb(display_handle, priority, appcontext);
162                         return NULL;
163                 }
164         }
165
166         return appcontext;
167
168 }
169
170 static void igd_appcontext_free_plb(
171         igd_display_h display_h,
172         int priority,
173         igd_appcontext_h appcontext_handle)
174 {
175
176         appcontext_t *appcontext = (appcontext_t *)appcontext_handle;
177
178         /* Free the appcontext struct */
179         if (appcontext) {
180                 state2d_shutdown_plb(appcontext);
181
182                 OS_FREE(appcontext_handle);
183         }
184 }
185
186 /*!
187  *
188  * @param context
189  *
190  * @return 0
191  */
192 static int appcontext_init_plb(igd_context_t *context)
193 {
194         return 0;
195 }
196
197 /*!
198  *
199  * @param context
200  *
201  * @return void
202  */
203 static void appcontext_shutdown_plb(igd_context_t *context)
204 {
205         return;
206 }
207