xref: /haiku/src/add-ons/kernel/drivers/graphics/framebuffer/driver.cpp (revision 830f67ef991407f287dbc1238aa5f5906d90c991)
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 framebuffer_info* gDeviceInfo[MAX_CARDS];
39 mutex gLock;
40 
41 
42 extern "C" const char**
43 publish_devices(void)
44 {
45 	TRACE((DEVICE_NAME ": publish_devices()\n"));
46 	return (const char**)gDeviceNames;
47 }
48 
49 
50 extern "C" status_t
51 init_hardware(void)
52 {
53 	TRACE((DEVICE_NAME ": init_hardware()\n"));
54 
55 	// If we don't have a VESA mode list, then we are a dumb
56 	// framebuffer, e.g. when there are no drivers available
57 	// on a UEFI system.
58 	return (get_boot_item(VESA_MODES_BOOT_INFO, NULL) == NULL
59 			&& get_boot_item(FRAME_BUFFER_BOOT_INFO, NULL) != NULL)
60 		? B_OK : B_ERROR;
61 }
62 
63 
64 extern "C" status_t
65 init_driver(void)
66 {
67 	TRACE((DEVICE_NAME ": init_driver()\n"));
68 
69 	gDeviceInfo[0] = (framebuffer_info*)malloc(sizeof(framebuffer_info));
70 	if (gDeviceInfo[0] == NULL)
71 		return B_NO_MEMORY;
72 
73 	memset(gDeviceInfo[0], 0, sizeof(framebuffer_info));
74 
75 	gDeviceNames[0] = strdup("graphics/framebuffer");
76 	if (gDeviceNames[0] == NULL) {
77 		free(gDeviceNames[0]);
78 		return B_NO_MEMORY;
79 	}
80 
81 	gDeviceNames[1] = NULL;
82 
83 	mutex_init(&gLock, "framebuffer lock");
84 	return B_OK;
85 }
86 
87 
88 extern "C" void
89 uninit_driver(void)
90 {
91 	TRACE((DEVICE_NAME ": uninit_driver()\n"));
92 
93 	mutex_destroy(&gLock);
94 
95 	// free device related structures
96 	char* name;
97 	for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) {
98 		free(gDeviceInfo[index]);
99 		free(name);
100 	}
101 }
102 
103 
104 extern "C" device_hooks*
105 find_device(const char* name)
106 {
107 	int index;
108 
109 	TRACE((DEVICE_NAME ": find_device()\n"));
110 
111 	for (index = 0; gDeviceNames[index] != NULL; index++) {
112 		if (!strcmp(name, gDeviceNames[index]))
113 			return &gDeviceHooks;
114 	}
115 
116 	return NULL;
117 }
118 
119