Added 400ns delay in ata_WaitBusyTO before read of device status.
[tangerine.git] / arch / common / hidd.radeon / ati_init.c
blob3cb82c38b67cef15c1c42e286ccf72e3dae91026
1 /*
2 Copyright © 2003-2007, 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 // sd->Card.vbios_org = (APTR)HIDD_PCIDriver_MapPCI(driver, buf, size);
150 sd->Card.vbios_org = (APTR)HIDD_PCIDriver_MapPCI(driver, (APTR)0x000c0000, size);
151 sd->Card.VBIOS = sd->Card.vbios_org;
152 D(bug("[ATI] Got BIOS @ %x (size=%dKiB)\n", sd->Card.VBIOS, size>>10));
154 if (sup->Init(sd))
156 struct CardState *state = AllocPooled(sd->memPool, sizeof(struct CardState));
158 sd->poweron_state = AllocPooled(sd->memPool, sizeof(struct CardState));
159 SaveState(sd, sd->poweron_state);
161 sd->CardMem.mh_Free = sd->Card.FbUsableSize;
162 sd->CardMem.mh_Upper = (APTR)(sd->CardMem.mh_Free + (IPTR)mc);
164 mc->mc_Next = NULL;
165 mc->mc_Bytes = sd->CardMem.mh_Free;
167 D(bug("[ATI] Usable size: %dKB\n", sd->CardMem.mh_Free >> 10));
169 sd->scratch_buffer = AllocBitmapArea(sd, 4096, 16, 4, TRUE);
170 sd->Card.CursorStart = AllocBitmapArea(sd, 64, 64, 4, TRUE);
172 OUTREG(RADEON_CUR_HORZ_VERT_OFF,RADEON_CUR_LOCK | 0);
173 OUTREG(RADEON_CUR_HORZ_VERT_POSN,RADEON_CUR_LOCK | 0);
174 OUTREG(RADEON_CUR_OFFSET, sd->Card.CursorStart);
176 sd->PCIDevice = pciDevice;
178 /*-------- DO NOT CHANGE/REMOVE -------------*/
179 bug("\003\n"); /* Tell vga text mode debug output to die */
180 /*-------- DO NOT CHANGE/REMOVE -------------*/
182 else
184 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size0, (APTR)&size);
185 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.FrameBuffer, size);
186 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Size2, (APTR)&size);
187 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.MMIO, size);
188 OOP_GetAttr(pciDevice, aHidd_PCIDevice_RomSize, (APTR)&size);
189 HIDD_PCIDriver_UnmapPCI(driver, (APTR)sd->Card.vbios_org, size);
190 sd->PCIDevice = NULL;
193 break;
196 sup++;
199 D(bug("[ATI] Enumerator found a card (ProductID=%04x)\n", ProductID));
200 D(bug("[ATI] The card is %ssupported\n",
201 sd->PCIDevice ? "":"un"));
203 AROS_USERFUNC_EXIT
206 static int ATI_Init(LIBBASETYPEPTR LIBBASE)
208 struct ati_staticdata *sd = &LIBBASE->sd;
210 struct OOP_ABDescr attrbases[] =
212 { (STRPTR)IID_Hidd_PCIDevice, &HiddPCIDeviceAttrBase },
213 { (STRPTR)IID_Hidd_BitMap, &HiddBitMapAttrBase },
214 { (STRPTR)IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
215 { (STRPTR)IID_Hidd_Sync, &HiddSyncAttrBase },
216 { (STRPTR)IID_Hidd_Gfx, &HiddGfxAttrBase },
217 { (STRPTR)IID_Hidd_ATIBitMap, &HiddATIBitMapAttrBase },
218 { (STRPTR)IID_Hidd_I2C, &HiddI2CAttrBase },
219 { (STRPTR)IID_Hidd_I2CDevice, &HiddI2CDeviceAttrBase },
220 { (STRPTR)IID_Hidd_PlanarBM, &__IHidd_PlanarBM },
221 { NULL, NULL }
224 D(bug("[ATI] Init\n"));
226 sd->memPool = CreatePool(MEMF_CLEAR | MEMF_PUBLIC | MEMF_SEM_PROTECTED, 8192, 4096);
228 if (sd->memPool)
230 if (OOP_ObtainAttrBases(attrbases))
232 sd->mid_CopyMemBox8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox8);
233 sd->mid_CopyMemBox16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox16);
234 sd->mid_CopyMemBox32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyMemBox32);
235 sd->mid_PutMem32Image8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMem32Image8);
236 sd->mid_PutMem32Image16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMem32Image16);
237 sd->mid_GetMem32Image8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_GetMem32Image8);
238 sd->mid_GetMem32Image16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_GetMem32Image16);
239 sd->mid_Clear = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_Clear);
240 sd->mid_PutMemTemplate8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate8);
241 sd->mid_PutMemTemplate16= OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate16);
242 sd->mid_PutMemTemplate32= OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemTemplate32);
243 sd->mid_PutMemPattern8 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern8);
244 sd->mid_PutMemPattern16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern16);
245 sd->mid_PutMemPattern32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_PutMemPattern32);
246 sd->mid_CopyLUTMemBox16 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyLUTMemBox16);
247 sd->mid_CopyLUTMemBox32 = OOP_GetMethodID((STRPTR)CLID_Hidd_BitMap, moHidd_BitMap_CopyLUTMemBox32);
249 InitSemaphore(&LIBBASE->sd.HWLock);
250 InitSemaphore(&LIBBASE->sd.MultiBMLock);
252 /* Initialize MsgPort */
253 LIBBASE->sd.mp.mp_SigBit = SIGB_SINGLE;
254 LIBBASE->sd.mp.mp_Flags = PA_SIGNAL;
255 LIBBASE->sd.mp.mp_SigTask = FindTask(NULL);
256 LIBBASE->sd.mp.mp_Node.ln_Type = NT_MSGPORT;
257 NEWLIST(&LIBBASE->sd.mp.mp_MsgList);
259 LIBBASE->sd.tr.tr_node.io_Message.mn_ReplyPort = &LIBBASE->sd.mp;
260 LIBBASE->sd.tr.tr_node.io_Message.mn_Length = sizeof(LIBBASE->sd.tr);
262 if (!OpenDevice((STRPTR)"timer.device", UNIT_MICROHZ, (struct IORequest *)&LIBBASE->sd.tr, 0))
264 if ((LIBBASE->sd.PCIObject = OOP_NewObject(NULL, (STRPTR)CLID_Hidd_PCI, NULL)))
266 struct Hook FindHook = {
267 h_Entry: (IPTR (*)())Enumerator,
268 h_Data: LIBBASE,
271 struct TagItem Requirements[] = {
272 { tHidd_PCI_Interface, 0x00 },
273 { tHidd_PCI_Class, 0x03 },
274 { tHidd_PCI_SubClass, 0x00 },
275 { tHidd_PCI_VendorID, 0x1002 }, // ATI VendorID. May require more of them
276 { TAG_DONE, 0UL }
279 HIDD_PCI_EnumDevices(LIBBASE->sd.PCIObject, &FindHook, Requirements);
281 return TRUE;
285 OOP_ReleaseAttrBases(attrbases);
288 DeletePool(LIBBASE->sd.memPool);
291 return FALSE;
294 static int ATI_Expunge(LIBBASETYPEPTR LIBBASE)
296 struct ati_staticdata *sd = &LIBBASE->sd;
298 struct OOP_ABDescr attrbases[] =
300 { (STRPTR)IID_Hidd_PCIDevice, &HiddPCIDeviceAttrBase },
301 { (STRPTR)IID_Hidd_BitMap, &HiddBitMapAttrBase },
302 { (STRPTR)IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
303 { (STRPTR)IID_Hidd_Sync, &HiddSyncAttrBase },
304 { (STRPTR)IID_Hidd_Gfx, &HiddGfxAttrBase },
305 { (STRPTR)IID_Hidd_ATIBitMap, &HiddATIBitMapAttrBase },
306 { (STRPTR)IID_Hidd_I2C, &HiddI2CAttrBase },
307 { (STRPTR)IID_Hidd_I2CDevice, &HiddI2CDeviceAttrBase },
308 { (STRPTR)IID_Hidd_PlanarBM, &__IHidd_PlanarBM },
309 { NULL, NULL }
312 if (sd->PCIDevice)
314 IPTR size;
315 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_Size0, (APTR)&size);
316 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.FrameBuffer, size);
317 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_Size2, (APTR)&size);
318 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.MMIO, size);
319 OOP_GetAttr(sd->PCIDevice, aHidd_PCIDevice_RomSize, (APTR)&size);
320 HIDD_PCIDriver_UnmapPCI(sd->PCIDriver, (APTR)sd->Card.vbios_org, size);
321 sd->PCIDevice = NULL;
324 OOP_DisposeObject(sd->PCIObject);
325 OOP_ReleaseAttrBases(attrbases);
326 DeletePool(sd->memPool);
328 return TRUE;
331 ADD2INITLIB(ATI_Init, 0)
332 ADD2EXPUNGELIB(ATI_Expunge, 0)
333 ADD2LIBS((STRPTR)"graphics.hidd", 0, static struct Library *, __gfxbase);