2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <core/option.h>
27 #include <subdev/top.h>
30 nvkm_mc_unk260(struct nvkm_device
*device
, u32 data
)
32 struct nvkm_mc
*mc
= device
->mc
;
33 if (likely(mc
) && mc
->func
->unk260
)
34 mc
->func
->unk260(mc
, data
);
38 nvkm_mc_intr_mask(struct nvkm_device
*device
, enum nvkm_devidx devidx
, bool en
)
40 struct nvkm_mc
*mc
= device
->mc
;
41 const struct nvkm_mc_map
*map
;
42 if (likely(mc
) && mc
->func
->intr_mask
) {
43 u32 mask
= nvkm_top_intr_mask(device
, devidx
);
44 for (map
= mc
->func
->intr
; !mask
&& map
->stat
; map
++) {
45 if (map
->unit
== devidx
)
48 mc
->func
->intr_mask(mc
, mask
, en
? mask
: 0);
53 nvkm_mc_intr_unarm(struct nvkm_device
*device
)
55 struct nvkm_mc
*mc
= device
->mc
;
57 mc
->func
->intr_unarm(mc
);
61 nvkm_mc_intr_rearm(struct nvkm_device
*device
)
63 struct nvkm_mc
*mc
= device
->mc
;
65 mc
->func
->intr_rearm(mc
);
69 nvkm_mc_intr_stat(struct nvkm_mc
*mc
)
71 u32 intr
= mc
->func
->intr_stat(mc
);
72 if (WARN_ON_ONCE(intr
== 0xffffffff))
73 intr
= 0; /* likely fallen off the bus */
78 nvkm_mc_intr(struct nvkm_device
*device
, bool *handled
)
80 struct nvkm_mc
*mc
= device
->mc
;
81 struct nvkm_subdev
*subdev
;
82 const struct nvkm_mc_map
*map
;
89 intr
= nvkm_mc_intr_stat(mc
);
90 stat
= nvkm_top_intr(device
, intr
, &subdevs
);
92 enum nvkm_devidx subidx
= __ffs64(subdevs
);
93 subdev
= nvkm_device_subdev(device
, subidx
);
95 nvkm_subdev_intr(subdev
);
96 subdevs
&= ~BIT_ULL(subidx
);
99 for (map
= mc
->func
->intr
; map
->stat
; map
++) {
100 if (intr
& map
->stat
) {
101 subdev
= nvkm_device_subdev(device
, map
->unit
);
103 nvkm_subdev_intr(subdev
);
109 nvkm_error(&mc
->subdev
, "intr %08x\n", stat
);
110 *handled
= intr
!= 0;
112 if (mc
->func
->intr_hack
)
113 mc
->func
->intr_hack(mc
, handled
);
117 nvkm_mc_reset_mask(struct nvkm_device
*device
, bool isauto
,
118 enum nvkm_devidx devidx
)
120 struct nvkm_mc
*mc
= device
->mc
;
121 const struct nvkm_mc_map
*map
;
124 if (!(pmc_enable
= nvkm_top_reset(device
, devidx
))) {
125 for (map
= mc
->func
->reset
; map
&& map
->stat
; map
++) {
126 if (!isauto
|| !map
->noauto
) {
127 if (map
->unit
== devidx
) {
128 pmc_enable
= map
->stat
;
139 nvkm_mc_reset(struct nvkm_device
*device
, enum nvkm_devidx devidx
)
141 u64 pmc_enable
= nvkm_mc_reset_mask(device
, true, devidx
);
143 nvkm_mask(device
, 0x000200, pmc_enable
, 0x00000000);
144 nvkm_mask(device
, 0x000200, pmc_enable
, pmc_enable
);
145 nvkm_rd32(device
, 0x000200);
150 nvkm_mc_disable(struct nvkm_device
*device
, enum nvkm_devidx devidx
)
152 u64 pmc_enable
= nvkm_mc_reset_mask(device
, false, devidx
);
154 nvkm_mask(device
, 0x000200, pmc_enable
, 0x00000000);
158 nvkm_mc_enable(struct nvkm_device
*device
, enum nvkm_devidx devidx
)
160 u64 pmc_enable
= nvkm_mc_reset_mask(device
, false, devidx
);
162 nvkm_mask(device
, 0x000200, pmc_enable
, pmc_enable
);
163 nvkm_rd32(device
, 0x000200);
168 nvkm_mc_enabled(struct nvkm_device
*device
, enum nvkm_devidx devidx
)
170 u64 pmc_enable
= nvkm_mc_reset_mask(device
, false, devidx
);
172 return (pmc_enable
!= 0) &&
173 ((nvkm_rd32(device
, 0x000200) & pmc_enable
) == pmc_enable
);
178 nvkm_mc_fini(struct nvkm_subdev
*subdev
, bool suspend
)
180 nvkm_mc_intr_unarm(subdev
->device
);
185 nvkm_mc_init(struct nvkm_subdev
*subdev
)
187 struct nvkm_mc
*mc
= nvkm_mc(subdev
);
190 nvkm_mc_intr_rearm(subdev
->device
);
195 nvkm_mc_dtor(struct nvkm_subdev
*subdev
)
197 return nvkm_mc(subdev
);
200 static const struct nvkm_subdev_func
202 .dtor
= nvkm_mc_dtor
,
203 .init
= nvkm_mc_init
,
204 .fini
= nvkm_mc_fini
,
208 nvkm_mc_ctor(const struct nvkm_mc_func
*func
, struct nvkm_device
*device
,
209 int index
, struct nvkm_mc
*mc
)
211 nvkm_subdev_ctor(&nvkm_mc
, device
, index
, &mc
->subdev
);
216 nvkm_mc_new_(const struct nvkm_mc_func
*func
, struct nvkm_device
*device
,
217 int index
, struct nvkm_mc
**pmc
)
220 if (!(mc
= *pmc
= kzalloc(sizeof(*mc
), GFP_KERNEL
)))
222 nvkm_mc_ctor(func
, device
, index
, *pmc
);