Skip to content

Commit

Permalink
Added new DeviceInfo API
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Jul 5, 2018
1 parent b5a0e77 commit 5206bd4
Show file tree
Hide file tree
Showing 7 changed files with 543 additions and 103 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
@@ -1,6 +1,10 @@
Lilu Changelog
==============

#### v1.2.5
- Added new DeviceInfo API
- Removed GPU detection code from CPUInfo API

#### v1.2.4
- Internalize new APIs from 1.2.3
- Added new EFI runtime API with custom variable extensions
Expand Down
10 changes: 8 additions & 2 deletions Lilu.xcodeproj/project.pbxproj
Expand Up @@ -83,6 +83,7 @@
CE75B9571EFB619C00D29B40 /* _label.h in Headers */ = {isa = PBXBuildFile; fileRef = CE75B9541EFB619C00D29B40 /* _label.h */; };
CE75B9581EFB619C00D29B40 /* mac_framework.h in Headers */ = {isa = PBXBuildFile; fileRef = CE75B9551EFB619C00D29B40 /* mac_framework.h */; };
CE75B9591EFB619C00D29B40 /* mac_policy.h in Headers */ = {isa = PBXBuildFile; fileRef = CE75B9561EFB619C00D29B40 /* mac_policy.h */; };
CEA03B5B20ED6D3100BA842F /* kern_devinfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEA03B5A20ED6D3100BA842F /* kern_devinfo.cpp */; };
CEA5F5D720B88EF2008E6E8A /* qsort.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEA5F5D520B88EF2008E6E8A /* qsort.cpp */; };
CEB6D9711F69A966005B6AC3 /* kern_crypto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CEB6D9701F69A966005B6AC3 /* kern_crypto.cpp */; };
CEB6D9831F69B42D005B6AC3 /* cc.h in Headers */ = {isa = PBXBuildFile; fileRef = CEB6D9781F69B42D005B6AC3 /* cc.h */; };
Expand Down Expand Up @@ -202,6 +203,8 @@
CE75B9541EFB619C00D29B40 /* _label.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _label.h; sourceTree = "<group>"; };
CE75B9551EFB619C00D29B40 /* mac_framework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mac_framework.h; sourceTree = "<group>"; };
CE75B9561EFB619C00D29B40 /* mac_policy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mac_policy.h; sourceTree = "<group>"; };
CEA03B5920ED6D0200BA842F /* kern_devinfo.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_devinfo.hpp; sourceTree = "<group>"; };
CEA03B5A20ED6D3100BA842F /* kern_devinfo.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = kern_devinfo.cpp; path = Lilu/Sources/kern_devinfo.cpp; sourceTree = "<group>"; };
CEA5F5D520B88EF2008E6E8A /* qsort.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = qsort.cpp; sourceTree = "<group>"; };
CEB6D9701F69A966005B6AC3 /* kern_crypto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = kern_crypto.cpp; path = Lilu/Sources/kern_crypto.cpp; sourceTree = "<group>"; };
CEB6D9721F69A98B005B6AC3 /* kern_crypto.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = kern_crypto.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -362,6 +365,7 @@
CE2E7B881E2C6A73009AC62A /* kern_disasm.hpp */,
CEC0C5F0208F99D8000BFE88 /* kern_efi.hpp */,
CE2E7B891E2C6A73009AC62A /* kern_file.hpp */,
CEA03B5920ED6D0200BA842F /* kern_devinfo.hpp */,
CE2E7B8A1E2C6A73009AC62A /* kern_iokit.hpp */,
CE2E7B8B1E2C6A73009AC62A /* kern_mach.hpp */,
CEB6D9941F69D8CF005B6AC3 /* kern_nvram.hpp */,
Expand All @@ -388,6 +392,7 @@
CEC0C5F1208F9A14000BFE88 /* kern_efi_trampoline.S */,
CE2E7BA61E2C6BAA009AC62A /* kern_file.cpp */,
CE2E7BA71E2C6BAA009AC62A /* kern_iokit.cpp */,
CEA03B5A20ED6D3100BA842F /* kern_devinfo.cpp */,
CE2E7BA81E2C6BAA009AC62A /* kern_mach.cpp */,
CEB6D9921F69D8B9005B6AC3 /* kern_nvram.cpp */,
CE2E7BA91E2C6BAA009AC62A /* kern_patcher.cpp */,
Expand Down Expand Up @@ -708,6 +713,7 @@
CE2E7BB01E2C6BAA009AC62A /* kern_disasm.cpp in Sources */,
CEC0C5EF208F99A6000BFE88 /* kern_efi.cpp in Sources */,
CE2E7BEB1E2C75CE009AC62A /* kern_api.cpp in Sources */,
CEA03B5B20ED6D3100BA842F /* kern_devinfo.cpp in Sources */,
1C3E7AE01C84B61700A6448A /* MCInst.c in Sources */,
1C3E7B161C84B65400A6448A /* X86Module.c in Sources */,
1C3E7AE41C84B61700A6448A /* MCRegisterInfo.c in Sources */,
Expand Down Expand Up @@ -864,7 +870,7 @@
MODULE_NAME = as.vit9696.Lilu;
MODULE_START = kern_start;
MODULE_STOP = kern_stop;
MODULE_VERSION = 1.2.4;
MODULE_VERSION = 1.2.5;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down Expand Up @@ -927,7 +933,7 @@
MODULE_NAME = as.vit9696.Lilu;
MODULE_START = kern_start;
MODULE_STOP = kern_stop;
MODULE_VERSION = 1.2.4;
MODULE_VERSION = 1.2.5;
OTHER_CFLAGS = (
"-mmmx",
"-msse",
Expand Down
30 changes: 3 additions & 27 deletions Lilu/Headers/kern_cpu.hpp
Expand Up @@ -104,45 +104,21 @@ namespace CPUInfo {
*/
EXPORT CpuGeneration getGeneration(uint32_t *ofamily=nullptr, uint32_t *omodel=nullptr);

/**
* Known platform ids used by Intel GPU kexts
*/
static constexpr uint32_t DefaultInvalidPlatformId {0xFFFFFFFF};
static constexpr uint32_t DefaultSkylakePlatformId {0x19120000};
static constexpr uint32_t DefaultKabyLakePlatformId {0x59160000};

/**
* Framebuffers without any ports used for hardware acceleration only
* Note: Broadwell framebuffers all have connectors added.
*/
static constexpr uint32_t ConnectorLessSandyBridgePlatformId1 {0x00030030};
static constexpr uint32_t ConnectorLessSandyBridgePlatformId2 {0x00050000};
static constexpr uint32_t ConnectorLessIvyBridgePlatformId1 {0x01620006};
static constexpr uint32_t ConnectorLessIvyBridgePlatformId2 {0x01620007};
static constexpr uint32_t ConnectorLessHaswellPlatformId1 {0x04120004};
static constexpr uint32_t ConnectorLessHaswellPlatformId2 {0x0412000B};
static constexpr uint32_t ConnectorLessSkylakePlatformId1 {0x19020001};
static constexpr uint32_t ConnectorLessSkylakePlatformId2 {0x19170001};
static constexpr uint32_t ConnectorLessSkylakePlatformId3 {0x19120001};
static constexpr uint32_t ConnectorLessSkylakePlatformId4 {0x19320001};
static constexpr uint32_t ConnectorLessKabyLakePlatformId1 {0x59180002};
static constexpr uint32_t ConnectorLessKabyLakePlatformId2 {0x59120003};

/**
* Check whether IGPU platform id contains any connectors
*
* @param id IGPU platform id
*
* @return true if the specified platform id has no connectors
*/
EXPORT bool isConnectorLessPlatformId(uint32_t id);
EXPORT bool isConnectorLessPlatformId(uint32_t id) DEPRECATE("Use DeviceInfo::reportedFramebufferIsConnectorLess");

/**
* Return Sandy Bridge default platform id.
*
* @return valid platform id or DefaultInvalidPlatformId
*/
EXPORT uint32_t getSandyGpuPlatformId();
EXPORT uint32_t getSandyGpuPlatformId() DEPRECATE("Use DeviceInfo::reportedFramebufferId");

/**
* Return running IGPU platform id.
Expand All @@ -152,7 +128,7 @@ namespace CPUInfo {
*
* @return valid platform id or DefaultInvalidPlatformId
*/
EXPORT uint32_t getGpuPlatformId(IORegistryEntry *sect=nullptr, bool *specified=nullptr);
EXPORT uint32_t getGpuPlatformId(IORegistryEntry *sect=nullptr, bool *specified=nullptr) DEPRECATE("Use DeviceInfo::reportedFramebufferId");
}

#endif /* kern_cpu_h */
232 changes: 232 additions & 0 deletions Lilu/Headers/kern_devinfo.hpp
@@ -0,0 +1,232 @@
//
// kern_devinfo.hpp
// Lilu
//
// Copyright © 2018 vit9696. All rights reserved.
//

#ifndef kern_devinfo_h
#define kern_devinfo_h

#include <Headers/kern_config.hpp>
#include <Headers/kern_util.hpp>
#include <Library/LegacyIOService.h>

/**
* Obtain installed devices split into categories.
* Should be used from onPatcherLoad and onwards.
*/
class DeviceInfo {
/**
* Updates reportedLayoutId
*/
void updateLayoutId();

/**
* Updates reportedFramebufferId
*/
void updateFramebufferId();

/**
* Updates firmwareVendor
*/
void updateFirmwareVendor();

public:
/**
* Obtains autodetected legacy framebuffer if applicable
*
* @return framebuffer or 0xFFFFFFFF
*/
static uint32_t getLegacyFramebufferId();

/**
* Checks whether the framebuffer has connectors or not.
*
* @return true if the framebuffer has no connectors
*/
static bool isConnectorLessPlatformId(uint32_t id);

/**
* Common external GPU parameter list
*/
struct ExternalVideo {
/**
* Aka GFX0 device
*/
IORegistryEntry *video {nullptr};

/**
* Aka HDAU device
*/
IORegistryEntry *audio {nullptr};

/**
* External GPU vendor
*/
uint32_t vendor {0};
};

/**
* Aka HDEF device
*/
IORegistryEntry *audioBuiltinAnalog {nullptr};

/**
* Aka HDAU device for builtin GPU
*/
IORegistryEntry *audioBuiltinDigital {nullptr};

/**
* Aka IGPU device
*/
IORegistryEntry *videoBuiltin {nullptr};

/**
* Aka IMEI device
*/
IORegistryEntry *managementEngine {nullptr};

/**
* Aka GFX0 devices (kept in sync with audioExternal)
*/
evector<ExternalVideo> videoExternal;

private:
/**
* This is the default reported layout-id passed to reportedLayoutId.
* The reason for choosing 7 is its presence in 10.14 and the fact
* Apple frameworks still communicate to the files present on disk.
* For information purposes only! Use reportedLayoutId!
*/
static constexpr uint32_t DefaultReportedLayoutId = 7;

/**
* The boot-arg to override the reported layout-id to AppleHDA.
* For user configuration only! Use reportedLayoutId!
*/
static constexpr const char *ReportedLayoutIdArg = "alcapplid";

/**
* The property to override the reported layout-id to AppleHDA.
* For user configuration only! Use reportedLayoutId!
*/
static constexpr const char *ReportedLayoutIdName = "apple-layout-id";

public:
/**
* Layout id to be reported by all audio devices (you must update it yourself).
* This follows the standard convention initially found in AppleALC:
* alcapplid=X boot-arg has highest priority and overrides any other value.
* apple-layout-id HDEF prop has normal priority, you may use it if you need.
* DefaultReportedLayoutId will be used if both of the above are not set.
*/
uint32_t reportedLayoutId {0};

private:
/**
* The boot-arg to override the reported AAPL,ig-platform-id to Intel drivers.
* For user configuration only! Use reportedFramebufferId!
*/
static constexpr const char *ReportedFrameIdArg = "igfxframe";

/**
* The property to set your platform id for Intel drivers (Ivy and newer).
* For user configuration only! Use reportedFramebufferName!
*/
static constexpr const char *ReportedFrameIdName = "AAPL,ig-platform-id";

/**
* The property to set your platform id for Intel drivers (Sandy).
* For user configuration only! Use reportedFramebufferName!
*/
static constexpr const char *ReportedFrameIdLegacyName = "AAPL,snb-platform-id";

/**
* Known platform ids used by Intel GPU kexts
* For user configuration only!
*/
static constexpr uint32_t DefaultSkylakePlatformId {0x19120000};
static constexpr uint32_t DefaultKabyLakePlatformId {0x59160000};

/**
* Framebuffers without any ports used for hardware acceleration only
* Note: Broadwell framebuffers all have connectors added.
* For user configuration only!
*/
static constexpr uint32_t ConnectorLessSandyBridgePlatformId1 {0x00030030};
static constexpr uint32_t ConnectorLessSandyBridgePlatformId2 {0x00050000};
static constexpr uint32_t ConnectorLessIvyBridgePlatformId1 {0x01620006};
static constexpr uint32_t ConnectorLessIvyBridgePlatformId2 {0x01620007};
static constexpr uint32_t ConnectorLessHaswellPlatformId1 {0x04120004};
static constexpr uint32_t ConnectorLessHaswellPlatformId2 {0x0412000B};
static constexpr uint32_t ConnectorLessSkylakePlatformId1 {0x19020001};
static constexpr uint32_t ConnectorLessSkylakePlatformId2 {0x19170001};
static constexpr uint32_t ConnectorLessSkylakePlatformId3 {0x19120001};
static constexpr uint32_t ConnectorLessSkylakePlatformId4 {0x19320001};
static constexpr uint32_t ConnectorLessKabyLakePlatformId1 {0x59180002};
static constexpr uint32_t ConnectorLessKabyLakePlatformId2 {0x59120003};

public:
/**
* Invalid framebuffer identifier
*/
static constexpr uint32_t DefaultInvalidPlatformId {0xFFFFFFFF};

/**
* Framebuffer id to be reported to IGPU.
* This follows the standard convention initially found in IntelGraphicsFixup:
* igfxframe=X boot-arg has highest priority and overrides any other value.
* Manually specified AAPL,ig-platform-id or AAPL,snb-platform-id go next.
* On Sandy Bridge processors a default AAPL,snb-platform-id will be tried afterwards.
* On Skylake and Kaby Lake processors some default id will be tried afterwards.
*/
uint32_t reportedFramebufferId {0};

/**
* Compatible platform id property name for this IGPU
*/
const char *reportedFramebufferName {nullptr};

/**
* Set to true if the framebuffer has no connectors
*/
bool reportedFramebufferIsConnectorLess {false};

/**
* Known variants of firmware vendors
* Please note, that it may not be possible to always detect the right vendor
*/
enum class FirmwareVendor {
Unknown,
Apple,
VMware,
EDKII,
Parallels,
AMI,
Insyde,
Phoenix,
HP
};

/**
* Firmware vendor manufacturer
*/
FirmwareVendor firmwareVendor {FirmwareVendor::Unknown};

/**
* Allocate and initialise the device list.
*
* @return device list or nullptr
*/
EXPORT static DeviceInfo *create();

/**
* Release initialised device list.
*
* @param d device list
*/
EXPORT static void deleter(DeviceInfo *d);
};

#endif /* kern_devinfo_h */
5 changes: 5 additions & 0 deletions Lilu/Headers/kern_util.hpp
Expand Up @@ -178,6 +178,11 @@ extern proc_t kernproc;

#endif

/**
* Deprecate the interface
*/
#define DEPRECATE(x) __attribute__((deprecated(x)))

/**
* Macros to bypass kernel address printing protection
*/
Expand Down

0 comments on commit 5206bd4

Please sign in to comment.