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_atomic_helper.h>
16 #include <drm/drm_drv.h>
17 #include <drm/drm_fbdev_generic.h>
18 #include <drm/drm_file.h>
19 #include <drm/drm_ioctl.h>
20 #include <drm/drm_managed.h>
21 #include <drm/drm_modeset_helper.h>
22 #include <drm/drm_module.h>
26 static int vbox_modeset = -1;
28 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
29 module_param_named(modeset, vbox_modeset, int, 0400);
31 static const struct drm_driver driver;
33 static const struct pci_device_id pciidlist[] = {
34 { PCI_DEVICE(0x80ee, 0xbeef) },
37 MODULE_DEVICE_TABLE(pci, pciidlist);
39 static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
41 struct vbox_private *vbox;
44 if (!vbox_check_supported(VBE_DISPI_ID_HGSMI))
47 ret = drm_aperture_remove_conflicting_pci_framebuffers(pdev, &driver);
51 vbox = devm_drm_dev_alloc(&pdev->dev, &driver,
52 struct vbox_private, ddev);
56 pci_set_drvdata(pdev, vbox);
57 mutex_init(&vbox->hw_mutex);
59 ret = pcim_enable_device(pdev);
63 ret = vbox_hw_init(vbox);
67 ret = vbox_mm_init(vbox);
71 ret = vbox_mode_init(vbox);
75 ret = vbox_irq_init(vbox);
79 ret = drm_dev_register(&vbox->ddev, 0);
83 drm_fbdev_generic_setup(&vbox->ddev, 32);
96 static void vbox_pci_remove(struct pci_dev *pdev)
98 struct vbox_private *vbox = pci_get_drvdata(pdev);
100 drm_dev_unregister(&vbox->ddev);
101 drm_atomic_helper_shutdown(&vbox->ddev);
103 vbox_mode_fini(vbox);
107 static void vbox_pci_shutdown(struct pci_dev *pdev)
109 struct vbox_private *vbox = pci_get_drvdata(pdev);
111 drm_atomic_helper_shutdown(&vbox->ddev);
114 static int vbox_pm_suspend(struct device *dev)
116 struct vbox_private *vbox = dev_get_drvdata(dev);
117 struct pci_dev *pdev = to_pci_dev(dev);
120 error = drm_mode_config_helper_suspend(&vbox->ddev);
124 pci_save_state(pdev);
125 pci_disable_device(pdev);
126 pci_set_power_state(pdev, PCI_D3hot);
131 static int vbox_pm_resume(struct device *dev)
133 struct vbox_private *vbox = dev_get_drvdata(dev);
134 struct pci_dev *pdev = to_pci_dev(dev);
136 if (pci_enable_device(pdev))
139 return drm_mode_config_helper_resume(&vbox->ddev);
142 static int vbox_pm_freeze(struct device *dev)
144 struct vbox_private *vbox = dev_get_drvdata(dev);
146 return drm_mode_config_helper_suspend(&vbox->ddev);
149 static int vbox_pm_thaw(struct device *dev)
151 struct vbox_private *vbox = dev_get_drvdata(dev);
153 return drm_mode_config_helper_resume(&vbox->ddev);
156 static int vbox_pm_poweroff(struct device *dev)
158 struct vbox_private *vbox = dev_get_drvdata(dev);
160 return drm_mode_config_helper_suspend(&vbox->ddev);
163 static const struct dev_pm_ops vbox_pm_ops = {
164 .suspend = vbox_pm_suspend,
165 .resume = vbox_pm_resume,
166 .freeze = vbox_pm_freeze,
167 .thaw = vbox_pm_thaw,
168 .poweroff = vbox_pm_poweroff,
169 .restore = vbox_pm_resume,
172 static struct pci_driver vbox_pci_driver = {
174 .id_table = pciidlist,
175 .probe = vbox_pci_probe,
176 .remove = vbox_pci_remove,
177 .shutdown = vbox_pci_shutdown,
178 .driver.pm = pm_sleep_ptr(&vbox_pm_ops),
181 DEFINE_DRM_GEM_FOPS(vbox_fops);
183 static const struct drm_driver driver = {
185 DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC | DRIVER_CURSOR_HOTSPOT,
191 .major = DRIVER_MAJOR,
192 .minor = DRIVER_MINOR,
193 .patchlevel = DRIVER_PATCHLEVEL,
198 drm_module_pci_driver_if_modeset(vbox_pci_driver, vbox_modeset);
200 MODULE_AUTHOR("Oracle Corporation");
202 MODULE_DESCRIPTION(DRIVER_DESC);
203 MODULE_LICENSE("GPL and additional rights");