forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements basic RTKit bring-up and UAT page table management. Signed-off-by: Asahi Lina <lina@asahilina.net>
- Loading branch information
Showing
6 changed files
with
568 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,14 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
config DRM_ASAHI | ||
tristate "Asahi (DRM support for Apple AGX GPUs)" | ||
depends on RUST | ||
depends on DRM | ||
depends on (ARM64 && ARCH_APPLE) || (COMPILE_TEST && !GENERIC_ATOMIC64) | ||
depends on MMU | ||
select DRM_SCHED | ||
select IOMMU_SUPPORT | ||
select IOMMU_IO_PGTABLE_LPAE | ||
select DRM_GEM_SHMEM_HELPER | ||
help | ||
DRM driver for Apple AGX GPUs (G13x, found in the M1 SoC family) |
This file contains 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,7 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
asahi-y := \ | ||
asahi_drv.o \ | ||
asahi_mmu.o | ||
|
||
obj-$(CONFIG_DRM_ASAHI) += asahi.o |
This file contains 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,105 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
|
||
//! Driver for the Apple AGX GPUs found in Apple Silicon SoCs. | ||
|
||
use kernel::{ | ||
bindings, device, | ||
error::{to_result, Result}, | ||
io_mem::IoMem, | ||
module_platform_driver, of, platform, | ||
prelude::*, | ||
soc::apple::rtkit, | ||
sync::smutex::Mutex, | ||
sync::{Arc, ArcBorrow}, | ||
}; | ||
|
||
const ASC_CTL_SIZE: usize = 0x4000; | ||
const CPU_CONTROL: usize = 0x44; | ||
const CPU_RUN: u32 = 0x1 << 4; // BIT(4) | ||
|
||
struct AsahiData { | ||
dev: device::Device, | ||
rtkit: Mutex<Option<rtkit::RTKit<AsahiDevice>>>, | ||
} | ||
|
||
struct AsahiResources { | ||
asc: IoMem<ASC_CTL_SIZE>, | ||
} | ||
|
||
type DeviceData = device::Data<(), AsahiResources, AsahiData>; | ||
|
||
struct AsahiDevice; | ||
|
||
impl AsahiDevice { | ||
fn start_cpu(data: ArcBorrow<'_, DeviceData>) -> Result { | ||
let res = data.resources().ok_or(ENXIO)?; | ||
let val = res.asc.readl_relaxed(CPU_CONTROL); | ||
|
||
res.asc.writel_relaxed(val | CPU_RUN, CPU_CONTROL); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[vtable] | ||
impl rtkit::Operations for AsahiDevice { | ||
type Data = (); | ||
} | ||
|
||
extern "C" { | ||
pub fn asahi_mmu_init(dev: *mut bindings::device) -> core::ffi::c_int; | ||
} | ||
|
||
impl platform::Driver for AsahiDevice { | ||
type Data = Arc<DeviceData>; | ||
|
||
kernel::define_of_id_table! {(), [ | ||
(of::DeviceId::Compatible(b"apple,agx-t8103"), None), | ||
]} | ||
|
||
fn probe( | ||
pdev: &mut platform::Device, | ||
_id_info: Option<&Self::IdInfo>, | ||
) -> Result<Arc<DeviceData>> { | ||
let dev = device::Device::from_dev(pdev); | ||
|
||
dev_info!(dev, "probing!\n"); | ||
|
||
// TODO: add device abstraction to ioremap by name | ||
// SAFETY: AGX does DMA via the UAT IOMMU (mostly) | ||
let asc_reg = unsafe { pdev.ioremap_resource(0)? }; | ||
|
||
let data = kernel::new_device_data!( | ||
(), | ||
AsahiResources { | ||
// SAFETY: This device does DMA via the UAT IOMMU. | ||
asc: asc_reg, | ||
}, | ||
AsahiData { | ||
dev: dev, | ||
rtkit: Mutex::new(None), | ||
}, | ||
"Asahi::Registrations" | ||
)?; | ||
|
||
let data = Arc::<DeviceData>::from(data); | ||
|
||
AsahiDevice::start_cpu(data.as_ref_borrow())?; | ||
|
||
to_result(unsafe { asahi_mmu_init((&data.dev as &dyn device::RawDevice).raw_device()) })?; | ||
|
||
let mut rtkit = unsafe { rtkit::RTKit::<AsahiDevice>::new(&data.dev, None, 0, ()) }?; | ||
|
||
rtkit.boot()?; | ||
*data.rtkit.lock() = Some(rtkit); | ||
|
||
dev_info!(data.dev, "probed!\n"); | ||
Ok(data) | ||
} | ||
} | ||
|
||
module_platform_driver! { | ||
type: AsahiDevice, | ||
name: "asahi", | ||
license: "Dual MIT/GPL", | ||
} |
Oops, something went wrong.