mirror of
https://github.com/torvalds/linux.git
synced 2026-05-25 23:52:08 +02:00
gpu: nova-core: gsp: simplify sequencer opcode parsing
The opcodes are already the right type in the C union, so we can use them directly instead of converting them to a byte stream and back again using `FromBytes`. Reviewed-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://patch.msgid.link/20260217-nova-misc-v3-3-b4e2d45eafbc@nvidia.com Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
This commit is contained in:
parent
3614290d75
commit
4503e61a62
|
|
@ -472,13 +472,7 @@ pub(crate) fn reg_write_payload(&self) -> Result<RegWritePayload> {
|
|||
return Err(EINVAL);
|
||||
}
|
||||
// SAFETY: Opcode is verified to be `RegWrite`, so union contains valid `RegWritePayload`.
|
||||
let payload_bytes = unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
core::ptr::addr_of!(self.0.payload.regWrite).cast::<u8>(),
|
||||
core::mem::size_of::<RegWritePayload>(),
|
||||
)
|
||||
};
|
||||
Ok(*RegWritePayload::from_bytes(payload_bytes).ok_or(EINVAL)?)
|
||||
Ok(RegWritePayload(unsafe { self.0.payload.regWrite }))
|
||||
}
|
||||
|
||||
/// Returns the register modify payload by value.
|
||||
|
|
@ -489,13 +483,7 @@ pub(crate) fn reg_modify_payload(&self) -> Result<RegModifyPayload> {
|
|||
return Err(EINVAL);
|
||||
}
|
||||
// SAFETY: Opcode is verified to be `RegModify`, so union contains valid `RegModifyPayload`.
|
||||
let payload_bytes = unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
core::ptr::addr_of!(self.0.payload.regModify).cast::<u8>(),
|
||||
core::mem::size_of::<RegModifyPayload>(),
|
||||
)
|
||||
};
|
||||
Ok(*RegModifyPayload::from_bytes(payload_bytes).ok_or(EINVAL)?)
|
||||
Ok(RegModifyPayload(unsafe { self.0.payload.regModify }))
|
||||
}
|
||||
|
||||
/// Returns the register poll payload by value.
|
||||
|
|
@ -506,13 +494,7 @@ pub(crate) fn reg_poll_payload(&self) -> Result<RegPollPayload> {
|
|||
return Err(EINVAL);
|
||||
}
|
||||
// SAFETY: Opcode is verified to be `RegPoll`, so union contains valid `RegPollPayload`.
|
||||
let payload_bytes = unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
core::ptr::addr_of!(self.0.payload.regPoll).cast::<u8>(),
|
||||
core::mem::size_of::<RegPollPayload>(),
|
||||
)
|
||||
};
|
||||
Ok(*RegPollPayload::from_bytes(payload_bytes).ok_or(EINVAL)?)
|
||||
Ok(RegPollPayload(unsafe { self.0.payload.regPoll }))
|
||||
}
|
||||
|
||||
/// Returns the delay payload by value.
|
||||
|
|
@ -523,13 +505,7 @@ pub(crate) fn delay_us_payload(&self) -> Result<DelayUsPayload> {
|
|||
return Err(EINVAL);
|
||||
}
|
||||
// SAFETY: Opcode is verified to be `DelayUs`, so union contains valid `DelayUsPayload`.
|
||||
let payload_bytes = unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
core::ptr::addr_of!(self.0.payload.delayUs).cast::<u8>(),
|
||||
core::mem::size_of::<DelayUsPayload>(),
|
||||
)
|
||||
};
|
||||
Ok(*DelayUsPayload::from_bytes(payload_bytes).ok_or(EINVAL)?)
|
||||
Ok(DelayUsPayload(unsafe { self.0.payload.delayUs }))
|
||||
}
|
||||
|
||||
/// Returns the register store payload by value.
|
||||
|
|
@ -540,13 +516,7 @@ pub(crate) fn reg_store_payload(&self) -> Result<RegStorePayload> {
|
|||
return Err(EINVAL);
|
||||
}
|
||||
// SAFETY: Opcode is verified to be `RegStore`, so union contains valid `RegStorePayload`.
|
||||
let payload_bytes = unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
core::ptr::addr_of!(self.0.payload.regStore).cast::<u8>(),
|
||||
core::mem::size_of::<RegStorePayload>(),
|
||||
)
|
||||
};
|
||||
Ok(*RegStorePayload::from_bytes(payload_bytes).ok_or(EINVAL)?)
|
||||
Ok(RegStorePayload(unsafe { self.0.payload.regStore }))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user