vboxvideo_drm.c revision 28023d61db8b6bb393f447d41e639a246dbae010
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync/** @file $Id$
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync *
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync * VirtualBox Additions Linux kernel driver, DRM support
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync */
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2007 Oracle Corporation
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 *
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
e4d40e67c9cbfecb0b2ed48eec081648ba3a14bavboxsync#include <linux/version.h>
e186c483172ada07f94a5dade662845b77dfe17cvboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
0a6162fc2a1b7abf4508627b77db1654b22aacb8vboxsync# include <generated/autoconf.h>
0a6162fc2a1b7abf4508627b77db1654b22aacb8vboxsync#else
0a6162fc2a1b7abf4508627b77db1654b22aacb8vboxsync# ifndef AUTOCONF_INCLUDED
0a6162fc2a1b7abf4508627b77db1654b22aacb8vboxsync# include <linux/autoconf.h>
0a6162fc2a1b7abf4508627b77db1654b22aacb8vboxsync# endif
0a6162fc2a1b7abf4508627b77db1654b22aacb8vboxsync#endif
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[] = {
28023d61db8b6bb393f447d41e639a246dbae010vboxsync 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)
28023d61db8b6bb393f447d41e639a246dbae010vboxsync return drm_vblank_init(dev, 1);
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync#else
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync return 0;
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync#endif
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync}
11f9b573aa91144e8a077e34864c9df96ec3d64cvboxsync
28023d61db8b6bb393f447d41e639a246dbae010vboxsyncstatic struct drm_driver driver =
28023d61db8b6bb393f447d41e639a246dbae010vboxsync{
28023d61db8b6bb393f447d41e639a246dbae010vboxsync /* .driver_features = DRIVER_USE_MTRR, */
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .load = vboxvideo_driver_load,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .reclaim_buffers = drm_core_reclaim_buffers,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync /* As of Linux 2.65.37, always the internal functions are used. */
d737d2386f85b53f460d5e6f891a09db60e57972vboxsync#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 37)
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .get_map_ofs = drm_core_get_map_ofs,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .get_reg_ofs = drm_core_get_reg_ofs,
d737d2386f85b53f460d5e6f891a09db60e57972vboxsync#endif
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .fops =
28023d61db8b6bb393f447d41e639a246dbae010vboxsync {
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .owner = THIS_MODULE,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .open = drm_open,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .release = drm_release,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync /* This was changed with Linux 2.6.33 but Fedora backported this
28023d61db8b6bb393f447d41e639a246dbae010vboxsync * change to their 2.6.32 kernel. */
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync#if defined(DRM_UNLOCKED) || LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 33)
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .unlocked_ioctl = drm_ioctl,
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync#else
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .ioctl = drm_ioctl,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#endif
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .mmap = drm_mmap,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .poll = drm_poll,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .fasync = drm_fasync,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync },
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39)
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .pci_driver =
28023d61db8b6bb393f447d41e639a246dbae010vboxsync {
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .name = DRIVER_NAME,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .id_table = pciidlist,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync },
6a608eb4f69e5bc1838d17fb9132acbbc6575e7cvboxsync#endif
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .name = DRIVER_NAME,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .desc = DRIVER_DESC,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .date = DRIVER_DATE,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .major = DRIVER_MAJOR,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .minor = DRIVER_MINOR,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .patchlevel = DRIVER_PATCHLEVEL,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync};
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 39)
28023d61db8b6bb393f447d41e639a246dbae010vboxsyncstatic struct pci_driver pci_driver =
28023d61db8b6bb393f447d41e639a246dbae010vboxsync{
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .name = DRIVER_NAME,
28023d61db8b6bb393f447d41e639a246dbae010vboxsync .id_table = pciidlist,
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync};
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#endif
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncstatic int __init vboxvideo_init(void)
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync{
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39)
28023d61db8b6bb393f447d41e639a246dbae010vboxsync return drm_init(&driver);
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#else
28023d61db8b6bb393f447d41e639a246dbae010vboxsync return drm_pci_init(&driver, &pci_driver);
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#endif
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync}
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync
90848209baf53a74f547fcf4254dc56d9b167ecavboxsyncstatic void __exit vboxvideo_exit(void)
90848209baf53a74f547fcf4254dc56d9b167ecavboxsync{
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#if LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 39)
28023d61db8b6bb393f447d41e639a246dbae010vboxsync drm_exit(&driver);
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#else
28023d61db8b6bb393f447d41e639a246dbae010vboxsync drm_pci_exit(&driver, &pci_driver);
28023d61db8b6bb393f447d41e639a246dbae010vboxsync#endif
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");