[PATCH 4/5] drm: Add support for subclassing struct drm_device
David Herrmann
dh.herrmann at gmail.com
Wed Jan 8 11:01:19 PST 2014
Hi
On Wed, Jan 8, 2014 at 7:31 PM, Damien Lespiau <damien.lespiau at intel.com> wrote:
> Currently, drivers are expected to allocate private data and attach it
> to dev_private in struct drm_device.
>
> This has the unfortunate property to require driver code to juggle
> between the pointer to struct drm_device and dev->dev_private instead of
> using the same pointer if they could embed the device structure.
>
> This patch enables drivers to declare the size of the device structure
> they want DRM core to create for them.
>
> Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
> ---
> drivers/gpu/drm/drm_stub.c | 8 +++++++-
> include/drm/drmP.h | 8 ++++++++
> 2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
> index 98a33c580..161dd9a 100644
> --- a/drivers/gpu/drm/drm_stub.c
> +++ b/drivers/gpu/drm/drm_stub.c
> @@ -433,8 +433,14 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
> {
> struct drm_device *dev;
> int ret;
> + size_t device_struct_size;
>
> - dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> + if (driver->device_struct_size)
> + device_struct_size = driver->device_struct_size;
> + else
> + device_struct_size = sizeof(*dev);
How about a:
WARN_ON(driver->device_struct_size < sizeof(*dev))
> +
> + dev = kzalloc(device_struct_size, GFP_KERNEL);
So the parent structure is expected to have "struct drm_device" at
offset 0? I'd rather like to see a "drm_dev_init()" alongside
drm_dev_alloc() similar to device_initialize().
Thanks
David
> if (!dev)
> return NULL;
>
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index 6800c20..219b153 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -996,6 +996,14 @@ struct drm_driver {
> u32 driver_features;
> /* size of the private data attached to a struct drm_buf */
> int buf_priv_size;
> + /*
> + * DRM drivers can subclass struct drm_device to have their own device
> + * structure to store private data. In this case, they need to declare
> + * the size of the child structure (ie the structure embedding a struct
> + * drm_device as first field) for the DRM core to allocate a big
> + * enough device structure.
> + */
> + size_t device_struct_size;
> const struct drm_ioctl_desc *ioctls;
> int num_ioctls;
> const struct file_operations *fops;
> --
> 1.8.3.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
More information about the dri-devel
mailing list