xref: /haiku/src/add-ons/kernel/drivers/graphics/vesa/driver.cpp (revision a5061ecec55353a5f394759473f1fd6df04890da)
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 	return get_boot_item(FRAME_BUFFER_BOOT_INFO, NULL) != NULL ? B_OK : B_ERROR;
57 }
58 
59 
60 extern "C" status_t
61 init_driver(void)
62 {
63 	TRACE((DEVICE_NAME ": init_driver()\n"));
64 
65 	gDeviceInfo[0] = (vesa_info*)malloc(sizeof(vesa_info));
66 	if (gDeviceInfo[0] == NULL)
67 		return B_NO_MEMORY;
68 
69 	memset(gDeviceInfo[0], 0, sizeof(vesa_info));
70 
71 	status_t status;
72 
73 	// ISA may not be available on all architectures
74 	status = get_module(B_ISA_MODULE_NAME, (module_info**)&gISA);
75 	if (status != B_OK) {
76 		TRACE((DEVICE_NAME ": ISA bus unavailable\n"));
77 		gISA = NULL;
78 	}
79 
80 	gDeviceNames[0] = strdup("graphics/vesa");
81 	if (gDeviceNames[0] == NULL) {
82 		status = B_NO_MEMORY;
83 		goto err;
84 	}
85 
86 	gDeviceNames[1] = NULL;
87 
88 	mutex_init(&gLock, "vesa lock");
89 	return B_OK;
90 
91 err:
92 	put_module(B_ISA_MODULE_NAME);
93 	free(gDeviceInfo[0]);
94 	return status;
95 }
96 
97 
98 extern "C" void
99 uninit_driver(void)
100 {
101 	TRACE((DEVICE_NAME ": uninit_driver()\n"));
102 
103 	put_module(B_ISA_MODULE_NAME);
104 	mutex_destroy(&gLock);
105 
106 	// free device related structures
107 	char* name;
108 	for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) {
109 		free(gDeviceInfo[index]);
110 		free(name);
111 	}
112 }
113 
114 
115 extern "C" device_hooks*
116 find_device(const char* name)
117 {
118 	int index;
119 
120 	TRACE((DEVICE_NAME ": find_device()\n"));
121 
122 	for (index = 0; gDeviceNames[index] != NULL; index++) {
123 		if (!strcmp(name, gDeviceNames[index]))
124 			return &gDeviceHooks;
125 	}
126 
127 	return NULL;
128 }
129 
130