Skip to content

Commit

Permalink
Add PCI BDF property for dscpi sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
phpdev32 committed Jan 9, 2014
1 parent 7a5612f commit 39af22d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions DPCIManager/PCI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@property (readonly) NSString *lspciString;
@property (readonly) long fullID;
@property (readonly) long fullSubID;
@property (readonly) short bdf;

+(long)nameToLong:(NSString *)name;
+(bool)isPCI:(io_service_t)service;
Expand Down
5 changes: 5 additions & 0 deletions DPCIManager/PCI.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ -(long)fullID{
-(long)fullSubID{
return subDevice.integerValue<<16 | subVendor.integerValue;
}
-(short)bdf {
if (self.bus.count > 2)
return [[self.bus objectAtIndex:0] unsignedCharValue] << 8 | [[self.bus objectAtIndex:1] unsignedCharValue] << 3 | [[self.bus objectAtIndex:2] unsignedCharValue];
return -1;
}
+(NSArray *)readIDs{
FILE *handle = fopen([[NSBundle.mainBundle pathForResource:@"pci" ofType:@"ids"] fileSystemRepresentation], "rb");
NSMutableDictionary *classes = [NSMutableDictionary dictionary];
Expand Down
9 changes: 7 additions & 2 deletions dspci/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ int main(int argc, const char * argv[])
io_iterator_t itThis;
if (IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching("IOPCIDevice"), &itThis) == KERN_SUCCESS) {
io_service_t service;
NSMutableArray *devices = [NSMutableArray array];
while((service = IOIteratorNext(itThis))){
pciDevice *pci = [pciDevice create:service classes:classes vendors:vendors];
if (pci.fullID+pci.fullSubID > 0) printf("%s\n", pci.lspciString.UTF8String);
pciDevice *device = [pciDevice create:service classes:classes vendors:vendors];
if (device.fullID + device.fullSubID > 0) [devices addObject:device];
IOObjectRelease(service);
}
IOObjectRelease(itThis);
for (pciDevice *device in [devices sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 bdf] - [obj2 bdf];
}])
printf("%s\n", device.lspciString.UTF8String);
}

}
Expand Down

0 comments on commit 39af22d

Please sign in to comment.