xref: /haiku/src/add-ons/kernel/drivers/graphics/vesa/driver.cpp (revision 7d6915b4d08ffe728cd38af02843d5e98ddfe0db)
1 /*
2  * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
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>
13 
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <malloc.h>
18 
19 #include "driver.h"
20 #include "device.h"
21 
22 
23 #define TRACE_DRIVER
24 #ifdef TRACE_DRIVER
25 #	define TRACE(x) dprintf x
26 #else
27 #	define TRACE(x) ;
28 #endif
29 
30 #define MAX_CARDS 1
31 
32 
33 int32 api_version = B_CUR_DRIVER_API_VERSION;
34 
35 char* gDeviceNames[MAX_CARDS + 1];
36 vesa_info* gDeviceInfo[MAX_CARDS];
37 isa_module_info* gISA;
38 mutex gLock;
39 
40 
41 extern "C" const char**
42 publish_devices(void)
43 {
44 	TRACE((DEVICE_NAME ": publish_devices()\n"));
45 	return (const char**)gDeviceNames;
46 }
47 
48 
49 extern "C" status_t
50 init_hardware(void)
51 {
52 	TRACE((DEVICE_NAME ": init_hardware()\n"));
53 
54 	return get_boot_item(FRAME_BUFFER_BOOT_INFO, NULL) != NULL ? B_OK : B_ERROR;
55 }
56 
57 
58 extern "C" status_t
59 init_driver(void)
60 {
61 	TRACE((DEVICE_NAME ": init_driver()\n"));
62 
63 	gDeviceInfo[0] = (vesa_info*)malloc(sizeof(vesa_info));
64 	if (gDeviceInfo[0] == NULL)
65 		return B_NO_MEMORY;
66 
67 	memset(gDeviceInfo[0], 0, sizeof(vesa_info));
68 
69 	status_t status = get_module(B_ISA_MODULE_NAME, (module_info**)&gISA);
70 	if (status != B_OK)
71 		goto err1;
72 
73 	gDeviceNames[0] = strdup("graphics/vesa");
74 	if (gDeviceNames[0] == NULL) {
75 		status = B_NO_MEMORY;
76 		goto err2;
77 	}
78 
79 	gDeviceNames[1] = NULL;
80 
81 	mutex_init(&gLock, "vesa lock");
82 	return B_OK;
83 
84 err2:
85 	put_module(B_ISA_MODULE_NAME);
86 err1:
87 	free(gDeviceInfo[0]);
88 	return status;
89 }
90 
91 
92 extern "C" void
93 uninit_driver(void)
94 {
95 	TRACE((DEVICE_NAME ": uninit_driver()\n"));
96 
97 	put_module(B_ISA_MODULE_NAME);
98 	mutex_destroy(&gLock);
99 
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);
105 	}
106 }
107 
108 
109 extern "C" device_hooks*
110 find_device(const char* name)
111 {
112 	int index;
113 
114 	TRACE((DEVICE_NAME ": find_device()\n"));
115 
116 	for (index = 0; gDeviceNames[index] != NULL; index++) {
117 		if (!strcmp(name, gDeviceNames[index]))
118 			return &gDeviceHooks;
119 	}
120 
121 	return NULL;
122 }
123 
124