revert between 56095 -> 55830 in arch
[AROS.git] / workbench / hidds / nouveau / drm / drm-aros / drm_aros.c
blob6e3f79eecc2077797b575759bfb30f7263adb1f5
1 /*
2 Copyright © 2009-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "drmP.h"
7 #include "drm_aros.h"
9 #include <aros/libcall.h>
11 #include <proto/oop.h>
13 #include <hidd/pci.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))
26 AROS_USERFUNC_INIT
28 IPTR ProductID;
29 IPTR VendorID;
30 IPTR SubSystemProductID;
31 IPTR SubSystemVendorID;
32 IPTR INTLine;
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");
49 return;
52 while (sup->VendorID)
54 if (sup->VendorID == VendorID && sup->ProductID == ProductID)
56 OOP_Object *driver;
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 */
63 { TAG_DONE, 0UL },
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
77 uninitialized.
79 OOP_SetAttrs(pciDevice, (struct TagItem*)&attrs);
81 OOP_GetAttr(pciDevice, aHidd_PCIDevice_Driver, (APTR)&driver);
82 pciDriver = 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");
93 return;
96 sup++;
99 AROS_USERFUNC_EXIT
102 static void
103 drm_aros_pci_find_card(struct drm_driver *drv)
105 if (pciBus)
107 struct Hook FindHook = {
108 h_Entry: (IPTR (*)())Enumerator,
109 h_Data: drv,
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 },
117 { TAG_DONE, 0UL }
120 struct pHidd_PCI_EnumDevices enummsg = {
121 mID: OOP_GetMethodID(IID_Hidd_PCI, moHidd_PCI_EnumDevices),
122 callback: &FindHook,
123 requirements: (struct TagItem*)&Requirements,
124 }, *msg = &enummsg;
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;
134 drv->IsAGP = FALSE;
135 drv->IsPCIE = FALSE;
136 pciDriver = NULL;
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" : "");
148 return 0;
150 else
152 DRM_INFO("Failed detecting card for VendorID: 0x%x\n", drv->VendorID);
153 drm_aros_pci_shutdown(drv);
154 return -1;
158 LONG drm_aros_pci_init(struct drm_driver * drv)
160 if (!OOPBase_DRM)
162 if ((OOPBase_DRM = OpenLibrary("oop.library", 0)) == NULL)
164 /* Failure */
165 return -1;
169 HiddPCIDeviceAttrBase = OOP_ObtainAttrBase(IID_Hidd_PCIDevice);
171 if (!pciBus)
173 pciBus = OOP_NewObject(NULL, CLID_Hidd_PCI, NULL);
174 if (!pciBus)
175 return -1;
178 return 0;
181 VOID drm_aros_pci_shutdown(struct drm_driver *drv)
183 /* Release AROS-specific PCI objects. Should be called at driver shutdown */
185 if (drv)
187 drv->pciDevice = NULL;
190 if (pciBus)
192 OOP_DisposeObject(pciBus);
193 pciBus = NULL;
196 pciDriver = NULL;
198 if (HiddPCIDeviceAttrBase != 0)
200 OOP_ReleaseAttrBase(IID_Hidd_PCIDevice);
201 HiddPCIDeviceAttrBase = 0;
204 if (OOPBase_DRM)
206 CloseLibrary(OOPBase_DRM);
207 OOPBase_DRM = NULL;