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>
|
2014-08-09 18:10:23 +00:00
|
|
|
|
2017-04-24 04:50:29 +00:00
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/drm_crtc_helper.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
|
|
|
#include <nvif/if0004.h>
|
|
|
|
|
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"
|
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);
|
2017-10-31 17:56:19 +00:00
|
|
|
nouveau_vmm_fini(&cli->vmm);
|
2017-10-31 17:56:19 +00:00
|
|
|
nvif_mmu_fini(&cli->mmu);
|
2016-05-18 03:57:42 +00:00
|
|
|
nvif_device_fini(&cli->device);
|
2017-10-31 17:56:19 +00:00
|
|
|
mutex_lock(&cli->drm->master.lock);
|
2016-05-18 03:36:34 +00:00
|
|
|
nvif_client_fini(&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);
|
|
|
|
ret = nvif_client_init(&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
|
|
|
|
2016-05-18 03:57:42 +00:00
|
|
|
ret = nvif_device_init(&cli->base.object, 0, NV_DEVICE,
|
|
|
|
&(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = nvif_mmu_init(&cli->device.object, mmus[ret].oclass, &cli->mmu);
|
|
|
|
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
|
|
|
|
nouveau_accel_fini(struct nouveau_drm *drm)
|
|
|
|
{
|
2015-08-20 04:54:22 +00:00
|
|
|
nouveau_channel_idle(drm->channel);
|
2014-08-09 18:10:22 +00:00
|
|
|
nvif_object_fini(&drm->ntfy);
|
2015-08-20 04:54:17 +00:00
|
|
|
nvkm_gpuobj_del(&drm->notify);
|
2015-08-20 04:54:22 +00:00
|
|
|
nvif_notify_fini(&drm->flip);
|
2014-08-09 18:10:22 +00:00
|
|
|
nvif_object_fini(&drm->nvsw);
|
2015-08-20 04:54:22 +00:00
|
|
|
nouveau_channel_del(&drm->channel);
|
|
|
|
|
|
|
|
nouveau_channel_idle(drm->cechan);
|
2014-08-09 18:10:22 +00:00
|
|
|
nvif_object_fini(&drm->ttm.copy);
|
2015-08-20 04:54:22 +00:00
|
|
|
nouveau_channel_del(&drm->cechan);
|
|
|
|
|
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;
|
2012-08-06 09:38:25 +00:00
|
|
|
u32 arg0, arg1;
|
2015-08-20 04:54:16 +00:00
|
|
|
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;
|
|
|
|
|
2018-05-08 10:39:46 +00:00
|
|
|
ret = nouveau_channels_init(drm);
|
|
|
|
if (ret)
|
|
|
|
return;
|
|
|
|
|
2018-05-08 10:39:48 +00:00
|
|
|
if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_VOLTA) {
|
|
|
|
ret = nvif_user_init(device);
|
|
|
|
if (ret)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-19 22:17:34 +00:00
|
|
|
/* initialise synchronisation routines */
|
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:
|
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;
|
|
|
|
}
|
|
|
|
|
2014-08-09 18:10:22 +00:00
|
|
|
if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
|
2016-05-18 03:57:42 +00:00
|
|
|
ret = nouveau_channel_new(drm, &drm->client.device,
|
2018-05-08 10:39:46 +00:00
|
|
|
nvif_fifo_runlist_ce(device), 0,
|
|
|
|
&drm->cechan);
|
2012-08-06 09:38:25 +00:00
|
|
|
if (ret)
|
|
|
|
NV_ERROR(drm, "failed to create ce channel, %d\n", ret);
|
|
|
|
|
2018-05-08 10:39:46 +00:00
|
|
|
arg0 = nvif_fifo_runlist(device, NV_DEVICE_INFO_ENGINE_GR);
|
2012-11-22 03:43:55 +00:00
|
|
|
arg1 = 1;
|
2013-07-09 04:20:15 +00:00
|
|
|
} else
|
2014-08-09 18:10:22 +00:00
|
|
|
if (device->info.chipset >= 0xa3 &&
|
|
|
|
device->info.chipset != 0xaa &&
|
|
|
|
device->info.chipset != 0xac) {
|
2016-05-18 03:57:42 +00:00
|
|
|
ret = nouveau_channel_new(drm, &drm->client.device,
|
2014-08-09 18:10:22 +00:00
|
|
|
NvDmaFB, NvDmaTT, &drm->cechan);
|
2013-07-09 04:20:15 +00:00
|
|
|
if (ret)
|
|
|
|
NV_ERROR(drm, "failed to create ce channel, %d\n", ret);
|
|
|
|
|
|
|
|
arg0 = NvDmaFB;
|
|
|
|
arg1 = NvDmaTT;
|
2012-08-06 09:38:25 +00:00
|
|
|
} else {
|
|
|
|
arg0 = NvDmaFB;
|
|
|
|
arg1 = NvDmaTT;
|
|
|
|
}
|
|
|
|
|
2016-05-18 03:57:42 +00:00
|
|
|
ret = nouveau_channel_new(drm, &drm->client.device,
|
|
|
|
arg0, arg1, &drm->channel);
|
2012-07-19 22:17:34 +00:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(drm, "failed to create kernel channel, %d\n", ret);
|
|
|
|
nouveau_accel_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-08 10:39:47 +00:00
|
|
|
if (device->info.family < NV_DEVICE_INFO_V0_TESLA) {
|
|
|
|
ret = nvif_object_init(&drm->channel->user, NVDRM_NVSW,
|
|
|
|
nouveau_abi16_swclass(drm), NULL, 0,
|
|
|
|
&drm->nvsw);
|
2013-11-13 00:58:51 +00:00
|
|
|
if (ret == 0) {
|
2018-05-08 10:39:47 +00:00
|
|
|
ret = RING_SPACE(drm->channel, 2);
|
|
|
|
if (ret == 0) {
|
2013-11-13 00:58:51 +00:00
|
|
|
BEGIN_NV04(drm->channel, NvSubSw, 0, 1);
|
2018-05-08 10:39:47 +00:00
|
|
|
OUT_RING (drm->channel, drm->nvsw.handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = nvif_notify_init(&drm->nvsw,
|
|
|
|
nouveau_flip_complete,
|
|
|
|
false, NV04_NVSW_NTFY_UEVENT,
|
|
|
|
NULL, 0, 0, &drm->flip);
|
|
|
|
if (ret == 0)
|
|
|
|
ret = nvif_notify_get(&drm->flip);
|
|
|
|
if (ret) {
|
|
|
|
nouveau_accel_fini(drm);
|
|
|
|
return;
|
2013-11-13 00:58:51 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-20 04:54:18 +00:00
|
|
|
|
|
|
|
if (ret) {
|
2018-05-08 10:39:47 +00:00
|
|
|
NV_ERROR(drm, "failed to allocate sw class, %d\n", ret);
|
2015-08-20 04:54:18 +00:00
|
|
|
nouveau_accel_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
2013-11-13 00:58:51 +00:00
|
|
|
}
|
|
|
|
|
2014-08-09 18:10:22 +00:00
|
|
|
if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
|
2016-05-18 03:57:42 +00:00
|
|
|
ret = nvkm_gpuobj_new(nvxx_device(&drm->client.device), 32, 0,
|
|
|
|
false, NULL, &drm->notify);
|
2012-07-19 22:17:34 +00:00
|
|
|
if (ret) {
|
|
|
|
NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
|
|
|
|
nouveau_accel_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-20 04:54:15 +00:00
|
|
|
ret = nvif_object_init(&drm->channel->user, NvNotify0,
|
2014-08-09 18:10:24 +00:00
|
|
|
NV_DMA_IN_MEMORY,
|
|
|
|
&(struct nv_dma_v0) {
|
|
|
|
.target = NV_DMA_V0_TARGET_VRAM,
|
|
|
|
.access = NV_DMA_V0_ACCESS_RDWR,
|
2012-07-19 22:17:34 +00:00
|
|
|
.start = drm->notify->addr,
|
|
|
|
.limit = drm->notify->addr + 31
|
2014-08-09 18:10:24 +00:00
|
|
|
}, sizeof(struct nv_dma_v0),
|
2014-08-09 18:10:22 +00:00
|
|
|
&drm->ntfy);
|
2012-07-19 22:17:34 +00:00
|
|
|
if (ret) {
|
|
|
|
nouveau_accel_fini(drm);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ret = nouveau_display_init(dev);
|
|
|
|
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);
|
2012-07-19 22:17:34 +00:00
|
|
|
nouveau_accel_init(drm);
|
|
|
|
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:
|
|
|
|
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);
|
|
|
|
nouveau_accel_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);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
struct apertures_struct *aper;
|
|
|
|
bool boot = false;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
ret = nvkm_device_pci_new(pdev, NULL, "error", true, false, 0, &device);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
nvkm_device_del(&device);
|
|
|
|
|
|
|
|
/* Remove conflicting drivers (vesafb, efifb etc). */
|
|
|
|
aper = alloc_apertures(3);
|
|
|
|
if (!aper)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
aper->ranges[0].base = pci_resource_start(pdev, 1);
|
|
|
|
aper->ranges[0].size = pci_resource_len(pdev, 1);
|
|
|
|
aper->count = 1;
|
|
|
|
|
|
|
|
if (pci_resource_len(pdev, 2)) {
|
|
|
|
aper->ranges[aper->count].base = pci_resource_start(pdev, 2);
|
|
|
|
aper->ranges[aper->count].size = pci_resource_len(pdev, 2);
|
|
|
|
aper->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pci_resource_len(pdev, 3)) {
|
|
|
|
aper->ranges[aper->count].base = pci_resource_start(pdev, 3);
|
|
|
|
aper->ranges[aper->count].size = pci_resource_len(pdev, 3);
|
|
|
|
aper->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86
|
|
|
|
boot = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
|
|
|
|
#endif
|
|
|
|
if (nouveau_modeset != 2)
|
|
|
|
drm_fb_helper_remove_conflicting_framebuffers(aper, "nouveaufb", boot);
|
|
|
|
kfree(aper);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2018-08-23 01:40:07 +00:00
|
|
|
struct pci_dev *pdev = dev->pdev;
|
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);
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
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);
|
|
|
|
|
|
|
|
nouveau_drm_device_remove(dev);
|
|
|
|
}
|
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;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
|
|
|
|
2017-08-13 22:40:55 +00:00
|
|
|
NV_DEBUG(drm, "resuming object tree...\n");
|
2017-10-31 17:56:19 +00:00
|
|
|
nvif_client_resume(&drm->master.base);
|
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);
|
|
|
|
|
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);
|
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);
|
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);
|
2014-02-12 05:00:59 +00:00
|
|
|
if (ret < 0 && ret != -EACCES)
|
2012-09-10 04:20:51 +00:00
|
|
|
return ret;
|
|
|
|
|
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[] = {
|
2015-09-08 11:56:30 +00:00
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_AUTH|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);
|
2014-02-12 05:00:59 +00:00
|
|
|
if (ret < 0 && ret != -EACCES)
|
2012-09-10 04:20:51 +00:00
|
|
|
return ret;
|
|
|
|
|
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 =
|
2015-06-23 07:18:49 +00:00
|
|
|
DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER |
|
|
|
|
DRIVER_KMS_LEGACY_CONTEXT,
|
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
|
|
|
|
|
2013-10-02 21:02:29 +00:00
|
|
|
.enable_vblank = nouveau_display_vblank_enable,
|
|
|
|
.disable_vblank = nouveau_display_vblank_disable,
|
2013-11-14 03:37:49 +00:00
|
|
|
.get_scanout_position = nouveau_display_scanoutpos,
|
drm/vblank: drop the mode argument from drm_calc_vbltimestamp_from_scanoutpos
If we restrict this helper to only kms drivers (which is the case) we
can look up the correct mode easily ourselves. But it's a bit tricky:
- All legacy drivers look at crtc->hwmode. But that is updated already
at the beginning of the modeset helper, which means when we disable
a pipe. Hence the final timestamps might be a bit off. But since
this is an existing bug I'm not going to change it, but just try to
be bug-for-bug compatible with the current code. This only applies
to radeon&amdgpu.
- i915 tries to get it perfect by updating crtc->hwmode when the pipe
is off (i.e. vblank->enabled = false).
- All other atomic drivers look at crtc->state->adjusted_mode. Those
that look at state->requested_mode simply don't adjust their mode,
so it's the same. That has two problems: Accessing crtc->state from
interrupt handling code is unsafe, and it's updated before we shut
down the pipe. For nonblocking modesets it's even worse.
For atomic drivers try to implement what i915 does. To do that we add
a new hwmode field to the vblank structure, and update it from
drm_calc_timestamping_constants(). For atomic drivers that's called
from the right spot by the helper library already, so all fine. But
for safety let's enforce that.
For legacy driver this function is only called at the end (oh the
fun), which is broken, so again let's not bother and just stay
bug-for-bug compatible.
The benefit is that we can use drm_calc_vbltimestamp_from_scanoutpos
directly to implement ->get_vblank_timestamp in every driver, deleting
a lot of code.
v2: Completely new approach, trying to mimick the i915 solution.
v3: Fixup kerneldoc.
v4: Drop the WARN_ON to check that the vblank is off, atomic helpers
currently unconditionally call this. Recomputing the same stuff should
be harmless.
v5: Fix typos and move misplaced hunks to the right patches (Neil).
v6: Undo hunk movement (kbuild).
Cc: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
Cc: Eric Anholt <eric@anholt.net>
Cc: Rob Clark <robdclark@gmail.com>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Acked-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170509140329.24114-4-daniel.vetter@ffwll.ch
2017-05-09 14:03:28 +00:00
|
|
|
.get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
|
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_export = drm_gem_prime_export,
|
|
|
|
.gem_prime_import = drm_gem_prime_import,
|
|
|
|
.gem_prime_pin = nouveau_gem_prime_pin,
|
2014-07-01 10:57:26 +00:00
|
|
|
.gem_prime_res_obj = nouveau_gem_prime_res_obj,
|
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
|
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");
|