VirtualBox

Ignore:
Timestamp:
Sep 22, 2012 4:53:18 PM (12 years ago)
Author:
vboxsync
Message:

Additions/haiku: cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/haiku/VBoxVideo/driver/driver.cpp

    r43366 r43408  
    4545 */
    4646
     47/*******************************************************************************
     48*   Header Files                                                               *
     49*******************************************************************************/
    4750#include <KernelExport.h>
    4851#include <PCI.h>
     
    5760#define VENDOR_ID 0x80ee
    5861#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. */
    6267#define ROUND_TO_PAGE_SIZE(x) (((x) + (B_PAGE_SIZE) - 1) & ~((B_PAGE_SIZE) - 1))
    6368
     
    109114struct DeviceInfo
    110115{
    111     uint32          openCount;                  // count of how many times device has been opened
    112     uint32          flags;                                      // device flags
    113     area_id         sharedArea;                 // area shared between driver and all accelerants
    114     SharedInfo     *sharedInfo;                 // pointer to shared info area memory
    115     pci_info        pciInfo;                    // copy of pci info for this device
    116     char            name[B_OS_NAME_LENGTH]; // name of device
     116    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 */
    117122};
    118123
    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*******************************************************************************/
    126127status_t device_open(const char *name, uint32 flags, void **cookie);
    127128status_t device_close(void *dev);
     
    132133static uint32 get_color_space_for_depth(uint32 depth);
    133134
     135/*******************************************************************************
     136*   Globals                                                                    *
     137*******************************************************************************/
     138/* At most one virtual video card ever appears, no reason for this to be an array */
     139static DeviceInfo gDeviceInfo;
     140static char *gDeviceNames[2] = { gDeviceInfo.name, NULL };
     141static bool gCanHasDevice = false; /* is the device present? */
     142static Benaphore gLock;
     143static pci_module_info *gPCI;
     144
    134145static device_hooks gDeviceHooks =
    135146{
    136     device_open, // open
    137     device_close, // close
    138     device_free, // free
    139     device_ioctl, // control
    140     device_read, // read
    141     device_write, // write
    142     NULL, // select
    143     NULL, // deselect
    144     NULL, // read_pages
    145     NULL  // write_pages
     147    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 */
    146157};
    147158
     159
    148160status_t init_hardware()
    149161{
    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
    166178
    167179status_t init_driver()
    168180{
    169     TRACE("init_driver\n");
     181    LogFlowFunc(("init_driver\n"));
    170182
    171183    gLock.Init("VBoxVideo driver lock");
     
    202214            gDeviceInfo.sharedInfo->currentMode.timing.h_display = width;
    203215            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: */
    205217            gDeviceInfo.sharedInfo->currentMode.timing.h_total = 1000;
    206218            gDeviceInfo.sharedInfo->currentMode.timing.v_total = 1;
    207219            gDeviceInfo.sharedInfo->currentMode.timing.pixel_clock = 850;
    208220
    209             // map the PCI memory space
     221            /* Map the PCI memory space */
    210222            uint32 command_reg = gPCI->read_pci_config(gDeviceInfo.pciInfo.bus,
    211223                                                       gDeviceInfo.pciInfo.device, gDeviceInfo.pciInfo.function,  PCI_command, 2);
     
    232244const char** publish_devices()
    233245{
    234     TRACE("publish_devices\n");
     246    LogFlowFunc(("publish_devices\n"));
    235247    if (gCanHasDevice)
    236248        return (const char **)gDeviceNames;
     
    241253device_hooks* find_device(const char *name)
    242254{
    243     TRACE("find_device\n");
     255    LogFlowFunc(a("find_device\n"));
    244256    if (gCanHasDevice && strcmp(name, gDeviceInfo.name) == 0)
    245257        return &gDeviceHooks;
     
    251263void uninit_driver()
    252264{
    253     TRACE("uninit_driver\n");
     265    LogFlowFunc(("uninit_driver\n"));
    254266    gLock.Delete();
    255267    put_module(VBOXGUEST_MODULE_NAME);
     
    258270status_t device_open(const char *name, uint32 flags, void **cookie)
    259271{
    260     TRACE("device_open\n");
     272    LogFlowFunc(("device_open\n"));
    261273
    262274    if (!gCanHasDevice || strcmp(name, gDeviceInfo.name) != 0)
    263275        return B_BAD_VALUE;
    264276
    265     // TODO init device!
     277    /* @todo init device! */
    266278
    267279    *cookie = (void *)&gDeviceInfo;
     
    272284status_t device_close(void *dev)
    273285{
    274     TRACE("device_close\n");
     286    LogFlowFunc(("device_close\n"));
    275287    return B_ERROR;
    276288}
     
    279291status_t device_free(void *dev)
    280292{
    281     TRACE("device_free\n");
     293    LogFlowFunc(("device_free\n"));
    282294
    283295    DeviceInfo& di = *(DeviceInfo *)dev;
     
    303315status_t device_read(void *dev, off_t pos, void *buf, size_t *len)
    304316{
    305     TRACE("device_read\n");
     317    LogFlowFunc(("device_read\n"));
    306318    return B_NOT_ALLOWED;
    307319}
     
    310322status_t device_write(void *dev, off_t pos, const void *buf, size_t *len)
    311323{
    312     TRACE("device_write\n");
     324    LogFlowFunc(("device_write\n"));
    313325    return B_NOT_ALLOWED;
    314326}
     
    317329status_t device_ioctl(void *cookie, uint32 msg, void *buf, size_t len)
    318330{
    319     TRACE("device_ioctl\n");
     331    LogFlowFunc(("device_ioctl\n"));
    320332
    321333    DeviceInfo *dev = (DeviceInfo *)cookie;
     
    324336    {
    325337        case B_GET_ACCELERANT_SIGNATURE:
     338        {
    326339            strcpy((char *)buf, "vboxvideo.accelerant");
    327340            return B_OK;
     341        }
    328342
    329343        case VBOXVIDEO_GET_PRIVATE_DATA:
     344        {
     345            /** @todo r=ramshankar: implement RTR0MemUserCopyFrom for haiku. */
    330346            return user_memcpy(buf, &dev->sharedArea, sizeof(area_id));
     347        }
    331348
    332349        case VBOXVIDEO_GET_DEVICE_NAME:
     350        {
     351            /** @todo r=ramshankar: implement RTR0MemUserCopyFrom for haiku. */
    333352            if (user_strlcpy((char *)buf, gDeviceInfo.name, len) < B_OK)
    334353                return B_BAD_ADDRESS;
    335             else
    336                 return B_OK;
     354            return B_OK;
     355        }
    337356
    338357        case VBOXVIDEO_SET_DISPLAY_MODE:
     
    347366            return B_BAD_VALUE;
    348367    }
    349 
    350 }
    351 
     368}
     369
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette