-
Notifications
You must be signed in to change notification settings - Fork 110
devices/x86_64: add cmos legacy device #419
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
Open
slp
wants to merge
3
commits into
containers:main
Choose a base branch
from
slp:add-cmos-device
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2025 Red Hat, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::cmp::min; | ||
|
||
use crate::bus::BusDevice; | ||
|
||
const INDEX_MASK: u8 = 0x7f; | ||
const INDEX_OFFSET: u64 = 0x0; | ||
const DATA_OFFSET: u64 = 0x1; | ||
const DATA_LEN: usize = 128; | ||
|
||
pub struct Cmos { | ||
index: u8, | ||
data: [u8; DATA_LEN], | ||
} | ||
|
||
impl Cmos { | ||
pub fn new(mem_below_4g: u64, mem_above_4g: u64) -> Cmos { | ||
debug!("cmos: mem_below_4g={mem_below_4g} mem_above_4g={mem_above_4g}"); | ||
|
||
let mut data = [0u8; DATA_LEN]; | ||
|
||
// Extended memory from 16 MB to 4 GB in units of 64 KB | ||
let ext_mem = min( | ||
0xFFFF, | ||
mem_below_4g.saturating_sub(16 * 1024 * 1024) / (64 * 1024), | ||
MatiasVara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
data[0x34] = ext_mem as u8; | ||
data[0x35] = (ext_mem >> 8) as u8; | ||
|
||
// High memory (> 4GB) in units of 64 KB | ||
let high_mem = min(0xFFFFFF, mem_above_4g / (64 * 1024)); | ||
data[0x5b] = high_mem as u8; | ||
data[0x5c] = (high_mem >> 8) as u8; | ||
data[0x5d] = (high_mem >> 16) as u8; | ||
|
||
Cmos { index: 0, data } | ||
} | ||
} | ||
|
||
impl BusDevice for Cmos { | ||
fn read(&mut self, _vcpuid: u64, offset: u64, data: &mut [u8]) { | ||
if data.len() != 1 { | ||
error!("cmos: unsupported read length"); | ||
return; | ||
} | ||
|
||
data[0] = match offset { | ||
INDEX_OFFSET => { | ||
debug!("cmos: read index offset"); | ||
self.index | ||
} | ||
DATA_OFFSET => { | ||
debug!("cmos: read data offset from index={:x}", self.index); | ||
self.data[(self.index & INDEX_MASK) as usize] | ||
} | ||
_ => { | ||
debug!("cmos: unsupported read offset"); | ||
0 | ||
} | ||
}; | ||
} | ||
|
||
fn write(&mut self, _vcpuid: u64, offset: u64, data: &[u8]) { | ||
if data.len() != 1 { | ||
error!("cmos: unsupported write length"); | ||
return; | ||
} | ||
|
||
match offset { | ||
INDEX_OFFSET => { | ||
debug!("cmos: update index"); | ||
self.index = data[0] & INDEX_MASK; | ||
} | ||
_ => error!("cmos: unsupported write to CMOS"), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod cmos; | ||
pub mod serial; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.