Skip to content
This repository has been archived by the owner on Jun 24, 2023. It is now read-only.

Commit

Permalink
Finalizes basic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
aluveitie committed Oct 3, 2021
1 parent 1bd37b3 commit 90b9af4
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build
.DS_Store

*.kext
RadeonSensor.xcodeproj/xcuserdata/**
8 changes: 4 additions & 4 deletions RadeonGadget/RadeonGadget.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.app-sandbox</key>
<false/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
3 changes: 1 addition & 2 deletions RadeonGadget/RadeonModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class RadeonModel {
}

let status = IOServiceOpen(serviceObject, mach_task_self_, 0, &connect)
print(status)

return status == KERN_SUCCESS
}
Expand Down Expand Up @@ -68,6 +67,6 @@ class RadeonModel {
return 0
}

return Int(scalerOut)
return Int(outputStr[0])
}
}
16 changes: 1 addition & 15 deletions RadeonGadget/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ class StatusBarController {
statusItem.button?.wantsLayer = true
statusItem.button?.addSubview(view)

//statusItem.button?.target = self
//statusItem.button?.action = #selector(itemClicked)
//statusItem.button?.sendAction(on: [.leftMouseUp, .rightMouseUp])

statusItem.length = 100
statusItem.length = 105
view.frame = statusItem.button!.bounds

updateTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { _ in
Expand All @@ -113,14 +109,4 @@ class StatusBarController {
NSStatusBar.system.removeStatusItem(statusItem!)
statusItem = nil
}

// @objc func toggleWindow(sender: AnyObject) {
// let mainWindow = NSApplication.shared.windows.first!
// if (mainWindow.isVisible) {
// mainWindow.close()
// } else {
// mainWindow.makeKeyAndOrderFront(nil)
// NSApplication.shared.activate(ignoringOtherApps: true)
// }
// }
}
74 changes: 69 additions & 5 deletions RadeonSensor/RadeonSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ bool RadeonSensor::init(OSDictionary *dictionary){

IOLog("%s[%p]::%s(%p)\n", getName(), this, __FUNCTION__, dictionary);

//atiCard = new ATICard();

return true;
}

Expand All @@ -32,6 +30,65 @@ void RadeonSensor::free() {
super::free();
}

IOService* RadeonSensor::probe(IOService* provider, SInt32* score) {
if (super::probe(provider, score) != this) {
return 0;
}

bool ret = false;
if (OSDictionary * dictionary = serviceMatching("IOPCIDevice")) {
if (OSIterator * iterator = getMatchingServices(dictionary)) {
IOPCIDevice* device = NULL;
UInt32 vendor_id = 0;
UInt32 class_id = 0;
do {
device = OSDynamicCast(IOPCIDevice, iterator->getNextObject());
if (!device) {
break;
}
vendor_id = 0;
OSData *data = OSDynamicCast(OSData, device->getProperty("vendor-id"));
if (data) {
vendor_id = *(UInt32*)data->getBytesNoCopy();
} else {
data = OSDynamicCast(OSData, device->getProperty("ATY,VendorID"));
if (data) {
vendor_id = *(UInt32*)data->getBytesNoCopy();
}
}

device_id = 0;
data = OSDynamicCast(OSData, device->getProperty("device-id"));
if (data) {
device_id = *(UInt32*)data->getBytesNoCopy();
}

class_id = 0;
data = OSDynamicCast(OSData, device->getProperty("class-code"));
if (data) {
class_id = *(UInt32*)data->getBytesNoCopy();
}

if ((vendor_id==0x1002) && (class_id == 0x030000)) {
InfoLog("found Radeon chip id=%x ", (unsigned int)device_id);
pciCard = device;
ret = true; //TODO - count a number of cards
break;
}
/*else {
WarningLog("ATI Radeon not found!");
}*/
} while (device);
}
}

if (ret) {
return this;
} else {
return 0;
}
}

bool RadeonSensor::start(IOService *provider) {
IOLog("%s[%p]::%s(%p)\n", getName(), this, __FUNCTION__, provider);

Expand All @@ -42,10 +99,17 @@ bool RadeonSensor::start(IOService *provider) {

registerService();

//atiCard->initialize();
IOLog("Found Radeon: %us", atiCard->chipID);
atiCard = new ATICard();
atiCard->VCard = pciCard;
atiCard->chipID = device_id;

return true;
if (atiCard->initialize()) {
IOLog("%s[%p]::initialized card %us", getName(), this, atiCard->chipID);
return true;
} else {
IOLog ("[Warning] %s[%p]::could not initialize card", getName(), this);
return false;
}
}

void RadeonSensor::stop(IOService *provider) {
Expand Down
5 changes: 4 additions & 1 deletion RadeonSensor/RadeonSensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RadeonSensor : public IOService {

public:
virtual bool init(OSDictionary* dictionary) override;
virtual IOService* probe(IOService* provider, SInt32* score) override;
virtual void free(void) override;

virtual bool start(IOService* provider) override;
Expand All @@ -38,7 +39,9 @@ class RadeonSensor : public IOService {


private:
ATICard *atiCard;
UInt32 device_id = 0;
ATICard* atiCard;
IOPCIDevice* pciCard;
};

#endif /* RadeonSensor_hpp */
2 changes: 1 addition & 1 deletion RadeonSensor/RadeonSensorUserClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RadeonSensorUserClient : public IOUserClient {
task_t mTask;

public:
bool initWithTask(task_t owningTask, void *securityToken, UInt32 type, OSDictionary *properties) override;
virtual bool initWithTask(task_t owningTask, void *securityToken, UInt32 type, OSDictionary *properties) override;

// IOUserClient methods
virtual void stop(IOService* provider) override;
Expand Down

0 comments on commit 90b9af4

Please sign in to comment.