Subversion Repositories Kolibri OS

Rev

Rev 2997 | Rev 3764 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2008 Advanced Micro Devices, Inc.
  3.  * Copyright 2008 Red Hat Inc.
  4.  * Copyright 2009 Jerome Glisse.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included in
  14.  * all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22.  * OTHER DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors: Dave Airlie
  25.  *          Alex Deucher
  26.  *          Jerome Glisse
  27.  */
  28. #include <drm/drmP.h>
  29. #include <drm/drm_crtc_helper.h>
  30. #include <drm/radeon_drm.h>
  31. #include "radeon_reg.h"
  32. #include "radeon.h"
  33. #include "atom.h"
  34.  
  35. #define RADEON_WAIT_IDLE_TIMEOUT 200
  36.  
  37. #define DRM_IRQ_ARGS            void *arg
  38.  
  39. struct drm_driver {
  40.     irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
  41.     void (*irq_preinstall) (struct drm_device *dev);
  42.     int (*irq_postinstall) (struct drm_device *dev);
  43. };
  44.  
  45. extern int irq_override;
  46.  
  47.  
  48. /**
  49.  * radeon_driver_irq_handler_kms - irq handler for KMS
  50.  *
  51.  * @DRM_IRQ_ARGS: args
  52.  *
  53.  * This is the irq handler for the radeon KMS driver (all asics).
  54.  * radeon_irq_process is a macro that points to the per-asic
  55.  * irq handler callback.
  56.  */
  57. irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
  58. {
  59.         struct drm_device *dev = (struct drm_device *) arg;
  60.         struct radeon_device *rdev = dev->dev_private;
  61.  
  62.     return radeon_irq_process(rdev);
  63. }
  64.  
  65. /**
  66.  * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
  67.  *
  68.  * @dev: drm dev pointer
  69.  *
  70.  * Gets the hw ready to enable irqs (all asics).
  71.  * This function disables all interrupt sources on the GPU.
  72.  */
  73. void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
  74. {
  75.         struct radeon_device *rdev = dev->dev_private;
  76.         unsigned long irqflags;
  77.     unsigned i;
  78.  
  79.         spin_lock_irqsave(&rdev->irq.lock, irqflags);
  80.     /* Disable *all* interrupts */
  81.         for (i = 0; i < RADEON_NUM_RINGS; i++)
  82.                 atomic_set(&rdev->irq.ring_int[i], 0);
  83.         for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
  84.                 rdev->irq.hpd[i] = false;
  85.         for (i = 0; i < RADEON_MAX_CRTCS; i++) {
  86.         rdev->irq.crtc_vblank_int[i] = false;
  87.                 atomic_set(&rdev->irq.pflip[i], 0);
  88.                 rdev->irq.afmt[i] = false;
  89.     }
  90.     radeon_irq_set(rdev);
  91.         spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  92.     /* Clear bits */
  93.     radeon_irq_process(rdev);
  94. }
  95.  
  96. /**
  97.  * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
  98.  *
  99.  * @dev: drm dev pointer
  100.  *
  101.  * Handles stuff to be done after enabling irqs (all asics).
  102.  * Returns 0 on success.
  103.  */
  104. int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
  105. {
  106.         dev->max_vblank_count = 0x001fffff;
  107.         return 0;
  108. }
  109.  
  110. /**
  111.  * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
  112.  *
  113.  * @dev: drm dev pointer
  114.  *
  115.  * This function disables all interrupt sources on the GPU (all asics).
  116.  */
  117. void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
  118. {
  119.         struct radeon_device *rdev = dev->dev_private;
  120.         unsigned long irqflags;
  121.         unsigned i;
  122.  
  123.         if (rdev == NULL) {
  124.                 return;
  125.         }
  126.         spin_lock_irqsave(&rdev->irq.lock, irqflags);
  127.         /* Disable *all* interrupts */
  128.         for (i = 0; i < RADEON_NUM_RINGS; i++)
  129.                 atomic_set(&rdev->irq.ring_int[i], 0);
  130.         for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
  131.                 rdev->irq.hpd[i] = false;
  132.         for (i = 0; i < RADEON_MAX_CRTCS; i++) {
  133.                 rdev->irq.crtc_vblank_int[i] = false;
  134.                 atomic_set(&rdev->irq.pflip[i], 0);
  135.                 rdev->irq.afmt[i] = false;
  136.         }
  137.     radeon_irq_set(rdev);
  138.         spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  139. }
  140.  
  141.  
  142.  
  143. /**
  144.  * radeon_irq_kms_init - init driver interrupt info
  145.  *
  146.  * @rdev: radeon device pointer
  147.  *
  148.  * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
  149.  * Returns 0 for success, error for failure.
  150.  */
  151. int radeon_irq_kms_init(struct radeon_device *rdev)
  152. {
  153.     int irq_line;
  154.         int r = 0;
  155.  
  156.     ENTER();
  157.  
  158.  
  159.         spin_lock_init(&rdev->irq.lock);
  160.         /* enable msi */
  161.         rdev->msi_enabled = 0;
  162.  
  163.     rdev->irq.installed = true;
  164.         r = drm_irq_install(rdev->ddev);
  165.     if (r) {
  166.        rdev->irq.installed = false;
  167.        FAIL();
  168.        return r;
  169.    }
  170.         DRM_INFO("radeon: irq initialized.\n");
  171.         return 0;
  172. }
  173.  
  174. /**
  175.  * radeon_irq_kms_fini - tear down driver interrrupt info
  176.  *
  177.  * @rdev: radeon device pointer
  178.  *
  179.  * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
  180.  */
  181. void radeon_irq_kms_fini(struct radeon_device *rdev)
  182. {
  183. //      drm_vblank_cleanup(rdev->ddev);
  184.         if (rdev->irq.installed) {
  185. //              drm_irq_uninstall(rdev->ddev);
  186.                 rdev->irq.installed = false;
  187. //       if (rdev->msi_enabled)
  188. //                      pci_disable_msi(rdev->pdev);
  189.         }
  190. //      flush_work(&rdev->hotplug_work);
  191. }
  192.  
  193. /**
  194.  * radeon_irq_kms_sw_irq_get - enable software interrupt
  195.  *
  196.  * @rdev: radeon device pointer
  197.  * @ring: ring whose interrupt you want to enable
  198.  *
  199.  * Enables the software interrupt for a specific ring (all asics).
  200.  * The software interrupt is generally used to signal a fence on
  201.  * a particular ring.
  202.  */
  203. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
  204. {
  205.         unsigned long irqflags;
  206.  
  207.         if (!rdev->ddev->irq_enabled)
  208.                 return;
  209.  
  210.         if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
  211.                 spin_lock_irqsave(&rdev->irq.lock, irqflags);
  212.                 radeon_irq_set(rdev);
  213.                 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  214.         }
  215. }
  216.  
  217. /**
  218.  * radeon_irq_kms_sw_irq_put - disable software interrupt
  219.  *
  220.  * @rdev: radeon device pointer
  221.  * @ring: ring whose interrupt you want to disable
  222.  *
  223.  * Disables the software interrupt for a specific ring (all asics).
  224.  * The software interrupt is generally used to signal a fence on
  225.  * a particular ring.
  226.  */
  227. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
  228. {
  229.         unsigned long irqflags;
  230.  
  231.         if (!rdev->ddev->irq_enabled)
  232.                 return;
  233.  
  234.         if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
  235.                 spin_lock_irqsave(&rdev->irq.lock, irqflags);
  236.                 radeon_irq_set(rdev);
  237.                 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  238.         }
  239. }
  240.  
  241. /**
  242.  * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
  243.  *
  244.  * @rdev: radeon device pointer
  245.  * @hpd_mask: mask of hpd pins you want to enable.
  246.  *
  247.  * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
  248.  */
  249. void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
  250. {
  251.         unsigned long irqflags;
  252.         int i;
  253.  
  254.         spin_lock_irqsave(&rdev->irq.lock, irqflags);
  255.         for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
  256.                 rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
  257.         radeon_irq_set(rdev);
  258.         spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  259. }
  260.  
  261. /**
  262.  * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
  263.  *
  264.  * @rdev: radeon device pointer
  265.  * @hpd_mask: mask of hpd pins you want to disable.
  266.  *
  267.  * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
  268.  */
  269. void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
  270. {
  271.         unsigned long irqflags;
  272.         int i;
  273.  
  274.         spin_lock_irqsave(&rdev->irq.lock, irqflags);
  275.         for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
  276.                 rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
  277.         radeon_irq_set(rdev);
  278.         spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  279. }
  280.  
  281.  
  282. static struct drm_driver drm_driver = {
  283.     .irq_preinstall = radeon_driver_irq_preinstall_kms,
  284.     .irq_postinstall = radeon_driver_irq_postinstall_kms,
  285.     .irq_handler = radeon_driver_irq_handler_kms
  286. };
  287.  
  288. static struct drm_driver *driver = &drm_driver;
  289.  
  290. int drm_irq_install(struct drm_device *dev)
  291. {
  292.     unsigned long sh_flags = 0;
  293.     int irq_line;
  294.     int ret = 0;
  295.  
  296.     char *irqname;
  297.  
  298.     mutex_lock(&dev->struct_mutex);
  299.  
  300.     /* Driver must have been initialized */
  301.     if (!dev->dev_private) {
  302.             mutex_unlock(&dev->struct_mutex);
  303.             return -EINVAL;
  304.     }
  305.  
  306.     if (dev->irq_enabled) {
  307.             mutex_unlock(&dev->struct_mutex);
  308.             return -EBUSY;
  309.     }
  310.     dev->irq_enabled = 1;
  311.     mutex_unlock(&dev->struct_mutex);
  312.  
  313.     irq_line   = drm_dev_to_irq(dev);
  314.  
  315.     DRM_DEBUG("irq=%d\n", drm_dev_to_irq(dev));
  316.  
  317.     /* Before installing handler */
  318.     if (driver->irq_preinstall)
  319.             driver->irq_preinstall(dev);
  320.  
  321.     ret = AttachIntHandler(irq_line, driver->irq_handler, (u32)dev);
  322.  
  323.     /* After installing handler */
  324.     if (driver->irq_postinstall)
  325.             ret = driver->irq_postinstall(dev);
  326.  
  327.     if (ret < 0) {
  328.             DRM_ERROR(__FUNCTION__);
  329.     }
  330.  
  331.     u16_t cmd = PciRead16(dev->pdev->busnr, dev->pdev->devfn, 4);
  332.     cmd&= ~(1<<10);
  333.     PciWrite16(dev->pdev->busnr, dev->pdev->devfn, 4, cmd);
  334.  
  335.     return ret;
  336. }
  337.