Skip to content

Commit

Permalink
Add clkops trait callback
Browse files Browse the repository at this point in the history
  • Loading branch information
lvyuemeng committed Jul 28, 2024
1 parent 4f90d0e commit c6f5534
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 87 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,6 @@ sphinx_*/

# Rust analyzer configuration
/rust-project.json

# lsp config
code_init.sh
74 changes: 0 additions & 74 deletions rust/kernel/clk_hw.rs

This file was deleted.

77 changes: 64 additions & 13 deletions rust/kernel/clk_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
//!
//! C header: [`include/linux/clk.h`](../../../../include/linux/clk-provider.h)
use core::ffi::c_ulong;

use crate::{
bindings,
error::{to_result, Result},
bindings, clk_hw,
error::{from_result, to_result, Result},
str::CStr,
types::Opaque,
};
Expand Down Expand Up @@ -42,6 +44,17 @@ impl ClkHw {
self.0.get()
}

// Unsafe: Argumets Wrapped in CStr.
unsafe fn register_clkdev(&mut self, con_id: &'static CStr, dev_id: &'static CStr) -> i32 {
unsafe {
bindings::clk_hw_register_clkdev(
self.0.get(),
con_id.as_char_ptr(),
dev_id.as_char_ptr(),
)
}
}

// How to implement clk_hw api?
/*
pub fn prepare_enable(&mut self) -> Result {
Expand All @@ -57,17 +70,6 @@ impl ClkHw {
Ok(())
}
*/

// Unsafe: Argumets Wrapped in CStr.
unsafe fn register_clkdev(&mut self, con_id: &'static CStr, dev_id: &'static CStr) -> i32 {
unsafe {
bindings::clk_hw_register_clkdev(
self.0.get(),
con_id.as_char_ptr(),
dev_id.as_char_ptr(),
)
}
}
}

/*
Expand Down Expand Up @@ -103,3 +105,52 @@ impl ClkOps {
self.0.get()
}
}

// TODO: Implement All ClkOps methods
#[vtable]
pub trait ClkOpsBase {
/// User data that will be accessible to all operations
type Data: ForeignOwnable + Send + Sync = ();

fn set_rate(_hw: &mut ClkHw, _rate: u32, _parent_rate: u32) -> Result<i32>;

fn round_rate(_hw: &mut ClkHw, _rate: u32, _round_rate: *mut u32) -> Result<i32>;

fn recalc_rate(_hw: &mut ClkHw, parent_rate: u32) -> u32;
}

unsafe extern "C" fn set_rate_callback<T: ClkOpsBase>(
hw: *mut bindings::clk_hw,
rate: core::ffi::c_ulong,
parent_rate: core::ffi::c_ulong,
) -> core::ffi::c_int {
from_result(|| {
unsafe {
let hw = ClkHw::from_raw(hw);
}
T::set_rate(hw, rate, parent_rate)
})
}

unsafe extern "C" fn round_rate_callback<T: ClkOpsBase>(
hw: *mut bindings::clk_hw,
rate: core::ffi::c_ulong,
round_rate: *mut core::ffi::c_ulong,
) -> core::ffi::c_int {
from_result(|| {
unsafe {
let hw = ClkHw::from_raw(hw);
}
T::round_rate(hw, rate, round_rate)
})
}

unsafe extern "C" fn recalc_rate_callback<T: ClkOpsBase>(
hw: *mut bindings::clk_hw,
parent_rate: core::ffi::c_ulong,
) -> core::ffi::c_ulong {
unsafe {
let hw = ClkHw::from_raw(hw);
}
T::recalc_rate(hw, parent_rate)
}

0 comments on commit c6f5534

Please sign in to comment.