Skip to content

Commit 6e42201

Browse files
bparrottomba
authored andcommitted
drm/omap: Add global state as a private atomic object
Global shared resources (like hw overlays) for omapdrm are implemented as a part of atomic state using the drm_private_obj infrastructure available in the atomic core. omap_global_state is introduced as a drm atomic private object. The two funcs omap_get_global_state() and omap_get_existing_global_state() are the two variants that will be used to access omap_global_state. drm_mode_config_init() needs to be called earlier because it creates/initializes the private_obj link list maintained by the atomic framework. The private_obj link list has to exist prior to calling drm_atomic_private_obj_init(). Similarly the cleanup handler are reordered appropriately. Signed-off-by: Benoit Parrot <[email protected]> Signed-off-by: Neil Armstrong <[email protected]> Reviewed-by: Tomi Valkeinen <[email protected]> Signed-off-by: Tomi Valkeinen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 3c265d9 commit 6e42201

File tree

2 files changed

+105
-3
lines changed

2 files changed

+105
-3
lines changed

drivers/gpu/drm/omapdrm/omap_drv.c

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,82 @@ static const struct drm_mode_config_funcs omap_mode_config_funcs = {
128128
.atomic_commit = drm_atomic_helper_commit,
129129
};
130130

131+
/* Global/shared object state funcs */
132+
133+
/*
134+
* This is a helper that returns the private state currently in operation.
135+
* Note that this would return the "old_state" if called in the atomic check
136+
* path, and the "new_state" after the atomic swap has been done.
137+
*/
138+
struct omap_global_state *
139+
omap_get_existing_global_state(struct omap_drm_private *priv)
140+
{
141+
return to_omap_global_state(priv->glob_obj.state);
142+
}
143+
144+
/*
145+
* This acquires the modeset lock set aside for global state, creates
146+
* a new duplicated private object state.
147+
*/
148+
struct omap_global_state *__must_check
149+
omap_get_global_state(struct drm_atomic_state *s)
150+
{
151+
struct omap_drm_private *priv = s->dev->dev_private;
152+
struct drm_private_state *priv_state;
153+
154+
priv_state = drm_atomic_get_private_obj_state(s, &priv->glob_obj);
155+
if (IS_ERR(priv_state))
156+
return ERR_CAST(priv_state);
157+
158+
return to_omap_global_state(priv_state);
159+
}
160+
161+
static struct drm_private_state *
162+
omap_global_duplicate_state(struct drm_private_obj *obj)
163+
{
164+
struct omap_global_state *state;
165+
166+
state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL);
167+
if (!state)
168+
return NULL;
169+
170+
__drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);
171+
172+
return &state->base;
173+
}
174+
175+
static void omap_global_destroy_state(struct drm_private_obj *obj,
176+
struct drm_private_state *state)
177+
{
178+
struct omap_global_state *omap_state = to_omap_global_state(state);
179+
180+
kfree(omap_state);
181+
}
182+
183+
static const struct drm_private_state_funcs omap_global_state_funcs = {
184+
.atomic_duplicate_state = omap_global_duplicate_state,
185+
.atomic_destroy_state = omap_global_destroy_state,
186+
};
187+
188+
static int omap_global_obj_init(struct drm_device *dev)
189+
{
190+
struct omap_drm_private *priv = dev->dev_private;
191+
struct omap_global_state *state;
192+
193+
state = kzalloc(sizeof(*state), GFP_KERNEL);
194+
if (!state)
195+
return -ENOMEM;
196+
197+
drm_atomic_private_obj_init(dev, &priv->glob_obj, &state->base,
198+
&omap_global_state_funcs);
199+
return 0;
200+
}
201+
202+
static void omap_global_obj_fini(struct omap_drm_private *priv)
203+
{
204+
drm_atomic_private_obj_fini(&priv->glob_obj);
205+
}
206+
131207
static void omap_disconnect_pipelines(struct drm_device *ddev)
132208
{
133209
struct omap_drm_private *priv = ddev->dev_private;
@@ -231,8 +307,6 @@ static int omap_modeset_init(struct drm_device *dev)
231307
if (!omapdss_stack_is_ready())
232308
return -EPROBE_DEFER;
233309

234-
drm_mode_config_init(dev);
235-
236310
ret = omap_modeset_init_properties(dev);
237311
if (ret < 0)
238312
return ret;
@@ -583,10 +657,16 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
583657

584658
omap_gem_init(ddev);
585659

586-
ret = omap_hwoverlays_init(priv);
660+
drm_mode_config_init(ddev);
661+
662+
ret = omap_global_obj_init(ddev);
587663
if (ret)
588664
goto err_gem_deinit;
589665

666+
ret = omap_hwoverlays_init(priv);
667+
if (ret)
668+
goto err_free_priv_obj;
669+
590670
ret = omap_modeset_init(ddev);
591671
if (ret) {
592672
dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
@@ -624,7 +704,10 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
624704
omap_modeset_fini(ddev);
625705
err_free_overlays:
626706
omap_hwoverlays_destroy(priv);
707+
err_free_priv_obj:
708+
omap_global_obj_fini(priv);
627709
err_gem_deinit:
710+
drm_mode_config_cleanup(ddev);
628711
omap_gem_deinit(ddev);
629712
destroy_workqueue(priv->wq);
630713
omap_disconnect_pipelines(ddev);
@@ -649,6 +732,8 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
649732

650733
omap_modeset_fini(ddev);
651734
omap_hwoverlays_destroy(priv);
735+
omap_global_obj_fini(priv);
736+
drm_mode_config_cleanup(ddev);
652737
omap_gem_deinit(ddev);
653738

654739
destroy_workqueue(priv->wq);

drivers/gpu/drm/omapdrm/omap_drv.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "dss/omapdss.h"
1515
#include "dss/dss.h"
1616

17+
#include <drm/drm_atomic.h>
1718
#include <drm/drm_gem.h>
1819
#include <drm/omap_drm.h>
1920

@@ -41,6 +42,16 @@ struct omap_drm_pipeline {
4142
unsigned int alias_id;
4243
};
4344

45+
/*
46+
* Global private object state for tracking resources that are shared across
47+
* multiple kms objects (planes/crtcs/etc).
48+
*/
49+
#define to_omap_global_state(x) container_of(x, struct omap_global_state, base)
50+
51+
struct omap_global_state {
52+
struct drm_private_state base;
53+
};
54+
4455
struct omap_drm_private {
4556
struct drm_device *ddev;
4657
struct device *dev;
@@ -61,6 +72,8 @@ struct omap_drm_private {
6172
unsigned int num_ovls;
6273
struct omap_hw_overlay *overlays[8];
6374

75+
struct drm_private_obj glob_obj;
76+
6477
struct drm_fb_helper *fbdev;
6578

6679
struct workqueue_struct *wq;
@@ -89,4 +102,8 @@ struct omap_drm_private {
89102

90103
void omap_debugfs_init(struct drm_minor *minor);
91104

105+
struct omap_global_state * __must_check omap_get_global_state(struct drm_atomic_state *s);
106+
107+
struct omap_global_state *omap_get_existing_global_state(struct omap_drm_private *priv);
108+
92109
#endif /* __OMAPDRM_DRV_H__ */

0 commit comments

Comments
 (0)