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
dragonball: add pci root bus and root device #8564
dragonball: add pci root bus and root device #8564
Conversation
@@ -2,8 +2,6 @@ | |||
// | |||
// SPDX-License-Identifier: Apache-2.0 | |||
|
|||
use std::any::Any; |
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.
Here's no compile warning check in CI?
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.
There is a bug in Dragonball CI and I have fixed it in #8599
@@ -30,22 +30,34 @@ mod bus; | |||
mod configuration; | |||
mod device; | |||
|
|||
pub use self::bus::PciBus; |
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.
Could we change the style like below?
mod xxx;
pub use xxx:yyy;
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.
modified.
|
||
use crate::fill_config_data; | ||
use crate::{Error, PciBus, Result}; | ||
#[derive(PartialEq)] |
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.
add a blank line here
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.
added
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.
Thanks @studychao! A few comments here.
let state = self.state.read().unwrap(); | ||
let (b, d, f, o) = parse_mmio_address(offset); | ||
if let Some(bus) = state.buses.get(&b) { | ||
return bus.read_config(d, f, o | ((offset as u32) & 0x3), data); |
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.
Could you set a const for 0x3
to describe what it is? Or leave some comments here.
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 found out that 0x3 is useless in this method because parse_mmio_address
will use the lowest 12 bits, so I remove them from the code.
let state = self.state.read().unwrap(); | ||
let (b, d, f, o) = parse_mmio_address(offset); | ||
if let Some(bus) = state.buses.get(&b) { | ||
return bus.write_config(d, f, o | (offset as u32 & 0x3), data); |
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.
Ditto.
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.
ditto
let len = data.len(); | ||
|
||
// Only allow naturally aligned Dword, Word and Byte access. | ||
if (len == 4 || len == 2 || len == 1) && offset as usize & (len - 1) == 0 { |
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.
Could you wrap this into an inline function? It is used three times.
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.
done, actually it is used four times lol
let offset = offset.raw_value(); | ||
let len = data.len(); | ||
|
||
if (len == 4 || len == 2 || len == 1) && offset as usize & (len - 1) == 0 { |
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.
Ditto.
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.
ditto
let len = data.len(); | ||
|
||
// Only allow naturally aligned Dword, Word and Byte access. | ||
if (len == 4 || len == 2 || len == 1) && offset as usize & (len - 1) == 0 { |
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.
Ditto.
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.
ditto
let shift = (offset & 0x3) * 8; | ||
if len == 4 { | ||
state.io_addr = NativeEndian::read_u32(data); | ||
} else if len == 2 { | ||
state.io_addr &= !(0xffffu32 << shift); | ||
state.io_addr |= u32::from(NativeEndian::read_u16(data)) << shift; | ||
} else { | ||
state.io_addr &= !(0xffu32 << shift); |
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.
There is a lot of hard code here.
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.
comments all added.
4..=7 => { | ||
// Safe to unwrap because no legal to generate poisoned RwLock. | ||
let state = self.state.read().unwrap(); | ||
if state.io_addr & 0x8000_0000 != 0 { |
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.
Hard code again.
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.
comment added.
bus_number, | ||
device_number, | ||
function_number, | ||
register_number & !0x3u32, |
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.
Ditto.
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.
document added.
(addr >> 20) & 0xff, | ||
(addr >> 15) & 0x1f, | ||
(addr >> 12) & 0x7, | ||
addr & 0xfff, |
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.
Ditto.
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.
const added.
@@ -324,8 +322,8 @@ impl PartialEq for PciBus { | |||
|
|||
#[inline] | |||
fn check_pci_cfg_valid(dev: u32, func: u32, offset: u32, data_len: usize) -> bool { | |||
dev > 0x1f || func !=0 || offset >= 0x1000 || offset & (data_len - 1 ) as u32 & 0x3 != 0 | |||
} | |||
dev > 0x1f || func != 0 || offset >= 0x1000 || offset & (data_len - 1) as u32 & 0x3 != 0 |
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.
Could you leave some comments here?
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
9a1da7e
to
e970b60
Compare
In order to follow up the PCI implementation in Dragonball, we need to add PCI root device and root bus support. root device is a pseudo PCI root device to manage accessing to PCI configuration space. root bus is mainly for emulating PCI root bridge and also create the PCI root bus with the given bus ID with the PCI root bridge. fixes: kata-containers#8563 Signed-off-by: Gerry Liu <gerry@linux.alibaba.com> Signed-off-by: Zizheng Bian <zizheng.bian@linux.alibaba.com> Signed-off-by: Shifang Feng <fengshifang@linux.alibaba.com> Signed-off-by: Yang Su <yang.su@linux.alibaba.com> Signed-off-by: Zha Bin <zhabin@linux.alibaba.com> Signed-off-by: Xin Lin <jingshan@linux.alibaba.com> Signed-off-by: Chao Wu <chaowu@linux.alibaba.com>
e970b60
to
b079e1a
Compare
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
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, thanks!
/test |
/test-arm |
In order to follow up the PCI implementation in Dragonball, we need to add PCI root device and root bus support.
root device is a pseudo PCI root device to manage accessing to PCI configuration space.
root bus is mainly for emulating PCI root bridge and also create the PCI root bus with the given bus ID with the PCI root bridge.
fixes: #8563
Signed-off-by: Gerry Liu gerry@linux.alibaba.com
Signed-off-by: Zizheng Bian zizheng.bian@linux.alibaba.com
Signed-off-by: Shifang Feng fengshifang@linux.alibaba.com
Signed-off-by: Yang Su yang.su@linux.alibaba.com
Signed-off-by: Zha Bin zhabin@linux.alibaba.com
Signed-off-by: Xin Lin jingshan@linux.alibaba.com
Signed-off-by: Chao Wu chaowu@linux.alibaba.com