revert between 56095 -> 55830 in arch
[AROS.git] / workbench / hidds / radeon / ati_init.c
blob55ed2d2b912a2708c901487228189b5b2542313c
1 /*
2 Copyright © 2003-2017, 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/gfx.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 HiddAttrBase
37 #undef HiddPCIDeviceAttrBase
38 #undef HiddGfxAttrBase
39 #undef HiddPixFmtAttrBase
40 #undef HiddSyncAttrBase
41 #undef HiddBitMapAttrBase
42 #undef HiddI2CAttrBase
43 #undef HiddI2CDeviceAttrBase
44 #define HiddAttrBase (LIBBASE->sd.hiddAttrBase)
45 #define HiddPCIDeviceAttrBase (LIBBASE->sd.pciAttrBase)
46 #define HiddATIBitMapAttrBase (LIBBASE->sd.atiBitMapAttrBase)
47 #define HiddBitMapAttrBase (LIBBASE->sd.bitMapAttrBase)
48 #define HiddPixFmtAttrBase (LIBBASE->sd.pixFmtAttrBase)
49 #define HiddGfxAttrBase (LIBBASE->sd.gfxAttrBase)
50 #define HiddSyncAttrBase (LIBBASE->sd.syncAttrBase)
51 #define HiddI2CAttrBase (LIBBASE->sd.i2cAttrBase)
52 #define HiddI2CDeviceAttrBase (LIBBASE->sd.i2cDeviceAttrBase)
53 #define __IHidd_PlanarBM (LIBBASE->sd.planarAttrBase)
55 static
56 AROS_UFH3(void, Enumerator,
57 AROS_UFHA(struct Hook *,hook, A0),
58 AROS_UFHA(OOP_Object *, pciDevice, A2),
59 AROS_UFHA(APTR, message, A1))
61 AROS_USERFUNC_INIT
62 LIBBASETYPEPTR LIBBASE = (LIBBASETYPEPTR)hook->h_Data;
63 struct ati_staticdata *sd = &LIBBASE->sd;
65 struct ATIDevice *sup = (struct ATIDevice *)support;
66 IPTR ProductID;
67 IPTR VendorID;
69 if (sd->PCIDevice != NULL)
70 return;
72 /* Get the Device's ProductID */
73 OOP_GetAttr(pciDevice, aHidd_PCIDevice_ProductID, &ProductID);
74 OOP_GetAttr(pciDevice, aHidd_PCIDevice_VendorID, &VendorID);
76 D(bug("[ATI] Enumerator: checking productid %04x vendorid %04x %08x\n",
77 ProductID, VendorID, pciDevice));
79 /* And try to match it with supported cards */
80 while (sup->VendorID)
82 BOOL found = FALSE;
84 if (sup->VendorID == VendorID)
86 if (!sup->masked_check && (sup->ProductID == ProductID))
88 found = TRUE;
90 else if (sup->masked_check && (sup->ProductID == (ProductID & 0xFFF0)))
92 found = TRUE;
96 if (found)
98 /* Matching card found */
99 APTR buf;
100 ULONG size;
101 OOP_Object *driver;
102 struct MemChunk *mc;
104 struct TagItem attrs[] = {
105 { aHidd_PCIDevice_isIO, TRUE }, /* Don't listen IO transactions */
106 { aHidd_PCIDevice_isMEM, TRUE }, /* Listen to MEM transactions */
107 { aHidd_PCIDevice_isMaster, TRUE }, /* Can work in BusMaster */
108 { TAG_DONE, 0UL },
111 D(bug("[ATI] Enumerator: found productid %04x vendorid %04x masked_check %d\n",
112 sup->ProductID, sup->VendorID, sup->masked_check));
114 sd->Card.ProductID = ProductID;
115 sd->Card.VendorID = VendorID;
116 sd->Card.Type = sup->Type;
119 Fix PCI device attributes (perhaps already set, but if the
120 ATI would be the second card in the system, it may stay
121 uninitialized.
123 OOP_SetAttrs(pciDevice, (struct TagItem*)&attrs);
125 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Driver, (APTR)&driver);
126 sd->PCIDriver = driver;
128 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Base0, (APTR)&buf);
129 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size0, (APTR)&size);
131 sd->Card.FbAddress = (IPTR)buf;
132 sd->Card.FrameBuffer = (IPTR)HIDD_PCIDriver_MapPCI(driver, buf, size);
133 mc = (struct MemChunk *)sd->Card.FrameBuffer;
135 sd->CardMem.mh_Node.ln_Type = NT_MEMORY;
136 sd->CardMem.mh_Node.ln_Name = "ATI Framebuffer";
137 sd->CardMem.mh_First = mc;
138 sd->CardMem.mh_Lower = (APTR)mc;
140 D(bug("[ATI] Got framebuffer @ %x (size=%dMiB)\n", sd->Card.FrameBuffer, size>>20));
142 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Base2, (APTR)&buf);
143 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size2, (APTR)&size);
145 sd->Card.MMIO = (APTR)HIDD_PCIDriver_MapPCI(driver, buf, size);
146 D(bug("[ATI] Got registers @ %x (size=%dKiB)\n", sd->Card.MMIO, size>>10));
148 OOP_GetAttr(pciDevice, aHidd_PCIDevice_RomBase, (APTR)&buf);
149 OOP_GetAttr(pciDevice, aHidd_PCIDevice_RomSize, (APTR)&size);
151 D(bug("[ATI] RomBase provided by ATI card: %x\n", buf));
153 if (buf)
154 sd->Card.vbios_org = (APTR)HIDD_PCIDriver_MapPCI(driver, buf, size);
155 else
156 sd->Card.vbios_org = (APTR)HIDD_PCIDriver_MapPCI(driver, (APTR)0x000c0000, size);
157 sd->Card.VBIOS = sd->Card.vbios_org;
158 D(bug("[ATI] Got BIOS @ %x (size=%dKiB)\n", sd->Card.VBIOS, size>>10));
160 if (sup->Init(sd))
162 sd->poweron_state = AllocPooled(sd->memPool, sizeof(struct CardState));
163 SaveState(sd, sd->poweron_state);
165 sd->CardMem.mh_Free = sd->Card.FbUsableSize;
166 sd->CardMem.mh_Upper = (APTR)(sd->CardMem.mh_Free + (IPTR)mc);
168 mc->mc_Next = NULL;
169 mc->mc_Bytes = sd->CardMem.mh_Free;
171 D(bug("[ATI] Usable size: %dKB\n", sd->CardMem.mh_Free >> 10));
173 sd->scratch_buffer = AllocBitmapArea(sd, 4096, 16, 4, TRUE);
174 sd->Card.CursorStart = AllocBitmapArea(sd, 64, 64, 4, TRUE);
175 sd->cpuscratch = AllocPooled(sd->memPool, 4096*4);
177 OUTREG(RADEON_CUR_HORZ_VERT_OFF,RADEON_CUR_LOCK | 0);
178 OUTREG(RADEON_CUR_HORZ_VERT_POSN,RADEON_CUR_LOCK | 0);
179 OUTREG(RADEON_CUR_OFFSET, sd->Card.CursorStart);
181 sd->PCIDevice = pciDevice;
183 /*-------- DO NOT CHANGE/REMOVE -------------*/
184 bug("\003\n"); /* Tell vga text mode debug output to die */
185 /*-------- DO NOT CHANGE/REMOVE -------------*/
187 else
189 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size0, (APTR)&size);
190 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.FrameBuffer, size);
191 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size2, (APTR)&size);
192 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.MMIO, size);
193 OOP_GetAttr(pciDevice, aHidd_PCIDevice_RomSize, (APTR)&size);
194 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.vbios_org, size);
195 sd->PCIDevice = NULL;
198 break;
201 sup++;
204 D(bug("[ATI] Enumerator found a card (ProductID=%04x)\n", ProductID));
205 D(bug("[ATI] The card is %ssupported\n",
206 sd->PCIDevice ? "":"un"));
208 AROS_USERFUNC_EXIT
211 static int ATI_Init(LIBBASETYPEPTR LIBBASE)
213 struct ati_staticdata *sd = &LIBBASE->sd;
215 struct OOP_ABDescr attrbases[] =
217 { (STRPTR)IID_Hidd, &HiddAttrBase },
218 { (STRPTR)IID_Hidd_PCIDevice, &HiddPCIDeviceAttrBase },
219 { (STRPTR)IID_Hidd_BitMap, &HiddBitMapAttrBase },
220 { (STRPTR)IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
221 { (STRPTR)IID_Hidd_Sync, &HiddSyncAttrBase },
222 { (STRPTR)IID_Hidd_Gfx, &HiddGfxAttrBase },
223 { (STRPTR)IID_Hidd_BitMap_ATI, &HiddATIBitMapAttrBase },
224 { (STRPTR)IID_Hidd_I2C, &HiddI2CAttrBase },
225 { (STRPTR)IID_Hidd_I2CDevice, &HiddI2CDeviceAttrBase },
226 { (STRPTR)IID_Hidd_PlanarBM, &__IHidd_PlanarBM },
227 { NULL, NULL }
230 D(bug("[ATI] Init\n"));
232 sd->memPool = CreatePool(MEMF_CLEAR | MEMF_PUBLIC | MEMF_SEM_PROTECTED, 8192, 4096);
234 if (sd->memPool)
236 if (OOP_ObtainAttrBases(attrbases))
238 sd->mid_CopyMemBox8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox8);
239 sd->mid_CopyMemBox16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox16);
240 sd->mid_CopyMemBox32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox32);
241 sd->mid_PutMem32Image8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMem32Image8);
242 sd->mid_PutMem32Image16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMem32Image16);
243 sd->mid_GetMem32Image8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_GetMem32Image8);
244 sd->mid_GetMem32Image16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_GetMem32Image16);
245 sd->mid_Clear = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_Clear);
246 sd->mid_PutMemTemplate8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate8);
247 sd->mid_PutMemTemplate16= OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate16);
248 sd->mid_PutMemTemplate32= OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate32);
249 sd->mid_PutMemPattern8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern8);
250 sd->mid_PutMemPattern16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern16);
251 sd->mid_PutMemPattern32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern32);
252 sd->mid_CopyLUTMemBox16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyLUTMemBox16);
253 sd->mid_CopyLUTMemBox32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyLUTMemBox32);
254 sd->mid_GetImage = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_GetImage);
256 LIBBASE->sd.basebm = OOP_FindClass(CLID_Hidd_BitMap);
258 InitSemaphore(&LIBBASE->sd.HWLock);
259 InitSemaphore(&LIBBASE->sd.MultiBMLock);
260 InitSemaphore(&LIBBASE->sd.CardMemLock);
262 /* Initialize MsgPort */
263 LIBBASE->sd.mp.mp_SigBit = SIGB_SINGLE;
264 LIBBASE->sd.mp.mp_Flags = PA_SIGNAL;
265 LIBBASE->sd.mp.mp_SigTask = FindTask(NULL);
266 LIBBASE->sd.mp.mp_Node.ln_Type = NT_MSGPORT;
267 NEWLIST(&LIBBASE->sd.mp.mp_MsgList);
269 LIBBASE->sd.tr.tr_node.io_Message.mn_ReplyPort = &LIBBASE->sd.mp;
270 LIBBASE->sd.tr.tr_node.io_Message.mn_Length = sizeof(LIBBASE->sd.tr);
272 if (!OpenDevice((STRPTR)"timer.device", UNIT_MICROHZ, (struct IORequest *)&LIBBASE->sd.tr, 0))
274 if ((LIBBASE->sd.PCIObject = OOP_NewObject(NULL, (STRPTR)CLID_Hidd_PCI, NULL)))
276 struct Hook FindHook = {
277 h_Entry: (IPTR (*)())Enumerator,
278 h_Data: LIBBASE,
281 struct TagItem Requirements[] = {
282 { tHidd_PCI_Interface, 0x00 },
283 { tHidd_PCI_Class, 0x03 },
284 { tHidd_PCI_SubClass, 0x00 },
285 { tHidd_PCI_VendorID, 0x1002 }, // ATI VendorID. May require more of them
286 { TAG_DONE, 0UL }
289 HIDD_PCI_EnumDevices(LIBBASE->sd.PCIObject, &FindHook, Requirements);
291 if (sd->PCIDevice)
292 return TRUE;
294 D(bug("[ATI] No supported cards found\n"));
296 CloseDevice((struct IORequest *)&LIBBASE->sd.tr);
301 return FALSE;
304 static int ATI_Expunge(LIBBASETYPEPTR LIBBASE)
306 struct ati_staticdata *sd = &LIBBASE->sd;
308 struct OOP_ABDescr attrbases[] =
310 { (STRPTR)IID_Hidd, &HiddAttrBase },
311 { (STRPTR)IID_Hidd_PCIDevice, &HiddPCIDeviceAttrBase },
312 { (STRPTR)IID_Hidd_BitMap, &HiddBitMapAttrBase },
313 { (STRPTR)IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
314 { (STRPTR)IID_Hidd_Sync, &HiddSyncAttrBase },
315 { (STRPTR)IID_Hidd_Gfx, &HiddGfxAttrBase },
316 { (STRPTR)IID_Hidd_BitMap_ATI, &HiddATIBitMapAttrBase },
317 { (STRPTR)IID_Hidd_I2C, &HiddI2CAttrBase },
318 { (STRPTR)IID_Hidd_I2CDevice, &HiddI2CDeviceAttrBase },
319 { (STRPTR)IID_Hidd_PlanarBM, &__IHidd_PlanarBM },
320 { NULL, NULL }
323 if (sd->PCIDevice)
325 IPTR size;
326 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_Size0, (APTR)&size);
327 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.FrameBuffer, size);
328 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_Size2, (APTR)&size);
329 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.MMIO, size);
330 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_RomSize, (APTR)&size);
331 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.vbios_org, size);
332 sd->PCIDevice = NULL;
335 if (sd->PCIObject)
336 OOP_DisposeObject(sd->PCIObject);
337 OOP_ReleaseAttrBases(attrbases);
338 if (sd->memPool)
339 DeletePool(sd->memPool);
341 return TRUE;
344 ADD2INITLIB(ATI_Init, 0)
345 ADD2EXPUNGELIB(ATI_Expunge, 0)
346 ADD2LIBS((STRPTR)"gfx.hidd", 0, static struct Library *, __gfxbase);