Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / hidds / radeon / ati_init.c
blobc5e860110b185e185625cd423c37801727dd606e
1 /*
2 Copyright © 2003-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/symbolsets.h>
8 #include <exec/execbase.h>
9 #include <exec/types.h>
10 #include <exec/resident.h>
11 #include <exec/libraries.h>
12 #include <exec/memory.h>
13 #include <exec/lists.h>
14 #include <exec/semaphores.h>
15 #include <dos/bptr.h>
17 #include <utility/utility.h>
19 #define DEBUG 1
21 #include <proto/exec.h>
22 #include <proto/oop.h>
23 #include <aros/debug.h>
25 #include <hidd/i2c.h>
26 #include <hidd/pci.h>
27 #include <hidd/graphics.h>
29 #include "ati.h"
30 #include "ids.h"
31 #include "radeon.h"
32 #include "radeon_reg.h"
33 #include "radeon_macros.h"
34 #include LC_LIBDEFS_FILE
36 #undef HiddPCIDeviceAttrBase
37 #undef HiddGfxAttrBase
38 #undef HiddPixFmtAttrBase
39 #undef HiddSyncAttrBase
40 #undef HiddBitMapAttrBase
41 #undef HiddI2CAttrBase
42 #undef HiddI2CDeviceAttrBase
43 #define HiddPCIDeviceAttrBase (LIBBASE->sd.pciAttrBase)
44 #define HiddATIBitMapAttrBase (LIBBASE->sd.atiBitMapAttrBase)
45 #define HiddBitMapAttrBase (LIBBASE->sd.bitMapAttrBase)
46 #define HiddPixFmtAttrBase (LIBBASE->sd.pixFmtAttrBase)
47 #define HiddGfxAttrBase (LIBBASE->sd.gfxAttrBase)
48 #define HiddSyncAttrBase (LIBBASE->sd.syncAttrBase)
49 #define HiddI2CAttrBase (LIBBASE->sd.i2cAttrBase)
50 #define HiddI2CDeviceAttrBase (LIBBASE->sd.i2cDeviceAttrBase)
51 #define __IHidd_PlanarBM (LIBBASE->sd.planarAttrBase)
53 static
54 AROS_UFH3(void, Enumerator,
55 AROS_UFHA(struct Hook *,hook, A0),
56 AROS_UFHA(OOP_Object *, pciDevice, A2),
57 AROS_UFHA(APTR, message, A1))
59 AROS_USERFUNC_INIT
60 LIBBASETYPEPTR LIBBASE = (LIBBASETYPEPTR)hook->h_Data;
61 struct ati_staticdata *sd = &LIBBASE->sd;
63 struct ATIDevice *sup = (struct ATIDevice *)support;
64 IPTR ProductID;
65 IPTR VendorID;
67 if (sd->PCIDevice != NULL)
68 return;
70 /* Get the Device's ProductID */
71 OOP_GetAttr(pciDevice, aHidd_PCIDevice_ProductID, &ProductID);
72 OOP_GetAttr(pciDevice, aHidd_PCIDevice_VendorID, &VendorID);
74 D(bug("[ATI] Enumerator: checking productid %04x vendorid %04x %08x\n",
75 ProductID, VendorID, pciDevice));
77 /* And try to match it with supported cards */
78 while (sup->VendorID)
80 BOOL found = FALSE;
82 if (sup->VendorID == VendorID)
84 if (!sup->masked_check && (sup->ProductID == ProductID))
86 found = TRUE;
88 else if (sup->masked_check && (sup->ProductID == (ProductID & 0xFFF0)))
90 found = TRUE;
94 if (found)
96 /* Matching card found */
97 APTR buf;
98 ULONG size;
99 OOP_Object *driver;
100 struct MemChunk *mc;
102 struct TagItem attrs[] = {
103 { aHidd_PCIDevice_isIO, TRUE }, /* Don't listen IO transactions */
104 { aHidd_PCIDevice_isMEM, TRUE }, /* Listen to MEM transactions */
105 { aHidd_PCIDevice_isMaster, TRUE }, /* Can work in BusMaster */
106 { TAG_DONE, 0UL },
109 D(bug("[ATI] Enumerator: found productid %04x vendorid %04x masked_check %d\n",
110 sup->ProductID, sup->VendorID, sup->masked_check));
112 sd->Card.ProductID = ProductID;
113 sd->Card.VendorID = VendorID;
114 sd->Card.Type = sup->Type;
117 Fix PCI device attributes (perhaps already set, but if the
118 ATI would be the second card in the system, it may stay
119 uninitialized.
121 OOP_SetAttrs(pciDevice, (struct TagItem*)&attrs);
123 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Driver, (APTR)&driver);
124 sd->PCIDriver = driver;
126 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Base0, (APTR)&buf);
127 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size0, (APTR)&size);
129 sd->Card.FbAddress = (IPTR)buf;
130 sd->Card.FrameBuffer = (IPTR)HIDD_PCIDriver_MapPCI(driver, buf, size);
131 mc = (struct MemChunk *)sd->Card.FrameBuffer;
133 sd->CardMem.mh_Node.ln_Type = NT_MEMORY;
134 sd->CardMem.mh_Node.ln_Name = "ATI Framebuffer";
135 sd->CardMem.mh_First = mc;
136 sd->CardMem.mh_Lower = (APTR)mc;
138 D(bug("[ATI] Got framebuffer @ %x (size=%dMiB)\n", sd->Card.FrameBuffer, size>>20));
140 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Base2, (APTR)&buf);
141 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size2, (APTR)&size);
143 sd->Card.MMIO = (APTR)HIDD_PCIDriver_MapPCI(driver, buf, size);
144 D(bug("[ATI] Got registers @ %x (size=%dKiB)\n", sd->Card.MMIO, size>>10));
146 OOP_GetAttr(pciDevice, aHidd_PCIDevice_RomBase, (APTR)&buf);
147 OOP_GetAttr(pciDevice, aHidd_PCIDevice_RomSize, (APTR)&size);
149 D(bug("[ATI] RomBase provided by ATI card: %x\n", buf));
151 if (buf)
152 sd->Card.vbios_org = (APTR)HIDD_PCIDriver_MapPCI(driver, buf, size);
153 else
154 sd->Card.vbios_org = (APTR)HIDD_PCIDriver_MapPCI(driver, (APTR)0x000c0000, size);
155 sd->Card.VBIOS = sd->Card.vbios_org;
156 D(bug("[ATI] Got BIOS @ %x (size=%dKiB)\n", sd->Card.VBIOS, size>>10));
158 if (sup->Init(sd))
160 sd->poweron_state = AllocPooled(sd->memPool, sizeof(struct CardState));
161 SaveState(sd, sd->poweron_state);
163 sd->CardMem.mh_Free = sd->Card.FbUsableSize;
164 sd->CardMem.mh_Upper = (APTR)(sd->CardMem.mh_Free + (IPTR)mc);
166 mc->mc_Next = NULL;
167 mc->mc_Bytes = sd->CardMem.mh_Free;
169 D(bug("[ATI] Usable size: %dKB\n", sd->CardMem.mh_Free >> 10));
171 sd->scratch_buffer = AllocBitmapArea(sd, 4096, 16, 4, TRUE);
172 sd->Card.CursorStart = AllocBitmapArea(sd, 64, 64, 4, TRUE);
173 sd->cpuscratch = AllocPooled(sd->memPool, 4096*4);
175 OUTREG(RADEON_CUR_HORZ_VERT_OFF,RADEON_CUR_LOCK | 0);
176 OUTREG(RADEON_CUR_HORZ_VERT_POSN,RADEON_CUR_LOCK | 0);
177 OUTREG(RADEON_CUR_OFFSET, sd->Card.CursorStart);
179 sd->PCIDevice = pciDevice;
181 /*-------- DO NOT CHANGE/REMOVE -------------*/
182 bug("\003\n"); /* Tell vga text mode debug output to die */
183 /*-------- DO NOT CHANGE/REMOVE -------------*/
185 else
187 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size0, (APTR)&size);
188 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.FrameBuffer, size);
189 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size2, (APTR)&size);
190 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.MMIO, size);
191 OOP_GetAttr(pciDevice, aHidd_PCIDevice_RomSize, (APTR)&size);
192 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.vbios_org, size);
193 sd->PCIDevice = NULL;
196 break;
199 sup++;
202 D(bug("[ATI] Enumerator found a card (ProductID=%04x)\n", ProductID));
203 D(bug("[ATI] The card is %ssupported\n",
204 sd->PCIDevice ? "":"un"));
206 AROS_USERFUNC_EXIT
209 static int ATI_Init(LIBBASETYPEPTR LIBBASE)
211 struct ati_staticdata *sd = &LIBBASE->sd;
213 struct OOP_ABDescr attrbases[] =
215 { (STRPTR)IID_Hidd_PCIDevice, &HiddPCIDeviceAttrBase },
216 { (STRPTR)IID_Hidd_BitMap, &HiddBitMapAttrBase },
217 { (STRPTR)IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
218 { (STRPTR)IID_Hidd_Sync, &HiddSyncAttrBase },
219 { (STRPTR)IID_Hidd_Gfx, &HiddGfxAttrBase },
220 { (STRPTR)IID_Hidd_ATIBitMap, &HiddATIBitMapAttrBase },
221 { (STRPTR)IID_Hidd_I2C, &HiddI2CAttrBase },
222 { (STRPTR)IID_Hidd_I2CDevice, &HiddI2CDeviceAttrBase },
223 { (STRPTR)IID_Hidd_PlanarBM, &__IHidd_PlanarBM },
224 { NULL, NULL }
227 D(bug("[ATI] Init\n"));
229 sd->memPool = CreatePool(MEMF_CLEAR | MEMF_PUBLIC | MEMF_SEM_PROTECTED, 8192, 4096);
231 if (sd->memPool)
233 if (OOP_ObtainAttrBases(attrbases))
235 sd->mid_CopyMemBox8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox8);
236 sd->mid_CopyMemBox16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox16);
237 sd->mid_CopyMemBox32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox32);
238 sd->mid_PutMem32Image8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMem32Image8);
239 sd->mid_PutMem32Image16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMem32Image16);
240 sd->mid_GetMem32Image8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_GetMem32Image8);
241 sd->mid_GetMem32Image16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_GetMem32Image16);
242 sd->mid_Clear = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_Clear);
243 sd->mid_PutMemTemplate8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate8);
244 sd->mid_PutMemTemplate16= OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate16);
245 sd->mid_PutMemTemplate32= OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate32);
246 sd->mid_PutMemPattern8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern8);
247 sd->mid_PutMemPattern16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern16);
248 sd->mid_PutMemPattern32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern32);
249 sd->mid_CopyLUTMemBox16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyLUTMemBox16);
250 sd->mid_CopyLUTMemBox32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyLUTMemBox32);
251 sd->mid_GetImage = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_GetImage);
253 LIBBASE->sd.basebm = OOP_FindClass(CLID_Hidd_BitMap);
255 InitSemaphore(&LIBBASE->sd.HWLock);
256 InitSemaphore(&LIBBASE->sd.MultiBMLock);
257 InitSemaphore(&LIBBASE->sd.CardMemLock);
259 /* Initialize MsgPort */
260 LIBBASE->sd.mp.mp_SigBit = SIGB_SINGLE;
261 LIBBASE->sd.mp.mp_Flags = PA_SIGNAL;
262 LIBBASE->sd.mp.mp_SigTask = FindTask(NULL);
263 LIBBASE->sd.mp.mp_Node.ln_Type = NT_MSGPORT;
264 NEWLIST(&LIBBASE->sd.mp.mp_MsgList);
266 LIBBASE->sd.tr.tr_node.io_Message.mn_ReplyPort = &LIBBASE->sd.mp;
267 LIBBASE->sd.tr.tr_node.io_Message.mn_Length = sizeof(LIBBASE->sd.tr);
269 if (!OpenDevice((STRPTR)"timer.device", UNIT_MICROHZ, (struct IORequest *)&LIBBASE->sd.tr, 0))
271 if ((LIBBASE->sd.PCIObject = OOP_NewObject(NULL, (STRPTR)CLID_Hidd_PCI, NULL)))
273 struct Hook FindHook = {
274 h_Entry: (IPTR (*)())Enumerator,
275 h_Data: LIBBASE,
278 struct TagItem Requirements[] = {
279 { tHidd_PCI_Interface, 0x00 },
280 { tHidd_PCI_Class, 0x03 },
281 { tHidd_PCI_SubClass, 0x00 },
282 { tHidd_PCI_VendorID, 0x1002 }, // ATI VendorID. May require more of them
283 { TAG_DONE, 0UL }
286 HIDD_PCI_EnumDevices(LIBBASE->sd.PCIObject, &FindHook, Requirements);
288 if (sd->PCIDevice)
289 return TRUE;
291 D(bug("[ATI] No supported cards found\n"));
293 CloseDevice((struct IORequest *)&LIBBASE->sd.tr);
298 return FALSE;
301 static int ATI_Expunge(LIBBASETYPEPTR LIBBASE)
303 struct ati_staticdata *sd = &LIBBASE->sd;
305 struct OOP_ABDescr attrbases[] =
307 { (STRPTR)IID_Hidd_PCIDevice, &HiddPCIDeviceAttrBase },
308 { (STRPTR)IID_Hidd_BitMap, &HiddBitMapAttrBase },
309 { (STRPTR)IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
310 { (STRPTR)IID_Hidd_Sync, &HiddSyncAttrBase },
311 { (STRPTR)IID_Hidd_Gfx, &HiddGfxAttrBase },
312 { (STRPTR)IID_Hidd_ATIBitMap, &HiddATIBitMapAttrBase },
313 { (STRPTR)IID_Hidd_I2C, &HiddI2CAttrBase },
314 { (STRPTR)IID_Hidd_I2CDevice, &HiddI2CDeviceAttrBase },
315 { (STRPTR)IID_Hidd_PlanarBM, &__IHidd_PlanarBM },
316 { NULL, NULL }
319 if (sd->PCIDevice)
321 IPTR size;
322 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_Size0, (APTR)&size);
323 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.FrameBuffer, size);
324 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_Size2, (APTR)&size);
325 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.MMIO, size);
326 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_RomSize, (APTR)&size);
327 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.vbios_org, size);
328 sd->PCIDevice = NULL;
331 if (sd->PCIObject)
332 OOP_DisposeObject(sd->PCIObject);
333 OOP_ReleaseAttrBases(attrbases);
334 if (sd->memPool)
335 DeletePool(sd->memPool);
337 return TRUE;
340 ADD2INITLIB(ATI_Init, 0)
341 ADD2EXPUNGELIB(ATI_Expunge, 0)
342 ADD2LIBS((STRPTR)"graphics.hidd", 0, static struct Library *, __gfxbase);