Skip to content

Commit 4aa4dd5

Browse files
committed
rust: compile readq/writeq only on 64-bit arch
Signed-off-by: Gary Guo <[email protected]>
1 parent 5444b8b commit 4aa4dd5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

rust/kernel/io_mem.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ pub struct IoMem<const SIZE: usize> {
6161
}
6262

6363
macro_rules! define_read {
64-
($name:ident, $try_name:ident, $type_name:ty) => {
64+
($(#[$attr:meta])* $name:ident, $try_name:ident, $type_name:ty) => {
6565
/// Reads IO data from the given offset known, at compile time.
6666
///
6767
/// If the offset is not known at compile time, the build will fail.
68+
$(#[$attr])*
6869
pub fn $name(&self, offset: usize) -> $type_name {
6970
Self::check_offset::<$type_name>(offset);
7071
let ptr = self.ptr.wrapping_add(offset);
@@ -77,6 +78,7 @@ macro_rules! define_read {
7778
/// Reads IO data from the given offset.
7879
///
7980
/// It fails if/when the offset (plus the type size) is out of bounds.
81+
$(#[$attr])*
8082
pub fn $try_name(&self, offset: usize) -> Result<$type_name> {
8183
if !Self::offset_ok::<$type_name>(offset) {
8284
return Err(Error::EINVAL);
@@ -91,10 +93,11 @@ macro_rules! define_read {
9193
}
9294

9395
macro_rules! define_write {
94-
($name:ident, $try_name:ident, $type_name:ty) => {
96+
($(#[$attr:meta])* $name:ident, $try_name:ident, $type_name:ty) => {
9597
/// Writes IO data to the given offset, known at compile time.
9698
///
9799
/// If the offset is not known at compile time, the build will fail.
100+
$(#[$attr])*
98101
pub fn $name(&self, value: $type_name, offset: usize) {
99102
Self::check_offset::<$type_name>(offset);
100103
let ptr = self.ptr.wrapping_add(offset);
@@ -107,6 +110,7 @@ macro_rules! define_write {
107110
/// Writes IO data to the given offset.
108111
///
109112
/// It fails if/when the offset (plus the type size) is out of bounds.
113+
$(#[$attr])*
110114
pub fn $try_name(&self, value: $type_name, offset: usize) -> Result {
111115
if !Self::offset_ok::<$type_name>(offset) {
112116
return Err(Error::EINVAL);
@@ -174,12 +178,22 @@ impl<const SIZE: usize> IoMem<SIZE> {
174178
define_read!(readb, try_readb, u8);
175179
define_read!(readw, try_readw, u16);
176180
define_read!(readl, try_readl, u32);
177-
define_read!(readq, try_readq, u64);
181+
define_read!(
182+
#[cfg(CONFIG_64BIT)]
183+
readq,
184+
try_readq,
185+
u64
186+
);
178187

179188
define_write!(writeb, try_writeb, u8);
180189
define_write!(writew, try_writew, u16);
181190
define_write!(writel, try_writel, u32);
182-
define_write!(writeq, try_writeq, u64);
191+
define_write!(
192+
#[cfg(CONFIG_64BIT)]
193+
writeq,
194+
try_writeq,
195+
u64
196+
);
183197
}
184198

185199
impl<const SIZE: usize> Drop for IoMem<SIZE> {

0 commit comments

Comments
 (0)