1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "priv.h"
25
26#include <core/option.h>
27
28void
29nvkm_mc_unk260(struct nvkm_mc *mc, u32 data)
30{
31 if (mc->func->unk260)
32 mc->func->unk260(mc, data);
33}
34
35void
36nvkm_mc_intr_unarm(struct nvkm_mc *mc)
37{
38 return mc->func->intr_unarm(mc);
39}
40
41void
42nvkm_mc_intr_rearm(struct nvkm_mc *mc)
43{
44 return mc->func->intr_rearm(mc);
45}
46
47static u32
48nvkm_mc_intr_mask(struct nvkm_mc *mc)
49{
50 u32 intr = mc->func->intr_mask(mc);
51 if (WARN_ON_ONCE(intr == 0xffffffff))
52 intr = 0;
53 return intr;
54}
55
56void
57nvkm_mc_intr(struct nvkm_mc *mc, bool *handled)
58{
59 struct nvkm_device *device = mc->subdev.device;
60 struct nvkm_subdev *subdev;
61 const struct nvkm_mc_intr *map = mc->func->intr;
62 u32 stat, intr;
63
64 stat = intr = nvkm_mc_intr_mask(mc);
65 while (map->stat) {
66 if (intr & map->stat) {
67 subdev = nvkm_device_subdev(device, map->unit);
68 if (subdev)
69 nvkm_subdev_intr(subdev);
70 stat &= ~map->stat;
71 }
72 map++;
73 }
74
75 if (stat)
76 nvkm_error(&mc->subdev, "intr %08x\n", stat);
77 *handled = intr != 0;
78}
79
80static int
81nvkm_mc_fini(struct nvkm_subdev *subdev, bool suspend)
82{
83 struct nvkm_mc *mc = nvkm_mc(subdev);
84 nvkm_mc_intr_unarm(mc);
85 return 0;
86}
87
88static int
89nvkm_mc_init(struct nvkm_subdev *subdev)
90{
91 struct nvkm_mc *mc = nvkm_mc(subdev);
92 if (mc->func->init)
93 mc->func->init(mc);
94 nvkm_mc_intr_rearm(mc);
95 return 0;
96}
97
98static void *
99nvkm_mc_dtor(struct nvkm_subdev *subdev)
100{
101 return nvkm_mc(subdev);
102}
103
104static const struct nvkm_subdev_func
105nvkm_mc = {
106 .dtor = nvkm_mc_dtor,
107 .init = nvkm_mc_init,
108 .fini = nvkm_mc_fini,
109};
110
111int
112nvkm_mc_new_(const struct nvkm_mc_func *func, struct nvkm_device *device,
113 int index, struct nvkm_mc **pmc)
114{
115 struct nvkm_mc *mc;
116
117 if (!(mc = *pmc = kzalloc(sizeof(*mc), GFP_KERNEL)))
118 return -ENOMEM;
119
120 nvkm_subdev_ctor(&nvkm_mc, device, index, 0, &mc->subdev);
121 mc->func = func;
122 return 0;
123}
124