1 /* 2 * Copyright 2005-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 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 #define TRACE_DRIVER 23 #ifdef TRACE_DRIVER 24 # define TRACE(x) dprintf x 25 #else 26 # define TRACE(x) ; 27 #endif 28 29 #define MAX_CARDS 1 30 31 int32 api_version = B_CUR_DRIVER_API_VERSION; 32 33 char *gDeviceNames[MAX_CARDS + 1]; 34 vesa_info *gDeviceInfo[MAX_CARDS]; 35 isa_module_info *gISA; 36 lock gLock; 37 38 39 extern "C" { 40 status_t init_hardware(void); 41 status_t init_driver(void); 42 void uninit_driver(void); 43 const char **publish_devices(void); 44 device_hooks *find_device(const char *name); 45 } 46 47 #if 0 48 static status_t 49 get_next_graphics_card(int32 *_cookie, pci_info &info) 50 { 51 int32 index = *_cookie; 52 53 // find devices 54 for (; gPCI->get_nth_pci_info(index, &info) == B_OK; index++) { 55 if (info.class_base == PCI_display) { 56 *_cookie = index + 1; 57 return B_OK; 58 } 59 } 60 61 return B_ENTRY_NOT_FOUND; 62 } 63 #endif 64 65 const char ** 66 publish_devices(void) 67 { 68 TRACE((DEVICE_NAME ": publish_devices()\n")); 69 return (const char **)gDeviceNames; 70 } 71 72 73 status_t 74 init_hardware(void) 75 { 76 TRACE((DEVICE_NAME ": init_hardware()\n")); 77 78 return get_boot_item(FRAME_BUFFER_BOOT_INFO, NULL) != NULL ? B_OK : B_ERROR; 79 } 80 81 82 status_t 83 init_driver(void) 84 { 85 TRACE((DEVICE_NAME ": init_driver()\n")); 86 87 if ((gDeviceInfo[0] = (vesa_info *)malloc(sizeof(vesa_info))) != NULL) 88 memset(gDeviceInfo[0], 0, sizeof(vesa_info)); 89 else 90 return B_NO_MEMORY; 91 92 status_t status = get_module(B_ISA_MODULE_NAME, (module_info **)&gISA); 93 if (status < B_OK) 94 goto err1; 95 96 gDeviceNames[0] = strdup("graphics/vesa"); 97 gDeviceNames[1] = NULL; 98 99 status = init_lock(&gLock, "vesa lock"); 100 if (status == B_OK) 101 return B_OK; 102 103 free(gDeviceNames[0]); 104 put_module(B_ISA_MODULE_NAME); 105 err1: 106 free(gDeviceInfo[0]); 107 return status; 108 } 109 110 111 void 112 uninit_driver(void) 113 { 114 TRACE((DEVICE_NAME ": uninit_driver()\n")); 115 116 put_module(B_ISA_MODULE_NAME); 117 uninit_lock(&gLock); 118 119 // free device related structures 120 char *name; 121 for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) { 122 free(gDeviceInfo[index]); 123 free(name); 124 } 125 } 126 127 128 device_hooks * 129 find_device(const char *name) 130 { 131 int index; 132 133 TRACE((DEVICE_NAME ": find_device()\n")); 134 135 for (index = 0; gDeviceNames[index] != NULL; index++) 136 if (!strcmp(name, gDeviceNames[index])) 137 return &gDeviceHooks; 138 139 return NULL; 140 } 141 142