Skip to content

Commit

Permalink
add ptp_clock_caps
Browse files Browse the repository at this point in the history
(backport <rust-lang#4128>)
(cherry picked from commit 38318cd)
  • Loading branch information
folkertdev authored and tgross35 committed Nov 25, 2024
1 parent 9956dfb commit 56fb296
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
13 changes: 11 additions & 2 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3956,7 +3956,8 @@ fn test_linux(target: &str) {
return true;
}
// FIXME: Requires >= 5.4 kernel headers
if name == "PTP_ENABLE_PPS2"
if name == "PTP_CLOCK_GETCAPS2"
|| name == "PTP_ENABLE_PPS2"
|| name == "PTP_EXTTS_REQUEST2"
|| name == "PTP_PEROUT_REQUEST2"
|| name == "PTP_PIN_GETFUNC2"
Expand Down Expand Up @@ -4410,7 +4411,11 @@ fn test_linux(target: &str) {
// `anonymous_1` is an anonymous union
(struct_ == "ptp_perout_request" && field == "anonymous_1") ||
// `anonymous_2` is an anonymous union
(struct_ == "ptp_perout_request" && field == "anonymous_2")
(struct_ == "ptp_perout_request" && field == "anonymous_2") ||
// FIXME(linux): `adjust_phase` requires >= 5.7 kernel headers
// FIXME(linux): `max_phase_adj` requires >= 5.19 kernel headers
// the rsv field shrunk when those fields got added, so is omitted too
(struct_ == "ptp_clock_caps" && (loongarch64 || sparc64) && (["adjust_phase", "max_phase_adj", "rsv"].contains(&field)))
});

cfg.volatile_item(|i| {
Expand Down Expand Up @@ -4485,6 +4490,10 @@ fn test_linux(target: &str) {
(struct_ == "ptp_perout_request" && field == "anonymous_1") ||
// `anonymous_2` is an anonymous union
(struct_ == "ptp_perout_request" && field == "anonymous_2") ||
// FIXME(linux): `adjust_phase` requires >= 5.7 kernel headers
// FIXME(linux): `max_phase_adj` requires >= 5.19 kernel headers
// the rsv field shrunk when those fields got added, so is omitted too
(struct_ == "ptp_clock_caps" && (loongarch64 || sparc64) && (["adjust_phase", "max_phase_adj", "rsv"].contains(&field))) ||
// invalid application of 'sizeof' to incomplete type 'long unsigned int[]'
(musl && struct_ == "mcontext_t" && field == "__extcontext" && loongarch64) ||
// FIXME(#4121): a new field was added from `f_spare`
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ PTHREAD_PRIO_PROTECT
PTHREAD_PROCESS_PRIVATE
PTHREAD_PROCESS_SHARED
PTHREAD_STACK_MIN
PTP_CLOCK_GETCAPS2
PTP_ENABLE_PPS
PTP_ENABLE_PPS2
PTP_EXTTS_REQUEST
Expand Down Expand Up @@ -3946,6 +3947,7 @@ pthread_spin_lock
pthread_spin_trylock
pthread_spin_unlock
pthread_spinlock_t
ptp_clock_caps
ptp_clock_time
ptp_extts_event
ptp_extts_request
Expand Down
19 changes: 15 additions & 4 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,19 @@ s! {
pub rsv: [::c_uint; 5],
}

pub struct ptp_clock_caps {
pub max_adj: ::c_int,
pub n_alarm: ::c_int,
pub n_ext_ts: ::c_int,
pub n_per_out: ::c_int,
pub pps: ::c_int,
pub n_pins: ::c_int,
pub cross_timestamping: ::c_int,
pub adjust_phase: ::c_int,
pub max_phase_adj: ::c_int,
pub rsv: [::c_int; 11],
}

// linux/if_xdp.h
pub struct xsk_tx_metadata_completion {
pub tx_timestamp: ::__u64,
Expand Down Expand Up @@ -4606,8 +4619,7 @@ pub const PTP_MAX_SAMPLES: ::c_uint = 25; // Maximum allowed offset measurement

const PTP_CLK_MAGIC: u32 = b'=' as u32;

// FIXME: needs the ptp_clock_caps struct
// pub const PTP_CLOCK_GETCAPS: ::c_uint = _IOR::<ptp_clock_caps>(PTP_CLK_MAGIC, 1);
pub const PTP_CLOCK_GETCAPS: ::c_uint = _IOR::<ptp_clock_caps>(PTP_CLK_MAGIC, 1);
pub const PTP_EXTTS_REQUEST: ::c_uint = _IOW::<ptp_extts_request>(PTP_CLK_MAGIC, 2);
pub const PTP_PEROUT_REQUEST: ::c_uint = _IOW::<ptp_perout_request>(PTP_CLK_MAGIC, 3);
pub const PTP_ENABLE_PPS: ::c_uint = _IOW::<::c_int>(PTP_CLK_MAGIC, 4);
Expand All @@ -4617,8 +4629,7 @@ pub const PTP_PIN_SETFUNC: ::c_uint = _IOW::<ptp_pin_desc>(PTP_CLK_MAGIC, 7);
pub const PTP_SYS_OFFSET_PRECISE: ::c_uint = _IOWR::<ptp_sys_offset_precise>(PTP_CLK_MAGIC, 8);
pub const PTP_SYS_OFFSET_EXTENDED: ::c_uint = _IOWR::<ptp_sys_offset_extended>(PTP_CLK_MAGIC, 9);

// FIXME: needs the ptp_clock_caps struct
// pub const PTP_CLOCK_GETCAPS2: ::c_uint = _IOR::<ptp_clock_caps>(PTP_CLK_MAGIC, 10);
pub const PTP_CLOCK_GETCAPS2: ::c_uint = _IOR::<ptp_clock_caps>(PTP_CLK_MAGIC, 10);
pub const PTP_EXTTS_REQUEST2: ::c_uint = _IOW::<ptp_extts_request>(PTP_CLK_MAGIC, 11);
pub const PTP_PEROUT_REQUEST2: ::c_uint = _IOW::<ptp_perout_request>(PTP_CLK_MAGIC, 12);
pub const PTP_ENABLE_PPS2: ::c_uint = _IOW::<::c_int>(PTP_CLK_MAGIC, 13);
Expand Down

0 comments on commit 56fb296

Please sign in to comment.