linux: reorder video devices after gpu

Create the virtio video-decoder and video-encoder devices after the GPU
device so that the device number of GPU will be consistent on ARCVM
platforms where video devices may or may not exist.

BUG=b:178348623
TEST=boot arcvm on betty and hatch, check gpu pci id is equal

Change-Id: I99d9d0befe6e5aea16fc4e85ed527e4954010466
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2773655
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
This commit is contained in:
Daniel Verkamp 2021-03-18 14:06:15 -07:00 committed by Commit Bot
parent 5018cef82d
commit ffb5912b5e

View file

@ -1124,12 +1124,10 @@ fn create_video_device(
#[cfg(any(feature = "video-decoder", feature = "video-encoder"))]
fn register_video_device(
devs: &mut Vec<VirtioDeviceStub>,
resource_bridges: &mut Vec<Tube>,
video_tube: Tube,
cfg: &Config,
typ: devices::virtio::VideoDeviceType,
) -> std::result::Result<(), Error> {
let (video_tube, gpu_tube) = Tube::pair().map_err(Error::CreateTube)?;
resource_bridges.push(gpu_tube);
devs.push(create_video_device(cfg, typ, video_tube)?);
Ok(())
}
@ -1488,28 +1486,22 @@ fn create_virtio_devices(
}
#[cfg(feature = "video-decoder")]
{
if cfg.video_dec {
register_video_device(
&mut devs,
&mut resource_bridges,
cfg,
devices::virtio::VideoDeviceType::Decoder,
)?;
}
}
let video_dec_tube = if cfg.video_dec {
let (video_tube, gpu_tube) = Tube::pair().map_err(Error::CreateTube)?;
resource_bridges.push(gpu_tube);
Some(video_tube)
} else {
None
};
#[cfg(feature = "video-encoder")]
{
if cfg.video_enc {
register_video_device(
&mut devs,
&mut resource_bridges,
cfg,
devices::virtio::VideoDeviceType::Encoder,
)?;
}
}
let video_enc_tube = if cfg.video_enc {
let (video_tube, gpu_tube) = Tube::pair().map_err(Error::CreateTube)?;
resource_bridges.push(gpu_tube);
Some(video_tube)
} else {
None
};
#[cfg(feature = "gpu")]
{
@ -1565,6 +1557,30 @@ fn create_virtio_devices(
}
}
#[cfg(feature = "video-decoder")]
{
if let Some(video_dec_tube) = video_dec_tube {
register_video_device(
&mut devs,
video_dec_tube,
cfg,
devices::virtio::VideoDeviceType::Decoder,
)?;
}
}
#[cfg(feature = "video-encoder")]
{
if let Some(video_enc_tube) = video_enc_tube {
register_video_device(
&mut devs,
video_enc_tube,
cfg,
devices::virtio::VideoDeviceType::Encoder,
)?;
}
}
if let Some(cid) = cfg.cid {
devs.push(create_vhost_vsock_device(cfg, cid, mem)?);
}