|
| 1 | +//! Arm PMU |
| 2 | +macro_rules! sys_coproc_read_raw { |
| 3 | + ($width:ty, [$cp:ident, $crn:ident, $opc1:literal, $crm:ident, $opc2:literal]) => { |
| 4 | + #[inline] |
| 5 | + fn get(&self) -> u32 { |
| 6 | + let reg; |
| 7 | + unsafe { |
| 8 | + asm!( |
| 9 | + concat!( |
| 10 | + "mrc ", stringify!($cp), ", ", stringify!($opc1), ", {}, ", |
| 11 | + stringify!($crn), ", ", stringify!($crm), ", ", stringify!($opc2) |
| 12 | + ), |
| 13 | + out(reg)reg, |
| 14 | + ); |
| 15 | + } |
| 16 | + reg |
| 17 | + } |
| 18 | + }; |
| 19 | +} |
| 20 | +/// Implements `register::cpu::RegisterReadWrite::set`. |
| 21 | +macro_rules! sys_coproc_write_raw { |
| 22 | + ($width:ty, [$cp:ident, $crn:ident, $opc1:literal, $crm:ident, $opc2:literal]) => { |
| 23 | + #[inline] |
| 24 | + fn set(&self, value: u32) { |
| 25 | + unsafe { |
| 26 | + asm!( |
| 27 | + concat!( |
| 28 | + "mcr ", stringify!($cp), ", ", stringify!($opc1), ", {}, ", |
| 29 | + stringify!($crn), ", ", stringify!($crm), ", ", stringify!($opc2) |
| 30 | + ), |
| 31 | + in(reg)value, |
| 32 | + ); |
| 33 | + } |
| 34 | + } |
| 35 | + }; |
| 36 | +} |
| 37 | + |
| 38 | +register::register_bitfields! {u32, |
| 39 | + pub PMCNTENSET [ |
| 40 | + /// PMCCNTR enable bit. |
| 41 | + C OFFSET(31) NUMBITS(1) [] |
| 42 | + ] |
| 43 | +} |
| 44 | + |
| 45 | +/// Performance Monitors Count Enable Set register |
| 46 | +pub const PMCNTENSET: PMCNTENSETAccessor = PMCNTENSETAccessor; |
| 47 | +pub struct PMCNTENSETAccessor; |
| 48 | + |
| 49 | +impl register::cpu::RegisterReadWrite<u32, PMCNTENSET::Register> for PMCNTENSETAccessor { |
| 50 | + sys_coproc_read_raw!(u32, [p15, c9, 0, c12, 1]); |
| 51 | + sys_coproc_write_raw!(u32, [p15, c9, 0, c12, 1]); |
| 52 | +} |
| 53 | + |
| 54 | +register::register_bitfields! {u32, |
| 55 | + pub PMCR [ |
| 56 | + /// Clock divider. |
| 57 | + D OFFSET(3) NUMBITS(1) [ |
| 58 | + DivideBy1 = 0, |
| 59 | + DivideBy64 = 1 |
| 60 | + ], |
| 61 | + /// Enable. |
| 62 | + E OFFSET(0) NUMBITS(1) [] |
| 63 | + ] |
| 64 | +} |
| 65 | + |
| 66 | +/// Performance Monitors Control Register |
| 67 | +pub const PMCR: PMCRAccessor = PMCRAccessor; |
| 68 | +pub struct PMCRAccessor; |
| 69 | + |
| 70 | +impl register::cpu::RegisterReadWrite<u32, PMCR::Register> for PMCRAccessor { |
| 71 | + sys_coproc_read_raw!(u32, [p15, c9, 0, c12, 0]); |
| 72 | + sys_coproc_write_raw!(u32, [p15, c9, 0, c12, 0]); |
| 73 | +} |
| 74 | + |
| 75 | +/// Performance Monitors Cycle Count Register |
| 76 | +pub const PMCCNTR: PMCCNTRAccessor = PMCCNTRAccessor; |
| 77 | +pub struct PMCCNTRAccessor; |
| 78 | + |
| 79 | +impl register::cpu::RegisterReadWrite<u32, ()> for PMCCNTRAccessor { |
| 80 | + sys_coproc_read_raw!(u32, [p15, c9, 0, c13, 0]); |
| 81 | + sys_coproc_write_raw!(u32, [p15, c9, 0, c13, 0]); |
| 82 | +} |
0 commit comments