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

Enhance VoodooI2CDeviceNub #468

Merged
merged 6 commits into from
Sep 7, 2021
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// VoodooI2CACPICRSParser.cpp
// VoodooI2CACPIResourcesParser.cpp
// VoodooI2C
//
// Created by CoolStar on 8/15/17.
Expand All @@ -11,37 +11,37 @@
#include <IOKit/IOLib.h>
#include <string.h>

#include "VoodooI2CACPICRSParser.hpp"
#include "VoodooI2CACPIResourcesParser.hpp"
#include "linuxirq.hpp"

VoodooI2CACPICRSParser::VoodooI2CACPICRSParser() {
VoodooI2CACPIResourcesParser::VoodooI2CACPIResourcesParser() {
found_gpio_interrupts = false;
found_i2c = false;
}

void VoodooI2CACPICRSParser::parseACPISerialBus(uint8_t const* crs, uint32_t offset, uint32_t sz) {
void VoodooI2CACPIResourcesParser::parseACPISerialBus(uint8_t const* res, uint32_t offset, uint32_t sz) {
if (found_i2c)
return;
if (offset >= sz)
return;
uint8_t opcode = crs[offset];
uint8_t opcode = res[offset];
if (opcode != 0x8e)
return;

uint16_t len;
memcpy(&len, crs + offset + 1, sizeof(uint16_t));
memcpy(&len, res + offset + 1, sizeof(uint16_t));

uint8_t bustype = crs[offset + 5];
uint8_t bustype = res[offset + 5];
if (bustype != 1)
return; // Only support I2C. Bus type 2 = SPI, 3 = UART

uint8_t flags = crs[offset + 6];
uint8_t flags = res[offset + 6];

uint16_t tflags;
memcpy(&tflags, crs + offset + 7, sizeof(uint16_t));
memcpy(&tflags, res + offset + 7, sizeof(uint16_t));

/*uint16_t datalen;
memcpy(&datalen, crs + offset + 10, sizeof(uint16_t));*/
memcpy(&datalen, res + offset + 10, sizeof(uint16_t));*/

if (bustype == 1) {
found_i2c = true;
Expand All @@ -51,58 +51,58 @@ void VoodooI2CACPICRSParser::parseACPISerialBus(uint8_t const* crs, uint32_t off
i2c_info.address_mode_10Bit = tflags & 0x1;

uint32_t busspeed;
memcpy(&busspeed, crs + offset + 12, sizeof(uint32_t));
memcpy(&busspeed, res + offset + 12, sizeof(uint32_t));
i2c_info.bus_speed = busspeed;

uint16_t address;
memcpy(&address, crs + offset + 16, sizeof(uint16_t));
memcpy(&address, res + offset + 16, sizeof(uint16_t));
i2c_info.address = address;

/*uint8_t i2cLen = len - (12 + datalen - 3);

char *i2cBus = (char *)malloc(i2cLen);
memcpy(i2cBus, crs + offset + 12 + datalen, i2cLen);
memcpy(i2cBus, res + offset + 12 + datalen, i2cLen);
IOLog("I2C Bus: %s\n", i2cBus);*/
}
}

void VoodooI2CACPICRSParser::parseACPIGPIO(uint8_t const* crs, uint32_t offset, uint32_t sz) {
void VoodooI2CACPIResourcesParser::parseACPIGPIO(uint8_t const* res, uint32_t offset, uint32_t sz) {
if (found_gpio_interrupts)
return;
if (offset >= sz)
return;

uint8_t opcode = crs[offset];
uint8_t opcode = res[offset];
if (opcode != 0x8c)
return;

uint16_t len;
memcpy(&len, crs + offset + 1, sizeof(uint16_t));
memcpy(&len, res + offset + 1, sizeof(uint16_t));

uint8_t gpio_type = crs[offset + 4];
uint8_t flags = crs[offset + 5];
uint8_t gpio_type = res[offset + 4];
uint8_t flags = res[offset + 5];

uint8_t gpio_flags = crs[offset + 7];
uint8_t gpio_flags = res[offset + 7];

uint8_t pin_config = crs[offset + 9];
uint8_t pin_config = res[offset + 9];

uint16_t pin_offset;
memcpy(&pin_offset, crs + offset + 14, sizeof(uint16_t));
memcpy(&pin_offset, res + offset + 14, sizeof(uint16_t));

/*uint16_t resourceOffset;
memcpy(&resourceOffset, crs + offset + 17, sizeof(uint16_t));
memcpy(&resourceOffset, res + offset + 17, sizeof(uint16_t));

uint16_t vendorOffset;
memcpy(&vendorOffset, crs + offset + 19, sizeof(uint16_t));*/
memcpy(&vendorOffset, res + offset + 19, sizeof(uint16_t));*/

uint16_t pin_number;
memcpy(&pin_number, crs + offset + pin_offset, sizeof(uint16_t));
memcpy(&pin_number, res + offset + pin_offset, sizeof(uint16_t));

if (pin_number == 0xFFFF) // pinNumber 0xFFFF is invalid
return;

/*char *gpioController = (char *)malloc(vendorOffset - resourceOffset);
memcpy(gpioController, crs + offset + resourceOffset, vendorOffset - resourceOffset);
memcpy(gpioController, res + offset + resourceOffset, vendorOffset - resourceOffset);
IOLog("GPIO Controller: %s\n", gpioController);*/

if (gpio_type == 0) {
Expand Down Expand Up @@ -167,20 +167,20 @@ void VoodooI2CACPICRSParser::parseACPIGPIO(uint8_t const* crs, uint32_t offset,
}
}

void VoodooI2CACPICRSParser::parseACPICRS(uint8_t const* crs, uint32_t offset, uint32_t sz) {
void VoodooI2CACPIResourcesParser::parseACPIResources(uint8_t const* res, uint32_t offset, uint32_t sz) {
if (offset >= sz)
return;

uint8_t opcode = crs[offset];
uint8_t opcode = res[offset];

uint16_t len;
memcpy(&len, crs + offset + 1, sizeof(uint16_t));
memcpy(&len, res + offset + 1, sizeof(uint16_t));

if (opcode == 0x8c)
parseACPIGPIO(crs, offset, sz);
parseACPIGPIO(res, offset, sz);
if (opcode == 0x8e)
parseACPISerialBus(crs, offset, sz);
parseACPISerialBus(res, offset, sz);

offset += (len + 3);
parseACPICRS(crs, offset, sz);
parseACPIResources(res, offset, sz);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// VoodooI2CACPICRSParser.hpp
// VoodooI2CACPIResourcesParser.hpp
// VoodooI2C
//
// Created by CoolStar on 8/15/17.
Expand All @@ -8,8 +8,8 @@

#include <stdint.h>

#ifndef VoodooI2CACPICRSParser_hpp
#define VoodooI2CACPICRSParser_hpp
#ifndef VoodooI2CACPIResourcesParser_hpp
#define VoodooI2CACPIResourcesParser_hpp

struct i2c_info {
bool resource_consumer;
Expand Down Expand Up @@ -44,7 +44,7 @@ struct gpio_io_info {
uint16_t pin_number;
};

class VoodooI2CACPICRSParser {
class VoodooI2CACPIResourcesParser {
public:
bool found_i2c;
bool found_gpio_interrupts;
Expand All @@ -54,11 +54,11 @@ class VoodooI2CACPICRSParser {
gpio_int_info gpio_interrupts;
gpio_io_info gpio_io;

VoodooI2CACPICRSParser();
void parseACPICRS(uint8_t const* crs, uint32_t offset, uint32_t sz);
VoodooI2CACPIResourcesParser();
void parseACPIResources(uint8_t const* res, uint32_t offset, uint32_t sz);
private:
void parseACPISerialBus(uint8_t const* crs, uint32_t offset, uint32_t sz);
void parseACPIGPIO(uint8_t const* crs, uint32_t offset, uint32_t sz);
void parseACPISerialBus(uint8_t const* res, uint32_t offset, uint32_t sz);
void parseACPIGPIO(uint8_t const* res, uint32_t offset, uint32_t sz);
};

#endif /* VoodooI2CACPICRSParser_hpp */
#endif /* VoodooI2CACPIResourcesParser_hpp */
24 changes: 12 additions & 12 deletions VoodooI2C/VoodooI2C.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
AC0955751F4ED4C50052E343 /* helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC0955731F4ED4C50052E343 /* helpers.cpp */; };
AC0955761F4ED4C50052E343 /* helpers.hpp in Headers */ = {isa = PBXBuildFile; fileRef = AC0955741F4ED4C50052E343 /* helpers.hpp */; };
AC09557A1F4ED4F60052E343 /* linuxirq.hpp in Headers */ = {isa = PBXBuildFile; fileRef = AC0955771F4ED4F60052E343 /* linuxirq.hpp */; };
AC09557B1F4ED4F60052E343 /* VoodooI2CACPICRSParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC0955781F4ED4F60052E343 /* VoodooI2CACPICRSParser.cpp */; };
AC09557C1F4ED4F60052E343 /* VoodooI2CACPICRSParser.hpp in Headers */ = {isa = PBXBuildFile; fileRef = AC0955791F4ED4F60052E343 /* VoodooI2CACPICRSParser.hpp */; };
AC09557B1F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC0955781F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.cpp */; };
AC09557C1F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.hpp in Headers */ = {isa = PBXBuildFile; fileRef = AC0955791F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.hpp */; };
AC0AD4581F3842800070A642 /* VoodooI2CDeviceNub.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC0AD4561F3842800070A642 /* VoodooI2CDeviceNub.cpp */; };
AC0AD4591F3842800070A642 /* VoodooI2CDeviceNub.hpp in Headers */ = {isa = PBXBuildFile; fileRef = AC0AD4571F3842800070A642 /* VoodooI2CDeviceNub.hpp */; };
AC0E75761F69997B002268D0 /* VoodooI2CDigitiserTransducer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC0E75741F69997B002268D0 /* VoodooI2CDigitiserTransducer.cpp */; };
Expand Down Expand Up @@ -167,9 +167,9 @@
AC0387541F5422FB00ECEDF9 /* VoodooI2CHID.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = VoodooI2CHID.xcodeproj; path = "../../VoodooI2C Satellites/VoodooI2CHID/VoodooI2CHID.xcodeproj"; sourceTree = "<group>"; };
AC0955731F4ED4C50052E343 /* helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = helpers.cpp; path = ../../Dependencies/helpers.cpp; sourceTree = "<group>"; };
AC0955741F4ED4C50052E343 /* helpers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = helpers.hpp; path = ../../Dependencies/helpers.hpp; sourceTree = "<group>"; };
AC0955771F4ED4F60052E343 /* linuxirq.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = linuxirq.hpp; path = ../../Dependencies/VoodooI2CACPICRSParser/linuxirq.hpp; sourceTree = "<group>"; };
AC0955781F4ED4F60052E343 /* VoodooI2CACPICRSParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VoodooI2CACPICRSParser.cpp; path = ../../Dependencies/VoodooI2CACPICRSParser/VoodooI2CACPICRSParser.cpp; sourceTree = "<group>"; };
AC0955791F4ED4F60052E343 /* VoodooI2CACPICRSParser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = VoodooI2CACPICRSParser.hpp; path = ../../Dependencies/VoodooI2CACPICRSParser/VoodooI2CACPICRSParser.hpp; sourceTree = "<group>"; };
AC0955771F4ED4F60052E343 /* linuxirq.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = linuxirq.hpp; path = ../../Dependencies/VoodooI2CACPIResourcesParser/linuxirq.hpp; sourceTree = "<group>"; };
AC0955781F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VoodooI2CACPIResourcesParser.cpp; path = ../../Dependencies/VoodooI2CACPIResourcesParser/VoodooI2CACPIResourcesParser.cpp; sourceTree = "<group>"; };
AC0955791F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = VoodooI2CACPIResourcesParser.hpp; path = ../../Dependencies/VoodooI2CACPIResourcesParser/VoodooI2CACPIResourcesParser.hpp; sourceTree = "<group>"; };
AC09558A1F4EE10C0052E343 /* VoodooGPIO.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = VoodooGPIO.xcodeproj; path = ../../Dependencies/VoodooGPIO/VoodooGPIO.xcodeproj; sourceTree = "<group>"; };
AC0A265A1F35F7FB00122252 /* VoodooI2CControllerConstants.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = VoodooI2CControllerConstants.hpp; path = VoodooI2CController/VoodooI2CControllerConstants.hpp; sourceTree = "<group>"; };
AC0AD4561F3842800070A642 /* VoodooI2CDeviceNub.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VoodooI2CDeviceNub.cpp; path = VoodooI2CDevice/VoodooI2CDeviceNub.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -284,19 +284,19 @@
AC09558A1F4EE10C0052E343 /* VoodooGPIO.xcodeproj */,
AC0955731F4ED4C50052E343 /* helpers.cpp */,
AC0955741F4ED4C50052E343 /* helpers.hpp */,
AC0955721F4ED4AA0052E343 /* VoodooI2CACPICRSParser */,
AC0955721F4ED4AA0052E343 /* VoodooI2CACPIResourcesParser */,
);
name = Dependencies;
sourceTree = "<group>";
};
AC0955721F4ED4AA0052E343 /* VoodooI2CACPICRSParser */ = {
AC0955721F4ED4AA0052E343 /* VoodooI2CACPIResourcesParser */ = {
isa = PBXGroup;
children = (
AC0955771F4ED4F60052E343 /* linuxirq.hpp */,
AC0955781F4ED4F60052E343 /* VoodooI2CACPICRSParser.cpp */,
AC0955791F4ED4F60052E343 /* VoodooI2CACPICRSParser.hpp */,
AC0955781F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.cpp */,
AC0955791F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.hpp */,
);
name = VoodooI2CACPICRSParser;
name = VoodooI2CACPIResourcesParser;
sourceTree = "<group>";
};
AC09558B1F4EE10C0052E343 /* Products */ = {
Expand Down Expand Up @@ -494,7 +494,7 @@
AC09557A1F4ED4F60052E343 /* linuxirq.hpp in Headers */,
AC6268951F2F6CF1000CBF2D /* VoodooI2CController.hpp in Headers */,
ACF6CF121F7587E5001CAAEE /* VoodooI2CMultitouchEngine.hpp in Headers */,
AC09557C1F4ED4F60052E343 /* VoodooI2CACPICRSParser.hpp in Headers */,
AC09557C1F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.hpp in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -731,7 +731,7 @@
6FE8F89C25290B9600318126 /* VoodooI2CPCILakeController.cpp in Sources */,
ACF810E81F3304720031A6F5 /* VoodooI2CControllerNub.cpp in Sources */,
AC6268941F2F6CF1000CBF2D /* VoodooI2CController.cpp in Sources */,
AC09557B1F4ED4F60052E343 /* VoodooI2CACPICRSParser.cpp in Sources */,
AC09557B1F4ED4F60052E343 /* VoodooI2CACPIResourcesParser.cpp in Sources */,
AC015C471F32345500516383 /* VoodooI2CACPIController.cpp in Sources */,
ACF6E5871F759B5D00A0CD61 /* VoodooI2CCSGestureEngine.cpp in Sources */,
ACF6CF111F7587E5001CAAEE /* VoodooI2CMultitouchEngine.cpp in Sources */,
Expand Down
Loading