diff options
Diffstat (limited to 'drivers/gpu/drm/nouveau/nvkm/subdev/mc/base.c')
-rw-r--r-- | drivers/gpu/drm/nouveau/nvkm/subdev/mc/base.c | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mc/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mc/base.c index ee4c34f..8d0f5ac 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/mc/base.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mc/base.c @@ -25,12 +25,11 @@ #include <core/option.h> -static inline void +void nvkm_mc_unk260(struct nvkm_mc *mc, u32 data) { - const struct nvkm_mc_oclass *impl = (void *)nv_oclass(mc); - if (impl->unk260) - impl->unk260(mc, data); + if (mc->func->unk260) + mc->func->unk260(mc, data); } static inline u32 @@ -49,8 +48,7 @@ nvkm_mc_intr(int irq, void *arg) struct nvkm_mc *mc = arg; struct nvkm_subdev *subdev = &mc->subdev; struct nvkm_device *device = subdev->device; - const struct nvkm_mc_oclass *oclass = (void *)nv_object(mc)->oclass; - const struct nvkm_mc_intr *map = oclass->intr; + const struct nvkm_mc_intr *map = mc->func->intr; struct nvkm_subdev *unit; u32 intr; @@ -58,13 +56,13 @@ nvkm_mc_intr(int irq, void *arg) nvkm_rd32(device, 0x000140); intr = nvkm_mc_intr_mask(mc); if (mc->use_msi) - oclass->msi_rearm(mc); + mc->func->msi_rearm(mc); if (intr) { u32 stat = intr = nvkm_mc_intr_mask(mc); while (map->stat) { if (intr & map->stat) { - unit = nvkm_subdev(mc, map->unit); + unit = nvkm_device_subdev(device, map->unit); if (unit) nvkm_subdev_intr(unit); stat &= ~map->stat; @@ -80,54 +78,62 @@ nvkm_mc_intr(int irq, void *arg) return intr ? IRQ_HANDLED : IRQ_NONE; } -int -_nvkm_mc_fini(struct nvkm_object *object, bool suspend) +static int +nvkm_mc_fini(struct nvkm_subdev *subdev, bool suspend) { - struct nvkm_mc *mc = (void *)object; - struct nvkm_device *device = mc->subdev.device; - nvkm_wr32(device, 0x000140, 0x00000000); - return nvkm_subdev_fini_old(&mc->subdev, suspend); + nvkm_wr32(subdev->device, 0x000140, 0x00000000); + return 0; } -int -_nvkm_mc_init(struct nvkm_object *object) +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) { - struct nvkm_mc *mc = (void *)object; + struct nvkm_mc *mc = nvkm_mc(subdev); struct nvkm_device *device = mc->subdev.device; - int ret = nvkm_subdev_init_old(&mc->subdev); - if (ret) - return ret; + if (mc->func->init) + mc->func->init(mc); nvkm_wr32(device, 0x000140, 0x00000001); return 0; } -void -_nvkm_mc_dtor(struct nvkm_object *object) +static void * +nvkm_mc_dtor(struct nvkm_subdev *subdev) { - struct nvkm_mc *mc = (void *)object; + struct nvkm_mc *mc = nvkm_mc(subdev); struct nvkm_device *device = mc->subdev.device; free_irq(mc->irq, mc); if (mc->use_msi) pci_disable_msi(device->pdev); - nvkm_subdev_destroy(&mc->subdev); + return mc; } +static const struct nvkm_subdev_func +nvkm_mc = { + .dtor = nvkm_mc_dtor, + .oneinit = nvkm_mc_oneinit, + .init = nvkm_mc_init, + .fini = nvkm_mc_fini, +}; + int -nvkm_mc_create_(struct nvkm_object *parent, struct nvkm_object *engine, - struct nvkm_oclass *bclass, int length, void **pobject) +nvkm_mc_new_(const struct nvkm_mc_func *func, struct nvkm_device *device, + int index, struct nvkm_mc **pmc) { - const struct nvkm_mc_oclass *oclass = (void *)bclass; - struct nvkm_device *device = (void *)parent; struct nvkm_mc *mc; int ret; - ret = nvkm_subdev_create_(parent, engine, bclass, 0, "PMC", - "master", length, pobject); - mc = *pobject; - if (ret) - return ret; + if (!(mc = *pmc = kzalloc(sizeof(*mc), GFP_KERNEL))) + return -ENOMEM; - mc->unk260 = nvkm_mc_unk260; + nvkm_subdev_ctor(&nvkm_mc, device, index, 0, &mc->subdev); + mc->func = func; if (nv_device_is_pci(device)) { switch (device->pdev->device & 0x0ff0) { @@ -149,11 +155,11 @@ nvkm_mc_create_(struct nvkm_object *parent, struct nvkm_object *engine, mc->use_msi = nvkm_boolopt(device->cfgopt, "NvMSI", mc->use_msi); - if (mc->use_msi && oclass->msi_rearm) { + if (mc->use_msi && mc->func->msi_rearm) { mc->use_msi = pci_enable_msi(device->pdev) == 0; if (mc->use_msi) { nvkm_debug(&mc->subdev, "MSI enabled\n"); - oclass->msi_rearm(mc); + mc->func->msi_rearm(mc); } } else { mc->use_msi = false; @@ -164,10 +170,5 @@ nvkm_mc_create_(struct nvkm_object *parent, struct nvkm_object *engine, if (ret < 0) return ret; mc->irq = ret; - - ret = request_irq(mc->irq, nvkm_mc_intr, IRQF_SHARED, "nvkm", mc); - if (ret < 0) - return ret; - return 0; } |