generated from general-packages/pika-pkg-template
Swap GPU info source location
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 26s
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 26s
This commit is contained in:
parent
912e6c7189
commit
ef35db3717
2
.github/release-nest-v3
vendored
2
.github/release-nest-v3
vendored
@ -1 +1 @@
|
||||
2
|
||||
1
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.zig-cache
|
2
main.sh
2
main.sh
@ -6,7 +6,7 @@ set -e
|
||||
|
||||
echo "$PIKA_BUILD_ARCH" > pika-build-arch
|
||||
|
||||
VERSION="0.4.0"
|
||||
VERSION="0.5.0"
|
||||
|
||||
cd ./pikafetch/
|
||||
|
||||
|
@ -1,3 +1,9 @@
|
||||
pikafetch (0.5.0-101pika5) pika; urgency=medium
|
||||
|
||||
* Swap GPU info source location
|
||||
|
||||
-- ferreo <harderthanfire@gmail.com> Wed, 18 Jan 2023 21:48:14 +0000
|
||||
|
||||
pikafetch (0.4.0-101pika5) pika; urgency=medium
|
||||
|
||||
* Smol birb
|
||||
|
39471
pikafetch/debian/pikafetch/usr/share/pikafetch/pci.ids
Normal file
39471
pikafetch/debian/pikafetch/usr/share/pikafetch/pci.ids
Normal file
File diff suppressed because it is too large
Load Diff
@ -87,10 +87,6 @@ pub fn getGPUInfo(allocator: mem.Allocator) ![][]const u8 {
|
||||
}
|
||||
|
||||
fn detectGPU(allocator: mem.Allocator, card_name: []const u8) !?[]const u8 {
|
||||
if (try queryHwdb(allocator, card_name)) |gpu| {
|
||||
return gpu;
|
||||
}
|
||||
|
||||
const vendor_path = try allocPrint(allocator, "/sys/class/drm/{s}/device/vendor", .{card_name});
|
||||
const vendor_file = fs.openFileAbsolute(vendor_path, .{}) catch return null;
|
||||
defer vendor_file.close();
|
||||
@ -107,17 +103,29 @@ fn detectGPU(allocator: mem.Allocator, card_name: []const u8) !?[]const u8 {
|
||||
const device_len = device_file.readAll(&device_buf) catch return null;
|
||||
const device_str = mem.trim(u8, device_buf[0..device_len], "\n\r \t0x");
|
||||
|
||||
const model = try allocPrint(allocator, "(vendor: 0x{s}, device: 0x{s})", .{ vendor_str, device_str });
|
||||
const pci_info = lookupPCIInfo(allocator, vendor_str, device_str) catch null;
|
||||
if (pci_info) |info| {
|
||||
const gpu_info = GPUInfo{
|
||||
.vendor = info.vendor,
|
||||
.model = info.device,
|
||||
.driver = null,
|
||||
.memory = null,
|
||||
};
|
||||
|
||||
const gpu_info = GPUInfo{
|
||||
.vendor = "GPU",
|
||||
.model = model,
|
||||
.driver = null,
|
||||
.memory = null,
|
||||
};
|
||||
const formatted = try gpu_info.format(allocator);
|
||||
return formatted;
|
||||
} else {
|
||||
const model = try allocPrint(allocator, "(vendor: 0x{s}, device: 0x{s})", .{ vendor_str, device_str });
|
||||
const gpu_info = GPUInfo{
|
||||
.vendor = "GPU",
|
||||
.model = model,
|
||||
.driver = null,
|
||||
.memory = null,
|
||||
};
|
||||
|
||||
const formatted = try gpu_info.format(allocator);
|
||||
return formatted;
|
||||
const formatted = try gpu_info.format(allocator);
|
||||
return formatted;
|
||||
}
|
||||
}
|
||||
|
||||
fn getShortVendorName(vendor: []const u8) []const u8 {
|
||||
@ -175,6 +183,56 @@ fn cleanModelName(model: []const u8) []const u8 {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
const PCIComponents = struct {
|
||||
vendor: []const u8,
|
||||
device: []const u8,
|
||||
};
|
||||
|
||||
fn lookupPCIInfo(allocator: mem.Allocator, vendor_id: []const u8, device_id: []const u8) !?PCIComponents {
|
||||
const path = "/usr/share/pikafetch/pci.ids";
|
||||
const file = try fs.openFileAbsolute(path, .{});
|
||||
const stat = try file.stat();
|
||||
const mapped = try std.posix.mmap(
|
||||
null,
|
||||
@as(usize, @intCast(stat.size)),
|
||||
std.posix.PROT.READ,
|
||||
.{ .TYPE = std.os.linux.MAP_TYPE.PRIVATE },
|
||||
file.handle,
|
||||
0,
|
||||
);
|
||||
file.close();
|
||||
defer std.posix.munmap(mapped);
|
||||
const data = mapped;
|
||||
|
||||
var current_vendor: ?[]const u8 = null;
|
||||
var start_index: usize = 0;
|
||||
while (start_index < data.len) {
|
||||
const remaining = data[start_index..];
|
||||
const newlineIndexOpt = std.mem.indexOfScalar(u8, remaining, '\n');
|
||||
const line_end = if (newlineIndexOpt) |idx| idx else remaining.len;
|
||||
const line = remaining[0..line_end];
|
||||
|
||||
if (line.len == 0 or line[0] == '#') {} else if (line[0] != ' ' and line[0] != '\t') {
|
||||
if (line.len >= 4 and simdStartsWith(line, vendor_id)) {
|
||||
current_vendor = std.mem.trim(u8, line[4..], " \t");
|
||||
} else {
|
||||
current_vendor = null;
|
||||
}
|
||||
} else if (current_vendor != null) {
|
||||
const trimmed = std.mem.trimLeft(u8, line, " \t");
|
||||
if (trimmed.len >= 4 and simdStartsWith(trimmed, device_id)) {
|
||||
const dev_name = std.mem.trim(u8, trimmed[4..], " \t");
|
||||
const vendor = try allocator.dupe(u8, getShortVendorName(current_vendor.?));
|
||||
const model = try allocator.dupe(u8, cleanModelName(dev_name));
|
||||
return PCIComponents{ .vendor = vendor, .device = model };
|
||||
}
|
||||
}
|
||||
|
||||
start_index += line_end + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
fn queryHwdb(allocator: mem.Allocator, card_name: []const u8) !?[]const u8 {
|
||||
const modalias_path = try allocPrint(allocator, "/sys/class/drm/{s}/device/modalias", .{card_name});
|
||||
const modalias_file = fs.openFileAbsolute(modalias_path, .{}) catch return null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user