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_mc *mc, u32 data)
33 mc->func->unk260(mc, data);
37 nvkm_mc_intr_unarm(struct nvkm_mc *mc)
39 return mc->func->intr_unarm(mc);
43 nvkm_mc_intr_rearm(struct nvkm_mc *mc)
45 return mc->func->intr_rearm(mc);
49 nvkm_mc_intr_mask(struct nvkm_mc *mc)
51 u32 intr = mc->func->intr_mask(mc);
52 if (WARN_ON_ONCE(intr == 0xffffffff))
53 intr = 0; /* likely fallen off the bus */
58 nvkm_mc_intr(struct nvkm_mc *mc, bool *handled)
60 struct nvkm_device *device = mc->subdev.device;
61 struct nvkm_subdev *subdev;
62 const struct nvkm_mc_map *map = mc->func->intr;
63 u32 stat, intr = nvkm_mc_intr_mask(mc);
66 stat = nvkm_top_intr(device->top, intr, &subdevs);
68 enum nvkm_devidx subidx = __ffs64(subdevs);
69 subdev = nvkm_device_subdev(device, subidx);
71 nvkm_subdev_intr(subdev);
72 subdevs &= ~BIT_ULL(subidx);
76 if (intr & map->stat) {
77 subdev = nvkm_device_subdev(device, map->unit);
79 nvkm_subdev_intr(subdev);
86 nvkm_error(&mc->subdev, "intr %08x\n", stat);
91 nvkm_mc_reset_(struct nvkm_mc *mc, enum nvkm_devidx devidx)
93 struct nvkm_device *device = mc->subdev.device;
94 const struct nvkm_mc_map *map;
97 if (!(pmc_enable = nvkm_top_reset(device->top, devidx))) {
98 for (map = mc->func->reset; map && map->stat; map++) {
99 if (map->unit == devidx) {
100 pmc_enable = map->stat;
107 nvkm_mask(device, 0x000200, pmc_enable, 0x00000000);
108 nvkm_mask(device, 0x000200, pmc_enable, pmc_enable);
109 nvkm_rd32(device, 0x000200);
114 nvkm_mc_reset(struct nvkm_mc *mc, enum nvkm_devidx devidx)
117 nvkm_mc_reset_(mc, devidx);
121 nvkm_mc_fini(struct nvkm_subdev *subdev, bool suspend)
123 struct nvkm_mc *mc = nvkm_mc(subdev);
124 nvkm_mc_intr_unarm(mc);
129 nvkm_mc_init(struct nvkm_subdev *subdev)
131 struct nvkm_mc *mc = nvkm_mc(subdev);
134 nvkm_mc_intr_rearm(mc);
139 nvkm_mc_dtor(struct nvkm_subdev *subdev)
141 return nvkm_mc(subdev);
144 static const struct nvkm_subdev_func
146 .dtor = nvkm_mc_dtor,
147 .init = nvkm_mc_init,
148 .fini = nvkm_mc_fini,
152 nvkm_mc_new_(const struct nvkm_mc_func *func, struct nvkm_device *device,
153 int index, struct nvkm_mc **pmc)
157 if (!(mc = *pmc = kzalloc(sizeof(*mc), GFP_KERNEL)))
160 nvkm_subdev_ctor(&nvkm_mc, device, index, &mc->subdev);