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
c8b8e7aaf61785a1ea51fcc79a79a80f04eaf319vboxsync#include <VBox/VBoxGuest.h>
c8b8e7aaf61785a1ea51fcc79a79a80f04eaf319vboxsync
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
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsyncstatic DEFINE_PCI_DEVICE_TABLE(pciidlist) =
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync{
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync {0x80ee, 0xbeef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync {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{
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync return drm_get_pci_dev(pdev, ent, &driver);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync}
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsyncstatic void vbox_pci_remove(struct pci_dev *pdev)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync{
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync struct drm_device *dev = pci_get_drvdata(pdev);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync drm_put_dev(dev);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync}
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsyncstatic struct pci_driver vbox_pci_driver =
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync{
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .name = DRIVER_NAME,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .id_table = pciidlist,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .probe = vbox_pci_probe,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .remove = vbox_pci_remove,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync};
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
c8b8e7aaf61785a1ea51fcc79a79a80f04eaf319vboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsyncstatic const struct file_operations vbox_fops =
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync{
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .owner = THIS_MODULE,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .open = drm_open,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .release = drm_release,
7d11300eeeab839003728db4f07924786ea4f848vboxsync .unlocked_ioctl = drm_ioctl,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .mmap = vbox_mmap,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .poll = drm_poll,
7d11300eeeab839003728db4f07924786ea4f848vboxsync#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0)
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .fasync = drm_fasync,
7d11300eeeab839003728db4f07924786ea4f848vboxsync#endif
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#ifdef CONFIG_COMPAT
7d11300eeeab839003728db4f07924786ea4f848vboxsync .compat_ioctl = drm_compat_ioctl,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#endif
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .read = drm_read,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync};
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsyncstatic struct drm_driver driver =
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync{
7d11300eeeab839003728db4f07924786ea4f848vboxsync .driver_features = DRIVER_MODESET | DRIVER_GEM,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .dev_priv_size = 0,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .load = vbox_driver_load,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .unload = vbox_driver_unload,
b60dc9deb80080af0c4284390436f8dd50311dfcvboxsync .lastclose = vbox_driver_lastclose,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .fops = &vbox_fops,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .name = DRIVER_NAME,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .desc = DRIVER_DESC,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .date = DRIVER_DATE,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .major = DRIVER_MAJOR,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .minor = DRIVER_MINOR,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .patchlevel = DRIVER_PATCHLEVEL,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .gem_free_object = vbox_gem_free_object,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .dumb_create = vbox_dumb_create,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .dumb_map_offset = vbox_dumb_mmap_offset,
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync .dumb_destroy = vbox_dumb_destroy,
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync};
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic int __init vbox_init(void)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync{
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#ifdef CONFIG_VGA_CONSOLE
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync if (vgacon_text_force() && vbox_modeset == -1)
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync return -EINVAL;
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync#endif
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync if (vbox_modeset == 0)
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync return -EINVAL;
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync return drm_pci_init(&driver, &vbox_pci_driver);
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync}
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsyncstatic void __exit vbox_exit(void)
771febc40626f2757c4c9e8d02d46b317f3e586bvboxsync{
4d3591cb1089f4a28f197c3eac20983c316f18d7vboxsync 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