Skip to content

Commit 935774c

Browse files
Brian Starkeydliviu
authored andcommitted
drm: Add writeback connector type
Writeback connectors represent writeback engines which can write the CRTC output to a memory framebuffer. Add a writeback connector type and related support functions. Drivers should initialize a writeback connector with drm_writeback_connector_init() which takes care of setting up all the writeback-specific details on top of the normal functionality of drm_connector_init(). Writeback connectors have a WRITEBACK_FB_ID property, used to set the output framebuffer, and a WRITEBACK_PIXEL_FORMATS blob used to expose the supported writeback formats to userspace. When a framebuffer is attached to a writeback connector with the WRITEBACK_FB_ID property, it is used only once (for the commit in which it was included), and userspace can never read back the value of WRITEBACK_FB_ID. WRITEBACK_FB_ID can only be set if the connector is attached to a CRTC. Changes since v1: - Added drm_writeback.c + documentation - Added helper to initialize writeback connector in one go - Added core checks - Squashed into a single commit - Dropped the client cap - Writeback framebuffers are no longer persistent Changes since v2: Daniel Vetter: - Subclass drm_connector to drm_writeback_connector - Relax check to allow CRTC to be set without an FB - Add some writeback_ prefixes - Drop PIXEL_FORMATS_SIZE property, as it was unnecessary Gustavo Padovan: - Add drm_writeback_job to handle writeback signalling centrally Changes since v3: - Rebased - Rename PIXEL_FORMATS -> WRITEBACK_PIXEL_FORMATS Chances since v4: - Embed a drm_encoder inside the drm_writeback_connector to reduce the amount of boilerplate code required from the drivers that are using it. Changes since v5: - Added Rob Clark's atomic_commit() vfunc to connector helper funcs, so that writeback jobs are committed from atomic helpers - Updated create_writeback_properties() signature to return an error code rather than a boolean false for failure. - Free writeback job with the connector state rather than when doing the cleanup_work() Changes since v7: - fix extraneous use of out_fence that is only introduced in a subsequent patch. Changes since v8: - whitespace changes pull from subsequent patch Changes since v9: - Revert the v6 changes that free the writeback job in the connector state cleanup and return to doing it in the cleanup_work() function Signed-off-by: Brian Starkey <[email protected]> [rebased and fixed conflicts] Signed-off-by: Mihail Atanassov <[email protected]> [rebased and added atomic_commit() vfunc for writeback jobs] Signed-off-by: Rob Clark <[email protected]> Signed-off-by: Liviu Dudau <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Link: https://patchwork.freedesktop.org/patch/229037/
1 parent f664a52 commit 935774c

File tree

12 files changed

+541
-2
lines changed

12 files changed

+541
-2
lines changed

Documentation/gpu/drm-kms.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ Connector Functions Reference
373373
.. kernel-doc:: drivers/gpu/drm/drm_connector.c
374374
:export:
375375

376+
Writeback Connectors
377+
--------------------
378+
379+
.. kernel-doc:: drivers/gpu/drm/drm_writeback.c
380+
:doc: overview
381+
382+
.. kernel-doc:: drivers/gpu/drm/drm_writeback.c
383+
:export:
384+
376385
Encoder Abstraction
377386
===================
378387

drivers/gpu/drm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \
1818
drm_encoder.o drm_mode_object.o drm_property.o \
1919
drm_plane.o drm_color_mgmt.o drm_print.o \
2020
drm_dumb_buffers.o drm_mode_config.o drm_vblank.o \
21-
drm_syncobj.o drm_lease.o
21+
drm_syncobj.o drm_lease.o drm_writeback.o
2222

2323
drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
2424
drm-$(CONFIG_DRM_VM) += drm_vm.o

drivers/gpu/drm/drm_atomic.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <drm/drm_atomic.h>
3131
#include <drm/drm_mode.h>
3232
#include <drm/drm_print.h>
33+
#include <drm/drm_writeback.h>
3334
#include <linux/sync_file.h>
3435

3536
#include "drm_crtc_internal.h"
@@ -690,6 +691,45 @@ static void drm_atomic_crtc_print_state(struct drm_printer *p,
690691
crtc->funcs->atomic_print_state(p, state);
691692
}
692693

694+
/**
695+
* drm_atomic_connector_check - check connector state
696+
* @connector: connector to check
697+
* @state: connector state to check
698+
*
699+
* Provides core sanity checks for connector state.
700+
*
701+
* RETURNS:
702+
* Zero on success, error code on failure
703+
*/
704+
static int drm_atomic_connector_check(struct drm_connector *connector,
705+
struct drm_connector_state *state)
706+
{
707+
struct drm_crtc_state *crtc_state;
708+
struct drm_writeback_job *writeback_job = state->writeback_job;
709+
710+
if ((connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) || !writeback_job)
711+
return 0;
712+
713+
if (writeback_job->fb && !state->crtc) {
714+
DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] framebuffer without CRTC\n",
715+
connector->base.id, connector->name);
716+
return -EINVAL;
717+
}
718+
719+
if (state->crtc)
720+
crtc_state = drm_atomic_get_existing_crtc_state(state->state,
721+
state->crtc);
722+
723+
if (writeback_job->fb && !crtc_state->active) {
724+
DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] has framebuffer, but [CRTC:%d] is off\n",
725+
connector->base.id, connector->name,
726+
state->crtc->base.id);
727+
return -EINVAL;
728+
}
729+
730+
return 0;
731+
}
732+
693733
/**
694734
* drm_atomic_get_plane_state - get plane state
695735
* @state: global atomic state object
@@ -1321,6 +1361,12 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector,
13211361
return -EINVAL;
13221362
}
13231363
state->content_protection = val;
1364+
} else if (property == config->writeback_fb_id_property) {
1365+
struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, NULL, val);
1366+
int ret = drm_atomic_set_writeback_fb_for_connector(state, fb);
1367+
if (fb)
1368+
drm_framebuffer_put(fb);
1369+
return ret;
13241370
} else if (connector->funcs->atomic_set_property) {
13251371
return connector->funcs->atomic_set_property(connector,
13261372
state, property, val);
@@ -1407,6 +1453,9 @@ drm_atomic_connector_get_property(struct drm_connector *connector,
14071453
*val = state->scaling_mode;
14081454
} else if (property == connector->content_protection_property) {
14091455
*val = state->content_protection;
1456+
} else if (property == config->writeback_fb_id_property) {
1457+
/* Writeback framebuffer is one-shot, write and forget */
1458+
*val = 0;
14101459
} else if (connector->funcs->atomic_get_property) {
14111460
return connector->funcs->atomic_get_property(connector,
14121461
state, property, val);
@@ -1631,6 +1680,70 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
16311680
}
16321681
EXPORT_SYMBOL(drm_atomic_set_crtc_for_connector);
16331682

1683+
/*
1684+
* drm_atomic_get_writeback_job - return or allocate a writeback job
1685+
* @conn_state: Connector state to get the job for
1686+
*
1687+
* Writeback jobs have a different lifetime to the atomic state they are
1688+
* associated with. This convenience function takes care of allocating a job
1689+
* if there isn't yet one associated with the connector state, otherwise
1690+
* it just returns the existing job.
1691+
*
1692+
* Returns: The writeback job for the given connector state
1693+
*/
1694+
static struct drm_writeback_job *
1695+
drm_atomic_get_writeback_job(struct drm_connector_state *conn_state)
1696+
{
1697+
WARN_ON(conn_state->connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK);
1698+
1699+
if (!conn_state->writeback_job)
1700+
conn_state->writeback_job =
1701+
kzalloc(sizeof(*conn_state->writeback_job), GFP_KERNEL);
1702+
1703+
return conn_state->writeback_job;
1704+
}
1705+
1706+
/**
1707+
* drm_atomic_set_writeback_fb_for_connector - set writeback framebuffer
1708+
* @conn_state: atomic state object for the connector
1709+
* @fb: fb to use for the connector
1710+
*
1711+
* This is used to set the framebuffer for a writeback connector, which outputs
1712+
* to a buffer instead of an actual physical connector.
1713+
* Changing the assigned framebuffer requires us to grab a reference to the new
1714+
* fb and drop the reference to the old fb, if there is one. This function
1715+
* takes care of all these details besides updating the pointer in the
1716+
* state object itself.
1717+
*
1718+
* Note: The only way conn_state can already have an fb set is if the commit
1719+
* sets the property more than once.
1720+
*
1721+
* See also: drm_writeback_connector_init()
1722+
*
1723+
* Returns: 0 on success
1724+
*/
1725+
int drm_atomic_set_writeback_fb_for_connector(
1726+
struct drm_connector_state *conn_state,
1727+
struct drm_framebuffer *fb)
1728+
{
1729+
struct drm_writeback_job *job =
1730+
drm_atomic_get_writeback_job(conn_state);
1731+
if (!job)
1732+
return -ENOMEM;
1733+
1734+
drm_framebuffer_assign(&job->fb, fb);
1735+
1736+
if (fb)
1737+
DRM_DEBUG_ATOMIC("Set [FB:%d] for connector state %p\n",
1738+
fb->base.id, conn_state);
1739+
else
1740+
DRM_DEBUG_ATOMIC("Set [NOFB] for connector state %p\n",
1741+
conn_state);
1742+
1743+
return 0;
1744+
}
1745+
EXPORT_SYMBOL(drm_atomic_set_writeback_fb_for_connector);
1746+
16341747
/**
16351748
* drm_atomic_add_affected_connectors - add connectors for crtc
16361749
* @state: atomic state
@@ -1752,6 +1865,8 @@ int drm_atomic_check_only(struct drm_atomic_state *state)
17521865
struct drm_plane_state *plane_state;
17531866
struct drm_crtc *crtc;
17541867
struct drm_crtc_state *crtc_state;
1868+
struct drm_connector *conn;
1869+
struct drm_connector_state *conn_state;
17551870
int i, ret = 0;
17561871

17571872
DRM_DEBUG_ATOMIC("checking %p\n", state);
@@ -1774,6 +1889,15 @@ int drm_atomic_check_only(struct drm_atomic_state *state)
17741889
}
17751890
}
17761891

1892+
for_each_new_connector_in_state(state, conn, conn_state, i) {
1893+
ret = drm_atomic_connector_check(conn, conn_state);
1894+
if (ret) {
1895+
DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] atomic core check failed\n",
1896+
conn->base.id, conn->name);
1897+
return ret;
1898+
}
1899+
}
1900+
17771901
if (config->funcs->atomic_check)
17781902
ret = config->funcs->atomic_check(state->dev, state);
17791903

drivers/gpu/drm/drm_atomic_helper.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <drm/drm_plane_helper.h>
3131
#include <drm/drm_crtc_helper.h>
3232
#include <drm/drm_atomic_helper.h>
33+
#include <drm/drm_writeback.h>
3334
#include <linux/dma-fence.h>
3435

3536
#include "drm_crtc_helper_internal.h"
@@ -1172,6 +1173,25 @@ void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev,
11721173
}
11731174
EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_disables);
11741175

1176+
static void drm_atomic_helper_commit_writebacks(struct drm_device *dev,
1177+
struct drm_atomic_state *old_state)
1178+
{
1179+
struct drm_connector *connector;
1180+
struct drm_connector_state *new_conn_state;
1181+
int i;
1182+
1183+
for_each_new_connector_in_state(old_state, connector, new_conn_state, i) {
1184+
const struct drm_connector_helper_funcs *funcs;
1185+
1186+
funcs = connector->helper_private;
1187+
1188+
if (new_conn_state->writeback_job && new_conn_state->writeback_job->fb) {
1189+
WARN_ON(connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK);
1190+
funcs->atomic_commit(connector, new_conn_state->writeback_job);
1191+
}
1192+
}
1193+
}
1194+
11751195
/**
11761196
* drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs
11771197
* @dev: DRM device
@@ -1251,6 +1271,8 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
12511271

12521272
drm_bridge_enable(encoder->bridge);
12531273
}
1274+
1275+
drm_atomic_helper_commit_writebacks(dev, old_state);
12541276
}
12551277
EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables);
12561278

@@ -3647,6 +3669,9 @@ __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
36473669
if (state->crtc)
36483670
drm_connector_get(connector);
36493671
state->commit = NULL;
3672+
3673+
/* Don't copy over a writeback job, they are used only once */
3674+
state->writeback_job = NULL;
36503675
}
36513676
EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
36523677

drivers/gpu/drm/drm_connector.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
8787
{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
8888
{ DRM_MODE_CONNECTOR_DSI, "DSI" },
8989
{ DRM_MODE_CONNECTOR_DPI, "DPI" },
90+
{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
9091
};
9192

9293
void drm_connector_ida_init(void)
@@ -253,7 +254,8 @@ int drm_connector_init(struct drm_device *dev,
253254
config->num_connector++;
254255
spin_unlock_irq(&config->connector_list_lock);
255256

256-
if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL)
257+
if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
258+
connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
257259
drm_object_attach_property(&connector->base,
258260
config->edid_property,
259261
0);

0 commit comments

Comments
 (0)