1 /* 2 * Copyright 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 "bus.h" 8 9 #include <KernelExport.h> 10 #include <PCI.h> 11 12 13 #define DRIVER_MODULE_NAME "drivers/graphics/generic_driver/driver_v1" 14 #define DRIVER_DEVICE_MODULE_NAME "drivers/graphics/generic_driver/device_v1" 15 16 17 // #pragma mark - driver 18 19 20 static float 21 supports_device(device_node* parent) 22 { 23 bus_for_driver_module_info* module; 24 void* data; 25 gDeviceManager->get_driver(parent, (driver_module_info**)&module, &data); 26 27 if (strcmp(module->info.info.name, BUS_FOR_DRIVER_NAME)) 28 return -1; 29 30 uint16 type; 31 if (gDeviceManager->get_attr_uint16(parent, B_DEVICE_TYPE, &type, false) 32 != B_OK) 33 return -1; 34 35 if (type == PCI_display) 36 return 0.1; 37 38 return 0.0; 39 } 40 41 42 static status_t 43 register_device(device_node* parent) 44 { 45 return gDeviceManager->register_node(parent, DRIVER_MODULE_NAME, NULL, 46 NULL, NULL); 47 } 48 49 50 static status_t 51 init_driver(device_node* node, void** _cookie) 52 { 53 *_cookie = node; 54 return B_OK; 55 } 56 57 58 static void 59 uninit_driver(void* cookie) 60 { 61 } 62 63 64 static status_t 65 register_child_devices(void* cookie) 66 { 67 device_node* node = (device_node*)cookie; 68 69 gDeviceManager->publish_device(node, "graphics/generic/0", 70 DRIVER_DEVICE_MODULE_NAME); 71 return B_OK; 72 } 73 74 75 static void 76 device_removed(device_node* node) 77 { 78 } 79 80 81 // #pragma mark - device 82 83 84 static status_t 85 init_device(void* driverCookie, void** _deviceCookie) 86 { 87 // called once before one or several open() calls 88 return B_OK; 89 } 90 91 92 static void 93 uninit_device(void* deviceCookie) 94 { 95 // supposed to free deviceCookie, called when the last reference to 96 // the device is closed 97 } 98 99 100 static status_t 101 device_open(void* deviceCookie, int openMode, void** _cookie) 102 { 103 // deviceCookie is an object attached to the published device 104 return B_ERROR; 105 } 106 107 108 static status_t 109 device_close(void* cookie) 110 { 111 return B_ERROR; 112 } 113 114 115 static status_t 116 device_free(void* cookie) 117 { 118 return B_ERROR; 119 } 120 121 122 static status_t 123 device_read(void* cookie, off_t pos, void* buffer, size_t* _length) 124 { 125 return B_ERROR; 126 } 127 128 129 static status_t 130 device_write(void* cookie, off_t pos, const void* buffer, size_t* _length) 131 { 132 return B_ERROR; 133 } 134 135 136 static status_t 137 device_ioctl(void* cookie, int32 op, void* buffer, size_t length) 138 { 139 return B_ERROR; 140 } 141 142 143 static status_t 144 device_io(void* cookie, io_request* request) 145 { 146 // new function to deal with I/O requests directly. 147 return B_ERROR; 148 } 149 150 151 // #pragma mark - 152 153 154 struct driver_module_info gGenericVideoDriverModuleInfo = { 155 { 156 DRIVER_MODULE_NAME, 157 0, 158 NULL, 159 }, 160 161 supports_device, 162 register_device, 163 init_driver, 164 uninit_driver, 165 register_child_devices, 166 NULL, 167 device_removed, 168 }; 169 170 struct device_module_info gGenericVideoDeviceModuleInfo = { 171 { 172 DRIVER_DEVICE_MODULE_NAME, 173 0, 174 NULL, 175 }, 176 177 init_device, 178 uninit_device, 179 NULL, // device_removed 180 181 device_open, 182 device_close, 183 device_free, 184 device_read, 185 device_write, 186 device_ioctl, 187 device_io, 188 }; 189