Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / hidds / nouveau / drm / drm-aros / drm_drv.c
bloba26e0b1ea0a71e12cd40199662de8d5835ee4937
1 /*
2 Copyright 2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "drmP.h"
7 #include "drm_aros.h"
8 #include "drm_global.h"
10 struct drm_driver *current_drm_driver = NULL;
12 int drm_lastclose(struct drm_device * dev)
14 if (dev->driver->lastclose)
15 dev->driver->lastclose(dev);
17 if (dev->irq_enabled)
18 drm_irq_uninstall(dev);
20 return 0;
23 static void drm_cleanup(struct drm_device * dev)
25 drm_lastclose(dev);
27 if (dev->driver->unload)
28 dev->driver->unload(dev);
30 if (drm_core_has_AGP(dev) && dev->agp)
32 kfree(dev->agp);
33 dev->agp = NULL;
37 void drm_exit(struct drm_driver * driver)
39 drm_cleanup(driver->dev);
41 drm_aros_pci_shutdown(driver);
43 HIDDNouveauFree(driver->dev->pdev);
44 HIDDNouveauFree(driver->dev);
45 driver->dev = NULL;
46 current_drm_driver = NULL;
49 static int drm_init_device(struct drm_driver * driver)
51 /* If this function is called, the card was already found */
52 driver->dev = HIDDNouveauAlloc(sizeof(struct drm_device));
53 struct drm_device * dev = driver->dev;
55 /* Init fields */
56 INIT_LIST_HEAD(&dev->maplist);
57 dev->irq_enabled = 0;
58 InitSemaphore(&dev->struct_mutex.semaphore);
59 dev->driver = driver;
60 dev->pci_vendor = driver->VendorID;
61 dev->pci_device = driver->ProductID;
62 dev->pdev = HIDDNouveauAlloc(sizeof(struct pci_dev));
63 dev->pdev->oopdev = driver->pciDevice;
64 int ret;
66 if (drm_core_has_AGP(dev)) {
67 if (drm_device_is_agp(dev))
68 dev->agp = drm_agp_init(dev);
69 if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP)
70 && (dev->agp == NULL)) {
71 DRM_ERROR("Cannot initialize the agpgart module.\n");
72 return -1;
76 if (driver->driver_features & DRIVER_GEM) {
77 if (drm_gem_init(dev)) {
78 DRM_ERROR("Cannot initialize graphics execution "
79 "manager (GEM)\n");
80 return -1;
84 if (!dev->driver->load)
85 return -1;
87 ret = dev->driver->load(dev, 0);
88 if (ret)
89 return -1;
91 if (dev->driver->firstopen)
93 ret = dev->driver->firstopen(dev);
94 if (ret)
95 return -1;
98 return 0;
101 int drm_init(struct drm_driver * driver)
103 drm_global_init();
105 if (drm_aros_pci_init(driver))
106 return -1;
108 if (drm_aros_pci_find_supported_video_card(driver))
109 return -1;
111 bug("\003\n"); /* Tell vga text mode debug output to die */
113 if (drm_init_device(driver))
115 drm_exit(driver);
116 return -1;
119 current_drm_driver = driver;
121 return 0;