2 Copyright © 2003-2006, The AROS Development Team. All rights reserved.
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>
17 #include <utility/utility.h>
21 #include <proto/exec.h>
22 #include <proto/oop.h>
23 #include <aros/debug.h>
27 #include <hidd/graphics.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)
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
))
60 LIBBASETYPEPTR LIBBASE
= (LIBBASETYPEPTR
)hook
->h_Data
;
61 struct ati_staticdata
*sd
= &LIBBASE
->sd
;
63 struct ATIDevice
*sup
= (struct ATIDevice
*)support
;
67 if (sd
->PCIDevice
!= NULL
)
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 */
82 if (sup
->VendorID
== VendorID
)
84 if (!sup
->masked_check
&& (sup
->ProductID
== ProductID
))
88 else if (sup
->masked_check
&& (sup
->ProductID
== (ProductID
& 0xFFF0)))
96 /* Matching card found */
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 */
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
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));
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
);
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 -------------*/
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
;
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"));
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
},
224 D(bug("[ATI] Init\n"));
226 sd
->memPool
= CreatePool(MEMF_CLEAR
| MEMF_PUBLIC
| MEMF_SEM_PROTECTED
, 8192, 4096);
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 LIBBASE
->sd
.sysbase
= LIBBASE
->sysbase
;
254 if ((LIBBASE
->sd
.PCIObject
= OOP_NewObject(NULL
, (STRPTR
)CLID_Hidd_PCI
, NULL
)))
256 struct Hook FindHook
= {
257 h_Entry
: (IPTR (*)())Enumerator
,
261 struct TagItem Requirements
[] = {
262 { tHidd_PCI_Interface
, 0x00 },
263 { tHidd_PCI_Class
, 0x03 },
264 { tHidd_PCI_SubClass
, 0x00 },
265 { tHidd_PCI_VendorID
, 0x1002 }, // ATI VendorID. May require more of them
269 HIDD_PCI_EnumDevices(LIBBASE
->sd
.PCIObject
, &FindHook
, Requirements
);
274 OOP_ReleaseAttrBases(attrbases
);
277 DeletePool(LIBBASE
->sd
.memPool
);
283 static int ATI_Expunge(LIBBASETYPEPTR LIBBASE
)
285 struct ati_staticdata
*sd
= &LIBBASE
->sd
;
287 struct OOP_ABDescr attrbases
[] =
289 { (STRPTR
)IID_Hidd_PCIDevice
, &HiddPCIDeviceAttrBase
},
290 { (STRPTR
)IID_Hidd_BitMap
, &HiddBitMapAttrBase
},
291 { (STRPTR
)IID_Hidd_PixFmt
, &HiddPixFmtAttrBase
},
292 { (STRPTR
)IID_Hidd_Sync
, &HiddSyncAttrBase
},
293 { (STRPTR
)IID_Hidd_Gfx
, &HiddGfxAttrBase
},
294 { (STRPTR
)IID_Hidd_ATIBitMap
, &HiddATIBitMapAttrBase
},
295 { (STRPTR
)IID_Hidd_I2C
, &HiddI2CAttrBase
},
296 { (STRPTR
)IID_Hidd_I2CDevice
, &HiddI2CDeviceAttrBase
},
297 { (STRPTR
)IID_Hidd_PlanarBM
, &__IHidd_PlanarBM
},
304 OOP_GetAttr(sd
->PCIDevice
, aHidd_PCIDevice_Size0
, (APTR
)&size
);
305 HIDD_PCIDriver_UnmapPCI(sd
->PCIDriver
, (APTR
)sd
->Card
.FrameBuffer
, size
);
306 OOP_GetAttr(sd
->PCIDevice
, aHidd_PCIDevice_Size2
, (APTR
)&size
);
307 HIDD_PCIDriver_UnmapPCI(sd
->PCIDriver
, (APTR
)sd
->Card
.MMIO
, size
);
308 OOP_GetAttr(sd
->PCIDevice
, aHidd_PCIDevice_RomSize
, (APTR
)&size
);
309 HIDD_PCIDriver_UnmapPCI(sd
->PCIDriver
, (APTR
)sd
->Card
.vbios_org
, size
);
310 sd
->PCIDevice
= NULL
;
313 OOP_DisposeObject(sd
->PCIObject
);
314 OOP_ReleaseAttrBases(attrbases
);
315 DeletePool(sd
->memPool
);
320 ADD2INITLIB(ATI_Init
, 0)
321 ADD2EXPUNGELIB(ATI_Expunge
, 0)
322 ADD2LIBS((STRPTR
)"graphics.hidd", 0, static struct Library
*, __gfxbase
);