Skip to content

Define and implement GicTrait using the crate_interface #4

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Build output and other log files from arceos
/target
*.asm
*.img
*.bin
*.elf
actual.out
qemu.log
rusty-tags.vi

# Visual Studio Code settings
/.vscode

# macOS system files
.DS_Store

# We ignore Cargo.lock because `axvcpu` is just a library
Cargo.lock
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"

members = [
"axdevice_base",
"vgic"
]

[workspace.package]
Expand All @@ -13,4 +14,5 @@ homepage = ""
repository = ""

[workspace.dependencies]
axdevice_base = { path = "axdevice_base", version = "0.1"}
axdevice_base = { path = "axdevice_base", version = "0.1"}
vgic = { path = "vgic", version = "0.1"}
19 changes: 19 additions & 0 deletions vgic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "vgic"
edition = "2021"
version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axdevice_base = { path = "../axdevice_base" }
axaddrspace = { path = "../../axaddrspace" }
memory_addr = "0.3.0"
axerrno = "0.1.0"
crate_interface = "0.1.0"
log = "0.4"
spin = "0.9"
66 changes: 66 additions & 0 deletions vgic/src/gic_traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate_interface::call_interface;

#[crate_interface::def_interface]
pub trait GicTrait {
fn set_enable(vector: usize, enable: bool);
fn get_enable(vector: usize) -> bool;
fn get_typer() -> u32;
fn get_iidr() -> u32;

fn set_state(int_id: usize, state: usize, current_cpu_id: usize);
fn get_state(int_id: usize) -> usize;

fn set_icfgr(int_id: usize, cfg: u8);

fn get_target_cpu(int_id: usize) -> usize;
fn set_target_cpu(int_id: usize, target: u8);

fn get_priority(int_id: usize) -> usize;
fn set_priority(int_id: usize, priority: u8);
}

pub struct GicInterface;

/// Implementation of [`GicTrait`] by crate_interface::call_interface,
/// to provide an easy-to-use interface to
/// the [vgic] crate.
impl GicInterface {
pub fn set_enable(vector: usize, enable: bool) {
call_interface!(GicTrait::set_enable(vector, enable));
}
pub fn get_enable(vector: usize) -> bool {
call_interface!(GicTrait::get_enable(vector))
}

pub fn get_typer() -> u32 {
call_interface!(GicTrait::get_typer())
}
fn get_iidr() -> u32 {
call_interface!(GicTrait::get_iidr())
}

pub fn set_state(int_id: usize, state: usize, current_cpu_id: usize) {
call_interface!(GicTrait::set_state(int_id, state, current_cpu_id));
}
fn get_state(int_id: usize) -> usize {
call_interface!(GicTrait::get_state(int_id))
}

fn set_icfgr(int_id: usize, cfg: u8) {
call_interface!(GicTrait::set_icfgr(int_id, cfg));
}

fn get_target_cpu(int_id: usize) -> usize {
call_interface!(GicTrait::get_target_cpu(int_id))
}
fn set_target_cpu(int_id: usize, target: u8) {
call_interface!(GicTrait::set_target_cpu(int_id, target));
}

fn get_priority(int_id: usize) -> usize {
call_interface!(GicTrait::get_priority(int_id))
}
fn set_priority(int_id: usize, priority: u8) {
call_interface!(GicTrait::set_priority(int_id, priority));
}
}
6 changes: 6 additions & 0 deletions vgic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![no_std]

mod gic_traits;

pub use gic_traits::GicInterface;
pub use gic_traits::GicTrait;