2019-06-20 00:13:43 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2012-07-31 06:16:21 +00:00
|
|
|
#include <linux/vgaarb.h>
|
|
|
|
#include <linux/vga_switcheroo.h>
|
|
|
|
|
Merge branch 'drm-next' of git://people.freedesktop.org/~airlied/linux
Pull drm merge (part 1) from Dave Airlie:
"So first of all my tree and uapi stuff has a conflict mess, its my
fault as the nouveau stuff didn't hit -next as were trying to rebase
regressions out of it before we merged.
Highlights:
- SH mobile modesetting driver and associated helpers
- some DRM core documentation
- i915 modesetting rework, haswell hdmi, haswell and vlv fixes, write
combined pte writing, ilk rc6 support,
- nouveau: major driver rework into a hw core driver, makes features
like SLI a lot saner to implement,
- psb: add eDP/DP support for Cedarview
- radeon: 2 layer page tables, async VM pte updates, better PLL
selection for > 2 screens, better ACPI interactions
The rest is general grab bag of fixes.
So why part 1? well I have the exynos pull req which came in a bit
late but was waiting for me to do something they shouldn't have and it
looks fairly safe, and David Howells has some more header cleanups
he'd like me to pull, that seem like a good idea, but I'd like to get
this merge out of the way so -next dosen't get blocked."
Tons of conflicts mostly due to silly include line changes, but mostly
mindless. A few other small semantic conflicts too, noted from Dave's
pre-merged branch.
* 'drm-next' of git://people.freedesktop.org/~airlied/linux: (447 commits)
drm/nv98/crypt: fix fuc build with latest envyas
drm/nouveau/devinit: fixup various issues with subdev ctor/init ordering
drm/nv41/vm: fix and enable use of "real" pciegart
drm/nv44/vm: fix and enable use of "real" pciegart
drm/nv04/dmaobj: fixup vm target handling in preparation for nv4x pcie
drm/nouveau: store supported dma mask in vmmgr
drm/nvc0/ibus: initial implementation of subdev
drm/nouveau/therm: add support for fan-control modes
drm/nouveau/hwmon: rename pwm0* to pmw1* to follow hwmon's rules
drm/nouveau/therm: calculate the pwm divisor on nv50+
drm/nouveau/fan: rewrite the fan tachometer driver to get more precision, faster
drm/nouveau/therm: move thermal-related functions to the therm subdev
drm/nouveau/bios: parse the pwm divisor from the perf table
drm/nouveau/therm: use the EXTDEV table to detect i2c monitoring devices
drm/nouveau/therm: rework thermal table parsing
drm/nouveau/gpio: expose the PWM/TOGGLE parameter found in the gpio vbios table
drm/nouveau: fix pm initialization order
drm/nouveau/bios: check that fixed tvdac gpio data is valid before using it
drm/nouveau: log channel debug/error messages from client object rather than drm client
drm/nouveau: have drm debugging macros build on top of core macros
...
2012-10-04 06:29:23 +00:00
|
|
|
#include <drm/drm_crtc_helper.h>
|
2017-12-05 18:25:00 +00:00
|
|
|
#include <drm/drm_fb_helper.h>
|
2012-07-31 06:16:21 +00:00
|
|
|
|
2016-05-19 23:22:55 +00:00
|
|
|
#include "nouveau_drv.h"
|
2012-07-31 06:16:21 +00:00
|
|
|
#include "nouveau_acpi.h"
|
|
|
|
#include "nouveau_fbcon.h"
|
2012-08-19 21:00:00 +00:00
|
|
|
#include "nouveau_vga.h"
|
2012-07-31 06:16:21 +00:00
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
nouveau_vga_set_decode(void *priv, bool state)
|
|
|
|
{
|
2015-08-20 04:54:15 +00:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(priv);
|
2016-05-18 03:57:42 +00:00
|
|
|
struct nvif_object *device = &drm->client.device.object;
|
2012-07-31 06:16:21 +00:00
|
|
|
|
2016-05-18 03:57:42 +00:00
|
|
|
if (drm->client.device.info.family == NV_DEVICE_INFO_V0_CURIE &&
|
|
|
|
drm->client.device.info.chipset >= 0x4c)
|
2014-08-09 18:10:22 +00:00
|
|
|
nvif_wr32(device, 0x088060, state);
|
2012-07-31 06:16:21 +00:00
|
|
|
else
|
2016-05-18 03:57:42 +00:00
|
|
|
if (drm->client.device.info.chipset >= 0x40)
|
2014-08-09 18:10:22 +00:00
|
|
|
nvif_wr32(device, 0x088054, state);
|
|
|
|
else
|
|
|
|
nvif_wr32(device, 0x001854, state);
|
2012-07-31 06:16:21 +00:00
|
|
|
|
|
|
|
if (state)
|
|
|
|
return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
|
|
|
|
VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
|
|
|
|
else
|
|
|
|
return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_switcheroo_set_state(struct pci_dev *pdev,
|
|
|
|
enum vga_switcheroo_state state)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
|
|
|
|
2012-09-10 04:20:51 +00:00
|
|
|
if ((nouveau_is_optimus() || nouveau_is_v1_dsm()) && state == VGA_SWITCHEROO_OFF)
|
|
|
|
return;
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
if (state == VGA_SWITCHEROO_ON) {
|
2017-02-28 12:55:54 +00:00
|
|
|
pr_err("VGA switcheroo: switched nouveau on\n");
|
2012-07-31 06:16:21 +00:00
|
|
|
dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
|
2012-11-02 01:04:28 +00:00
|
|
|
nouveau_pmops_resume(&pdev->dev);
|
2012-07-31 06:16:21 +00:00
|
|
|
dev->switch_power_state = DRM_SWITCH_POWER_ON;
|
|
|
|
} else {
|
2017-02-28 12:55:54 +00:00
|
|
|
pr_err("VGA switcheroo: switched nouveau off\n");
|
2012-07-31 06:16:21 +00:00
|
|
|
dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
|
|
|
|
nouveau_switcheroo_optimus_dsm();
|
2012-11-02 01:04:28 +00:00
|
|
|
nouveau_pmops_suspend(&pdev->dev);
|
2012-07-31 06:16:21 +00:00
|
|
|
dev->switch_power_state = DRM_SWITCH_POWER_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_switcheroo_reprobe(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
2017-12-05 18:25:00 +00:00
|
|
|
drm_fb_helper_output_poll_changed(dev);
|
2012-07-31 06:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
nouveau_switcheroo_can_switch(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
|
|
|
|
2013-11-03 19:46:34 +00:00
|
|
|
/*
|
|
|
|
* FIXME: open_count is protected by drm_global_mutex but that would lead to
|
|
|
|
* locking inversion with the driver load path. And the access here is
|
|
|
|
* completely racy anyway. So don't bother with locking for now.
|
|
|
|
*/
|
|
|
|
return dev->open_count == 0;
|
2012-07-31 06:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct vga_switcheroo_client_ops
|
|
|
|
nouveau_switcheroo_ops = {
|
|
|
|
.set_gpu_state = nouveau_switcheroo_set_state,
|
|
|
|
.reprobe = nouveau_switcheroo_reprobe,
|
|
|
|
.can_switch = nouveau_switcheroo_can_switch,
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_vga_init(struct nouveau_drm *drm)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = drm->dev;
|
2017-06-02 04:38:07 +00:00
|
|
|
bool runtime = nouveau_pmops_runtime();
|
2014-02-17 06:17:26 +00:00
|
|
|
|
|
|
|
/* only relevant for PCI devices */
|
|
|
|
if (!dev->pdev)
|
|
|
|
return;
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode);
|
2012-09-10 04:20:51 +00:00
|
|
|
|
2017-03-10 20:23:45 +00:00
|
|
|
/* don't register Thunderbolt eGPU with vga_switcheroo */
|
|
|
|
if (pci_is_thunderbolt_attached(dev->pdev))
|
|
|
|
return;
|
|
|
|
|
2012-09-10 04:20:51 +00:00
|
|
|
vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops, runtime);
|
|
|
|
|
|
|
|
if (runtime && nouveau_is_v1_dsm() && !nouveau_is_optimus())
|
|
|
|
vga_switcheroo_init_domain_pm_ops(drm->dev->dev, &drm->vga_pm_domain);
|
2012-07-31 06:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_vga_fini(struct nouveau_drm *drm)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = drm->dev;
|
2017-06-02 04:38:07 +00:00
|
|
|
bool runtime = nouveau_pmops_runtime();
|
2014-09-12 22:06:56 +00:00
|
|
|
|
2017-06-09 12:25:41 +00:00
|
|
|
/* only relevant for PCI devices */
|
|
|
|
if (!dev->pdev)
|
|
|
|
return;
|
|
|
|
|
2017-03-10 20:23:45 +00:00
|
|
|
vga_client_register(dev->pdev, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (pci_is_thunderbolt_attached(dev->pdev))
|
|
|
|
return;
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
vga_switcheroo_unregister_client(dev->pdev);
|
2014-09-12 22:06:56 +00:00
|
|
|
if (runtime && nouveau_is_v1_dsm() && !nouveau_is_optimus())
|
|
|
|
vga_switcheroo_fini_domain_pm_ops(drm->dev->dev);
|
2012-07-31 06:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_vga_lastclose(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
vga_switcheroo_process_delayed_switch();
|
|
|
|
}
|