drivers/gpu/drm/nouveau/nvif/object.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/nouveau/nvif/object.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/nouveau/nvif/object.c
Extension
.c
Size
6854 bytes
Lines
280
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (object->map.size) {
			client->driver->unmap(client, object->map.ptr,
						      object->map.size);
			object->map.size = 0;
		}
		object->map.ptr = NULL;
		nvif_object_unmap_handle(object);
	}
}

int
nvif_object_map(struct nvif_object *object, void *argv, u32 argc)
{
	struct nvif_client *client = object->client;
	u64 handle, length;
	int ret = nvif_object_map_handle(object, argv, argc, &handle, &length);
	if (ret >= 0) {
		if (ret) {
			object->map.ptr = client->driver->map(client,
							      handle,
							      length);
			if (ret = -ENOMEM, object->map.ptr) {
				object->map.size = length;
				return 0;
			}
		} else {
			object->map.ptr = (void *)(unsigned long)handle;
			return 0;
		}
		nvif_object_unmap_handle(object);
	}
	return ret;
}

void
nvif_object_dtor(struct nvif_object *object)
{
	struct {
		struct nvif_ioctl_v0_hdr ioctl;
		struct nvif_ioctl_del del;
	} args = {
		.ioctl.type = NVIF_IOCTL_V0_DEL,
	};

	if (!nvif_object_constructed(object))
		return;

	nvif_object_unmap(object);
	nvif_object_ioctl(object, &args, sizeof(args), NULL);
	object->client = NULL;
}

int
nvif_object_ctor(struct nvif_object *parent, const char *name, u32 handle,
		 s32 oclass, void *data, u32 size, struct nvif_object *object)
{
	struct {
		struct nvif_ioctl_v0_hdr ioctl;
		struct nvif_ioctl_new_v0 new;
	} *args;
	int ret = 0;

	object->client = NULL;
	object->name = name ? name : "nvifObject";
	object->handle = handle;
	object->oclass = oclass;
	object->map.ptr = NULL;
	object->map.size = 0;

	if (parent) {
		u32 args_size;

		if (check_add_overflow(sizeof(*args), size, &args_size)) {
			nvif_object_dtor(object);
			return -ENOMEM;
		}

		args = kmalloc(args_size, GFP_KERNEL);
		if (!args) {
			nvif_object_dtor(object);
			return -ENOMEM;
		}

		object->parent = parent->parent;

		args->ioctl.version = 0;
		args->ioctl.type = NVIF_IOCTL_V0_NEW;
		args->new.version = 0;
		args->new.object = nvif_handle(object);
		args->new.handle = handle;

Annotation

Implementation Notes