FireBurn

radeon: initial runtime poweroff support

Sep 5th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 22.21 KB | None | 0 0
  1. From c50c188c5c2c12d1cbf0d71d624850f984a13619 Mon Sep 17 00:00:00 2001
  2. From: Mike Lothian <mike@fireburn.co.uk>
  3. Date: Thu, 5 Sep 2013 23:38:45 +0000
  4. Subject: [PATCH] radeon: initial runtime poweroff support
  5.  
  6. ---
  7.  drivers/gpu/drm/radeon/radeon.h            |   6 +-
  8.  drivers/gpu/drm/radeon/radeon.h.rej        |  12 +++
  9.  drivers/gpu/drm/radeon/radeon_connectors.c |  63 +++++++++++++--
  10.  drivers/gpu/drm/radeon/radeon_device.c     |  52 +++++++-----
  11.  drivers/gpu/drm/radeon/radeon_display.c    |  47 ++++++++++-
  12.  drivers/gpu/drm/radeon/radeon_drv.c        | 124 +++++++++++++++++++++++++----
  13.  drivers/gpu/drm/radeon/radeon_irq_kms.c    |   8 +-
  14.  drivers/gpu/drm/radeon/radeon_kms.c        |  24 +++++-
  15.  8 files changed, 284 insertions(+), 52 deletions(-)
  16.  create mode 100644 drivers/gpu/drm/radeon/radeon.h.rej
  17.  
  18. diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
  19. index ff8b564..cb8c164 100644
  20. --- a/drivers/gpu/drm/radeon/radeon.h
  21. +++ b/drivers/gpu/drm/radeon/radeon.h
  22. @@ -2184,6 +2184,8 @@ struct radeon_device {
  23.     /* ACPI interface */
  24.     struct radeon_atif      atif;
  25.     struct radeon_atcs      atcs;
  26. +   struct dev_pm_domain        vga_pm_domain;
  27. +   bool have_disp_power_ref;
  28.     /* srbm instance registers */
  29.     struct mutex            srbm_mutex;
  30.     /* clock, powergating flags */
  31. @@ -2593,8 +2595,8 @@ extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  32.  extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  33.  extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  34.  extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  35. -extern int radeon_resume_kms(struct drm_device *dev);
  36. -extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  37. +extern int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
  38. +extern int radeon_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
  39.  extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  40.  extern void radeon_program_register_sequence(struct radeon_device *rdev,
  41.                          const u32 *registers,
  42. diff --git a/drivers/gpu/drm/radeon/radeon.h.rej b/drivers/gpu/drm/radeon/radeon.h.rej
  43. new file mode 100644
  44. index 0000000..4cb2b21
  45. --- /dev/null
  46. +++ b/drivers/gpu/drm/radeon/radeon.h.rej
  47. @@ -0,0 +1,12 @@
  48. +--- drivers/gpu/drm/radeon/radeon.h
  49. ++++ drivers/gpu/drm/radeon/radeon.h
  50. +@@ -2092,6 +2092,9 @@
  51. +   /* ACPI interface */
  52. +   struct radeon_atif      atif;
  53. +   struct radeon_atcs      atcs;
  54. ++
  55. ++  struct dev_pm_domain vga_pm_domain;
  56. ++  bool have_disp_power_ref;
  57. + };
  58. +
  59. + int radeon_device_init(struct radeon_device *rdev,
  60. diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
  61. index 2399f25..f5a525b 100644
  62. --- a/drivers/gpu/drm/radeon/radeon_connectors.c
  63. +++ b/drivers/gpu/drm/radeon/radeon_connectors.c
  64. @@ -31,6 +31,8 @@
  65.  #include "radeon.h"
  66.  #include "atom.h"
  67.  
  68. +#include <linux/pm_runtime.h>
  69. +
  70.  extern void
  71.  radeon_combios_connected_scratch_regs(struct drm_connector *connector,
  72.                       struct drm_encoder *encoder,
  73. @@ -611,6 +613,11 @@ radeon_lvds_detect(struct drm_connector *connector, bool force)
  74.     struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  75.     struct drm_encoder *encoder = radeon_best_single_encoder(connector);
  76.     enum drm_connector_status ret = connector_status_disconnected;
  77. +   int r;
  78. +
  79. +   r = pm_runtime_get_sync(connector->dev->dev);
  80. +   if (r < 0)
  81. +       return connector_status_disconnected;
  82.  
  83.     if (encoder) {
  84.         struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  85. @@ -636,6 +643,8 @@ radeon_lvds_detect(struct drm_connector *connector, bool force)
  86.     /* check acpi lid status ??? */
  87.  
  88.     radeon_connector_update_scratch_regs(connector, ret);
  89. +   pm_runtime_mark_last_busy(connector->dev->dev);
  90. +   pm_runtime_put_autosuspend(connector->dev->dev);
  91.     return ret;
  92.  }
  93.  
  94. @@ -735,6 +744,11 @@ radeon_vga_detect(struct drm_connector *connector, bool force)
  95.     struct drm_encoder_helper_funcs *encoder_funcs;
  96.     bool dret = false;
  97.     enum drm_connector_status ret = connector_status_disconnected;
  98. +   int r;
  99. +
  100. +   r = pm_runtime_get_sync(connector->dev->dev);
  101. +   if (r < 0)
  102. +       return connector_status_disconnected;
  103.  
  104.     encoder = radeon_best_single_encoder(connector);
  105.     if (!encoder)
  106. @@ -775,9 +789,8 @@ radeon_vga_detect(struct drm_connector *connector, bool force)
  107.              * detected a monitor via load.
  108.              */
  109.             if (radeon_connector->detected_by_load)
  110. -               return connector->status;
  111. -           else
  112. -               return ret;
  113. +               ret = connector->status;
  114. +           goto out;
  115.         }
  116.  
  117.         if (radeon_connector->dac_load_detect && encoder) {
  118. @@ -802,6 +815,11 @@ radeon_vga_detect(struct drm_connector *connector, bool force)
  119.     }
  120.  
  121.     radeon_connector_update_scratch_regs(connector, ret);
  122. +
  123. +out:
  124. +   pm_runtime_mark_last_busy(connector->dev->dev);
  125. +   pm_runtime_put_autosuspend(connector->dev->dev);
  126. +
  127.     return ret;
  128.  }
  129.  
  130. @@ -858,10 +876,15 @@ radeon_tv_detect(struct drm_connector *connector, bool force)
  131.     struct drm_encoder_helper_funcs *encoder_funcs;
  132.     struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  133.     enum drm_connector_status ret = connector_status_disconnected;
  134. +   int r;
  135.  
  136.     if (!radeon_connector->dac_load_detect)
  137.         return ret;
  138.  
  139. +   r = pm_runtime_get_sync(connector->dev->dev);
  140. +   if (r < 0)
  141. +       return connector_status_disconnected;
  142. +
  143.     encoder = radeon_best_single_encoder(connector);
  144.     if (!encoder)
  145.         ret = connector_status_disconnected;
  146. @@ -872,6 +895,8 @@ radeon_tv_detect(struct drm_connector *connector, bool force)
  147.     if (ret == connector_status_connected)
  148.         ret = radeon_connector_analog_encoder_conflict_solve(connector, encoder, ret, false);
  149.     radeon_connector_update_scratch_regs(connector, ret);
  150. +   pm_runtime_mark_last_busy(connector->dev->dev);
  151. +   pm_runtime_put_autosuspend(connector->dev->dev);
  152.     return ret;
  153.  }
  154.  
  155. @@ -939,12 +964,18 @@ radeon_dvi_detect(struct drm_connector *connector, bool force)
  156.     struct drm_encoder *encoder = NULL;
  157.     struct drm_encoder_helper_funcs *encoder_funcs;
  158.     struct drm_mode_object *obj;
  159. -   int i;
  160. +   int i, r;
  161.     enum drm_connector_status ret = connector_status_disconnected;
  162.     bool dret = false, broken_edid = false;
  163.  
  164. -   if (!force && radeon_check_hpd_status_unchanged(connector))
  165. -       return connector->status;
  166. +   r = pm_runtime_get_sync(connector->dev->dev);
  167. +   if (r < 0)
  168. +       return connector_status_disconnected;
  169. +
  170. +   if (!force && radeon_check_hpd_status_unchanged(connector)) {
  171. +       ret = connector->status;
  172. +       goto exit;
  173. +   }
  174.  
  175.     if (radeon_connector->ddc_bus)
  176.         dret = radeon_ddc_probe(radeon_connector, false);
  177. @@ -1095,6 +1126,11 @@ out:
  178.  
  179.     /* updated in get modes as well since we need to know if it's analog or digital */
  180.     radeon_connector_update_scratch_regs(connector, ret);
  181. +
  182. +exit:
  183. +   pm_runtime_mark_last_busy(connector->dev->dev);
  184. +   pm_runtime_put_autosuspend(connector->dev->dev);
  185. +
  186.     return ret;
  187.  }
  188.  
  189. @@ -1362,9 +1398,16 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
  190.     enum drm_connector_status ret = connector_status_disconnected;
  191.     struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
  192.     struct drm_encoder *encoder = radeon_best_single_encoder(connector);
  193. +   int r;
  194.  
  195. -   if (!force && radeon_check_hpd_status_unchanged(connector))
  196. -       return connector->status;
  197. +   r = pm_runtime_get_sync(connector->dev->dev);
  198. +   if (r < 0)
  199. +       return connector_status_disconnected;
  200. +
  201. +   if (!force && radeon_check_hpd_status_unchanged(connector)) {
  202. +       ret = connector->status;
  203. +       goto out;
  204. +   }
  205.  
  206.     if (radeon_connector->edid) {
  207.         kfree(radeon_connector->edid);
  208. @@ -1428,6 +1471,10 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
  209.     }
  210.  
  211.     radeon_connector_update_scratch_regs(connector, ret);
  212. +out:
  213. +   pm_runtime_mark_last_busy(connector->dev->dev);
  214. +   pm_runtime_put_autosuspend(connector->dev->dev);
  215. +
  216.     return ret;
  217.  }
  218.  
  219. diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
  220. index 16cb879..0e4796d 100644
  221. --- a/drivers/gpu/drm/radeon/radeon_device.c
  222. +++ b/drivers/gpu/drm/radeon/radeon_device.c
  223. @@ -1076,7 +1076,6 @@ static bool radeon_switcheroo_quirk_long_wakeup(struct pci_dev *pdev)
  224.  static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  225.  {
  226.     struct drm_device *dev = pci_get_drvdata(pdev);
  227. -   pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
  228.     if (state == VGA_SWITCHEROO_ON) {
  229.         unsigned d3_delay = dev->pdev->d3_delay;
  230.  
  231. @@ -1087,7 +1086,7 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
  232.         if (d3_delay < 20 && radeon_switcheroo_quirk_long_wakeup(pdev))
  233.             dev->pdev->d3_delay = 20;
  234.  
  235. -       radeon_resume_kms(dev);
  236. +       radeon_resume_kms(dev, true, true);
  237.  
  238.         dev->pdev->d3_delay = d3_delay;
  239.  
  240. @@ -1097,7 +1096,7 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
  241.         printk(KERN_INFO "radeon: switched off\n");
  242.         drm_kms_helper_poll_disable(dev);
  243.         dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  244. -       radeon_suspend_kms(dev, pmm);
  245. +       radeon_suspend_kms(dev, true, true);
  246.         dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  247.     }
  248.  }
  249. @@ -1282,7 +1281,8 @@ int radeon_device_init(struct radeon_device *rdev,
  250.     /* this will fail for cards that aren't VGA class devices, just
  251.      * ignore it */
  252.     vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode);
  253. -   vga_switcheroo_register_client(rdev->pdev, &radeon_switcheroo_ops, false);
  254. +   vga_switcheroo_register_client(rdev->pdev, &radeon_switcheroo_ops, true);
  255. +   vga_switcheroo_init_domain_pm_ops(rdev->dev, &rdev->vga_pm_domain);
  256.  
  257.     r = radeon_init(rdev);
  258.     if (r)
  259. @@ -1363,7 +1363,7 @@ void radeon_device_fini(struct radeon_device *rdev)
  260.   * Returns 0 for success or an error on failure.
  261.   * Called at driver suspend.
  262.   */
  263. -int radeon_suspend_kms(struct drm_device *dev, pm_message_t state)
  264. +int radeon_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon)
  265.  {
  266.     struct radeon_device *rdev;
  267.     struct drm_crtc *crtc;
  268. @@ -1374,9 +1374,7 @@ int radeon_suspend_kms(struct drm_device *dev, pm_message_t state)
  269.     if (dev == NULL || dev->dev_private == NULL) {
  270.         return -ENODEV;
  271.     }
  272. -   if (state.event == PM_EVENT_PRETHAW) {
  273. -       return 0;
  274. -   }
  275. +
  276.     rdev = dev->dev_private;
  277.  
  278.     if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  279. @@ -1435,14 +1433,17 @@ int radeon_suspend_kms(struct drm_device *dev, pm_message_t state)
  280.     radeon_agp_suspend(rdev);
  281.  
  282.     pci_save_state(dev->pdev);
  283. -   if (state.event == PM_EVENT_SUSPEND) {
  284. +   if (suspend) {
  285.         /* Shut down the device */
  286.         pci_disable_device(dev->pdev);
  287.         pci_set_power_state(dev->pdev, PCI_D3hot);
  288.     }
  289. -   console_lock();
  290. -   radeon_fbdev_set_suspend(rdev, 1);
  291. -   console_unlock();
  292. +
  293. +   if (fbcon) {
  294. +       console_lock();
  295. +       radeon_fbdev_set_suspend(rdev, 1);
  296. +       console_unlock();
  297. +   }
  298.     return 0;
  299.  }
  300.  
  301. @@ -1455,7 +1456,7 @@ int radeon_suspend_kms(struct drm_device *dev, pm_message_t state)
  302.   * Returns 0 for success or an error on failure.
  303.   * Called at driver resume.
  304.   */
  305. -int radeon_resume_kms(struct drm_device *dev)
  306. +int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon)
  307.  {
  308.     struct drm_connector *connector;
  309.     struct radeon_device *rdev = dev->dev_private;
  310. @@ -1464,12 +1465,17 @@ int radeon_resume_kms(struct drm_device *dev)
  311.     if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  312.         return 0;
  313.  
  314. -   console_lock();
  315. -   pci_set_power_state(dev->pdev, PCI_D0);
  316. -   pci_restore_state(dev->pdev);
  317. -   if (pci_enable_device(dev->pdev)) {
  318. -       console_unlock();
  319. -       return -1;
  320. +   if (fbcon) {
  321. +       console_lock();
  322. +   }
  323. +   if (resume) {
  324. +       pci_set_power_state(dev->pdev, PCI_D0);
  325. +       pci_restore_state(dev->pdev);
  326. +       if (pci_enable_device(dev->pdev)) {
  327. +           if (fbcon)
  328. +               console_unlock();
  329. +           return -1;
  330. +       }
  331.     }
  332.     /* resume AGP if in use */
  333.     radeon_agp_resume(rdev);
  334. @@ -1482,9 +1488,11 @@ int radeon_resume_kms(struct drm_device *dev)
  335.     radeon_pm_resume(rdev);
  336.     radeon_restore_bios_scratch_regs(rdev);
  337.  
  338. -   radeon_fbdev_set_suspend(rdev, 0);
  339. -   console_unlock();
  340. -
  341. +   if (fbcon) {
  342. +       radeon_fbdev_set_suspend(rdev, 0);
  343. +       console_unlock();
  344. +   }
  345. +      
  346.     /* init dig PHYs, disp eng pll */
  347.     if (rdev->is_atom_bios) {
  348.         radeon_atom_encoder_init(rdev);
  349. diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
  350. index b055bdd..246c7a8 100644
  351. --- a/drivers/gpu/drm/radeon/radeon_display.c
  352. +++ b/drivers/gpu/drm/radeon/radeon_display.c
  353. @@ -30,6 +30,7 @@
  354.  #include "atom.h"
  355.  #include <asm/div64.h>
  356.  
  357. +#include <linux/pm_runtime.h>
  358.  #include <drm/drm_crtc_helper.h>
  359.  #include <drm/drm_edid.h>
  360.  
  361. @@ -494,11 +495,55 @@ unlock_free:
  362.     return r;
  363.  }
  364.  
  365. +static int
  366. +radeon_crtc_set_config(struct drm_mode_set *set)
  367. +{
  368. +   struct drm_device *dev;
  369. +   struct radeon_device *rdev;
  370. +   struct drm_crtc *crtc;
  371. +   bool active = false;
  372. +   int ret;
  373. +
  374. +   if (!set || !set->crtc)
  375. +       return -EINVAL;
  376. +
  377. +   dev = set->crtc->dev;
  378. +
  379. +   ret = pm_runtime_get_sync(dev->dev);
  380. +   if (ret < 0)
  381. +       return ret;
  382. +
  383. +   ret = drm_crtc_helper_set_config(set);
  384. +
  385. +   list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  386. +       if (crtc->enabled)
  387. +           active = true;
  388. +
  389. +   pm_runtime_mark_last_busy(dev->dev);
  390. +
  391. +   rdev = dev->dev_private;
  392. +   /* if we have active crtcs and we don't have a power ref,
  393. +      take the current one */
  394. +   if (active && !rdev->have_disp_power_ref) {
  395. +       rdev->have_disp_power_ref = true;
  396. +       return ret;
  397. +   }
  398. +   /* if we have no active crtcs, then drop the power ref
  399. +      we got before */
  400. +   if (!active && rdev->have_disp_power_ref) {
  401. +       pm_runtime_put_autosuspend(dev->dev);
  402. +       rdev->have_disp_power_ref = false;
  403. +   }
  404. +
  405. +   /* drop the power reference we got coming in here */
  406. +   pm_runtime_put_autosuspend(dev->dev);
  407. +   return ret;
  408. +}
  409.  static const struct drm_crtc_funcs radeon_crtc_funcs = {
  410.     .cursor_set = radeon_crtc_cursor_set,
  411.     .cursor_move = radeon_crtc_cursor_move,
  412.     .gamma_set = radeon_crtc_gamma_set,
  413. -   .set_config = drm_crtc_helper_set_config,
  414. +   .set_config = radeon_crtc_set_config,
  415.     .destroy = radeon_crtc_destroy,
  416.     .page_flip = radeon_crtc_page_flip,
  417.  };
  418. diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
  419. index cb4445f..4379eed 100644
  420. --- a/drivers/gpu/drm/radeon/radeon_drv.c
  421. +++ b/drivers/gpu/drm/radeon/radeon_drv.c
  422. @@ -36,8 +36,9 @@
  423.  #include <drm/drm_pciids.h>
  424.  #include <linux/console.h>
  425.  #include <linux/module.h>
  426. -
  427. -
  428. +#include <linux/pm_runtime.h>
  429. +#include <linux/vga_switcheroo.h>
  430. +#include "drm_crtc_helper.h"
  431.  /*
  432.   * KMS wrapper.
  433.   * - 2.0.0 - initial interface
  434. @@ -87,8 +88,8 @@ void radeon_driver_postclose_kms(struct drm_device *dev,
  435.                  struct drm_file *file_priv);
  436.  void radeon_driver_preclose_kms(struct drm_device *dev,
  437.                 struct drm_file *file_priv);
  438. -int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  439. -int radeon_resume_kms(struct drm_device *dev);
  440. +int radeon_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
  441. +int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
  442.  u32 radeon_get_vblank_counter_kms(struct drm_device *dev, int crtc);
  443.  int radeon_enable_vblank_kms(struct drm_device *dev, int crtc);
  444.  void radeon_disable_vblank_kms(struct drm_device *dev, int crtc);
  445. @@ -259,6 +260,7 @@ static int radeon_resume(struct drm_device *dev)
  446.     return 0;
  447.  }
  448.  
  449. +
  450.  static const struct file_operations radeon_driver_old_fops = {
  451.     .owner = THIS_MODULE,
  452.     .open = drm_open,
  453. @@ -353,25 +355,116 @@ radeon_pci_remove(struct pci_dev *pdev)
  454.     drm_put_dev(dev);
  455.  }
  456.  
  457. -static int
  458. -radeon_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  459. +static int radeon_pmops_suspend(struct device *dev)
  460.  {
  461. -   struct drm_device *dev = pci_get_drvdata(pdev);
  462. -   return radeon_suspend_kms(dev, state);
  463. +   struct pci_dev *pdev = to_pci_dev(dev);
  464. +   struct drm_device *drm_dev = pci_get_drvdata(pdev);
  465. +   return radeon_suspend_kms(drm_dev, true, true);
  466.  }
  467.  
  468. -static int
  469. -radeon_pci_resume(struct pci_dev *pdev)
  470. +static int radeon_pmops_resume(struct device *dev)
  471.  {
  472. -   struct drm_device *dev = pci_get_drvdata(pdev);
  473. -   return radeon_resume_kms(dev);
  474. +   struct pci_dev *pdev = to_pci_dev(dev);
  475. +   struct drm_device *drm_dev = pci_get_drvdata(pdev);
  476. +   return radeon_resume_kms(drm_dev, true, true);
  477. +}
  478. +
  479. +static int radeon_pmops_freeze(struct device *dev)
  480. +{
  481. +   struct pci_dev *pdev = to_pci_dev(dev);
  482. +   struct drm_device *drm_dev = pci_get_drvdata(pdev);
  483. +   return radeon_suspend_kms(drm_dev, false, true);
  484. +}
  485. +
  486. +static int radeon_pmops_thaw(struct device *dev)
  487. +{
  488. +   struct pci_dev *pdev = to_pci_dev(dev);
  489. +   struct drm_device *drm_dev = pci_get_drvdata(pdev);
  490. +   return radeon_resume_kms(drm_dev, false, true);
  491. +}
  492. +
  493. +static int radeon_pmops_runtime_suspend(struct device *dev)
  494. +{
  495. +   struct pci_dev *pdev = to_pci_dev(dev);
  496. +   struct drm_device *drm_dev = pci_get_drvdata(pdev);
  497. +   int ret;
  498. +
  499. +   drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  500. +   drm_kms_helper_poll_disable(drm_dev);
  501. +   vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_OFF);
  502. +
  503. +   ret = radeon_suspend_kms(drm_dev, false, false);
  504. +   pci_save_state(pdev);
  505. +   pci_disable_device(pdev);
  506. +   pci_set_power_state(pdev, PCI_D3cold);
  507. +   drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
  508. +
  509. +   return 0;
  510. +}
  511. +
  512. +static int radeon_pmops_runtime_resume(struct device *dev)
  513. +{
  514. +   struct pci_dev *pdev = to_pci_dev(dev);
  515. +   struct drm_device *drm_dev = pci_get_drvdata(pdev);
  516. +   int ret;
  517. +
  518. +   drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  519. +
  520. +   pci_set_power_state(pdev, PCI_D0);
  521. +   pci_restore_state(pdev);
  522. +   ret = pci_enable_device(pdev);
  523. +   if (ret)
  524. +       return ret;
  525. +   pci_set_master(pdev);
  526. +
  527. +   ret = radeon_resume_kms(drm_dev, false, false);
  528. +   drm_kms_helper_poll_enable(drm_dev);
  529. +   vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_ON);
  530. +   drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
  531. +   return 0;
  532. +}
  533. +
  534. +static int radeon_pmops_runtime_idle(struct device *dev)
  535. +{
  536. +   pm_runtime_autosuspend(dev);
  537. +   return 1;
  538. +}
  539. +
  540. +static long radeon_drm_ioctl(struct file *filp,
  541. +                unsigned int cmd, unsigned long arg)
  542. +{
  543. +   struct drm_file *file_priv = filp->private_data;
  544. +   struct drm_device *dev;
  545. +   long ret;
  546. +   dev = file_priv->minor->dev;
  547. +   ret = pm_runtime_get_sync(dev->dev);
  548. +   if (ret < 0)
  549. +       return ret;
  550. +
  551. +   ret = drm_ioctl(filp, cmd, arg);
  552. +  
  553. +   pm_runtime_mark_last_busy(dev->dev);
  554. +   pm_runtime_put_autosuspend(dev->dev);
  555. +   return ret;
  556.  }
  557.  
  558. +static const struct dev_pm_ops radeon_pm_ops = {
  559. +   .suspend = radeon_pmops_suspend,
  560. +   .resume = radeon_pmops_resume,
  561. +   .freeze = radeon_pmops_freeze,
  562. +   .thaw = radeon_pmops_thaw,
  563. +   .poweroff = radeon_pmops_freeze,
  564. +   .restore = radeon_pmops_resume,
  565. +   .runtime_suspend = radeon_pmops_runtime_suspend,
  566. +   .runtime_resume = radeon_pmops_runtime_resume,
  567. +   .runtime_idle = radeon_pmops_runtime_idle,
  568. +};
  569. +
  570.  static const struct file_operations radeon_driver_kms_fops = {
  571.     .owner = THIS_MODULE,
  572.     .open = drm_open,
  573.     .release = drm_release,
  574. -   .unlocked_ioctl = drm_ioctl,
  575. +   .unlocked_ioctl = radeon_drm_ioctl,
  576.     .mmap = radeon_mmap,
  577.     .poll = drm_poll,
  578.     .read = drm_read,
  579. @@ -392,8 +485,6 @@ static struct drm_driver kms_driver = {
  580.     .postclose = radeon_driver_postclose_kms,
  581.     .lastclose = radeon_driver_lastclose_kms,
  582.     .unload = radeon_driver_unload_kms,
  583. -   .suspend = radeon_suspend_kms,
  584. -   .resume = radeon_resume_kms,
  585.     .get_vblank_counter = radeon_get_vblank_counter_kms,
  586.     .enable_vblank = radeon_enable_vblank_kms,
  587.     .disable_vblank = radeon_disable_vblank_kms,
  588. @@ -451,8 +542,7 @@ static struct pci_driver radeon_kms_pci_driver = {
  589.     .id_table = pciidlist,
  590.     .probe = radeon_pci_probe,
  591.     .remove = radeon_pci_remove,
  592. -   .suspend = radeon_pci_suspend,
  593. -   .resume = radeon_pci_resume,
  594. +   .driver.pm = &radeon_pm_ops,
  595.  };
  596.  
  597.  static int __init radeon_init(void)
  598. diff --git a/drivers/gpu/drm/radeon/radeon_irq_kms.c b/drivers/gpu/drm/radeon/radeon_irq_kms.c
  599. index cc9e848..ec6240b 100644
  600. --- a/drivers/gpu/drm/radeon/radeon_irq_kms.c
  601. +++ b/drivers/gpu/drm/radeon/radeon_irq_kms.c
  602. @@ -32,6 +32,8 @@
  603.  #include "radeon.h"
  604.  #include "atom.h"
  605.  
  606. +#include <linux/pm_runtime.h>
  607. +
  608.  #define RADEON_WAIT_IDLE_TIMEOUT 200
  609.  
  610.  /**
  611. @@ -47,8 +49,12 @@ irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
  612.  {
  613.     struct drm_device *dev = (struct drm_device *) arg;
  614.     struct radeon_device *rdev = dev->dev_private;
  615. +   irqreturn_t ret;
  616.  
  617. -   return radeon_irq_process(rdev);
  618. +   ret = radeon_irq_process(rdev);
  619. +   if (ret == IRQ_HANDLED)
  620. +       pm_runtime_mark_last_busy(dev->dev);
  621. +   return ret;
  622.  }
  623.  
  624.  /*
  625. diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
  626. index 61580dd..2b63461 100644
  627. --- a/drivers/gpu/drm/radeon/radeon_kms.c
  628. +++ b/drivers/gpu/drm/radeon/radeon_kms.c
  629. @@ -32,7 +32,7 @@
  630.  
  631.  #include <linux/vga_switcheroo.h>
  632.  #include <linux/slab.h>
  633. -
  634. +#include <linux/pm_runtime.h>
  635.  /**
  636.   * radeon_driver_unload_kms - Main unload function for KMS.
  637.   *
  638. @@ -50,9 +50,14 @@ int radeon_driver_unload_kms(struct drm_device *dev)
  639.  
  640.     if (rdev == NULL)
  641.         return 0;
  642. +
  643.     if (rdev->rmmio == NULL)
  644.         goto done_free;
  645. +
  646. +   pm_runtime_get_sync(dev->dev);
  647. +
  648.     radeon_acpi_fini(rdev);
  649. +  
  650.     radeon_modeset_fini(rdev);
  651.     radeon_device_fini(rdev);
  652.  
  653. @@ -125,9 +130,18 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
  654.                 "Error during ACPI methods call\n");
  655.     }
  656.  
  657. +   pm_runtime_use_autosuspend(dev->dev);
  658. +   pm_runtime_set_autosuspend_delay(dev->dev, 5000);
  659. +   pm_runtime_set_active(dev->dev);
  660. +   pm_runtime_allow(dev->dev);
  661. +   pm_runtime_mark_last_busy(dev->dev);
  662. +   pm_runtime_put_autosuspend(dev->dev);
  663. +
  664.  out:
  665.     if (r)
  666.         radeon_driver_unload_kms(dev);
  667. +
  668. +
  669.     return r;
  670.  }
  671.  
  672. @@ -475,9 +489,14 @@ void radeon_driver_lastclose_kms(struct drm_device *dev)
  673.  int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  674.  {
  675.     struct radeon_device *rdev = dev->dev_private;
  676. +   int r;
  677.  
  678.     file_priv->driver_priv = NULL;
  679.  
  680. +   r = pm_runtime_get_sync(dev->dev);
  681. +   if (r < 0)
  682. +       return r;
  683. +
  684.     /* new gpu have virtual address space support */
  685.     if (rdev->family >= CHIP_CAYMAN) {
  686.         struct radeon_fpriv *fpriv;
  687. @@ -506,6 +525,9 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  688.  
  689.         file_priv->driver_priv = fpriv;
  690.     }
  691. +
  692. +   pm_runtime_mark_last_busy(dev->dev);
  693. +   pm_runtime_put_autosuspend(dev->dev);
  694.     return 0;
  695.  }
  696.  
  697. --
  698. 1.8.3.2
Advertisement
Add Comment
Please, Sign In to add comment