Skip to content

Commit e71def0

Browse files
author
Thomas Zimmermann
committed
drm/plane: Allocate planes with drm_universal_plane_alloc()
Provide drm_univeral_plane_alloc() to allocate and initialize a plane. Code for non-atomic drivers uses this pattern. Convert them to the new function. The modeset helpers contain a quirk for handling their color formats differently. Set the flag outside plane allocation. The new function is already deprecated to some extend. Drivers should rather use drmm_univeral_plane_alloc() or drm_universal_plane_init(). v2: * kerneldoc fixes (Javier) * grammar fixes in commit message Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Reviewed-by: Lyude Paul <[email protected]> # nouveau Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 7221941 commit e71def0

File tree

4 files changed

+121
-63
lines changed

4 files changed

+121
-63
lines changed

drivers/gpu/drm/drm_modeset_helper.c

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -113,38 +113,6 @@ static const struct drm_plane_funcs primary_plane_funcs = {
113113
.destroy = drm_plane_helper_destroy,
114114
};
115115

116-
static struct drm_plane *create_primary_plane(struct drm_device *dev)
117-
{
118-
struct drm_plane *primary;
119-
int ret;
120-
121-
primary = kzalloc(sizeof(*primary), GFP_KERNEL);
122-
if (primary == NULL) {
123-
DRM_DEBUG_KMS("Failed to allocate primary plane\n");
124-
return NULL;
125-
}
126-
127-
/*
128-
* Remove the format_default field from drm_plane when dropping
129-
* this helper.
130-
*/
131-
primary->format_default = true;
132-
133-
/* possible_crtc's will be filled in later by crtc_init */
134-
ret = drm_universal_plane_init(dev, primary, 0,
135-
&primary_plane_funcs,
136-
safe_modeset_formats,
137-
ARRAY_SIZE(safe_modeset_formats),
138-
NULL,
139-
DRM_PLANE_TYPE_PRIMARY, NULL);
140-
if (ret) {
141-
kfree(primary);
142-
primary = NULL;
143-
}
144-
145-
return primary;
146-
}
147-
148116
/**
149117
* drm_crtc_init - Legacy CRTC initialization function
150118
* @dev: DRM device
@@ -176,10 +144,33 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
176144
const struct drm_crtc_funcs *funcs)
177145
{
178146
struct drm_plane *primary;
147+
int ret;
148+
149+
/* possible_crtc's will be filled in later by crtc_init */
150+
primary = __drm_universal_plane_alloc(dev, sizeof(*primary), 0, 0,
151+
&primary_plane_funcs,
152+
safe_modeset_formats,
153+
ARRAY_SIZE(safe_modeset_formats),
154+
NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
155+
if (IS_ERR(primary))
156+
return PTR_ERR(primary);
179157

180-
primary = create_primary_plane(dev);
181-
return drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs,
182-
NULL);
158+
/*
159+
* Remove the format_default field from drm_plane when dropping
160+
* this helper.
161+
*/
162+
primary->format_default = true;
163+
164+
ret = drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs, NULL);
165+
if (ret)
166+
goto err_drm_plane_cleanup;
167+
168+
return 0;
169+
170+
err_drm_plane_cleanup:
171+
drm_plane_cleanup(primary);
172+
kfree(primary);
173+
return ret;
183174
}
184175
EXPORT_SYMBOL(drm_crtc_init);
185176

drivers/gpu/drm/drm_plane.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,44 @@ void *__drmm_universal_plane_alloc(struct drm_device *dev, size_t size,
448448
}
449449
EXPORT_SYMBOL(__drmm_universal_plane_alloc);
450450

451+
void *__drm_universal_plane_alloc(struct drm_device *dev, size_t size,
452+
size_t offset, uint32_t possible_crtcs,
453+
const struct drm_plane_funcs *funcs,
454+
const uint32_t *formats, unsigned int format_count,
455+
const uint64_t *format_modifiers,
456+
enum drm_plane_type type,
457+
const char *name, ...)
458+
{
459+
void *container;
460+
struct drm_plane *plane;
461+
va_list ap;
462+
int ret;
463+
464+
if (drm_WARN_ON(dev, !funcs))
465+
return ERR_PTR(-EINVAL);
466+
467+
container = kzalloc(size, GFP_KERNEL);
468+
if (!container)
469+
return ERR_PTR(-ENOMEM);
470+
471+
plane = container + offset;
472+
473+
va_start(ap, name);
474+
ret = __drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
475+
formats, format_count, format_modifiers,
476+
type, name, ap);
477+
va_end(ap);
478+
if (ret)
479+
goto err_kfree;
480+
481+
return container;
482+
483+
err_kfree:
484+
kfree(container);
485+
return ERR_PTR(ret);
486+
}
487+
EXPORT_SYMBOL(__drm_universal_plane_alloc);
488+
451489
int drm_plane_register_all(struct drm_device *dev)
452490
{
453491
unsigned int num_planes = 0;

drivers/gpu/drm/nouveau/dispnv04/crtc.c

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,32 +1281,6 @@ static const struct drm_plane_funcs nv04_primary_plane_funcs = {
12811281
.destroy = drm_plane_helper_destroy,
12821282
};
12831283

1284-
static struct drm_plane *
1285-
create_primary_plane(struct drm_device *dev)
1286-
{
1287-
struct drm_plane *primary;
1288-
int ret;
1289-
1290-
primary = kzalloc(sizeof(*primary), GFP_KERNEL);
1291-
if (primary == NULL) {
1292-
DRM_DEBUG_KMS("Failed to allocate primary plane\n");
1293-
return NULL;
1294-
}
1295-
1296-
/* possible_crtc's will be filled in later by crtc_init */
1297-
ret = drm_universal_plane_init(dev, primary, 0,
1298-
&nv04_primary_plane_funcs,
1299-
modeset_formats,
1300-
ARRAY_SIZE(modeset_formats), NULL,
1301-
DRM_PLANE_TYPE_PRIMARY, NULL);
1302-
if (ret) {
1303-
kfree(primary);
1304-
primary = NULL;
1305-
}
1306-
1307-
return primary;
1308-
}
1309-
13101284
static int nv04_crtc_vblank_handler(struct nvif_notify *notify)
13111285
{
13121286
struct nouveau_crtc *nv_crtc =
@@ -1321,6 +1295,7 @@ nv04_crtc_create(struct drm_device *dev, int crtc_num)
13211295
{
13221296
struct nouveau_display *disp = nouveau_display(dev);
13231297
struct nouveau_crtc *nv_crtc;
1298+
struct drm_plane *primary;
13241299
int ret;
13251300

13261301
nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL);
@@ -1335,8 +1310,18 @@ nv04_crtc_create(struct drm_device *dev, int crtc_num)
13351310
nv_crtc->save = nv_crtc_save;
13361311
nv_crtc->restore = nv_crtc_restore;
13371312

1338-
drm_crtc_init_with_planes(dev, &nv_crtc->base,
1339-
create_primary_plane(dev), NULL,
1313+
primary = __drm_universal_plane_alloc(dev, sizeof(*primary), 0, 0,
1314+
&nv04_primary_plane_funcs,
1315+
modeset_formats,
1316+
ARRAY_SIZE(modeset_formats), NULL,
1317+
DRM_PLANE_TYPE_PRIMARY, NULL);
1318+
if (IS_ERR(primary)) {
1319+
ret = PTR_ERR(primary);
1320+
kfree(nv_crtc);
1321+
return ret;
1322+
}
1323+
1324+
drm_crtc_init_with_planes(dev, &nv_crtc->base, primary, NULL,
13401325
&nv04_crtc_funcs, NULL);
13411326
drm_crtc_helper_add(&nv_crtc->base, &nv04_crtc_helper_funcs);
13421327
drm_mode_crtc_set_gamma_size(&nv_crtc->base, 256);

include/drm/drm_plane.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,50 @@ void *__drmm_universal_plane_alloc(struct drm_device *dev,
809809
format_count, format_modifiers, \
810810
plane_type, name, ##__VA_ARGS__))
811811

812+
__printf(10, 11)
813+
void *__drm_universal_plane_alloc(struct drm_device *dev,
814+
size_t size, size_t offset,
815+
uint32_t possible_crtcs,
816+
const struct drm_plane_funcs *funcs,
817+
const uint32_t *formats,
818+
unsigned int format_count,
819+
const uint64_t *format_modifiers,
820+
enum drm_plane_type plane_type,
821+
const char *name, ...);
822+
823+
/**
824+
* drm_universal_plane_alloc() - Allocate and initialize an universal plane object
825+
* @dev: DRM device
826+
* @type: the type of the struct which contains struct &drm_plane
827+
* @member: the name of the &drm_plane within @type
828+
* @possible_crtcs: bitmask of possible CRTCs
829+
* @funcs: callbacks for the new plane
830+
* @formats: array of supported formats (DRM_FORMAT\_\*)
831+
* @format_count: number of elements in @formats
832+
* @format_modifiers: array of struct drm_format modifiers terminated by
833+
* DRM_FORMAT_MOD_INVALID
834+
* @plane_type: type of plane (overlay, primary, cursor)
835+
* @name: printf style format string for the plane name, or NULL for default name
836+
*
837+
* Allocates and initializes a plane object of type @type. The caller
838+
* is responsible for releasing the allocated memory with kfree().
839+
*
840+
* Drivers are encouraged to use drmm_universal_plane_alloc() instead.
841+
*
842+
* Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
843+
* @format_modifiers to NULL. The plane will advertise the linear modifier.
844+
*
845+
* Returns:
846+
* Pointer to new plane, or ERR_PTR on failure.
847+
*/
848+
#define drm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
849+
format_count, format_modifiers, plane_type, name, ...) \
850+
((type *)__drm_universal_plane_alloc(dev, sizeof(type), \
851+
offsetof(type, member), \
852+
possible_crtcs, funcs, formats, \
853+
format_count, format_modifiers, \
854+
plane_type, name, ##__VA_ARGS__))
855+
812856
/**
813857
* drm_plane_index - find the index of a registered plane
814858
* @plane: plane to find index for

0 commit comments

Comments
 (0)