Skip to content

Commit 83513c3

Browse files
committed
nvme: Add nvme_ensure_shutdown()
We're not using it in the end because we fixed this in Linux, but I went through the trouble of writing the function so we might as well leave it lying around. Signed-off-by: Hector Martin <[email protected]>
1 parent c2c0ac0 commit 83513c3

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/asc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ asc_dev_t *asc_init(const char *path)
5252
asc->cpu_base = base;
5353
asc->base = base + 0x8000;
5454

55-
clear32(base + ASC_CPU_CONTROL, ASC_CPU_CONTROL_START);
55+
// clear32(base + ASC_CPU_CONTROL, ASC_CPU_CONTROL_START);
5656
return asc;
5757
}
5858

@@ -76,6 +76,11 @@ void asc_cpu_stop(asc_dev_t *asc)
7676
clear32(asc->cpu_base + ASC_CPU_CONTROL, ASC_CPU_CONTROL_START);
7777
}
7878

79+
bool asc_cpu_running(asc_dev_t *asc)
80+
{
81+
return read32(asc->cpu_base + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_START;
82+
}
83+
7984
bool asc_can_recv(asc_dev_t *asc)
8085
{
8186
return !(read32(asc->base + ASC_MBOX_I2A_CONTROL) & ASC_MBOX_CONTROL_EMPTY);

src/asc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int asc_get_iop_node(asc_dev_t *asc);
1919

2020
void asc_cpu_start(asc_dev_t *asc);
2121
void asc_cpu_stop(asc_dev_t *asc);
22+
bool asc_cpu_running(asc_dev_t *asc);
2223

2324
bool asc_can_recv(asc_dev_t *asc);
2425
bool asc_can_send(asc_dev_t *asc);

src/nvme.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,55 @@ bool nvme_init(void)
427427
return false;
428428
}
429429

430+
void nvme_ensure_shutdown(void)
431+
{
432+
nvme_asc = asc_init("/arm-io/ans");
433+
if (!nvme_asc)
434+
return;
435+
436+
if (!asc_cpu_running(nvme_asc)) {
437+
printf("nvme: ANS not running\n");
438+
asc_free(nvme_asc);
439+
nvme_asc = NULL;
440+
return;
441+
}
442+
443+
printf("nvme: Found ANS left powered, doing a proper shutdown\n");
444+
445+
nvme_sart = sart_init("/arm-io/sart-ans");
446+
if (!nvme_sart)
447+
goto fail;
448+
449+
nvme_rtkit = rtkit_init("nvme", nvme_asc, NULL, NULL, nvme_sart);
450+
if (!nvme_rtkit)
451+
goto fail;
452+
453+
if (!rtkit_boot(nvme_rtkit))
454+
goto fail;
455+
456+
rtkit_sleep(nvme_rtkit);
457+
458+
fail:
459+
if (nvme_rtkit) {
460+
rtkit_free(nvme_rtkit);
461+
nvme_rtkit = NULL;
462+
}
463+
if (nvme_sart) {
464+
sart_free(nvme_sart);
465+
nvme_sart = NULL;
466+
}
467+
asc_free(nvme_asc);
468+
nvme_asc = NULL;
469+
470+
// Some machines call this ANS, some ANS2...
471+
pmgr_reset(nvme_die, "ANS");
472+
pmgr_reset(nvme_die, "ANS2");
473+
}
474+
430475
void nvme_shutdown(void)
431476
{
432477
if (!nvme_initialized) {
433-
printf("nvme: trying to shut down but not initialized\n");
478+
// nvme_ensure_shutdown();
434479
return;
435480
}
436481

0 commit comments

Comments
 (0)