Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions drivers/gpu/drm/apple/dcp-color.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ struct dcp_color_request {
bool allow_dsc;
bool allow_unsafe_sdr;
bool default_rgb;
/*
* The engine cannot run a DSC-compressed link (a T6050 external engine
* without firmware clocks): never select a DSC-required color element.
*/
bool no_dsc;
};

static inline bool dcp_color_request_is_default(const struct dcp_color_request *req)
Expand Down Expand Up @@ -303,8 +308,8 @@ dcp_scan_color_modes(const struct dcp_display_mode *mode,

if ((e->flags & DCP_COLOR_FLAG_UNSAFE) && !allow_unsafe)
continue;
if ((e->flags & DCP_COLOR_FLAG_DSC) && hdr &&
(!req->allow_dsc || allow_unsafe))
if ((e->flags & DCP_COLOR_FLAG_DSC) &&
(req->no_dsc || (hdr && (!req->allow_dsc || allow_unsafe))))
continue;
if (allow_unsafe && hdr && mode->sdr_unsafe_max_bpp &&
dcp_color_wire_bpp(fmt, e->depth) > mode->sdr_unsafe_max_bpp)
Expand All @@ -331,6 +336,34 @@ dcp_scan_color_modes(const struct dcp_display_mode *mode,
return best;
}

static inline bool dcp_color_id_needs_dsc(const struct dcp_display_mode *mode, s64 id)
{
unsigned int i;

for (i = 0; i < mode->nr_colors; i++)
if (mode->colors[i].id == id)
return mode->colors[i].flags & DCP_COLOR_FLAG_DSC;
return false;
}

/*
* Whether @mode has an SDR color element that runs without DSC and is not
* unsafe: what a request with no_dsc and default SDR settings can select.
*/
static inline bool dcp_mode_has_dsc_free_sdr(const struct dcp_display_mode *mode)
{
unsigned int i;

for (i = 0; i < mode->nr_colors; i++) {
const struct dcp_color_entry *e = &mode->colors[i];

if (e->eotf == DCP_EOTF_SDR_GAMMA &&
!(e->flags & (DCP_COLOR_FLAG_DSC | DCP_COLOR_FLAG_UNSAFE)))
return true;
}
return false;
}

static inline int dcp_select_color_mode(const struct dcp_display_mode *mode,
const struct dcp_color_request *req,
struct dcp_color_mode *out)
Expand All @@ -339,13 +372,20 @@ static inline int dcp_select_color_mode(const struct dcp_display_mode *mode,
const struct dcp_color_entry *best;

if (dcp_color_request_is_default(req)) {
/*
* The timing's own pick can be a DSC-required element (10-bit RGB
* at 2560x1600@165 over HDMI) next to one that runs uncompressed
* (8-bit RGB): without DSC, the scan below picks among the others.
*/
if (req->eotf == HDMI_EOTF_TRADITIONAL_GAMMA_SDR &&
req->colorspace == DRM_MODE_COLORIMETRY_DEFAULT)
req->colorspace == DRM_MODE_COLORIMETRY_DEFAULT &&
!(req->no_dsc && dcp_color_id_needs_dsc(mode, mode->color_mode_id)))
return dcp_default_sdr_color(mode, out);
if (req->eotf == HDMI_EOTF_SMPTE_ST2084 &&
(req->colorspace == DRM_MODE_COLORIMETRY_DEFAULT ||
req->colorspace == DRM_MODE_COLORIMETRY_BT2020_RGB)) {
if (!req->allow_hdr || mode->pq.score < 0)
if (!req->allow_hdr || mode->pq.score < 0 ||
(req->no_dsc && dcp_color_id_needs_dsc(mode, mode->pq.id)))
return -EINVAL;
*out = mode->pq;
return 0;
Expand Down
35 changes: 34 additions & 1 deletion drivers/gpu/drm/apple/iomfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3730,6 +3730,25 @@ static void dcp_hdr_metadata_sync(struct apple_dcp *dcp, struct drm_crtc *crtc,
afk_service_put(service);
}

/*
* A T6050 external engine leaves a mode black when its firmware compresses it
* with DSC: on the J716s a USB-C display at 2560x1600@240 and @260, which the
* firmware lists as DSC required for every color element, while the same
* display runs uncompressed up to 180 Hz. The J716s ADT gives these engines no
* clock-ids, so the driver has no provider clock to answer the firmware with.
* Until that is solved, such an engine never selects a color element the
* firmware lists in DSCRequiredColorElementIDs, the list it sends with each
* timing of the connected display (dcp_color_request.no_dsc), and offers a
* timing only when one of its SDR elements is not on it. Over HDMI at
* 2560x1600@165 that keeps the timing on 8-bit RGB, where 10-bit RGB needs
* DSC; no link rate, lane count or port type is assumed.
*/
static bool dcp_ext_unclocked(struct apple_dcp *dcp)
{
return !dcp->num_firmware_clocks && dcp->hw.external_processor &&
of_device_is_compatible(dcp->dev->of_node, "apple,t6050-dcpext");
}

static void dcp_crtc_color_request(struct apple_dcp *dcp, struct drm_crtc *crtc,
struct drm_atomic_commit *commit,
struct dcp_color_request *req)
Expand All @@ -3751,6 +3770,7 @@ static void dcp_crtc_color_request(struct apple_dcp *dcp, struct drm_crtc *crtc,
.allow_unsafe_sdr = dcp->hw.iomfb_method_profile !=
DCP_IOMFB_METHODS_H17P_EXTERNAL,
.default_rgb = dcp_sdr_default_rgb(dcp),
.no_dsc = dcp_ext_unclocked(dcp),
};
}

Expand Down Expand Up @@ -3937,6 +3957,18 @@ static bool dcp_mode_beyond_provider_clock(struct apple_dcp *dcp,
READ_ONCE(dcp->pmp_display_acked));
}

static bool dcp_ext_mode_needs_unclocked_dsc(struct apple_dcp *dcp,
const struct drm_display_mode *mode)
{
const struct dcp_display_mode *dcp_mode;

if (!dcp_ext_unclocked(dcp))
return false;
/* A timing with an uncompressed SDR element stays: the mode set picks it (no_dsc). */
dcp_mode = dcp_find_mode(dcp, mode);
return dcp_mode && !dcp_mode_has_dsc_free_sdr(dcp_mode);
}

enum drm_mode_status dcp_mode_valid(struct drm_connector *connector,
const struct drm_display_mode *mode)
{
Expand Down Expand Up @@ -3965,7 +3997,8 @@ enum drm_mode_status dcp_mode_valid(struct drm_connector *connector,
*/
if (dcp_peer_mode_limited_v27(dcp, mode->clock))
return MODE_CLOCK_HIGH;
if (dcp_mode_beyond_provider_clock(dcp, connector, mode))
if (dcp_mode_beyond_provider_clock(dcp, connector, mode) ||
dcp_ext_mode_needs_unclocked_dsc(dcp, mode))
return MODE_CLOCK_HIGH;
return dcp_mode_settable(dcp, mode) ? MODE_OK : MODE_BAD;
}
Expand Down
53 changes: 53 additions & 0 deletions drivers/gpu/drm/apple/parser-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <drm/drm_atomic_state_helper.h>

#include "dcp.h"
#include "dcp-color.h"
#include <drm/drm_edid.h>
#include <linux/unaligned.h>

Expand Down Expand Up @@ -253,6 +254,57 @@ static void parser_tiled_size_keeps_dsc_modes(struct kunit *test)
kfree(modes);
}

/*
* A clockless T6050 external engine (dcp_color_request.no_dsc) runs a timing
* on an SDR element the firmware does not list as DSC required, even when the
* timing's own pick is on the list, and refuses the timing when all are.
*/
static void color_no_dsc_picks_uncompressed(struct kunit *test)
{
struct dcp_display_mode mode = {
.color_mode_id = 88,
.sdr_rgb = { .id = 88, .score = 1, .depth = 10, .eotf = DCP_EOTF_SDR_GAMMA,
.format = DCP_COLOR_FORMAT_RGB, .colorimetry = DCP_COLORIMETRY_SRGB },
.sdr_444 = { .score = -1 }, .sdr = { .score = -1 }, .best = { .score = -1 },
.pq = { .score = -1 },
.nr_colors = 2,
.colors = {
{ .id = 88, .depth = 10, .eotf = DCP_EOTF_SDR_GAMMA,
.format = DCP_COLOR_FORMAT_RGB, .colorimetry = DCP_COLORIMETRY_SRGB,
.flags = DCP_COLOR_FLAG_DSC },
{ .id = 83, .depth = 8, .eotf = DCP_EOTF_SDR_GAMMA,
.format = DCP_COLOR_FORMAT_RGB, .colorimetry = DCP_COLORIMETRY_SRGB },
},
};
struct dcp_color_request req = {
.eotf = HDMI_EOTF_TRADITIONAL_GAMMA_SDR,
.colorspace = DRM_MODE_COLORIMETRY_DEFAULT,
.color_format = DRM_CONNECTOR_COLOR_FORMAT_AUTO,
.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO,
};
struct dcp_color_mode out;

/* Engines that compress keep the timing's own pick. */
KUNIT_ASSERT_EQ(test, dcp_select_color_mode(&mode, &req, &out), 0);
KUNIT_EXPECT_EQ(test, out.id, 88);

req.no_dsc = true;
KUNIT_EXPECT_TRUE(test, dcp_mode_has_dsc_free_sdr(&mode));
KUNIT_ASSERT_EQ(test, dcp_select_color_mode(&mode, &req, &out), 0);
KUNIT_EXPECT_EQ(test, out.id, 83);
KUNIT_EXPECT_EQ(test, out.depth, 8);
/* A compositor's 10 bpc cap changes nothing. */
req.max_bpc = 10;
KUNIT_ASSERT_EQ(test, dcp_select_color_mode(&mode, &req, &out), 0);
KUNIT_EXPECT_EQ(test, out.id, 83);

/* 2560x1600@240: every element needs DSC. */
mode.colors[1].flags = DCP_COLOR_FLAG_DSC;
KUNIT_EXPECT_FALSE(test, dcp_mode_has_dsc_free_sdr(&mode));
req.max_bpc = 0;
KUNIT_EXPECT_EQ(test, dcp_select_color_mode(&mode, &req, &out), -EINVAL);
}

static void parser_score_presence(struct kunit *test)
{
struct parser_record records[] = { valid_record(7, 100), valid_record(8, 0) };
Expand Down Expand Up @@ -2428,6 +2480,7 @@ static struct kunit_case parser_cases[] = {
KUNIT_CASE(parser_panel_color_target),
KUNIT_CASE(parser_panel_adt_color_target),
KUNIT_CASE(parser_tiled_size_keeps_dsc_modes),
KUNIT_CASE(color_no_dsc_picks_uncompressed),
KUNIT_CASE(parser_score_presence),
KUNIT_CASE(parser_legacy_ties),
KUNIT_CASE(parser_color_presence),
Expand Down
Loading