acpica_bindings/interface/handler/handler_trait.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
#[cfg(not(all(feature = "builtin_cache", feature = "builtin_lock",)))]
use crate::types::{AcpiAllocationError, AcpiCpuFlags};
use core::ffi::c_void;
use alloc::string::String;
use crate::{
interface::status::AcpiError,
types::{
tables::AcpiTableHeader, AcpiInterruptCallback, AcpiInterruptCallbackTag, AcpiIoAddress,
AcpiMappingError, AcpiPciId, AcpiPhysicalAddress, AcpiPredefinedNames, AcpiThreadCallback,
},
};
/// The interface between ACPICA and the host OS. Each method in this trait is mapped to an `AcpiOs...` function,
/// which will be called on the object registered with [`register_interface`].
///
/// # Optional Methods
///
/// Some methods are only present if certain features of the crate are enabled or disabled:
/// * `create_cache`, `delete_cache`, `purge_cache`, `acquire_object`, and `release_object`
/// are only present if the crate feature `builtin_cache` is disabled
/// * `create_lock`, `delete_lock`, `acquire_lock`, and `release_lock`
/// are only present if the crate feature `builtin_lock` is disabled
/// * `create_semaphore`, `delete_semaphore`, `wait_semaphore`, and `signal_semaphore`
/// are only present if the crate feature `builtin_semaphore` is disabled
///
/// # Safety
/// This trait is unsafe to implement because some functions have restrictions on their
/// implementation as well as their caller. This is indicated per method under the heading "Implementation Safety".
///
/// As well as this, it is undefined behaviour for a panic to unwind across an FFI boundary from rust code to C code.
/// Users of this library who have panic unwinding enabled are responsible for ensuring that a panic never unwinds out of a method in this trait.
/// If the OS is built with `panic=abort`, this is not an issue.
///
/// [`register_interface`]: crate::register_interface
pub unsafe trait AcpiHandler {
/// Method called when ACPICA initialises. The default implementation of this method is a no-op.
///
/// # Safety
/// * This method is only called from `AcpiOsInitialize`
unsafe fn initialize(&mut self) -> Result<(), AcpiError> {
Ok(())
}
/// Method called when ACPICA shuts down. The default implementation of this method is a no-op
///
/// # Safety
/// * This method is only called from `AcpiOsTerminate`
/// * After this method is called, the object will be dropped and no other methods will be called
unsafe fn terminate(&mut self) -> Result<(), AcpiError> {
Ok(())
}
/// Gets a physical pointer to the RSDP.
///
/// # Implementation Safety
/// * The returned pointer must point to the system's RSDP.
fn get_root_pointer(&mut self) -> AcpiPhysicalAddress;
/// Allows the OS to specify an override for a predefined object in the ACPI namespace.
/// The returned string will be converted to a [`CString`], so the FFI handler for this
/// method will panic if it contains null bytes.
///
/// # Safety
/// * This function is only called from `AcpiOsPredefinedOverride`
///
/// [`CString`]: alloc::ffi::CString
#[allow(unused_variables)]
unsafe fn predefined_override(
&mut self,
predefined_object: &AcpiPredefinedNames,
) -> Result<Option<String>, AcpiError> {
Ok(None)
}
/// Allows the OS to override an ACPI table using a logical address.
/// This method is called once on each ACPI table in the order they are listed in the DSDT/XSDT,
/// and when tables are loaded by the `Load` AML instruction. To keep the original table, return `Ok(None)`.
///
/// To override the table using a physical address instead, use [`physical_table_override`]
///
/// # Safety
/// * This method is only called from `AcpiOsTableOverride`
///
/// [`physical_table_override`]: AcpiHandler::physical_table_override
#[allow(unused_variables)]
unsafe fn table_override(
&mut self,
table: &AcpiTableHeader,
) -> Result<Option<AcpiTableHeader>, AcpiError> {
Ok(None)
}
/// Allows the OS to override an ACPI table using a physical address.
/// To keep the original table, return `Ok(None)`
///
/// # Safety
/// * This method is only called from `AcpiOsPhysicalTableOverride`
///
/// # Implementation Safety
/// * The returned physical address must point to a valid new ACPI table with the returned length
/// * The memory indicated by the returned pointer and length is now managed by ACPICA and must
/// not be written to while ACPICA is active
#[allow(unused_variables)]
unsafe fn physical_table_override(
&mut self,
table: &AcpiTableHeader,
) -> Result<Option<(AcpiPhysicalAddress, u32)>, AcpiError> {
Ok(None)
}
/// Map `length` bytes of physical memory starting at `physical_address`, and return the virtual address where they have been mapped.
///
/// # Safety
/// * This function is only called from `AcpiOsMapMemory`
/// * The memory at `physical_address` is valid for writes for `length` bytes
///
/// # Implementation Safety
/// * The memory must stay mapped until `unmap_memory` is called.
unsafe fn map_memory(
&mut self,
physical_address: AcpiPhysicalAddress,
length: usize,
) -> Result<*mut u8, AcpiMappingError>;
/// Unmap `length` pages bytes of memory which were previously allocated with [`map_memory`]
///
/// # Safety
/// * This function is only called from `AcpiOsUnmapMemory`
/// * `address` is a pointer which was previously returned from [`map_memory`]
///
/// [`map_memory`]: AcpiHandler::map_memory
unsafe fn unmap_memory(&mut self, address: *mut u8, length: usize);
/// Translate a logical address to the physical address it's mapped to.
///
/// # Return value
/// * `Ok(Some(address))`: The translation was successful
/// * `Ok(None)`: The translation was successful but the virtual address is not mapped
/// * `Err(e)`: There was an error carrying out the translation
fn get_physical_address(
&mut self,
logical_address: *mut u8,
) -> Result<Option<AcpiPhysicalAddress>, AcpiError>;
/// Read a [`u8`] from the given physical address.
///
/// # Safety
/// * The given physical address is valid for reads
/// * This method is only called from `AcpiOsReadMemory`
///
/// # Implementation Safety
/// * As this read could be from memory mapped IO, the read should be volatile
///
/// If you want your implementation of this method to look the same as [`read_physical_u16`], [`..._u32`], and [`..._u64`],
/// Read the documentation for these methods before implementing this one as the size of the type makes a difference in implementing the method soundly.
///
/// [`read_physical_u16`]: AcpiHandler::read_physical_u16
/// [`..._u32`]: AcpiHandler::read_physical_u32
/// [`..._u64`]: AcpiHandler::read_physical_u64
unsafe fn read_physical_u8(&mut self, address: AcpiPhysicalAddress) -> Result<u8, AcpiError>;
/// Read a [`u16`] from the given physical address.
///
/// # Safety
/// * The given physical address is valid for reads
/// * This method is only called from `AcpiOsReadMemory`
///
/// # Implementation Safety
/// * As this read could be from memory mapped IO, the read should be volatile
/// * The physical address may not be 2 byte aligned, so the read should be unaligned
///
/// These requirements can be difficult to satisfy at the same time.
/// If you are alright with using unstable compiler intrinsics, the [`core::intrinsics::unaligned_volatile_load`] method.
/// Otherwise, it is possible to read the data as a `[u8; 2]` and then transmute it into a [`u16`].
unsafe fn read_physical_u16(&mut self, address: AcpiPhysicalAddress) -> Result<u16, AcpiError>;
/// Read a [`u32`] from the given physical address.
///
/// # Safety
/// * The given physical address is valid for reads
/// * This method is only called from `AcpiOsReadMemory`
///
/// # Implementation Safety
/// * As this read could be from memory mapped IO, the read should be volatile
/// * The physical address may not be 4 byte aligned, so the read should be unaligned
///
/// These requirements can be difficult to satisfy at the same time.
/// If you are alright with using unstable compiler intrinsics, the [`core::intrinsics::unaligned_volatile_load`] method.
/// Otherwise, it is possible to read the data as a `[u8; 4]` and then transmute it into a [`u32`].
unsafe fn read_physical_u32(&mut self, address: AcpiPhysicalAddress) -> Result<u32, AcpiError>;
/// Read a [`u64`] from the given physical address.
///
/// # Safety
/// * The given physical address is valid for reads
/// * This method is only called from `AcpiOsReadMemory`
///
/// # Implementation Safety
/// * As this read could be from memory mapped IO, the read should be volatile
/// * The physical address may not be 8 byte aligned, so the read should be unaligned
///
/// These requirements can be difficult to satisfy at the same time.
/// If you are alright with using unstable compiler intrinsics, the [`core::intrinsics::unaligned_volatile_load`] method.
/// Otherwise, it is possible to read the data as a `[u8; 8]` and then transmute it into a [`u64`].
unsafe fn read_physical_u64(&mut self, address: AcpiPhysicalAddress) -> Result<u64, AcpiError>;
/// Read a [`u8`] from the given physical address.
///
/// # Safety
/// * The given physical address is valid for writes
/// * This method is only called from `AcpiOsWriteMemory`
///
/// # Implementation Safety
/// * As this read could be to memory mapped IO, the write should be volatile
///
/// If you want your implementation of this method to look the same as [`write_physical_u16`], [`..._u32`], and [`..._u64`],
/// Read the documentation for these methods before implementing this one as the size of the type makes a difference in implementing the method soundly.
///
/// [`write_physical_u16`]: AcpiHandler::write_physical_u16
/// [`..._u32`]: AcpiHandler::write_physical_u32
/// [`..._u64`]: AcpiHandler::write_physical_u64
unsafe fn write_physical_u8(
&mut self,
address: AcpiPhysicalAddress,
value: u8,
) -> Result<(), AcpiError>;
/// Read a [`u16`] from the given physical address.
///
/// # Safety
/// * The given physical address is valid for writes
/// * This method is only called from `AcpiOsWriteMemory`
///
/// # Implementation Safety
/// * As this read could be to memory mapped IO, the write should be volatile
/// * The physical address may not be 2 byte aligned, so the read should be unaligned
///
/// These requirements can be difficult to satisfy at the same time.
/// If you are alright with using unstable compiler intrinsics, the [`core::intrinsics::unaligned_volatile_store`] method.
/// Otherwise, it is possible to transmute the data into a `[u8; 2]` before writing it.
unsafe fn write_physical_u16(
&mut self,
address: AcpiPhysicalAddress,
value: u16,
) -> Result<(), AcpiError>;
/// Read a [`u32`] from the given physical address.
///
/// # Safety
/// * The given physical address is valid for writes
/// * This method is only called from `AcpiOsWriteMemory`
///
/// # Implementation Safety
/// * As this read could be to memory mapped IO, the write should be volatile
/// * The physical address may not be 4 byte aligned, so the read should be unaligned
///
/// These requirements can be difficult to satisfy at the same time.
/// If you are alright with using unstable compiler intrinsics, the [`core::intrinsics::unaligned_volatile_store`] method.
/// Otherwise, it is possible to transmute the data into a `[u8; 4]` before writing it.
unsafe fn write_physical_u32(
&mut self,
address: AcpiPhysicalAddress,
value: u32,
) -> Result<(), AcpiError>;
/// Read a [`u64`] from the given physical address.
///
/// # Safety
/// * The given physical address is valid for writes
/// * This method is only called from `AcpiOsWriteMemory`
///
/// # Implementation Safety
/// * As this read could be to memory mapped IO, the write should be volatile
/// * The physical address may not be 8 byte aligned, so the read should be unaligned
///
/// These requirements can be difficult to satisfy at the same time.
/// If you are alright with using unstable compiler intrinsics, the [`core::intrinsics::unaligned_volatile_store`] method.
/// Otherwise, it is possible to transmute the data into a `[u8; 8]` before writing it.
unsafe fn write_physical_u64(
&mut self,
address: AcpiPhysicalAddress,
value: u64,
) -> Result<(), AcpiError>;
/// Check whether `pointer` is valid for reads of `length` bytes.
/// This is only in terms of the memory being mapped with the right permissions and valid, not in terms of rust's ownership rules.
///
/// # Return Value
/// * `true` if the pointer is valid for `length` bytes of reads
/// * `false` if the pointer is not valid
///
/// # Safety
/// * This method is only called from `AcpiOsReadable`
unsafe fn readable(&mut self, pointer: *mut c_void, length: usize) -> bool;
/// Check whether `pointer` is valid for writes of `length` bytes.
/// This is only in terms of the memory being mapped with the right permissions and valid, not in terms of rust's ownership rules.
///
/// # Return Value
/// * `true` if the pointer is valid for `length` bytes of writes
/// * `false` if the pointer is not valid
///
/// # Safety
/// * This method is only called from `AcpiOsWritable`
unsafe fn writable(&mut self, pointer: *mut c_void, length: usize) -> bool;
/// Register the given `callback` to run in the interrupt handler for the given `interrupt_number`
///
/// # Safety
/// * This method is only called from `AcpiOsInstallInterruptHandler`
unsafe fn install_interrupt_handler(
&mut self,
interrupt_number: u32,
callback: AcpiInterruptCallback,
) -> Result<(), AcpiError>;
/// Remove an interrupt handler which was previously registered with [`install_interrupt_handler`].
/// The passed `tag` should be compared to each registered handler using [`is_tag`], and whichever handler returns `true` should be removed.
/// If no handler is found, [`AcpiError::NotExist`] should be returned.
///
/// # Safety
/// * This method is only called from `AcpiOsRemoveInterruptHandler`
///
/// # Implementation Safety
/// * If the handler is found, it must be removed and not called again and [`Ok`] returned.
/// * If the handler is not found, [`AcpiError::NotExist`] must be returned.
///
/// [`install_interrupt_handler`]: AcpiHandler::install_interrupt_handler
/// [`is_tag`]: AcpiInterruptCallback::is_tag
unsafe fn remove_interrupt_handler(
&mut self,
interrupt_number: u32,
tag: AcpiInterruptCallbackTag,
) -> Result<(), AcpiError>;
/// Gets the thread ID of the kernel thread this method is called from.
///
/// # Implementation safety
/// * The returned thread ID must be and must be unique to the executing thread
/// * The thread ID may not be 0 and may not be equal to [`u64::MAX`]
fn get_thread_id(&mut self) -> u64;
/// Run the callback in a new kernel thread. The [`call`] method of the given `callback` must be run, and then the kernel thread should be destroyed.
/// The OS should keep track of which kernel threads were spawned using this method so that [`wait_for_events`] can be implemented correctly.
///
/// # Safety
/// * This method is only called from `AcpiOsExecute`
///
/// # Return value
/// * `Ok(())`: The thread is queued and ready to execute
/// * `Err(e)`: There was an error creating the thread
///
/// [`call`]: AcpiThreadCallback::call
/// [`wait_for_events`]: AcpiHandler::wait_for_events
unsafe fn execute(
&mut self,
// callback_type: AcpiExecuteType,
callback: AcpiThreadCallback,
) -> Result<(), AcpiError>;
/// Waits for all tasks run with [`execute`] to complete before returning.
///
/// # Safety
/// * This method is only called from `AcpiOsWaitEventsComplete`
///
/// # Implementation Safety
/// * This method must not return until all
///
/// [`execute`]: AcpiHandler::execute
unsafe fn wait_for_events(&mut self);
/// Sleep the current kernel thread for the given number of milliseconds
///
/// # Safety
/// * This method is only called from `AcpiOsSleep`
///
/// # Implementation Safety
/// * This method must not return until the given number of milliseconds has elapsed. The OS should attempt not to overshoot the target time by too much.
unsafe fn sleep(&mut self, millis: usize);
/// Loop for the given number of microseconds, without sleeping the kernel thread
///
/// # Safety
/// * This method is only called from `AcpiOsStall`
///
/// # Implementation Safety
/// * This method must not return until the given number of microseconds has elapsed. The OS should attempt not to overshoot the target time by too much.
unsafe fn stall(&mut self, micros: usize);
/// Print a message to the kernel's output.
///
/// Multiple calls to `printf` may be used to print a single line of output, and ACPICA will write a newline character at the end of each line.
/// For this reason, the OS should not add its own newline characters or this could break formatting.
/// If your kernel has a macro which behaves like the standard `print!` macro, the implementation of this method can be as simple as
///
/// ```ignore
/// fn printf(&mut self, message: core::fmt::Arguments) {
/// print!("{message}");
/// }
/// ```
fn printf(&mut self, message: core::fmt::Arguments);
/// Read a [`u8`] from the given port
///
/// # Safety
/// * This method is only called from `AcpiOsReadPort`
unsafe fn read_port_u8(&mut self, address: AcpiIoAddress) -> Result<u8, AcpiError>;
/// Read a [`u16`] from the given port
///
/// # Safety
/// * This method is only called from `AcpiOsReadPort`
unsafe fn read_port_u16(&mut self, address: AcpiIoAddress) -> Result<u16, AcpiError>;
/// Read a [`u32`] from the given port
///
/// # Safety
/// * This method is only called from `AcpiOsReadPort`
unsafe fn read_port_u32(&mut self, address: AcpiIoAddress) -> Result<u32, AcpiError>;
/// Write a [`u8`] to the given port
///
/// # Safety
/// * This method is only called from `AcpiOsWritePort`
unsafe fn write_port_u8(&mut self, address: AcpiIoAddress, value: u8) -> Result<(), AcpiError>;
/// Write a [`u16`] to the given port
///
/// # Safety
/// * This method is only called from `AcpiOsWritePort`
unsafe fn write_port_u16(
&mut self,
address: AcpiIoAddress,
value: u16,
) -> Result<(), AcpiError>;
/// Write a [`u32`] to the given port
///
/// # Safety
/// * This method is only called from `AcpiOsWritePort`
unsafe fn write_port_u32(
&mut self,
address: AcpiIoAddress,
value: u32,
) -> Result<(), AcpiError>;
/// Called just before the system enters a sleep state.
/// This method allows the OS to do any final processing before entering the new state.
/// The default implementation is a no-op.
///
/// # Safety
/// * This method is only called from `AcpiOsEnterSleep`
///
// TODO: Figure out what reg_a and reg_b are and add docs
#[allow(unused_variables)]
unsafe fn enter_sleep(&mut self, state: u8, reg_a: u32, reg_b: u32) -> Result<(), AcpiError> {
Ok(())
}
/// Get the value of the system timer in 100 nanosecond units
///
/// # Safety
/// * This method is only called from `AcpiOsGetTimer`
///
/// # Implementation Safety
/// * The timer must not decrease i.e. later calls to this function must return a greater value
// TODO: There might be more safety conditions
unsafe fn get_timer(&mut self) -> u64;
/// Read a [`u8`] from the configuration space of the given PCI ID and return it.
/// `register` is the offset of the value to read in bytes.
///
/// # Safety
/// * This method is only called from `AcpiOsReadPciConfiguration`
/// * The read is sound i.e. it has no memory-safety related side-effects.
unsafe fn read_pci_config_u8(
&mut self,
id: AcpiPciId,
register: usize,
) -> Result<u8, AcpiError>;
/// Read a [`u16`] from the configuration space of the given PCI ID and return it.
/// `register` is the offset of the value to read in bytes.
///
/// # Safety
/// * This method is only called from `AcpiOsReadPciConfiguration`
/// * The read is sound i.e. it has no memory-safety related side-effects.
unsafe fn read_pci_config_u16(
&mut self,
id: AcpiPciId,
register: usize,
) -> Result<u16, AcpiError>;
/// Read a [`u32`] from the configuration space of the given PCI ID and return it.
/// `register` is the offset of the value to read in bytes.
///
/// # Safety
/// * This method is only called from `AcpiOsReadPciConfiguration`
/// * The read is sound i.e. it has no memory-safety related side-effects.
unsafe fn read_pci_config_u32(
&mut self,
id: AcpiPciId,
register: usize,
) -> Result<u32, AcpiError>;
/// Read a [`u64`] from the configuration space of the given PCI ID and return it.
/// `register` is the offset of the value to read in bytes.
///
/// # Safety
/// * This method is only called from `AcpiOsReadPciConfiguration`
/// * The read is sound i.e. it has no memory-safety related side-effects.
unsafe fn read_pci_config_u64(
&mut self,
id: AcpiPciId,
register: usize,
) -> Result<u64, AcpiError>;
/// Write a [`u8`] to the configuration space of the given PCI ID.
/// `register` is the offset of the value to read in bytes.
///
/// # Safety
/// * This method is only called from `AcpiOsWritePciConfiguration`
/// * The write is sound i.e. it has no memory-safety related side-effects.
unsafe fn write_pci_config_u8(
&mut self,
id: AcpiPciId,
register: usize,
value: u8,
) -> Result<(), AcpiError>;
/// Write a [`u16`] to the configuration space of the given PCI ID.
/// `register` is the offset of the value to read in bytes.
///
/// # Safety
/// * This method is only called from `AcpiOsRWriteciConfiguration`
/// * The write is sound i.e. it has no memory-safety related side-effects.
unsafe fn write_pci_config_u16(
&mut self,
id: AcpiPciId,
register: usize,
value: u16,
) -> Result<(), AcpiError>;
/// Write a [`u32`] to the configuration space of the given PCI ID.
/// `register` is the offset of the value to read in bytes.
///
/// # Safety
/// * This method is only called from `AcpiOsRWriteciConfiguration`
/// * The write is sound i.e. it has no memory-safety related side-effects.
unsafe fn write_pci_config_u32(
&mut self,
id: AcpiPciId,
register: usize,
value: u32,
) -> Result<(), AcpiError>;
/// Write a [`u64`] to the configuration space of the given PCI ID.
/// `register` is the offset of the value to read in bytes.
///
/// # Safety
/// * This method is only called from `AcpiOsRWriteciConfiguration`
/// * The write is sound i.e. it has no memory-safety related side-effects.
unsafe fn write_pci_config_u64(
&mut self,
id: AcpiPciId,
register: usize,
value: u64,
) -> Result<(), AcpiError>;
/// Called when the AML `Fatal` opcode is encountered. The OS can return from this method, or kill the thread executing the AML.
///
/// # Safety
/// * This method is only called from `AcpiOsSignal`
unsafe fn signal_fatal(
&mut self,
fatal_type: u32,
code: u32,
argument: u32,
) -> Result<(), AcpiError>;
/// Called when the AML `Breakpoint` opcode is encountered.
///
/// # Safety
/// * This method is only called from `AcpiOsSignal`
unsafe fn signal_breakpoint(&mut self, message: &str) -> Result<(), AcpiError>;
// TODO: Verify the info in the docs for these cache methods
/// Creates a cache for ACPICA to store objects in to avoid lots of small heap allocations.
///
/// This method is only present in the trait if the `builtin_cache` feature is not set.
/// Otherwise, ACPICA's builtin implementation is used.
///
/// The cache stores up to `max_depth` objects of size `object_size`.
/// The OS is responsible for allocating and de-allocating objects within the cache.
///
/// The OS returns a type-erased pointer which can safely be passed via FFI,
/// but the pointer may point to any type.
///
/// # Safety
/// * This method is only called from `AcpiCreateCache`.
///
/// [`Vec`]: alloc::vec::Vec
/// [`BitVec`]: bitvec::vec::BitVec
#[cfg(not(feature = "builtin_cache"))]
unsafe fn create_cache(
&mut self,
cache_name: &str,
object_size: u16,
max_depth: u16,
) -> Result<*mut c_void, AcpiError>;
/// Deletes a cache which was previously created by [`create_cache`].
///
/// This method is only present in the trait if the `builtin_cache` feature is not set.
///
/// The OS is responsible for deallocating the backing memory of the cache.
///
/// # Safety
/// * This method is only called from `AcpiDeleteCache`
/// * `cache` is a pointer which was previously returned from [`create_cache`]
/// * After this method is called, other cache methods will not be called for this cache
///
/// [`create_cache`]: AcpiHandler::create_cache
#[cfg(not(feature = "builtin_cache"))]
unsafe fn delete_cache(&mut self, cache: *mut c_void) -> Result<(), AcpiAllocationError>;
/// Removes all items from a cache.
///
/// This method is only present in the trait if the `builtin_cache` feature is not set
///
/// This method should mark all slots in the cache as empty, but not deallocate the backing memory
///
/// # Safety
/// * This method is only called from `AcpiPurgeCache`
/// * `cache` is a pointer which was previously returned from [`create_cache`]
///
/// [`create_cache`]: AcpiHandler::create_cache
#[cfg(not(feature = "builtin_cache"))]
unsafe fn purge_cache(&mut self, cache: *mut c_void);
/// Allocates an object inside a cache.
///
/// This method is only present in the trait if the `builtin_cache` feature is not set.
///
/// This method should return a pointer to a free slot in the cache, or `None` if all slots are full.
///
/// # Safety
/// * This method is only called from `AcpiPurgeCache`.
/// * `cache` is a pointer which was previously returned from [`create_cache`].
///
/// # Implementation safety
/// * The returned pointer must be free for writes for the object size passed to [`create_cache`]
/// - i.e. it must not be being used by rust code, and it must not have been returned from this method before,
/// unless it has been explicitly freed using [`release_object`] or [`purge_cache`].
///
/// [`create_cache`]: AcpiHandler::create_cache
/// [`release_object`]: AcpiHandler::release_object
/// [`purge_cache`]: AcpiHandler::purge_cache
#[cfg(not(feature = "builtin_cache"))]
unsafe fn acquire_object(&mut self, cache: *mut c_void) -> Option<*mut u8>;
/// Marks an object as free in a cache.
///
/// This method is only present in the trait if the `builtin_cache` feature is not set.
///
/// This method should mark the given object within the cache as free - i.e. allow it to be allocated again by [`acquire_object`].
///
/// # Safety
/// * This method is only called from `AcpiReleaseObject`.
/// * `cache` is a pointer which was previously returned from [`create_cache`].
/// * `object` is a pointer which was previously returned from [`acquire_object`].
///
/// [`acquire_object`]: AcpiHandler::acquire_object
/// [`create_cache`]: AcpiHandler::create_cache
#[cfg(not(feature = "builtin_cache"))]
unsafe fn release_object(&mut self, cache: *mut c_void, object: *mut u8);
#[allow(missing_docs)] // TODO: docs
#[cfg(not(feature = "builtin_lock"))]
unsafe fn create_lock(&mut self) -> Result<*mut c_void, AcpiError>;
#[allow(missing_docs)] // TODO: docs
#[cfg(not(feature = "builtin_lock"))]
unsafe fn delete_lock(&mut self, lock: *mut c_void);
#[allow(missing_docs)] // TODO: docs
#[cfg(not(feature = "builtin_lock"))]
unsafe fn acquire_lock(&mut self, handle: *mut c_void) -> AcpiCpuFlags;
#[allow(missing_docs)] // TODO: docs
#[cfg(not(feature = "builtin_lock"))]
unsafe fn release_lock(&mut self, handle: *mut c_void, flags: AcpiCpuFlags);
#[allow(missing_docs)] // TODO: docs
#[cfg(not(feature = "builtin_semaphore"))]
unsafe fn create_semaphore(
&mut self,
max_units: u32,
initial_units: u32,
) -> Result<*mut c_void, AcpiError>;
#[allow(missing_docs)] // TODO: docs
#[cfg(not(feature = "builtin_semaphore"))]
unsafe fn delete_semaphore(&mut self, handle: *mut c_void) -> Result<(), AcpiError>;
#[allow(missing_docs)] // TODO: docs
#[cfg(not(feature = "builtin_semaphore"))]
unsafe fn wait_semaphore(
&mut self,
handle: *mut c_void,
units: u32,
timeout: u16,
) -> Result<(), AcpiError>;
#[allow(missing_docs)] // TODO: docs
#[cfg(not(feature = "builtin_semaphore"))]
unsafe fn signal_semaphore(&mut self, handle: *mut c_void, units: u32)
-> Result<(), AcpiError>;
}