blob: cc429396c60c223c393858697b75617fb36db37c [file] [log] [blame]
Pierre-Clément Tosi82aaf032024-10-30 21:00:38 +00001// Copyright 2024, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Low-level CPU-specific operations.
16
Pierre-Clément Tosi043dfb72024-10-30 21:17:10 +000017#[cfg(target_arch = "aarch64")]
Pierre-Clément Tosi82aaf032024-10-30 21:00:38 +000018pub mod aarch64;
19
Bartłomiej Grzesik86f108d2024-11-29 15:48:00 +010020#[cfg(target_arch = "aarch64")]
21pub use aarch64::platform;
22
Michał Mazurekf08509a2025-01-24 11:39:24 +000023#[cfg(target_arch = "aarch64")]
24pub use aarch64::layout;
25
Michał Mazurek6cd065f2024-11-29 13:07:11 +010026#[cfg(target_arch = "aarch64")]
27pub use aarch64::linker;
28
Michał Mazurek626347c2024-11-29 13:08:27 +010029#[cfg(target_arch = "aarch64")]
30pub use aarch64::dbm;
31
Bartłomiej Grzesik3d7fccf2025-01-30 15:10:01 +000032#[cfg(target_arch = "aarch64")]
Bartłomiej Grzesikee0a5c62025-02-04 09:06:17 +000033pub use aarch64::rand;
34
35#[cfg(target_arch = "aarch64")]
Bartłomiej Grzesik3d7fccf2025-01-30 15:10:01 +000036pub use aarch64::uart;
37
Bartłomiej Grzesik802ad042025-01-30 14:00:06 +000038#[cfg(target_arch = "aarch64")]
39pub use aarch64_paging::paging::VirtualAddress;
40
Pierre-Clément Tosi043dfb72024-10-30 21:17:10 +000041/// Write with well-defined compiled behavior.
42///
43/// See https://github.com/rust-lang/rust/issues/131894
44///
45/// # Safety
46///
47/// `dst` must be valid for writes.
48#[inline]
49pub unsafe fn write_volatile_u8(dst: *mut u8, src: u8) {
50 cfg_if::cfg_if! {
51 if #[cfg(target_arch = "aarch64")] {
52 // SAFETY: `dst` is valid for writes.
53 unsafe { aarch64::strb(dst, src) }
54 } else {
55 compile_error!("Unsupported target_arch")
56 }
57 }
58}
Pierre-Clément Tosi8ab7c372024-10-30 20:46:04 +000059
60/// Flush `size` bytes of data cache by virtual address.
61#[inline]
62pub(crate) fn flush_region(start: usize, size: usize) {
63 cfg_if::cfg_if! {
64 if #[cfg(target_arch = "aarch64")] {
65 let line_size = aarch64::min_dcache_line_size();
66 let end = start + size;
67 let start = crate::util::unchecked_align_down(start, line_size);
Pierre-Clément Tosi8ab7c372024-10-30 20:46:04 +000068 for line in (start..end).step_by(line_size) {
69 crate::dc!("cvau", line);
70 }
71 } else {
72 compile_error!("Unsupported target_arch")
73 }
74 }
75}