2 Copyright © 2009-2013, The AROS Development Team. All rights reserved.
9 #include <aros/libcall.h>
11 #include <proto/oop.h>
14 #include <hidd/hidd.h>
16 OOP_AttrBase HiddPCIDeviceAttrBase
= 0;
17 struct Library
* OOPBase_DRM
= NULL
;
18 OOP_Object
* pciDriver
= NULL
;
19 OOP_Object
* pciBus
= NULL
;
21 AROS_UFH3(void, Enumerator
,
22 AROS_UFHA(struct Hook
*, hook
, A0
),
23 AROS_UFHA(OOP_Object
*, pciDevice
, A2
),
24 AROS_UFHA(APTR
, message
, A1
))
30 IPTR SubSystemProductID
;
31 IPTR SubSystemVendorID
;
33 struct drm_driver
*drv
= (struct drm_driver
*)hook
->h_Data
;
34 struct drm_pciid
*sup
= drv
->PciIDs
;
36 /* Get the Device's ProductID */
37 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_ProductID
, &ProductID
);
38 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_VendorID
, &VendorID
);
39 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_SubsystemID
, &SubSystemProductID
);
40 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_SubsystemVendorID
, &SubSystemVendorID
);
42 DRM_DEBUG("VendorID: %x, ProductID: %x\n", VendorID
, ProductID
);
44 /* Check interrupt line. If it is not set, just skip the device */
45 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_INTLine
, &INTLine
);
46 if ((INTLine
== 0) || (INTLine
>= 255))
48 DRM_DEBUG("INT line is not set. Skipping device.\n");
54 if (sup
->VendorID
== VendorID
&& sup
->ProductID
== ProductID
)
57 IPTR AGPCap
= 0, PCIECap
= 0;
59 struct TagItem attrs
[] = {
60 { aHidd_PCIDevice_isIO
, FALSE
}, /* Don't listen IO transactions */
61 { aHidd_PCIDevice_isMEM
, TRUE
}, /* Listen to MEM transactions */
62 { aHidd_PCIDevice_isMaster
, TRUE
}, /* Can work in BusMaster */
66 DRM_DEBUG("Found!\n");
67 /* Filling out device properties */
68 drv
->VendorID
= (UWORD
)VendorID
;
69 drv
->ProductID
= (UWORD
)ProductID
;
70 drv
->SubSystemVendorID
= (UWORD
)SubSystemVendorID
;
71 drv
->SubSystemProductID
= (UWORD
)SubSystemProductID
;
72 drv
->pciDevice
= pciDevice
;
75 Fix PCI device attributes (perhaps already set, but if the
76 NVidia would be the second card in the system, it may stay
79 OOP_SetAttrs(pciDevice
, (struct TagItem
*)&attrs
);
81 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_Driver
, (APTR
)&driver
);
84 /* Check AGP/PCIE capabilities */
85 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_CapabilityAGP
, (APTR
)&AGPCap
);
86 OOP_GetAttr(pciDevice
, aHidd_PCIDevice_CapabilityPCIE
, (APTR
)&PCIECap
);
88 drv
->IsAGP
= (AGPCap
!= 0);
89 drv
->IsPCIE
= (PCIECap
!= 0);
91 DRM_DEBUG("Acquired pcidriver\n");
103 drm_aros_pci_find_card(struct drm_driver
*drv
)
107 struct Hook FindHook
= {
108 h_Entry
: (IPTR (*)())Enumerator
,
112 struct TagItem Requirements
[] = {
113 { tHidd_PCI_Interface
, 0x00 },
114 { tHidd_PCI_Class
, 0x03 },
115 { tHidd_PCI_SubClass
, 0x00 },
116 { tHidd_PCI_VendorID
, drv
->VendorID
},
120 struct pHidd_PCI_EnumDevices enummsg
= {
121 mID
: OOP_GetMethodID(IID_Hidd_PCI
, moHidd_PCI_EnumDevices
),
123 requirements
: (struct TagItem
*)&Requirements
,
125 DRM_DEBUG("Calling search Hook\n");
126 OOP_DoMethod(pciBus
, (OOP_Msg
)msg
);
130 LONG
drm_aros_pci_find_supported_video_card(struct drm_driver
*drv
)
132 drv
->pciDevice
= NULL
;
133 drv
->ProductID
= 0x0;
138 drm_aros_pci_find_card(drv
);
140 /* If objects are set, detection was successful */
141 if (pciBus
&& drv
->pciDevice
&& pciDriver
)
143 DRM_INFO("Detected card: 0x%x/0x%x - %s%s%s\n",
144 drv
->VendorID
, drv
->ProductID
,
145 (!drv
->IsAGP
) && (!drv
->IsPCIE
) ? "PCI" : "",
146 drv
->IsAGP
? "AGP" : "",
147 drv
->IsPCIE
? "PCIe" : "");
152 DRM_INFO("Failed detecting card for VendorID: 0x%x\n", drv
->VendorID
);
153 drm_aros_pci_shutdown(drv
);
158 LONG
drm_aros_pci_init(struct drm_driver
* drv
)
162 if ((OOPBase_DRM
= OpenLibrary("oop.library", 0)) == NULL
)
169 HiddPCIDeviceAttrBase
= OOP_ObtainAttrBase(IID_Hidd_PCIDevice
);
173 pciBus
= OOP_NewObject(NULL
, CLID_Hidd_PCI
, NULL
);
181 VOID
drm_aros_pci_shutdown(struct drm_driver
*drv
)
183 /* Release AROS-specific PCI objects. Should be called at driver shutdown */
187 drv
->pciDevice
= NULL
;
192 OOP_DisposeObject(pciBus
);
198 if (HiddPCIDeviceAttrBase
!= 0)
200 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice
);
201 HiddPCIDeviceAttrBase
= 0;
206 CloseLibrary(OOPBase_DRM
);