#include "priv.h"
#include "conn.h"
#include "head.h"
#include "outp.h"
#include <nvif/class.h>
#include <nvif/if0010.h>
static int
nvkm_udisp_sclass(struct nvkm_object *object, int index, struct nvkm_oclass *sclass)
{
struct nvkm_disp *disp = nvkm_udisp(object);
if (index-- == 0) {
sclass->base = (struct nvkm_sclass) { 0, 0, NVIF_CLASS_CONN };
sclass->ctor = nvkm_uconn_new;
return 0;
}
if (index-- == 0) {
sclass->base = (struct nvkm_sclass) { 0, 0, NVIF_CLASS_OUTP };
sclass->ctor = nvkm_uoutp_new;
return 0;
}
if (index-- == 0) {
sclass->base = (struct nvkm_sclass) { 0, 0, NVIF_CLASS_HEAD };
sclass->ctor = nvkm_uhead_new;
return 0;
}
if (disp->func->user[index].ctor) {
sclass->base = disp->func->user[index].base;
sclass->ctor = disp->func->user[index].ctor;
return 0;
}
return -EINVAL;
}
static void *
nvkm_udisp_dtor(struct nvkm_object *object)
{
struct nvkm_disp *disp = nvkm_udisp(object);
spin_lock(&disp->client.lock);
if (object == &disp->client.object)
disp->client.object.func = NULL;
spin_unlock(&disp->client.lock);
return NULL;
}
static const struct nvkm_object_func
nvkm_udisp = {
.dtor = nvkm_udisp_dtor,
.sclass = nvkm_udisp_sclass,
};
int
nvkm_udisp_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, struct nvkm_object **pobject)
{
struct nvkm_disp *disp = nvkm_disp(oclass->engine);
struct nvkm_conn *conn;
struct nvkm_outp *outp;
struct nvkm_head *head;
union nvif_disp_args *args = argv;
if (argc != sizeof(args->v0) || args->v0.version != 0)
return -ENOSYS;
spin_lock(&disp->client.lock);
if (disp->client.object.func) {
spin_unlock(&disp->client.lock);
return -EBUSY;
}
nvkm_object_ctor(&nvkm_udisp, oclass, &disp->client.object);
*pobject = &disp->client.object;
spin_unlock(&disp->client.lock);
args->v0.conn_mask = 0;
list_for_each_entry(conn, &disp->conns, head)
args->v0.conn_mask |= BIT(conn->index);
args->v0.outp_mask = 0;
list_for_each_entry(outp, &disp->outps, head)
args->v0.outp_mask |= BIT(outp->index);
args->v0.head_mask = 0;
list_for_each_entry(head, &disp->heads, head)
args->v0.head_mask |= BIT(head->id);
return 0;
}