Commit 20d8a88e authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau: tidy up the client init/fini interfaces

These were a little insane.
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent fc1b0a02
...@@ -111,35 +111,37 @@ nouveau_name(struct drm_device *dev) ...@@ -111,35 +111,37 @@ nouveau_name(struct drm_device *dev)
return nouveau_platform_name(dev->platformdev); return nouveau_platform_name(dev->platformdev);
} }
static void
nouveau_cli_fini(struct nouveau_cli *cli)
{
nvkm_vm_ref(NULL, &nvxx_client(&cli->base)->vm, NULL);
usif_client_fini(cli);
nvif_client_fini(&cli->base);
}
static int static int
nouveau_cli_create(struct drm_device *dev, const char *sname, nouveau_cli_init(struct nouveau_drm *drm, const char *sname,
int size, void **pcli) struct nouveau_cli *cli)
{ {
struct nouveau_cli *cli = *pcli = kzalloc(size, GFP_KERNEL); u64 device = nouveau_name(drm->dev);
int ret; int ret;
if (cli) {
snprintf(cli->name, sizeof(cli->name), "%s", sname);
cli->dev = dev;
ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug, snprintf(cli->name, sizeof(cli->name), "%s", sname);
cli->name, nouveau_name(dev), cli->dev = drm->dev;
&cli->base); mutex_init(&cli->mutex);
if (ret == 0) { usif_client_init(cli);
mutex_init(&cli->mutex);
usif_client_init(cli); ret = nvif_driver_init(NULL, nouveau_config, nouveau_debug,
} cli->name, device, &cli->base);
return ret; if (ret) {
NV_ERROR(drm, "Client allocation failed: %d\n", ret);
goto done;
} }
return -ENOMEM;
}
static void done:
nouveau_cli_destroy(struct nouveau_cli *cli) if (ret)
{ nouveau_cli_fini(cli);
nvkm_vm_ref(NULL, &nvxx_client(&cli->base)->vm, NULL); return ret;
nvif_client_fini(&cli->base);
usif_client_fini(cli);
kfree(cli);
} }
static void static void
...@@ -409,12 +411,15 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags) ...@@ -409,12 +411,15 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags)
struct nouveau_drm *drm; struct nouveau_drm *drm;
int ret; int ret;
ret = nouveau_cli_create(dev, "DRM", sizeof(*drm), (void **)&drm); if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL)))
return -ENOMEM;
dev->dev_private = drm;
drm->dev = dev;
ret = nouveau_cli_init(drm, "DRM", &drm->client);
if (ret) if (ret)
return ret; return ret;
dev->dev_private = drm;
drm->dev = dev;
nvxx_client(&drm->client.base)->debug = nvxx_client(&drm->client.base)->debug =
nvkm_dbgopt(nouveau_debug, "DRM"); nvkm_dbgopt(nouveau_debug, "DRM");
...@@ -500,7 +505,8 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags) ...@@ -500,7 +505,8 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags)
nouveau_vga_fini(drm); nouveau_vga_fini(drm);
fail_device: fail_device:
nvif_device_fini(&drm->device); nvif_device_fini(&drm->device);
nouveau_cli_destroy(&drm->client); nouveau_cli_fini(&drm->client);
kfree(drm);
return ret; return ret;
} }
...@@ -532,7 +538,8 @@ nouveau_drm_unload(struct drm_device *dev) ...@@ -532,7 +538,8 @@ nouveau_drm_unload(struct drm_device *dev)
nvif_device_fini(&drm->device); nvif_device_fini(&drm->device);
if (drm->hdmi_device) if (drm->hdmi_device)
pci_dev_put(drm->hdmi_device); pci_dev_put(drm->hdmi_device);
nouveau_cli_destroy(&drm->client); nouveau_cli_fini(&drm->client);
kfree(drm);
} }
void void
...@@ -843,20 +850,20 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv) ...@@ -843,20 +850,20 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
get_task_comm(tmpname, current); get_task_comm(tmpname, current);
snprintf(name, sizeof(name), "%s[%d]", tmpname, pid_nr(fpriv->pid)); snprintf(name, sizeof(name), "%s[%d]", tmpname, pid_nr(fpriv->pid));
ret = nouveau_cli_create(dev, name, sizeof(*cli), (void **)&cli); if (!(cli = kzalloc(sizeof(*cli), GFP_KERNEL)))
return ret;
ret = nouveau_cli_init(drm, name, cli);
if (ret) if (ret)
goto out_suspend; goto done;
cli->base.super = false; cli->base.super = false;
if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
ret = nvkm_vm_new(nvxx_device(&drm->device), 0, (1ULL << 40), ret = nvkm_vm_new(nvxx_device(&drm->device), 0, (1ULL << 40),
0x1000, NULL, &cli->vm); 0x1000, NULL, &cli->vm);
if (ret) { if (ret)
nouveau_cli_destroy(cli); goto done;
goto out_suspend;
}
nvxx_client(&cli->base)->vm = cli->vm; nvxx_client(&cli->base)->vm = cli->vm;
} }
...@@ -867,10 +874,14 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv) ...@@ -867,10 +874,14 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
list_add(&cli->head, &drm->clients); list_add(&cli->head, &drm->clients);
mutex_unlock(&drm->client.mutex); mutex_unlock(&drm->client.mutex);
out_suspend: done:
if (ret && cli) {
nouveau_cli_fini(cli);
kfree(cli);
}
pm_runtime_mark_last_busy(dev->dev); pm_runtime_mark_last_busy(dev->dev);
pm_runtime_put_autosuspend(dev->dev); pm_runtime_put_autosuspend(dev->dev);
return ret; return ret;
} }
...@@ -897,7 +908,8 @@ static void ...@@ -897,7 +908,8 @@ static void
nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv) nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv)
{ {
struct nouveau_cli *cli = nouveau_cli(fpriv); struct nouveau_cli *cli = nouveau_cli(fpriv);
nouveau_cli_destroy(cli); nouveau_cli_fini(cli);
kfree(cli);
pm_runtime_mark_last_busy(dev->dev); pm_runtime_mark_last_busy(dev->dev);
pm_runtime_put_autosuspend(dev->dev); pm_runtime_put_autosuspend(dev->dev);
} }
......
...@@ -86,14 +86,15 @@ enum nouveau_drm_handle { ...@@ -86,14 +86,15 @@ enum nouveau_drm_handle {
struct nouveau_cli { struct nouveau_cli {
struct nvif_client base; struct nvif_client base;
struct drm_device *dev;
struct mutex mutex;
struct nvkm_vm *vm; /*XXX*/ struct nvkm_vm *vm; /*XXX*/
struct list_head head; struct list_head head;
struct mutex mutex;
void *abi16; void *abi16;
struct list_head objects; struct list_head objects;
struct list_head notifys; struct list_head notifys;
char name[32]; char name[32];
struct drm_device *dev;
}; };
static inline struct nouveau_cli * static inline struct nouveau_cli *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment