Repository navigation
aml: deliver Notify to the host through Handler::handle_notify #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,13 @@ assert_impl_all!(Object: Send, Sync); | |
| #[derive(Clone, Debug)] | ||
| pub struct WrappedObject(Arc<UnsafeCell<Object>>); | ||
|
|
||
| impl WrappedObject { | ||
| /// Returns `true` if both wrappers refer to the same underlying object. | ||
| pub(crate) fn ptr_eq(&self, other: &WrappedObject) -> bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this function into the main |
||
| Arc::ptr_eq(&self.0, &other.0) | ||
| } | ||
| } | ||
|
|
||
| unsafe impl Send for WrappedObject {} | ||
| unsafe impl Sync for WrappedObject {} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,15 @@ | ||
| use acpi::{ | ||
| Handle, | ||
| Handler, | ||
| RawPhysicalMapping, | ||
| aml::{AmlError, namespace::AmlName}, | ||
| }; | ||
| use aml_test_tools::handlers::null_handler::NullHandler; | ||
| use pci_types::PciAddress; | ||
| use std::{ | ||
| str::FromStr, | ||
| sync::{Arc, Mutex}, | ||
| }; | ||
|
|
||
| mod test_infra; | ||
|
|
||
|
|
@@ -21,3 +32,175 @@ DefinitionBlock ("", "SSDT", 2, "RSACPI", "NOTIFY", 0x00000002) { | |
| let handler = NullHandler {}; | ||
| test_infra::run_aml_test(AML, handler); | ||
| } | ||
|
|
||
| /// A [`NullHandler`] that records every notification it receives. | ||
| #[derive(Clone, Default)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please could the tests be grouped together? (As opposed to having this handler in the middle) Did you consider merging this with |
||
| struct NotifyRecorder { | ||
| notifications: Arc<Mutex<Vec<(AmlName, u64)>>>, | ||
| } | ||
|
|
||
| impl Handler for NotifyRecorder { | ||
| unsafe fn map_physical_region<T>(&self, physical_address: usize, size: usize) -> RawPhysicalMapping<T> { | ||
| unsafe { NullHandler.map_physical_region(physical_address, size) } | ||
| } | ||
|
|
||
| unsafe fn unmap_physical_region<T>(&self, region: RawPhysicalMapping<T>) { | ||
| unsafe { NullHandler.unmap_physical_region(region) } | ||
| } | ||
|
|
||
| fn read_u8(&self, address: usize) -> u8 { | ||
| NullHandler.read_u8(address) | ||
| } | ||
|
|
||
| fn read_u16(&self, address: usize) -> u16 { | ||
| NullHandler.read_u16(address) | ||
| } | ||
|
|
||
| fn read_u32(&self, address: usize) -> u32 { | ||
| NullHandler.read_u32(address) | ||
| } | ||
|
|
||
| fn read_u64(&self, address: usize) -> u64 { | ||
| NullHandler.read_u64(address) | ||
| } | ||
|
|
||
| fn write_u8(&self, address: usize, value: u8) { | ||
| NullHandler.write_u8(address, value) | ||
| } | ||
|
|
||
| fn write_u16(&self, address: usize, value: u16) { | ||
| NullHandler.write_u16(address, value) | ||
| } | ||
|
|
||
| fn write_u32(&self, address: usize, value: u32) { | ||
| NullHandler.write_u32(address, value) | ||
| } | ||
|
|
||
| fn write_u64(&self, address: usize, value: u64) { | ||
| NullHandler.write_u64(address, value) | ||
| } | ||
|
|
||
| fn read_io_u8(&self, port: u16) -> u8 { | ||
| NullHandler.read_io_u8(port) | ||
| } | ||
|
|
||
| fn read_io_u16(&self, port: u16) -> u16 { | ||
| NullHandler.read_io_u16(port) | ||
| } | ||
|
|
||
| fn read_io_u32(&self, port: u16) -> u32 { | ||
| NullHandler.read_io_u32(port) | ||
| } | ||
|
|
||
| fn write_io_u8(&self, port: u16, value: u8) { | ||
| NullHandler.write_io_u8(port, value) | ||
| } | ||
|
|
||
| fn write_io_u16(&self, port: u16, value: u16) { | ||
| NullHandler.write_io_u16(port, value) | ||
| } | ||
|
|
||
| fn write_io_u32(&self, port: u16, value: u32) { | ||
| NullHandler.write_io_u32(port, value) | ||
| } | ||
|
|
||
| fn read_pci_u8(&self, address: PciAddress, offset: u16) -> u8 { | ||
| NullHandler.read_pci_u8(address, offset) | ||
| } | ||
|
|
||
| fn read_pci_u16(&self, address: PciAddress, offset: u16) -> u16 { | ||
| NullHandler.read_pci_u16(address, offset) | ||
| } | ||
|
|
||
| fn read_pci_u32(&self, address: PciAddress, offset: u16) -> u32 { | ||
| NullHandler.read_pci_u32(address, offset) | ||
| } | ||
|
|
||
| fn write_pci_u8(&self, address: PciAddress, offset: u16, value: u8) { | ||
| NullHandler.write_pci_u8(address, offset, value) | ||
| } | ||
|
|
||
| fn write_pci_u16(&self, address: PciAddress, offset: u16, value: u16) { | ||
| NullHandler.write_pci_u16(address, offset, value) | ||
| } | ||
|
|
||
| fn write_pci_u32(&self, address: PciAddress, offset: u16, value: u32) { | ||
| NullHandler.write_pci_u32(address, offset, value) | ||
| } | ||
|
|
||
| fn nanos_since_boot(&self) -> u64 { | ||
| NullHandler.nanos_since_boot() | ||
| } | ||
|
|
||
| fn stall(&self, microseconds: u64) { | ||
| NullHandler.stall(microseconds) | ||
| } | ||
|
|
||
| fn sleep(&self, milliseconds: u64) { | ||
| NullHandler.sleep(milliseconds) | ||
| } | ||
|
|
||
| fn create_mutex(&self) -> Handle { | ||
| NullHandler.create_mutex() | ||
| } | ||
|
|
||
| fn acquire(&self, mutex: Handle, timeout: u16) -> Result<(), AmlError> { | ||
| NullHandler.acquire(mutex, timeout) | ||
| } | ||
|
|
||
| fn release(&self, mutex: Handle) { | ||
| NullHandler.release(mutex) | ||
| } | ||
|
|
||
| fn handle_notify(&self, object: &AmlName, value: u64) { | ||
| self.notifications.lock().unwrap().push((object.clone(), value)); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_notify_delivers_resolved_path() { | ||
| const AML: &str = r#" | ||
| DefinitionBlock ("", "SSDT", 2, "RSACPI", "NOTIFY", 0x00000002) { | ||
| Scope (\_SB) { | ||
| Device (CPUS) { | ||
| Name (_HID, "ACPI0010") | ||
| Device (C001) { | ||
| Name (_HID, "ACPI0007") | ||
| } | ||
| Method (NTFY, 0, NotSerialized) { | ||
| // Relative, resolved against the scope of the running method (\_SB.CPUS) | ||
| Notify (C001, 0x01) | ||
| // Absolute | ||
| Notify (\_SB.CPUS.C001, 0x02) | ||
| // Relative with a parent prefix and a computed value | ||
| Local0 = 0x80 | ||
| Notify (^C001, Local0) | ||
| } | ||
| Method (NTFA, 2, NotSerialized) { | ||
| // The device arrives as an argument | ||
| Notify (Arg0, Arg1) | ||
| } | ||
| Method (NTFR, 0, NotSerialized) { | ||
| // The device is held by a local as a reference | ||
| Local0 = RefOf (C001) | ||
| Notify (Local0, 0x04) | ||
| } | ||
| } | ||
| } | ||
| Method (MAIN, 0, NotSerialized) { | ||
| \_SB.CPUS.NTFY () | ||
| \_SB.CPUS.NTFA (\_SB.CPUS.C001, 0x03) | ||
| \_SB.CPUS.NTFR () | ||
| Return (0) | ||
| } | ||
| } | ||
| "#; | ||
|
|
||
| let handler = NotifyRecorder::default(); | ||
| let notifications = handler.notifications.clone(); | ||
| test_infra::run_aml_test(AML, handler); | ||
|
|
||
| let path = AmlName::from_str("\\_SB_.CPUS.C001").unwrap(); | ||
| let expected: Vec<_> = [0x01, 0x02, 0x80, 0x03, 0x04].into_iter().map(|value| (path.clone(), value)).collect(); | ||
| assert_eq!(*notifications.lock().unwrap(), expected); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please would you add a test of the error path? e.g. Local0 = 1 // Local0 does not refer to a namespace object
Notify(Local0, 2) |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
cargo fmtslightly changes your code inpath_of- please could you runcargo fmt?