1 /* 2 * Copyright 2015 Red Hat Inc. 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 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. 21 * 22 * Authors: Ben Skeggs <bskeggs@redhat.com> 23 */ 24 #include <core/tegra.h> 25 #ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER 26 #include "priv.h" 27 28 static struct nvkm_device_tegra * 29 nvkm_device_tegra(struct nvkm_device *device) 30 { 31 return container_of(device, struct nvkm_device_tegra, device); 32 } 33 34 static struct resource * 35 nvkm_device_tegra_resource(struct nvkm_device *device, unsigned bar) 36 { 37 struct nvkm_device_tegra *tdev = nvkm_device_tegra(device); 38 return platform_get_resource(tdev->pdev, IORESOURCE_MEM, bar); 39 } 40 41 static resource_size_t 42 nvkm_device_tegra_resource_addr(struct nvkm_device *device, unsigned bar) 43 { 44 struct resource *res = nvkm_device_tegra_resource(device, bar); 45 return res ? res->start : 0; 46 } 47 48 static resource_size_t 49 nvkm_device_tegra_resource_size(struct nvkm_device *device, unsigned bar) 50 { 51 struct resource *res = nvkm_device_tegra_resource(device, bar); 52 return res ? resource_size(res) : 0; 53 } 54 55 static irqreturn_t 56 nvkm_device_tegra_intr(int irq, void *arg) 57 { 58 struct nvkm_device_tegra *tdev = arg; 59 struct nvkm_mc *mc = tdev->device.mc; 60 bool handled = false; 61 if (likely(mc)) { 62 nvkm_mc_intr_unarm(mc); 63 nvkm_mc_intr(mc, &handled); 64 nvkm_mc_intr_rearm(mc); 65 } 66 return handled ? IRQ_HANDLED : IRQ_NONE; 67 } 68 69 static void 70 nvkm_device_tegra_fini(struct nvkm_device *device, bool suspend) 71 { 72 struct nvkm_device_tegra *tdev = nvkm_device_tegra(device); 73 if (tdev->irq) { 74 free_irq(tdev->irq, tdev); 75 tdev->irq = 0; 76 }; 77 } 78 79 static int 80 nvkm_device_tegra_init(struct nvkm_device *device) 81 { 82 struct nvkm_device_tegra *tdev = nvkm_device_tegra(device); 83 int irq, ret; 84 85 irq = platform_get_irq_byname(tdev->pdev, "stall"); 86 if (irq < 0) 87 return irq; 88 89 ret = request_irq(irq, nvkm_device_tegra_intr, 90 IRQF_SHARED, "nvkm", tdev); 91 if (ret) 92 return ret; 93 94 tdev->irq = irq; 95 return 0; 96 } 97 98 static const struct nvkm_device_func 99 nvkm_device_tegra_func = { 100 .tegra = nvkm_device_tegra, 101 .init = nvkm_device_tegra_init, 102 .fini = nvkm_device_tegra_fini, 103 .resource_addr = nvkm_device_tegra_resource_addr, 104 .resource_size = nvkm_device_tegra_resource_size, 105 }; 106 107 int 108 nvkm_device_tegra_new(struct platform_device *pdev, 109 const char *cfg, const char *dbg, 110 bool detect, bool mmio, u64 subdev_mask, 111 struct nvkm_device **pdevice) 112 { 113 struct nvkm_device_tegra *tdev; 114 115 if (!(tdev = kzalloc(sizeof(*tdev), GFP_KERNEL))) 116 return -ENOMEM; 117 *pdevice = &tdev->device; 118 tdev->pdev = pdev; 119 tdev->irq = -1; 120 121 return nvkm_device_ctor(&nvkm_device_tegra_func, NULL, pdev, 122 NVKM_BUS_PLATFORM, pdev->id, NULL, 123 cfg, dbg, detect, mmio, subdev_mask, 124 &tdev->device); 125 } 126 #else 127 int 128 nvkm_device_tegra_new(struct platform_device *pdev, 129 const char *cfg, const char *dbg, 130 bool detect, bool mmio, u64 subdev_mask, 131 struct nvkm_device **pdevice) 132 { 133 return -ENOSYS; 134 } 135 #endif 136