summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nouveau/compote/compote-pfault.c
blob: f46c13fad44d6e3d31765d1ccbdae24132557e13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright 2017 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors: Jérôme Glisse <jglisse@redhat.com>
 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <uapi/drm/compote-uapi.h>
#include "compote.h"

#include <nvif/driver.h>
#include <nvif/class.h>
#include <nvif/clb069.h>

#include "nouveau_ttm.h"
#include "nouveau_usif.h"
#include "nouveau_abi16.h"

struct compote_pfault {
	uint64_t		inst;
	uint64_t		addr;
	uint64_t		time;
	uint32_t		rsvd;
	uint32_t		info;
};

static inline uint32_t compote_pfault_valid(const struct compote_pfault *pfault)
{
	return (pfault->info & 0x80000000) >> 31;
}

static inline uint32_t compote_pfault_gpc(const struct compote_pfault *pfault)
{
	return (pfault->info & 0x1f000000) >> 24;
}

static inline uint32_t compote_pfault_isgpc(const struct compote_pfault *pfault)
{
	return (pfault->info & 0x00100000) >> 20;
}

static inline uint32_t compote_pfault_access(const struct compote_pfault *pfault)
{
	return (pfault->info & 0x00070000) >> 16;
}

static inline uint32_t compote_pfault_client(const struct compote_pfault *pfault)
{
	return (pfault->info & 0x00007f00) >> 8;
}

static inline uint32_t compote_pfault_fault(const struct compote_pfault *pfault)
{
	return (pfault->info & 0x0000001f) >> 0;
}

static inline void compote_file_pfault_read(struct compote_file *cfile,
					    struct compote_pfault *pfault,
					    uint32_t index)
{
	index *= 32;
	pfault->inst = nvif_rd32(&cfile->nvpfault_buffer, index + 0x00);
	pfault->inst |= ((uint64_t)nvif_rd32(&cfile->nvpfault_buffer, index + 0x04)) << 32;
	pfault->addr = nvif_rd32(&cfile->nvpfault_buffer, index + 0x08);
	pfault->addr |= ((uint64_t)nvif_rd32(&cfile->nvpfault_buffer, index + 0x0c)) << 32;
	pfault->time = nvif_rd32(&cfile->nvpfault_buffer, index + 0x10);
	pfault->time |= ((uint64_t)nvif_rd32(&cfile->nvpfault_buffer, index + 0x14)) << 32;
	pfault->rsvd = nvif_rd32(&cfile->nvpfault_buffer, index + 0x18);
	pfault->info = nvif_rd32(&cfile->nvpfault_buffer, index + 0x1c);
}

static int compote_pfault_handler(struct compote_file *cfile,
				  const struct compote_pfault *pfault)
{
	return -EINVAL;
}

static int compote_file_pfault_process(struct nvif_notify *notify)
{
	struct compote_file *cfile;
	struct nvif_device *device;
	uint32_t get, put;

	cfile = container_of(notify, struct compote_file, nvpfault_notifier);
	device = &cfile->nvclient.device;

	get = nvif_rd32(&device->object, 0x002a7c);
	put = nvif_rd32(&device->object, 0x002a80);

	for (; get != put; get++) {
		struct compote_pfault pfault;
		int ret;

		compote_file_pfault_read(cfile, &pfault, get);

		nvif_wr32(&device->object, 0x002a7c, get + 1);
		if (!compote_pfault_valid(&pfault))
			continue;

		nvif_mask(&cfile->nvpfault_buffer, 0x1c, 0x80000000, 0x00000000);

		ret = compote_pfault_handler(cfile, &pfault);
		if (ret) {
			/* Kill threads */
			nvif_wr32(&device->object, 0x100cbc, 0x80000000 | (4 << 3) |
				  (compote_pfault_client(&pfault) << 9) |
				  (compote_pfault_gpc(&pfault) << 15) |
				  (compote_pfault_isgpc(&pfault) << 20));
		} else {
			/* Resume threads */
			nvif_wr32(&device->object, 0x100cbc, 0x80000000 | (1 << 3) |
				  (compote_pfault_client(&pfault) << 9) |
				  (compote_pfault_gpc(&pfault) << 15) |
				  (compote_pfault_isgpc(&pfault) << 20));
		}
	}

	return NVIF_NOTIFY_KEEP;
}

int compote_file_pfault_init(struct compote_file *cfile)
{
	struct nvif_device *device = &cfile->nvclient.device;
	int ret;

	/* Allocate replayable fault buffer. */
	ret = nvif_object_init(&device->object, 0, MAXWELL_FAULT_BUFFER_A,
			       NULL, 0, &cfile->nvpfault_buffer);
	if (ret)
		return ret;
	nvif_object_map(&cfile->nvpfault_buffer);

	/* Request notification of pending replayable faults. */
	ret = nvif_notify_init(&cfile->nvpfault_buffer,
			       compote_file_pfault_process,
			       true, NVB069_VN_NTFY_FAULT,
			       NULL, 0, 0,
			       &cfile->nvpfault_notifier);
	if (ret)
		goto error;
	ret = nvif_notify_get(&cfile->nvpfault_notifier);
	if (ret)
		goto error_get;

	return 0;

error_get:
	nvif_notify_fini(&cfile->nvpfault_notifier);
error:
	nvif_object_fini(&cfile->nvpfault_buffer);
	return ret;
}

void compote_file_pfault_fini(struct compote_file *cfile)
{
	nvif_notify_put(&cfile->nvpfault_notifier);
	nvif_notify_fini(&cfile->nvpfault_notifier);
	nvif_object_fini(&cfile->nvpfault_buffer);
}