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
70 changes: 70 additions & 0 deletions drivers/gpu/drm/apple/afk-service-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,81 @@ static void afk_service_declined_channel_test(struct kunit *test)
KUNIT_EXPECT_TRUE(test, afk_service_retired(service, 3));
}

static const struct apple_epic_service_ops singleton_video_ops = {
.name = "singleton-video",
.reusable = true,
.singleton = true,
};

static const struct apple_epic_service_ops singleton_audio_ops = {
.name = "singleton-audio",
.reusable = true,
.singleton = true,
};

/*
* The firmware announces its AV video and audio interfaces again on fresh
* channels on every display attach and never closes the old ones. Announce
* them as the endpoint's receive path does: supersede, then take the first
* reclaimable slot. The superseded audio instance stays pinned by its owner
* until the successor's init drops it.
*/
static struct apple_epic_service *
afk_test_announce(struct apple_epic_service *slots, unsigned int nr,
const struct apple_epic_service_ops *ops, u32 channel)
{
unsigned int i;

for (i = 0; i < nr; i++)
afk_service_supersede(&slots[i], ops, channel);
for (i = 0; i < nr; i++)
if (afk_service_reinit(&slots[i], NULL, ops, channel))
return &slots[i];
return NULL;
}

static void afk_service_singleton_reannounce_test(struct kunit *test)
{
struct apple_epic_service *slots, *video, *audio, *owned = NULL;
const unsigned int nr = 4;
unsigned int i;
u32 channel = 5;

slots = kunit_kcalloc(test, nr, sizeof(*slots), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, slots);
for (i = 0; i < nr; i++)
spin_lock_init(&slots[i].lock);

/* Many more attaches than slots: the budget stays bounded. */
for (i = 0; i < 4 * AFK_MAX_CHANNEL; i++, channel += 4) {
video = afk_test_announce(slots, nr, &singleton_video_ops, channel);
KUNIT_ASSERT_NOT_NULL(test, video);
KUNIT_EXPECT_TRUE(test, afk_service_matches(video, channel));
audio = afk_test_announce(slots, nr, &singleton_audio_ops, channel + 2);
KUNIT_ASSERT_NOT_NULL(test, audio);
/* The audio owner pins the new instance and lets go of the old one. */
KUNIT_ASSERT_PTR_EQ(test, afk_service_get(audio), audio);
if (owned)
afk_service_put(owned);
owned = audio;
}

/* A different service is never superseded by a singleton announcement. */
KUNIT_EXPECT_FALSE(test, afk_service_supersede(owned, &singleton_video_ops, 1));
/* Nor is the instance announced on the same channel. */
KUNIT_EXPECT_FALSE(test, afk_service_supersede(owned, &singleton_audio_ops,
owned->channel));
/* Only singleton services are superseded. */
KUNIT_EXPECT_FALSE(test, afk_service_supersede(owned, &reusable_ops, 1));
afk_service_put(owned);
}

static struct kunit_case afk_service_cases[] = {
KUNIT_CASE(afk_service_admission_test),
KUNIT_CASE(dptx_service_identity_test),
KUNIT_CASE(dptx_service_duplicate_close_test),
KUNIT_CASE(afk_service_many_generations_test),
KUNIT_CASE(afk_service_singleton_reannounce_test),
KUNIT_CASE(afk_service_reader_pin_test),
KUNIT_CASE(afk_service_pending_reply_test),
KUNIT_CASE(afk_service_completed_reader_test),
Expand Down
10 changes: 10 additions & 0 deletions drivers/gpu/drm/apple/afk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,16 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel,
goto free;
}

for (ch_idx = 0; ch_idx < ep->num_channels; ch_idx++) {
struct apple_epic_service *old = &ep->services[ch_idx];

if (afk_service_supersede(old, ops, channel)) {
dev_info(ep->dcp->dev,
"AFK[ep:%02x]: %s on channel %u supersedes channel %u\n",
ep->endpoint, service_name, channel, old->channel);
afk_remove_service_debugfs(old);
}
}
for (ch_idx = 0; ch_idx < AFK_MAX_CHANNEL; ch_idx++) {
struct apple_epic_service *candidate = &ep->services[ch_idx];

Expand Down
28 changes: 28 additions & 0 deletions drivers/gpu/drm/apple/afk.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,34 @@ static inline void afk_service_retire_channel(struct apple_epic_service *service
spin_unlock_irqrestore(&service->lock, flags);
}

/*
* A singleton service has one live instance per endpoint. The firmware
* announces it again on a fresh channel when the display is attached again,
* without closing the previous channel (as for compact services, see
* afk_compact_slot()). The announcement on @channel then supersedes
* @service: retire it, so that its slot is reclaimed once its last user
* lets go. The successor's init takes over the service's state.
*/
static inline bool afk_service_supersede(struct apple_epic_service *service,
const struct apple_epic_service_ops *ops,
u32 channel)
{
unsigned long flags;
bool superseded;

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

static inline bool afk_service_matches(struct apple_epic_service *service,
u32 channel)
{
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/av.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,12 +1060,14 @@ static const struct apple_epic_service_ops avep_ops[] = {
{
.name = "DCPAVSimpleVideoInterface",
.reusable = true,
.singleton = true,
.init = av_interface_init,
.teardown = av_interface_teardown,
},
{
.name = "DCPAVAudioInterface",
.reusable = true,
.singleton = true,
.init = av_audiosrv_init,
.report = av_audiosrv_report,
.teardown = av_audiosrv_teardown,
Expand Down
5 changes: 3 additions & 2 deletions tools/asahi/dcpext26-startup-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def run(name,code,reject=False):
#define MAX_PENDING_CMDS 16
struct dcp_parse_ctx {void *dcp;const void *blob;u32 pos,len;};
struct apple_epic_service;struct apple_dcp_afkep;
struct apple_epic_service_ops {const char *name;bool reusable,optional,open_later;int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init)(struct apple_epic_service *,const char *,const char *,s64);void (*teardown)(struct apple_epic_service *);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);};
struct apple_epic_service_ops {const char *name;bool reusable,optional,open_later,singleton;int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init)(struct apple_epic_service *,const char *,const char *,s64);void (*teardown)(struct apple_epic_service *);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);};
struct apple_epic_service {struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;bool enabled,torndown,pending_open,defer_start;unsigned users;int lock;u32 channel;void *cookie;const char *pending_name,*pending_class;s64 pending_unit;int cmd_map[1];};
struct dptx_port {struct apple_epic_service *service;s64 unit;bool enabled,connected;int enable_completion;};
struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;bool afk_announced_names;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];};
Expand All @@ -108,6 +108,7 @@ def run(name,code,reject=False):
static unsigned opened[256][16],queued,published;
static int open_error;
static void afk_populate_service_debugfs(struct apple_epic_service *s){}
static void afk_remove_service_debugfs(struct apple_epic_service *s){}
static void afk_recv_handle_teardown(struct apple_dcp_afkep *e,u32 c){}
static void afk_retry_service_init(struct apple_dcp_afkep *ep);
void afk_service_retry(struct apple_dcp_afkep *ep);
Expand All @@ -119,7 +120,7 @@ def run(name,code,reject=False):
# Drop the audio-only helper region from the extracted prefix.
identity=re.sub(r'#if IS_ENABLED\(CONFIG_DRM_APPLE_AUDIO\).*?#endif','',identity,flags=re.S)
identity+=block(parser,'struct iterator {')+'\n'+fn(parser,'iterator_begin')+'\n'+fn(parser,'parse')+'\n'+fn(parser,'parse_epic_service_init')+'\n'
for name in ['afk_service_reclaimable','afk_service_reinit','afk_service_discard','afk_service_publish','afk_service_matches']:
for name in ['afk_service_reclaimable','afk_service_reinit','afk_service_discard','afk_service_publish','afk_service_matches','afk_service_supersede']:
identity+=fn(h,name)+'\n'
identity+=fn(dptx,'dptx_native_controllers_ready')+'\n'+fn(dptx,'dptx_native_controller_prepare')+'\n'+fn(dptx,'dptx_controller_service_init')+'\n'
for name in ['afk_match_service','afk_epic_find_service','afk_discard_pending_open','afk_retry_service_init','afk_service_retry']:
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/drivers/gpu/apple-dcp/edid.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def function(file,signature):
struct apple_dcp;struct apple_dcp_afkep;struct apple_epic_service;
void afk_service_retry(struct apple_dcp_afkep *ep);
/* open_later: a firmware 27 panel service that sends its own OPEN; none is here. */
struct apple_epic_service_ops { char name[32];bool reusable,optional,open_later;void (*init)(struct apple_epic_service *,const char *,const char *,s64);int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);void (*teardown)(struct apple_epic_service *); };
struct apple_epic_service_ops { char name[32];bool reusable,optional,open_later,singleton;void (*init)(struct apple_epic_service *,const char *,const char *,s64);int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);void (*teardown)(struct apple_epic_service *); };
struct epic_cmd_info { u16 tag;u8 type;size_t reply_length,reply_len;bool reply_len_valid;void *rxbuf,*txbuf;dma_addr_t rxbuf_dma,txbuf_dma;size_t rxlen,txlen;u32 retcode;bool done,free_on_ack;int *completion; };
struct apple_epic_service {
struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;
Expand Down Expand Up @@ -183,7 +183,7 @@ def function(file,signature):
function('epic/dpavservep.c','static void dcpavserv_teardown('),function('epic/dpavservep.c','void dpavservep_detach('),
function('afk.c','static const struct apple_epic_service_ops *\nafk_match_service('),
function('afk.c','static struct apple_epic_service *afk_epic_find_service('),
function('afk.h','static inline bool afk_service_retired('),function('afk.c','static bool afk_epic_channel_retired('),
function('afk.h','static inline bool afk_service_retired('),function('afk.h','static inline bool afk_service_supersede('),function('afk.c','static bool afk_epic_channel_retired('),
function('afk.c','static void afk_discard_pending_open('),function('afk.c','static void afk_retry_service_init('),function('afk.c','static void afk_service_worker('),function('afk.c','static void afk_recv_handle_init('),
function('epic/dpavservep.c','static int dcpdpserv_prepare('),
function('epic/dpavservep.c','static void dcpdpserv_teardown('),function('afk.c','static void afk_recv_handle_teardown('),
Expand Down
Loading