revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / devs / monitors / IntelGMA / intelgma_galliumclass.c
blob64472ef166dbfcea0f72fd31233a8b72cd38f73c
1 /*
2 Copyright © 2011-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <aros/debug.h>
9 #include <aros/libcall.h>
10 #include <aros/asmcall.h>
11 #include <aros/symbolsets.h>
12 #include <utility/tagitem.h>
14 #include <proto/oop.h>
15 #include <proto/exec.h>
16 #include <proto/utility.h>
18 #include <hidd/gallium.h>
19 #include <proto/graphics.h>
21 #include "intelgma_hidd.h"
22 #include "intelgma_winsys.h"
23 #include "intelgma_gallium.h"
24 #include "intelG45_regs.h"
26 #include "i915/i915_public.h"
27 #include "i915/i915_resource.h"
28 #include "util/u_memory.h"
29 #include "util/u_atomic.h"
30 #include "util/u_inlines.h"
31 #include "i915/i915_winsys.h"
32 #include "i915/i915_debug.h"
34 const struct OOP_InterfaceDescr Gallium_ifdescr[];
35 extern OOP_AttrBase MetaAttrBase;
36 OOP_AttrBase HiddGalliumAttrBase;
37 APTR i915MemPool;
39 extern ULONG allocated_mem;
40 extern struct g45staticdata sd;
41 #define sd ((struct g45staticdata*)&(sd))
43 struct Hidd915WinSys
45 struct HIDDT_WinSys base;
46 struct pipe_screen *pscreen;
49 static INLINE struct Hidd915WinSys *
50 Hidd915WinSys(struct pipe_winsys *ws)
52 return (struct Hidd915WinSys *)ws;
55 static VOID
56 HIDD915DestroyWinSys(struct pipe_winsys *ws)
58 struct Hidd915WinSys *hiddws = Hidd915WinSys(ws);
59 FREE(hiddws);
62 static VOID
63 HIDD915FlushFrontBuffer( struct pipe_screen *screen,
64 struct pipe_resource *resource,
65 unsigned level, unsigned layer,
66 void *winsys_drawable_handle )
68 /* No Op */
71 BOOL InitGalliumClass()
73 if( sd->force_gallium
74 || sd->ProductID == 0x2582 // GMA 900
75 || sd->ProductID == 0x2782
76 || sd->ProductID == 0x2592
77 || sd->ProductID == 0x2792
78 || sd->ProductID == 0x2772 // GMA 950
79 || sd->ProductID == 0x2776
80 || sd->ProductID == 0x27A2
81 || sd->ProductID == 0x27A6
82 || sd->ProductID == 0x27AE
83 || sd->ProductID == 0x2972 // GMA 3000
84 || sd->ProductID == 0x2973
85 || sd->ProductID == 0x2992
86 || sd->ProductID == 0x2993
88 CloseLibrary( OpenLibrary("gallium.library",0)); // ???
90 if((HiddGalliumAttrBase = OOP_ObtainAttrBase(IID_Hidd_Gallium)))
92 struct TagItem Gallium_tags[] =
94 {aMeta_SuperID , (IPTR)CLID_Hidd_Gallium },
95 {aMeta_InterfaceDescr, (IPTR)Gallium_ifdescr },
96 {aMeta_InstSize , sizeof(struct HIDDGalliumData)},
97 {aMeta_ID , (IPTR)CLID_Hidd_Gallium_IntelGMA},
98 {TAG_DONE, 0}
101 sd->galliumclass = OOP_NewObject(NULL, CLID_HiddMeta, Gallium_tags);
102 if (sd->galliumclass)
104 sd->galliumclass->UserData = sd;
105 OOP_AddClass(sd->galliumclass);
107 sd->basegallium = OOP_FindClass(CLID_Hidd_Gallium);
109 i915MemPool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR | MEMF_SEM_PROTECTED, 32 * 1024, 16 * 1024);
111 init_aros_winsys();
112 bug("i915 gallium init OK\n");
113 return TRUE;
116 OOP_ReleaseAttrBase(IID_Hidd_Gallium);
120 return FALSE;
124 /* PUBLIC METHODS */
125 OOP_Object *METHOD(i915Gallium, Root, New)
127 IPTR interfaceVers;
129 D(bug("[i915gallium] New\n"));
131 interfaceVers = GetTagData(aHidd_Gallium_InterfaceVersion, -1, msg->attrList);
132 if (interfaceVers != GALLIUM_INTERFACE_VERSION)
133 return NULL;
135 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
136 if(o)
141 return o;
145 VOID METHOD(i915Gallium, Root, Get)
147 ULONG idx;
148 D(bug("[i915gallium] get\n"));
149 if (IS_GALLIUM_ATTR(msg->attrID, idx))
151 switch (idx)
153 /* Overload the property */
154 case aoHidd_Gallium_InterfaceVersion:
155 *msg->storage = GALLIUM_INTERFACE_VERSION;
156 return;
160 /* Use parent class for all other properties */
161 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
164 APTR METHOD(i915Gallium, Hidd_Gallium, CreatePipeScreen)
167 bug("[i915gallium] CreatePipeScreen currently allocated_mem %d\n",allocated_mem);
169 struct Hidd915WinSys *hiddws;
170 struct aros_winsys *aws;
171 struct pipe_winsys *ws;
173 aws = winsys_create();
175 if (!aws) {
176 return NULL;
179 hiddws = CALLOC_STRUCT(Hidd915WinSys);
180 if (!hiddws) {
181 return NULL;
184 ws = &hiddws->base.base;
185 ws->destroy = HIDD915DestroyWinSys;
187 hiddws->pscreen = i915_screen_create( &aws->base );
188 if (!hiddws->pscreen) {
189 ws->destroy(ws);
190 return NULL;
193 hiddws->pscreen->flush_frontbuffer = HIDD915FlushFrontBuffer;
194 hiddws->pscreen->winsys = (struct pipe_winsys*)hiddws;
195 /* Preserve pointer to HIDD driver */
196 hiddws->base.driver = o;
198 return hiddws->pscreen;
202 VOID METHOD(i915Gallium, Hidd_Gallium, DisplayResource)
204 // bug("[i915gallium] DisplayResource\n");
206 #ifndef GALLIUM_SIMULATION
207 OOP_Object *bm = HIDD_BM_OBJ(msg->bitmap);
208 GMABitMap_t *bm_dst;
210 // if (!((IPTR)bm == (IPTR)sd.BMClass) ) return; // Check if bitmap is really intelGFX bitmap
212 bm_dst = OOP_INST_DATA(OOP_OCLASS(bm), bm);
213 struct i915_texture *tex = i915_texture(msg->resource);
215 IF_BAD_MAGIC(tex->buffer) return;
217 LOCK_BITMAP_BM(bm_dst)
219 uint32_t br00, br13, br22, br23, br09, br11, br26, br12;
220 int mode = 3;
222 br00 = (2 << 29) | (0x53 << 22) | (6);
223 if (bm_dst->bpp == 4)
224 br00 |= 3 << 20;
226 br13 = bm_dst->pitch | ROP_table[mode].rop;
227 if (bm_dst->bpp == 4)
228 br13 |= 3 << 24;
229 else if (bm_dst->bpp == 2)
230 br13 |= 1 << 24;
232 br22 = msg->dstx | (msg->dsty << 16);
233 br23 = (msg->dstx + msg->width) | (msg->dsty + msg->height) << 16;
234 br09 = bm_dst->framebuffer;
236 br11 = tex->stride;
237 br26 = msg->srcx | (msg->srcy << 16);
238 br12 = (IPTR)tex->buffer->map - (IPTR)sd->Card.Framebuffer;
240 while(buffer_is_busy(0,tex->buffer)){};
242 LOCK_HW
243 START_RING(8);
244 OUT_RING(br00);
245 OUT_RING(br13);
246 OUT_RING(br22);
247 OUT_RING(br23);
248 OUT_RING(br09);
249 OUT_RING(br26);
250 OUT_RING(br11);
251 OUT_RING(br12);
252 ADVANCE_RING();
253 //DO_FLUSH();
254 UNLOCK_HW
255 UNLOCK_BITMAP_BM(bm_dst)
256 #endif
257 destroy_unused_buffers();
261 static const struct OOP_MethodDescr Gallium_Root_descr[] =
263 {(OOP_MethodFunc)i915Gallium__Root__New, moRoot_New},
264 {(OOP_MethodFunc)i915Gallium__Root__Get, moRoot_Get},
265 {NULL, 0}
268 static const struct OOP_MethodDescr Gallium_Hidd_Gallium_descr[] =
270 {(OOP_MethodFunc)i915Gallium__Hidd_Gallium__CreatePipeScreen, moHidd_Gallium_CreatePipeScreen},
271 {(OOP_MethodFunc)i915Gallium__Hidd_Gallium__DisplayResource, moHidd_Gallium_DisplayResource},
272 {NULL, 0}
275 const struct OOP_InterfaceDescr Gallium_ifdescr[] =
277 {(struct OOP_MethodDescr*)Gallium_Root_descr, IID_Root, 2},
278 {(struct OOP_MethodDescr*)Gallium_Hidd_Gallium_descr, IID_Hidd_Gallium, 2},
279 {NULL, NULL,0}