Commit e781dc8f authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau/device: tidy ctor/dtor interfaces

Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 76ecea5b
...@@ -210,12 +210,10 @@ enum nv_bus_type { ...@@ -210,12 +210,10 @@ enum nv_bus_type {
NVKM_BUS_PLATFORM, NVKM_BUS_PLATFORM,
}; };
#define nvkm_device_create(p,t,n,s,c,d,u) \ int nvkm_device_new(void *, enum nv_bus_type type, u64 name,
nvkm_device_create_((void *)(p), (t), (n), (s), (c), (d), \ const char *sname, const char *cfg, const char *dbg,
sizeof(**u), (void **)u) struct nvkm_device **);
int nvkm_device_create_(void *, enum nv_bus_type type, u64 name, void nvkm_device_del(struct nvkm_device **);
const char *sname, const char *cfg, const char *dbg,
int, void **);
/* device logging */ /* device logging */
#define nvdev_printk_(d,l,p,f,a...) do { \ #define nvdev_printk_(d,l,p,f,a...) do { \
......
...@@ -325,9 +325,9 @@ static int nouveau_drm_probe(struct pci_dev *pdev, ...@@ -325,9 +325,9 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
remove_conflicting_framebuffers(aper, "nouveaufb", boot); remove_conflicting_framebuffers(aper, "nouveaufb", boot);
kfree(aper); kfree(aper);
ret = nvkm_device_create(pdev, NVKM_BUS_PCI, ret = nvkm_device_new(pdev, NVKM_BUS_PCI, nouveau_pci_name(pdev),
nouveau_pci_name(pdev), pci_name(pdev), pci_name(pdev), nouveau_config, nouveau_debug,
nouveau_config, nouveau_debug, &device); &device);
if (ret) if (ret)
return ret; return ret;
...@@ -335,7 +335,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev, ...@@ -335,7 +335,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
ret = drm_get_pci_dev(pdev, pent, &driver_pci); ret = drm_get_pci_dev(pdev, pent, &driver_pci);
if (ret) { if (ret) {
nvkm_object_ref(NULL, (struct nvkm_object **)&device); nvkm_device_del(&device);
return ret; return ret;
} }
...@@ -537,7 +537,7 @@ nouveau_drm_device_remove(struct drm_device *dev) ...@@ -537,7 +537,7 @@ nouveau_drm_device_remove(struct drm_device *dev)
device = client->device; device = client->device;
drm_put_dev(dev); drm_put_dev(dev);
nvkm_object_ref(NULL, (struct nvkm_object **)&device); nvkm_device_del(&device);
} }
static void static void
...@@ -1062,12 +1062,12 @@ nouveau_platform_device_create(struct platform_device *pdev, ...@@ -1062,12 +1062,12 @@ nouveau_platform_device_create(struct platform_device *pdev,
struct drm_device *drm; struct drm_device *drm;
int err; int err;
err = nvkm_device_create(pdev, NVKM_BUS_PLATFORM, err = nvkm_device_new(pdev, NVKM_BUS_PLATFORM,
nouveau_platform_name(pdev), nouveau_platform_name(pdev),
dev_name(&pdev->dev), nouveau_config, dev_name(&pdev->dev), nouveau_config,
nouveau_debug, pdevice); nouveau_debug, pdevice);
if (err) if (err)
return ERR_PTR(err); goto err_free;
drm = drm_dev_alloc(&driver_platform, &pdev->dev); drm = drm_dev_alloc(&driver_platform, &pdev->dev);
if (!drm) { if (!drm) {
...@@ -1085,7 +1085,7 @@ nouveau_platform_device_create(struct platform_device *pdev, ...@@ -1085,7 +1085,7 @@ nouveau_platform_device_create(struct platform_device *pdev,
return drm; return drm;
err_free: err_free:
nvkm_object_ref(NULL, (struct nvkm_object **)pdevice); nvkm_device_del(pdevice);
return ERR_PTR(err); return ERR_PTR(err);
} }
......
...@@ -666,23 +666,6 @@ nvkm_device_init(struct nvkm_object *object) ...@@ -666,23 +666,6 @@ nvkm_device_init(struct nvkm_object *object)
return ret; return ret;
} }
static void
nvkm_device_dtor(struct nvkm_object *object)
{
struct nvkm_device *device = (void *)object;
nvkm_event_fini(&device->event);
mutex_lock(&nv_devices_mutex);
list_del(&device->head);
mutex_unlock(&nv_devices_mutex);
if (device->pri)
iounmap(device->pri);
nvkm_engine_destroy(&device->engine);
}
resource_size_t resource_size_t
nv_device_resource_start(struct nvkm_device *device, unsigned int bar) nv_device_resource_start(struct nvkm_device *device, unsigned int bar)
{ {
...@@ -728,16 +711,34 @@ static struct nvkm_oclass ...@@ -728,16 +711,34 @@ static struct nvkm_oclass
nvkm_device_oclass = { nvkm_device_oclass = {
.handle = NV_ENGINE(DEVICE, 0x00), .handle = NV_ENGINE(DEVICE, 0x00),
.ofuncs = &(struct nvkm_ofuncs) { .ofuncs = &(struct nvkm_ofuncs) {
.dtor = nvkm_device_dtor,
.init = nvkm_device_init, .init = nvkm_device_init,
.fini = nvkm_device_fini, .fini = nvkm_device_fini,
}, },
}; };
void
nvkm_device_del(struct nvkm_device **pdevice)
{
struct nvkm_device *device = *pdevice;
if (device) {
nvkm_event_fini(&device->event);
mutex_lock(&nv_devices_mutex);
list_del(&device->head);
mutex_unlock(&nv_devices_mutex);
if (device->pri)
iounmap(device->pri);
nvkm_engine_destroy(&device->engine);
*pdevice = NULL;
}
}
int int
nvkm_device_create_(void *dev, enum nv_bus_type type, u64 name, nvkm_device_new(void *dev, enum nv_bus_type type, u64 name,
const char *sname, const char *cfg, const char *dbg, const char *sname, const char *cfg, const char *dbg,
int length, void **pobject) struct nvkm_device **pdevice)
{ {
struct nvkm_device *device; struct nvkm_device *device;
int ret = -EEXIST; int ret = -EEXIST;
...@@ -748,9 +749,9 @@ nvkm_device_create_(void *dev, enum nv_bus_type type, u64 name, ...@@ -748,9 +749,9 @@ nvkm_device_create_(void *dev, enum nv_bus_type type, u64 name,
goto done; goto done;
} }
ret = nvkm_engine_create_(NULL, NULL, &nvkm_device_oclass, true, ret = nvkm_engine_create(NULL, NULL, &nvkm_device_oclass, true,
"DEVICE", "device", length, pobject); "DEVICE", "device", &device);
device = *pobject; *pdevice = device;
if (ret) if (ret)
goto done; goto done;
......
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