revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / devs / monitors / IntelGMA / intelgma_startup.c
blob2be3f577691e0c5be4948cd3327eea18c3a062f9
1 /*
2 Copyright © 2011-2019, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <dos/dosextens.h>
8 #include <hidd/gfx.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 "intelgma_hidd.h"
22 #include "intelgma_compositor.h"
23 #include "intelgma_gallium.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 HiddCompositorAttrBase;
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_Compositor , &HiddCompositorAttrBase},
69 {NULL, NULL }
72 const TEXT version_string[] = "$VER: IntelGMA 3.13 (17.10.2016)\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);
175 sd.basei2c = OOP_FindClass(CLID_Hidd_I2C);
177 if (success)
179 struct TagItem INTELG45_tags[] =
181 {aMeta_SuperID , (IPTR)CLID_Hidd_Gfx },
182 {aMeta_InterfaceDescr, (IPTR)INTELG45_ifdescr },
183 {aMeta_InstSize , sizeof(struct g45data) },
184 {aMeta_ID , (IPTR)CLID_Hidd_Gfx_IntelGMA},
185 {TAG_DONE, 0}
188 /* Create classes */
189 sd.IntelG45Class = OOP_NewObject(NULL, CLID_HiddMeta, INTELG45_tags);
190 if (sd.IntelG45Class)
192 struct TagItem GMABM_tags[] =
194 {aMeta_SuperID , (IPTR)CLID_Hidd_BitMap},
195 {aMeta_InterfaceDescr, (IPTR)GMABM_ifdescr },
196 {aMeta_InstSize , sizeof(GMABitMap_t) },
197 {aMeta_ID , (IPTR)CLID_Hidd_BitMap_IntelGMA},
198 {TAG_DONE, 0}
201 /* According to a tradition, we store a pointer to static data in class' UserData */
202 sd.IntelG45Class->UserData = &sd;
204 sd.BMClass = OOP_NewObject(NULL, CLID_HiddMeta, GMABM_tags);
205 if (sd.BMClass)
207 struct TagItem INTELI2C_tags[] =
209 {aMeta_SuperID , (IPTR)CLID_Hidd_I2C },
210 {aMeta_InterfaceDescr, (IPTR)INTELI2C_ifdescr},
211 {aMeta_InstSize , sizeof(struct i2cdata)},
212 {TAG_DONE, 0}
215 sd.BMClass->UserData = &sd;
217 sd.IntelI2C = OOP_NewObject(NULL, CLID_HiddMeta, INTELI2C_tags);
218 if (sd.IntelI2C)
220 struct TagItem Compositor_tags[] =
222 {aMeta_SuperID , (IPTR)CLID_Hidd},
223 {aMeta_InterfaceDescr, (IPTR)Compositor_ifdescr},
224 {aMeta_InstSize , sizeof(struct HIDDCompositorData)},
225 {TAG_DONE, 0}
228 sd.IntelI2C->UserData = &sd;
230 sd.compositorclass = OOP_NewObject(NULL, CLID_HiddMeta, Compositor_tags);
231 if (sd.compositorclass)
234 #ifndef GALLIUM_SIMULATION
235 /* Init internal stuff */
236 if (G45_Init(&sd))
237 #endif
239 struct Process *me = (struct Process *)FindTask(NULL);
241 #ifndef GALLIUM_SIMULATION
243 * Register our gfx class as public, we use it as a
244 * protection against double start
246 OOP_AddClass(sd.IntelG45Class);
247 #endif
249 /* Init Galliumclass */
250 InitGalliumClass();
252 /* Everything is okay, stay resident and exit */
254 D(bug("[SDL] Staying resident, process 0x%p\n", me));
255 if (me->pr_CLI)
257 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
259 cli->cli_Module = BNULL;
261 else
262 me->pr_SegList = BNULL;
265 * Note also that we don't close needed libraries and
266 * don't free attribute bases
268 return RETURN_OK;
270 OOP_DisposeObject((OOP_Object *)sd.compositorclass);
272 OOP_DisposeObject((OOP_Object *)sd.IntelI2C);
274 OOP_DisposeObject((OOP_Object *)sd.BMClass);
276 OOP_DisposeObject((OOP_Object *)sd.IntelG45Class);
278 OOP_ReleaseAttrBases(attrbases);
281 if (StdCIOBase != NULL)
282 CloseLibrary(StdCIOBase);
283 if (StdCBase != NULL)
284 CloseLibrary(StdCBase);
285 if (UtilityBase != NULL)
286 CloseLibrary(UtilityBase);
287 if (OOPBase != NULL)
288 CloseLibrary(OOPBase);
290 return ret;