root/drivers/gpu/drm/mgag200/mgag200_drv.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mga_pci_probe
  2. mga_pci_remove
  3. mgag200_pin_bo_at_0
  4. mgag200_driver_dumb_create
  5. mgag200_init
  6. mgag200_exit

   1 // SPDX-License-Identifier: GPL-2.0-only
   2 /*
   3  * Copyright 2012 Red Hat
   4  *
   5  * Authors: Matthew Garrett
   6  *          Dave Airlie
   7  */
   8 
   9 #include <linux/module.h>
  10 #include <linux/console.h>
  11 
  12 #include <drm/drm_drv.h>
  13 #include <drm/drm_file.h>
  14 #include <drm/drm_ioctl.h>
  15 #include <drm/drm_pci.h>
  16 #include <drm/drm_pciids.h>
  17 
  18 #include "mgag200_drv.h"
  19 
  20 /*
  21  * This is the generic driver code. This binds the driver to the drm core,
  22  * which then performs further device association and calls our graphics init
  23  * functions
  24  */
  25 int mgag200_modeset = -1;
  26 
  27 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  28 module_param_named(modeset, mgag200_modeset, int, 0400);
  29 
  30 static struct drm_driver driver;
  31 
  32 static const struct pci_device_id pciidlist[] = {
  33         { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  34                 G200_SE_A | MGAG200_FLAG_HW_BUG_NO_STARTADD},
  35         { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
  36         { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
  37         { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
  38         { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
  39         { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
  40         { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
  41         { PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
  42         {0,}
  43 };
  44 
  45 MODULE_DEVICE_TABLE(pci, pciidlist);
  46 
  47 
  48 static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  49 {
  50         drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "mgag200drmfb");
  51 
  52         return drm_get_pci_dev(pdev, ent, &driver);
  53 }
  54 
  55 static void mga_pci_remove(struct pci_dev *pdev)
  56 {
  57         struct drm_device *dev = pci_get_drvdata(pdev);
  58 
  59         drm_put_dev(dev);
  60 }
  61 
  62 static const struct file_operations mgag200_driver_fops = {
  63         .owner = THIS_MODULE,
  64         DRM_VRAM_MM_FILE_OPERATIONS
  65 };
  66 
  67 static bool mgag200_pin_bo_at_0(const struct mga_device *mdev)
  68 {
  69         return mdev->flags & MGAG200_FLAG_HW_BUG_NO_STARTADD;
  70 }
  71 
  72 int mgag200_driver_dumb_create(struct drm_file *file,
  73                                struct drm_device *dev,
  74                                struct drm_mode_create_dumb *args)
  75 {
  76         struct mga_device *mdev = dev->dev_private;
  77         unsigned long pg_align;
  78 
  79         if (WARN_ONCE(!dev->vram_mm, "VRAM MM not initialized"))
  80                 return -EINVAL;
  81 
  82         pg_align = 0ul;
  83 
  84         /*
  85          * Aligning scanout buffers to the size of the video ram forces
  86          * placement at offset 0. Works around a bug where HW does not
  87          * respect 'startadd' field.
  88          */
  89         if (mgag200_pin_bo_at_0(mdev))
  90                 pg_align = PFN_UP(mdev->mc.vram_size);
  91 
  92         return drm_gem_vram_fill_create_dumb(file, dev, &dev->vram_mm->bdev,
  93                                              pg_align, false, args);
  94 }
  95 
  96 static struct drm_driver driver = {
  97         .driver_features = DRIVER_GEM | DRIVER_MODESET,
  98         .load = mgag200_driver_load,
  99         .unload = mgag200_driver_unload,
 100         .fops = &mgag200_driver_fops,
 101         .name = DRIVER_NAME,
 102         .desc = DRIVER_DESC,
 103         .date = DRIVER_DATE,
 104         .major = DRIVER_MAJOR,
 105         .minor = DRIVER_MINOR,
 106         .patchlevel = DRIVER_PATCHLEVEL,
 107         .dumb_create = mgag200_driver_dumb_create,
 108         .dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset,
 109         .gem_prime_mmap = drm_gem_prime_mmap,
 110 };
 111 
 112 static struct pci_driver mgag200_pci_driver = {
 113         .name = DRIVER_NAME,
 114         .id_table = pciidlist,
 115         .probe = mga_pci_probe,
 116         .remove = mga_pci_remove,
 117 };
 118 
 119 static int __init mgag200_init(void)
 120 {
 121         if (vgacon_text_force() && mgag200_modeset == -1)
 122                 return -EINVAL;
 123 
 124         if (mgag200_modeset == 0)
 125                 return -EINVAL;
 126 
 127         return pci_register_driver(&mgag200_pci_driver);
 128 }
 129 
 130 static void __exit mgag200_exit(void)
 131 {
 132         pci_unregister_driver(&mgag200_pci_driver);
 133 }
 134 
 135 module_init(mgag200_init);
 136 module_exit(mgag200_exit);
 137 
 138 MODULE_AUTHOR(DRIVER_AUTHOR);
 139 MODULE_DESCRIPTION(DRIVER_DESC);
 140 MODULE_LICENSE("GPL");

/* [<][>][^][v][top][bottom][index][help] */