Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
Wi-Fi: mission mode, and the radio's registers answer
vcvkk1c0dcae6a079
diff --git a/prebuilt/SHA256SUMS b/prebuilt/SHA256SUMSindex bcf3222..17beffa 100644--- a/prebuilt/SHA256SUMS+++ b/prebuilt/SHA256SUMS@@ -1,6 +1,6 @@-Built 2026-10-13 15:40 from this tree.+Built 2026-10-13 18:03 from this tree.-bdcdc18746553734d7da47971d3d68f07b158d316a2b8862d8d61f5e42747d4b prebuilt/mach.development.bcm2837+da06e84cf381e3b8f9a8b8d4e06ff56bf99fb6d9b2b52d679448d9bc8377e3ab prebuilt/mach.development.bcm28371332a598d2dec00a1d8e930044e4f00a12ad44c6e5e50eecf4b7fe7fae803bf2 prebuilt/loader.efid2a35a4a1d6658ffb3696914f727661b52c9333de8a3af8a31642b8023ce03ac prebuilt/userland/child1a413befd511384052e1962c1394adce20f718e1f2657ce63ab09828ebc4bd1b prebuilt/userland/cpu_testdiff --git a/prebuilt/mach.development.bcm2837 b/prebuilt/mach.development.bcm2837index 8fa5c73..1717236 100755Binary files a/prebuilt/mach.development.bcm2837 and b/prebuilt/mach.development.bcm2837 differdiff --git a/xnu/files/bsd/dev/redwood_wifi.c b/xnu/files/bsd/dev/redwood_wifi.cindex b40d388..45fc9a9 100644--- a/xnu/files/bsd/dev/redwood_wifi.c+++ b/xnu/files/bsd/dev/redwood_wifi.c@@ -53,12 +53,15 @@* of ours looks the Wi-Fi firmware's service up (sys/redwood_qrtr.h)* 15 talks to the Wi-Fi firmware's service, what a WCN6750's driver says to it before it* touches the radio: a stand-in for ath11k's own code, see redwood_wlfw.c+ * 16 reads seven words of the radio's registers, where the firmware said they are: only+ * with wifi_radio_read=1, and only with the firmware in mission mode (outside+ * it a read there has ended the kernel)* Steps 1 to 5 are the survey; they write to nothing but the arbiter's command word.*- * What is started is stopped: when the steps are over, and wherever a run ends in order while- * the DSP runs, TrustZone is asked to shut the DSP down and the always-on processor is told- * that the image is gone. A run that ends otherwise leaves the DSP running, and the kernel- * after it cannot ask the hardware whether that is so. But the shared memory outlives our+ * What is started is stopped: when the steps are over, wherever a run ends in order while the+ * DSP runs, and on a panic's way back to the loader, TrustZone is asked to shut the DSP down+ * and the always-on processor is told that the image is gone. A kernel that dies otherwise+ * leaves the DSP running, and the kernel after it cannot ask the hardware whether that is so. But the shared memory outlives our* kernels (the phone is not restarted between them), and the DSP's own item in it is there if* and only if the DSP has run since the phone was started: when step 8 finds it, TrustZone is* first asked for the shutdown. On a phone just started nothing is asked that is not needed.@@ -89,6 +92,8 @@* wifi_cal=1 step 15 asks for cold-boot calibration as ath11k does when it is on, and* waits up to a minute for it; wifi_ready=S: how long it waits for* "firmware ready" otherwise (default 5)+ * wifi_mission=1 step 15 goes on to the configuration and the mode "mission"+ * wifi_radio_read=1 step 16 does read (2: whatever mode the firmware is in)* wifi_keep=1 when the steps are over the DSP and the link stay up while the system* runs, for whoever uses sys/redwood_qrtr.h; stopped when the run ends* wifi_dirty=1 the DSP is not stopped: left as a kernel that died leaves it@@ -149,6 +154,7 @@ extern void loader_log_putc(char c);static int say(const char *format, ...) __printflike(1, 2);static LCK_MTX_DECLARE(say_lock, &wifi_lock_group); /* two threads talk here: a line at a time */+static bool leaving; /* on the way back to the loader after a panic: no lock is taken, nothing sleeps */static intsay(const char *format, ...)@@ -158,8 +164,14 @@ say(const char *format, ...)int length;va_start(list, format);- vsnprintf(line, sizeof(line), format, list);+ length = vsnprintf(line, sizeof(line), format, list);va_end(list);+ if (leaving) {+ for (const char *c = line; *c != 0; c++) {+ loader_log_putc(*c);+ }+ return length;+ }lck_mtx_lock(&say_lock);for (const char *c = line; *c != 0; c++) {loader_log_putc(*c);@@ -1503,7 +1515,7 @@ dsp_listen(const struct smp2p *theirs)* True: the DSP has stopped by its own word, now or (its entry still says so) before.*/static bool-dsp_ask_to_stop(void)+dsp_ask_to_stop(uint32_t bound_ms){struct smp2p ours, theirs;uint32_t at = our_item_find(), state, value_at;@@ -1537,7 +1549,7 @@ dsp_ask_to_stop(void)settle();wr(ipcc.base + IPCC_SEND, IPCC_WPSS << 16 | IPCC_SMP2P);asked = now = now_us();- while (now - asked < 5 * 1000000ull) {+ while (now - asked < bound_ms * 1000ull) {if (dsp_words(&theirs) && (dsp_state(&theirs) & (DSP_STOP_ACK | DSP_FATAL))) {break;}@@ -1621,8 +1633,11 @@ dsp_shutdown(const char *why)int32_t result;printf("wifi: %u: %s: the DSP is asked to stop, then TrustZone to shut it down\n", step, why);- link_stop();- stopped_by_its_word = dsp_ask_to_stop();+ if (!leaving) {+ redwood_wlfw_stop(step); /* (what the stand-in of step 15 has to say first, while there is a link) */+ link_stop();+ }+ stopped_by_its_word = dsp_ask_to_stop(leaving ? 2000 : 5000);result = scm("to shut the Wi-Fi DSP down", SCM_PAS_SHUTDOWN, SCM_ONE_VALUE, PAS_WPSS, 0, 0, &answer);if (result != 0 || answer != 0) {printf("wifi: %u: TRUSTZONE DOES NOT SHUT THE DSP DOWN: the call returns %d, its answer is %#llx\n", step, result, answer);@@ -3099,6 +3114,103 @@ step_exchange(void)return redwood_wlfw_exchange(step);}+/* ---- step 16: the radio's registers, looked at ------------------------------------------------------- */++/*+ * The firmware says where the radio's registers are (step 15: 0x61e00000, 2 MB), and ath11k+ * maps that address as it is and reads and writes there: no SMMU is involved, it is the+ * processor's own view (qmi.c: ath11k_qmi_request_device_info(), devm_ioremap()). In the+ * phone's device tree the address is no device's: it lies in the memory window of the first+ * PCIe controller (pcie@1c00000: "ranges" 0x60300000 + 0x3d00000), whose node the tree keeps+ * for another use. Whether a kernel under this phone's hypervisor may read there is what this+ * step asks, with four reads and no write.+ *+ * THE ANSWER: YES, ONCE THE FIRMWARE IS IN MISSION MODE, AND ONLY THEN. With the firmware+ * calibrated and "ready" but in no mode, the first read ended the kernel with an asynchronous+ * abort -- a bus error, where the DSP's clocks, which the hypervisor keeps to itself, gave a+ * synchronous one -- and half a minute later the phone restarted by itself (the panic had left+ * the DSP running; a panic's way back now stops it, and with that the phone stays up). After+ * the configuration and the mode "mission" (step 15 with wifi_mission=1), which is when ath11k+ * begins to use the registers, all seven words below read: the copy engines' rings at zero,+ * copy engine 1's control 0x80, the reorder block's enable 0x3000150, and 0x40140110 where the+ * chip's PCI siblings have their hardware version. ath11k has no wake-up to make before an+ * access on this chip and no window register to write (ahb.c: the pci_ops for wcn6750 have+ * neither, and the windows are fixed). So the step reads only in mission mode, and only when+ * told to (wifi_radio_read=1; 2: in any state, which HAS ENDED THE KERNEL).+ *+ * The 2 MB are not the chip's registers one to one (ahb.c: ath11k_ahb_get_window_start_wcn6750()):+ * the first 512K are, the second 512K show the chip's 512K at 0xa00000 (the data path), the+ * third those at 0x1b80000 (the copy engines). The words read: the two ath11k itself reads+ * first when it sets the chip up (hal.c: the control word of copy engine 1's destination ring;+ * hw.c: the reorder block's "general enable"), the reorder ring's id word, and the word where+ * this chip's PCI siblings have their hardware version (pci.c: TCSR_SOC_HW_VERSION), which this+ * one may or may not have.+ */+#define RADIO_WINDOW 0x80000u+#define RADIO_DATA_PATH 0x00a00000u /* hal.h: HAL_SEQ_WCSS_UMAC_OFFSET */+#define RADIO_COPY_ENGINES 0x01b80000u /* hw.c: wcn6750_regs.hal_seq_wcss_umac_ce0_src_reg */++static bool+step_registers(void)+{+ /*+ * The first: the word ath11k touches first once the firmware is in mission mode (it writes+ * it: ce.c: ath11k_ce_init_pipes() begins with copy engine 0's source ring, and hal.c:+ * ath11k_hal_srng_src_hw_init() with that ring's interrupt address). The rest only if the+ * first answers: the ring's base and id, the first word ath11k reads (copy engine 1's+ * destination ring control), the reorder block's two, and the hardware version of this+ * chip's PCI siblings.+ */+ static const struct {+ uint32_t chip; /* the register's address in the chip */+ const char *name;+ } words[] = {+ { 0x01b80000 + 0x48, "copy engine 0, source ring, interrupt address (low)" },+ { 0x01b80000 + 0x00, "copy engine 0, source ring, base (low)" },+ { 0x01b80000 + 0x08, "copy engine 0, source ring, id" },+ { 0x01b83000 + 0xb0, "copy engine 1, destination ring control" },+ { 0x00a38000 + 0x000, "reorder block, general enable" },+ { 0x00a38000 + 0x1f4, "reorder ring 1, id" },+ { 0x00000224, "hardware version (if this chip has it where its siblings do)" },+ };+ static struct block radio = { "radio", 0, 0 };+ uint64_t address = 0;+ uint32_t size = 0, asked = 0;+ bool mission = false;++ if (!redwood_wlfw_registers(&address, &size, &mission) || address > 0xffffffffull || size < 3 * RADIO_WINDOW) {+ printf("wifi: %u: the firmware has not said where the radio's registers are (step 15)\n", step);+ return false;+ }+ PE_parse_boot_argn("wifi_radio_read", &asked, sizeof(asked));+ if (asked == 0 || (!mission && asked < 2)) {+ printf("wifi: %u: THE RADIO'S REGISTERS (%#llx) ARE NOT READ: %s (see the top of this step in redwood_wifi.c)\n", step,+ address, asked == 0 ? "not asked for (wifi_radio_read=1)" : "the firmware is not in mission mode (wifi_mission=1), "+ "and outside it a read there has ended the kernel with a bus error (wifi_radio_read=2 to read all the same)");+ return false;+ }+ announce("read the radio's registers where the firmware says they are, the word ath11k touches first before any other; "+ "if nothing answers there the kernel ends at that read");+ printf("wifi: %u: the registers: %#x bytes at %#llx; the firmware %s\n", step, size, address, mission ? "is in mission mode" :+ "IS NOT IN MISSION MODE (wifi_mission=1 gets it there): the state in which the read failed before");+ radio.phys = (uint32_t)address;+ radio.size = size;+ radio.base = ml_io_map_unmappable(radio.phys, radio.size, VM_WIMG_IO);+ for (unsigned i = 0; i < sizeof(words) / sizeof(words[0]); i++) {+ uint32_t chip = words[i].chip, at;++ /* ahb.c: which of the three windows a register of the chip is seen through, and where in it */+ at = chip < RADIO_WINDOW ? chip : (chip ^ RADIO_DATA_PATH) < RADIO_WINDOW ? RADIO_WINDOW + (chip & (RADIO_WINDOW - 1)) :+ 2 * RADIO_WINDOW + (chip & (RADIO_WINDOW - 1));+ printf("wifi: %u: about to read the radio's %s (the chip's %#x) at %#x\n", step, words[i].name, chip, radio.phys + at);+ snprintf(last_write, sizeof(last_write), "step %u was reading the radio's registers at %#x", step, radio.phys + at);+ sleep_ms(i == 0 ? pause_ms : 50);+ printf("wifi: %u: THE RADIO'S %s (%#x) = %#x\n", step, words[i].name, radio.phys + at, rd(radio.base + at));+ }+ ml_io_unmap(radio.base, radio.size);+ return true;+}+static boolstep_qrtr(void){@@ -3216,7 +3328,7 @@ smmu_look(void)static bool(*const steps[])(void) = {step_smem, step_mailbox, step_rpmh, step_rails, step_pins, step_firmware, step_mailbox_open, step_header, step_image,- step_our_item, step_start, step_queues, step_link, step_qrtr, step_exchange,+ step_our_item, step_start, step_queues, step_link, step_qrtr, step_exchange, step_registers,};#define STEPS ((uint32_t)(sizeof(steps) / sizeof(steps[0])))@@ -3234,6 +3346,25 @@ redwood_wifi_stop(void)lck_mtx_unlock(&dsp_lock);}+/*+ * The same when the kernel goes back to the loader without having been through the above: after+ * a panic. A DSP left running then is one that nobody listens to any more, and the next kernel+ * has to find and stop it; better it is stopped now. One processor is left, with its interrupts+ * off: nothing here takes a lock or sleeps (the waits are loops), and the link's thread is+ * simply never run again. The DSP is asked first, for two seconds at most; whatever it says,+ * TrustZone is asked to shut it down.+ */+void+redwood_wifi_quiesce(void)+{+ if (!dsp_started || dirty) {+ return;+ }+ leaving = true;+ new_from = ~0u; /* (no pauses) */+ dsp_shutdown("the kernel is on its way back to the loader");+}+#define REDWOOD_SOC_BASE 0x00400000ul /* where the loader says the phone's peripherals begin (its "redwood") */extern vm_offset_t pe_arm_get_soc_base_phys(void);diff --git a/xnu/files/bsd/dev/redwood_wlfw.c b/xnu/files/bsd/dev/redwood_wlfw.cindex e1e5ec3..be1ab3f 100644--- a/xnu/files/bsd/dev/redwood_wlfw.c+++ b/xnu/files/bsd/dev/redwood_wlfw.c@@ -11,9 +11,14 @@* whether it takes the phone's own board file, and what calibration does.** It is step 15 of wifi=N (redwood_wifi.c), and stops where qmi.c hands over to the rest of the- * driver: the configuration and "mission mode" messages are not sent, because what goes into- * them (the copy engines' pipes and the shadow registers) is worked out by code this does not- * have. Boot-arg wifi_cal=1 adds what qmi.c does with cold-boot calibration switched on.+ * driver. Boot-arg wifi_cal=1 adds what qmi.c does with cold-boot calibration switched on.+ * Boot-arg wifi_mission=1 adds what qmi.c is asked for next (ath11k_qmi_firmware_start()): the+ * firmware's logging, the configuration, the mode "mission", after which the firmware has the+ * radio on and the driver begins to use its registers. The configuration is NOT ALL OF+ * ath11k's: the copy engines' pipes and the map of services to them are its own tables for this+ * chip, taken out with the message tables, but the list of shadow registers, which the driver+ * works out from its rings when it runs, is left out. With that mode the handle stays open+ * until redwood_wlfw_stop(), which sends the mode "off" as ath11k does when it stops.** What the phone said (13 October, firmware WLAN.MSL.1.0.1-01277): every request is answered* with success; the regulatory database goes down in 4 pieces and bd_m20gl.elf in 10; "init@@ -22,7 +27,9 @@* after that, it does not say "ready" (10 s waited): that waits for a mode. Asked for cold-boot* calibration, it says "calibration done" 6.7 s later and "ready" 0.1 s after that -- with the* radio's pins and supply rails as the boot loader leaves them. The mode "off" sent after that- * (which qmi.c does not send at that point) it refuses, error 48.+ * (which qmi.c does not send at that point) it refuses, error 48. With wifi_mission=1: logging,+ * the configuration without a list of shadow registers, and the mode "mission" are all taken+ * (3, 3 and 342 ms), the radio's registers then answer (step 16), and the mode "off" is taken.** The messages' structures and the tables that describe them are ath11k's own, taken out of its* sources when the kernel is built (tools/mk-wlfw.sh) and not kept anywhere: nothing of them is@@ -41,6 +48,17 @@#if !__has_include("redwood_wlfw_ath11k.h")+bool+redwood_wlfw_registers(__unused uint64_t *address, __unused uint32_t *size, __unused bool *mission)+{+ return false;+}++void+redwood_wlfw_stop(__unused uint32_t step)+{+}+boolredwood_wlfw_exchange(uint32_t step){@@ -55,8 +73,12 @@ redwood_wlfw_exchange(uint32_t step)#include "redwood_wlfw_ath11k.h"#define MODE_COLD_BOOT 7 /* core.h: ATH11K_FIRMWARE_MODE_COLD_BOOT */+#define ATH11K_FIRMWARE_MODE_NORMAL 0 /* core.h: the mode "mission" */static struct qmi_handle handle;+static bool handle_open, in_mission;+static uint64_t registers_at; /* where the firmware said the radio's registers are, and ... */+static uint32_t registers_size; /* ... how many bytes of them; 0: it has not said */static struct {volatile bool server, gone, init_done, ready, cal_done;uint64_t began, init_done_at, ready_at, cal_done_at;@@ -240,6 +262,107 @@ wait_for(volatile bool *flag, uint32_t ms)return *flag;}+bool+redwood_wlfw_registers(uint64_t *address, uint32_t *size, bool *mission)+{+ *address = registers_at;+ *size = registers_size;+ *mission = in_mission;+ return registers_size != 0;+}++static bool ask(const char *what, int message, size_t largest, const struct qmi_elem_info *request_ei, const void *request,+ const struct qmi_elem_info *reply_ei, void *reply, bool quiet);++/* ath11k_qmi_firmware_stop(): the mode "off"; and our handle given up. Before the DSP is stopped, while the link is up. */+void+redwood_wlfw_stop(uint32_t step)+{+ struct qmi_wlanfw_wlan_mode_req_msg_v01 mode;+ struct qmi_wlanfw_wlan_mode_resp_msg_v01 mode_reply;++ if (!handle_open) {+ return;+ }+ wlfw.step = step;+ if (in_mission) {+ bzero(&mode, sizeof(mode));+ bzero(&mode_reply, sizeof(mode_reply));+ mode.mode = ATH11K_FIRMWARE_MODE_OFF;+ mode.hw_debug_valid = 1;+ ask("the mode: off", QMI_WLANFW_WLAN_MODE_REQ_V01, QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN,+ qmi_wlanfw_wlan_mode_req_msg_v01_ei, &mode, qmi_wlanfw_wlan_mode_resp_msg_v01_ei, &mode_reply, false);+ in_mission = false;+ }+ qmi_handle_release(&handle);+ handle_open = false;+}++/*+ * ath11k_qmi_firmware_start(), mode "mission": the firmware's logging on (this chip's entry+ * says so), the configuration, the mode. True: the firmware took the mode.+ */+static bool+mission(void)+{+ static struct qmi_wlanfw_wlan_cfg_req_msg_v01 cfg;+ struct qmi_wlanfw_wlan_cfg_resp_msg_v01 cfg_reply;+ struct qmi_wlanfw_wlan_ini_req_msg_v01 ini;+ struct qmi_wlanfw_wlan_ini_resp_msg_v01 ini_reply;+ struct qmi_wlanfw_wlan_mode_req_msg_v01 mode;+ struct qmi_wlanfw_wlan_mode_resp_msg_v01 mode_reply;++ if (WLFW_SENDS_INI) {+ bzero(&ini, sizeof(ini));+ bzero(&ini_reply, sizeof(ini_reply));+ ini.enablefwlog_valid = 1;+ ini.enablefwlog = 1;+ if (!ask("the firmware's logging: on", QMI_WLANFW_WLAN_INI_REQ_V01, QMI_WLANFW_WLAN_INI_REQ_MSG_V01_MAX_LEN,+ qmi_wlanfw_wlan_ini_req_msg_v01_ei, &ini, qmi_wlanfw_wlan_ini_resp_msg_v01_ei, &ini_reply, false)) {+ return false;+ }+ }+ /* ath11k_qmi_wlanfw_wlan_cfg_send(), but for the shadow registers (see the top) */+ bzero(&cfg, sizeof(cfg));+ bzero(&cfg_reply, sizeof(cfg_reply));+ cfg.host_version_valid = 1;+ strlcpy(cfg.host_version, ATH11K_HOST_VERSION_STRING, sizeof(cfg.host_version));+ cfg.tgt_cfg_valid = 1;+ cfg.tgt_cfg_len = WLFW_PIPE_COUNT;+ for (uint32_t i = 0; i < cfg.tgt_cfg_len; i++) {+ cfg.tgt_cfg[i].pipe_num = WLFW_PIPES[i].pipenum;+ cfg.tgt_cfg[i].pipe_dir = WLFW_PIPES[i].pipedir;+ cfg.tgt_cfg[i].nentries = WLFW_PIPES[i].nentries;+ cfg.tgt_cfg[i].nbytes_max = WLFW_PIPES[i].nbytes_max;+ cfg.tgt_cfg[i].flags = WLFW_PIPES[i].flags;+ }+ cfg.svc_cfg_valid = 1;+ cfg.svc_cfg_len = WLFW_SERVICE_COUNT;+ for (uint32_t i = 0; i < cfg.svc_cfg_len; i++) {+ cfg.svc_cfg[i].service_id = WLFW_SERVICES[i].service_id;+ cfg.svc_cfg[i].pipe_dir = WLFW_SERVICES[i].pipedir;+ cfg.svc_cfg[i].pipe_num = WLFW_SERVICES[i].pipenum;+ }+ say("wifi: %u: the configuration: host version \"%s\", %u pipes and %u services from ath11k's tables for this chip; "+ "shadow registers: none%s\n", wlfw.step, cfg.host_version, cfg.tgt_cfg_len, cfg.svc_cfg_len, WLFW_SHADOW_REGISTERS ?+ " (ath11k SENDS A LIST of up to 36 here)" : "");+ if (!ask("the configuration", QMI_WLANFW_WLAN_CFG_REQ_V01, QMI_WLANFW_WLAN_CFG_REQ_MSG_V01_MAX_LEN,+ qmi_wlanfw_wlan_cfg_req_msg_v01_ei, &cfg, qmi_wlanfw_wlan_cfg_resp_msg_v01_ei, &cfg_reply, false)) {+ return false;+ }+ bzero(&mode, sizeof(mode));+ bzero(&mode_reply, sizeof(mode_reply));+ mode.mode = ATH11K_FIRMWARE_MODE_NORMAL;+ mode.hw_debug_valid = 1;+ mode.hw_debug = 0;+ if (!ask("the mode: mission", QMI_WLANFW_WLAN_MODE_REQ_V01, QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN,+ qmi_wlanfw_wlan_mode_req_msg_v01_ei, &mode, qmi_wlanfw_wlan_mode_resp_msg_v01_ei, &mode_reply, false)) {+ return false;+ }+ say("wifi: %u: THE FIRMWARE IS IN MISSION MODE\n", wlfw.step);+ return true;+}+boolredwood_wlfw_exchange(uint32_t step){@@ -253,20 +376,25 @@ redwood_wlfw_exchange(uint32_t step)struct qmi_wlanfw_device_info_resp_msg_v01 device;struct qmi_wlanfw_wlan_mode_req_msg_v01 mode;struct qmi_wlanfw_wlan_mode_resp_msg_v01 mode_reply;- uint32_t calibrate = 0, seconds = 5, board_id;+ uint32_t calibrate = 0, seconds = 5, to_mission = 0, board_id;bool far = false, board = false;int ret;+ if (handle_open) {+ return false;+ }bzero(&wlfw, sizeof(wlfw));wlfw.step = step;wlfw.began = now_ms();PE_parse_boot_argn("wifi_cal", &calibrate, sizeof(calibrate));PE_parse_boot_argn("wifi_ready", &seconds, sizeof(seconds));+ PE_parse_boot_argn("wifi_mission", &to_mission, sizeof(to_mission));ret = qmi_handle_init(&handle, ATH11K_QMI_RESP_LEN_MAX, &wlfw_ops, wlfw_handlers);if (ret < 0) {say("wifi: %u: no handle on the router: %d\n", step, ret);return false;}+ handle_open = true;ret = qmi_add_lookup(&handle, ATH11K_QMI_WLFW_SERVICE_ID_V01, ATH11K_QMI_WLFW_SERVICE_VERS_V01,ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_WCN6750);if (ret < 0 || !wait_for(&wlfw.server, 3000)) {@@ -335,6 +463,10 @@ redwood_wlfw_exchange(uint32_t step)qmi_wlanfw_device_info_req_msg_v01_ei, &where, qmi_wlfw_device_info_resp_msg_v01_ei, &device, false)) {goto out;}+ if (device.bar_addr_valid && device.bar_size_valid) {+ registers_at = device.bar_addr;+ registers_size = device.bar_size;+ }say("wifi: %u: registers at %#llx (%s), %#x bytes (%s; ath11k wants exactly %#x)\n", step,(unsigned long long)device.bar_addr, device.bar_addr_valid ? "given" : "not given", device.bar_size,device.bar_size_valid ? "given" : "not given", ATH11K_QMI_DEVICE_BAR_SIZE);@@ -356,7 +488,11 @@ redwood_wlfw_exchange(uint32_t step)goto out;}if (!calibrate) {- /* (with cold-boot calibration off qmi.c goes on to the rest of the driver at this point, and so stops here) */+ /* (with cold-boot calibration off qmi.c goes on to the rest of the driver at this point) */+ if (to_mission) {+ in_mission = mission();+ goto out;+ }say("wifi: %u: cold-boot calibration is off: waiting %u s to see whether \"firmware ready\" comes by itself\n", step,seconds);wait_for(&wlfw.ready, seconds * 1000);@@ -381,6 +517,11 @@ redwood_wlfw_exchange(uint32_t step)say("wifi: %u: calibration: \"done\" %s, \"firmware ready\" %s\n", step, wlfw.cal_done ? "came" : "did not come",wlfw.ready ? "CAME" : "DID NOT COME");}+ if (to_mission && wlfw.ready) {+ /* (qmi.c, on "ready": the rest of the driver, which begins with ath11k_qmi_firmware_start()) */+ in_mission = mission();+ goto out;+ }/** Not qmi.c's next message: it goes on to configuration and mission mode from here. This is* what it sends when the driver stops (ath11k_qmi_firmware_stop()), tried here to leave the@@ -391,9 +532,13 @@ redwood_wlfw_exchange(uint32_t step)ask("the mode: off (not ath11k's next message)", QMI_WLANFW_WLAN_MODE_REQ_V01, QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN,qmi_wlanfw_wlan_mode_req_msg_v01_ei, &mode, qmi_wlanfw_wlan_mode_resp_msg_v01_ei, &mode_reply, false);out:- say("wifi: %u: the exchange ends %llu ms after it began: \"init done\" %s, \"ready\" %s, \"calibration done\" %s\n", step,- now_ms() - wlfw.began, wlfw.init_done ? "yes" : "no", wlfw.ready ? "yes" : "no", wlfw.cal_done ? "yes" : "no");- qmi_handle_release(&handle);+ say("wifi: %u: the exchange ends %llu ms after it began: \"init done\" %s, \"ready\" %s, \"calibration done\" %s, mission "+ "mode %s\n", step, now_ms() - wlfw.began, wlfw.init_done ? "yes" : "no", wlfw.ready ? "yes" : "no", wlfw.cal_done ? "yes" :+ "no", in_mission ? "YES" : "no");+ if (!in_mission) {+ qmi_handle_release(&handle);+ handle_open = false;+ }return far && wlfw.init_done;}diff --git a/xnu/files/bsd/sys/redwood_input.h b/xnu/files/bsd/sys/redwood_input.hindex 5d057d1..ed224a6 100644--- a/xnu/files/bsd/sys/redwood_input.h+++ b/xnu/files/bsd/sys/redwood_input.h@@ -53,6 +53,9 @@ void redwood_wifi_stop(void); /* where a run ends in order: the Wi-Fiint redwood_wifi_say(const char *format, ...) __printflike(1, 2); /* a line of the Wi-Fi steps' log */const uint8_t *redwood_wifi_file(const char *name, uint64_t *size); /* a file of fw/ in the small image, in place */bool redwood_wlfw_exchange(uint32_t step); /* step 15 of wifi=N: bsd/dev/redwood_wlfw.c */+bool redwood_wlfw_registers(uint64_t *address, uint32_t *size, bool *mission); /* ... and what it learnt for step 16 */+void redwood_wlfw_stop(uint32_t step); /* ... and its end, before the DSP is stopped */+void redwood_wifi_quiesce(void); /* on the way back to the loader: the Wi-Fi DSP, if it still runs, shut down *//** The GPU kept on (boot-arg adreno_keep=1), for iokit/Kernel/RedwoodGPU.cpp: see "the GPU kept on"diff --git a/xnu/files/osfmk/arm64/loader_return.c b/xnu/files/osfmk/arm64/loader_return.cindex 0d78fb6..59318b2 100644--- a/xnu/files/osfmk/arm64/loader_return.c+++ b/xnu/files/osfmk/arm64/loader_return.c@@ -48,6 +48,7 @@ extern void redwood_adreno_quiesce(void);extern void redwood_adreno_stop(void);extern void redwood_adreno_minute(void);extern void redwood_wifi_stop(void);+extern void redwood_wifi_quiesce(void);void loader_checkpoint(uint64_t n);/* Also referenced from the early exception vector in start.s. */@@ -316,6 +317,7 @@ loader_return(void)psci_smp_stop_others();#endifredwood_adreno_quiesce(); /* the GPU block, if it was started, has tables in memory that is about to be reused */+ redwood_wifi_quiesce(); /* the Wi-Fi DSP, if it still runs (a panic), is not left to itself *//** A panic's text is first collected in the panic buffer and only later* flushed to the console; if the console itself is what failed, that