### Call site in handleController Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Example usage of quirksForController in handleController, OR-ing the returned quirks into the entry's quirks field. ```cpp entry.quirks |= NVMe::quirksForController(ctrl->vid, ctrl->mn, ctrl->fr); ``` -------------------------------- ### Use nvme_quirks in driver_data lookup Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Example from nvme_quirks.cpp that ORs driver_data for matching vendor/device entries. Demonstrates the operator|= usage. ```cpp unsigned ret = NVME_QUIRK_NONE; for (const auto& entry : nvme_id_table) if (vendor == entry.vendor && device == entry.device) ret |= entry.driver_data; ``` -------------------------------- ### Enable APST using NVMeFeatures Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Example from nvme_apst.cpp: sets dword11 to 1 and calls NVMeFeatures with NVME_FEAT_AUTO_PST to enable APST. The apstDesc buffer is passed as the data descriptor. ```cpp uint32_t dword11 {1}; ret = NVMeFeatures(entry, NVMe::NVME_FEAT_AUTO_PST, &dword11, apstDesc, nullptr, true); ``` -------------------------------- ### ADDPR(config) registration in NVMeFix.cpp Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/Plugin-Entry-Point.md Defines the plugin configuration using the ADDPR macro. It registers boot arguments -nvmefoff and -nvmefdbg, sets kernel version limits from Mojave to Tahoe, and provides a start callback that initializes the plugin. The values for name and version come from Xcode build settings PRODUCT_NAME and MODULE_VERSION. ```cpp static const char *bootargOff[] { "-nvmefoff" }; static const char *bootargDebug[] { "-nvmefdbg" }; PluginConfiguration ADDPR(config) { xStringify(PRODUCT_NAME), parseModuleVersion(xStringify(MODULE_VERSION)), LiluAPI::AllowNormal | LiluAPI::AllowInstallerRecovery, bootargOff, arrsize(bootargOff), bootargDebug, arrsize(bootargDebug), nullptr, 0, KernelVersion::Mojave, KernelVersion::Tahoe, []() { NVMeFixPlugin::globalPlugin().init(); } }; ``` -------------------------------- ### Query power state using NVMeFeatures Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Example from nvme_pm.cpp: calls NVMeFeatures with NVME_FEAT_POWER_MGMT to get the current power state. On failure logs an error, otherwise masks the result with 0b1111. ```cpp uint32_t res {}; auto ret = plugin.NVMeFeatures(*entry, NVMe::NVME_FEAT_POWER_MGMT, nullptr, nullptr, &res, false); if (ret != kIOReturnSuccess) SYSLOG(Log::PM, "Failed to get power state"); else res &= 0b1111; ``` -------------------------------- ### Reading and masking current power state Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Example implementation pattern for reading the current power state via NVMeFeatures, masking it with 0b1111, and conditionally setting a new power state if not already in the deepest non-operational state. Logs errors on failure. ```cpp uint32_t res {}; auto ret = plugin.NVMeFeatures(*entry, NVMe::NVME_FEAT_POWER_MGMT, nullptr, nullptr, &res, false); res &= 0b1111; if (ret != kIOReturnSuccess) { SYSLOG(Log::PM, "Failed to get power state"); } else if (res < entry->nstates - 1) { unsigned dword11 = ((static_cast(entry->nstates) - 1) - static_cast(powerStateOrdinal)) & 0b1111; ret = plugin.NVMeFeatures(*entry, NVMe::NVME_FEAT_POWER_MGMT, &dword11, nullptr, nullptr, true); } ``` -------------------------------- ### Call site of quirksForController in handleController Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Example usage from NVMeFix.cpp:262. Calls quirksForController to get quirks and then reads ps-max-latency-us from the controller's parent. ```cpp entry.quirks = NVMe::quirksForController(entry.controller); propertyFromParent(entry.controller, "ps-max-latency-us", entry.ps_max_latency_us); ``` -------------------------------- ### Member template declaration (NVMeFixPlugin.hpp:164-218) Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Records a disassembled member offset into an Apple kext object. Provides get to retrieve the member, has to check if the offset is non-zero, and fromFunc to disassemble instructions looking for a specific opcode/modrm pattern. Instances live in NVMeFixPlugin::kextMembers. ```cpp template struct Member { const char* const name {}; // DEBUG only mach_vm_address_t offs {}; T& get(void* obj); bool has(); bool fromFunc(mach_vm_address_t start, uint32_t opcode, uint32_t reg, uint32_t rm, uint32_t add=0, size_t ninsts_max=128); }; ``` -------------------------------- ### Include plugin_start.hpp header Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/Plugin-Entry-Point.md Import path for Lilu's plugin_start.hpp header, which defines the ADDPR macro used for plugin registration. ```cpp #include ``` -------------------------------- ### NVMeFixPlugin::init call from Lilu plugin configuration callback Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Shows how to call init from within the Lilu plugin configuration callback. This is the intended entry point for plugin initialization. ```cpp // Inside the Lilu plugin configuration callback: NVMeFixPlugin::globalPlugin().init(); ``` -------------------------------- ### NVMeFixPlugin file-static singleton instantiation Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Creates the file-static singleton instance of NVMeFixPlugin. The comment notes that the plugin is constructed before Lilu invokes the bootstrap callback. ```cpp #include "NVMeFixPlugin.hpp" // The plugin is constructed before Lilu invokes the bootstrap callback. static NVMeFixPlugin plugin; ``` -------------------------------- ### Startup callback lambda Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/Plugin-Entry-Point.md A lambda that calls NVMeFixPlugin::globalPlugin().init() to perform notification and kext-load registration. It returns void and is invoked by the loader; application code does not call it directly. Disable the plugin with the boot argument -nvmefoff and enable verbose logging in DEBUG builds with -nvmefdbg. ```cpp []() { NVMeFixPlugin::globalPlugin().init(); } ``` -------------------------------- ### NVMeFixPlugin::globalPlugin typical usage Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Shows how to obtain the plugin instance and call NVMeFeatures with the power management feature. This is typical usage as seen in nvme_pm.cpp. ```cpp auto& plugin = NVMeFixPlugin::globalPlugin(); plugin.NVMeFeatures(*entry, NVMe::NVME_FEAT_POWER_MGMT, nullptr, nullptr, &res, false); ``` -------------------------------- ### Include NVMeFixPlugin.hpp Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Import path for the NVMePMProxy class. Required to use the class in your code. ```cpp #include "NVMeFixPlugin.hpp" ``` -------------------------------- ### NVMeFixPlugin::init error-aware implementation Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Shows the internal cleanup pattern used by init. It allocates a lock, registers notifications, and on failure frees resources and removes notifiers. ```cpp void NVMeFixPlugin::init() { LiluAPI::Error err; if (!(lck = IOLockAlloc())) { SYSLOG(Log::Plugin, "Failed to alloc lock"); goto fail; } // ... register notifications ... err = lilu.onKextLoad(&kextInfo, 1, NVMeFixPlugin::processKext, this); if (err != LiluAPI::Error::NoError) { SYSLOG(Log::Plugin, "Failed to register kext load cb"); goto fail; } return; fail: if (lck) IOLockFree(lck); if (matchingNotifier) matchingNotifier->remove(); if (terminationNotifier) terminationNotifier->remove(); } ``` -------------------------------- ### NVMeFixPlugin::init declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Declares the init method, which takes no parameters and returns void. On failure, it logs and cleans up without returning an error. ```cpp void init(); ``` -------------------------------- ### PM::init declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Initializes and enables NVMePMProxy to handle controller power state change events for APST re-enable, or configures active NVMe PM when apst is false. ```cpp bool init(ControllerEntry& entry, const NVMe::nvme_id_ctrl* ctrl, bool apst); ``` -------------------------------- ### Boot arguments for disabling and debug logging Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/Plugin-Entry-Point.md Boot arguments used to control the plugin: -nvmefoff disables the plugin, and -nvmefdbg enables verbose logging in DEBUG builds. ```text -nvmefoff ``` ```text -nvmefdbg ``` -------------------------------- ### PM::solveSymbols declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Routes the virtual method for IONVMeController at fixed vtable offset 249 to PM::activityTickle using KernelPatcher. ```cpp bool solveSymbols(KernelPatcher& kp); ``` -------------------------------- ### Include nvme_quirks.hpp Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Import path for the NVMe quirk subsystem header. Required to use the nvme_quirks enum and its operators. ```cpp #include "nvme_quirks.hpp" ``` -------------------------------- ### Log namespace constants Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/Plugin-Entry-Point.md Declares the string prefixes used for DBGLOG and SYSLOG throughout the kext. Each constant maps to a specific subsystem: Plugin, APST, PM, Quirks, Feature, and Disasm. ```cpp namespace Log { static constexpr auto Plugin {"nvmef"}, APST {"apst"}, PM {"pm"}, Quirks {"quirks"}, Feature {"feature"}, Disasm {"disasm"}; }; ``` -------------------------------- ### Registering power change interest in PM::init Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Registers the proxy as an interested driver for the controller when APST is enabled, allowing it to receive power state change notifications. ```cpp // NVMeFixPlugin::PM::init (nvme_pm.cpp) if (apst) { DBGLOG(Log::PM, "Registering power change interest"); entry.controller->registerInterestedDriver(entry.pm); entry.nstates = 0; entry.powerStates = nullptr; } ``` -------------------------------- ### NVMeFixPlugin::PM struct definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the power management proxy structure. Contains initialization and symbol solving methods, a static idle period constant, and a static activity tickle callback. The constructor stores a reference to the owning plugin. ```cpp struct PM { bool init(ControllerEntry&,const NVMe::nvme_id_ctrl*,bool apst); bool solveSymbols(KernelPatcher&); static constexpr unsigned idlePeriod {2}; /* seconds */ static bool activityTickle(void*,unsigned long,unsigned long); explicit PM(NVMeFixPlugin& plugin) : plugin(plugin) {} private: NVMeFixPlugin& plugin; bool initActivePM(ControllerEntry&, const NVMe::nvme_id_ctrl*); } PM; ``` -------------------------------- ### Include NVMe header Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Protocol.md Import the NVMe namespace header. This is the required include for using the NVMe namespace and its helper functions. ```cpp #include "nvme.h" ``` -------------------------------- ### Enable verbose logging with -nvmefdbg Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/errors.md Sets the boot argument `-nvmefdbg` to enable verbose logging in DEBUG builds. After boot, look for lines emitted by `Log::APST`, such as `APST enabled: max PS = %d, max round-trip latency = %lluus` or `Failed to configure APST with 0x%x`. ```text boot-args = "-nvmefdbg" ``` -------------------------------- ### NVMe::nvme_completion structure definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the completion structure. Not read field-by-field; the plugin reads the result via the disassembled AppleNVMeRequest.result offset as a uint32_t. ```cpp struct nvme_completion { union nvme_result { __le16 u16; __le32 u32; __le64 u64; } result; __le16 sq_head; __le16 sq_id; __u16 command_id; __le16 status; }; ``` -------------------------------- ### NVMeFixPlugin class definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Full class definition from NVMeFix/NVMeFixPlugin.hpp:33-315. Shows public methods (init, deinit, globalPlugin, constructor) and private members including notification handlers, symbol solving, and kext info. ```cpp class NVMeFixPlugin { public: friend class NVMePMProxy; void init(); void deinit(); static NVMeFixPlugin& globalPlugin(); explicit NVMeFixPlugin() : PM(*this) {} private: static void processKext(void*, KernelPatcher&, size_t, mach_vm_address_t, size_t); static bool matchingNotificationHandler(void*, void*, IOService*, IONotifier*); static bool terminatedNotificationHandler(void*, void*, IOService*, IONotifier*); bool solveSymbols(KernelPatcher& kp); atomic_bool solvedSymbols = false; IONotifier* matchingNotifier {nullptr}, * terminationNotifier {nullptr}; /* Used for synchronising concurrent access to this class from notification handlers */ IOLock* lck {nullptr}; const char* kextPath { "/System/Library/Extensions/IONVMeFamily.kext/Contents/MacOS/IONVMeFamily" }; KernelPatcher::KextInfo kextInfo { "com.apple.iokit.IONVMeFamily", &kextPath, 1, {true}, {}, KernelPatcher::KextInfo::Unloaded }; /* ... enumerations, kextFuncs, kextMembers, ControllerEntry, PM ... */ }; ``` -------------------------------- ### NVMeFixPlugin constructor definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Defines the default constructor, which initializes the nested PM sub-object with a reference to this. Used when the plugin is instantiated. ```cpp explicit NVMeFixPlugin() : PM(*this) {} ``` -------------------------------- ### Define integer aliases with USING_TY macro Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the integer type aliases (__le16, __le32, __le64, __u8, __u16, __u32, __u64) and kernel_ulong_t in the linux_types namespace. The USING_TY macro expands to 'using p##sz = uint##sz##_t;', creating type aliases only; no byte-swapping is performed. ```cpp namespace linux_types { USING_TY(__le, 16) USING_TY(__le, 32) USING_TY(__le, 64) USING_TY(__u, 8) USING_TY(__u, 16) USING_TY(__u, 32) USING_TY(__u, 64) using kernel_ulong_t = unsigned long; }; ``` -------------------------------- ### PM class declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Declares the PM nested class with init, solveSymbols, activityTickle, and private initActivePM methods. Includes idlePeriod constant and plugin back-reference. ```cpp struct PM { /** * If `apst`, initialises and enables NVMePMProxy to handle controller power state change * events in order to re-enable APST after reset. * If `!apst`, active NVMe PM is configured. */ bool init(ControllerEntry&,const NVMe::nvme_id_ctrl*,bool apst); bool solveSymbols(KernelPatcher&); static constexpr unsigned idlePeriod {2}; /* seconds */ static bool activityTickle(void*,unsigned long,unsigned long); explicit PM(NVMeFixPlugin& plugin) : plugin(plugin) {} private: NVMeFixPlugin& plugin; bool initActivePM(ControllerEntry&, const NVMe::nvme_id_ctrl*); } PM; ``` -------------------------------- ### Check APST status and quirks via ioreg Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/errors.md Reads the `apst` and `quirks` properties from the IONVMeController entry in the IORegistry. Use after boot to check whether APST configuration failed (`apst` = false) and to see the applied quirk bitmask. ```sh ioreg -r -n IONVMeController -d 1 | grep -E '"apst"|"quirks"' ``` -------------------------------- ### NVMe::quirksForController (IOService* overload) declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Declares the quirksForController function that takes an IOService* controller and returns nvme_quirks. The controller is an IONVMeController and is asserted by propertyFromParent. ```cpp nvme_quirks quirksForController(IOService* controller); ``` -------------------------------- ### PM::activityTickle declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Static method that forwards activity tickle calls to the original IONVMeController::activityTickle, and optionally manages NVMe PM when APST is not enabled. ```cpp static bool activityTickle(void* controller, unsigned long type, unsigned long stateNumber); ``` -------------------------------- ### NVMe::quirksForController(IOService*) Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Determines the quirk flags for a given NVMe controller by reading its vendor and device IDs from the parent IOPCIDevice and matching against the internal quirk table. Returns NVME_QUIRK_NONE if the controller's parent is not an IOPCIDevice or if the IDs cannot be read. ```APIDOC ## NVMe::quirksForController(IOService*) ### Description Determines the quirk flags for a given NVMe controller by reading its vendor and device IDs from the parent IOPCIDevice and matching against the internal quirk table. Returns NVME_QUIRK_NONE if the controller's parent is not an IOPCIDevice or if the IDs cannot be read. ### Method Function ### Signature ```cpp nvme_quirks quirksForController(IOService* controller); ``` ### Parameters - **controller** (`IOService*`) - Required - An `IONVMeController`; asserted by `propertyFromParent`. ### Return Value `NVMe::nvme_quirks` - The OR of all matching PCI-table entries and any vendor-combination bug quirks. Returns `NVME_QUIRK_NONE` on failure. ### Behavior Reads `vendor-id` and `device-id` from the parent IOPCIDevice, matches against the static `nvme_id_table`, then ORs in `check_vendor_combination_bug(vendor, device)`. ### Example ```cpp entry.quirks = NVMe::quirksForController(entry.controller); propertyFromParent(entry.controller, "ps-max-latency-us", entry.ps_max_latency_us); ``` ``` -------------------------------- ### NVMe::nvme_features structure definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the generic features command structure. Reached by NVMeFeatures through kextMembers.AppleNVMeRequest.command.get(req).features. ```cpp struct nvme_features { __u8 opcode; __u8 flags; __u16 command_id; __le32 nsid; __u64 rsvd2[2]; union nvme_data_ptr dptr; __le32 fid; __le32 dword11; __le32 dword12; __le32 dword13; __le32 dword14; __le32 dword15; }; ``` -------------------------------- ### PM::initActivePM declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Private method that configures active NVMe power management by populating powerStates and nstates, registering the power driver, and setting idle timer period. ```cpp bool initActivePM(ControllerEntry& entry, const NVMe::nvme_id_ctrl* ctrl); ``` -------------------------------- ### Func template declaration (NVMeFixPlugin.hpp:78-109) Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Wraps a manually resolved kext symbol. Provides solve to resolve the symbol via KernelPatcher::solveSymbol, route to call solve then routeFunction, routeVirtual to route a virtual function at a vtable offset, and operator() to invoke the resolved function pointer. Instances are aggregated in NVMeFixPlugin::kextFuncs. ```cpp template struct Func { const char* const name; mach_vm_address_t fptr {}; bool solve(KernelPatcher& kp, size_t idx); bool route(KernelPatcher& kp, size_t idx, T(*repl)(Args...)); bool routeVirtual(KernelPatcher& kp, size_t idx, const char* vtFor, size_t offs, T(*repl)(Args...)); T operator()(Args... args) const; }; ``` -------------------------------- ### Check if command is write (nvme_is_write) Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Protocol.md Returns true for write commands. For fabrics commands, checks bit 0 of fabrics.fctype; otherwise checks bit 0 of common.opcode. Note: unlikely is defined to nothing in this build. ```cpp static inline bool nvme_is_write(struct nvme_command *cmd) { if (unlikely(nvme_is_fabrics(cmd))) return cmd->fabrics.fctype & 1; return cmd->common.opcode & 1; } ``` -------------------------------- ### nvme_core_quirk_entry struct and core_quirks array Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Definition of the nvme_core_quirk_entry struct and the static core_quirks array, which matches by vendor ID, model number, and firmware revision to apply quirks. ```cpp struct nvme_core_quirk_entry { linux_types::__u16 vid; const char *mn; const char *fr; unsigned long quirks; }; static const struct nvme_core_quirk_entry core_quirks[] = { { 0x1179, "THNSF5256GPUK TOSHIBA", nullptr, NVME_QUIRK_NO_APST, }, { 0x14a4, nullptr, "22301111", NVME_QUIRK_SIMPLE_SUSPEND, }, { 0x2646, nullptr, "E8FK11", NVME_QUIRK_SIMPLE_SUSPEND, }, { 0x2646, nullptr, "S5Z42105", NVME_QUIRK_NO_DEEPEST_PS, }, }; ``` -------------------------------- ### NVMeFixPlugin::globalPlugin declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Declares the static accessor that returns a reference to the single process-wide plugin instance. It has no parameters and cannot fail. ```cpp static NVMeFixPlugin& globalPlugin(); ``` -------------------------------- ### NVMePMProxy::setPowerState declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Declaration of the setPowerState method, which is overridden from IOService. It takes a power state ordinal and a requesting device, and returns an IOReturn. The implementation always returns kIOPMAckImplied. ```cpp virtual IOReturn setPowerState( unsigned long powerStateOrdinal, IOService * whatDevice ) override; ``` -------------------------------- ### pci_device_id struct and nvme_id_table Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Definition of the pci_device_id struct and the static nvme_id_table array listing PCI vendor/device IDs with their associated NVMe quirks. ```cpp struct pci_device_id { linux_types::__u32 vendor, device; /* kernel_ulong_t */ unsigned long driver_data; }; static constexpr struct pci_device_id nvme_id_table[] = { { 0x8086, 0x0953, NVME_QUIRK_STRIPE_SIZE | NVME_QUIRK_DEALLOCATE_ZEROES, }, { 0x8086, 0x0a53, NVME_QUIRK_STRIPE_SIZE | NVME_QUIRK_DEALLOCATE_ZEROES, }, { 0x8086, 0x0a54, NVME_QUIRK_STRIPE_SIZE | NVME_QUIRK_DEALLOCATE_ZEROES, }, { 0x8086, 0x0a55, NVME_QUIRK_STRIPE_SIZE | NVME_QUIRK_DEALLOCATE_ZEROES, }, { 0x8086, 0xf1a5, NVME_QUIRK_NO_DEEPEST_PS | NVME_QUIRK_MEDIUM_PRIO_SQ, }, { 0x8086, 0xf1a6, NVME_QUIRK_IGNORE_DEV_SUBNQN, }, { 0x8086, 0x5845, NVME_QUIRK_IDENTIFY_CNS | NVME_QUIRK_DISABLE_WRITE_ZEROES, }, { 0x1bb1, 0x0100, NVME_QUIRK_DELAY_BEFORE_CHK_RDY, }, { 0x1c58, 0x0003, NVME_QUIRK_DELAY_BEFORE_CHK_RDY, }, { 0x1c58, 0x0023, NVME_QUIRK_DELAY_BEFORE_CHK_RDY, }, { 0x1c5f, 0x0540, NVME_QUIRK_DELAY_BEFORE_CHK_RDY, }, { 0x144d, 0xa821, NVME_QUIRK_DELAY_BEFORE_CHK_RDY, }, { 0x144d, 0xa822, NVME_QUIRK_DELAY_BEFORE_CHK_RDY, }, { 0x1d1d, 0x1f1f, NVME_QUIRK_LIGHTNVM, }, { 0x1d1d, 0x2807, NVME_QUIRK_LIGHTNVM, }, { 0x1d1d, 0x2601, NVME_QUIRK_LIGHTNVM, }, { 0x10ec, 0x5762, NVME_QUIRK_IGNORE_DEV_SUBNQN, }, { 0x1cc1, 0x8201, NVME_QUIRK_NO_DEEPEST_PS | NVME_QUIRK_IGNORE_DEV_SUBNQN, }, { 0, } }; ``` -------------------------------- ### NVMe::nvme_command union definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines an untagged union of every command layout. nvme_common_command (nvme.h:694-708) is the common header shared by all variants. ```cpp struct nvme_command { union { struct nvme_common_command common; struct nvme_rw_command rw; struct nvme_identify identify; struct nvme_features features; struct nvme_create_cq create_cq; struct nvme_create_sq create_sq; struct nvme_delete_queue delete_queue; struct nvme_download_firmware dlfw; struct nvme_format_cmd format; struct nvme_dsm_cmd dsm; struct nvme_write_zeroes_cmd write_zeroes; struct nvme_abort_cmd abort; struct nvme_get_log_page_command get_log_page; struct nvmf_common_command fabrics; struct nvmf_connect_command connect; struct nvmf_property_set_command prop_set; struct nvmf_property_get_command prop_get; struct nvme_dbbuf dbbuf; struct nvme_directive_cmd directive; }; }; ``` -------------------------------- ### NVMeFeatures method declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMeFixPlugin.md Declares the private NVMeFeatures method. It takes a controller entry, feature ID, dword11 value, optional data buffer, result pointer, and a set flag. Returns IOReturn, kIOReturnSuccess on success. ```cpp IOReturn NVMeFeatures(ControllerEntry& entry, unsigned fid, unsigned* dword11, IOBufferMemoryDescriptor* desc, uint32_t* res, bool set); ``` -------------------------------- ### NVMe::nvme_feat_auto_pst structure definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the APST feature structure with 32 entries, one per power state. Used by configureAPST (write) and dumpAPST (read). ```cpp struct nvme_feat_auto_pst { __le64 entries[32]; }; ``` -------------------------------- ### Check if command is fabrics (nvme_is_fabrics) Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Protocol.md Returns true if the command's common opcode equals nvme_fabrics_command. Used to distinguish fabrics commands from regular NVMe commands. ```cpp static inline bool nvme_is_fabrics(struct nvme_command *cmd) { return cmd->common.opcode == nvme_fabrics_command; } ``` -------------------------------- ### NVMe version helper macros Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Protocol.md Defines macros to encode and decode NVMe version numbers. NVME_VS packs major, minor, and tertiary into a 32-bit value; NVME_MAJOR, NVME_MINOR, and NVME_TERTIARY extract each component. Source: NVMeFix/nvme.h:1413-1418. ```cpp #define NVME_VS(major, minor, tertiary) \ (((major) << 16) | ((minor) << 8) | (tertiary)) #define NVME_MAJOR(ver) ((ver) >> 16) #define NVME_MINOR(ver) (((ver) >> 8) & 0xff) #define NVME_TERTIARY(ver) ((ver) & 0xff) ``` -------------------------------- ### NVMePMProxy class definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md The class definition of NVMePMProxy, an IOService subclass. It overrides setPowerState and powerStateDidChangeTo for power management and APST recovery. The OSDeclareDefaultStructors macro expands to standard IOKit OSMetaClass boilerplate. ```cpp class NVMePMProxy : public IOService { OSDeclareDefaultStructors(NVMePMProxy) public: // NVMe power management virtual IOReturn setPowerState( unsigned long powerStateOrdinal, IOService * whatDevice ) override; // Monitoring IONVMeController power state to re-enable APST virtual IOReturn powerStateDidChangeTo( IOPMPowerFlags capabilities, unsigned long stateNumber, IOService * whatDevice ) override; NVMeFixPlugin::ControllerEntry* entry {nullptr}; }; ``` -------------------------------- ### NVMeFixPlugin::ControllerEntry struct definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the per-controller state structure used by NVMeFix. Allocated per discovered IONVMeController and freed through the deleter. Includes fields for APST configuration, power states, and a per-controller lock. ```cpp struct ControllerEntry { IOService* controller {nullptr}; bool processed {false}; NVMe::nvme_quirks quirks {NVMe::NVME_QUIRK_NONE}; uint64_t ps_max_latency_us {100000}; IOPMPowerState* powerStates {nullptr}; size_t nstates {0}; IOLock* lck {nullptr}; IOService* pm {nullptr}; IOBufferMemoryDescriptor* identify {nullptr}; bool apste {false}; bool apstAllowed(); static void deleter(ControllerEntry* entry); explicit ControllerEntry(IOService* c) : controller(c) { lck = IOLockAlloc(); assert(lck); } }; ``` -------------------------------- ### NVMe::nvme_data_ptr union definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the data pointer union with PRP and SGL variants. ```cpp union nvme_data_ptr { struct { __le64 prp1; __le64 prp2; }; struct nvme_sgl_desc sgl; struct nvme_keyed_sgl_desc ksgl; }; ``` -------------------------------- ### NVMePMProxy::powerStateDidChangeTo method signature Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMePMProxy.md Declares the powerStateDidChangeTo method that is called when a device's power state changes. It returns kIOPMAckImplied and is used to re-enable APST after wake. ```cpp virtual IOReturn powerStateDidChangeTo( IOPMPowerFlags capabilities, unsigned long stateNumber, IOService * whatDevice ) override; ``` -------------------------------- ### NVMe::quirksForController declaration Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Function declaration for quirksForController, which takes a vendor ID, model number, and firmware revision to return the OR of all matching quirks from core_quirks. ```cpp nvme_quirks quirksForController(uint16_t vid, mn_ref_t mn, fr_ref_t fr); ``` -------------------------------- ### NVMe Admin Opcodes Enum (nvme_admin_opcode) Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Protocol.md Defines the standard NVMe admin command opcodes used for queue management, feature access, firmware, security, and other admin commands. Source: NVMeFix/nvme.h:817-841. ```cpp enum nvme_admin_opcode { nvme_admin_delete_sq = 0x00, nvme_admin_create_sq = 0x01, nvme_admin_get_log_page = 0x02, nvme_admin_delete_cq = 0x04, nvme_admin_create_cq = 0x05, nvme_admin_identify = 0x06, nvme_admin_abort_cmd = 0x08, nvme_admin_set_features = 0x09, nvme_admin_get_features = 0x0a, nvme_admin_async_event = 0x0c, nvme_admin_ns_mgmt = 0x0d, nvme_admin_activate_fw = 0x10, nvme_admin_download_fw = 0x11, nvme_admin_ns_attach = 0x15, nvme_admin_keep_alive = 0x18, nvme_admin_directive_send = 0x19, nvme_admin_directive_recv = 0x1a, nvme_admin_dbbuf = 0x7C, nvme_admin_format_nvm = 0x80, nvme_admin_security_send = 0x81, nvme_admin_security_recv = 0x82, nvme_admin_sanitize_nvm = 0x84, nvme_admin_get_lba_status = 0x86, }; ``` -------------------------------- ### NVMe::nvme_id_power_state struct definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the power state descriptor structure used in NVMe power management. Fields include max_power, entry_lat, exit_lat, and flags. Read by configureAPST and PM::initActivePM. ```cpp struct nvme_id_power_state { __le16 max_power; /* centiwatts */ __u8 rsvd2; __u8 flags; __le32 entry_lat; /* microseconds */ __le32 exit_lat; /* microseconds */ __u8 read_tput; __u8 read_lat; __u8 write_tput; __u8 write_lat; __le16 idle_power; __u8 idle_scale; __u8 rsvd19; __le16 active_power; __u8 active_work_scale; __u8 rsvd23[9]; }; ``` -------------------------------- ### Type aliases for NVMe field widths Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Defines reference aliases for the model number and firmware revision fields of nvme_id_ctrl. mn_ref_t is a reference to const char[40] and fr_ref_t is a reference to const char[8]. ```cpp using mn_ref_t = const char(&)[40]; using fr_ref_t = const char(&)[8]; ``` -------------------------------- ### Type Aliases: mn_ref_t and fr_ref_t Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Type aliases for the model number and firmware revision fields of the NVMe identify controller structure, used to enforce field widths. ```APIDOC ## Type Aliases ### Description Type aliases for the model number and firmware revision fields of the NVMe identify controller structure, used to enforce field widths. ### Aliases - **mn_ref_t** - `const char(&)[40]` - Model number field width of `nvme_id_ctrl::mn`. - **fr_ref_t** - `const char(&)[8]` - Firmware revision field width of `nvme_id_ctrl::fr`. ### Source `NVMeFix/nvme_quirks.hpp:138-139`. ``` -------------------------------- ### NVMe Feature Identifiers Enum Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Protocol.md Defines the NVMe feature identifiers and log page identifiers used by the NVMeFix plugin. The plugin uses NVME_FEAT_POWER_MGMT (0x02) and NVME_FEAT_AUTO_PST (0x0c) for power management. This enum is selected from the large anonymous enum at NVMeFix/nvme.h:870-916. ```cpp enum { NVME_FEAT_ARBITRATION = 0x01, NVME_FEAT_POWER_MGMT = 0x02, NVME_FEAT_LBA_RANGE = 0x03, NVME_FEAT_TEMP_THRESH = 0x04, NVME_FEAT_ERR_RECOVERY = 0x05, NVME_FEAT_VOLATILE_WC = 0x06, NVME_FEAT_NUM_QUEUES = 0x07, NVME_FEAT_IRQ_COALESCE = 0x08, NVME_FEAT_IRQ_CONFIG = 0x09, NVME_FEAT_WRITE_ATOMIC = 0x0a, NVME_FEAT_ASYNC_EVENT = 0x0b, NVME_FEAT_AUTO_PST = 0x0c, NVME_FEAT_HOST_MEM_BUF = 0x0d, NVME_FEAT_TIMESTAMP = 0x0e, NVME_FEAT_KATO = 0x0f, NVME_FEAT_HCTM = 0x10, NVME_FEAT_NOPSC = 0x11, NVME_FEAT_RRL = 0x12, NVME_FEAT_PLM_CONFIG = 0x13, NVME_FEAT_PLM_WINDOW = 0x14, NVME_FEAT_HOST_BEHAVIOR = 0x16, NVME_FEAT_SW_PROGRESS = 0x80, NVME_FEAT_HOST_ID = 0x81, NVME_FEAT_RESV_MASK = 0x82, NVME_FEAT_RESV_PERSIST = 0x83, NVME_FEAT_WRITE_PROTECT = 0x84, NVME_LOG_ERROR = 0x01, NVME_LOG_SMART = 0x02, NVME_LOG_FW_SLOT = 0x03, NVME_LOG_CHANGED_NS = 0x04, NVME_LOG_CMD_EFFECTS = 0x05, NVME_LOG_ANA = 0x0c, NVME_LOG_DISC = 0x70, NVME_LOG_RESERVATION = 0x80, NVME_FWACT_REPL = (0 << 3), NVME_FWACT_REPL_ACTV = (1 << 3), NVME_FWACT_ACTV = (2 << 3), }; ``` -------------------------------- ### NVMe Power-State Flags Enum Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Protocol.md Defines flags for NVMe power states. Used by configureAPST and PM::initActivePM to identify non-operational (idle) power states via nvme_id_power_state::flags. Source: NVMeFix/nvme.h:216-219. ```cpp enum { NVME_PS_FLAGS_MAX_POWER_SCALE = 1 << 0, NVME_PS_FLAGS_NON_OP_STATE = 1 << 1, }; ``` -------------------------------- ### Define nvme_quirks enum with bit flags Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Declares the nvme_quirks enum as an unsigned long long with bit flags for each quirk. NVMeFix only acts on NVME_QUIRK_NO_APST and NVME_QUIRK_NO_DEEPEST_PS; the rest are recorded for compatibility. ```cpp enum nvme_quirks : unsigned long long { NVME_QUIRK_NONE = 0, NVME_QUIRK_STRIPE_SIZE = (1 << 0), NVME_QUIRK_IDENTIFY_CNS = (1 << 1), NVME_QUIRK_DEALLOCATE_ZEROES = (1 << 2), NVME_QUIRK_DELAY_BEFORE_CHK_RDY = (1 << 3), NVME_QUIRK_NO_APST = (1 << 4), NVME_QUIRK_NO_DEEPEST_PS = (1 << 5), NVME_QUIRK_LIGHTNVM = (1 << 6), NVME_QUIRK_MEDIUM_PRIO_SQ = (1 << 7), NVME_QUIRK_IGNORE_DEV_SUBNQN = (1 << 8), NVME_QUIRK_DISABLE_WRITE_ZEROES = (1 << 9), NVME_QUIRK_SIMPLE_SUSPEND = (1 << 10), NVME_QUIRK_SINGLE_VECTOR = (1 << 11), NVME_QUIRK_128_BYTES_SQES = (1 << 12), NVME_QUIRK_SHARED_TAGS = (1 << 13), }; ``` -------------------------------- ### nvme_quirks enum definition Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/types.md Defines the bitmask constants for NVMe quirks. The full definition is in NVMeFix/nvme_quirks.hpp:37-109; the excerpt shows the first and last enumerators. Accepted and returned by both NVMe::quirksForController overloads, ControllerEntry::quirks, and the NVME_QUIRK_* table fields. ```cpp enum nvme_quirks : unsigned long long { NVME_QUIRK_NONE = 0, NVME_QUIRK_STRIPE_SIZE = (1 << 0), /* ... */ NVME_QUIRK_SHARED_TAGS = (1 << 13), }; ``` -------------------------------- ### Declare bitwise operator templates for nvme_quirks Source: https://github.com/acidanthera/nvmefix/blob/master/_autodocs/api-reference/NVMe-Quirks.md Declares constexpr template operators to allow bitwise operations on the nvme_quirks enum, which cannot use built-in operators directly. These are defined in nvme_quirks.hpp. ```cpp template constexpr nvme_quirks operator|(T a, T b); template constexpr nvme_quirks operator|=(T& a, T b); template constexpr nvme_quirks operator&(T a, T b); template constexpr nvme_quirks operator&=(T& a, T b); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.