vbox_drv.c revision 771febc40626f2757c4c9e8d02d46b317f3e586b
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync/** @file $Id$
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync *
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * VirtualBox Additions Linux kernel video driver
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync */
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync/*
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * Copyright (C) 2013 Oracle Corporation
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync *
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * available from http://www.virtualbox.org. This file is free software;
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * General Public License (GPL) as published by the Free Software
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * --------------------------------------------------------------------
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync *
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * This code is based on
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * ast_drv.c
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * with the following copyright and permission notice:
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync *
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * Copyright 2012 Red Hat Inc.
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync *
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * Permission is hereby granted, free of charge, to any person obtaining a
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * copy of this software and associated documentation files (the
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * "Software"), to deal in the Software without restriction, including
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * without limitation the rights to use, copy, modify, merge, publish,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * distribute, sub license, and/or sell copies of the Software, and to
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * permit persons to whom the Software is furnished to do so, subject to
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * the following conditions:
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync *
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * USE OR OTHER DEALINGS IN THE SOFTWARE.
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync *
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * The above copyright notice and this permission notice (including the
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * next paragraph) shall be included in all copies or substantial portions
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * of the Software.
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync *
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync */
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync/*
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync * Authors: Dave Airlie <airlied@redhat.com>
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync */
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#include "vbox_drv.h"
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#include <linux/module.h>
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#include <linux/console.h>
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#include <drm/drmP.h>
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#include <drm/drm_crtc_helper.h>
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncint vbox_modeset = -1;
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncMODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncmodule_param_named(modeset, vbox_modeset, int, 0400);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic struct drm_driver driver;
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync {0x80ee, 0xbeef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync {0, 0, 0},
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync};
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncMODULE_DEVICE_TABLE(pci, pciidlist);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync{
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync return drm_get_pci_dev(pdev, ent, &driver);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync}
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic void
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncvbox_pci_remove(struct pci_dev *pdev)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync{
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync struct drm_device *dev = pci_get_drvdata(pdev);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync drm_put_dev(dev);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync}
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic struct pci_driver vbox_pci_driver = {
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .name = DRIVER_NAME,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .id_table = pciidlist,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .probe = vbox_pci_probe,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .remove = vbox_pci_remove,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync};
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic const struct file_operations vbox_fops = {
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .owner = THIS_MODULE,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .open = drm_open,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .release = drm_release,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .unlocked_ioctl = drm_ioctl,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .mmap = vbox_mmap,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .poll = drm_poll,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .fasync = drm_fasync,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#ifdef CONFIG_COMPAT
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .compat_ioctl = drm_compat_ioctl,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#endif
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .read = drm_read,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync};
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic struct drm_driver driver = {
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .driver_features = DRIVER_USE_MTRR | DRIVER_MODESET | DRIVER_GEM,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .dev_priv_size = 0,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .load = vbox_driver_load,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .unload = vbox_driver_unload,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .fops = &vbox_fops,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .name = DRIVER_NAME,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .desc = DRIVER_DESC,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .date = DRIVER_DATE,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .major = DRIVER_MAJOR,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .minor = DRIVER_MINOR,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .patchlevel = DRIVER_PATCHLEVEL,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .gem_init_object = vbox_gem_init_object,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .gem_free_object = vbox_gem_free_object,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .dumb_create = vbox_dumb_create,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .dumb_map_offset = vbox_dumb_mmap_offset,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync .dumb_destroy = vbox_dumb_destroy,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync};
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic int __init vbox_init(void)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync{
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#ifdef CONFIG_VGA_CONSOLE
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync if (vgacon_text_force() && vbox_modeset == -1)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync return -EINVAL;
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#endif
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync if (vbox_modeset == 0)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync return -EINVAL;
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync return drm_pci_init(&driver, &vbox_pci_driver);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync}
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic void __exit vbox_exit(void)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync{
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync drm_pci_exit(&driver, &vbox_pci_driver);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync}
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncmodule_init(vbox_init);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncmodule_exit(vbox_exit);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncMODULE_AUTHOR(DRIVER_AUTHOR);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncMODULE_DESCRIPTION(DRIVER_DESC);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncMODULE_LICENSE("GPL and additional rights");
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync