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
6 changes: 6 additions & 0 deletions drivers/gpu/drm/apple/apple_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#include "apple_boot_display.h"
#include "apple_resume.h"
#include "dcp-hdr-metadata.h"
#include "dcp.h"
#include "plane.h"
#include "iomfb_m4.h"
Expand Down Expand Up @@ -918,8 +919,13 @@ static int apple_connector_atomic_check(struct drm_connector *conn,
{
struct drm_connector_state *old = drm_atomic_get_old_connector_state(state, conn);
struct drm_connector_state *new = drm_atomic_get_new_connector_state(state, conn);
const struct drm_property_blob *blob = new->hdr_output_metadata;
struct drm_crtc_state *crtc_state;

if (blob && (blob->length != sizeof(struct hdr_output_metadata) ||
!dcp_hdr_is_type1(blob->data)))
return -EINVAL;

if (!new->crtc || (old->colorspace == new->colorspace &&
drm_connector_atomic_hdr_metadata_equal(old, new)))
return 0;
Expand Down
9 changes: 7 additions & 2 deletions drivers/gpu/drm/apple/dcp-hdr-metadata.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
/*
* HDR10 static metadata for the DCPAV service of desktop 26.x DCPs.
* HDR10 static metadata for the DCPAV service.
*
* The display's Dynamic Range and Mastering InfoFrame is link state the
* firmware builds itself: the host sends DCPAV selector 0x15
Expand Down Expand Up @@ -62,14 +62,19 @@
#define DCP_HDR_STOP_STATUS 0x70
#define DCP_HDR_INFOFRAME_DRM 0x87

static inline bool dcp_hdr_is_type1(const struct hdr_output_metadata *hdr)
{
return !hdr->metadata_type && !hdr->hdmi_metadata_type1.metadata_type;
}

/* The 24-byte Type 1 body of @hdr; -EINVAL unless it is a Type 1 block. */
static inline int dcp_hdr_data(u8 data[DCP_HDR_DATA_SIZE],
const struct hdr_output_metadata *hdr)
{
const struct hdr_metadata_infoframe *t1 = &hdr->hdmi_metadata_type1;
unsigned int i;

if (hdr->metadata_type || t1->metadata_type)
if (!dcp_hdr_is_type1(hdr))
return -EINVAL;
for (i = 0; i < 3; i++) {
put_unaligned_le16(t1->display_primaries[i].x, data + i * 4);
Expand Down
23 changes: 11 additions & 12 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,6 @@ struct dcp_desktop_state {
u32 vrr_min_on, vrr_min_off, vrr_min_sent;
/* The frame's colour matrix, sent after an adaptive sync update. */
struct iomfb_set_matrix_req matrix;
/*
* HDR10 static metadata (external processors): the pinned
* dcpav-service-epic service, the Type 1 body last sent on this link
* (taken or refused), if any, and whether the firmware took one, so
* that the link carries a Dynamic Range and Mastering InfoFrame.
* hdr_lock protects all of them.
*/
spinlock_t hdr_lock;
struct apple_epic_service *av_service;
u8 hdr_sent[24];
bool hdr_sent_valid;
bool hdr_infoframe;
u32 present_id;
bool present_pending;
/*
Expand Down Expand Up @@ -822,6 +810,17 @@ struct apple_dcp {
bool typec_hpd_held;
bool use_timestamps;
bool vrr_enabled;
struct {
/* Pins the AV service and tracks HDR10 metadata for its link. */
spinlock_t lock;
struct apple_epic_service *service;
u64 generation;
u8 sent[24];
bool sent_valid;
bool infoframe;
} hdr;
/* The selected IOMFB backend programs catalogue colour IDs and PQ surfaces. */
bool iomfb_template_pq;
/*
* The mode set asks for a PQ signal; output_pq: the one set carries it;
* output_edr: a panel shows the PQ content as EDR, edr_sent: swaps
Expand Down
40 changes: 5 additions & 35 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4236,45 +4236,15 @@ static const struct apple_epic_service_ops dcp_compact_aux_ops[] = {
static void dcp_av_service_init(struct apple_epic_service *service,
const char *name, const char *class, s64 unit)
{
struct dcp_desktop_state *d = service->ep->dcp->desktop;
struct apple_epic_service *old;

service = afk_service_get(service);
if (!service)
return;
scoped_guard(spinlock_irqsave, &d->hdr_lock) {
old = d->av_service;
d->av_service = service;
d->hdr_sent_valid = false;
d->hdr_infoframe = false;
}
if (old)
afk_service_put(old);
}

static void dcp_av_service_teardown(struct apple_epic_service *service)
{
struct dcp_desktop_state *d = service->ep->dcp->desktop;
bool owned;

scoped_guard(spinlock_irqsave, &d->hdr_lock) {
owned = d->av_service == service;
if (owned) {
d->av_service = NULL;
d->hdr_sent_valid = false;
d->hdr_infoframe = false;
}
}
if (owned)
afk_service_put(service);
dcp_hdr_service_bind(service);
}

static const struct apple_epic_service_ops dcp_ext_av_service_ops[] = {
{
.name = "dcpav-service-epic",
.reusable = true,
.init = dcp_av_service_init,
.teardown = dcp_av_service_teardown,
.teardown = dcp_hdr_service_unbind,
},
{
.name = "*",
Expand Down Expand Up @@ -4902,8 +4872,6 @@ static void _dcp_poweroff(struct apple_dcp *dcp)
iomfb_poweroff_v26_6_desktop(dcp);
if (dcp->edr_hm)
dcp->edr_restart = true;
/* The link set up again starts without HDR10 metadata. */
dcp_hdr_metadata_forget(dcp);
break;
case DCP_FIRMWARE_V_26_6:
iomfb_v26_6_poweroff(dcp);
Expand All @@ -4925,6 +4893,8 @@ static void _dcp_poweroff(struct apple_dcp *dcp)
WARN_ONCE(true, "Unexpected firmware version: %u\n", dcp->fw_compat);
break;
}
/* The link set up again starts without HDR10 metadata. */
dcp_hdr_metadata_forget(dcp);
}

static void dcp_resume_enable_irq(void *ctx)
Expand Down Expand Up @@ -7284,7 +7254,6 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev)
dcp->desktop = devm_kzalloc(dev, sizeof(*dcp->desktop), GFP_KERNEL);
if (!dcp->desktop)
return -ENOMEM;
spin_lock_init(&dcp->desktop->hdr_lock);
/*
* The opaque client identity of the IOMFB calls. The firmware's
* own client passes a kernel pointer there; pass a random value
Expand Down Expand Up @@ -7328,6 +7297,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev)
dcp_fabric_init(dcp);
spin_lock_init(&dcp->mode_state.lock);
spin_lock_init(&dcp->metadata.lock);
spin_lock_init(&dcp->hdr.lock);
mutex_init(&dcp->dcpavserv.lock);
INIT_WORK(&dcp->dcpavserv.close_wq, dcpavserv_close_work);
ret = dcpavserv_edid_retry_init(dcp);
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/apple/epic/dpavservep-v14-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static struct av14_test *av14_setup(struct kunit *test, bool native)
t->dcp->external_native = native;
mutex_init(&t->dcp->hpd_mutex);
mutex_init(&t->dcp->dcpavserv.lock);
spin_lock_init(&t->dcp->hdr.lock);
INIT_WORK(&t->dcp->dcpavserv.close_wq, dcpavserv_close_work);
/* Queued work runs here, in test context: av14_run_close_work() */
disable_work(&t->dcp->dcpavserv.close_wq);
Expand Down
8 changes: 8 additions & 0 deletions drivers/gpu/drm/apple/epic/dpavservep.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "../dcp.h"
#include "../dcp-internal.h"
#include "../connector.h"
#include "../iomfb_internal.h"
#include "../trace.h"

static void dcpavserv_notify_edid(struct apple_epic_service *service)
Expand Down Expand Up @@ -130,6 +131,11 @@ static void dcpavserv_init(struct apple_epic_service *service, const char *name,
dcp->dcpavserv.opened = NULL;
dcp->dcpavserv.opened_epoch = 0;
service->cookie = &dcp->dcpavserv;
if (!v2 && !dcp->desktop && class &&
(!strcmp(class, "DCPDP13Service") ||
!strcmp(class, "DCPDPService") ||
!strcmp(class, "AppleDCPDP2HDMI")))
dcp_hdr_service_bind(service);
complete(&dcp->dcpavserv.enable_completion);
published = true;
}
Expand Down Expand Up @@ -175,6 +181,7 @@ static void dcpavserv_teardown(struct apple_epic_service *service)

mutex_lock(&dcp->dcpavserv.lock);
if (dcp->dcpavserv.service == service) {
dcp_hdr_service_unbind(service);
dcp->dcpavserv.enabled = false;
dcp->dcpavserv.service = NULL;
dcp->dcpavserv.epoch++;
Expand Down Expand Up @@ -204,6 +211,7 @@ void dpavservep_detach(struct apple_dcp *dcp)
dcp->dcpavserv.opened_epoch = 0;
reinit_completion(&dcp->dcpavserv.enable_completion);
if (service) {
dcp_hdr_service_unbind(service);
afk_service_retire(service);
dcpavserv_invalidate_edid(dcp);
}
Expand Down
Loading
Loading