NVKM_BUS_PLATFORM,
};
-#define nvkm_device_create(p,t,n,s,c,d,u) \
- nvkm_device_create_((void *)(p), (t), (n), (s), (c), (d), \
- sizeof(**u), (void **)u)
-int nvkm_device_create_(void *, enum nv_bus_type type, u64 name,
- const char *sname, const char *cfg, const char *dbg,
- int, void **);
+int nvkm_device_new(void *, enum nv_bus_type type, u64 name,
+ const char *sname, const char *cfg, const char *dbg,
+ struct nvkm_device **);
+void nvkm_device_del(struct nvkm_device **);
/* device logging */
#define nvdev_printk_(d,l,p,f,a...) do { \
remove_conflicting_framebuffers(aper, "nouveaufb", boot);
kfree(aper);
- ret = nvkm_device_create(pdev, NVKM_BUS_PCI,
- nouveau_pci_name(pdev), pci_name(pdev),
- nouveau_config, nouveau_debug, &device);
+ ret = nvkm_device_new(pdev, NVKM_BUS_PCI, nouveau_pci_name(pdev),
+ pci_name(pdev), nouveau_config, nouveau_debug,
+ &device);
if (ret)
return ret;
ret = drm_get_pci_dev(pdev, pent, &driver_pci);
if (ret) {
- nvkm_object_ref(NULL, (struct nvkm_object **)&device);
+ nvkm_device_del(&device);
return ret;
}
device = client->device;
drm_put_dev(dev);
- nvkm_object_ref(NULL, (struct nvkm_object **)&device);
+ nvkm_device_del(&device);
}
static void
struct drm_device *drm;
int err;
- err = nvkm_device_create(pdev, NVKM_BUS_PLATFORM,
- nouveau_platform_name(pdev),
- dev_name(&pdev->dev), nouveau_config,
- nouveau_debug, pdevice);
+ err = nvkm_device_new(pdev, NVKM_BUS_PLATFORM,
+ nouveau_platform_name(pdev),
+ dev_name(&pdev->dev), nouveau_config,
+ nouveau_debug, pdevice);
if (err)
- return ERR_PTR(err);
+ goto err_free;
drm = drm_dev_alloc(&driver_platform, &pdev->dev);
if (!drm) {
return drm;
err_free:
- nvkm_object_ref(NULL, (struct nvkm_object **)pdevice);
+ nvkm_device_del(pdevice);
return ERR_PTR(err);
}
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
nv_device_resource_start(struct nvkm_device *device, unsigned int bar)
{
nvkm_device_oclass = {
.handle = NV_ENGINE(DEVICE, 0x00),
.ofuncs = &(struct nvkm_ofuncs) {
- .dtor = nvkm_device_dtor,
.init = nvkm_device_init,
.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
-nvkm_device_create_(void *dev, enum nv_bus_type type, u64 name,
- const char *sname, const char *cfg, const char *dbg,
- int length, void **pobject)
+nvkm_device_new(void *dev, enum nv_bus_type type, u64 name,
+ const char *sname, const char *cfg, const char *dbg,
+ struct nvkm_device **pdevice)
{
struct nvkm_device *device;
int ret = -EEXIST;
goto done;
}
- ret = nvkm_engine_create_(NULL, NULL, &nvkm_device_oclass, true,
- "DEVICE", "device", length, pobject);
- device = *pobject;
+ ret = nvkm_engine_create(NULL, NULL, &nvkm_device_oclass, true,
+ "DEVICE", "device", &device);
+ *pdevice = device;
if (ret)
goto done;