1 /* 2 * Copyright 2005, 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 lock gLock; 36 37 38 extern "C" { 39 status_t init_hardware(void); 40 status_t init_driver(void); 41 void uninit_driver(void); 42 const char **publish_devices(void); 43 device_hooks *find_device(const char *name); 44 } 45 46 #if 0 47 static status_t 48 get_next_graphics_card(int32 *_cookie, pci_info &info) 49 { 50 int32 index = *_cookie; 51 52 // find devices 53 for (; gPCI->get_nth_pci_info(index, &info) == B_OK; index++) { 54 if (info.class_base == PCI_display) { 55 *_cookie = index + 1; 56 return B_OK; 57 } 58 } 59 60 return B_ENTRY_NOT_FOUND; 61 } 62 #endif 63 64 const char ** 65 publish_devices(void) 66 { 67 TRACE((DEVICE_NAME ": publish_devices()\n")); 68 return (const char **)gDeviceNames; 69 } 70 71 72 status_t 73 init_hardware(void) 74 { 75 TRACE((DEVICE_NAME ": init_hardware()\n")); 76 77 return get_boot_item(FRAME_BUFFER_BOOT_INFO) != NULL ? B_OK : B_ERROR; 78 } 79 80 81 status_t 82 init_driver(void) 83 { 84 TRACE((DEVICE_NAME ": init_driver()\n")); 85 86 if ((gDeviceInfo[0] = (vesa_info *)malloc(sizeof(vesa_info))) != NULL) 87 memset(gDeviceInfo[0], 0, sizeof(vesa_info)); 88 else 89 return B_NO_MEMORY; 90 91 gDeviceNames[0] = strdup("graphics/vesa"); 92 gDeviceNames[1] = NULL; 93 94 return init_lock(&gLock, "vesa lock"); 95 } 96 97 98 void 99 uninit_driver(void) 100 { 101 TRACE((DEVICE_NAME ": uninit_driver()\n")); 102 103 uninit_lock(&gLock); 104 105 // free device related structures 106 char *name; 107 for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) { 108 free(gDeviceInfo[index]); 109 free(name); 110 } 111 } 112 113 114 device_hooks * 115 find_device(const char *name) 116 { 117 int index; 118 119 TRACE((DEVICE_NAME ": find_device()\n")); 120 121 for (index = 0; gDeviceNames[index] != NULL; index++) 122 if (!strcmp(name, gDeviceNames[index])) 123 return &gDeviceHooks; 124 125 return NULL; 126 } 127 128