Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / monitors / IntelGMA / startup.c
blob24e360a99c3f3ec1fd2cd19ece4deef4feb14c9c
1 /*
2 Copyright © 2011-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <dos/dosextens.h>
8 #include <hidd/graphics.h>
9 #include <hidd/hidd.h>
10 #include <workbench/startup.h>
11 #include <workbench/workbench.h>
12 #include <proto/dos.h>
13 #include <proto/exec.h>
14 #include <proto/graphics.h>
15 #include <proto/icon.h>
16 #include <proto/oop.h>
18 #include <stdlib.h>
19 #include <string.h>
21 #include "intelG45_intern.h"
22 #include "compositing_intern.h"
23 #include "gallium_intern.h"
25 struct Library *OOPBase;
26 struct Library *UtilityBase;
27 struct Library *StdCBase;
28 struct Library *StdCIOBase;
30 OOP_AttrBase HiddPCIDeviceAttrBase;
31 OOP_AttrBase HiddGMABitMapAttrBase;
32 OOP_AttrBase HiddI2CAttrBase;
33 OOP_AttrBase HiddI2CDeviceAttrBase;
34 OOP_AttrBase HiddGCAttrBase;
35 OOP_AttrBase HiddCompositingAttrBase;
36 OOP_AttrBase MetaAttrBase;
37 OOP_AttrBase HiddAttrBase;
38 OOP_AttrBase HiddPCIDeviceAttrBase;
39 OOP_AttrBase HiddGMABitMapAttrBase;
40 OOP_AttrBase HiddPixFmtAttrBase;
41 OOP_AttrBase HiddBitMapAttrBase;
42 OOP_AttrBase HiddColorMapAttrBase;
43 OOP_AttrBase HiddSyncAttrBase;
44 OOP_AttrBase HiddGfxAttrBase;
45 OOP_AttrBase __IHidd_PlanarBM;
47 /*
48 * Class static data is really static now. :)
49 * If the driver would be compiled as a ROM resident, this structure
50 * needs to be allocated using AllocMem()
52 struct g45staticdata sd;
54 static const struct OOP_ABDescr attrbases[] =
56 {IID_Meta , &MetaAttrBase },
57 {IID_Hidd , &HiddAttrBase },
58 {IID_Hidd_PCIDevice , &HiddPCIDeviceAttrBase },
59 {IID_Hidd_BitMap , &HiddBitMapAttrBase },
60 {IID_Hidd_PixFmt , &HiddPixFmtAttrBase },
61 {IID_Hidd_Sync , &HiddSyncAttrBase },
62 {IID_Hidd_Gfx , &HiddGfxAttrBase },
63 {IID_Hidd_BitMap_IntelGMA, &HiddGMABitMapAttrBase },
64 {IID_Hidd_I2C , &HiddI2CAttrBase },
65 {IID_Hidd_I2CDevice , &HiddI2CDeviceAttrBase },
66 {IID_Hidd_PlanarBM , &__IHidd_PlanarBM },
67 {IID_Hidd_GC , &HiddGCAttrBase },
68 {IID_Hidd_Compositing , &HiddCompositingAttrBase},
69 {NULL, NULL }
72 const TEXT version_string[] = "$VER: IntelGMA 3.12 (18.8.2015)\n";
74 extern struct WBStartup *WBenchMsg;
75 int __nocommandline = 1;
77 int main(void)
79 BPTR olddir = BNULL;
80 STRPTR myname;
81 struct DiskObject *icon;
82 struct RDArgs *rdargs = NULL;
83 IPTR args[2] = {0};
84 int ret = RETURN_FAIL;
85 BOOL success = TRUE;
87 /*
88 * Open libraries manually, otherwise they will be closed
89 * when this subroutine exits. Driver needs them.
91 OOPBase = OpenLibrary("oop.library", 42);
92 if (OOPBase == NULL)
93 success = FALSE;
96 * If our class is already registered, the user attempts to run us twice.
97 * Just ignore this.
99 if (success)
101 if (OOP_FindClass(CLID_Hidd_Gfx_IntelGMA))
103 success = FALSE;
104 ret = RETURN_OK;
108 UtilityBase = OpenLibrary("utility.library", 36);
109 StdCBase = OpenLibrary("stdc.library", 0);
110 StdCIOBase = OpenLibrary("stdcio.library", 0);
111 if (UtilityBase == NULL || StdCBase == NULL || StdCIOBase == NULL)
112 success = FALSE;
114 if (success)
116 memset(&sd, 0, sizeof(sd));
118 /* We don't open dos.library and icon.library manually because only startup code
119 needs them and these libraries can be closed even upon successful exit */
120 if (WBenchMsg)
122 olddir = CurrentDir(WBenchMsg->sm_ArgList[0].wa_Lock);
123 myname = WBenchMsg->sm_ArgList[0].wa_Name;
125 else
127 struct Process *me = (struct Process *)FindTask(NULL);
129 if (me->pr_CLI)
131 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
133 myname = AROS_BSTR_ADDR(cli->cli_CommandName);
135 else
136 myname = me->pr_Task.tc_Node.ln_Name;
139 icon = GetDiskObject(myname);
141 if (icon)
143 STRPTR str;
145 str = FindToolType(icon->do_ToolTypes, "FORCEGMA");
146 args[0] = str ? TRUE : FALSE;
148 str = FindToolType(icon->do_ToolTypes, "FORCEGALLIUM");
149 args[1] = str ? TRUE : FALSE;
152 if (!WBenchMsg)
153 rdargs = ReadArgs("FORCEGMA/S,FORCEGALLIUM/S", args, NULL);
155 sd.forced = args[0];
156 sd.force_gallium = args[1];
158 if (rdargs)
159 FreeArgs(rdargs);
160 if (icon)
161 FreeDiskObject(icon);
162 if (olddir)
163 CurrentDir(olddir);
166 /* Obtain attribute bases first */
167 if (success)
169 if (!OOP_ObtainAttrBases(attrbases))
170 success = FALSE;
173 sd.basegc = OOP_FindClass(CLID_Hidd_GC);
174 sd.basebm = OOP_FindClass(CLID_Hidd_BitMap);
176 if (success)
178 struct TagItem INTELG45_tags[] =
180 {aMeta_SuperID , (IPTR)CLID_Hidd_Gfx },
181 {aMeta_InterfaceDescr, (IPTR)INTELG45_ifdescr },
182 {aMeta_InstSize , sizeof(struct g45data) },
183 {aMeta_ID , (IPTR)CLID_Hidd_Gfx_IntelGMA},
184 {TAG_DONE, 0}
187 /* Create classes */
188 sd.IntelG45Class = OOP_NewObject(NULL, CLID_HiddMeta, INTELG45_tags);
189 if (sd.IntelG45Class)
191 struct TagItem GMABM_tags[] =
193 {aMeta_SuperID , (IPTR)CLID_Hidd_BitMap},
194 {aMeta_InterfaceDescr, (IPTR)GMABM_ifdescr },
195 {aMeta_InstSize , sizeof(GMABitMap_t) },
196 {aMeta_ID , (IPTR)CLID_Hidd_BitMap_IntelGMA},
197 {TAG_DONE, 0}
200 /* According to a tradition, we store a pointer to static data in class' UserData */
201 sd.IntelG45Class->UserData = &sd;
203 sd.BMClass = OOP_NewObject(NULL, CLID_HiddMeta, GMABM_tags);
204 if (sd.BMClass)
206 struct TagItem INTELI2C_tags[] =
208 {aMeta_SuperID , (IPTR)CLID_Hidd_I2C },
209 {aMeta_InterfaceDescr, (IPTR)INTELI2C_ifdescr},
210 {aMeta_InstSize , sizeof(struct i2cdata)},
211 {TAG_DONE, 0}
214 sd.BMClass->UserData = &sd;
216 sd.IntelI2C = OOP_NewObject(NULL, CLID_HiddMeta, INTELI2C_tags);
217 if (sd.IntelI2C)
219 struct TagItem Compositing_tags[] =
221 {aMeta_SuperID , (IPTR)CLID_Hidd},
222 {aMeta_InterfaceDescr, (IPTR)Compositing_ifdescr},
223 {aMeta_InstSize , sizeof(struct HIDDCompositingData)},
224 {TAG_DONE, 0}
227 sd.IntelI2C->UserData = &sd;
229 sd.compositingclass = OOP_NewObject(NULL, CLID_HiddMeta, Compositing_tags);
230 if (sd.compositingclass)
233 #ifndef GALLIUM_SIMULATION
234 /* Init internal stuff */
235 if (G45_Init(&sd))
236 #endif
238 struct Process *me = (struct Process *)FindTask(NULL);
240 #ifndef GALLIUM_SIMULATION
242 * Register our gfx class as public, we use it as a
243 * protection against double start
245 OOP_AddClass(sd.IntelG45Class);
246 #endif
248 /* Init Galliumclass */
249 InitGalliumClass();
251 /* Everything is okay, stay resident and exit */
253 D(bug("[SDL] Staying resident, process 0x%p\n", me));
254 if (me->pr_CLI)
256 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
258 cli->cli_Module = BNULL;
260 else
261 me->pr_SegList = BNULL;
264 * Note also that we don't close needed libraries and
265 * don't free attribute bases
267 return RETURN_OK;
269 OOP_DisposeObject((OOP_Object *)sd.compositingclass);
271 OOP_DisposeObject((OOP_Object *)sd.IntelI2C);
273 OOP_DisposeObject((OOP_Object *)sd.BMClass);
275 OOP_DisposeObject((OOP_Object *)sd.IntelG45Class);
277 OOP_ReleaseAttrBases(attrbases);
280 if (StdCIOBase != NULL)
281 CloseLibrary(StdCIOBase);
282 if (StdCBase != NULL)
283 CloseLibrary(StdCBase);
284 if (UtilityBase != NULL)
285 CloseLibrary(UtilityBase);
286 if (OOPBase != NULL)
287 CloseLibrary(OOPBase);
289 return ret;