-----BEGIN PGP SIGNATURE----- iQJIBAABCgAyFiEEgMe7l+5h9hnxdsnuWYigwDrT+vwFAmA2xiQUHGJoZWxnYWFz QGdvb2dsZS5jb20ACgkQWYigwDrT+vzRDA/9GCyEskI9DMtyT9UeoTMzpHcUZpaU eCbLa2BSPjOKlrHLnPY7IwE0nT7ihe4OOcm8uOYOWtulE46XJNCHfxlUYP3SbI0Y JlG0FBCh4ldzCzzKsftwkSvVhk+gn+ms9ucJ8q2iBSOXVhG/41IbX7++8IfbQM4v VHjdYUmTCCiOSRDtBVi82p4+GAHxH8IhaB0gDNb1Q7myj+qJKL5nKjK/nukgO0fO UpCnSxyua48Ij+c59Y1QAIhGeORq5Gg5Q4ussY3FxS9ovhZODEGQwCFniTfilqRw wEB9Fb8tiPY60ljEyDPnERMkiW69zutTJqOY4LfwmoRM9IEbxD6VPIqF5gin8sB7 pHhX4KUU+eB1hQdK9SGKjkwyehquNKzTdxsu2jccltOKwBm5jcXYeOvu2bJTzZn+ rrZPYJoA1dQig3bEuOzsBxvW4Jaj7IsVfVcao4OzXyh8Y7tLr9kVDXxr7JC/EkPM zRK24yglERD2J1JXgNMvOuJQj6JmRHhEbV/faZci8x8ZEaz1FawRAUZqHf/gGmnW 2CllarHbRnchPyD8btv03Mp84WG6fCfKy7zG2D8HxOsiStDO/5ICehHtGcvYg7IL RuE4Tj8OKdcbw/8cO4C3842FqiSj34+jooNIHSLyBqcpJam6VsN4XqNIZCL+DeG5 Q2JXruAaahTWOZg= =GXL5 -----END PGP SIGNATURE----- Merge tag 'pci-v5.12-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci Pull PCI updates from Bjorn Helgaas: "Enumeration: - Remove unnecessary locking around _OSC (Bjorn Helgaas) - Clarify message about _OSC failure (Bjorn Helgaas) - Remove notification of PCIe bandwidth changes (Bjorn Helgaas) - Tidy checking of syscall user config accessors (Heiner Kallweit) Resource management: - Decline to resize resources if boot config must be preserved (Ard Biesheuvel) - Fix pci_register_io_range() memory leak (Geert Uytterhoeven) Error handling (Keith Busch): - Clear error status from the correct device - Retain error recovery status so drivers can use it after reset - Log the type of Port (Root or Switch Downstream) that we reset - Always request a reset for Downstream Ports in frozen state Endpoint framework and NTB (Kishon Vijay Abraham I): - Make *_get_first_free_bar() take into account 64 bit BAR - Add helper API to get the 'next' unreserved BAR - Make *_free_bar() return error codes on failure - Remove unused pci_epf_match_device() - Add support to associate secondary EPC with EPF - Add support in configfs to associate two EPCs with EPF - Add pci_epc_ops to map MSI IRQ - Add pci_epf_ops to expose function-specific attrs - Allow user to create sub-directory of 'EPF Device' directory - Implement ->msi_map_irq() ops for cadence - Configure LM_EP_FUNC_CFG based on epc->function_num_map for cadence - Add EP function driver to provide NTB functionality - Add support for EPF PCI Non-Transparent Bridge - Add specification for PCI NTB function device - Add PCI endpoint NTB function user guide - Add configfs binding documentation for pci-ntb endpoint function Broadcom STB PCIe controller driver: - Add support for BCM4908 and external PERST# signal controller (Rafał Miłecki) Cadence PCIe controller driver: - Retrain Link to work around Gen2 training defect (Nadeem Athani) - Fix merge botch in cdns_pcie_host_map_dma_ranges() (Krzysztof Wilczyński) Freescale Layerscape PCIe controller driver: - Add LX2160A rev2 EP mode support (Hou Zhiqiang) - Convert to builtin_platform_driver() (Michael Walle) MediaTek PCIe controller driver: - Fix OF node reference leak (Krzysztof Wilczyński) Microchip PolarFlare PCIe controller driver: - Add Microchip PolarFire PCIe controller driver (Daire McNamara) Qualcomm PCIe controller driver: - Use PHY_REFCLK_USE_PAD only for ipq8064 (Ansuel Smith) - Add support for ddrss_sf_tbu clock for sm8250 (Dmitry Baryshkov) Renesas R-Car PCIe controller driver: - Drop PCIE_RCAR config option (Lad Prabhakar) - Always allocate MSI addresses in 32bit space (Marek Vasut) Rockchip PCIe controller driver: - Add FriendlyARM NanoPi M4B DT binding (Chen-Yu Tsai) - Make 'ep-gpios' DT property optional (Chen-Yu Tsai) Synopsys DesignWare PCIe controller driver: - Work around ECRC configuration hardware defect (Vidya Sagar) - Drop support for config space in DT 'ranges' (Rob Herring) - Change size to u64 for EP outbound iATU (Shradha Todi) - Add upper limit address for outbound iATU (Shradha Todi) - Make dw_pcie ops optional (Jisheng Zhang) - Remove unnecessary dw_pcie_ops from al driver (Jisheng Zhang) Xilinx Versal CPM PCIe controller driver: - Fix OF node reference leak (Pan Bian) Miscellaneous: - Remove tango host controller driver (Arnd Bergmann) - Remove IRQ handler & data together (altera-msi, brcmstb, dwc) (Martin Kaiser) - Fix xgene-msi race in installing chained IRQ handler (Martin Kaiser) - Apply CONFIG_PCI_DEBUG to entire drivers/pci hierarchy (Junhao He) - Fix pci-bridge-emul array overruns (Russell King) - Remove obsolete uses of WARN_ON(in_interrupt()) (Sebastian Andrzej Siewior)" * tag 'pci-v5.12-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: (69 commits) PCI: qcom: Use PHY_REFCLK_USE_PAD only for ipq8064 PCI: qcom: Add support for ddrss_sf_tbu clock dt-bindings: PCI: qcom: Document ddrss_sf_tbu clock for sm8250 PCI: al: Remove useless dw_pcie_ops PCI: dwc: Don't assume the ops in dw_pcie always exist PCI: dwc: Add upper limit address for outbound iATU PCI: dwc: Change size to u64 for EP outbound iATU PCI: dwc: Drop support for config space in 'ranges' PCI: layerscape: Convert to builtin_platform_driver() PCI: layerscape: Add LX2160A rev2 EP mode support dt-bindings: PCI: layerscape: Add LX2160A rev2 compatible strings PCI: dwc: Work around ECRC configuration issue PCI/portdrv: Report reset for frozen channel PCI/AER: Specify the type of Port that was reset PCI/ERR: Retain status from error notification PCI/AER: Clear AER status from Root Port when resetting Downstream Port PCI/ERR: Clear status of the reporting device dt-bindings: arm: rockchip: Add FriendlyARM NanoPi M4B PCI: rockchip: Make 'ep-gpios' DT property optional Documentation: PCI: Add PCI endpoint NTB function user guide ...
317 lines
7.7 KiB
C
317 lines
7.7 KiB
C
/* vim: set ts=8 sw=8 tw=78 ai noexpandtab */
|
|
/* qxl_drv.c -- QXL driver -*- linux-c -*-
|
|
*
|
|
* Copyright 2011 Red Hat, Inc.
|
|
* All Rights Reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice (including the next
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
* Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* Authors:
|
|
* Dave Airlie <airlie@redhat.com>
|
|
* Alon Levy <alevy@redhat.com>
|
|
*/
|
|
|
|
#include "qxl_drv.h"
|
|
#include <linux/console.h>
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
|
|
#include <drm/drm.h>
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_drv.h>
|
|
#include <drm/drm_file.h>
|
|
#include <drm/drm_modeset_helper.h>
|
|
#include <drm/drm_prime.h>
|
|
#include <drm/drm_probe_helper.h>
|
|
|
|
#include "qxl_object.h"
|
|
|
|
static const struct pci_device_id pciidlist[] = {
|
|
{ 0x1b36, 0x100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8,
|
|
0xffff00, 0 },
|
|
{ 0x1b36, 0x100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_OTHER << 8,
|
|
0xffff00, 0 },
|
|
{ 0, 0, 0 },
|
|
};
|
|
MODULE_DEVICE_TABLE(pci, pciidlist);
|
|
|
|
static int qxl_modeset = -1;
|
|
int qxl_num_crtc = 4;
|
|
|
|
MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
|
|
module_param_named(modeset, qxl_modeset, int, 0400);
|
|
|
|
MODULE_PARM_DESC(num_heads, "Number of virtual crtcs to expose (default 4)");
|
|
module_param_named(num_heads, qxl_num_crtc, int, 0400);
|
|
|
|
static struct drm_driver qxl_driver;
|
|
static struct pci_driver qxl_pci_driver;
|
|
|
|
static bool is_vga(struct pci_dev *pdev)
|
|
{
|
|
return pdev->class == PCI_CLASS_DISPLAY_VGA << 8;
|
|
}
|
|
|
|
static int
|
|
qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
|
{
|
|
struct qxl_device *qdev;
|
|
int ret;
|
|
|
|
if (pdev->revision < 4) {
|
|
DRM_ERROR("qxl too old, doesn't support client_monitors_config,"
|
|
" use xf86-video-qxl in user mode");
|
|
return -EINVAL; /* TODO: ENODEV ? */
|
|
}
|
|
|
|
qdev = devm_drm_dev_alloc(&pdev->dev, &qxl_driver,
|
|
struct qxl_device, ddev);
|
|
if (IS_ERR(qdev)) {
|
|
pr_err("Unable to init drm dev");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
ret = pci_enable_device(pdev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "qxl");
|
|
if (ret)
|
|
goto disable_pci;
|
|
|
|
if (is_vga(pdev) && pdev->revision < 5) {
|
|
ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
|
|
if (ret) {
|
|
DRM_ERROR("can't get legacy vga ioports\n");
|
|
goto disable_pci;
|
|
}
|
|
}
|
|
|
|
ret = qxl_device_init(qdev, pdev);
|
|
if (ret)
|
|
goto put_vga;
|
|
|
|
ret = qxl_modeset_init(qdev);
|
|
if (ret)
|
|
goto unload;
|
|
|
|
drm_kms_helper_poll_init(&qdev->ddev);
|
|
|
|
/* Complete initialization. */
|
|
ret = drm_dev_register(&qdev->ddev, ent->driver_data);
|
|
if (ret)
|
|
goto modeset_cleanup;
|
|
|
|
drm_fbdev_generic_setup(&qdev->ddev, 32);
|
|
return 0;
|
|
|
|
modeset_cleanup:
|
|
qxl_modeset_fini(qdev);
|
|
unload:
|
|
qxl_device_fini(qdev);
|
|
put_vga:
|
|
if (is_vga(pdev) && pdev->revision < 5)
|
|
vga_put(pdev, VGA_RSRC_LEGACY_IO);
|
|
disable_pci:
|
|
pci_disable_device(pdev);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void qxl_drm_release(struct drm_device *dev)
|
|
{
|
|
struct qxl_device *qdev = to_qxl(dev);
|
|
|
|
/*
|
|
* TODO: qxl_device_fini() call should be in qxl_pci_remove(),
|
|
* reordering qxl_modeset_fini() + qxl_device_fini() calls is
|
|
* non-trivial though.
|
|
*/
|
|
qxl_modeset_fini(qdev);
|
|
qxl_device_fini(qdev);
|
|
}
|
|
|
|
static void
|
|
qxl_pci_remove(struct pci_dev *pdev)
|
|
{
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
|
|
|
drm_dev_unregister(dev);
|
|
drm_atomic_helper_shutdown(dev);
|
|
if (is_vga(pdev) && pdev->revision < 5)
|
|
vga_put(pdev, VGA_RSRC_LEGACY_IO);
|
|
}
|
|
|
|
DEFINE_DRM_GEM_FOPS(qxl_fops);
|
|
|
|
static int qxl_drm_freeze(struct drm_device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev->dev);
|
|
struct qxl_device *qdev = to_qxl(dev);
|
|
int ret;
|
|
|
|
ret = drm_mode_config_helper_suspend(dev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
qxl_destroy_monitors_object(qdev);
|
|
qxl_surf_evict(qdev);
|
|
qxl_vram_evict(qdev);
|
|
|
|
while (!qxl_check_idle(qdev->command_ring));
|
|
while (!qxl_check_idle(qdev->release_ring))
|
|
qxl_queue_garbage_collect(qdev, 1);
|
|
|
|
pci_save_state(pdev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int qxl_drm_resume(struct drm_device *dev, bool thaw)
|
|
{
|
|
struct qxl_device *qdev = to_qxl(dev);
|
|
|
|
qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
|
|
if (!thaw) {
|
|
qxl_reinit_memslots(qdev);
|
|
qxl_ring_init_hdr(qdev->release_ring);
|
|
}
|
|
|
|
qxl_create_monitors_object(qdev);
|
|
return drm_mode_config_helper_resume(dev);
|
|
}
|
|
|
|
static int qxl_pm_suspend(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
|
int error;
|
|
|
|
error = qxl_drm_freeze(drm_dev);
|
|
if (error)
|
|
return error;
|
|
|
|
pci_disable_device(pdev);
|
|
pci_set_power_state(pdev, PCI_D3hot);
|
|
return 0;
|
|
}
|
|
|
|
static int qxl_pm_resume(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
|
|
|
pci_set_power_state(pdev, PCI_D0);
|
|
pci_restore_state(pdev);
|
|
if (pci_enable_device(pdev)) {
|
|
return -EIO;
|
|
}
|
|
|
|
return qxl_drm_resume(drm_dev, false);
|
|
}
|
|
|
|
static int qxl_pm_thaw(struct device *dev)
|
|
{
|
|
struct drm_device *drm_dev = dev_get_drvdata(dev);
|
|
|
|
return qxl_drm_resume(drm_dev, true);
|
|
}
|
|
|
|
static int qxl_pm_freeze(struct device *dev)
|
|
{
|
|
struct drm_device *drm_dev = dev_get_drvdata(dev);
|
|
|
|
return qxl_drm_freeze(drm_dev);
|
|
}
|
|
|
|
static int qxl_pm_restore(struct device *dev)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
|
struct qxl_device *qdev = to_qxl(drm_dev);
|
|
|
|
qxl_io_reset(qdev);
|
|
return qxl_drm_resume(drm_dev, false);
|
|
}
|
|
|
|
static const struct dev_pm_ops qxl_pm_ops = {
|
|
.suspend = qxl_pm_suspend,
|
|
.resume = qxl_pm_resume,
|
|
.freeze = qxl_pm_freeze,
|
|
.thaw = qxl_pm_thaw,
|
|
.poweroff = qxl_pm_freeze,
|
|
.restore = qxl_pm_restore,
|
|
};
|
|
static struct pci_driver qxl_pci_driver = {
|
|
.name = DRIVER_NAME,
|
|
.id_table = pciidlist,
|
|
.probe = qxl_pci_probe,
|
|
.remove = qxl_pci_remove,
|
|
.driver.pm = &qxl_pm_ops,
|
|
};
|
|
|
|
static struct drm_driver qxl_driver = {
|
|
.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
|
|
|
|
.dumb_create = qxl_mode_dumb_create,
|
|
.dumb_map_offset = qxl_mode_dumb_mmap,
|
|
#if defined(CONFIG_DEBUG_FS)
|
|
.debugfs_init = qxl_debugfs_init,
|
|
#endif
|
|
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
|
|
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
|
|
.gem_prime_import_sg_table = qxl_gem_prime_import_sg_table,
|
|
.gem_prime_mmap = qxl_gem_prime_mmap,
|
|
.fops = &qxl_fops,
|
|
.ioctls = qxl_ioctls,
|
|
.irq_handler = qxl_irq_handler,
|
|
.name = DRIVER_NAME,
|
|
.desc = DRIVER_DESC,
|
|
.date = DRIVER_DATE,
|
|
.major = 0,
|
|
.minor = 1,
|
|
.patchlevel = 0,
|
|
|
|
.release = qxl_drm_release,
|
|
};
|
|
|
|
static int __init qxl_init(void)
|
|
{
|
|
if (vgacon_text_force() && qxl_modeset == -1)
|
|
return -EINVAL;
|
|
|
|
if (qxl_modeset == 0)
|
|
return -EINVAL;
|
|
qxl_driver.num_ioctls = qxl_max_ioctls;
|
|
return pci_register_driver(&qxl_pci_driver);
|
|
}
|
|
|
|
static void __exit qxl_exit(void)
|
|
{
|
|
pci_unregister_driver(&qxl_pci_driver);
|
|
}
|
|
|
|
module_init(qxl_init);
|
|
module_exit(qxl_exit);
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
MODULE_LICENSE("GPL and additional rights");
|