refactor SCSI
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2022-12-15 20:39:45 +01:00
parent df9d85a1a5
commit 56d10459ed
2 changed files with 48 additions and 46 deletions

@ -1,4 +1,7 @@
mod scsi;
use crate::{println, serial_println};
use scsi::{SCSIPacket};
use core::convert::TryInto;
use core::future::Future;
@ -8,9 +11,7 @@ use core::task::{Context, Poll};
use lazy_static::lazy_static;
use futures_util::task::AtomicWaker;
use serde::{Serialize, Deserialize};
use spin::Mutex;
use postcard::{to_vec};
use x86_64::instructions::port::Port;
const CD_SECTOR_SIZE: usize = 2048;
@ -265,7 +266,7 @@ impl ATABus {
packet.op_code = SCSI_READ_12;
packet.set_lba(lba);
packet.transfer_length_lo = 1;
packet.set_transfer_length(1);
self.send_packet(packet);
@ -301,7 +302,7 @@ impl ATABus {
packet.op_code = SCSI_READ_12;
packet.set_lba(lba);
packet.transfer_length_lo = 1;
packet.set_transfer_length(1);
self.send_packet(packet);
@ -361,48 +362,6 @@ impl ATABus {
}
}
#[derive(Default, Serialize, Deserialize, Debug, Eq, PartialEq)]
#[repr(C, packed)]
struct SCSIPacket {
op_code: u8,
flags_lo: u8,
lba_hi: u8,
lba_mihi: u8,
lba_milo: u8,
lba_lo: u8,
transfer_length_hi: u8,
transfer_length_mihi: u8,
transfer_length_milo: u8,
transfer_length_lo: u8,
flags_hi: u8,
control: u8
}
impl SCSIPacket {
fn new() -> Self {
SCSIPacket::default()
}
fn serialize(&self) -> heapless::Vec<u8, 12> {
to_vec(&self).unwrap()
}
fn set_lba(&mut self, lba: u32) {
self.lba_lo = (lba & 0xff) as u8;
self.lba_milo = ((lba >> 0x8) & 0xff) as u8;
self.lba_mihi = ((lba >> 0x10) & 0xff) as u8;
self.lba_hi = ((lba >> 0x18) & 0xff) as u8;
}
#[allow(dead_code)]
fn set_transfer_length(&mut self, l: u32) {
self.transfer_length_lo = (l & 0xff) as u8;
self.transfer_length_milo = ((l >> 0x8) & 0xff) as u8;
self.transfer_length_mihi = ((l >> 0x10) & 0xff) as u8;
self.transfer_length_hi = ((l >> 0x18) & 0xff) as u8;
}
}
pub async fn print_block() {
DRIVE.lock().as_mut().unwrap().read_block(0).await;

43
src/drivers/atapi/scsi.rs Normal file

@ -0,0 +1,43 @@
use postcard::{to_vec};
use serde::{Serialize, Deserialize};
#[derive(Default, Serialize, Deserialize, Debug, Eq, PartialEq)]
#[repr(C, packed)]
pub struct SCSIPacket {
pub op_code: u8,
flags_lo: u8,
lba_hi: u8,
lba_mihi: u8,
lba_milo: u8,
lba_lo: u8,
transfer_length_hi: u8,
transfer_length_mihi: u8,
transfer_length_milo: u8,
transfer_length_lo: u8,
flags_hi: u8,
control: u8
}
impl SCSIPacket {
pub fn new() -> Self {
SCSIPacket::default()
}
pub fn serialize(&self) -> heapless::Vec<u8, 12> {
to_vec(&self).unwrap()
}
pub fn set_lba(&mut self, lba: u32) {
self.lba_lo = (lba & 0xff) as u8;
self.lba_milo = ((lba >> 0x8) & 0xff) as u8;
self.lba_mihi = ((lba >> 0x10) & 0xff) as u8;
self.lba_hi = ((lba >> 0x18) & 0xff) as u8;
}
pub fn set_transfer_length(&mut self, l: u32) {
self.transfer_length_lo = (l & 0xff) as u8;
self.transfer_length_milo = ((l >> 0x8) & 0xff) as u8;
self.transfer_length_mihi = ((l >> 0x10) & 0xff) as u8;
self.transfer_length_hi = ((l >> 0x18) & 0xff) as u8;
}
}