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/device.h>
27 #include <core/option.h>
30 nvkm_mc_unk260(struct nvkm_mc *pmc, u32 data)
32 const struct nvkm_mc_oclass *impl = (void *)nv_oclass(pmc);
34 impl->unk260(pmc, data);
38 nvkm_mc_intr_mask(struct nvkm_mc *pmc)
40 u32 intr = nv_rd32(pmc, 0x000100);
41 if (intr == 0xffffffff) /* likely fallen off the bus */
47 nvkm_mc_intr(int irq, void *arg)
49 struct nvkm_mc *pmc = arg;
50 const struct nvkm_mc_oclass *oclass = (void *)nv_object(pmc)->oclass;
51 const struct nvkm_mc_intr *map = oclass->intr;
52 struct nvkm_subdev *unit;
55 nv_wr32(pmc, 0x000140, 0x00000000);
56 nv_rd32(pmc, 0x000140);
57 intr = nvkm_mc_intr_mask(pmc);
59 oclass->msi_rearm(pmc);
62 u32 stat = intr = nvkm_mc_intr_mask(pmc);
64 if (intr & map->stat) {
65 unit = nvkm_subdev(pmc, map->unit);
66 if (unit && unit->intr)
74 nv_error(pmc, "unknown intr 0x%08x\n", stat);
77 nv_wr32(pmc, 0x000140, 0x00000001);
78 return intr ? IRQ_HANDLED : IRQ_NONE;
82 _nvkm_mc_fini(struct nvkm_object *object, bool suspend)
84 struct nvkm_mc *pmc = (void *)object;
85 nv_wr32(pmc, 0x000140, 0x00000000);
86 return nvkm_subdev_fini(&pmc->base, suspend);
90 _nvkm_mc_init(struct nvkm_object *object)
92 struct nvkm_mc *pmc = (void *)object;
93 int ret = nvkm_subdev_init(&pmc->base);
96 nv_wr32(pmc, 0x000140, 0x00000001);
101 _nvkm_mc_dtor(struct nvkm_object *object)
103 struct nvkm_device *device = nv_device(object);
104 struct nvkm_mc *pmc = (void *)object;
105 free_irq(pmc->irq, pmc);
107 pci_disable_msi(device->pdev);
108 nvkm_subdev_destroy(&pmc->base);
112 nvkm_mc_create_(struct nvkm_object *parent, struct nvkm_object *engine,
113 struct nvkm_oclass *bclass, int length, void **pobject)
115 const struct nvkm_mc_oclass *oclass = (void *)bclass;
116 struct nvkm_device *device = nv_device(parent);
120 ret = nvkm_subdev_create_(parent, engine, bclass, 0, "PMC",
121 "master", length, pobject);
126 pmc->unk260 = nvkm_mc_unk260;
128 if (nv_device_is_pci(device)) {
129 switch (device->pdev->device & 0x0ff0) {
132 /* BR02? NFI how these would be handled yet exactly */
135 switch (device->chipset) {
137 /* reported broken, nv also disable it */
145 pmc->use_msi = nvkm_boolopt(device->cfgopt, "NvMSI",
148 if (pmc->use_msi && oclass->msi_rearm) {
149 pmc->use_msi = pci_enable_msi(device->pdev) == 0;
151 nv_info(pmc, "MSI interrupts enabled\n");
152 oclass->msi_rearm(pmc);
155 pmc->use_msi = false;
159 ret = nv_device_get_irq(device, true);
164 ret = request_irq(pmc->irq, nvkm_mc_intr, IRQF_SHARED, "nvkm", pmc);