-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
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.
struct IsrInner { | ||
disabled: bool, | ||
value: u8, | ||
pin: Option<Arc<dyn IntrPin>>, | ||
} | ||
struct IsrState { | ||
inner: Mutex<IsrInner>, | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
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, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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 aconst fn
note: see issue #74935 rust-lang/rust#74935 for more information
I'll add a comment mentioning it, though.
propolis/src/hw/pci/bus.rs
Outdated
let res = self.slots[bdf.dev.get() as usize].funcs | ||
[bdf.func.get() as usize] | ||
.as_ref() | ||
.map(|d| Arc::clone(d)); |
There was a problem hiding this comment.
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)
There was a problem hiding this 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.
Merged in c3558de |
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.