summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nouveau/nvkm/engine/fault/base.c
blob: a970012e84c86c14bfa223f54f067f902bef94d0 (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
/*
 * Copyright 2017 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.
 */
#include "priv.h"
#include "user.h"

#include <core/client.h>
#include <core/notify.h>

static int
nvkm_fault_ntfy_ctor(struct nvkm_object *object, void *data, u32 size,
		     struct nvkm_notify *notify)
{
	if (size == 0) {
		notify->size  = 0;
		notify->types = 1;
		notify->index = 0;
		return 0;
	}
	return -ENOSYS;
}

static const struct nvkm_event_func
nvkm_fault_ntfy = {
	.ctor = nvkm_fault_ntfy_ctor,
};

static int
nvkm_fault_class_new(struct nvkm_device *device,
		     const struct nvkm_oclass *oclass, void *data, u32 size,
		     struct nvkm_object **pobject)
{
	struct nvkm_fault *fault = nvkm_fault(device->fault);
	if (!oclass->client->super)
		return -EACCES;
	return nvkm_ufault_new(fault, oclass, data, size, pobject);
}

static const struct nvkm_device_oclass
nvkm_fault_class = {
	.ctor = nvkm_fault_class_new,
};

static int
nvkm_fault_class_get(struct nvkm_oclass *oclass, int index,
		     const struct nvkm_device_oclass **class)
{
	struct nvkm_fault *fault = nvkm_fault(oclass->engine);
	if (index == 0) {
		oclass->base.oclass = fault->func->oclass;
		oclass->base.minver = -1;
		oclass->base.maxver = -1;
		*class = &nvkm_fault_class;
	}
	return 1;
}

static void
nvkm_fault_intr(struct nvkm_engine *engine)
{
	struct nvkm_fault *fault = nvkm_fault(engine);
	nvkm_event_send(&fault->event, 1, 0, NULL, 0);
}

static void *
nvkm_fault_dtor(struct nvkm_engine *engine)
{
	struct nvkm_fault *fault = nvkm_fault(engine);
	nvkm_event_fini(&fault->event);
	return fault;
}

static const struct nvkm_engine_func
nvkm_fault = {
	.dtor = nvkm_fault_dtor,
	.intr = nvkm_fault_intr,
	.base.sclass = nvkm_fault_class_get,
};

int
nvkm_fault_new_(const struct nvkm_fault_func *func, struct nvkm_device *device,
		int index, struct nvkm_engine **pengine)
{
	struct nvkm_fault *fault;
	int ret;

	if (!(fault = kzalloc(sizeof(*fault), GFP_KERNEL)))
		return -ENOMEM;
	*pengine = &fault->engine;
	fault->func = func;

	ret = nvkm_engine_ctor(&nvkm_fault, device, index, true,
			       &fault->engine);
	if (ret)
		return ret;

	return nvkm_event_init(&nvkm_fault_ntfy, 1, 1, &fault->event);
}