Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a04d0423 authored by Ben Skeggs's avatar Ben Skeggs
Browse files

drm/nouveau/nvif: import library functions for the ioctl/event interfaces



This is a wrapper around the interfaces defined in an earlier commit,
and is also used by various userspace (either by a libdrm backend, or
libpciaccess) tools/tests.

In the future this will be extended to handle channels, replacing some
long-unloved code we currently use, and allow fifo/display/mpeg (hi
Ilia ;)) engines to all be exposed in the same way.

Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 803c1787
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -327,6 +327,12 @@ nouveau-y += core/engine/vp/nv98.o
nouveau-y += core/engine/vp/nvc0.o
nouveau-y += core/engine/vp/nve0.o

# nvif
nouveau-y += nvif/object.o
nouveau-y += nvif/client.o
nouveau-y += nvif/device.o
nouveau-y += nvif/notify.o

# drm/core
nouveau-y += nouveau_drm.o nouveau_chan.o nouveau_dma.o nouveau_fence.o
nouveau-y += nouveau_vga.o nouveau_agp.o
+0 −2
Original line number Diff line number Diff line
@@ -146,9 +146,7 @@ nouveau_handle_create(struct nouveau_object *parent, u32 _parent, u32 _handle,
	}

	hprintk(handle, TRACE, "created\n");

	*phandle = handle;

	return 0;
}

+2 −0
Original line number Diff line number Diff line
#ifndef __NOUVEAU_CLASS_H__
#define __NOUVEAU_CLASS_H__

#include <nvif/class.h>

/* Device class
 *
 * 0080: NV_DEVICE
+130 −0
Original line number Diff line number Diff line
/*
 * Copyright 2013 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs <bskeggs@redhat.com>
 */

#include "client.h"
#include "driver.h"
#include "ioctl.h"

int
nvif_client_ioctl(struct nvif_client *client, void *data, u32 size)
{
	return client->driver->ioctl(client->base.priv, client->super, data, size, NULL);
}

int
nvif_client_suspend(struct nvif_client *client)
{
	return client->driver->suspend(client->base.priv);
}

int
nvif_client_resume(struct nvif_client *client)
{
	return client->driver->resume(client->base.priv);
}

void
nvif_client_fini(struct nvif_client *client)
{
	if (client->driver) {
		client->driver->fini(client->base.priv);
		client->driver = NULL;
		client->base.parent = NULL;
		nvif_object_fini(&client->base);
	}
}

const struct nvif_driver *
nvif_drivers[] = {
#ifdef __KERNEL__
#if 0
	&nvif_driver_nvkm,
#endif
#else
	&nvif_driver_lib,
#endif
	NULL
};

int
nvif_client_init(void (*dtor)(struct nvif_client *), const char *driver,
		 const char *name, u64 device, const char *cfg, const char *dbg,
		 struct nvif_client *client)
{
	int ret, i;

	ret = nvif_object_init(NULL, (void*)dtor, 0, 0, NULL, 0, &client->base);
	if (ret)
		return ret;

	client->base.parent = &client->base;
	client->base.handle = ~0;
	client->object = &client->base;
	client->super = true;

	for (i = 0, ret = -EINVAL; (client->driver = nvif_drivers[i]); i++) {
		if (!driver || !strcmp(client->driver->name, driver)) {
			ret = client->driver->init(name, device, cfg, dbg,
						  &client->base.priv);
			if (!ret || driver)
				break;
		}
	}

	if (ret)
		nvif_client_fini(client);
	return ret;
}

static void
nvif_client_del(struct nvif_client *client)
{
	nvif_client_fini(client);
	kfree(client);
}

int
nvif_client_new(const char *driver, const char *name, u64 device,
		const char *cfg, const char *dbg,
		struct nvif_client **pclient)
{
	struct nvif_client *client = kzalloc(sizeof(*client), GFP_KERNEL);
	if (client) {
		int ret = nvif_client_init(nvif_client_del, driver, name,
					   device, cfg, dbg, client);
		if (ret) {
			kfree(client);
			client = NULL;
		}
		*pclient = client;
		return ret;
	}
	return -ENOMEM;
}

void
nvif_client_ref(struct nvif_client *client, struct nvif_client **pclient)
{
	nvif_object_ref(&client->base, (struct nvif_object **)pclient);
}
+39 −0
Original line number Diff line number Diff line
#ifndef __NVIF_CLIENT_H__
#define __NVIF_CLIENT_H__

#include "object.h"

struct nvif_client {
	struct nvif_object base;
	struct nvif_object *object; /*XXX: hack for nvif_object() */
	const struct nvif_driver *driver;
	bool super;
};

static inline struct nvif_client *
nvif_client(struct nvif_object *object)
{
	while (object && object->parent != object)
		object = object->parent;
	return (void *)object;
}

int  nvif_client_init(void (*dtor)(struct nvif_client *), const char *,
		      const char *, u64, const char *, const char *,
		      struct nvif_client *);
void nvif_client_fini(struct nvif_client *);
int  nvif_client_new(const char *, const char *, u64, const char *,
		     const char *, struct nvif_client **);
void nvif_client_ref(struct nvif_client *, struct nvif_client **);
int  nvif_client_ioctl(struct nvif_client *, void *, u32);
int  nvif_client_suspend(struct nvif_client *);
int  nvif_client_resume(struct nvif_client *);

/*XXX*/
#include <core/client.h>
#define nvkm_client(a) ({ \
	struct nvif_client *_client = nvif_client(nvif_object(a)); \
	nouveau_client(_client->base.priv); \
})

#endif
Loading