Skip to content
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

Wait for VoodooPS2 if present #90

Merged
merged 6 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ Linux:
* VoodooRMI releases (for now) include VoodooSMBus. If you are building VoodooSMBus yourself, build from the Dev branch of the VoodooSMBus git repo.
* [VoodooPS2](https://github.com/acidanthera/VoodooPS2)
* Needed for PS2 reset of the trackpad
* Generally users should only add VoodooPS2Controller and VoodooPS2Keyboard. VoodooPS2Trackpad/VoodooPS2Mouse will cause VoodooRMI to not attach.
* OpenCore users can just disable VoodooPS2Trackpad/VoodooPS2Mouse in their `config.plist`.
* Clover users can go inside the VoodooPS2 kext and remove VoodooPS2Trackpad/VoodooPS2Mouse from PlugIns folder.
* VoodooPS2 2.2.0 or greater needed
* VoodooPS2Trackpad should be left in (unlike in previous versions)

**I2C**
* [VoodooI2C](https://github.com/VoodooI2C/VoodooI2C) 2.5 or newer is required
Expand Down
1 change: 1 addition & 0 deletions VoodooRMI/Transports/RMITransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <IOKit/IOService.h>
#include "../Utility/LinuxCompat.h"
#include "../Utility/Logging.h"
#include "../rmi.h"

#define kIOMessageVoodooSMBusHostNotify iokit_vendor_specific_msg(420)
#define kIOMessageVoodooI2CHostNotify iokit_vendor_specific_msg(421)
Expand Down
72 changes: 61 additions & 11 deletions VoodooRMI/Transports/SMBus/RMISMBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ bool RMISMBus::init(OSDictionary *dictionary)

RMISMBus *RMISMBus::probe(IOService *provider, SInt32 *score)
{
int retval = 0, attempts = 0;
if (!super::probe(provider, score)) {
IOLogError("Failed probe");
return NULL;
Expand All @@ -37,33 +36,83 @@ RMISMBus *RMISMBus::probe(IOService *provider, SInt32 *score)
device_nub->wakeupController();
device_nub->setSlaveDeviceFlags(I2C_CLIENT_HOST_NOTIFY);

return this;
}

bool RMISMBus::start(IOService *provider)
{
auto dict = IOService::nameMatching("ApplePS2SynapticsTouchPad");
if (!dict) {
IOLogError("Unable to create name matching dictionary");
return false;
}


// Do a reset over PS2 if possible
// If ApplePS2Synaptics isn't there, we can *likely* assume that they did not inject VoodooPS2Trackpad
// In which case, resetting isn't important unless it's a broken HP machine
auto ps2 = waitForMatchingService(dict, UInt64 (5) * kSecondScale);

if (ps2) {
// VoodooPS2Trackpad is currently initializing.
// We don't know what state it is in, so wait for registerService()
IOLogInfo("Found PS2 Trackpad driver! Waiting for registerService()");

IONotifier *notifierStatus = addMatchingNotification(gIOMatchedNotification,
dict, 0,
^bool (IOService *newService, IONotifier *notifier) {
if (!newService->getProperty("VoodooInputSupported")) {
IOLogDebug("Too early notification - No VoodooInput on PS2 yet");
return true;
}

IOLogInfo("VoodooPS2Mouse finished init, starting...");
messageClient(kPS2M_SMBusStart, newService);
rmiStart();

notifier->remove();
return rmiStart();
});

IOLogDebug("Notifier installed: %s", notifierStatus ? "true" : "false");

// Retained by addMatchingNotification
OSSafeReleaseNULL(dict);
OSSafeReleaseNULL(ps2);
return true;
}

OSSafeReleaseNULL(dict);

// No VoodooPS2Trackpad, start now
return rmiStart();
}

bool RMISMBus::rmiStart()
{
int retval = 0, attempts = 0;

do {
retval = rmi_smb_get_version();
IOSleep(500);
} while (retval < 0 && attempts++ < 5);

if (retval < 0) {
IOLogError("Error: Failed to read SMBus version. Code: 0x%02X", retval);
return NULL;
return false;
}

if (retval != 2 && retval != 3) {
IOLogError("Unrecognized SMB Version %d", retval);
return NULL;
return false;
}

setProperty("SMBus Version", retval, 32);
IOLogInfo("SMBus version %u", retval);

return this;
}

bool RMISMBus::start(IOService *provider)
{
bool res = super::start(provider);
registerService();
setProperty(RMIBusSupported, kOSBooleanTrue);
return res;
registerService();
return true;
}

void RMISMBus::stop(IOService *provider)
Expand Down Expand Up @@ -132,6 +181,7 @@ int RMISMBus::rmi_smb_get_command_code(u16 rmiaddr, int bytecount,
retval = device_nub->writeBlockData(i + 0x80,
sizeof(new_map), reinterpret_cast<u8*>(&new_map));
if (retval < 0) {
IOLogError("smb_get_command_code: Failed to write mapping table data");
/*
* if not written to device mapping table
* clear the driver mapping table records
Expand Down
3 changes: 2 additions & 1 deletion VoodooRMI/Transports/SMBus/RMISMBus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class RMISMBus : public RMITransport {
IOLock *mapping_table_mutex;

struct mapping_table_entry mapping_table[RMI_SMB2_MAP_SIZE];
u8 table_index;
u8 table_index {0};

bool rmiStart();
int rmi_smb_get_version();
int rmi_smb_get_command_code(u16 rmiaddr, int bytecount,
bool isread, u8 *commandcode);
Expand Down
4 changes: 3 additions & 1 deletion VoodooRMI/rmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ enum {
// from keyboard to mouse/trackpad
kKeyboardSetTouchStatus = iokit_vendor_specific_msg(100), // set disable/enable trackpad (data is bool*)
kKeyboardGetTouchStatus = iokit_vendor_specific_msg(101), // get disable/enable trackpad (data is bool*)
kKeyboardKeyPressTime = iokit_vendor_specific_msg(110) // notify of timestamp a non-modifier key was pressed (data is uint64_t*)
kKeyboardKeyPressTime = iokit_vendor_specific_msg(110), // notify of timestamp a non-modifier key was pressed (data is uint64_t*)
// From SMBus to PS2 Trackpad
kPS2M_SMBusStart = iokit_vendor_specific_msg(152), // Reset, disable PS2 comms to not interfere with SMBus comms
};

// RMI message types
Expand Down