2 * Copyright 2015 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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
27 #include <core/option.h>
29 #include <subdev/mc.h>
32 nvkm_pci_rd32(struct nvkm_pci *pci, u16 addr)
34 return pci->func->rd32(pci, addr);
38 nvkm_pci_wr08(struct nvkm_pci *pci, u16 addr, u8 data)
40 pci->func->wr08(pci, addr, data);
44 nvkm_pci_wr32(struct nvkm_pci *pci, u16 addr, u32 data)
46 pci->func->wr32(pci, addr, data);
50 nvkm_pci_rom_shadow(struct nvkm_pci *pci, bool shadow)
52 u32 data = nvkm_pci_rd32(pci, 0x0050);
57 nvkm_pci_wr32(pci, 0x0050, data);
61 nvkm_pci_intr(int irq, void *arg)
63 struct nvkm_pci *pci = arg;
64 struct nvkm_mc *mc = pci->subdev.device->mc;
67 nvkm_mc_intr_unarm(mc);
69 pci->func->msi_rearm(pci);
70 nvkm_mc_intr(mc, &handled);
71 nvkm_mc_intr_rearm(mc);
73 return handled ? IRQ_HANDLED : IRQ_NONE;
77 nvkm_pci_fini(struct nvkm_subdev *subdev, bool suspend)
79 struct nvkm_pci *pci = nvkm_pci(subdev);
82 free_irq(pci->irq, pci);
93 nvkm_pci_preinit(struct nvkm_subdev *subdev)
95 struct nvkm_pci *pci = nvkm_pci(subdev);
97 nvkm_agp_preinit(pci);
102 nvkm_pci_init(struct nvkm_subdev *subdev)
104 struct nvkm_pci *pci = nvkm_pci(subdev);
105 struct pci_dev *pdev = pci->pdev;
108 if (pci->agp.bridge) {
109 ret = nvkm_agp_init(pci);
114 ret = request_irq(pdev->irq, nvkm_pci_intr, IRQF_SHARED, "nvkm", pci);
118 pci->irq = pdev->irq;
123 nvkm_pci_dtor(struct nvkm_subdev *subdev)
125 struct nvkm_pci *pci = nvkm_pci(subdev);
128 pci_disable_msi(pci->pdev);
129 return nvkm_pci(subdev);
132 static const struct nvkm_subdev_func
134 .dtor = nvkm_pci_dtor,
135 .preinit = nvkm_pci_preinit,
136 .init = nvkm_pci_init,
137 .fini = nvkm_pci_fini,
141 nvkm_pci_new_(const struct nvkm_pci_func *func, struct nvkm_device *device,
142 int index, struct nvkm_pci **ppci)
144 struct nvkm_pci *pci;
146 if (!(pci = *ppci = kzalloc(sizeof(**ppci), GFP_KERNEL)))
148 nvkm_subdev_ctor(&nvkm_pci_func, device, index, 0, &pci->subdev);
150 pci->pdev = device->func->pci(device)->pdev;
153 if (device->type == NVKM_DEVICE_AGP)
156 switch (pci->pdev->device & 0x0ff0) {
159 /* BR02? NFI how these would be handled yet exactly */
162 switch (device->chipset) {
164 /* reported broken, nv also disable it */
172 pci->msi = nvkm_boolopt(device->cfgopt, "NvMSI", pci->msi);
173 if (pci->msi && func->msi_rearm) {
174 pci->msi = pci_enable_msi(pci->pdev) == 0;
176 nvkm_debug(&pci->subdev, "MSI enabled\n");