#include <core/event.h>
enum nvkm_devidx {
- NVDEV_ENGINE_DEVICE,
NVDEV_SUBDEV_VBIOS,
/* All subdevs from DEVINIT to DEVINIT_LAST will be created before
struct nvkm_device {
struct nvkm_engine engine;
+
struct list_head head;
+ struct mutex mutex;
+ int refcount;
struct pci_dev *pdev;
struct platform_device *platformdev;
NVKM_BUS_PLATFORM,
};
+extern struct nvkm_ofuncs nvkm_udevice_ofuncs;
+
int nvkm_device_new(void *, enum nv_bus_type type, u64 name,
const char *sname, const char *cfg, const char *dbg,
bool detect, bool mmio, u64 subdev_mask,
struct nvkm_device **);
void nvkm_device_del(struct nvkm_device **);
+int nvkm_device_init(struct nvkm_device *);
+int nvkm_device_fini(struct nvkm_device *, bool suspend);
/* device logging */
#define nvdev_printk_(d,l,p,f,a...) do { \
}
}
+static struct nvkm_oclass
+nvkm_client_sclass[] = {
+ { NV_DEVICE, &nvkm_udevice_ofuncs },
+ {}
+};
+
int
nvkm_client_new(const char *name, u64 devname, const char *cfg,
const char *dbg, struct nvkm_client **pclient)
return -ENODEV;
ret = nvkm_namedb_create(NULL, NULL, &nvkm_client_oclass,
- NV_CLIENT_CLASS, NULL,
- (1ULL << NVDEV_ENGINE_DEVICE),
- &client);
+ NV_CLIENT_CLASS, nvkm_client_sclass,
+ 0, &client);
*pclient = client;
if (ret)
return ret;
u32 size, u32 align, u32 flags,
struct nvkm_gpuobj **pgpuobj)
{
- struct nvkm_object *engine = parent;
struct nvkm_gpuobj_class args = {
.pargpu = pargpu,
.size = size,
.flags = flags,
};
- if (!nv_iclass(engine, NV_SUBDEV_CLASS))
- engine = &engine->engine->subdev.object;
- BUG_ON(engine == NULL);
-
- return nvkm_object_ctor(parent, engine, &_nvkm_gpuobj_oclass,
- &args, sizeof(args),
+ return nvkm_object_ctor(parent, &parent->engine->subdev.object,
+ &_nvkm_gpuobj_oclass, &args, sizeof(args),
(struct nvkm_object **)pgpuobj);
}
struct nvkm_object *object = nv_object(obj);
while (object && !nv_iclass(object, NV_SUBDEV_CLASS))
object = object->parent;
- if (object == NULL || nv_subidx(nv_subdev(object)) != idx)
+ if (object == NULL || !object->parent || nv_subidx(nv_subdev(object)) != idx)
object = nv_device(obj)->subdev[idx];
return object ? nv_subdev(object) : NULL;
}
return nr;
}
+#include <core/parent.h>
+
struct nvkm_device *
nv_device(void *obj)
{
struct nvkm_object *device = nv_object(obj);
+
if (device->engine == NULL) {
- while (device && device->parent)
+ while (device && device->parent) {
+ if (nv_mclass(device) == 0x0080) {
+ struct {
+ struct nvkm_parent base;
+ struct nvkm_device *device;
+ } *udevice = (void *)device;
+ return udevice->device;
+ }
device = device->parent;
+ }
} else {
device = &nv_object(obj)->engine->subdev.object;
if (device && device->parent)
return (void *)device;
}
-static struct nvkm_oclass
-nvkm_device_sclass[] = {
- { 0x0080, &nvkm_udevice_ofuncs },
- {}
-};
-
static int
nvkm_device_event_ctor(struct nvkm_object *object, void *data, u32 size,
struct nvkm_notify *notify)
.ctor = nvkm_device_event_ctor,
};
-static int
-nvkm_device_fini(struct nvkm_object *object, bool suspend)
+int
+nvkm_device_fini(struct nvkm_device *device, bool suspend)
{
- struct nvkm_device *device = (void *)object;
struct nvkm_object *subdev;
int ret, i;
return ret;
}
-static int
-nvkm_device_init(struct nvkm_object *object)
+int
+nvkm_device_init(struct nvkm_device *device)
{
- struct nvkm_device *device = (void *)object;
struct nvkm_object *subdev;
int ret, i = 0, c;
if (ret)
goto fail;
- for (i = 1, c = 1; i < NVDEV_SUBDEV_NR; i++) {
+ for (i = 0, c = 0; i < NVDEV_SUBDEV_NR; i++) {
#define _(s,m) case s: if (device->oclass[s] && !device->subdev[s]) { \
ret = nvkm_object_ctor(nv_object(device), NULL, \
device->oclass[s], NULL, (s), \
static struct nvkm_oclass
nvkm_device_oclass = {
- .handle = NV_ENGINE(DEVICE, 0x00),
.ofuncs = &(struct nvkm_ofuncs) {
- .init = nvkm_device_init,
- .fini = nvkm_device_fini,
},
};
device->name = sname;
nv_subdev(device)->debug = nvkm_dbgopt(device->dbgopt, "DEVICE");
- nv_engine(device)->sclass = nvkm_device_sclass;
list_add_tail(&device->head, &nv_devices);
ret = nvkm_event_init(&nvkm_device_event_func, 1, 1, &device->event);
device->oclass[i] = NULL;
}
+ atomic_set(&device->engine.subdev.object.usecount, 2);
+ mutex_init(&device->mutex);
done:
mutex_unlock(&nv_devices_mutex);
return ret;
int gf100_identify(struct nvkm_device *);
int gk104_identify(struct nvkm_device *);
int gm100_identify(struct nvkm_device *);
-
-extern struct nvkm_ofuncs nvkm_udevice_ofuncs;
#endif
return 0;
}
+static int
+nvkm_udevice_fini(struct nvkm_object *object, bool suspend)
+{
+ struct nvkm_udevice *udev = (void *)object;
+ struct nvkm_device *device = udev->device;
+ int ret = 0;
+
+ mutex_lock(&device->mutex);
+ if (!--device->refcount) {
+ ret = nvkm_device_fini(device, suspend);
+ if (ret && suspend) {
+ device->refcount++;
+ goto done;
+ }
+ }
+
+done:
+ mutex_unlock(&device->mutex);
+ return ret;
+}
+
+static int
+nvkm_udevice_init(struct nvkm_object *object)
+{
+ struct nvkm_udevice *udev = (void *)object;
+ struct nvkm_device *device = udev->device;
+ int ret = 0;
+
+ mutex_lock(&device->mutex);
+ if (!device->refcount++) {
+ ret = nvkm_device_init(device);
+ if (ret) {
+ device->refcount--;
+ goto done;
+ }
+ }
+
+done:
+ mutex_unlock(&device->mutex);
+ return ret;
+}
+
static struct nvkm_oclass
nvkm_udevice_oclass_super = {
.handle = NV_DEVICE,
.ofuncs = &(struct nvkm_ofuncs) {
.dtor = _nvkm_parent_dtor,
- .init = _nvkm_parent_init,
- .fini = _nvkm_parent_fini,
+ .init = nvkm_udevice_init,
+ .fini = nvkm_udevice_fini,
.mthd = nvkm_udevice_mthd,
.map = nvkm_udevice_map,
.rd08 = nvkm_udevice_rd08,
return -ENODEV;
}
- ret = nvkm_parent_create(parent, nv_object(device), oclass, 0,
- nvkm_control_oclass,
+ ret = nvkm_parent_create(parent, NULL, oclass, 0, nvkm_control_oclass,
(1ULL << NVDEV_ENGINE_DMAOBJ) |
(1ULL << NVDEV_ENGINE_FIFO) |
(1ULL << NVDEV_ENGINE_DISP) |
nvkm_udevice_ofuncs = {
.ctor = nvkm_udevice_ctor,
.dtor = _nvkm_parent_dtor,
- .init = _nvkm_parent_init,
- .fini = _nvkm_parent_fini,
+ .init = nvkm_udevice_init,
+ .fini = nvkm_udevice_fini,
.mthd = nvkm_udevice_mthd,
};
#include "outpdp.h"
#include <core/client.h>
-#include <core/engctx.h>
+#include <core/gpuobj.h>
#include <core/enum.h>
#include <core/handle.h>
#include <core/ramht.h>
struct nvkm_object **pobject)
{
struct nv50_disp *disp = (void *)engine;
- struct nvkm_engctx *ectx;
- int ret = -EBUSY;
+ struct nvkm_gpuobj *gpuobj;
+ int ret;
/* no context needed for channel objects... */
if (nv_mclass(parent) != NV_DEVICE) {
}
/* allocate display hardware to client */
+ ret = nvkm_gpuobj_create(parent, engine, oclass, 0, NULL,
+ 0x10000, 0x10000, NVOBJ_FLAG_HEAP,
+ &gpuobj);
+ *pobject = nv_object(gpuobj);
mutex_lock(&nv_subdev(disp)->mutex);
- if (list_empty(&nv_engine(disp)->contexts)) {
- ret = nvkm_engctx_create(parent, engine, oclass, NULL, 0x10000,
- 0x10000, NVOBJ_FLAG_HEAP, &ectx);
- *pobject = nv_object(ectx);
- }
+ if (!list_empty(&nv_engine(disp)->contexts))
+ ret = -EBUSY;
mutex_unlock(&nv_subdev(disp)->mutex);
return ret;
}
struct nvkm_oclass
nv50_disp_cclass = {
- .handle = NV_ENGCTX(DISP, 0x50),
.ofuncs = &(struct nvkm_ofuncs) {
.ctor = nv50_disp_data_ctor,
- .dtor = _nvkm_engctx_dtor,
- .init = _nvkm_engctx_init,
- .fini = _nvkm_engctx_fini,
- .rd32 = _nvkm_engctx_rd32,
- .wr32 = _nvkm_engctx_wr32,
+ .dtor = _nvkm_gpuobj_dtor,
+ .init = _nvkm_gpuobj_init,
+ .fini = _nvkm_gpuobj_fini,
+ .rd32 = _nvkm_gpuobj_rd32,
+ .wr32 = _nvkm_gpuobj_wr32,
},
};
struct nvkm_perfctx *ctx = (void *)object;
mutex_lock(&nv_subdev(pm)->mutex);
- nvkm_engctx_destroy(&ctx->base);
+ nvkm_gpuobj_destroy(&ctx->base);
if (pm->context == ctx)
pm->context = NULL;
mutex_unlock(&nv_subdev(pm)->mutex);
return 1;
}
- ret = nvkm_engctx_create(parent, engine, oclass, NULL, 0, 0, 0, &ctx);
+ ret = nvkm_gpuobj_create(parent, engine, oclass, 0, NULL, 0, 0, 0, &ctx);
*pobject = nv_object(ctx);
if (ret)
return ret;
struct nvkm_oclass
nvkm_pm_cclass = {
- .handle = NV_ENGCTX(PM, 0x00),
.ofuncs = &(struct nvkm_ofuncs) {
.ctor = nvkm_perfctx_ctor,
.dtor = nvkm_perfctx_dtor,
- .init = _nvkm_engctx_init,
- .fini = _nvkm_engctx_fini,
+ .init = _nvkm_gpuobj_init,
+ .fini = _nvkm_gpuobj_fini,
},
};
extern struct nvkm_oclass nvkm_pm_sclass[];
-#include <core/engctx.h>
+#include <core/gpuobj.h>
struct nvkm_perfctx {
- struct nvkm_engctx base;
+ struct nvkm_gpuobj base;
};
extern struct nvkm_oclass nvkm_pm_cclass;