xref: /cloud-hypervisor/devices/src/legacy/fwdebug.rs (revision 19d36c765fdf00be749d95b3e61028bc302d6d73)
1 // Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE-BSD-3-Clause file.
4 //
5 // Copyright © 2020 Intel Corporation
6 //
7 // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
8 //
9 
10 use std::sync::{Arc, Barrier};
11 
12 use vm_device::BusDevice;
13 
14 /// Provides firmware debug output via I/O port controls
15 #[derive(Default)]
16 pub struct FwDebugDevice {}
17 
18 impl FwDebugDevice {
19     pub fn new() -> Self {
20         Self {}
21     }
22 }
23 
24 /// FwDebugDevice sits on the I/O bus as 0x402 and receives ASCII characters
25 impl BusDevice for FwDebugDevice {
26     /// Upon read return the magic value to indicate that there is a debug port
27     fn read(&mut self, _base: u64, _offset: u64, data: &mut [u8]) {
28         if data.len() == 1 {
29             data[0] = 0xe9
30         } else {
31             error!("Invalid read size on debug port: {}", data.len())
32         }
33     }
34 
35     fn write(&mut self, _base: u64, _offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
36         if data.len() == 1 {
37             print!("{}", data[0] as char);
38         } else {
39             error!("Invalid write size on debug port: {}", data.len())
40         }
41 
42         None
43     }
44 }
45