2012-07-11 15:58:56 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright 2012 Red Hat Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Authors: Ben Skeggs
|
|
|
|
|
*/
|
2014-06-12 22:15:21 +10:00
|
|
|
#include "priv.h"
|
2015-01-14 15:08:21 +10:00
|
|
|
|
2013-08-28 02:00:50 +02:00
|
|
|
#include <core/option.h>
|
2012-07-11 15:58:56 +10:00
|
|
|
|
2015-08-20 14:54:21 +10:00
|
|
|
void
|
2015-08-20 14:54:07 +10:00
|
|
|
nvkm_mc_unk260(struct nvkm_mc *mc, u32 data)
|
2014-06-12 22:15:21 +10:00
|
|
|
{
|
2015-08-20 14:54:21 +10:00
|
|
|
if (mc->func->unk260)
|
|
|
|
|
mc->func->unk260(mc, data);
|
2014-06-12 22:15:21 +10:00
|
|
|
}
|
|
|
|
|
|
2013-11-05 09:09:30 +10:00
|
|
|
static inline u32
|
2015-08-20 14:54:07 +10:00
|
|
|
nvkm_mc_intr_mask(struct nvkm_mc *mc)
|
2013-11-05 09:09:30 +10:00
|
|
|
{
|
2015-08-20 14:54:09 +10:00
|
|
|
struct nvkm_device *device = mc->subdev.device;
|
|
|
|
|
u32 intr = nvkm_rd32(device, 0x000100);
|
2013-11-05 09:09:30 +10:00
|
|
|
if (intr == 0xffffffff) /* likely fallen off the bus */
|
|
|
|
|
intr = 0x00000000;
|
|
|
|
|
return intr;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 10:05:03 +10:00
|
|
|
static irqreturn_t
|
2015-01-14 15:08:21 +10:00
|
|
|
nvkm_mc_intr(int irq, void *arg)
|
2012-07-11 15:58:56 +10:00
|
|
|
{
|
2015-08-20 14:54:07 +10:00
|
|
|
struct nvkm_mc *mc = arg;
|
2015-08-20 14:54:12 +10:00
|
|
|
struct nvkm_subdev *subdev = &mc->subdev;
|
|
|
|
|
struct nvkm_device *device = subdev->device;
|
2015-08-20 14:54:21 +10:00
|
|
|
const struct nvkm_mc_intr *map = mc->func->intr;
|
2015-01-14 15:08:21 +10:00
|
|
|
struct nvkm_subdev *unit;
|
2013-10-11 14:56:39 +10:00
|
|
|
u32 intr;
|
2012-07-11 15:58:56 +10:00
|
|
|
|
2015-08-20 14:54:09 +10:00
|
|
|
nvkm_wr32(device, 0x000140, 0x00000000);
|
|
|
|
|
nvkm_rd32(device, 0x000140);
|
2015-08-20 14:54:07 +10:00
|
|
|
intr = nvkm_mc_intr_mask(mc);
|
|
|
|
|
if (mc->use_msi)
|
2015-08-20 14:54:21 +10:00
|
|
|
mc->func->msi_rearm(mc);
|
2013-10-11 14:56:39 +10:00
|
|
|
|
|
|
|
|
if (intr) {
|
2015-08-20 14:54:07 +10:00
|
|
|
u32 stat = intr = nvkm_mc_intr_mask(mc);
|
2013-10-11 14:41:27 +10:00
|
|
|
while (map->stat) {
|
|
|
|
|
if (intr & map->stat) {
|
2015-08-20 14:54:21 +10:00
|
|
|
unit = nvkm_device_subdev(device, map->unit);
|
2015-08-20 14:54:17 +10:00
|
|
|
if (unit)
|
|
|
|
|
nvkm_subdev_intr(unit);
|
2013-10-11 14:41:27 +10:00
|
|
|
stat &= ~map->stat;
|
|
|
|
|
}
|
|
|
|
|
map++;
|
|
|
|
|
}
|
2013-08-28 02:00:50 +02:00
|
|
|
|
2013-10-11 14:41:27 +10:00
|
|
|
if (stat)
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_error(subdev, "unknown intr %08x\n", stat);
|
2012-07-11 15:58:56 +10:00
|
|
|
}
|
2013-03-22 10:05:03 +10:00
|
|
|
|
2015-08-20 14:54:09 +10:00
|
|
|
nvkm_wr32(device, 0x000140, 0x00000001);
|
2013-10-11 14:41:27 +10:00
|
|
|
return intr ? IRQ_HANDLED : IRQ_NONE;
|
2013-03-22 10:05:03 +10:00
|
|
|
}
|
|
|
|
|
|
2015-08-20 14:54:21 +10:00
|
|
|
static int
|
|
|
|
|
nvkm_mc_fini(struct nvkm_subdev *subdev, bool suspend)
|
2013-03-22 10:05:03 +10:00
|
|
|
{
|
2015-08-20 14:54:21 +10:00
|
|
|
nvkm_wr32(subdev->device, 0x000140, 0x00000000);
|
|
|
|
|
return 0;
|
2013-03-22 10:05:03 +10:00
|
|
|
}
|
|
|
|
|
|
2015-08-20 14:54:21 +10:00
|
|
|
static int
|
|
|
|
|
nvkm_mc_oneinit(struct nvkm_subdev *subdev)
|
|
|
|
|
{
|
|
|
|
|
struct nvkm_mc *mc = nvkm_mc(subdev);
|
|
|
|
|
return request_irq(mc->irq, nvkm_mc_intr, IRQF_SHARED, "nvkm", mc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
nvkm_mc_init(struct nvkm_subdev *subdev)
|
2013-03-22 10:05:03 +10:00
|
|
|
{
|
2015-08-20 14:54:21 +10:00
|
|
|
struct nvkm_mc *mc = nvkm_mc(subdev);
|
2015-08-20 14:54:09 +10:00
|
|
|
struct nvkm_device *device = mc->subdev.device;
|
2015-08-20 14:54:21 +10:00
|
|
|
if (mc->func->init)
|
|
|
|
|
mc->func->init(mc);
|
2015-08-20 14:54:09 +10:00
|
|
|
nvkm_wr32(device, 0x000140, 0x00000001);
|
2013-03-22 10:05:03 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 14:54:21 +10:00
|
|
|
static void *
|
|
|
|
|
nvkm_mc_dtor(struct nvkm_subdev *subdev)
|
2013-03-22 10:05:03 +10:00
|
|
|
{
|
2015-08-20 14:54:21 +10:00
|
|
|
struct nvkm_mc *mc = nvkm_mc(subdev);
|
2015-08-20 14:54:09 +10:00
|
|
|
struct nvkm_device *device = mc->subdev.device;
|
2015-08-20 14:54:07 +10:00
|
|
|
free_irq(mc->irq, mc);
|
|
|
|
|
if (mc->use_msi)
|
2013-08-28 02:00:50 +02:00
|
|
|
pci_disable_msi(device->pdev);
|
2015-08-20 14:54:21 +10:00
|
|
|
return mc;
|
2013-03-22 10:05:03 +10:00
|
|
|
}
|
|
|
|
|
|
2015-08-20 14:54:21 +10:00
|
|
|
static const struct nvkm_subdev_func
|
|
|
|
|
nvkm_mc = {
|
|
|
|
|
.dtor = nvkm_mc_dtor,
|
|
|
|
|
.oneinit = nvkm_mc_oneinit,
|
|
|
|
|
.init = nvkm_mc_init,
|
|
|
|
|
.fini = nvkm_mc_fini,
|
|
|
|
|
};
|
|
|
|
|
|
2013-03-22 10:05:03 +10:00
|
|
|
int
|
2015-08-20 14:54:21 +10:00
|
|
|
nvkm_mc_new_(const struct nvkm_mc_func *func, struct nvkm_device *device,
|
|
|
|
|
int index, struct nvkm_mc **pmc)
|
2013-03-22 10:05:03 +10:00
|
|
|
{
|
2015-08-20 14:54:07 +10:00
|
|
|
struct nvkm_mc *mc;
|
2013-03-22 10:05:03 +10:00
|
|
|
int ret;
|
|
|
|
|
|
2015-08-20 14:54:21 +10:00
|
|
|
if (!(mc = *pmc = kzalloc(sizeof(*mc), GFP_KERNEL)))
|
|
|
|
|
return -ENOMEM;
|
2013-03-22 10:05:03 +10:00
|
|
|
|
2015-08-20 14:54:21 +10:00
|
|
|
nvkm_subdev_ctor(&nvkm_mc, device, index, 0, &mc->subdev);
|
|
|
|
|
mc->func = func;
|
2014-06-12 22:15:21 +10:00
|
|
|
|
2014-12-30 14:59:42 +08:00
|
|
|
if (nv_device_is_pci(device)) {
|
2014-02-17 15:17:26 +09:00
|
|
|
switch (device->pdev->device & 0x0ff0) {
|
|
|
|
|
case 0x00f0:
|
|
|
|
|
case 0x02e0:
|
|
|
|
|
/* BR02? NFI how these would be handled yet exactly */
|
2013-10-22 14:14:33 +10:00
|
|
|
break;
|
2014-02-17 15:17:26 +09:00
|
|
|
default:
|
|
|
|
|
switch (device->chipset) {
|
|
|
|
|
case 0xaa:
|
|
|
|
|
/* reported broken, nv also disable it */
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2015-08-20 14:54:07 +10:00
|
|
|
mc->use_msi = true;
|
2014-02-17 15:17:26 +09:00
|
|
|
break;
|
2014-12-30 14:59:42 +08:00
|
|
|
}
|
2013-10-22 14:14:33 +10:00
|
|
|
}
|
|
|
|
|
|
2015-08-20 14:54:07 +10:00
|
|
|
mc->use_msi = nvkm_boolopt(device->cfgopt, "NvMSI",
|
|
|
|
|
mc->use_msi);
|
2014-02-17 15:17:26 +09:00
|
|
|
|
2015-08-20 14:54:21 +10:00
|
|
|
if (mc->use_msi && mc->func->msi_rearm) {
|
2015-08-20 14:54:07 +10:00
|
|
|
mc->use_msi = pci_enable_msi(device->pdev) == 0;
|
|
|
|
|
if (mc->use_msi) {
|
2015-08-20 14:54:12 +10:00
|
|
|
nvkm_debug(&mc->subdev, "MSI enabled\n");
|
2015-08-20 14:54:21 +10:00
|
|
|
mc->func->msi_rearm(mc);
|
2014-02-17 15:17:26 +09:00
|
|
|
}
|
|
|
|
|
} else {
|
2015-08-20 14:54:07 +10:00
|
|
|
mc->use_msi = false;
|
2013-08-28 02:00:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 15:17:26 +09:00
|
|
|
ret = nv_device_get_irq(device, true);
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
return ret;
|
2015-08-20 14:54:07 +10:00
|
|
|
mc->irq = ret;
|
2013-03-22 10:05:03 +10:00
|
|
|
return 0;
|
2012-07-11 15:58:56 +10:00
|
|
|
}
|