Skip to content
Closed
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 drivers/soc/apple/pm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ unsafe extern "C" fn pm_wake() {
}
// SAFETY: as in `pm_event`.
let sep = unsafe { <Arc<SepData> as ForeignOwnable>::borrow(ptr) };
sep.sensor_after_sleep();
if sep.sleep_exit() {
// The enclave slept and is back: report the accessory service online
// again, as macOS does right after the wake.
Expand Down
16 changes: 16 additions & 0 deletions drivers/soc/apple/sbio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2255,12 +2255,14 @@ impl SepData {
None
};

let mut recalibrated = false;
if !self.sensor_calibrated.load(Relaxed) {
if !self.calibrate_sensor() {
diag::sensor_brought_up(bind, false);
return false;
}
self.sensor_calibrated.store(true, Relaxed);
recalibrated = self.sensor_recalibrate.xchg(false, Relaxed);
if parameters.is_none() {
let Some(reloaded_patch) = self.wake_sensor() else {
diag::sensor_brought_up(bind, false);
Expand All @@ -2278,6 +2280,20 @@ impl SepData {
Some(parameters) => self.finish_sensor_setup(patch, parameters),
None => self.complete_bringup(patch),
};
// On a sensor with a nonce session the calibration takes effect only
// in a session made after it: on J813 the capture on the session that
// carried the calibration after a deep sleep never scanned (3V0 rail
// at 1 mA, not 3 mA) and saw no finger, while the next bring-up's did.
// At boot the attach-time bring-up calibrates and the first verify
// brings the sensor up again; after a sleep do that second bring-up
// here, before the capture.
if ok && recalibrated && self.profile.nonce_session {
dev_info_ratelimited!(
self.dev,
"sensor: calibrated again after a system sleep; bringing it up once more for the capture\n"
);
return self.bring_sensor_online();
}
diag::sensor_brought_up(bind, ok);
// The sensor is patched and idle here -- the only safe moment to
// configure the data-ready interrupt, which is then left alone for the
Expand Down
14 changes: 14 additions & 0 deletions drivers/soc/apple/sep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ struct SepData {
cold_restore_candidate: Atomic<bool>,

sensor_calibrated: Atomic<bool>,
// Set by a system sleep: the next calibration is a recalibration.
sensor_recalibrate: Atomic<bool>,
sensor_key_loaded: Atomic<bool>,

enrol_open: Atomic<bool>,
Expand Down Expand Up @@ -1208,6 +1210,7 @@ impl SepData {
xart_refusal_logged: Atomic::new(false),
capture_refusal_logged: Atomic::new(false),
sensor_calibrated: Atomic::new(false),
sensor_recalibrate: Atomic::new(false),
sensor_key_loaded: Atomic::new(false),
templates_restored: Atomic::new(false),
cold_restore_candidate: Atomic::new(false),
Expand Down Expand Up @@ -1620,6 +1623,17 @@ impl SepData {
}
}

/// After a system sleep the sensor is neither kept nor calibrated: its
/// suspend powered it off, and a deep sleep also put the enclave to sleep.
/// On J813 every capture after a deep sleep then ended without a frame
/// until the next boot. The next bring-up calibrates the sensor again, as
/// the first one after boot does.
pub(crate) fn sensor_after_sleep(&self) {
self.sensor_kept.store(false, Relaxed);
self.sensor_calibrated.store(false, Relaxed);
self.sensor_recalibrate.store(true, Relaxed);
}

/// A refused precommit attempt was never sent; reopen normal admission.
/// A sent request can be restarted only after actual physical sleep/wake.
/// Returns whether the enclave came back from a sleep it was told of.
Expand Down
Loading