usb_ecm: Use the current configuration instead of a fixed one.
[haiku.git] / src / add-ons / kernel / drivers / graphics / vesa / driver.cpp
blobfccea326e1acbd2e4356eb7eca7da7f6ab0c4292
1 /*
2 * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <OS.h>
8 #include <KernelExport.h>
9 #include <SupportDefs.h>
10 #include <PCI.h>
11 #include <frame_buffer_console.h>
12 #include <boot_item.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <malloc.h>
19 #include "driver.h"
20 #include "device.h"
23 #define TRACE_DRIVER
24 #ifdef TRACE_DRIVER
25 # define TRACE(x) dprintf x
26 #else
27 # define TRACE(x) ;
28 #endif
30 #define MAX_CARDS 1
33 int32 api_version = B_CUR_DRIVER_API_VERSION;
35 char* gDeviceNames[MAX_CARDS + 1];
36 vesa_info* gDeviceInfo[MAX_CARDS];
37 isa_module_info* gISA;
38 mutex gLock;
41 extern "C" const char**
42 publish_devices(void)
44 TRACE((DEVICE_NAME ": publish_devices()\n"));
45 return (const char**)gDeviceNames;
49 extern "C" status_t
50 init_hardware(void)
52 TRACE((DEVICE_NAME ": init_hardware()\n"));
54 return get_boot_item(FRAME_BUFFER_BOOT_INFO, NULL) != NULL ? B_OK : B_ERROR;
58 extern "C" status_t
59 init_driver(void)
61 TRACE((DEVICE_NAME ": init_driver()\n"));
63 gDeviceInfo[0] = (vesa_info*)malloc(sizeof(vesa_info));
64 if (gDeviceInfo[0] == NULL)
65 return B_NO_MEMORY;
67 memset(gDeviceInfo[0], 0, sizeof(vesa_info));
69 status_t status = get_module(B_ISA_MODULE_NAME, (module_info**)&gISA);
70 if (status != B_OK)
71 goto err1;
73 gDeviceNames[0] = strdup("graphics/vesa");
74 if (gDeviceNames[0] == NULL) {
75 status = B_NO_MEMORY;
76 goto err2;
79 gDeviceNames[1] = NULL;
81 mutex_init(&gLock, "vesa lock");
82 return B_OK;
84 err2:
85 put_module(B_ISA_MODULE_NAME);
86 err1:
87 free(gDeviceInfo[0]);
88 return status;
92 extern "C" void
93 uninit_driver(void)
95 TRACE((DEVICE_NAME ": uninit_driver()\n"));
97 put_module(B_ISA_MODULE_NAME);
98 mutex_destroy(&gLock);
100 // free device related structures
101 char* name;
102 for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) {
103 free(gDeviceInfo[index]);
104 free(name);
109 extern "C" device_hooks*
110 find_device(const char* name)
112 int index;
114 TRACE((DEVICE_NAME ": find_device()\n"));
116 for (index = 0; gDeviceNames[index] != NULL; index++) {
117 if (!strcmp(name, gDeviceNames[index]))
118 return &gDeviceHooks;
121 return NULL;