xref: /haiku/src/add-ons/kernel/drivers/graphics/vesa/driver.cpp (revision 99d1318ec02694fc520a0dc38ae38565db7e8c3c)
1 /*
2  * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
3  * Copyright 2016, Jessica Hamilton, jessica.l.hamilton@gmail.com.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 
8 #include <OS.h>
9 #include <KernelExport.h>
10 #include <SupportDefs.h>
11 #include <PCI.h>
12 #include <frame_buffer_console.h>
13 #include <boot_item.h>
14 #include <vesa_info.h>
15 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <malloc.h>
20 
21 #include "driver.h"
22 #include "device.h"
23 
24 
25 #define TRACE_DRIVER
26 #ifdef TRACE_DRIVER
27 #	define TRACE(x) dprintf x
28 #else
29 #	define TRACE(x) ;
30 #endif
31 
32 #define MAX_CARDS 1
33 
34 
35 int32 api_version = B_CUR_DRIVER_API_VERSION;
36 
37 char* gDeviceNames[MAX_CARDS + 1];
38 vesa_info* gDeviceInfo[MAX_CARDS];
39 isa_module_info* gISA;
40 mutex gLock;
41 
42 
43 extern "C" const char**
44 publish_devices(void)
45 {
46 	TRACE((DEVICE_NAME ": publish_devices()\n"));
47 	return (const char**)gDeviceNames;
48 }
49 
50 
51 extern "C" status_t
52 init_hardware(void)
53 {
54 	TRACE((DEVICE_NAME ": init_hardware()\n"));
55 
56 	// If we don't have the VESA mode info, then we have a
57 	// dumb framebuffer, in which case we bail, and leave it
58 	// up to the framebuffer driver to handle.
59 	return (get_boot_item(VESA_MODES_BOOT_INFO, NULL) != NULL
60 			&& get_boot_item(FRAME_BUFFER_BOOT_INFO, NULL) != NULL)
61 		? B_OK : B_ERROR;
62 }
63 
64 
65 extern "C" status_t
66 init_driver(void)
67 {
68 	TRACE((DEVICE_NAME ": init_driver()\n"));
69 
70 	gDeviceInfo[0] = (vesa_info*)malloc(sizeof(vesa_info));
71 	if (gDeviceInfo[0] == NULL)
72 		return B_NO_MEMORY;
73 
74 	memset(gDeviceInfo[0], 0, sizeof(vesa_info));
75 
76 	status_t status;
77 
78 	// ISA may not be available on all architectures
79 	status = get_module(B_ISA_MODULE_NAME, (module_info**)&gISA);
80 	if (status != B_OK) {
81 		TRACE((DEVICE_NAME ": ISA bus unavailable\n"));
82 		gISA = NULL;
83 	}
84 
85 	gDeviceNames[0] = strdup("graphics/vesa");
86 	if (gDeviceNames[0] == NULL) {
87 		status = B_NO_MEMORY;
88 		goto err;
89 	}
90 
91 	gDeviceNames[1] = NULL;
92 
93 	mutex_init(&gLock, "vesa lock");
94 	return B_OK;
95 
96 err:
97 	put_module(B_ISA_MODULE_NAME);
98 	free(gDeviceInfo[0]);
99 	return status;
100 }
101 
102 
103 extern "C" void
104 uninit_driver(void)
105 {
106 	TRACE((DEVICE_NAME ": uninit_driver()\n"));
107 
108 	put_module(B_ISA_MODULE_NAME);
109 	mutex_destroy(&gLock);
110 
111 	// free device related structures
112 	char* name;
113 	for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) {
114 		free(gDeviceInfo[index]);
115 		free(name);
116 	}
117 }
118 
119 
120 extern "C" device_hooks*
121 find_device(const char* name)
122 {
123 	int index;
124 
125 	TRACE((DEVICE_NAME ": find_device()\n"));
126 
127 	for (index = 0; gDeviceNames[index] != NULL; index++) {
128 		if (!strcmp(name, gDeviceNames[index]))
129 			return &gDeviceHooks;
130 	}
131 
132 	return NULL;
133 }
134 
135