Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make input context could clone device value from output ctx #173

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
device: Device::new(),
}
}

/// copy output ctx to input
/// refer linux code
Copy link
Member

@toku-sa-n toku-sa-n Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, and sorry for the delay.
Could you tell me the exact location for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's located at here
btw, here is how I use it in my project
and one more thing: i added some more utilitity functions after first pr,just for convenient

pub fn copy_from_output(&mut self, out_ctx: &Device<N>) {
self.device = out_ctx.clone()

Check failure on line 84 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / build

[clippy] reported by reviewdog 🐶 error: consider adding a `;` to the last statement for consistent formatting --> src/context/mod.rs:84:9 | 84 | self.device = out_ctx.clone() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `self.device = out_ctx.clone();` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic` = help: to override `-D clippy::pedantic` add `#[allow(clippy::semicolon_if_nothing_returned)]` Raw Output: src/context/mod.rs:84:9:e:error: consider adding a `;` to the last statement for consistent formatting --> src/context/mod.rs:84:9 | 84 | self.device = out_ctx.clone() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `self.device = out_ctx.clone();` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic` = help: to override `-D clippy::pedantic` add `#[allow(clippy::semicolon_if_nothing_returned)]` __END__

Check failure on line 84 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / build

[clippy] reported by reviewdog 🐶 error: using `clone` on type `Device<N>` which implements the `Copy` trait --> src/context/mod.rs:84:23 | 84 | self.device = out_ctx.clone() | ^^^^^^^^^^^^^^^ help: try dereferencing it: `*out_ctx` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `-D clippy::clone-on-copy` implied by `-D clippy::all` = help: to override `-D clippy::all` add `#[allow(clippy::clone_on_copy)]` Raw Output: src/context/mod.rs:84:23:e:error: using `clone` on type `Device<N>` which implements the `Copy` trait --> src/context/mod.rs:84:23 | 84 | self.device = out_ctx.clone() | ^^^^^^^^^^^^^^^ help: try dereferencing it: `*out_ctx` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `-D clippy::clone-on-copy` implied by `-D clippy::all` = help: to override `-D clippy::all` add `#[allow(clippy::clone_on_copy)]` __END__
}
}
impl<const N: usize> InputHandler for Input<N> {
fn control(&self) -> &dyn InputControlHandler {
Expand Down Expand Up @@ -216,6 +222,16 @@
self.as_mut()[1].set_bit(i, false);
}

/// clear all add flag expect ep 0
fn clear_all_nonep0_add_flag(&mut self) {
self.as_mut()[1] = 1u32;
}

/// clear all drop flag
fn clear_all_drop_flag(&mut self) {
self.as_mut()[0] = 0u32;
}

rw_field_cx!([7](0..=7), configuration_value, "Configuration Value", u8);
rw_field_cx!([7](8..=15), interface_number, "Interface Number", u8);
rw_field_cx!([7](16..=23), alternate_setting, "Alternate Setting", u8);
Expand Down Expand Up @@ -283,6 +299,10 @@

&mut self.endpoints[dci - 1]
}

fn fill_endpoints_with_0(&mut self) {
self.endpoints.fill(Endpoint::new())

Check failure on line 304 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / build

[clippy] reported by reviewdog 🐶 error: consider adding a `;` to the last statement for consistent formatting --> src/context/mod.rs:304:9 | 304 | self.endpoints.fill(Endpoint::new()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `self.endpoints.fill(Endpoint::new());` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned Raw Output: src/context/mod.rs:304:9:e:error: consider adding a `;` to the last statement for consistent formatting --> src/context/mod.rs:304:9 | 304 | self.endpoints.fill(Endpoint::new()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `self.endpoints.fill(Endpoint::new());` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned __END__
}
}

/// A trait to handle Device Context.
Expand All @@ -308,6 +328,9 @@
/// This method panics if `dci > 31 || dci == 0`. Call [`DeviceHandler::slot_mut`] if you want
/// a mutable handler of Slot Context.
fn endpoint_mut(&mut self, dci: usize) -> &mut dyn EndpointHandler;

/// fill all endpoints with 0
fn fill_endpoints_with_0(&mut self);
}

/// Slot Context.
Expand Down
2 changes: 1 addition & 1 deletion src/registers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
/// ```
pub unsafe fn new(mmio_base: usize, mapper: M) -> Self {
let capability = Capability::new(mmio_base, &mapper);
let doorbell = doorbell::Doorbell::new(mmio_base, &capability, mapper.clone());
let doorbell = Doorbell::new(mmio_base, &capability, mapper.clone());
let operational =
Operational::new(mmio_base, capability.caplength.read_volatile(), &mapper);
let port_register_set = PortRegisterSet::new(mmio_base, &capability, mapper.clone());
Expand Down
Loading