Skip to content
Merged
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
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ members = [
"drivers/blk/*",
"drivers/examples/*",
"drivers/firmware/*",
"drivers/gpu/*",
"drivers/intc/*",
"drivers/interface/*",
"drivers/net/*",
Expand Down Expand Up @@ -242,6 +243,7 @@ rdif-timer = { version = "0.6.3", path = "drivers/interface/rdif-timer" }
rdif-vsock = { version = "0.1.2", path = "drivers/interface/rdif-vsock" }
rk3588-pci = { version = "0.2.3", path = "drivers/pci/rk3588-pci" }
rockchip-npu = { version = "0.2.5", path = "drivers/npu/rockchip-npu" }
rockchip-rga = { version = "0.1.0", path = "drivers/gpu/rockchip-rga" }
k230-kpu = { version = "0.1.0", path = "drivers/npu/k230-kpu" }
realtek-rtl8125 = { version = "0.2.3", path = "drivers/net/realtek-rtl8125" }
rockchip-pm = { version = "0.4.5", path = "drivers/soc/rockchip/rockchip-pm" }
Expand Down
2 changes: 2 additions & 0 deletions drivers/ax-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ xhci-pci = ["usb", "pci"]
serial = ["plat-dyn", "dep:some-serial"]
sg2002-placeholder = ["plat-dyn"]
rknpu = ["plat-dyn", "rockchip-pm", "rockchip-soc", "dep:rockchip-npu"]
rga = ["plat-dyn", "dep:rockchip-rga"]
rockchip-sdhci = [
"block",
"plat-dyn",
Expand Down Expand Up @@ -134,6 +135,7 @@ rdrive.workspace = true
rdrive-macros.workspace = true
rk3588-pci = { workspace = true, optional = true }
rockchip-npu = { workspace = true, optional = true }
rockchip-rga = { workspace = true, optional = true }
rockchip-pm = { workspace = true, optional = true }
rockchip-soc = { workspace = true, optional = true }
phytium-mci-host = { workspace = true, optional = true }
Expand Down
2 changes: 2 additions & 0 deletions drivers/ax-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pub mod vsock;

#[cfg(feature = "pci")]
pub mod pci;
#[cfg(feature = "rga")]
pub mod rga;
#[cfg(feature = "rknpu")]
pub mod rknpu;
#[cfg(feature = "serial")]
Expand Down
88 changes: 88 additions & 0 deletions drivers/ax-driver/src/rga.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use alloc::vec::Vec;

use log::info;
use rdrive::{
probe::OnProbeError,
register::{FdtInfo, ProbeFdt},
};
use rockchip_rga::{RgaCoreConfig, RgaCoreResource, RockchipRga};

use crate::mmio::iomap;

crate::model_register!(
name: "Rockchip RGA",
level: ProbeLevel::PostKernel,
priority: ProbePriority::DEFAULT,
probe_kinds: &[
ProbeKind::Fdt {
compatibles: &[
"rockchip,rga3_core0",
"rockchip,rga3_core1",
"rockchip,rga2_core0",
],
on_probe: probe
}
],
);

fn probe(probe: ProbeFdt<'_>) -> Result<(), OnProbeError> {
let (info, plat_dev) = probe.into_parts();
let config = detect_core_config(&info)
.ok_or_else(|| OnProbeError::other("unsupported Rockchip RGA compatible string"))?;

let mut resources = Vec::new();
for reg in info.node.regs() {
let start_raw = reg.address as usize;
let size_raw = reg.size.unwrap_or(0x1000) as usize;
let (start, size, offset) = page_aligned_region(start_raw, size_raw);
let base = unsafe { iomap(start, size)?.add(offset) };

resources.push(RgaCoreResource {
base,
size: size_raw,
irq: decode_fdt_irq(&info.interrupts()),
config,
});
}

let dma = axklib::dma::device_with_mask(u32::MAX as u64);
let rga = RockchipRga::new(&resources, dma);
let core_count = rga.core_count();
plat_dev.register(rga);

info!("RGA registered successfully, cores={core_count}");
Ok(())
}

fn detect_core_config(info: &FdtInfo<'_>) -> Option<RgaCoreConfig> {
for compatible in info.node.as_node().compatibles() {
match compatible {
"rockchip,rga3_core0" => return Some(RgaCoreConfig::rga3(0)),
"rockchip,rga3_core1" => return Some(RgaCoreConfig::rga3(1)),
"rockchip,rga2_core0" => return Some(RgaCoreConfig::rga2(0)),
_ => {}
}
}
None
}

fn page_aligned_region(start_raw: usize, size_raw: usize) -> (usize, usize, usize) {
let page_size = 0x1000;
let start = start_raw & !(page_size - 1);
let offset = start_raw - start;
let end = (start_raw + size_raw + page_size - 1) & !(page_size - 1);
(start, end - start, offset)
}

fn decode_fdt_irq(interrupts: &[rdrive::probe::fdt::InterruptRef]) -> Option<usize> {
let interrupt = interrupts.first()?;
match interrupt.specifier.as_slice() {
[irq] => Some(*irq as usize),
[kind, irq, ..] => match *kind {
0 => Some(*irq as usize + 32),
1 => Some(*irq as usize + 16),
_ => Some(*irq as usize),
},
_ => None,
}
}
14 changes: 14 additions & 0 deletions drivers/gpu/rockchip-rga/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
authors.workspace = true
categories = ["embedded", "hardware-support", "no-std"]
description = "Low-level device layer for Rockchip RGA 2D accelerators"
edition.workspace = true
keywords = ["rk3588", "rga", "graphics"]
license.workspace = true
name = "rockchip-rga"
repository.workspace = true
version = "0.1.0"

[dependencies]
dma-api.workspace = true
rdif-base.workspace = true
Loading