1 // SPDX-License-Identifier: MIT
3 * Copyright (C) 2013-2017 Oracle Corporation
4 * This file is based on ast_drv.c
5 * Copyright 2012 Red Hat Inc.
10 #include <linux/module.h>
11 #include <linux/pci.h>
12 #include <linux/vt_kern.h>
14 #include <drm/drm_aperture.h>
15 #include <drm/drm_drv.h>
16 #include <drm/drm_fbdev_generic.h>
17 #include <drm/drm_file.h>
18 #include <drm/drm_ioctl.h>
19 #include <drm/drm_managed.h>
20 #include <drm/drm_modeset_helper.h>
21 #include <drm/drm_module.h>
25 static int vbox_modeset = -1;
27 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
28 module_param_named(modeset, vbox_modeset, int, 0400);
30 static const struct drm_driver driver;
32 static const struct pci_device_id pciidlist[] = {
33 { PCI_DEVICE(0x80ee, 0xbeef) },
36 MODULE_DEVICE_TABLE(pci, pciidlist);
38 static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40 struct vbox_private *vbox;
43 if (!vbox_check_supported(VBE_DISPI_ID_HGSMI))
46 ret = drm_aperture_remove_conflicting_pci_framebuffers(pdev, &driver);
50 vbox = devm_drm_dev_alloc(&pdev->dev, &driver,
51 struct vbox_private, ddev);
55 pci_set_drvdata(pdev, vbox);
56 mutex_init(&vbox->hw_mutex);
58 ret = pcim_enable_device(pdev);
62 ret = vbox_hw_init(vbox);
66 ret = vbox_mm_init(vbox);
70 ret = vbox_mode_init(vbox);
74 ret = vbox_irq_init(vbox);
78 ret = drm_dev_register(&vbox->ddev, 0);
82 drm_fbdev_generic_setup(&vbox->ddev, 32);
95 static void vbox_pci_remove(struct pci_dev *pdev)
97 struct vbox_private *vbox = pci_get_drvdata(pdev);
99 drm_dev_unregister(&vbox->ddev);
101 vbox_mode_fini(vbox);
105 static int vbox_pm_suspend(struct device *dev)
107 struct vbox_private *vbox = dev_get_drvdata(dev);
108 struct pci_dev *pdev = to_pci_dev(dev);
111 error = drm_mode_config_helper_suspend(&vbox->ddev);
115 pci_save_state(pdev);
116 pci_disable_device(pdev);
117 pci_set_power_state(pdev, PCI_D3hot);
122 static int vbox_pm_resume(struct device *dev)
124 struct vbox_private *vbox = dev_get_drvdata(dev);
125 struct pci_dev *pdev = to_pci_dev(dev);
127 if (pci_enable_device(pdev))
130 return drm_mode_config_helper_resume(&vbox->ddev);
133 static int vbox_pm_freeze(struct device *dev)
135 struct vbox_private *vbox = dev_get_drvdata(dev);
137 return drm_mode_config_helper_suspend(&vbox->ddev);
140 static int vbox_pm_thaw(struct device *dev)
142 struct vbox_private *vbox = dev_get_drvdata(dev);
144 return drm_mode_config_helper_resume(&vbox->ddev);
147 static int vbox_pm_poweroff(struct device *dev)
149 struct vbox_private *vbox = dev_get_drvdata(dev);
151 return drm_mode_config_helper_suspend(&vbox->ddev);
154 static const struct dev_pm_ops vbox_pm_ops = {
155 .suspend = vbox_pm_suspend,
156 .resume = vbox_pm_resume,
157 .freeze = vbox_pm_freeze,
158 .thaw = vbox_pm_thaw,
159 .poweroff = vbox_pm_poweroff,
160 .restore = vbox_pm_resume,
163 static struct pci_driver vbox_pci_driver = {
165 .id_table = pciidlist,
166 .probe = vbox_pci_probe,
167 .remove = vbox_pci_remove,
168 .driver.pm = pm_sleep_ptr(&vbox_pm_ops),
171 DEFINE_DRM_GEM_FOPS(vbox_fops);
173 static const struct drm_driver driver = {
175 DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
181 .major = DRIVER_MAJOR,
182 .minor = DRIVER_MINOR,
183 .patchlevel = DRIVER_PATCHLEVEL,
188 drm_module_pci_driver_if_modeset(vbox_pci_driver, vbox_modeset);
190 MODULE_AUTHOR("Oracle Corporation");
192 MODULE_DESCRIPTION(DRIVER_DESC);
193 MODULE_LICENSE("GPL and additional rights");