Skip to content
Merged
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
1 change: 1 addition & 0 deletions arch/arm64/configs/asahi.config
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ CONFIG_DRM_ASAHI_M3_T8122=y
CONFIG_DRM_ADP=m
CONFIG_DRM_APPLE=m
CONFIG_DRM_APPLE_DCP_T8132=y
CONFIG_DRM_APPLE_CEC=y
CONFIG_DRM_APPLE_AUDIO=y
CONFIG_DRM_APPLE_DCP_T6030_AUDIO=y
CONFIG_DRM_ACCEL=y
Expand Down
11 changes: 11 additions & 0 deletions drivers/gpu/drm/apple/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@ config DRM_APPLE
depends on BACKLIGHT_CLASS_DEVICE
select MULTIPLEXER
select DRM_APPLE_FABRIC_CORE
select CEC_CORE if DRM_APPLE_CEC
help
Say Y if you have an Apple Silicon chipset. This includes the
Type-C display fabric and Thunderbolt display routing.

config DRM_APPLE_CEC
bool "HDMI CEC support"
default y
depends on DRM_APPLE
help
Enable HDMI Consumer Electronics Control (CEC) support on Apple
Silicon machines with a built-in HDMI port via the compact EPIC
dcpav-cec-interface-epic service. Say Y here to expose a standard
Linux /dev/cecX adapter bound to the built-in HDMI connector.

config DRM_APPLE_AUDIO
bool "DisplayPort/HDMI Audio support"
default y
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CFLAGS_trace.o = -I$(src)
appledrm-y := apple_drv.o apple_resume.o
appledrm-y += afk.o dcp.o dcp-fabric.o dcp_backlight.o dptxep.o iomfb.o parser.o systemep.o
appledrm-y += dcp-hdmi.o
appledrm-$(CONFIG_DRM_APPLE_CEC) += cec.o
appledrm-$(CONFIG_DRM_APPLE_AUDIO) += audio.o
appledrm-$(CONFIG_DRM_APPLE_AUDIO) += av.o
appledrm-y += connector.o dcp-panel-adt.o dcp-display-metadata.o dcp-180hz.o
Expand Down Expand Up @@ -47,6 +48,7 @@ obj-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp-indicator-test.o
obj-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp-announce-test.o

obj-$(CONFIG_DRM_APPLE_KUNIT_TEST) += afk-service-test.o
obj-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_cec_test.o

obj-$(CONFIG_DRM_APPLE_PARSER_KUNIT_TEST) += afkv2-test.o

Expand Down
80 changes: 80 additions & 0 deletions drivers/gpu/drm/apple/afk-parser-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,85 @@ static void afk_serialized_report_test(struct kunit *test)
KUNIT_EXPECT_FALSE(test, afk_compact_report_dictionary(dictionary, sizeof(dictionary)));
}

struct compact_call_report_capture {
unsigned int count;
size_t size;
u16 group;
u32 command;
u32 magic;
u16 pa;
};

static int compact_call_report_cb(struct apple_epic_service *service,
enum epic_subtype type,
const void *data, size_t data_size)
{
struct compact_call_report_capture *cap = service->cookie;
const struct epic_service_call *call = data;

cap->count++;
cap->size = data_size;
if (data_size >= sizeof(*call) + sizeof(u16)) {
cap->group = le16_to_cpu(call->group);
cap->command = le32_to_cpu(call->command);
cap->magic = le32_to_cpu(call->magic);
cap->pa = get_unaligned_le16((const u8 *)(call + 1));
}
return 0;
}

static const struct apple_epic_service_ops compact_call_report_ops = {
.name = "compact-report-test",
.report = compact_call_report_cb,
};

static void afk_compact_service_call_report_test(struct kunit *test)
{
struct apple_dcp_afkep *ep = test->priv;
struct compact_call_report_capture cap = {};
u8 wire[16 + sizeof(struct epic_compact_desc) +
sizeof(struct epic_service_call) + 0x50] = {};
struct epic_compact_sub_hdr *sub = (void *)(wire + 8);
struct epic_service_call *call;

ep->services[0].ops = &compact_call_report_ops;
ep->services[0].cookie = ∩
sub->category = 0;
sub->type = EPIC_SUBTYPE_STD_SERVICE;

/* The bare service-call header immediately follows the subheader. */
call = (void *)(sub + 1);
call->group = cpu_to_le16(2);
call->command = cpu_to_le32(4);
call->data_len = cpu_to_le32(0x50);
call->magic = cpu_to_le32(EPIC_SERVICE_CALL_MAGIC);
put_unaligned_le16(0x2100, (u8 *)(call + 1));

afk_recv_compact_message(ep, 1, wire,
16 + sizeof(*call) + 0x50);
KUNIT_EXPECT_EQ(test, cap.count, 1U);
KUNIT_EXPECT_EQ(test, cap.size, sizeof(*call) + 0x50);
KUNIT_EXPECT_EQ(test, cap.magic, (u32)EPIC_SERVICE_CALL_MAGIC);
KUNIT_EXPECT_EQ(test, cap.group, 2);
KUNIT_EXPECT_EQ(test, cap.command, 4U);
KUNIT_EXPECT_EQ(test, cap.pa, 0x2100);

/* Descriptor-wrapped struct epic_service_call report still strips 8 bytes. */
memset(wire + 16, 0, sizeof(wire) - 16);
call = (void *)((u8 *)(sub + 1) + sizeof(struct epic_compact_desc));
call->group = cpu_to_le16(2);
call->command = cpu_to_le32(4);
call->data_len = cpu_to_le32(0x50);
call->magic = cpu_to_le32(EPIC_SERVICE_CALL_MAGIC);
put_unaligned_le16(0x3400, (u8 *)(call + 1));

afk_recv_compact_message(ep, 1, wire, sizeof(wire));
KUNIT_EXPECT_EQ(test, cap.count, 2U);
KUNIT_EXPECT_EQ(test, cap.size, sizeof(*call) + 0x50);
KUNIT_EXPECT_EQ(test, cap.magic, (u32)EPIC_SERVICE_CALL_MAGIC);
KUNIT_EXPECT_EQ(test, cap.pa, 0x3400);
}

/*
* Slot reuse for re-announced compact services. The firmware re-announces a
* service under a fresh interface on every DP relink without closing the old
Expand Down Expand Up @@ -210,6 +289,7 @@ static void afk_compact_siblings_kept_test(struct kunit *test)

static struct kunit_case afk_parser_cases[] = {
KUNIT_CASE(afk_serialized_report_test),
KUNIT_CASE(afk_compact_service_call_report_test),
KUNIT_CASE(afk_compact_header_test),
KUNIT_CASE(afk_short_epic_test),
KUNIT_CASE(afk_short_reply_test),
Expand Down
25 changes: 23 additions & 2 deletions drivers/gpu/drm/apple/afk.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ static bool afk_compact_capable(struct apple_dcp_afkep *ep)
ep->endpoint == AV_AUDIO_ENDPOINT_DESKTOP);
}

bool afk_compact_av_capable(struct apple_dcp *dcp)
{
return (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP &&
dcp->desktop_external) ||
dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL ||
dcp_is_v27_external(dcp);
}

static u32 afk_compact_next_status(struct apple_epic_service *service)
{
unsigned long flags;
Expand Down Expand Up @@ -1199,6 +1207,18 @@ static bool afk_compact_report_dictionary(const void *payload, size_t size)
((get_unaligned_le32(payload + sizeof(u32)) >> 24) & 0x1f) == 1;
}

/*
* A bare compact report starts with the service-call header. Its magic
* is at the usual offset from the start of the payload.
*/
static bool afk_compact_report_service_call(const void *payload, size_t size)
{
const struct epic_service_call *call = payload;

return size >= sizeof(*call) &&
get_unaligned_le32(&call->magic) == EPIC_SERVICE_CALL_MAGIC;
}

static void afk_recv_compact_message(struct apple_dcp_afkep *ep, u16 intf_id,
const void *body, size_t size)
{
Expand All @@ -1221,10 +1241,11 @@ static void afk_recv_compact_message(struct apple_dcp_afkep *ep, u16 intf_id,
return;
}
if (sub->category == 0) {
/* Preserve bare dictionaries; command-style reports have a descriptor. */
/* Preserve bare dictionaries and EPIC call headers; others carry a descriptor. */
if (sub->type == EPIC_SUBTYPE_STD_SERVICE &&
payload_size >= sizeof(struct epic_compact_desc) &&
!afk_compact_report_dictionary(payload, payload_size)) {
!afk_compact_report_dictionary(payload, payload_size) &&
!afk_compact_report_service_call(payload, payload_size)) {
payload += sizeof(struct epic_compact_desc);
payload_size -= sizeof(struct epic_compact_desc);
}
Expand Down
18 changes: 18 additions & 0 deletions drivers/gpu/drm/apple/afk.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,23 @@ static inline void afk_service_retire(struct apple_epic_service *service)
spin_unlock_irqrestore(&service->lock, flags);
}

/*
* Retire @service only if it still serves @channel; a singleton slot reused
* in place for a later announcement keeps its new channel enabled.
*/
static inline void afk_service_retire_channel(struct apple_epic_service *service,
u32 channel)
{
unsigned long flags;

spin_lock_irqsave(&service->lock, flags);
if (service->channel == channel) {
service->enabled = false;
service->torndown = true;
}
spin_unlock_irqrestore(&service->lock, flags);
}

static inline bool afk_service_matches(struct apple_epic_service *service,
u32 channel)
{
Expand Down Expand Up @@ -595,6 +612,7 @@ static inline void afk_ep_init_state(struct apple_dcp_afkep *ep)

struct apple_dcp_afkep *afk_init(struct apple_dcp *dcp, u32 endpoint,
const struct apple_epic_service_ops *ops);
bool afk_compact_av_capable(struct apple_dcp *dcp);
int afk_v2_copy_owned(struct apple_epic_service *service, u64 dva,
void *buffer, size_t size, bool to_peer);
int afk_start(struct apple_dcp_afkep *ep);
Expand Down
15 changes: 2 additions & 13 deletions drivers/gpu/drm/apple/av.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "audio.h"
#include "afk.h"
#include "av.h"
#include "cec.h"
#include "dcp.h"
#include "dcp-internal.h"

Expand Down Expand Up @@ -994,19 +995,7 @@ static const struct apple_epic_service_ops av_desktop_ops[] = {
.report = av_audiosrv_report,
.teardown = av_audiosrv_teardown,
},
{
/*
* The same endpoint also publishes the processor's CEC
* interface, cut to "dcpav-cec-interface-ep" as above. The
* host makes no use of CEC: take it and drop its reports.
*/
.name = "dcpav-cec-interface-epic",
.compact_full = "dcpav-cec-interface-epic:0",
.singleton = true,
.init = av_cec_init,
.report = av_cec_report,
.teardown = av_cec_teardown,
},
DCP_CEC_COMPACT_SERVICE_OPS,
{
/*
* And its video interface, cut to "dcpav-video-interface-" on
Expand Down
Loading
Loading