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 = get_module(B_ISA_MODULE_NAME, (module_info**)&gISA); 77 if (status != B_OK) 78 goto err1; 79 80 gDeviceNames[0] = strdup("graphics/vesa"); 81 if (gDeviceNames[0] == NULL) { 82 status = B_NO_MEMORY; 83 goto err2; 84 } 85 86 gDeviceNames[1] = NULL; 87 88 mutex_init(&gLock, "vesa lock"); 89 return B_OK; 90 91 err2: 92 put_module(B_ISA_MODULE_NAME); 93 err1: 94 free(gDeviceInfo[0]); 95 return status; 96 } 97 98 99 extern "C" void 100 uninit_driver(void) 101 { 102 TRACE((DEVICE_NAME ": uninit_driver()\n")); 103 104 put_module(B_ISA_MODULE_NAME); 105 mutex_destroy(&gLock); 106 107 // free device related structures 108 char* name; 109 for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) { 110 free(gDeviceInfo[index]); 111 free(name); 112 } 113 } 114 115 116 extern "C" device_hooks* 117 find_device(const char* name) 118 { 119 int index; 120 121 TRACE((DEVICE_NAME ": find_device()\n")); 122 123 for (index = 0; gDeviceNames[index] != NULL; index++) { 124 if (!strcmp(name, gDeviceNames[index])) 125 return &gDeviceHooks; 126 } 127 128 return NULL; 129 } 130 131