diff options
author | Lepton Wu <lepton@chromium.org> | 2018-11-21 11:06:18 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-14 20:53:53 -0700 |
commit | 608938818be555b51695972a78fc3bbe9c64c850 (patch) | |
tree | 557a028cc1fa98052b516a41751e6ca4f223bb0a /render_node_forward | |
parent | 1bc4a06801a312e4fb770d323c35d34065a4d618 (diff) | |
download | crosvm-608938818be555b51695972a78fc3bbe9c64c850.tar crosvm-608938818be555b51695972a78fc3bbe9c64c850.tar.gz crosvm-608938818be555b51695972a78fc3bbe9c64c850.tar.bz2 crosvm-608938818be555b51695972a78fc3bbe9c64c850.tar.lz crosvm-608938818be555b51695972a78fc3bbe9c64c850.tar.xz crosvm-608938818be555b51695972a78fc3bbe9c64c850.tar.zst crosvm-608938818be555b51695972a78fc3bbe9c64c850.zip |
Start render node host service in crosvm
BUG=b:118408510 TEST=manual - build crosvm with/without crosvm-gpu-forward USE flag and run arcvm. Change-Id: Ibb85d52dc679aa8524b29d86148ca28d82d8fe98 Reviewed-on: https://chromium-review.googlesource.com/1347330 Commit-Ready: Lepton Wu <lepton@chromium.org> Tested-by: Lepton Wu <lepton@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Lepton Wu <lepton@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'render_node_forward')
-rw-r--r-- | render_node_forward/Cargo.toml | 10 | ||||
-rw-r--r-- | render_node_forward/lib.rs | 62 |
2 files changed, 72 insertions, 0 deletions
diff --git a/render_node_forward/Cargo.toml b/render_node_forward/Cargo.toml new file mode 100644 index 0000000..accd36d --- /dev/null +++ b/render_node_forward/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "render_node_forward" +version = "0.1.0" +authors = ["The Chromium OS Authors"] + +[lib] +path = "lib.rs" + +[dependencies] +sys_util = { path = "../sys_util" } diff --git a/render_node_forward/lib.rs b/render_node_forward/lib.rs new file mode 100644 index 0000000..8c04eb9 --- /dev/null +++ b/render_node_forward/lib.rs @@ -0,0 +1,62 @@ +// Copyright 2019 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +extern crate sys_util; + +use sys_util::{GuestAddress, GuestMemory, MemoryMapping}; + +#[link(name = "rendernodehost")] +extern "C" { + fn start_render_node_host( + gpu_host_mem: *mut u8, + gpu_guest_mem_start: u64, + gpu_guest_mem_size: u64, + host_start: *const u8, + host_4g_start: *const u8, + ); +} + +/// The number of bytes in 4 GiB. +pub const FOUR_GB: u64 = (1 << 32); +/// The size required for the render node host in host and guest address space. +pub const RENDER_NODE_HOST_SIZE: u64 = FOUR_GB; + +/// A render node host device that interfaces with the guest render node forwarder. +pub struct RenderNodeHost { + #[allow(dead_code)] + guest_mem: GuestMemory, +} + +impl RenderNodeHost { + /// Starts the render node host forwarding service over the given guest and host address ranges. + pub fn start( + mmap: &MemoryMapping, + gpu_guest_address: u64, + guest_mem: GuestMemory, + ) -> RenderNodeHost { + // Render node forward library need to do address translation between host user space + // address and guest physical address. We could call Rust function from C library. But + // since it's actually a linear mapping now, we just pass the host start address to + // render node forward library. We need two start address here since there would be a + // hole below 4G if guest memory size is bigger than 4G. + + let host_start_addr = guest_mem.get_host_address(GuestAddress(0)).unwrap(); + let host_4g_addr = if guest_mem.memory_size() > FOUR_GB { + guest_mem.get_host_address(GuestAddress(FOUR_GB)).unwrap() + } else { + host_start_addr + }; + // Safe because only valid addresses are given. + unsafe { + start_render_node_host( + mmap.as_ptr(), + gpu_guest_address, + mmap.size() as u64, + host_start_addr, + host_4g_addr, + ) + } + RenderNodeHost { guest_mem } + } +} |