vboxvideo_drm.c revision e43535ace2499e7f8ef8822186047979bd58d464
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync/** @file $Id$
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * VirtualBox Additions Linux kernel driver, DRM support
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync */
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync/*
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * available from http://www.virtualbox.org. This file is free software;
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * you can redistribute it and/or modify it under the terms of the GNU
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * General Public License (GPL) as published by the Free Software
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * additional information or have any questions.
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * --------------------------------------------------------------------
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * This code is based on:
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * tdfx_drv.c -- tdfx driver -*- linux-c -*-
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Created: Thu Oct 7 10:38:32 1999 by faith@precisioninsight.com
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * All Rights Reserved.
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Permission is hereby granted, free of charge, to any person obtaining a
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * copy of this software and associated documentation files (the "Software"),
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * to deal in the Software without restriction, including without limitation
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * the rights to use, copy, modify, merge, publish, distribute, sublicense,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * and/or sell copies of the Software, and to permit persons to whom the
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Software is furnished to do so, subject to the following conditions:
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * The above copyright notice and this permission notice (including the next
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * paragraph) shall be included in all copies or substantial portions of the
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Software.
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * DEALINGS IN THE SOFTWARE.
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Authors:
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Rickard E. (Rik) Faith <faith@valinux.com>
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Daryll Strauss <daryll@valinux.com>
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * Gareth Hughes <gareth@valinux.com>
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync */
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
45d5cb099583c61c3b7ebf80f58c55d1362b80a9vboxsync#ifndef AUTOCONF_INCLUDED
45d5cb099583c61c3b7ebf80f58c55d1362b80a9vboxsync# include <linux/autoconf.h>
45d5cb099583c61c3b7ebf80f58c55d1362b80a9vboxsync#endif
e4d40e67c9cbfecb0b2ed48eec081648ba3a14bavboxsync#include <linux/version.h>
e482bceaf56f15ca2dc706c32feeb275933d96f9vboxsync#include <linux/module.h>
e43535ace2499e7f8ef8822186047979bd58d464vboxsync#include "version-generated.h"
e4d40e67c9cbfecb0b2ed48eec081648ba3a14bavboxsync
e4d40e67c9cbfecb0b2ed48eec081648ba3a14bavboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
e4d40e67c9cbfecb0b2ed48eec081648ba3a14bavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync#include "drm/drmP.h"
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync#include "vboxvideo_drm.h"
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncstatic struct pci_device_id pciidlist[] = {
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync vboxvideo_PCI_IDS
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync};
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsyncint vboxvideo_driver_load(struct drm_device * dev, unsigned long flags)
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync{
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync# if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 28)
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync return drm_vblank_init(dev, 1);
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync#else
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync return 0;
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync#endif
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync}
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncstatic struct drm_driver driver = {
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync /* .driver_features = DRIVER_USE_MTRR, */
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync .load = vboxvideo_driver_load,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .reclaim_buffers = drm_core_reclaim_buffers,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .get_map_ofs = drm_core_get_map_ofs,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .get_reg_ofs = drm_core_get_reg_ofs,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .fops = {
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .owner = THIS_MODULE,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .open = drm_open,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .release = drm_release,
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync /* This was changed with Linux 2.6.33 but Fedora backported this
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync * change to their 2.6.32 kernel. */
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync#if defined(DRM_UNLOCKED) || LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 33)
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync .unlocked_ioctl = drm_ioctl,
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync#else
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .ioctl = drm_ioctl,
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync#endif
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .mmap = drm_mmap,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .poll = drm_poll,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .fasync = drm_fasync,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync },
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .pci_driver = {
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .name = DRIVER_NAME,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .id_table = pciidlist,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync },
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .name = DRIVER_NAME,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .desc = DRIVER_DESC,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .date = DRIVER_DATE,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .major = DRIVER_MAJOR,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .minor = DRIVER_MINOR,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync .patchlevel = DRIVER_PATCHLEVEL,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync};
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncstatic int __init vboxvideo_init(void)
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync{
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync return drm_init(&driver);
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync}
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncstatic void __exit vboxvideo_exit(void)
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync{
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync drm_exit(&driver);
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync}
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncmodule_init(vboxvideo_init);
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncmodule_exit(vboxvideo_exit);
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncMODULE_AUTHOR(DRIVER_AUTHOR);
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncMODULE_DESCRIPTION(DRIVER_DESC);
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
e4d40e67c9cbfecb0b2ed48eec081648ba3a14bavboxsync#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) */
e482bceaf56f15ca2dc706c32feeb275933d96f9vboxsync
e43535ace2499e7f8ef8822186047979bd58d464vboxsync#ifdef MODULE_VERSION
e43535ace2499e7f8ef8822186047979bd58d464vboxsyncMODULE_VERSION(VBOX_VERSION_STRING);
e43535ace2499e7f8ef8822186047979bd58d464vboxsync#endif
e482bceaf56f15ca2dc706c32feeb275933d96f9vboxsyncMODULE_LICENSE("GPL and additional rights");