2012-07-06 02:14:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* 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 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
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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: Ben Skeggs
|
|
|
|
*/
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
#include <linux/console.h>
|
2015-04-19 15:18:01 +00:00
|
|
|
#include <linux/delay.h>
|
2012-07-06 02:14:00 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
2012-09-10 04:20:51 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include <linux/vga_switcheroo.h>
|
2019-08-06 23:15:42 +00:00
|
|
|
#include <linux/mmu_notifier.h>
|
2014-08-09 18:10:23 +00:00
|
|
|
|
2017-04-24 04:50:29 +00:00
|
|
|
#include <drm/drm_crtc_helper.h>
|
2019-05-19 14:00:44 +00:00
|
|
|
#include <drm/drm_ioctl.h>
|
|
|
|
#include <drm/drm_vblank.h>
|
2014-08-09 18:10:23 +00:00
|
|
|
|
2012-07-19 22:17:34 +00:00
|
|
|
#include <core/gpuobj.h>
|
2014-02-14 02:35:14 +00:00
|
|
|
#include <core/option.h>
|
2015-08-20 04:54:17 +00:00
|
|
|
#include <core/pci.h>
|
|
|
|
#include <core/tegra.h>
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2016-05-22 10:35:16 +00:00
|
|
|
#include <nvif/driver.h>
|
2018-05-08 10:39:46 +00:00
|
|
|
#include <nvif/fifo.h>
|
2018-05-08 10:39:48 +00:00
|
|
|
#include <nvif/user.h>
|
2016-05-22 10:35:16 +00:00
|
|
|
|
2015-11-08 02:23:16 +00:00
|
|
|
#include <nvif/class.h>
|
2015-11-08 02:16:40 +00:00
|
|
|
#include <nvif/cl0002.h>
|
2015-11-08 01:28:26 +00:00
|
|
|
#include <nvif/cla06f.h>
|
2015-11-08 00:34:50 +00:00
|
|
|
|
2016-05-19 23:22:55 +00:00
|
|
|
#include "nouveau_drv.h"
|
2012-07-19 22:17:34 +00:00
|
|
|
#include "nouveau_dma.h"
|
2012-07-31 06:16:21 +00:00
|
|
|
#include "nouveau_ttm.h"
|
|
|
|
#include "nouveau_gem.h"
|
|
|
|
#include "nouveau_vga.h"
|
2016-08-25 00:57:07 +00:00
|
|
|
#include "nouveau_led.h"
|
2013-10-14 23:44:02 +00:00
|
|
|
#include "nouveau_hwmon.h"
|
2012-07-31 06:16:21 +00:00
|
|
|
#include "nouveau_acpi.h"
|
|
|
|
#include "nouveau_bios.h"
|
|
|
|
#include "nouveau_ioctl.h"
|
2012-07-19 22:17:34 +00:00
|
|
|
#include "nouveau_abi16.h"
|
|
|
|
#include "nouveau_fbcon.h"
|
|
|
|
#include "nouveau_fence.h"
|
2013-02-08 20:42:13 +00:00
|
|
|
#include "nouveau_debugfs.h"
|
2014-08-09 18:10:31 +00:00
|
|
|
#include "nouveau_usif.h"
|
2014-08-18 20:43:24 +00:00
|
|
|
#include "nouveau_connector.h"
|
2015-01-15 06:29:56 +00:00
|
|
|
#include "nouveau_platform.h"
|
2018-07-05 02:57:12 +00:00
|
|
|
#include "nouveau_svm.h"
|
2018-07-26 21:59:13 +00:00
|
|
|
#include "nouveau_dmem.h"
|
2012-07-19 22:17:34 +00:00
|
|
|
|
2012-07-06 02:14:00 +00:00
|
|
|
MODULE_PARM_DESC(config, "option string to pass to driver core");
|
|
|
|
static char *nouveau_config;
|
|
|
|
module_param_named(config, nouveau_config, charp, 0400);
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(debug, "debug string to pass to driver core");
|
|
|
|
static char *nouveau_debug;
|
|
|
|
module_param_named(debug, nouveau_debug, charp, 0400);
|
|
|
|
|
2012-07-19 22:17:34 +00:00
|
|
|
MODULE_PARM_DESC(noaccel, "disable kernel/abi16 acceleration");
|
|
|
|
static int nouveau_noaccel = 0;
|
|
|
|
module_param_named(noaccel, nouveau_noaccel, int, 0400);
|
|
|
|
|
2012-10-31 02:11:15 +00:00
|
|
|
MODULE_PARM_DESC(modeset, "enable driver (default: auto, "
|
|
|
|
"0 = disabled, 1 = enabled, 2 = headless)");
|
|
|
|
int nouveau_modeset = -1;
|
2012-07-31 06:16:21 +00:00
|
|
|
module_param_named(modeset, nouveau_modeset, int, 0400);
|
|
|
|
|
2018-07-03 20:31:41 +00:00
|
|
|
MODULE_PARM_DESC(atomic, "Expose atomic ioctl (default: disabled)");
|
|
|
|
static int nouveau_atomic = 0;
|
|
|
|
module_param_named(atomic, nouveau_atomic, int, 0400);
|
|
|
|
|
2012-09-10 04:20:51 +00:00
|
|
|
MODULE_PARM_DESC(runpm, "disable (0), force enable (1), optimus only default (-1)");
|
2017-06-02 04:38:07 +00:00
|
|
|
static int nouveau_runtime_pm = -1;
|
2012-09-10 04:20:51 +00:00
|
|
|
module_param_named(runpm, nouveau_runtime_pm, int, 0400);
|
|
|
|
|
2014-08-29 10:12:43 +00:00
|
|
|
static struct drm_driver driver_stub;
|
|
|
|
static struct drm_driver driver_pci;
|
|
|
|
static struct drm_driver driver_platform;
|
2012-07-31 06:16:21 +00:00
|
|
|
|
2012-07-06 02:14:00 +00:00
|
|
|
static u64
|
2014-02-17 06:17:26 +00:00
|
|
|
nouveau_pci_name(struct pci_dev *pdev)
|
2012-07-06 02:14:00 +00:00
|
|
|
{
|
|
|
|
u64 name = (u64)pci_domain_nr(pdev->bus) << 32;
|
|
|
|
name |= pdev->bus->number << 16;
|
|
|
|
name |= PCI_SLOT(pdev->devfn) << 8;
|
|
|
|
return name | PCI_FUNC(pdev->devfn);
|
|
|
|
}
|
|
|
|
|
2014-02-17 06:17:26 +00:00
|
|
|
static u64
|
|
|
|
nouveau_platform_name(struct platform_device *platformdev)
|
|
|
|
{
|
|
|
|
return platformdev->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64
|
|
|
|
nouveau_name(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
if (dev->pdev)
|
|
|
|
return nouveau_pci_name(dev->pdev);
|
|
|
|
else
|
2016-12-17 22:01:19 +00:00
|
|
|
return nouveau_platform_name(to_platform_device(dev->dev));
|
2014-02-17 06:17:26 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 17:56:20 +00:00
|
|
|
static inline bool
|
2018-05-08 10:39:47 +00:00
|
|
|
nouveau_cli_work_ready(struct dma_fence *fence)
|
2017-10-31 17:56:20 +00:00
|
|
|
{
|
2018-05-08 10:39:47 +00:00
|
|
|
if (!dma_fence_is_signaled(fence))
|
|
|
|
return false;
|
2017-10-31 17:56:20 +00:00
|
|
|
dma_fence_put(fence);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-05-08 10:39:47 +00:00
|
|
|
nouveau_cli_work(struct work_struct *w)
|
2017-10-31 17:56:20 +00:00
|
|
|
{
|
2018-05-08 10:39:47 +00:00
|
|
|
struct nouveau_cli *cli = container_of(w, typeof(*cli), work);
|
2017-10-31 17:56:20 +00:00
|
|
|
struct nouveau_cli_work *work, *wtmp;
|
|
|
|
mutex_lock(&cli->lock);
|
|
|
|
list_for_each_entry_safe(work, wtmp, &cli->worker, head) {
|
2018-05-08 10:39:47 +00:00
|
|
|
if (!work->fence || nouveau_cli_work_ready(work->fence)) {
|
2017-10-31 17:56:20 +00:00
|
|
|
list_del(&work->head);
|
|
|
|
work->func(work);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&cli->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_cli_work_fence(struct dma_fence *fence, struct dma_fence_cb *cb)
|
|
|
|
{
|
|
|
|
struct nouveau_cli_work *work = container_of(cb, typeof(*work), cb);
|
|
|
|
schedule_work(&work->cli->work);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_cli_work_queue(struct nouveau_cli *cli, struct dma_fence *fence,
|
|
|
|
struct nouveau_cli_work *work)
|
|
|
|
{
|
|
|
|
work->fence = dma_fence_get(fence);
|
|
|
|
work->cli = cli;
|
|
|
|
mutex_lock(&cli->lock);
|
|
|
|
list_add_tail(&work->head, &cli->worker);
|
|
|
|
if (dma_fence_add_callback(fence, &work->cb, nouveau_cli_work_fence))
|
|
|
|
nouveau_cli_work_fence(fence, &work->cb);
|
2017-12-22 22:54:28 +00:00
|
|
|
mutex_unlock(&cli->lock);
|
2017-10-31 17:56:20 +00:00
|
|
|
}
|
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
static void
|
|
|
|
nouveau_cli_fini(struct nouveau_cli *cli)
|
|
|
|
{
|
2018-05-08 10:39:47 +00:00
|
|
|
/* All our channels are dead now, which means all the fences they
|
|
|
|
* own are signalled, and all callback functions have been called.
|
|
|
|
*
|
|
|
|
* So, after flushing the workqueue, there should be nothing left.
|
|
|
|
*/
|
|
|
|
flush_work(&cli->work);
|
|
|
|
WARN_ON(!list_empty(&cli->worker));
|
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
usif_client_fini(cli);
|
2019-02-19 07:21:48 +00:00
|
|
|
nouveau_vmm_fini(&cli->svm);
|
2017-10-31 17:56:19 +00:00
|
|
|
nouveau_vmm_fini(&cli->vmm);
|
2020-03-30 03:51:38 +00:00
|
|
|
nvif_mmu_dtor(&cli->mmu);
|
2020-03-30 03:49:05 +00:00
|
|
|
nvif_device_dtor(&cli->device);
|
2017-10-31 17:56:19 +00:00
|
|
|
mutex_lock(&cli->drm->master.lock);
|
2020-03-30 03:45:33 +00:00
|
|
|
nvif_client_dtor(&cli->base);
|
2017-10-31 17:56:19 +00:00
|
|
|
mutex_unlock(&cli->drm->master.lock);
|
2016-05-18 03:36:34 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 02:14:00 +00:00
|
|
|
static int
|
2016-05-18 03:36:34 +00:00
|
|
|
nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
|
|
|
|
struct nouveau_cli *cli)
|
2012-07-06 02:14:00 +00:00
|
|
|
{
|
2017-10-31 17:56:20 +00:00
|
|
|
static const struct nvif_mclass
|
|
|
|
mems[] = {
|
|
|
|
{ NVIF_CLASS_MEM_GF100, -1 },
|
|
|
|
{ NVIF_CLASS_MEM_NV50 , -1 },
|
|
|
|
{ NVIF_CLASS_MEM_NV04 , -1 },
|
|
|
|
{}
|
|
|
|
};
|
2017-10-31 17:56:19 +00:00
|
|
|
static const struct nvif_mclass
|
|
|
|
mmus[] = {
|
|
|
|
{ NVIF_CLASS_MMU_GF100, -1 },
|
|
|
|
{ NVIF_CLASS_MMU_NV50 , -1 },
|
|
|
|
{ NVIF_CLASS_MMU_NV04 , -1 },
|
|
|
|
{}
|
|
|
|
};
|
2017-10-31 17:56:20 +00:00
|
|
|
static const struct nvif_mclass
|
|
|
|
vmms[] = {
|
|
|
|
{ NVIF_CLASS_VMM_GP100, -1 },
|
|
|
|
{ NVIF_CLASS_VMM_GM200, -1 },
|
|
|
|
{ NVIF_CLASS_VMM_GF100, -1 },
|
|
|
|
{ NVIF_CLASS_VMM_NV50 , -1 },
|
|
|
|
{ NVIF_CLASS_VMM_NV04 , -1 },
|
|
|
|
{}
|
|
|
|
};
|
2016-05-18 03:36:34 +00:00
|
|
|
u64 device = nouveau_name(drm->dev);
|
2015-08-20 04:54:13 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
snprintf(cli->name, sizeof(cli->name), "%s", sname);
|
2017-10-31 17:56:19 +00:00
|
|
|
cli->drm = drm;
|
2016-05-18 03:36:34 +00:00
|
|
|
mutex_init(&cli->mutex);
|
|
|
|
usif_client_init(cli);
|
|
|
|
|
2017-10-31 17:56:20 +00:00
|
|
|
INIT_WORK(&cli->work, nouveau_cli_work);
|
|
|
|
INIT_LIST_HEAD(&cli->worker);
|
2017-10-31 17:56:19 +00:00
|
|
|
mutex_init(&cli->lock);
|
|
|
|
|
|
|
|
if (cli == &drm->master) {
|
2016-05-23 01:25:17 +00:00
|
|
|
ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug,
|
|
|
|
cli->name, device, &cli->base);
|
|
|
|
} else {
|
2017-10-31 17:56:19 +00:00
|
|
|
mutex_lock(&drm->master.lock);
|
2020-03-30 03:45:33 +00:00
|
|
|
ret = nvif_client_ctor(&drm->master.base, cli->name, device,
|
2015-08-20 04:54:13 +00:00
|
|
|
&cli->base);
|
2017-10-31 17:56:19 +00:00
|
|
|
mutex_unlock(&drm->master.lock);
|
2012-12-10 20:59:52 +00:00
|
|
|
}
|
2016-05-18 03:36:34 +00:00
|
|
|
if (ret) {
|
2018-08-28 04:10:34 +00:00
|
|
|
NV_PRINTK(err, cli, "Client allocation failed: %d\n", ret);
|
2016-05-18 03:36:34 +00:00
|
|
|
goto done;
|
2012-12-10 20:59:52 +00:00
|
|
|
}
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2020-03-30 03:49:05 +00:00
|
|
|
ret = nvif_device_ctor(&cli->base.object, "drmDevice", 0, NV_DEVICE,
|
2016-05-18 03:57:42 +00:00
|
|
|
&(struct nv_device_v0) {
|
|
|
|
.device = ~0,
|
|
|
|
}, sizeof(struct nv_device_v0),
|
|
|
|
&cli->device);
|
|
|
|
if (ret) {
|
2018-08-28 04:10:34 +00:00
|
|
|
NV_PRINTK(err, cli, "Device allocation failed: %d\n", ret);
|
2016-05-18 03:57:42 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2017-10-31 17:56:19 +00:00
|
|
|
ret = nvif_mclass(&cli->device.object, mmus);
|
|
|
|
if (ret < 0) {
|
2018-08-28 04:10:34 +00:00
|
|
|
NV_PRINTK(err, cli, "No supported MMU class\n");
|
2017-10-31 17:56:19 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2020-03-30 03:51:38 +00:00
|
|
|
ret = nvif_mmu_ctor(&cli->device.object, "drmMmu", mmus[ret].oclass,
|
|
|
|
&cli->mmu);
|
2017-10-31 17:56:19 +00:00
|
|
|
if (ret) {
|
2018-08-28 04:10:34 +00:00
|
|
|
NV_PRINTK(err, cli, "MMU allocation failed: %d\n", ret);
|
2017-10-31 17:56:19 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2017-10-31 17:56:20 +00:00
|
|
|
ret = nvif_mclass(&cli->mmu.object, vmms);
|
|
|
|
if (ret < 0) {
|
2018-08-28 04:10:34 +00:00
|
|
|
NV_PRINTK(err, cli, "No supported VMM class\n");
|
2017-10-31 17:56:20 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = nouveau_vmm_init(cli, vmms[ret].oclass, &cli->vmm);
|
|
|
|
if (ret) {
|
2018-08-28 04:10:34 +00:00
|
|
|
NV_PRINTK(err, cli, "VMM allocation failed: %d\n", ret);
|
2017-10-31 17:56:20 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2017-10-31 17:56:20 +00:00
|
|
|
ret = nvif_mclass(&cli->mmu.object, mems);
|
|
|
|
if (ret < 0) {
|
2018-08-28 04:10:34 +00:00
|
|
|
NV_PRINTK(err, cli, "No supported MEM class\n");
|
2017-10-31 17:56:20 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
cli->mem = &mems[ret];
|
|
|
|
return 0;
|
2016-05-18 03:36:34 +00:00
|
|
|
done:
|
|
|
|
if (ret)
|
|
|
|
nouveau_cli_fini(cli);
|
|
|
|
return ret;
|
2012-07-06 02:14:00 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 22:17:34 +00:00
|
|
|
static void
|
2019-02-12 12:28:13 +00:00
|
|
|
nouveau_accel_ce_fini(struct nouveau_drm *drm)
|
|
|
|
{
|
|
|
|
nouveau_channel_idle(drm->cechan);
|
2020-03-29 23:51:33 +00:00
|
|
|
nvif_object_dtor(&drm->ttm.copy);
|
2019-02-12 12:28:13 +00:00
|
|
|
nouveau_channel_del(&drm->cechan);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_accel_ce_init(struct nouveau_drm *drm)
|
|
|
|
{
|
|
|
|
struct nvif_device *device = &drm->client.device;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* Allocate channel that has access to a (preferably async) copy
|
|
|
|
* engine, to use for TTM buffer moves.
|
|
|
|
*/
|
|
|
|
if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
|
|
|
|
ret = nouveau_channel_new(drm, device,
|
|
|
|
nvif_fifo_runlist_ce(device), 0,
|
|
|
|
true, &drm->cechan);
|
|
|
|
} else
|
|
|
|
if (device->info.chipset >= 0xa3 &&
|
|
|
|
device->info.chipset != 0xaa &&
|
|
|
|
device->info.chipset != 0xac) {
|
|
|
|
/* Prior to Kepler, there's only a single runlist, so all
|
|
|
|
* engines can be accessed from any channel.
|
|
|
|
*
|
|
|
|
* We still want to use a separate channel though.
|
|
|
|
*/
|
|
|
|
ret = nouveau_channel_new(drm, device, NvDmaFB, NvDmaTT, false,
|
|
|
|
&drm->cechan);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
NV_ERROR(drm, "failed to create ce channel, %d\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_accel_gr_fini(struct nouveau_drm *drm)
|
2012-07-19 22:17:34 +00:00
|
|
|
{
|
2015-08-20 04:54:22 +00:00
|
|
|
nouveau_channel_idle(drm->channel);
|
2020-03-29 23:51:33 +00:00
|
|
|
nvif_object_dtor(&drm->ntfy);
|
2015-08-20 04:54:17 +00:00
|
|
|
nvkm_gpuobj_del(&drm->notify);
|
2020-03-29 23:51:33 +00:00
|
|
|
nvif_object_dtor(&drm->nvsw);
|
2015-08-20 04:54:22 +00:00
|
|
|
nouveau_channel_del(&drm->channel);
|
2019-02-12 12:28:13 +00:00
|
|
|
}
|
2015-08-20 04:54:22 +00:00
|
|
|
|
2019-02-12 12:28:13 +00:00
|
|
|
static void
|
|
|
|
nouveau_accel_gr_init(struct nouveau_drm *drm)
|
|
|
|
{
|
|
|
|
struct nvif_device *device = &drm->client.device;
|
|
|
|
u32 arg0, arg1;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Allocate channel that has access to the graphics engine. */
|
|
|
|
if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
|
|
|
|
arg0 = nvif_fifo_runlist(device, NV_DEVICE_INFO_ENGINE_GR);
|
|
|
|
arg1 = 1;
|
|
|
|
} else {
|
|
|
|
arg0 = NvDmaFB;
|
|
|
|
arg1 = NvDmaTT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = nouveau_channel_new(drm, device, arg0, arg1, false,
|
|
|
|
&drm->channel);
|
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(drm, "failed to create kernel channel, %d\n", ret);
|
|
|
|
nouveau_accel_gr_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A SW class is used on pre-NV50 HW to assist with handling the
|
|
|
|
* synchronisation of page flips, as well as to implement fences
|
|
|
|
* on TNT/TNT2 HW that lacks any kind of support in host.
|
|
|
|
*/
|
|
|
|
if (device->info.family < NV_DEVICE_INFO_V0_TESLA) {
|
2020-03-29 23:51:33 +00:00
|
|
|
ret = nvif_object_ctor(&drm->channel->user, "drmNvsw",
|
|
|
|
NVDRM_NVSW, nouveau_abi16_swclass(drm),
|
|
|
|
NULL, 0, &drm->nvsw);
|
2019-02-12 12:28:13 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
ret = RING_SPACE(drm->channel, 2);
|
|
|
|
if (ret == 0) {
|
|
|
|
BEGIN_NV04(drm->channel, NvSubSw, 0, 1);
|
|
|
|
OUT_RING (drm->channel, drm->nvsw.handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(drm, "failed to allocate sw class, %d\n", ret);
|
|
|
|
nouveau_accel_gr_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NvMemoryToMemoryFormat requires a notifier ctxdma for some reason,
|
|
|
|
* even if notification is never requested, so, allocate a ctxdma on
|
|
|
|
* any GPU where it's possible we'll end up using M2MF for BO moves.
|
|
|
|
*/
|
|
|
|
if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
|
|
|
|
ret = nvkm_gpuobj_new(nvxx_device(device), 32, 0, false, NULL,
|
|
|
|
&drm->notify);
|
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
|
|
|
|
nouveau_accel_gr_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-29 23:51:33 +00:00
|
|
|
ret = nvif_object_ctor(&drm->channel->user, "drmM2mfNtfy",
|
|
|
|
NvNotify0, NV_DMA_IN_MEMORY,
|
2019-02-12 12:28:13 +00:00
|
|
|
&(struct nv_dma_v0) {
|
|
|
|
.target = NV_DMA_V0_TARGET_VRAM,
|
|
|
|
.access = NV_DMA_V0_ACCESS_RDWR,
|
|
|
|
.start = drm->notify->addr,
|
|
|
|
.limit = drm->notify->addr + 31
|
|
|
|
}, sizeof(struct nv_dma_v0),
|
|
|
|
&drm->ntfy);
|
|
|
|
if (ret) {
|
|
|
|
nouveau_accel_gr_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 04:54:22 +00:00
|
|
|
|
2019-02-12 12:28:13 +00:00
|
|
|
static void
|
|
|
|
nouveau_accel_fini(struct nouveau_drm *drm)
|
|
|
|
{
|
|
|
|
nouveau_accel_ce_fini(drm);
|
|
|
|
nouveau_accel_gr_fini(drm);
|
2012-07-19 22:17:34 +00:00
|
|
|
if (drm->fence)
|
|
|
|
nouveau_fence(drm)->dtor(drm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_accel_init(struct nouveau_drm *drm)
|
|
|
|
{
|
2016-05-18 03:57:42 +00:00
|
|
|
struct nvif_device *device = &drm->client.device;
|
2015-08-20 04:54:16 +00:00
|
|
|
struct nvif_sclass *sclass;
|
|
|
|
int ret, i, n;
|
2012-07-19 22:17:34 +00:00
|
|
|
|
2014-08-09 18:10:22 +00:00
|
|
|
if (nouveau_noaccel)
|
2012-07-19 22:17:34 +00:00
|
|
|
return;
|
|
|
|
|
2019-02-12 12:28:13 +00:00
|
|
|
/* Initialise global support for channels, and synchronisation. */
|
2018-05-08 10:39:46 +00:00
|
|
|
ret = nouveau_channels_init(drm);
|
|
|
|
if (ret)
|
|
|
|
return;
|
|
|
|
|
2014-08-09 18:10:22 +00:00
|
|
|
/*XXX: this is crap, but the fence/channel stuff is a little
|
|
|
|
* backwards in some places. this will be fixed.
|
|
|
|
*/
|
2015-08-20 04:54:16 +00:00
|
|
|
ret = n = nvif_object_sclass_get(&device->object, &sclass);
|
2014-08-09 18:10:22 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
2015-08-20 04:54:16 +00:00
|
|
|
for (ret = -ENOSYS, i = 0; i < n; i++) {
|
|
|
|
switch (sclass[i].oclass) {
|
2014-08-09 18:10:25 +00:00
|
|
|
case NV03_CHANNEL_DMA:
|
2014-08-09 18:10:22 +00:00
|
|
|
ret = nv04_fence_create(drm);
|
|
|
|
break;
|
2014-08-09 18:10:25 +00:00
|
|
|
case NV10_CHANNEL_DMA:
|
2014-08-09 18:10:22 +00:00
|
|
|
ret = nv10_fence_create(drm);
|
|
|
|
break;
|
2014-08-09 18:10:25 +00:00
|
|
|
case NV17_CHANNEL_DMA:
|
|
|
|
case NV40_CHANNEL_DMA:
|
2014-08-09 18:10:22 +00:00
|
|
|
ret = nv17_fence_create(drm);
|
|
|
|
break;
|
2014-08-09 18:10:25 +00:00
|
|
|
case NV50_CHANNEL_GPFIFO:
|
2014-08-09 18:10:22 +00:00
|
|
|
ret = nv50_fence_create(drm);
|
|
|
|
break;
|
2014-08-09 18:10:25 +00:00
|
|
|
case G82_CHANNEL_GPFIFO:
|
2014-08-09 18:10:22 +00:00
|
|
|
ret = nv84_fence_create(drm);
|
|
|
|
break;
|
2014-08-09 18:10:25 +00:00
|
|
|
case FERMI_CHANNEL_GPFIFO:
|
|
|
|
case KEPLER_CHANNEL_GPFIFO_A:
|
2016-03-11 03:09:28 +00:00
|
|
|
case KEPLER_CHANNEL_GPFIFO_B:
|
2015-04-14 01:47:24 +00:00
|
|
|
case MAXWELL_CHANNEL_GPFIFO_A:
|
2016-07-09 00:41:01 +00:00
|
|
|
case PASCAL_CHANNEL_GPFIFO_A:
|
2018-05-08 10:39:48 +00:00
|
|
|
case VOLTA_CHANNEL_GPFIFO_A:
|
2018-12-11 04:50:02 +00:00
|
|
|
case TURING_CHANNEL_GPFIFO_A:
|
2014-08-09 18:10:22 +00:00
|
|
|
ret = nvc0_fence_create(drm);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-20 04:54:16 +00:00
|
|
|
nvif_object_sclass_put(&sclass);
|
2012-07-19 22:17:34 +00:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(drm, "failed to initialise sync subsystem, %d\n", ret);
|
|
|
|
nouveau_accel_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-12 12:28:13 +00:00
|
|
|
/* Volta requires access to a doorbell register for kickoff. */
|
|
|
|
if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_VOLTA) {
|
|
|
|
ret = nvif_user_init(device);
|
2013-07-09 04:20:15 +00:00
|
|
|
if (ret)
|
2012-07-19 22:17:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-12 12:28:13 +00:00
|
|
|
/* Allocate channels we need to support various functions. */
|
|
|
|
nouveau_accel_gr_init(drm);
|
|
|
|
nouveau_accel_ce_init(drm);
|
2012-07-19 22:17:34 +00:00
|
|
|
|
2019-02-12 12:28:13 +00:00
|
|
|
/* Initialise accelerated TTM buffer moves. */
|
2012-08-06 09:38:25 +00:00
|
|
|
nouveau_bo_move_init(drm);
|
2012-07-19 22:17:34 +00:00
|
|
|
}
|
|
|
|
|
2012-08-19 21:00:00 +00:00
|
|
|
static int
|
2018-08-23 01:40:07 +00:00
|
|
|
nouveau_drm_device_init(struct drm_device *dev)
|
2012-07-06 02:14:00 +00:00
|
|
|
{
|
|
|
|
struct nouveau_drm *drm;
|
|
|
|
int ret;
|
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL)))
|
|
|
|
return -ENOMEM;
|
|
|
|
dev->dev_private = drm;
|
|
|
|
drm->dev = dev;
|
|
|
|
|
2017-10-31 17:56:19 +00:00
|
|
|
ret = nouveau_cli_init(drm, "DRM-master", &drm->master);
|
|
|
|
if (ret)
|
2018-08-23 01:40:06 +00:00
|
|
|
goto fail_alloc;
|
2017-10-31 17:56:19 +00:00
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
ret = nouveau_cli_init(drm, "DRM", &drm->client);
|
2012-07-06 02:14:00 +00:00
|
|
|
if (ret)
|
2018-08-23 01:40:06 +00:00
|
|
|
goto fail_master;
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2016-05-18 03:57:42 +00:00
|
|
|
dev->irq_enabled = true;
|
|
|
|
|
2015-01-12 02:33:37 +00:00
|
|
|
nvxx_client(&drm->client.base)->debug =
|
2015-01-14 05:36:34 +00:00
|
|
|
nvkm_dbgopt(nouveau_debug, "DRM");
|
2012-07-31 06:16:21 +00:00
|
|
|
|
2012-07-06 02:14:00 +00:00
|
|
|
INIT_LIST_HEAD(&drm->clients);
|
2012-07-19 22:17:34 +00:00
|
|
|
spin_lock_init(&drm->tile.lock);
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
/* workaround an odd issue on nvc1 by disabling the device's
|
|
|
|
* nosnoop capability. hopefully won't cause issues until a
|
|
|
|
* better fix is found - assuming there is one...
|
|
|
|
*/
|
2016-05-18 03:57:42 +00:00
|
|
|
if (drm->client.device.info.chipset == 0xc1)
|
|
|
|
nvif_mask(&drm->client.device.object, 0x00088080, 0x00000800, 0x00000000);
|
2012-07-19 22:17:34 +00:00
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_vga_init(drm);
|
2012-07-11 00:44:20 +00:00
|
|
|
|
2012-07-19 22:17:34 +00:00
|
|
|
ret = nouveau_ttm_init(drm);
|
2012-07-06 02:14:00 +00:00
|
|
|
if (ret)
|
2012-07-31 06:16:21 +00:00
|
|
|
goto fail_ttm;
|
|
|
|
|
|
|
|
ret = nouveau_bios_init(dev);
|
|
|
|
if (ret)
|
|
|
|
goto fail_bios;
|
|
|
|
|
2019-02-12 12:28:13 +00:00
|
|
|
nouveau_accel_init(drm);
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
ret = nouveau_display_create(dev);
|
2012-07-19 22:17:34 +00:00
|
|
|
if (ret)
|
2012-07-31 06:16:21 +00:00
|
|
|
goto fail_dispctor;
|
|
|
|
|
|
|
|
if (dev->mode_config.num_crtc) {
|
2019-02-12 12:28:13 +00:00
|
|
|
ret = nouveau_display_init(dev, false, false);
|
2012-07-31 06:16:21 +00:00
|
|
|
if (ret)
|
|
|
|
goto fail_dispinit;
|
|
|
|
}
|
|
|
|
|
2015-07-30 09:52:23 +00:00
|
|
|
nouveau_debugfs_init(drm);
|
2013-10-14 23:44:02 +00:00
|
|
|
nouveau_hwmon_init(dev);
|
2018-07-05 02:57:12 +00:00
|
|
|
nouveau_svm_init(drm);
|
2018-07-26 21:59:13 +00:00
|
|
|
nouveau_dmem_init(drm);
|
2012-07-19 22:17:34 +00:00
|
|
|
nouveau_fbcon_init(dev);
|
2016-08-25 00:57:07 +00:00
|
|
|
nouveau_led_init(dev);
|
2012-09-10 04:20:51 +00:00
|
|
|
|
2017-06-02 04:49:45 +00:00
|
|
|
if (nouveau_pmops_runtime()) {
|
2012-09-10 04:20:51 +00:00
|
|
|
pm_runtime_use_autosuspend(dev->dev);
|
|
|
|
pm_runtime_set_autosuspend_delay(dev->dev, 5000);
|
|
|
|
pm_runtime_set_active(dev->dev);
|
|
|
|
pm_runtime_allow(dev->dev);
|
|
|
|
pm_runtime_mark_last_busy(dev->dev);
|
|
|
|
pm_runtime_put(dev->dev);
|
|
|
|
}
|
2018-08-15 19:15:13 +00:00
|
|
|
|
2012-07-06 02:14:00 +00:00
|
|
|
return 0;
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
fail_dispinit:
|
|
|
|
nouveau_display_destroy(dev);
|
|
|
|
fail_dispctor:
|
2019-02-12 12:28:13 +00:00
|
|
|
nouveau_accel_fini(drm);
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_bios_takedown(dev);
|
|
|
|
fail_bios:
|
2012-07-19 22:17:34 +00:00
|
|
|
nouveau_ttm_fini(drm);
|
2012-07-31 06:16:21 +00:00
|
|
|
fail_ttm:
|
|
|
|
nouveau_vga_fini(drm);
|
2016-05-18 03:36:34 +00:00
|
|
|
nouveau_cli_fini(&drm->client);
|
2018-08-23 01:40:06 +00:00
|
|
|
fail_master:
|
2017-10-31 17:56:19 +00:00
|
|
|
nouveau_cli_fini(&drm->master);
|
2018-08-23 01:40:06 +00:00
|
|
|
fail_alloc:
|
2016-05-18 03:36:34 +00:00
|
|
|
kfree(drm);
|
2012-07-06 02:14:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:57:31 +00:00
|
|
|
static void
|
2018-08-23 01:40:07 +00:00
|
|
|
nouveau_drm_device_fini(struct drm_device *dev)
|
2012-07-06 02:14:00 +00:00
|
|
|
{
|
2012-07-31 06:16:21 +00:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2017-06-02 04:49:45 +00:00
|
|
|
if (nouveau_pmops_runtime()) {
|
2016-06-08 16:47:27 +00:00
|
|
|
pm_runtime_get_sync(dev->dev);
|
2016-06-08 16:47:27 +00:00
|
|
|
pm_runtime_forbid(dev->dev);
|
2016-06-08 16:47:27 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 00:57:07 +00:00
|
|
|
nouveau_led_fini(dev);
|
2012-07-19 22:17:34 +00:00
|
|
|
nouveau_fbcon_fini(dev);
|
2018-07-26 21:59:13 +00:00
|
|
|
nouveau_dmem_fini(drm);
|
2018-07-05 02:57:12 +00:00
|
|
|
nouveau_svm_fini(drm);
|
2013-10-14 23:44:02 +00:00
|
|
|
nouveau_hwmon_fini(dev);
|
2015-07-30 09:52:23 +00:00
|
|
|
nouveau_debugfs_fini(drm);
|
2012-07-31 06:16:21 +00:00
|
|
|
|
2012-10-31 02:11:15 +00:00
|
|
|
if (dev->mode_config.num_crtc)
|
2018-08-07 21:32:48 +00:00
|
|
|
nouveau_display_fini(dev, false, false);
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_display_destroy(dev);
|
|
|
|
|
2019-02-12 12:28:13 +00:00
|
|
|
nouveau_accel_fini(drm);
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_bios_takedown(dev);
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2012-07-19 22:17:34 +00:00
|
|
|
nouveau_ttm_fini(drm);
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_vga_fini(drm);
|
2012-07-11 00:44:20 +00:00
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
nouveau_cli_fini(&drm->client);
|
2017-10-31 17:56:19 +00:00
|
|
|
nouveau_cli_fini(&drm->master);
|
2016-05-18 03:36:34 +00:00
|
|
|
kfree(drm);
|
2012-07-06 02:14:00 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 20:29:23 +00:00
|
|
|
/*
|
|
|
|
* On some Intel PCIe bridge controllers doing a
|
|
|
|
* D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not reappear.
|
|
|
|
* Skipping the intermediate D3hot step seems to make it work again. This is
|
|
|
|
* probably caused by not meeting the expectation the involved AML code has
|
|
|
|
* when the GPU is put into D3hot state before invoking it.
|
|
|
|
*
|
|
|
|
* This leads to various manifestations of this issue:
|
|
|
|
* - AML code execution to power on the GPU hits an infinite loop (as the
|
|
|
|
* code waits on device memory to change).
|
|
|
|
* - kernel crashes, as all PCI reads return -1, which most code isn't able
|
|
|
|
* to handle well enough.
|
|
|
|
*
|
|
|
|
* In all cases dmesg will contain at least one line like this:
|
|
|
|
* 'nouveau 0000:01:00.0: Refused to change power state, currently in D3'
|
|
|
|
* followed by a lot of nouveau timeouts.
|
|
|
|
*
|
|
|
|
* In the \_SB.PCI0.PEG0.PG00._OFF code deeper down writes bit 0x80 to the not
|
|
|
|
* documented PCI config space register 0x248 of the Intel PCIe bridge
|
|
|
|
* controller (0x1901) in order to change the state of the PCIe link between
|
|
|
|
* the PCIe port and the GPU. There are alternative code paths using other
|
|
|
|
* registers, which seem to work fine (executed pre Windows 8):
|
|
|
|
* - 0xbc bit 0x20 (publicly available documentation claims 'reserved')
|
|
|
|
* - 0xb0 bit 0x10 (link disable)
|
|
|
|
* Changing the conditions inside the firmware by poking into the relevant
|
|
|
|
* addresses does resolve the issue, but it seemed to be ACPI private memory
|
|
|
|
* and not any device accessible memory at all, so there is no portable way of
|
|
|
|
* changing the conditions.
|
|
|
|
* On a XPS 9560 that means bits [0,3] on \CPEX need to be cleared.
|
|
|
|
*
|
|
|
|
* The only systems where this behavior can be seen are hybrid graphics laptops
|
|
|
|
* with a secondary Nvidia Maxwell, Pascal or Turing GPU. It's unclear whether
|
|
|
|
* this issue only occurs in combination with listed Intel PCIe bridge
|
|
|
|
* controllers and the mentioned GPUs or other devices as well.
|
|
|
|
*
|
|
|
|
* documentation on the PCIe bridge controller can be found in the
|
|
|
|
* "7th Generation Intel® Processor Families for H Platforms Datasheet Volume 2"
|
|
|
|
* Section "12 PCI Express* Controller (x16) Registers"
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void quirk_broken_nv_runpm(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
|
|
|
struct pci_dev *bridge = pci_upstream_bridge(pdev);
|
|
|
|
|
|
|
|
if (!bridge || bridge->vendor != PCI_VENDOR_ID_INTEL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (bridge->device) {
|
|
|
|
case 0x1901:
|
|
|
|
drm->old_pm_cap = pdev->pm_cap;
|
|
|
|
pdev->pm_cap = 0;
|
|
|
|
NV_INFO(drm, "Disabling PCI power management to avoid bug\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:40:07 +00:00
|
|
|
static int nouveau_drm_probe(struct pci_dev *pdev,
|
|
|
|
const struct pci_device_id *pent)
|
|
|
|
{
|
|
|
|
struct nvkm_device *device;
|
|
|
|
struct drm_device *drm_dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (vga_switcheroo_client_probe_defer(pdev))
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
|
|
|
/* We need to check that the chipset is supported before booting
|
|
|
|
* fbdev off the hardware, as there's no way to put it back.
|
|
|
|
*/
|
2019-05-09 06:48:50 +00:00
|
|
|
ret = nvkm_device_pci_new(pdev, nouveau_config, "error",
|
|
|
|
true, false, 0, &device);
|
2018-08-23 01:40:07 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
nvkm_device_del(&device);
|
|
|
|
|
|
|
|
/* Remove conflicting drivers (vesafb, efifb etc). */
|
2020-05-26 04:18:27 +00:00
|
|
|
ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "nouveaufb");
|
2020-02-02 03:55:23 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-08-23 01:40:07 +00:00
|
|
|
|
|
|
|
ret = nvkm_device_pci_new(pdev, nouveau_config, nouveau_debug,
|
|
|
|
true, true, ~0ULL, &device);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pci_set_master(pdev);
|
|
|
|
|
|
|
|
if (nouveau_atomic)
|
|
|
|
driver_pci.driver_features |= DRIVER_ATOMIC;
|
|
|
|
|
|
|
|
drm_dev = drm_dev_alloc(&driver_pci, &pdev->dev);
|
|
|
|
if (IS_ERR(drm_dev)) {
|
|
|
|
ret = PTR_ERR(drm_dev);
|
|
|
|
goto fail_nvkm;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pci_enable_device(pdev);
|
|
|
|
if (ret)
|
|
|
|
goto fail_drm;
|
|
|
|
|
|
|
|
drm_dev->pdev = pdev;
|
|
|
|
pci_set_drvdata(pdev, drm_dev);
|
|
|
|
|
|
|
|
ret = nouveau_drm_device_init(drm_dev);
|
|
|
|
if (ret)
|
|
|
|
goto fail_pci;
|
|
|
|
|
|
|
|
ret = drm_dev_register(drm_dev, pent->driver_data);
|
|
|
|
if (ret)
|
|
|
|
goto fail_drm_dev_init;
|
|
|
|
|
2020-03-24 20:29:23 +00:00
|
|
|
quirk_broken_nv_runpm(pdev);
|
2018-08-23 01:40:07 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_drm_dev_init:
|
|
|
|
nouveau_drm_device_fini(drm_dev);
|
|
|
|
fail_pci:
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
fail_drm:
|
|
|
|
drm_dev_put(drm_dev);
|
|
|
|
fail_nvkm:
|
|
|
|
nvkm_device_del(&device);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-26 05:33:32 +00:00
|
|
|
void
|
|
|
|
nouveau_drm_device_remove(struct drm_device *dev)
|
2012-07-06 02:14:00 +00:00
|
|
|
{
|
2012-07-31 06:16:21 +00:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2015-01-14 05:36:34 +00:00
|
|
|
struct nvkm_client *client;
|
2015-08-20 04:54:15 +00:00
|
|
|
struct nvkm_device *device;
|
2012-07-31 06:16:21 +00:00
|
|
|
|
2018-08-23 01:40:07 +00:00
|
|
|
drm_dev_unregister(dev);
|
|
|
|
|
2014-01-30 00:53:00 +00:00
|
|
|
dev->irq_enabled = false;
|
2015-01-12 02:33:37 +00:00
|
|
|
client = nvxx_client(&drm->client.base);
|
2015-08-20 04:54:15 +00:00
|
|
|
device = nvkm_device_find(client->device);
|
2012-07-31 06:16:21 +00:00
|
|
|
|
2018-08-23 01:40:07 +00:00
|
|
|
nouveau_drm_device_fini(dev);
|
|
|
|
drm_dev_put(dev);
|
2015-08-20 04:54:15 +00:00
|
|
|
nvkm_device_del(&device);
|
2012-07-06 02:14:00 +00:00
|
|
|
}
|
2014-06-26 05:33:32 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_drm_remove(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
2020-03-24 20:29:23 +00:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2014-06-26 05:33:32 +00:00
|
|
|
|
2020-03-24 20:29:23 +00:00
|
|
|
/* revert our workaround */
|
|
|
|
if (drm->old_pm_cap)
|
|
|
|
pdev->pm_cap = drm->old_pm_cap;
|
2014-06-26 05:33:32 +00:00
|
|
|
nouveau_drm_device_remove(dev);
|
2019-12-09 12:00:00 +00:00
|
|
|
pci_disable_device(pdev);
|
2014-06-26 05:33:32 +00:00
|
|
|
}
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2013-01-27 14:01:55 +00:00
|
|
|
static int
|
2014-03-26 04:10:06 +00:00
|
|
|
nouveau_do_suspend(struct drm_device *dev, bool runtime)
|
2012-07-06 02:14:00 +00:00
|
|
|
{
|
2012-07-31 06:16:21 +00:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2012-07-06 02:14:00 +00:00
|
|
|
int ret;
|
|
|
|
|
2018-07-05 02:57:12 +00:00
|
|
|
nouveau_svm_suspend(drm);
|
2018-07-26 21:59:13 +00:00
|
|
|
nouveau_dmem_suspend(drm);
|
2016-08-25 00:57:07 +00:00
|
|
|
nouveau_led_suspend(dev);
|
|
|
|
|
2014-10-02 03:22:27 +00:00
|
|
|
if (dev->mode_config.num_crtc) {
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "suspending console...\n");
|
2014-10-02 03:22:27 +00:00
|
|
|
nouveau_fbcon_set_suspend(dev, 1);
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "suspending display...\n");
|
2014-10-02 03:22:27 +00:00
|
|
|
ret = nouveau_display_suspend(dev, runtime);
|
2012-10-31 02:11:15 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "evicting buffers...\n");
|
2012-07-19 22:17:34 +00:00
|
|
|
ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM);
|
|
|
|
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "waiting for kernel channels to go idle...\n");
|
2013-05-06 22:33:10 +00:00
|
|
|
if (drm->cechan) {
|
|
|
|
ret = nouveau_channel_idle(drm->cechan);
|
|
|
|
if (ret)
|
2014-01-23 07:45:02 +00:00
|
|
|
goto fail_display;
|
2013-05-06 22:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (drm->channel) {
|
|
|
|
ret = nouveau_channel_idle(drm->channel);
|
|
|
|
if (ret)
|
2014-01-23 07:45:02 +00:00
|
|
|
goto fail_display;
|
2013-05-06 22:33:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "suspending fence...\n");
|
2012-07-19 22:17:34 +00:00
|
|
|
if (drm->fence && nouveau_fence(drm)->suspend) {
|
2014-01-23 07:45:02 +00:00
|
|
|
if (!nouveau_fence(drm)->suspend(drm)) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail_display;
|
|
|
|
}
|
2012-07-19 22:17:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "suspending object tree...\n");
|
2017-10-31 17:56:19 +00:00
|
|
|
ret = nvif_client_suspend(&drm->master.base);
|
2012-07-06 02:14:00 +00:00
|
|
|
if (ret)
|
|
|
|
goto fail_client;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_client:
|
2014-01-23 07:45:02 +00:00
|
|
|
if (drm->fence && nouveau_fence(drm)->resume)
|
|
|
|
nouveau_fence(drm)->resume(drm);
|
|
|
|
|
|
|
|
fail_display:
|
2012-10-31 02:11:15 +00:00
|
|
|
if (dev->mode_config.num_crtc) {
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "resuming display...\n");
|
2014-10-02 03:22:27 +00:00
|
|
|
nouveau_display_resume(dev, runtime);
|
2012-10-31 02:11:15 +00:00
|
|
|
}
|
2012-07-06 02:14:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-27 14:01:55 +00:00
|
|
|
static int
|
2014-10-02 03:22:27 +00:00
|
|
|
nouveau_do_resume(struct drm_device *dev, bool runtime)
|
2012-11-02 01:04:28 +00:00
|
|
|
{
|
2019-03-28 13:17:31 +00:00
|
|
|
int ret = 0;
|
2012-11-02 01:04:28 +00:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
|
|
|
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "resuming object tree...\n");
|
2019-03-28 13:17:31 +00:00
|
|
|
ret = nvif_client_resume(&drm->master.base);
|
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(drm, "Client resume failed with error: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-07-06 02:14:00 +00:00
|
|
|
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "resuming fence...\n");
|
2013-05-06 22:33:10 +00:00
|
|
|
if (drm->fence && nouveau_fence(drm)->resume)
|
|
|
|
nouveau_fence(drm)->resume(drm);
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_run_vbios_init(dev);
|
|
|
|
|
2012-10-31 02:11:15 +00:00
|
|
|
if (dev->mode_config.num_crtc) {
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "resuming display...\n");
|
2014-10-02 03:22:27 +00:00
|
|
|
nouveau_display_resume(dev, runtime);
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "resuming console...\n");
|
2014-10-02 03:22:27 +00:00
|
|
|
nouveau_fbcon_set_suspend(dev, 0);
|
2012-10-31 02:11:15 +00:00
|
|
|
}
|
2012-09-10 04:20:51 +00:00
|
|
|
|
2016-08-25 00:57:07 +00:00
|
|
|
nouveau_led_resume(dev);
|
2018-07-26 21:59:13 +00:00
|
|
|
nouveau_dmem_resume(drm);
|
2018-07-05 02:57:12 +00:00
|
|
|
nouveau_svm_resume(drm);
|
2012-07-31 06:16:21 +00:00
|
|
|
return 0;
|
2012-07-06 02:14:00 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 03:31:00 +00:00
|
|
|
int
|
|
|
|
nouveau_pmops_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
|
|
|
|
drm_dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = nouveau_do_suspend(drm_dev, false);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pci_save_state(pdev);
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
pci_set_power_state(pdev, PCI_D3hot);
|
2015-04-19 15:18:01 +00:00
|
|
|
udelay(200);
|
2014-10-02 03:31:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_pmops_resume(struct device *dev)
|
2012-11-02 01:04:28 +00:00
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
|
|
|
int ret;
|
|
|
|
|
2012-09-10 04:20:51 +00:00
|
|
|
if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
|
|
|
|
drm_dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF)
|
2012-11-02 01:04:28 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
pci_set_power_state(pdev, PCI_D0);
|
|
|
|
pci_restore_state(pdev);
|
|
|
|
ret = pci_enable_device(pdev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
pci_set_master(pdev);
|
|
|
|
|
2016-11-21 16:50:55 +00:00
|
|
|
ret = nouveau_do_resume(drm_dev, false);
|
|
|
|
|
|
|
|
/* Monitors may have been connected / disconnected during suspend */
|
|
|
|
schedule_work(&nouveau_drm(drm_dev)->hpd_work);
|
|
|
|
|
|
|
|
return ret;
|
2012-11-02 01:04:28 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 03:31:00 +00:00
|
|
|
static int
|
|
|
|
nouveau_pmops_freeze(struct device *dev)
|
2012-11-02 01:04:28 +00:00
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
2014-10-02 03:22:27 +00:00
|
|
|
return nouveau_do_suspend(drm_dev, false);
|
2012-11-02 01:04:28 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 03:31:00 +00:00
|
|
|
static int
|
|
|
|
nouveau_pmops_thaw(struct device *dev)
|
2012-11-02 01:04:28 +00:00
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
2014-10-02 03:22:27 +00:00
|
|
|
return nouveau_do_resume(drm_dev, false);
|
2012-11-02 01:04:28 +00:00
|
|
|
}
|
|
|
|
|
2017-06-02 04:38:07 +00:00
|
|
|
bool
|
2017-06-09 10:38:33 +00:00
|
|
|
nouveau_pmops_runtime(void)
|
2017-06-02 04:38:07 +00:00
|
|
|
{
|
|
|
|
if (nouveau_runtime_pm == -1)
|
|
|
|
return nouveau_is_optimus() || nouveau_is_v1_dsm();
|
|
|
|
return nouveau_runtime_pm == 1;
|
|
|
|
}
|
|
|
|
|
2014-10-02 03:31:00 +00:00
|
|
|
static int
|
|
|
|
nouveau_pmops_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
|
|
|
int ret;
|
|
|
|
|
2017-06-02 04:38:07 +00:00
|
|
|
if (!nouveau_pmops_runtime()) {
|
2014-10-02 03:31:00 +00:00
|
|
|
pm_runtime_forbid(dev);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nouveau_switcheroo_optimus_dsm();
|
|
|
|
ret = nouveau_do_suspend(drm_dev, true);
|
|
|
|
pci_save_state(pdev);
|
|
|
|
pci_disable_device(pdev);
|
2014-12-08 00:33:52 +00:00
|
|
|
pci_ignore_hotplug(pdev);
|
2014-10-02 03:31:00 +00:00
|
|
|
pci_set_power_state(pdev, PCI_D3cold);
|
|
|
|
drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nouveau_pmops_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
|
|
|
struct drm_device *drm_dev = pci_get_drvdata(pdev);
|
2019-03-28 13:17:31 +00:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(drm_dev);
|
2016-05-18 03:57:42 +00:00
|
|
|
struct nvif_device *device = &nouveau_drm(drm_dev)->client.device;
|
2014-10-02 03:31:00 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-06-02 04:38:07 +00:00
|
|
|
if (!nouveau_pmops_runtime()) {
|
|
|
|
pm_runtime_forbid(dev);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2014-10-02 03:31:00 +00:00
|
|
|
|
|
|
|
pci_set_power_state(pdev, PCI_D0);
|
|
|
|
pci_restore_state(pdev);
|
|
|
|
ret = pci_enable_device(pdev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
pci_set_master(pdev);
|
|
|
|
|
|
|
|
ret = nouveau_do_resume(drm_dev, true);
|
2019-03-28 13:17:31 +00:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(drm, "resume failed with: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-01-12 02:25:23 +00:00
|
|
|
|
2014-10-02 03:31:00 +00:00
|
|
|
/* do magic */
|
2015-08-20 04:54:15 +00:00
|
|
|
nvif_mask(&device->object, 0x088488, (1 << 25), (1 << 25));
|
2014-10-02 03:31:00 +00:00
|
|
|
drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
|
2016-11-21 16:50:55 +00:00
|
|
|
|
|
|
|
/* Monitors may have been connected / disconnected during suspend */
|
|
|
|
schedule_work(&nouveau_drm(drm_dev)->hpd_work);
|
|
|
|
|
2014-10-02 03:31:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nouveau_pmops_runtime_idle(struct device *dev)
|
|
|
|
{
|
2017-06-02 04:38:07 +00:00
|
|
|
if (!nouveau_pmops_runtime()) {
|
2014-10-02 03:31:00 +00:00
|
|
|
pm_runtime_forbid(dev);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
pm_runtime_autosuspend(dev);
|
|
|
|
/* we don't want the main rpm_idle to call suspend - we want to autosuspend */
|
|
|
|
return 1;
|
|
|
|
}
|
2012-11-02 01:04:28 +00:00
|
|
|
|
2012-08-19 21:00:00 +00:00
|
|
|
static int
|
2012-07-19 22:17:34 +00:00
|
|
|
nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
|
|
|
|
{
|
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
|
|
|
struct nouveau_cli *cli;
|
2012-12-09 14:45:21 +00:00
|
|
|
char name[32], tmpname[TASK_COMM_LEN];
|
2012-07-19 22:17:34 +00:00
|
|
|
int ret;
|
|
|
|
|
2012-09-10 04:20:51 +00:00
|
|
|
/* need to bring up power immediately if opening device */
|
|
|
|
ret = pm_runtime_get_sync(dev->dev);
|
2020-06-14 01:41:56 +00:00
|
|
|
if (ret < 0 && ret != -EACCES) {
|
|
|
|
pm_runtime_put_autosuspend(dev->dev);
|
2012-09-10 04:20:51 +00:00
|
|
|
return ret;
|
2020-06-14 01:41:56 +00:00
|
|
|
}
|
2012-09-10 04:20:51 +00:00
|
|
|
|
2012-12-09 14:45:21 +00:00
|
|
|
get_task_comm(tmpname, current);
|
|
|
|
snprintf(name, sizeof(name), "%s[%d]", tmpname, pid_nr(fpriv->pid));
|
2012-09-12 03:09:23 +00:00
|
|
|
|
2018-07-12 17:02:52 +00:00
|
|
|
if (!(cli = kzalloc(sizeof(*cli), GFP_KERNEL))) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto done;
|
|
|
|
}
|
2014-02-17 06:17:26 +00:00
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
ret = nouveau_cli_init(drm, name, cli);
|
2012-07-19 22:17:34 +00:00
|
|
|
if (ret)
|
2016-05-18 03:36:34 +00:00
|
|
|
goto done;
|
2012-07-19 22:17:34 +00:00
|
|
|
|
2014-08-09 18:10:22 +00:00
|
|
|
cli->base.super = false;
|
|
|
|
|
2012-07-19 22:17:34 +00:00
|
|
|
fpriv->driver_priv = cli;
|
|
|
|
|
|
|
|
mutex_lock(&drm->client.mutex);
|
|
|
|
list_add(&cli->head, &drm->clients);
|
|
|
|
mutex_unlock(&drm->client.mutex);
|
2012-09-10 04:20:51 +00:00
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
done:
|
|
|
|
if (ret && cli) {
|
|
|
|
nouveau_cli_fini(cli);
|
|
|
|
kfree(cli);
|
|
|
|
}
|
|
|
|
|
2012-09-10 04:20:51 +00:00
|
|
|
pm_runtime_mark_last_busy(dev->dev);
|
|
|
|
pm_runtime_put_autosuspend(dev->dev);
|
|
|
|
return ret;
|
2012-07-19 22:17:34 +00:00
|
|
|
}
|
|
|
|
|
2012-08-19 21:00:00 +00:00
|
|
|
static void
|
2017-05-08 08:26:30 +00:00
|
|
|
nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv)
|
2012-07-19 22:17:34 +00:00
|
|
|
{
|
|
|
|
struct nouveau_cli *cli = nouveau_cli(fpriv);
|
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
|
|
|
|
2012-09-10 04:20:51 +00:00
|
|
|
pm_runtime_get_sync(dev->dev);
|
|
|
|
|
2015-07-15 15:18:15 +00:00
|
|
|
mutex_lock(&cli->mutex);
|
2012-07-19 22:17:34 +00:00
|
|
|
if (cli->abi16)
|
|
|
|
nouveau_abi16_fini(cli->abi16);
|
2015-07-15 15:18:15 +00:00
|
|
|
mutex_unlock(&cli->mutex);
|
2012-07-19 22:17:34 +00:00
|
|
|
|
|
|
|
mutex_lock(&drm->client.mutex);
|
|
|
|
list_del(&cli->head);
|
|
|
|
mutex_unlock(&drm->client.mutex);
|
2012-09-10 04:20:51 +00:00
|
|
|
|
2016-05-18 03:36:34 +00:00
|
|
|
nouveau_cli_fini(cli);
|
|
|
|
kfree(cli);
|
2012-09-10 04:20:51 +00:00
|
|
|
pm_runtime_mark_last_busy(dev->dev);
|
|
|
|
pm_runtime_put_autosuspend(dev->dev);
|
2012-07-19 22:17:34 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 17:27:49 +00:00
|
|
|
static const struct drm_ioctl_desc
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_ioctls[] = {
|
2019-05-27 08:17:36 +00:00
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_RENDER_ALLOW),
|
2019-05-22 15:02:19 +00:00
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
2019-05-27 08:17:36 +00:00
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_SVM_INIT, nouveau_svmm_init, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_SVM_BIND, nouveau_svmm_bind, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_RENDER_ALLOW),
|
2012-07-31 06:16:21 +00:00
|
|
|
};
|
|
|
|
|
2014-08-09 18:10:31 +00:00
|
|
|
long
|
|
|
|
nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
2012-09-10 04:20:51 +00:00
|
|
|
{
|
2014-08-09 18:10:31 +00:00
|
|
|
struct drm_file *filp = file->private_data;
|
|
|
|
struct drm_device *dev = filp->minor->dev;
|
2012-09-10 04:20:51 +00:00
|
|
|
long ret;
|
|
|
|
|
|
|
|
ret = pm_runtime_get_sync(dev->dev);
|
2020-06-14 01:41:56 +00:00
|
|
|
if (ret < 0 && ret != -EACCES) {
|
|
|
|
pm_runtime_put_autosuspend(dev->dev);
|
2012-09-10 04:20:51 +00:00
|
|
|
return ret;
|
2020-06-14 01:41:56 +00:00
|
|
|
}
|
2012-09-10 04:20:51 +00:00
|
|
|
|
2014-08-09 18:10:31 +00:00
|
|
|
switch (_IOC_NR(cmd) - DRM_COMMAND_BASE) {
|
|
|
|
case DRM_NOUVEAU_NVIF:
|
|
|
|
ret = usif_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = drm_ioctl(file, cmd, arg);
|
|
|
|
break;
|
|
|
|
}
|
2012-09-10 04:20:51 +00:00
|
|
|
|
|
|
|
pm_runtime_mark_last_busy(dev->dev);
|
|
|
|
pm_runtime_put_autosuspend(dev->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-08-09 18:10:31 +00:00
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
static const struct file_operations
|
|
|
|
nouveau_driver_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = drm_open,
|
|
|
|
.release = drm_release,
|
2012-09-10 04:20:51 +00:00
|
|
|
.unlocked_ioctl = nouveau_drm_ioctl,
|
2012-07-31 06:16:21 +00:00
|
|
|
.mmap = nouveau_ttm_mmap,
|
|
|
|
.poll = drm_poll,
|
|
|
|
.read = drm_read,
|
|
|
|
#if defined(CONFIG_COMPAT)
|
|
|
|
.compat_ioctl = nouveau_compat_ioctl,
|
|
|
|
#endif
|
|
|
|
.llseek = noop_llseek,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct drm_driver
|
2014-08-29 10:12:43 +00:00
|
|
|
driver_stub = {
|
2012-07-31 06:16:21 +00:00
|
|
|
.driver_features =
|
2019-06-17 15:39:24 +00:00
|
|
|
DRIVER_GEM | DRIVER_MODESET | DRIVER_RENDER
|
2019-04-18 06:45:15 +00:00
|
|
|
#if defined(CONFIG_NOUVEAU_LEGACY_CTX_SUPPORT)
|
|
|
|
| DRIVER_KMS_LEGACY_CONTEXT
|
|
|
|
#endif
|
|
|
|
,
|
2012-07-31 06:16:21 +00:00
|
|
|
|
|
|
|
.open = nouveau_drm_open,
|
|
|
|
.postclose = nouveau_drm_postclose,
|
|
|
|
.lastclose = nouveau_vga_lastclose,
|
|
|
|
|
2013-02-08 20:42:13 +00:00
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
2015-07-30 22:35:42 +00:00
|
|
|
.debugfs_init = nouveau_drm_debugfs_init,
|
2013-02-08 20:42:13 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
.ioctls = nouveau_ioctls,
|
2013-08-02 17:27:49 +00:00
|
|
|
.num_ioctls = ARRAY_SIZE(nouveau_ioctls),
|
2012-07-31 06:16:21 +00:00
|
|
|
.fops = &nouveau_driver_fops,
|
|
|
|
|
|
|
|
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
|
|
|
|
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
|
2013-01-15 20:47:43 +00:00
|
|
|
.gem_prime_pin = nouveau_gem_prime_pin,
|
2013-06-27 11:38:19 +00:00
|
|
|
.gem_prime_unpin = nouveau_gem_prime_unpin,
|
2013-01-15 20:47:43 +00:00
|
|
|
.gem_prime_get_sg_table = nouveau_gem_prime_get_sg_table,
|
|
|
|
.gem_prime_import_sg_table = nouveau_gem_prime_import_sg_table,
|
|
|
|
.gem_prime_vmap = nouveau_gem_prime_vmap,
|
|
|
|
.gem_prime_vunmap = nouveau_gem_prime_vunmap,
|
2012-07-31 06:16:21 +00:00
|
|
|
|
2016-05-30 17:53:00 +00:00
|
|
|
.gem_free_object_unlocked = nouveau_gem_object_del,
|
2012-07-31 06:16:21 +00:00
|
|
|
.gem_open_object = nouveau_gem_object_open,
|
|
|
|
.gem_close_object = nouveau_gem_object_close,
|
|
|
|
|
|
|
|
.dumb_create = nouveau_display_dumb_create,
|
|
|
|
.dumb_map_offset = nouveau_display_dumb_map_offset,
|
|
|
|
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.desc = DRIVER_DESC,
|
|
|
|
#ifdef GIT_REVISION
|
|
|
|
.date = GIT_REVISION,
|
|
|
|
#else
|
|
|
|
.date = DRIVER_DATE,
|
|
|
|
#endif
|
|
|
|
.major = DRIVER_MAJOR,
|
|
|
|
.minor = DRIVER_MINOR,
|
|
|
|
.patchlevel = DRIVER_PATCHLEVEL,
|
|
|
|
};
|
|
|
|
|
2012-07-06 02:14:00 +00:00
|
|
|
static struct pci_device_id
|
|
|
|
nouveau_drm_pci_table[] = {
|
|
|
|
{
|
|
|
|
PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
|
|
|
|
.class = PCI_BASE_CLASS_DISPLAY << 16,
|
|
|
|
.class_mask = 0xff << 16,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID),
|
|
|
|
.class = PCI_BASE_CLASS_DISPLAY << 16,
|
|
|
|
.class_mask = 0xff << 16,
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2014-08-18 20:43:24 +00:00
|
|
|
static void nouveau_display_options(void)
|
|
|
|
{
|
|
|
|
DRM_DEBUG_DRIVER("Loading Nouveau with parameters:\n");
|
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("... tv_disable : %d\n", nouveau_tv_disable);
|
|
|
|
DRM_DEBUG_DRIVER("... ignorelid : %d\n", nouveau_ignorelid);
|
|
|
|
DRM_DEBUG_DRIVER("... duallink : %d\n", nouveau_duallink);
|
|
|
|
DRM_DEBUG_DRIVER("... nofbaccel : %d\n", nouveau_nofbaccel);
|
|
|
|
DRM_DEBUG_DRIVER("... config : %s\n", nouveau_config);
|
|
|
|
DRM_DEBUG_DRIVER("... debug : %s\n", nouveau_debug);
|
|
|
|
DRM_DEBUG_DRIVER("... noaccel : %d\n", nouveau_noaccel);
|
|
|
|
DRM_DEBUG_DRIVER("... modeset : %d\n", nouveau_modeset);
|
|
|
|
DRM_DEBUG_DRIVER("... runpm : %d\n", nouveau_runtime_pm);
|
|
|
|
DRM_DEBUG_DRIVER("... vram_pushbuf : %d\n", nouveau_vram_pushbuf);
|
2016-11-04 01:44:21 +00:00
|
|
|
DRM_DEBUG_DRIVER("... hdmimhz : %d\n", nouveau_hdmimhz);
|
2014-08-18 20:43:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 01:04:28 +00:00
|
|
|
static const struct dev_pm_ops nouveau_pm_ops = {
|
|
|
|
.suspend = nouveau_pmops_suspend,
|
|
|
|
.resume = nouveau_pmops_resume,
|
|
|
|
.freeze = nouveau_pmops_freeze,
|
|
|
|
.thaw = nouveau_pmops_thaw,
|
|
|
|
.poweroff = nouveau_pmops_freeze,
|
|
|
|
.restore = nouveau_pmops_resume,
|
2012-09-10 04:20:51 +00:00
|
|
|
.runtime_suspend = nouveau_pmops_runtime_suspend,
|
|
|
|
.runtime_resume = nouveau_pmops_runtime_resume,
|
|
|
|
.runtime_idle = nouveau_pmops_runtime_idle,
|
2012-11-02 01:04:28 +00:00
|
|
|
};
|
|
|
|
|
2012-07-06 02:14:00 +00:00
|
|
|
static struct pci_driver
|
|
|
|
nouveau_drm_pci_driver = {
|
|
|
|
.name = "nouveau",
|
|
|
|
.id_table = nouveau_drm_pci_table,
|
|
|
|
.probe = nouveau_drm_probe,
|
|
|
|
.remove = nouveau_drm_remove,
|
2012-11-02 01:04:28 +00:00
|
|
|
.driver.pm = &nouveau_pm_ops,
|
2012-07-06 02:14:00 +00:00
|
|
|
};
|
|
|
|
|
2014-06-26 05:33:32 +00:00
|
|
|
struct drm_device *
|
2015-09-04 10:59:31 +00:00
|
|
|
nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
|
|
|
|
struct platform_device *pdev,
|
2015-08-20 04:54:15 +00:00
|
|
|
struct nvkm_device **pdevice)
|
2014-02-17 06:17:26 +00:00
|
|
|
{
|
2014-06-26 05:33:32 +00:00
|
|
|
struct drm_device *drm;
|
|
|
|
int err;
|
2014-02-17 06:17:26 +00:00
|
|
|
|
2015-09-04 10:59:31 +00:00
|
|
|
err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug,
|
2015-08-20 04:54:17 +00:00
|
|
|
true, true, ~0ULL, pdevice);
|
2014-06-26 05:33:32 +00:00
|
|
|
if (err)
|
2015-08-20 04:54:15 +00:00
|
|
|
goto err_free;
|
2014-06-26 05:33:32 +00:00
|
|
|
|
2014-08-29 10:12:43 +00:00
|
|
|
drm = drm_dev_alloc(&driver_platform, &pdev->dev);
|
2016-09-21 14:59:19 +00:00
|
|
|
if (IS_ERR(drm)) {
|
|
|
|
err = PTR_ERR(drm);
|
2014-06-26 05:33:32 +00:00
|
|
|
goto err_free;
|
2014-02-17 06:17:26 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 12:11:51 +00:00
|
|
|
err = nouveau_drm_device_init(drm);
|
|
|
|
if (err)
|
|
|
|
goto err_put;
|
|
|
|
|
2014-06-26 05:33:32 +00:00
|
|
|
platform_set_drvdata(pdev, drm);
|
|
|
|
|
|
|
|
return drm;
|
|
|
|
|
2018-11-23 12:11:51 +00:00
|
|
|
err_put:
|
|
|
|
drm_dev_put(drm);
|
2014-06-26 05:33:32 +00:00
|
|
|
err_free:
|
2015-08-20 04:54:15 +00:00
|
|
|
nvkm_device_del(pdevice);
|
2014-06-26 05:33:32 +00:00
|
|
|
|
|
|
|
return ERR_PTR(err);
|
2014-02-17 06:17:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 02:14:00 +00:00
|
|
|
static int __init
|
|
|
|
nouveau_drm_init(void)
|
|
|
|
{
|
2014-08-29 10:12:43 +00:00
|
|
|
driver_pci = driver_stub;
|
|
|
|
driver_platform = driver_stub;
|
|
|
|
|
2014-08-18 20:43:24 +00:00
|
|
|
nouveau_display_options();
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
if (nouveau_modeset == -1) {
|
|
|
|
if (vgacon_text_force())
|
|
|
|
nouveau_modeset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nouveau_modeset)
|
|
|
|
return 0;
|
|
|
|
|
2015-01-15 06:29:56 +00:00
|
|
|
#ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
|
|
|
|
platform_driver_register(&nouveau_platform_driver);
|
|
|
|
#endif
|
|
|
|
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_register_dsm_handler();
|
drm/nouveau/bl: Assign different names to interfaces
Currently, every backlight interface created by Nouveau uses the same name,
nv_backlight. This leads to a sysfs warning as it tries to create an already
existing folder. This patch adds a incremented number to the name, but keeps
the initial name as nv_backlight, to avoid possibly breaking userspace; the
second interface will be named nv_backlight1, and so on.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=86539
v2:
* Switch to using ida for generating unique IDs, as suggested by Ilia Mirkin;
* Allocate backlight name on the stack, as suggested by Ilia Mirkin;
* Move `nouveau_get_backlight_name()` to avoid forward declaration, as
suggested by Ilia Mirkin;
* Fix reference to bug report formatting, as reported by Nick Tenney.
v3:
* Define a macro for the size of the backlight name, to avoid defining
it multiple times;
* Use snprintf in place of sprintf.
v4:
* Do not create similarly named interfaces when reaching the maximum
amount of unique names, but fail instead, as pointed out by Lukas Wunner
Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2016-12-07 23:57:08 +00:00
|
|
|
nouveau_backlight_ctor();
|
2017-05-24 14:51:40 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
return pci_register_driver(&nouveau_drm_pci_driver);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2012-07-06 02:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit
|
|
|
|
nouveau_drm_exit(void)
|
|
|
|
{
|
2012-07-31 06:16:21 +00:00
|
|
|
if (!nouveau_modeset)
|
|
|
|
return;
|
|
|
|
|
2017-05-24 14:51:40 +00:00
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
pci_unregister_driver(&nouveau_drm_pci_driver);
|
|
|
|
#endif
|
drm/nouveau/bl: Assign different names to interfaces
Currently, every backlight interface created by Nouveau uses the same name,
nv_backlight. This leads to a sysfs warning as it tries to create an already
existing folder. This patch adds a incremented number to the name, but keeps
the initial name as nv_backlight, to avoid possibly breaking userspace; the
second interface will be named nv_backlight1, and so on.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=86539
v2:
* Switch to using ida for generating unique IDs, as suggested by Ilia Mirkin;
* Allocate backlight name on the stack, as suggested by Ilia Mirkin;
* Move `nouveau_get_backlight_name()` to avoid forward declaration, as
suggested by Ilia Mirkin;
* Fix reference to bug report formatting, as reported by Nick Tenney.
v3:
* Define a macro for the size of the backlight name, to avoid defining
it multiple times;
* Use snprintf in place of sprintf.
v4:
* Do not create similarly named interfaces when reaching the maximum
amount of unique names, but fail instead, as pointed out by Lukas Wunner
Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2016-12-07 23:57:08 +00:00
|
|
|
nouveau_backlight_dtor();
|
2012-07-31 06:16:21 +00:00
|
|
|
nouveau_unregister_dsm_handler();
|
2015-01-15 06:29:56 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
|
|
|
|
platform_driver_unregister(&nouveau_platform_driver);
|
|
|
|
#endif
|
2019-08-06 23:15:42 +00:00
|
|
|
if (IS_ENABLED(CONFIG_DRM_NOUVEAU_SVM))
|
|
|
|
mmu_notifier_synchronize();
|
2012-07-06 02:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(nouveau_drm_init);
|
|
|
|
module_exit(nouveau_drm_exit);
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(pci, nouveau_drm_pci_table);
|
2012-07-31 06:16:21 +00:00
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
2012-07-06 02:14:00 +00:00
|
|
|
MODULE_LICENSE("GPL and additional rights");
|