All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: intel-gfx@lists.freedesktop.org,
	laurent.pinchart@ideasonboard.com,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 4/9] drm: Begin an API for in-kernel clients
Date: Mon, 28 May 2018 15:26:48 +0200	[thread overview]
Message-ID: <f6ae662f-a608-9f14-5273-973d6515fdb3@tronnes.org> (raw)
In-Reply-To: <20180524084213.GG3438@phenom.ffwll.local>


Den 24.05.2018 10.42, skrev Daniel Vetter:
> On Wed, May 23, 2018 at 04:34:06PM +0200, Noralf Trønnes wrote:
>> This the beginning of an API for in-kernel clients.
>> First out is a way to get a framebuffer backed by a dumb buffer.
>>
>> Only GEM drivers are supported.
>> The original idea of using an exported dma-buf was dropped because it
>> also creates an anonomous file descriptor which doesn't work when the
>> buffer is created from a kernel thread. The easy way out is to use
>> drm_driver.gem_prime_vmap to get the virtual address, which requires a
>> GEM object. This excludes the vmwgfx driver which is the only non-GEM
>> driver apart from the legacy ones. A solution for vmwgfx will have to be
>> worked out later if it wants to support the client API which it probably
>> will when we have a bootsplash client.
>>
>> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
> A few small nits below, with those addressed:
>
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>> ---

[...]

>> +/**
>> + * drm_client_new - Create a DRM client
>> + * @dev: DRM device
>> + *
>> + * Returns:
>> + * Pointer to a client or an error pointer on failure.
>> + */
>> +struct drm_client_dev *drm_client_new(struct drm_device *dev)
> Api nitpick:
>
> int drm_client_init(struct drm_device *dev,
> 		    struct drm_client_dev *client)
>
> and dropping the kzalloc from this structure here. This allows users of
> this to embed the client struct into their own thing, which means the
> ->private backpointer isn't necessary. Allowing embedding is the preferred
> interface in the kernel (since it's strictly more powerful, you can always
> just kzalloc + _init to get the _new behaviour).
>
>> +{
>> +	struct drm_client_dev *client;
>> +	int ret;
>> +
>> +	if (!drm_core_check_feature(dev, DRIVER_MODESET) ||
>> +	    !dev->driver->dumb_create || !dev->driver->gem_prime_vmap)
>> +		return ERR_PTR(-ENOTSUPP);
>> +
>> +	client = kzalloc(sizeof(*client), GFP_KERNEL);
>> +	if (!client)
>> +		return ERR_PTR(-ENOMEM);
>> +
>> +	client->dev = dev;
>> +
>> +	ret = drm_client_alloc_file(client);
>> +	if (ret) {
>> +		kfree(client);
>> +		return ERR_PTR(ret);
>> +	}
>> +
>> +	return client;
>> +}
>> +EXPORT_SYMBOL(drm_client_new);
>> +

[...]

>> +static struct drm_client_buffer *
>> +drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format)
>> +{
>> +	struct drm_mode_create_dumb dumb_args = { };
>> +	struct drm_device *dev = client->dev;
>> +	struct drm_client_buffer *buffer;
>> +	struct drm_gem_object *obj;
>> +	void *vaddr;
>> +	int ret;
>> +
>> +	buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
>> +	if (!buffer)
>> +		return ERR_PTR(-ENOMEM);
>> +
>> +	buffer->client = client;
>> +
>> +	dumb_args.width = width;
>> +	dumb_args.height = height;
>> +	dumb_args.bpp = drm_format_plane_cpp(format, 0) * 8;
>> +	ret = drm_mode_create_dumb(dev, &dumb_args, client->file);
>> +	if (ret)
>> +		goto err_free;
>> +
>> +	buffer->handle = dumb_args.handle;
>> +	buffer->pitch = dumb_args.pitch;
>> +
>> +	obj = drm_gem_object_lookup(client->file, dumb_args.handle);
>> +	if (!obj)  {
>> +		ret = -ENOENT;
>> +		goto err_delete;
>> +	}
>> +
>> +	buffer->gem = obj;
>> +
> I'm paranoid, I think an
>
> 	if (WARN_ON(!gem_prime_vmap))
> 		return -EINVAL;
>
> would be cool here.

This is already checked in drm_client_init().

Noralf.

> Also perhaps the following comment:
>
> 	/*
> 	 * FIXME: The dependency on GEM here isn't required, we could
> 	 * convert the driver handle to a dma-buf instead and use the
> 	 * backend-agnostic dma-buf vmap support instead. This would
> 	 * require that the handle2fd prime ioctl is reworked to pull the
> 	 * fd_install step out of the driver backend hooks, to make that
> 	 * final step optional for internal users.
> 	 */
>
>
>> +	vaddr = dev->driver->gem_prime_vmap(obj);
>> +	if (!vaddr) {
>> +		ret = -ENOMEM;
>> +		goto err_delete;
>> +	}
>> +
>> +	buffer->vaddr = vaddr;
>> +
>> +	return buffer;
>> +
>> +err_delete:
>> +	drm_client_buffer_delete(buffer);
>> +err_free:
>> +	kfree(buffer);
>> +
>> +	return ERR_PTR(ret);
>> +}


_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2018-05-28 13:26 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-23 14:34 [PATCH 0/9] drm: Add generic fbdev emulation Noralf Trønnes
2018-05-23 14:34 ` [PATCH 1/9] drm: provide management functions for drm_file Noralf Trønnes
2018-05-23 14:34 ` [PATCH 2/9] drm/file: Don't set master on in-kernel clients Noralf Trønnes
2018-05-23 14:34 ` [PATCH 3/9] drm: Make ioctls available for " Noralf Trønnes
2018-05-24  8:22   ` Daniel Vetter
2018-05-23 14:34 ` [PATCH 4/9] drm: Begin an API " Noralf Trønnes
2018-05-23 21:45   ` Thomas Hellstrom
2018-05-24  8:32     ` Daniel Vetter
2018-05-24  9:25       ` Thomas Hellstrom
2018-05-24 10:14         ` Daniel Vetter
2018-05-24 16:51           ` Thomas Hellstrom
2018-05-24  8:42   ` Daniel Vetter
2018-05-28 13:26     ` Noralf Trønnes [this message]
2018-05-29  7:53       ` Daniel Vetter
2018-05-23 14:34 ` [PATCH 5/9] drm/fb-helper: Add generic fbdev emulation .fb_probe function Noralf Trønnes
2018-05-24  9:16   ` Daniel Vetter
2018-05-24 10:16     ` Daniel Vetter
2018-05-25 12:42     ` Noralf Trønnes
2018-05-29  7:54       ` Daniel Vetter
2018-12-28 20:38         ` Daniel Vetter
2019-01-03 17:06           ` Noralf Trønnes
2019-01-07 10:14             ` Daniel Vetter
2018-05-23 14:34 ` [PATCH 6/9] drm/pl111: Set .gem_prime_vmap and .gem_prime_mmap Noralf Trønnes
2018-05-30 19:04   ` Eric Anholt
2018-05-23 14:34 ` [PATCH 7/9] drm/cma-helper: Use the generic fbdev emulation Noralf Trønnes
2018-05-24 10:16   ` Daniel Vetter
2018-05-23 14:34 ` [PATCH 8/9] drm/client: Add client callbacks Noralf Trønnes
2018-05-24  9:52   ` Daniel Vetter
2018-05-23 14:34 ` [PATCH 9/9] drm/fb-helper: Finish the generic fbdev emulation Noralf Trønnes
2018-05-24  9:57   ` Daniel Vetter
2018-05-23 15:20 ` ✗ Fi.CI.CHECKPATCH: warning for drm: Add " Patchwork
2018-05-23 15:38 ` ✓ Fi.CI.BAT: success " Patchwork
2018-05-23 17:31 ` ✗ Fi.CI.IGT: failure " Patchwork
2018-05-24 10:17 ` [PATCH 0/9] " Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f6ae662f-a608-9f14-5273-973d6515fdb3@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.