Changeset 43408 in vbox for trunk/src/VBox/Additions/haiku/VBoxVideo/driver
- Timestamp:
- Sep 22, 2012 4:53:18 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/haiku/VBoxVideo/driver/driver.cpp
r43366 r43408 45 45 */ 46 46 47 /******************************************************************************* 48 * Header Files * 49 *******************************************************************************/ 47 50 #include <KernelExport.h> 48 51 #include <PCI.h> … … 57 60 #define VENDOR_ID 0x80ee 58 61 #define DEVICE_ID 0xbeef 59 60 #define DEVICE_FORMAT "vd_%04X_%04X_%02X%02X%02X" 61 62 #define DRIVER_NAME "VBoxVideoDriver" 63 #define DEVICE_FORMAT "vd_%04X_%04X_%02X%02X%02X" 64 65 /** @todo r=ramshankar: pretty sure IPRT has something for page rounding, 66 * replace with IPRT version later. */ 62 67 #define ROUND_TO_PAGE_SIZE(x) (((x) + (B_PAGE_SIZE) - 1) & ~((B_PAGE_SIZE) - 1)) 63 68 … … 109 114 struct DeviceInfo 110 115 { 111 uint32 openCount; / / count of how many times device has been opened112 uint32 flags; / / device flags113 area_id sharedArea; / / area shared between driver and all accelerants114 SharedInfo *sharedInfo; / / pointer to shared info area memory115 pci_info pciInfo; / / copy of pci info for this device116 char name[B_OS_NAME_LENGTH]; / / name of device116 uint32 openCount; /* Count of how many times device has been opened */ 117 uint32 flags; /* Device flags */ 118 area_id sharedArea; /* Area shared between driver and all accelerants */ 119 SharedInfo *sharedInfo; /* Pointer to shared info area memory */ 120 pci_info pciInfo; /* Copy of pci info for this device */ 121 char name[B_OS_NAME_LENGTH]; /* Name of device */ 117 122 }; 118 123 119 // at most one virtual video card ever appears, no reason for this to be an array 120 static DeviceInfo gDeviceInfo; 121 static char *gDeviceNames[2] = { gDeviceInfo.name, NULL }; 122 static bool gCanHasDevice = false; // is the device present? 123 static Benaphore gLock; 124 static pci_module_info *gPCI; 125 124 /******************************************************************************* 125 * Internal Functions * 126 *******************************************************************************/ 126 127 status_t device_open(const char *name, uint32 flags, void **cookie); 127 128 status_t device_close(void *dev); … … 132 133 static uint32 get_color_space_for_depth(uint32 depth); 133 134 135 /******************************************************************************* 136 * Globals * 137 *******************************************************************************/ 138 /* At most one virtual video card ever appears, no reason for this to be an array */ 139 static DeviceInfo gDeviceInfo; 140 static char *gDeviceNames[2] = { gDeviceInfo.name, NULL }; 141 static bool gCanHasDevice = false; /* is the device present? */ 142 static Benaphore gLock; 143 static pci_module_info *gPCI; 144 134 145 static device_hooks gDeviceHooks = 135 146 { 136 device_open, // open137 device_close, // close138 device_free, // free139 device_ioctl, // control140 device_read, // read141 device_write, // write142 NULL, // select143 NULL, // deselect144 NULL, // read_pages145 NULL // write_pages147 device_open, 148 device_close, 149 device_free, 150 device_ioctl, 151 device_read, 152 device_write, 153 NULL, /* select */ 154 NULL, /* deselect */ 155 NULL, /* read_pages */ 156 NULL /* write_pages */ 146 157 }; 147 158 159 148 160 status_t init_hardware() 149 161 { 150 TRACE("init_hardware\n");151 152 if (get_module(VBOXGUEST_MODULE_NAME, (module_info **)&g_VBoxGuest) != B_OK)153 {154 dprintf("get_module(%s) failed\n", VBOXGUEST_MODULE_NAME);155 return B_ERROR;156 }157 158 if (get_module(B_PCI_MODULE_NAME, (module_info **)&gPCI) != B_OK) 159 {160 dprintf("get_module(%s) failed\n", B_PCI_MODULE_NAME);161 return B_ERROR;162 }163 164 return B_OK; 165 } 162 LogFlowFunc(("init_hardware\n")); 163 164 status_t err = get_module(VBOXGUEST_MODULE_NAME, (module_info **)&g_VBoxGuest) 165 if (err == B_OK) 166 { 167 err = get_module(B_PCI_MODULE_NAME, (module_info **)&gPCI); 168 if (err == B_OK) 169 return B_OK; 170 171 LogRel((DRIVER_NAME ":_init_hardware() get_module(%s) failed. err=%08lx\n", B_PCI_MODULE_NAME)); 172 } 173 else 174 LogRel((DRIVER_NAME ":_init_hardware() get_module(%s) failed. err=%08lx\n", VBOXGUEST_MODULE_NAME, err)); 175 return B_ERROR; 176 } 177 166 178 167 179 status_t init_driver() 168 180 { 169 TRACE("init_driver\n");181 LogFlowFunc(("init_driver\n")); 170 182 171 183 gLock.Init("VBoxVideo driver lock"); … … 202 214 gDeviceInfo.sharedInfo->currentMode.timing.h_display = width; 203 215 gDeviceInfo.sharedInfo->currentMode.timing.v_display = height; 204 / / not used, but this makes a reasonable-sounding refresh rate show in screen prefs:216 /* Not used, but this makes a reasonable-sounding refresh rate show in screen prefs: */ 205 217 gDeviceInfo.sharedInfo->currentMode.timing.h_total = 1000; 206 218 gDeviceInfo.sharedInfo->currentMode.timing.v_total = 1; 207 219 gDeviceInfo.sharedInfo->currentMode.timing.pixel_clock = 850; 208 220 209 / / map the PCI memory space221 /* Map the PCI memory space */ 210 222 uint32 command_reg = gPCI->read_pci_config(gDeviceInfo.pciInfo.bus, 211 223 gDeviceInfo.pciInfo.device, gDeviceInfo.pciInfo.function, PCI_command, 2); … … 232 244 const char** publish_devices() 233 245 { 234 TRACE("publish_devices\n");246 LogFlowFunc(("publish_devices\n")); 235 247 if (gCanHasDevice) 236 248 return (const char **)gDeviceNames; … … 241 253 device_hooks* find_device(const char *name) 242 254 { 243 TRACE("find_device\n");255 LogFlowFunc(a("find_device\n")); 244 256 if (gCanHasDevice && strcmp(name, gDeviceInfo.name) == 0) 245 257 return &gDeviceHooks; … … 251 263 void uninit_driver() 252 264 { 253 TRACE("uninit_driver\n");265 LogFlowFunc(("uninit_driver\n")); 254 266 gLock.Delete(); 255 267 put_module(VBOXGUEST_MODULE_NAME); … … 258 270 status_t device_open(const char *name, uint32 flags, void **cookie) 259 271 { 260 TRACE("device_open\n");272 LogFlowFunc(("device_open\n")); 261 273 262 274 if (!gCanHasDevice || strcmp(name, gDeviceInfo.name) != 0) 263 275 return B_BAD_VALUE; 264 276 265 / / TODO init device!277 /* @todo init device! */ 266 278 267 279 *cookie = (void *)&gDeviceInfo; … … 272 284 status_t device_close(void *dev) 273 285 { 274 TRACE("device_close\n");286 LogFlowFunc(("device_close\n")); 275 287 return B_ERROR; 276 288 } … … 279 291 status_t device_free(void *dev) 280 292 { 281 TRACE("device_free\n");293 LogFlowFunc(("device_free\n")); 282 294 283 295 DeviceInfo& di = *(DeviceInfo *)dev; … … 303 315 status_t device_read(void *dev, off_t pos, void *buf, size_t *len) 304 316 { 305 TRACE("device_read\n");317 LogFlowFunc(("device_read\n")); 306 318 return B_NOT_ALLOWED; 307 319 } … … 310 322 status_t device_write(void *dev, off_t pos, const void *buf, size_t *len) 311 323 { 312 TRACE("device_write\n");324 LogFlowFunc(("device_write\n")); 313 325 return B_NOT_ALLOWED; 314 326 } … … 317 329 status_t device_ioctl(void *cookie, uint32 msg, void *buf, size_t len) 318 330 { 319 TRACE("device_ioctl\n");331 LogFlowFunc(("device_ioctl\n")); 320 332 321 333 DeviceInfo *dev = (DeviceInfo *)cookie; … … 324 336 { 325 337 case B_GET_ACCELERANT_SIGNATURE: 338 { 326 339 strcpy((char *)buf, "vboxvideo.accelerant"); 327 340 return B_OK; 341 } 328 342 329 343 case VBOXVIDEO_GET_PRIVATE_DATA: 344 { 345 /** @todo r=ramshankar: implement RTR0MemUserCopyFrom for haiku. */ 330 346 return user_memcpy(buf, &dev->sharedArea, sizeof(area_id)); 347 } 331 348 332 349 case VBOXVIDEO_GET_DEVICE_NAME: 350 { 351 /** @todo r=ramshankar: implement RTR0MemUserCopyFrom for haiku. */ 333 352 if (user_strlcpy((char *)buf, gDeviceInfo.name, len) < B_OK) 334 353 return B_BAD_ADDRESS; 335 else336 return B_OK;354 return B_OK; 355 } 337 356 338 357 case VBOXVIDEO_SET_DISPLAY_MODE: … … 347 366 return B_BAD_VALUE; 348 367 } 349 350 } 351 368 } 369
Note:
See TracChangeset
for help on using the changeset viewer.