-----BEGIN PGP SIGNATURE----- iQJIBAABCgAyFiEEgMe7l+5h9hnxdsnuWYigwDrT+vwFAmVBaU8UHGJoZWxnYWFz QGdvb2dsZS5jb20ACgkQWYigwDrT+vwEdxAAo++s98+ZaaTdUuoV0Zpft1fuY6Yr mR80jUDxjHDbcI1G4iNVUSWG6pGIdlURnrBp5kU74FV9R2Ps3Fl49XQUHowE0HfH D/qmihiJQdnMsQKwzw3XGoTSINrDcF6nLafl9brBItVkgjNxfxSEbnweJMBf+Boc rpRXHzxbVHVjwwhBLODF2Wt/8sQ24w9c+wcQkpo7im8ZZReoigNMKgEa4J7tLlqA vTyPR/K6QeU8IBUk2ObCY3GeYrVuqi82eRK3Uwzu7IkQwA9orE416Okvq3Z026/h TUAivtrcygHaFRdGNvzspYLbc2hd2sEXF+KKKb6GNAjxuDWUhVQW4ObY4FgFkZ65 Gqz/05D6c1dqTS3vTxp3nZYpvPEbNnO1RaGRL4h0/mbU+QSPSlHXWd9Lfg6noVVd 3O+CcstQK8RzMiiWLeyctRPV5XIf7nGVQTJW5aCLajlHeJWcvygNpNG4N57j/hXQ gyEHrz3idXXHXkBKmyWZfre6YpLkxZtKyONZDHWI/AVhU0TgRdJWmqpRfC1kVVUe IUWBRcPUF4/r3jEu6t10N/aDWQN1uQzIsJNnCrKzAddPDTTYQJk8VVzKPo8SVxPD X+OjEMgBB/fXUfkJ7IMwgYnWaFJhxthrs6/3j1UqRvGYRoulE4NdWwJDky9UYIHd qV3dzuAxC/cpv08= =G//C -----END PGP SIGNATURE----- Merge tag 'pci-v6.7-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci Pull pci updates from Bjorn Helgaas: "Enumeration: - Use acpi_evaluate_dsm_typed() instead of open-coding _DSM evaluation to learn device characteristics (Andy Shevchenko) - Tidy multi-function header checks using new PCI_HEADER_TYPE_MASK definition (Ilpo Järvinen) - Simplify config access error checking in various drivers (Ilpo Järvinen) - Use pcie_capability_clear_word() (not pcie_capability_clear_and_set_word()) when only clearing (Ilpo Järvinen) - Add pci_get_base_class() to simplify finding devices using base class only (ignoring subclass and programming interface) (Sui Jingfeng) - Add pci_is_vga(), which includes ancient PCI_CLASS_NOT_DEFINED_VGA devices from before the Class Code was added to PCI (Sui Jingfeng) - Use pci_is_vga() for vgaarb, sysfs "boot_vga", virtio, qxl to include ancient VGA devices (Sui Jingfeng) Resource management: - Make pci_assign_unassigned_resources() non-init because sparc uses it after init (Randy Dunlap) Driver binding: - Retain .remove() and .probe() callbacks (previously __init) because sysfs may cause them to be called later (Uwe Kleine-König) - Prevent xHCI driver from claiming AMD VanGogh USB3 DRD device, so it can be claimed by dwc3 instead (Vicki Pfau) PCI device hotplug: - Add Ampere Altra Attention Indicator extension driver for acpiphp (D Scott Phillips) Power management: - Quirk VideoPropulsion Torrent QN16e with longer delay after reset (Lukas Wunner) - Prevent users from overriding drivers that say we shouldn't use D3cold (Lukas Wunner) - Avoid PME from D3hot/D3cold for AMD Rembrandt and Phoenix USB4 because wakeup interrupts from those states don't work if amd-pmc has put the platform in a hardware sleep state (Mario Limonciello) IOMMU: - Disable ATS for Intel IPU E2000 devices with invalidation message endianness erratum (Bartosz Pawlowski) Error handling: - Factor out interrupt enable/disable into helpers (Kai-Heng Feng) Peer-to-peer DMA: - Fix flexible-array usage in struct pci_p2pdma_pagemap in case we ever use pagemaps with multiple entries (Gustavo A. R. Silva) ASPM: - Revert a change that broke when drivers disabled L1 and users later enabled an L1.x substate via sysfs, and fix a similar issue when users disabled L1 via sysfs (Heiner Kallweit) Endpoint framework: - Fix double free in __pci_epc_create() (Dan Carpenter) - Use IS_ERR_OR_NULL() to simplify endpoint core (Ruan Jinjie) Cadence PCIe controller driver: - Drop unused "is_rc" member (Li Chen) Freescale Layerscape PCIe controller driver: - Enable 64-bit addressing in endpoint mode (Guanhua Gao) Intel VMD host bridge driver: - Fix multi-function header check (Ilpo Järvinen) Microsoft Hyper-V host bridge driver: - Annotate struct hv_dr_state with __counted_by (Kees Cook) NVIDIA Tegra194 PCIe controller driver: - Drop setting of LNKCAP_MLW (max link width) since dw_pcie_setup() already does this via dw_pcie_link_set_max_link_width() (Yoshihiro Shimoda) Qualcomm PCIe controller driver: - Use PCIE_SPEED2MBS_ENC() to simplify encoding of link speed (Manivannan Sadhasivam) - Add a .write_dbi2() callback so DBI2 register writes, e.g., for setting the BAR size, work correctly (Manivannan Sadhasivam) - Enable ASPM for platforms that use 1.9.0 ops, because the PCI core doesn't enable ASPM states that haven't been enabled by the firmware (Manivannan Sadhasivam) Renesas R-Car Gen4 PCIe controller driver: - Add DesignWare core support (set max link width, EDMA_UNROLL flag, .pre_init(), .deinit(), etc) for use by R-Car Gen4 driver (Yoshihiro Shimoda) - Add driver and DT schema for DesignWare-based Renesas R-Car Gen4 controller in both host and endpoint mode (Yoshihiro Shimoda) Xilinx NWL PCIe controller driver: - Update ECAM size to support 256 buses (Thippeswamy Havalige) - Stop setting bridge primary/secondary/subordinate bus numbers, since PCI core does this (Thippeswamy Havalige) Xilinx XDMA controller driver: - Add driver and DT schema for Zynq UltraScale+ MPSoCs devices with Xilinx XDMA Soft IP (Thippeswamy Havalige) Miscellaneous: - Use FIELD_GET()/FIELD_PREP() to simplify and reduce use of _SHIFT macros (Ilpo Järvinen, Bjorn Helgaas) - Remove logic_outb(), _outw(), outl() duplicate declarations (John Sanpe) - Replace unnecessary UTF-8 in Kconfig help text because menuconfig doesn't render it correctly (Liu Song)" * tag 'pci-v6.7-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci: (102 commits) PCI: qcom-ep: Add dedicated callback for writing to DBI2 registers PCI: Simplify pcie_capability_clear_and_set_word() to ..._clear_word() PCI: endpoint: Fix double free in __pci_epc_create() PCI: xilinx-xdma: Add Xilinx XDMA Root Port driver dt-bindings: PCI: xilinx-xdma: Add schemas for Xilinx XDMA PCIe Root Port Bridge PCI: xilinx-cpm: Move IRQ definitions to a common header PCI: xilinx-nwl: Modify ECAM size to enable support for 256 buses PCI: xilinx-nwl: Rename the NWL_ECAM_VALUE_DEFAULT macro dt-bindings: PCI: xilinx-nwl: Modify ECAM size in the DT example PCI: xilinx-nwl: Remove redundant code that sets Type 1 header fields PCI: hotplug: Add Ampere Altra Attention Indicator extension driver PCI/AER: Factor out interrupt toggling into helpers PCI: acpiphp: Allow built-in drivers for Attention Indicators PCI/portdrv: Use FIELD_GET() PCI/VC: Use FIELD_GET() PCI/PTM: Use FIELD_GET() PCI/PME: Use FIELD_GET() PCI/ATS: Use FIELD_GET() PCI/ATS: Show PASID Capability register width in bitmasks PCI/ASPM: Fix L1 substate handling in aspm_attr_store_common() ...
313 lines
7.9 KiB
C
313 lines
7.9 KiB
C
/* 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/module.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/vgaarb.h>
|
|
|
|
#include <drm/drm.h>
|
|
#include <drm/drm_aperture.h>
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_drv.h>
|
|
#include <drm/drm_fbdev_generic.h>
|
|
#include <drm/drm_file.h>
|
|
#include <drm/drm_gem_ttm_helper.h>
|
|
#include <drm/drm_module.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 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_aperture_remove_conflicting_pci_framebuffers(pdev, &qxl_driver);
|
|
if (ret)
|
|
goto disable_pci;
|
|
|
|
if (pci_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 (pci_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 (pci_is_vga(pdev) && pdev->revision < 5)
|
|
vga_put(pdev, VGA_RSRC_LEGACY_IO);
|
|
}
|
|
|
|
static void
|
|
qxl_pci_shutdown(struct pci_dev *pdev)
|
|
{
|
|
drm_atomic_helper_shutdown(pci_get_drvdata(pdev));
|
|
}
|
|
|
|
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_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);
|
|
struct qxl_device *qdev = to_qxl(drm_dev);
|
|
|
|
pci_set_power_state(pdev, PCI_D0);
|
|
pci_restore_state(pdev);
|
|
if (pci_enable_device(pdev)) {
|
|
return -EIO;
|
|
}
|
|
|
|
qxl_io_reset(qdev);
|
|
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,
|
|
.shutdown = qxl_pci_shutdown,
|
|
.driver.pm = &qxl_pm_ops,
|
|
};
|
|
|
|
static const struct drm_ioctl_desc qxl_ioctls[] = {
|
|
DRM_IOCTL_DEF_DRV(QXL_ALLOC, qxl_alloc_ioctl, DRM_AUTH),
|
|
DRM_IOCTL_DEF_DRV(QXL_MAP, qxl_map_ioctl, DRM_AUTH),
|
|
DRM_IOCTL_DEF_DRV(QXL_EXECBUFFER, qxl_execbuffer_ioctl, DRM_AUTH),
|
|
DRM_IOCTL_DEF_DRV(QXL_UPDATE_AREA, qxl_update_area_ioctl, DRM_AUTH),
|
|
DRM_IOCTL_DEF_DRV(QXL_GETPARAM, qxl_getparam_ioctl, DRM_AUTH),
|
|
DRM_IOCTL_DEF_DRV(QXL_CLIENTCAP, qxl_clientcap_ioctl, DRM_AUTH),
|
|
DRM_IOCTL_DEF_DRV(QXL_ALLOC_SURF, qxl_alloc_surf_ioctl, DRM_AUTH),
|
|
};
|
|
|
|
static struct drm_driver qxl_driver = {
|
|
.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
|
|
|
|
.dumb_create = qxl_mode_dumb_create,
|
|
.dumb_map_offset = drm_gem_ttm_dumb_map_offset,
|
|
#if defined(CONFIG_DEBUG_FS)
|
|
.debugfs_init = qxl_debugfs_init,
|
|
#endif
|
|
.gem_prime_import_sg_table = qxl_gem_prime_import_sg_table,
|
|
.fops = &qxl_fops,
|
|
.ioctls = qxl_ioctls,
|
|
.num_ioctls = ARRAY_SIZE(qxl_ioctls),
|
|
.name = DRIVER_NAME,
|
|
.desc = DRIVER_DESC,
|
|
.date = DRIVER_DATE,
|
|
.major = 0,
|
|
.minor = 1,
|
|
.patchlevel = 0,
|
|
|
|
.release = qxl_drm_release,
|
|
};
|
|
|
|
drm_module_pci_driver_if_modeset(qxl_pci_driver, qxl_modeset);
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
MODULE_LICENSE("GPL and additional rights");
|