diff --git a/drivers/gpu/drm/asahi/g17/mod.rs b/drivers/gpu/drm/asahi/g17/mod.rs index c3f3a783d5f22..ba849d7c70bdf 100644 --- a/drivers/gpu/drm/asahi/g17/mod.rs +++ b/drivers/gpu/drm/asahi/g17/mod.rs @@ -648,11 +648,7 @@ impl Coprocessor { ) -> Result> { for attempt in 0..RECEIVER_ATTEMPTS { match rtkit::RtKit::::new(dev.as_ref().as_ref(), None, index, state.clone()) { - Ok(receiver) => { - // Its OSLOG counters stay unanswered until a soak shows echoing them is safe. - receiver.set_oslog_echo(false); - return Ok(receiver); - } + Ok(receiver) => return Ok(receiver), Err(error) if error == EINVAL || error == ETIMEDOUT => { if attempt + 1 < RECEIVER_ATTEMPTS { fsleep(Delta::from_millis(RECEIVER_RETRY_MS)); diff --git a/drivers/soc/apple/rtkit-internal.h b/drivers/soc/apple/rtkit-internal.h index fedfa637a6b20..20ee592e698c5 100644 --- a/drivers/soc/apple/rtkit-internal.h +++ b/drivers/soc/apple/rtkit-internal.h @@ -88,7 +88,10 @@ struct apple_rtkit { * hand out kdebug buffers, and poll the mailbox while waiting. */ bool sync_syslog_ack; - /* Echo each OSLOG channel-0 counter, as macOS does. */ + /* + * Echo each OSLOG channel-0 counter, as macOS does. On unless the node has + * apple,sync-syslog-ack or the client turned it off; off drops the counters. + */ bool oslog_echo; /* A counter queued for the receive work and not yet echoed. */ u64 oslog_owed; @@ -158,7 +161,6 @@ struct apple_rtkit { bool crashlog_inherited; /* The crash log buffer is the firmware's own, mapped here when it crashed. */ bool crashlog_placed; - bool oslog_inherited; /* A crash reported before the crashlog buffer was mapped: the log is * read once the co-processor has written it. */ diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 5c96f3ac054a0..8eaca927905f1 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -102,7 +102,6 @@ enum { #define APPLE_RTKIT_OSLOG_TYPE GENMASK_ULL(63, 56) #define APPLE_RTKIT_OSLOG_BUFFER_REQUEST 1 #define APPLE_RTKIT_OSLOG_LOG 2 -#define APPLE_RTKIT_OSLOG_LOG_RESERVED GENMASK_ULL(55, 32) #define APPLE_RTKIT_OSLOG_SIZE GENMASK_ULL(55, 36) #define APPLE_RTKIT_OSLOG_IOVA GENMASK_ULL(35, 0) @@ -1410,25 +1409,6 @@ static void apple_rtkit_syslog_rx(struct apple_rtkit *rtk, u64 msg) } } -/* Where a counter has only ever run unanswered: nothing is echoed. */ -static bool apple_rtkit_oslog_unanswered(struct apple_rtkit *rtk) -{ - return !rtk->oslog_echo && - (rtk->sync_syslog_ack || of_machine_is_compatible("apple,t8140") || - of_machine_is_compatible("apple,t8142")); -} - -/* An OSLOG counter that is answered with its echo, on any lane. */ -static bool apple_rtkit_oslog_echoed(struct apple_rtkit *rtk, u64 msg) -{ - if (rtk->oslog_echo) - return true; - if (apple_rtkit_oslog_unanswered(rtk)) - return false; - return (rtk->oslog_buffer.size || rtk->oslog_inherited) && - !(msg & APPLE_RTKIT_OSLOG_LOG_RESERVED); -} - static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) { u8 type = FIELD_GET(APPLE_RTKIT_OSLOG_TYPE, msg); @@ -1438,6 +1418,8 @@ static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) * A firmware counts its log writes and holds the next counter until the last is * echoed, and with one outstanding takes no AP power notice: a DCP after a warm * restart, the MTP and the SMC after about eight sleeps. macOS echoes every one. + * The counter is cumulative, so echoing the newest one acknowledges every write + * before it. */ if (type == APPLE_RTKIT_OSLOG_LOG && rtk->oslog_echo) { /* A polled idle that came first echoed it already. */ @@ -1452,13 +1434,9 @@ static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) return; } - if (type == APPLE_RTKIT_OSLOG_LOG && !apple_rtkit_oslog_echoed(rtk, msg)) { - /* Preserve the tested Neo/M5 and synchronous-log no-ACK policy. */ - if (apple_rtkit_oslog_unanswered(rtk)) - dev_dbg(rtk->dev, "RTKit: oslog notification: %016llx\n", msg); - else - dev_warn_ratelimited(rtk->dev, "RTKit: invalid oslog notification: %llx\n", - msg); + /* Where the echo is off (apple_rtkit_set_oslog_echo()), the counter is dropped. */ + if (type == APPLE_RTKIT_OSLOG_LOG) { + dev_dbg(rtk->dev, "RTKit: oslog notification: %016llx\n", msg); return; } @@ -1467,20 +1445,6 @@ static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) apple_rtkit_common_rx_get_buffer(rtk, &rtk->oslog_buffer, APPLE_RTKIT_EP_OSLOG, msg); break; - case APPLE_RTKIT_OSLOG_LOG: - /* Channel zero reports a cumulative 32-bit write counter. Even - * though we discard these logs, acknowledge that exact counter: - * AppleDCP waits for its log transport to drain before AP sleep. - * This is not a buffer offset and may wrap. Other channels do not - * have a buffer admitted by this endpoint implementation. An inherited - * channel zero needs no buffer mapping to acknowledge its counter - * (apple_rtkit_oslog_echoed()). - */ - err = apple_rtkit_send_message(rtk, APPLE_RTKIT_EP_OSLOG, - msg, NULL, false); - if (err) - dev_err(rtk->dev, "RTKit: oslog acknowledgment failed: %d\n", err); - break; case 3 ... 5: /* * Undocumented notifications sent during normal operation. They @@ -1904,8 +1868,7 @@ static bool apple_rtkit_log_word(struct apple_rtkit *rtk, u8 ep, u64 msg) if (ep == APPLE_RTKIT_EP_SYSLOG) return apple_rtkit_notification_msg(ep, msg); return ep == APPLE_RTKIT_EP_OSLOG && - FIELD_GET(APPLE_RTKIT_OSLOG_TYPE, msg) == APPLE_RTKIT_OSLOG_LOG && - apple_rtkit_oslog_echoed(rtk, msg); + FIELD_GET(APPLE_RTKIT_OSLOG_TYPE, msg) == APPLE_RTKIT_OSLOG_LOG && rtk->oslog_echo; } int apple_rtkit_m5_saved_poll(struct apple_rtkit *rtk) @@ -2384,7 +2347,6 @@ static void apple_rtkit_mark_running(struct apple_rtkit *rtk) rtk->ap_power_state = APPLE_RTKIT_PWR_STATE_ON; rtk->syslog_inherited = true; rtk->crashlog_inherited = true; - rtk->oslog_inherited = true; } static int apple_rtkit_claim_rx(struct apple_rtkit *rtk) @@ -2576,13 +2538,17 @@ static struct apple_rtkit *__apple_rtkit_init(struct device *dev, void *cookie, rtk->sync_syslog_ack = of_property_read_bool(dev->of_node, "apple,sync-syslog-ack"); /* - * As macOS does; a driver whose firmware shouldn't get them turns it off. T8142 too: - * its MTP left a counter unechoed after the first sleep's resume, then took no AP - * idle notice for the next one (J815, -ETIME at prepare) and asserted on the one - * after ("Invalid AP power"). + * Echo every OSLOG channel-0 counter, as macOS does. This is the OSLOG protocol of + * every RTKit firmware that sends counters: it holds the next one until the last is + * echoed and takes no AP power notice while one is outstanding (T8140, and the J815 + * MTP, whose second sleep failed at prepare with -ETIME without it). The IOP sends + * no version or capability for this; a firmware that does not use the protocol + * sends no counters, so the echo never goes out. apple,sync-syslog-ack turns it + * off: the dcpext that carries it (T8122) has only run with its counters + * unanswered; a DCP driver that restarts its DCP across a sleep turns the echo + * back on. */ - rtk->oslog_echo = of_machine_is_compatible("apple,t8140") || - of_machine_is_compatible("apple,t8142"); + rtk->oslog_echo = !rtk->sync_syslog_ack; rtk->m5_saved.tracked = track_saved; atomic_set(&rtk->m5_saved.jobs, 0); atomic_set(&rtk->v27_jobs, 0); @@ -2910,7 +2876,6 @@ static void apple_rtkit_reset_session(struct apple_rtkit *rtk, bool keep_buffers rtk->syslog_msg_size = 0; rtk->syslog_inherited = false; rtk->crashlog_inherited = false; - rtk->oslog_inherited = false; } bitmap_zero(rtk->endpoints, APPLE_RTKIT_MAX_ENDPOINTS); diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index a3d7678c62c64..da14ebcd4a5b2 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -449,8 +449,9 @@ int apple_rtkit_power_cycled_return(struct apple_rtkit *rtk, void __iomem *cpu_c int apple_rtkit_sleep_return_start(struct apple_rtkit *rtk, void __iomem *cpu_control); /* - * Echo each OSLOG channel-0 counter the firmware sends, as macOS does. On by default on - * T8140, where a firmware with one outstanding takes no AP power notice. + * Echo each OSLOG channel-0 counter the firmware sends, as macOS does, or drop them. On by + * default (off on a node with apple,sync-syslog-ack): a firmware with one outstanding + * takes no AP power notice. */ void apple_rtkit_set_oslog_echo(struct apple_rtkit *rtk, bool echo); diff --git a/tools/asahi/rtkit-oslog-tests.py b/tools/asahi/rtkit-oslog-tests.py index d1dd8f8b919b5..d19b24e3c03dc 100644 --- a/tools/asahi/rtkit-oslog-tests.py +++ b/tools/asahi/rtkit-oslog-tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only OR MIT -"""Check OSLog counter acknowledgements and inherited-session reset.""" +"""Check the OSLog counter echo policy and the session reset.""" import argparse import hashlib import json @@ -61,7 +61,7 @@ def function(source, name): int sync_ack_fifo; int ioreport_lock, ioreport_state_lock; enum apple_rtkit_ioreport_state ioreport_state; - bool sync_syslog_ack, oslog_inherited, syslog_inherited, crashlog_inherited, crashed, shutting_down; + bool sync_syslog_ack, syslog_inherited, crashlog_inherited, crashed, shutting_down; bool oslog_echo; u64 oslog_owed; /* Read only by the J714s firmware 27 sleep; a failed echo sets it. */ @@ -77,9 +77,6 @@ def function(source, name): static unsigned sent, warnings, errors, requests, detachments, flushes, freed, checks; static int send_error, setup_error, start_error; static u64 sent_message; -static bool neo, m5; -static bool of_machine_is_compatible(const char *s) -{ return (!strcmp(s, "apple,t8140") && neo) || (!strcmp(s, "apple,t8142") && m5); } #define kfifo_reset(f) (*(f)=0) #define dev_dbg(...) ((void)0) #define dev_warn(...) (++warnings) @@ -108,12 +105,13 @@ def function(source, name): MAIN = r''' static void reset(void) { sent=warnings=errors=requests=0; send_error=setup_error=0; } -static void event(struct apple_rtkit *r, u64 msg, bool ack) +/* A counter as the receive work sees it: owed is what the IRQ path recorded. */ +static void event(struct apple_rtkit *r, u64 msg, u64 owed, bool echo) { - reset(); apple_rtkit_oslog_rx(r,msg); - assert(sent==(unsigned)ack && requests==0 && errors==0); - if (ack) { assert(sent_message==msg && warnings==0); } - else { assert(warnings==1); } + reset(); r->oslog_owed=owed; apple_rtkit_oslog_rx(r,msg); + assert(sent==(unsigned)echo && requests==0 && errors==0 && warnings==0); + if (echo) assert(sent_message==msg && r->oslog_owed==0); + else assert(r->oslog_owed==owed); ++checks; } int main(void) @@ -121,50 +119,55 @@ def function(source, name): struct mailbox m={0}; struct apple_rtkit r={.mbox=&m}; const u64 type=(u64)APPLE_RTKIT_OSLOG_LOG<<56; const uint32_t counters[]={0,1,4095,4096,UINT32_MAX,0,0x80000000}; - for (unsigned owner=0; owner<3; owner++) { - r.oslog_buffer.size=owner==1?4096:0; r.oslog_inherited=false; - if (owner==2) { apple_rtkit_mark_running(&r); assert(r.oslog_inherited); } - for (unsigned i=0;i=3 && kind<=5)) continue; - event(&r,(u64)kind<<56,false); + for (unsigned echo=0; echo<2; echo++) { + for (unsigned owner=0; owner<3; owner++) { + memset(&r,0,sizeof(r)); r.mbox=&m; r.oslog_echo=echo; + r.oslog_buffer.size=owner==1?4096:0; + if (owner==2) apple_rtkit_mark_running(&r); + // Echoed exactly when the echo is on, with or without a buffer, on any channel. + for (unsigned i=0;i=3 && kind<=5)) continue; + reset(); apple_rtkit_oslog_rx(&r,(u64)kind<<56); + assert(warnings==1 && sent==0); ++checks; + } } } for (unsigned fail=0;fail<2;fail++) { - memset(&r,0,sizeof(r));r.mbox=&m; reset();setup_error=fail?-5:0; + memset(&r,0,sizeof(r));r.mbox=&m;r.oslog_echo=true; reset();setup_error=fail?-5:0; const u64 req=((u64)APPLE_RTKIT_OSLOG_BUFFER_REQUEST<<56)|(4096ULL<<36); apple_rtkit_oslog_rx(&r,req); assert(requests==1 && sent==0); - event(&r,type|UINT32_MAX,!fail);++checks; + event(&r,type|UINT32_MAX,type|UINT32_MAX,true); } - r.oslog_buffer.size=4096; for (unsigned failure=0;failure<2;failure++) { - reset();send_error=failure?-5:0;apple_rtkit_oslog_rx(&r,type|UINT32_MAX); - assert(sent==1 && sent_message==(type|UINT32_MAX));assert(errors==failure && warnings==0);++checks; + memset(&r,0,sizeof(r));r.mbox=&m;r.oslog_echo=true; + reset();send_error=failure?-5:0;r.oslog_owed=type|UINT32_MAX;apple_rtkit_oslog_rx(&r,type|UINT32_MAX); + assert(sent==1 && sent_message==(type|UINT32_MAX));assert(errors==failure && warnings==0); + assert(r.v27_rx_failed==failure);++checks; } for (unsigned fail=0;fail<2;fail++) { - memset(&r,0,sizeof(r));r.mbox=&m;apple_rtkit_mark_running(&r); - assert(r.oslog_inherited && (r.endpoints[0]&(1UL<size=4096; r.crashed=true;r.syslog_msg_size=128; detachments=flushes=freed=0;start_error=fail?-5:0; assert(apple_rtkit_reinit(&r)==start_error); - assert(!r.oslog_inherited && !r.syslog_inherited && !r.crashlog_inherited); + assert(!r.syslog_inherited && !r.crashlog_inherited); assert(!r.crashed && !r.syslog_msg_size && freed==ARRAY_SIZE(buffers)); // Every buffer of the old firmware session goes, the OSLog one included. for (unsigned i=0;isize); assert(r.endpoints[0]==(1UL<oslog_buffer.size && !rtk->oslog_inherited)', 'false') - bodies = bodies.replace('(rtk->oslog_buffer.size || rtk->oslog_inherited)', 'true') - elif args.mutate == 'channel': - bodies = bodies.replace('(msg & APPLE_RTKIT_OSLOG_LOG_RESERVED)', 'false') + if args.mutate == 'owed': + bodies = bodies.replace('cmpxchg(&rtk->oslog_owed, msg, 0) != msg', 'false') + elif args.mutate == 'policy': + bodies = bodies.replace('type == APPLE_RTKIT_OSLOG_LOG && rtk->oslog_echo', 'type == APPLE_RTKIT_OSLOG_LOG') elif args.mutate == 'counter': bodies = bodies.replace('msg, NULL, false);', '(msg & ~0xffffffffULL) | ((u32)msg % 4096), NULL, false);') elif args.mutate == 'reset': - bodies = bodies.replace('rtk->oslog_inherited = false;', 'rtk->oslog_inherited = true;') + bodies = bodies.replace('rtk->syslog_inherited = false;', 'rtk->syslog_inherited = true;') elif args.mutate == 'buffer': bodies = bodies.replace('apple_rtkit_free_buffer(rtk, &rtk->oslog_buffer);', '') # A mutation that no longer matches the driver would test nothing. diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index d3b19ac23ed4c..0d5213d526dc3 100644 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -732,7 +732,7 @@ def mutations(flag, names, base, expect=KILL): 'rtkit-crashlog-map-tests.py': [(out(), PASS), (out() + ['--old-ref', 'cacf35543b4d534fccef3033bd2ddbb415a325b2'], PASS)], 'rtkit-oslog-tests.py': [(out(), PASS)] - + mutations('--mutate', ('admission', 'channel', 'counter', 'reset', 'buffer'), out()), + + mutations('--mutate', ('owed', 'policy', 'counter', 'reset', 'buffer'), out()), 'rtkit-adopted-session-tests.py': [(out(), PASS)] + mutations('--mutation', ('no-management', 'any-system', 'any-version', 'ignore-ops-version', 'any-buffer-endpoint'), out()), diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index 779fe70019576..6ad95083dc6b9 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -9,11 +9,6 @@ def oslog(root): source = (root / 'drivers/soc/apple/rtkit.c').read_text() constants = '\n'.join(line for line in source.splitlines() if line.startswith('#define APPLE_RTKIT_OSLOG_')) - # The echo's predicate, where the receiver is built on one. - helpers = ''.join(block(source, marker) + '\n' - for marker in ('static bool apple_rtkit_oslog_unanswered(', - 'static bool apple_rtkit_oslog_echoed(') - if marker in source) return r''' #include #include @@ -27,7 +22,7 @@ def oslog(root): #define APPLE_RTKIT_EP_OSLOG 8 struct buffer { unsigned sentinel; unsigned size; }; /* v27_rx_failed: read only by the J714s firmware 27 sleep; a failed echo sets it. */ -struct apple_rtkit { void *dev; struct buffer oslog_buffer; bool oslog_inherited, sync_syslog_ack, oslog_echo; u64 oslog_owed; bool v27_rx_failed; }; +struct apple_rtkit { void *dev; struct buffer oslog_buffer; bool sync_syslog_ack, oslog_echo; u64 oslog_owed; bool v27_rx_failed; }; #define cmpxchg(p,o,n) __sync_val_compare_and_swap((p),(o),(n)) #define WRITE_ONCE(x,v) ((x)=(v)) /* As the shared Apple configuration builds it. */ @@ -35,8 +30,6 @@ def oslog(root): #define IS_ENABLED(option) (option) static unsigned warnings, notifications, requests, acks, errors; static u64 observed; -static bool neo, m5; -#define of_machine_is_compatible(s) ((!strcmp(s,"apple,t8140") && neo) || (!strcmp(s,"apple,t8142") && m5)) #define dev_warn(dev,fmt,msg) do { (void)(dev); (void)(fmt); warnings++; observed=(msg); } while (0) #define dev_warn_ratelimited(dev,fmt,msg) dev_warn(dev,fmt,msg) #define dev_dbg(dev,fmt,msg) do { (void)(dev); (void)(fmt); notifications++; observed=(msg); } while (0) @@ -45,12 +38,12 @@ def oslog(root): { (void)rtk; assert(ep==8 && !completion && !atomic); acks++; observed=msg; return 0; } static void apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk, struct buffer *b, u8 ep, u64 msg) { assert(b==&rtk->oslog_buffer && ep==8); requests++; observed=msg; } -''' + constants + '\n' + helpers + block(source, 'static void apple_rtkit_oslog_rx(') + r''' +''' + constants + '\n' + block(source, 'static void apple_rtkit_oslog_rx(') + r''' static void reset(void) { warnings=notifications=requests=acks=errors=0; observed=0; } int main(void) { + /* Echo off: a client turned it off, or the node has apple,sync-syslog-ack. */ struct apple_rtkit rtk={.oslog_buffer={.sentinel=0x12345678}}; - neo=true; for (u8 type=2; type<=5; type++) { for (unsigned edge=0; edge<2; edge++) { u64 msg=((u64)type<<56) | (edge ? ((1ULL<<56)-1) : 0); @@ -72,28 +65,30 @@ def oslog(root): assert(requests==1 && !warnings && !notifications && observed==(1ULL<<56)); puts("PASS buffer requests retain existing dispatch"); #ifdef APPLE_RTKIT_OSLOG_LOG - /* Other machines acknowledge only admitted channel-zero counters. */ - neo=m5=false; - reset(); apple_rtkit_oslog_rx(&rtk,2ULL<<56); - assert(warnings==1 && !acks && !notifications); - for (unsigned inherited=0; inherited<2; inherited++) { - rtk.oslog_buffer.size=inherited ? 0 : 4096; - rtk.oslog_inherited=inherited; - reset(); apple_rtkit_oslog_rx(&rtk,(2ULL<<56)|UINT32_MAX); - assert(acks==1 && !warnings && observed==((2ULL<<56)|UINT32_MAX)); - reset(); apple_rtkit_oslog_rx(&rtk,(2ULL<<56)|(1ULL<<32)); - assert(warnings==1 && !acks); - } - /* Each tested platform policy overrides channel and buffer admission. */ - rtk.oslog_inherited=false; - for (unsigned policy=0; policy<3; policy++) { - neo=policy==0; m5=policy==1; rtk.sync_syslog_ack=policy==2; - reset(); apple_rtkit_oslog_rx(&rtk,(2ULL<<56)|(1ULL<<32)); - assert(notifications==1 && !warnings && !acks); + /* Echo on (every RTKit by default): the exact counter goes back, whatever its + * channel bits and whether or not a buffer was negotiated. */ + rtk.oslog_echo=true; + const u64 counters[]={2ULL<<56, (2ULL<<56)|UINT32_MAX, (2ULL<<56)|(1ULL<<32), (2ULL<<56)|((1ULL<<56)-1)}; + for (unsigned buffer=0; buffer<2; buffer++) { + rtk.oslog_buffer.size=buffer ? 4096 : 0; + for (unsigned i=0; i