aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86_64/io_port.rs
diff options
context:
space:
mode:
authorTianhao Wang <wth@riseup.net>2024-02-01 22:01:25 +0100
committerTianhao Wang <shrik3@mailbox.org>2024-06-11 15:13:38 +0200
commitf857bd1d4f12316bd3434192d41c2489407c11a4 (patch)
tree7ccedde31f7c403f6afbda7cd547e7af20145ef6 /src/arch/x86_64/io_port.rs
parent0ebc5ab0ee0fc80c801487f534687c8bd236abc1 (diff)
add IOPort struct
So that device IO can be be synchronized.
Diffstat (limited to 'src/arch/x86_64/io_port.rs')
-rw-r--r--src/arch/x86_64/io_port.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/arch/x86_64/io_port.rs b/src/arch/x86_64/io_port.rs
index 7b37989..cb6c80f 100644
--- a/src/arch/x86_64/io_port.rs
+++ b/src/arch/x86_64/io_port.rs
@@ -1,5 +1,9 @@
use core::arch::asm;
+// put a few cycles of delay after IO ops
+use super::misc::delay;
+
+#[inline(always)]
pub fn inw(p: u16) -> u16 {
let result: u16;
unsafe {
@@ -8,9 +12,11 @@ pub fn inw(p: u16) -> u16 {
out("ax") result
)
}
+ delay();
result
}
+#[inline(always)]
pub fn inb(p: u16) -> u8 {
let result: u8;
unsafe {
@@ -19,9 +25,11 @@ pub fn inb(p: u16) -> u8 {
out("al") result
)
}
+ delay();
result
}
+#[inline(always)]
pub fn outb(p: u16, val: u8) {
unsafe {
asm!("out dx, al",
@@ -29,8 +37,10 @@ pub fn outb(p: u16, val: u8) {
in("al") val,
)
}
+ delay();
}
+#[inline(always)]
pub fn outw(p: u16, val: u16) {
unsafe {
asm!("out dx, ax",
@@ -38,4 +48,5 @@ pub fn outw(p: u16, val: u16) {
in("ax") val,
)
}
+ delay();
}