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

Rework PCI emulation to better expose inner data #57

Closed
wants to merge 2 commits into from

Conversation

pfmooney
Copy link
Collaborator

The previous structure for PCI device emulation made it inconvenient to
access the inner data of devices for initialization during setup. This
attempts to flatten some of the data model at the cost of more
monoporphization.

The previous structure for PCI device emulation made it inconvenient to
access the inner data of devices for initialization during setup.  This
attempts to flatten some of the data model at the cost of more
monoporphization.
@pfmooney pfmooney requested a review from luqmana October 14, 2021 03:47
Comment on lines +471 to +478
struct IsrInner {
disabled: bool,
value: u8,
pin: Option<Arc<dyn IntrPin>>,
}
struct IsrState {
inner: Mutex<IsrInner>,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a useful abstraction we could use for other device code

Copy link
Collaborator Author

@pfmooney pfmooney Oct 18, 2021

Choose a reason for hiding this comment

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

I'll work on something a more generic for this stuff. (separately)

Comment on lines +110 to 118
let bnum = BusNum::new(bus);
let dnum = DevNum::new(dev);
let fnum = FuncNum::new(func);
match (bnum, dnum, fnum) {
(Some(b), Some(d), Some(f)) => {
Some(Self { bus: b, dev: d, func: f })
}
_ => None,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let bnum = BusNum::new(bus);
let dnum = DevNum::new(dev);
let fnum = FuncNum::new(func);
match (bnum, dnum, fnum) {
(Some(b), Some(d), Some(f)) => {
Some(Self { bus: b, dev: d, func: f })
}
_ => None,
}
let bus = BusNum::new(bus)?;
let dev = DevNum::new(dev)?;
let func = FuncNum::new(func)?;
Some(Self { bus, dev, func })

? also works for Option

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's probably how I wrote it the first time. Unfortunately:

error[E0658]: ? is not allowed in a const fn
note: see issue #74935 rust-lang/rust#74935 for more information

I'll add a comment mentioning it, though.

let res = self.slots[bdf.dev.get() as usize].funcs
[bdf.func.get() as usize]
.as_ref()
.map(|d| Arc::clone(d));
Copy link
Contributor

Choose a reason for hiding this comment

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

Small suggestion: you can eschew the extra lambda here by just passing Arc:clone directly: .map(Arc::clone)

Copy link
Contributor

@luqmana luqmana left a comment

Choose a reason for hiding this comment

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

LGTM, aside from a few small nits. Factoring out the IsrState stuff can be done separately.

@pfmooney pfmooney closed this Oct 18, 2021
@pfmooney pfmooney deleted the pci-rework branch October 18, 2021 21:04
@pfmooney
Copy link
Collaborator Author

Merged in c3558de

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants