mga_drv.c revision 152909
195584Sanholt/* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*- 2145132Sanholt * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com 3145132Sanholt */ 4139749Simp/*- 595584Sanholt * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 695584Sanholt * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 795584Sanholt * All Rights Reserved. 895584Sanholt * 995584Sanholt * Permission is hereby granted, free of charge, to any person obtaining a 1095584Sanholt * copy of this software and associated documentation files (the "Software"), 1195584Sanholt * to deal in the Software without restriction, including without limitation 1295584Sanholt * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1395584Sanholt * and/or sell copies of the Software, and to permit persons to whom the 1495584Sanholt * Software is furnished to do so, subject to the following conditions: 1595584Sanholt * 1695584Sanholt * The above copyright notice and this permission notice (including the next 1795584Sanholt * paragraph) shall be included in all copies or substantial portions of the 1895584Sanholt * Software. 1995584Sanholt * 2095584Sanholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2195584Sanholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2295584Sanholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2395584Sanholt * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 2495584Sanholt * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2595584Sanholt * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2695584Sanholt * OTHER DEALINGS IN THE SOFTWARE. 2795584Sanholt * 2895584Sanholt * Authors: 2995584Sanholt * Rickard E. (Rik) Faith <faith@valinux.com> 3095584Sanholt * Gareth Hughes <gareth@valinux.com> 3195584Sanholt * 3295584Sanholt */ 3395584Sanholt 34152909Sanholt#include <sys/cdefs.h> 35152909Sanholt__FBSDID("$FreeBSD: head/sys/dev/drm/mga_drv.c 152909 2005-11-28 23:13:57Z anholt $"); 36152909Sanholt 3795584Sanholt#include "dev/drm/drmP.h" 38112015Sanholt#include "dev/drm/drm.h" 3995746Sanholt#include "dev/drm/mga_drm.h" 4095584Sanholt#include "dev/drm/mga_drv.h" 41145132Sanholt#include "dev/drm/drm_pciids.h" 4295584Sanholt 43145132Sanholt/* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */ 44145132Sanholtstatic drm_pci_id_list_t mga_pciidlist[] = { 45145132Sanholt mga_PCI_IDS 46145132Sanholt}; 4795584Sanholt 48152909Sanholt/** 49152909Sanholt * Determine if the device really is AGP or not. 50152909Sanholt * 51152909Sanholt * In addition to the usual tests performed by \c drm_device_is_agp, this 52152909Sanholt * function detects PCI G450 cards that appear to the system exactly like 53152909Sanholt * AGP G450 cards. 54152909Sanholt * 55152909Sanholt * \param dev The device to be tested. 56152909Sanholt * 57152909Sanholt * \returns 58152909Sanholt * If the device is a PCI G450, zero is returned. Otherwise non-zero is 59152909Sanholt * returned. 60152909Sanholt * 61152909Sanholt * \bug 62152909Sanholt * This function needs to be filled in! The implementation in 63152909Sanholt * linux-core/mga_drv.c shows what needs to be done. 64152909Sanholt */ 65152909Sanholtstatic int mga_driver_device_is_agp(drm_device_t * dev) 66152909Sanholt{ 67152909Sanholt /* There are PCI versions of the G450. These cards have the 68152909Sanholt * same PCI ID as the AGP G450, but have an additional PCI-to-PCI 69152909Sanholt * bridge chip. We detect these cards, which are not currently 70152909Sanholt * supported by this driver, by looking at the device ID of the 71152909Sanholt * bus the "card" is on. If vendor is 0x3388 (Hint Corp) and the 72152909Sanholt * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the 73152909Sanholt * device. 74152909Sanholt */ 75152909Sanholt if (pci_get_device(dev->device) == 0x0525 && 76152909Sanholt pci_get_vendor(device_get_parent(dev->device)) == 0x3388 && 77152909Sanholt pci_get_device(device_get_parent(dev->device)) == 0x0021) 78152909Sanholt return 0; 79152909Sanholt else 80152909Sanholt return 2; 81152909Sanholt} 82145132Sanholt 83145132Sanholtstatic void mga_configure(drm_device_t *dev) 84145132Sanholt{ 85152909Sanholt dev->driver.buf_priv_size = sizeof(drm_mga_buf_priv_t); 86152909Sanholt dev->driver.load = mga_driver_load; 87152909Sanholt dev->driver.unload = mga_driver_unload; 88152909Sanholt dev->driver.lastclose = mga_driver_lastclose; 89152909Sanholt dev->driver.vblank_wait = mga_driver_vblank_wait; 90152909Sanholt dev->driver.irq_preinstall = mga_driver_irq_preinstall; 91152909Sanholt dev->driver.irq_postinstall = mga_driver_irq_postinstall; 92152909Sanholt dev->driver.irq_uninstall = mga_driver_irq_uninstall; 93152909Sanholt dev->driver.irq_handler = mga_driver_irq_handler; 94152909Sanholt dev->driver.dma_ioctl = mga_dma_buffers; 95152909Sanholt dev->driver.dma_quiescent = mga_driver_dma_quiescent; 96152909Sanholt dev->driver.device_is_agp = mga_driver_device_is_agp; 97145132Sanholt 98152909Sanholt dev->driver.ioctls = mga_ioctls; 99152909Sanholt dev->driver.max_ioctl = mga_max_ioctl; 100145132Sanholt 101152909Sanholt dev->driver.name = DRIVER_NAME; 102152909Sanholt dev->driver.desc = DRIVER_DESC; 103152909Sanholt dev->driver.date = DRIVER_DATE; 104152909Sanholt dev->driver.major = DRIVER_MAJOR; 105152909Sanholt dev->driver.minor = DRIVER_MINOR; 106152909Sanholt dev->driver.patchlevel = DRIVER_PATCHLEVEL; 107145132Sanholt 108152909Sanholt dev->driver.use_agp = 1; 109152909Sanholt dev->driver.require_agp = 1; 110152909Sanholt dev->driver.use_mtrr = 1; 111152909Sanholt dev->driver.use_dma = 1; 112152909Sanholt dev->driver.use_irq = 1; 113152909Sanholt dev->driver.use_vbl_irq = 1; 114145132Sanholt} 115145132Sanholt 116152909Sanholt 117152909Sanholt 118112015Sanholt#ifdef __FreeBSD__ 119145132Sanholtstatic int 120145132Sanholtmga_probe(device_t dev) 121145132Sanholt{ 122145132Sanholt return drm_probe(dev, mga_pciidlist); 123145132Sanholt} 124145132Sanholt 125145132Sanholtstatic int 126145132Sanholtmga_attach(device_t nbdev) 127145132Sanholt{ 128145132Sanholt drm_device_t *dev = device_get_softc(nbdev); 129145132Sanholt 130145132Sanholt bzero(dev, sizeof(drm_device_t)); 131145132Sanholt mga_configure(dev); 132145132Sanholt return drm_attach(nbdev, mga_pciidlist); 133145132Sanholt} 134145132Sanholt 135145132Sanholtstatic device_method_t mga_methods[] = { 136145132Sanholt /* Device interface */ 137145132Sanholt DEVMETHOD(device_probe, mga_probe), 138145132Sanholt DEVMETHOD(device_attach, mga_attach), 139145132Sanholt DEVMETHOD(device_detach, drm_detach), 140145132Sanholt 141145132Sanholt { 0, 0 } 142145132Sanholt}; 143145132Sanholt 144145132Sanholtstatic driver_t mga_driver = { 145145132Sanholt "drm", 146145132Sanholt mga_methods, 147145132Sanholt sizeof(drm_device_t) 148145132Sanholt}; 149145132Sanholt 150145132Sanholtextern devclass_t drm_devclass; 151145132SanholtDRIVER_MODULE(mga, pci, mga_driver, drm_devclass, 0, 0); 152145132SanholtMODULE_DEPEND(mga, drm, 1, 1, 1); 153145132Sanholt 154145132Sanholt#elif defined(__NetBSD__) || defined(__OpenBSD__) 155152909Sanholt#ifdef _LKM 156112015SanholtCFDRIVER_DECL(mga, DV_TTY, NULL); 157152909Sanholt#else 158152909SanholtCFATTACH_DECL(mga, sizeof(drm_device_t), drm_probe, drm_attach, drm_detach, 159152909Sanholt drm_activate); 160112015Sanholt#endif 161152909Sanholt#endif 162