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#include <core/object.h>
26#include <core/subdev.h>
27#include <core/device.h>
28#include <core/option.h>
29
30void
31nouveau_subdev_reset(struct nouveau_object *subdev)
32{
33 nv_trace(subdev, "resetting...\n");
34 nv_ofuncs(subdev)->fini(subdev, false);
35 nv_debug(subdev, "reset\n");
36}
37
38int
39nouveau_subdev_init(struct nouveau_subdev *subdev)
40{
41 int ret = nouveau_object_init(&subdev->base);
42 if (ret)
43 return ret;
44
45 nouveau_subdev_reset(&subdev->base);
46 return 0;
47}
48
49int
50_nouveau_subdev_init(struct nouveau_object *object)
51{
52 return nouveau_subdev_init(nv_subdev(object));
53}
54
55int
56nouveau_subdev_fini(struct nouveau_subdev *subdev, bool suspend)
57{
58 if (subdev->unit) {
59 nv_mask(subdev, 0x000200, subdev->unit, 0x00000000);
60 nv_mask(subdev, 0x000200, subdev->unit, subdev->unit);
61 }
62
63 return nouveau_object_fini(&subdev->base, suspend);
64}
65
66int
67_nouveau_subdev_fini(struct nouveau_object *object, bool suspend)
68{
69 return nouveau_subdev_fini(nv_subdev(object), suspend);
70}
71
72void
73nouveau_subdev_destroy(struct nouveau_subdev *subdev)
74{
75 int subidx = nv_hclass(subdev) & 0xff;
76 nv_device(subdev)->subdev[subidx] = NULL;
77 nouveau_object_destroy(&subdev->base);
78}
79
80void
81_nouveau_subdev_dtor(struct nouveau_object *object)
82{
83 nouveau_subdev_destroy(nv_subdev(object));
84}
85
86int
87nouveau_subdev_create_(struct nouveau_object *parent,
88 struct nouveau_object *engine,
89 struct nouveau_oclass *oclass, u32 pclass,
90 const char *subname, const char *sysname,
91 int size, void **pobject)
92{
93 struct nouveau_subdev *subdev;
94 int ret;
95
96 ret = nouveau_object_create_(parent, engine, oclass, pclass |
97 NV_SUBDEV_CLASS, size, pobject);
98 subdev = *pobject;
99 if (ret)
100 return ret;
101
102 __mutex_init(&subdev->mutex, subname, &oclass->lock_class_key);
103 subdev->name = subname;
104
105 if (parent) {
106 struct nouveau_device *device = nv_device(parent);
107 int subidx = nv_hclass(subdev) & 0xff;
108
109 subdev->debug = nouveau_dbgopt(device->dbgopt, subname);
110 subdev->mmio = nv_subdev(device)->mmio;
111 device->subdev[subidx] = *pobject;
112 }
113
114 return 0;
115}
116