aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2021-04-27 18:05:39 +0530
committerViresh Kumar <viresh.kumar@linaro.org>2021-04-28 17:10:17 +0530
commitaf0030be837a291d8394ebe7a0e3832a70bec46f (patch)
tree6a3edb8591df8aa43b6b7048ed5ea3ef8735dfb6
parent2d3728dc0d46381fb2290dfeb8cbbd73a8cb96f0 (diff)
testdebug
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
-rw-r--r--Cargo.toml1
-rw-r--r--src/i2c.rs11
-rw-r--r--src/vhu_i2c.rs5
3 files changed, 13 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 39a7ac3..b322998 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,5 +18,6 @@ vm-memory = ">=0.3.0"
virtio-bindings = ">=0.1"
# currently these are based of checkouts
+type-layout = { path = "/home/vireshk/work/repos/virtio/rust/reference/type-layout" }
vhost = { git = "https://github.com/rust-vmm/vhost" }
vhost-user-backend = { git = "https://github.com/rust-vmm/vhost-user-backend" }
diff --git a/src/i2c.rs b/src/i2c.rs
index adeb4bf..24e8c56 100644
--- a/src/i2c.rs
+++ b/src/i2c.rs
@@ -62,7 +62,8 @@ struct I2cSmbusIoctlData {
// I2C definitions
pub const I2C_M_RD: u16 = 0x0001; // read data, from slave to master
-#[derive(Copy, Clone)]
+use type_layout::TypeLayout;
+#[derive(TypeLayout, Copy, Clone)]
#[repr(C)]
pub struct I2cMsg {
pub addr: u16,
@@ -71,12 +72,14 @@ pub struct I2cMsg {
pub buf: *mut u8
}
+#[derive(TypeLayout)]
#[repr(C)]
struct I2cRdwrIoctlData {
msgs: *mut I2cMsg,
nmsgs: u32
}
+#[derive(TypeLayout)]
#[repr(C)]
pub struct I2cReq {
pub addr: u16,
@@ -85,7 +88,6 @@ pub struct I2cReq {
pub buf: Vec<u8>
}
-
// Local I2C definitions
const MAX_I2C_VDEV: usize = 1 << 7;
const I2C_INVALID_ADAPTER: u32 = 0xFFFFFFFF;
@@ -136,6 +138,7 @@ fn i2c_xfer(adapter: &I2cAdapter, reqs: &mut [I2cReq]) -> bool {
println!("Failed to transfer i2c data to client addr to {:x}", reqs[0].addr);
false
} else {
+ println!("{:?}", reqs[1].buf);
true
}
}
@@ -254,7 +257,7 @@ pub fn vi2c_xfer(backend: &I2cBackend, reqs: &mut [I2cReq]) -> bool {
return false;
}
- if adapter.smbus {
+ if !adapter.smbus {
return smbus_xfer(&adapter, reqs);
} else {
return i2c_xfer(&adapter, reqs);
@@ -269,6 +272,8 @@ impl I2cBackend {
let count: usize = devices.len();
let mut smbus;
+ println!("Size is {}: {}: {}", I2cMsg::type_layout(), I2cReq::type_layout(), I2cRdwrIoctlData::type_layout());
+
for i in 0..count {
let list: Vec<&str> = devices[i].split(':').collect();
let bus = list[0].parse::<u32>().unwrap();
diff --git a/src/vhu_i2c.rs b/src/vhu_i2c.rs
index b023372..e657154 100644
--- a/src/vhu_i2c.rs
+++ b/src/vhu_i2c.rs
@@ -66,7 +66,7 @@ struct VirtioI2cOutHdr {
}
unsafe impl ByteValued for VirtioI2cOutHdr {}
-#[derive(Copy, Clone, Default)]
+#[derive(Debug, Copy, Clone, Default)]
#[repr(C)]
struct VirtioI2cInHdr {
status: u8
@@ -177,11 +177,14 @@ impl VhostUserI2c {
// Write the data read from the I2C client
if desc_buf.is_write_only() {
+ println!("Final read buf: {:?}", reqs[index].buf);
desc_chain
.memory()
.write(&reqs[index].buf, desc_buf.addr()).unwrap();
}
+ println!("In hdr: {:?}", in_hdr);
+
// Write the transfer status
desc_chain
.memory()