diff --git a/bin/omarchy-hw-hybrid-gpu b/bin/omarchy-hw-hybrid-gpu index 2606d1e2b577..5e241cceaab9 100755 --- a/bin/omarchy-hw-hybrid-gpu +++ b/bin/omarchy-hw-hybrid-gpu @@ -2,19 +2,11 @@ # omarchy:summary=Detect whether the system has an active hybrid GPU configuration -# Count display controllers (PCI class 0x03) from the cached sysfs IDs rather -# than lspci, which reads PCI config space and resumes a runtime-suspended -# dGPU -- on every menu open, since the menu's Hybrid GPU row asks this. -pci_devices_path="${OMARCHY_PCI_DEVICES_PATH:-/sys/bus/pci/devices}" +export OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}" +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" multiple_gpus() { - local device class count=0 - - for device in "$pci_devices_path"/*; do - [[ -r $device/class ]] && read -r class <"$device/class" && [[ $class == 0x03* ]] && ((count += 1)) - done - - ((count >= 2)) + (( $(omarchy-pci-class-count 0x03) >= 2 )) } if omarchy-cmd-present supergfxctl; then diff --git a/bin/omarchy-hw-nvidia b/bin/omarchy-hw-nvidia index 7d1805935448..75919447ef1d 100755 --- a/bin/omarchy-hw-nvidia +++ b/bin/omarchy-hw-nvidia @@ -2,15 +2,7 @@ # omarchy:summary=Detect whether the computer has an NVIDIA GPU. -# Read the cached sysfs IDs rather than lspci, which reads PCI config space and -# resumes runtime-suspended GPUs. -pci_devices_path="${OMARCHY_PCI_DEVICES_PATH:-/sys/bus/pci/devices}" +export OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}" +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" -shopt -s nullglob - -for device in "$pci_devices_path"/*; do - [[ $(< "$device/vendor") == "0x10de" ]] || continue - [[ $(< "$device/class") == 0x03* ]] && exit 0 -done - -exit 1 +omarchy-pci-class-vendor 0x03 0x10de diff --git a/bin/omarchy-install-gaming-gpu-lib32 b/bin/omarchy-install-gaming-gpu-lib32 index 4a20bb32607f..5fc5399b938a 100755 --- a/bin/omarchy-install-gaming-gpu-lib32 +++ b/bin/omarchy-install-gaming-gpu-lib32 @@ -11,16 +11,19 @@ set -e # x86_64. aarch64 runs Valve's native arm64 Steam client and needs none. omarchy-hw-x86 || exit 0 +export OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}" +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" + echo "Installing lib32 graphics drivers..." PACKAGES=() declare -A VULKAN_DRIVERS=( - [Intel]=lib32-vulkan-intel - [AMD]=lib32-vulkan-radeon + [0x8086]=lib32-vulkan-intel + [0x1002]=lib32-vulkan-radeon ) for vendor in "${!VULKAN_DRIVERS[@]}"; do - if lspci | grep -iE "(VGA|Display).*$vendor" >/dev/null; then + if omarchy-pci-class-vendor 0x03 "$vendor"; then PACKAGES+=("${VULKAN_DRIVERS[$vendor]}") fi done diff --git a/install/hardware/apple/fix-brcmfmac-supplicant.sh b/install/hardware/apple/fix-brcmfmac-supplicant.sh index b679790f4e5e..df4e9b029188 100644 --- a/install/hardware/apple/fix-brcmfmac-supplicant.sh +++ b/install/hardware/apple/fix-brcmfmac-supplicant.sh @@ -26,11 +26,13 @@ if omarchy-hw-aarch64-apple; then return 0 fi +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" + sys_vendor="$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null || true)" -if lspci -nn | grep "106b:180[12]" >/dev/null || +if omarchy-pci-id 0x106b 0x1801 0x1802 || { [[ $sys_vendor == Apple* ]] && - lspci -nn | grep -E "14e4:(43ba|43bb|43bc|43a3|43dc|4464|4488|4425|4433)" >/dev/null; }; then + omarchy-pci-id 0x14e4 0x43ba 0x43bb 0x43bc 0x43a3 0x43dc 0x4464 0x4488 0x4425 0x4433; }; then echo "Detected a Mac with Broadcom Wi-Fi; running the WPA handshake in software" mkdir -p /etc/modprobe.d diff --git a/install/hardware/apple/fix-t2.sh b/install/hardware/apple/fix-t2.sh index 90d4a7df0fa3..dc544eb112a1 100644 --- a/install/hardware/apple/fix-t2.sh +++ b/install/hardware/apple/fix-t2.sh @@ -1,6 +1,8 @@ # Detect T2 MacBook models using PCI IDs # Vendor: 106b (Apple), Device IDs: 1801 or 1802 (T2 Security Chip) -if lspci -nn | grep "106b:180[12]" >/dev/null; then +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" + +if omarchy-pci-id 0x106b 0x1801 0x1802; then echo "Detected MacBook with T2 chip. Installing support items..." # apple-bcm-firmware-fetcher reads its firmware off an on-disk macOS volume — diff --git a/install/hardware/fix-bcm43xx.sh b/install/hardware/fix-bcm43xx.sh index 0f9cf474a5be..e3fddad52a59 100644 --- a/install/hardware/fix-bcm43xx.sh +++ b/install/hardware/fix-bcm43xx.sh @@ -2,9 +2,9 @@ # - BCM4360 (2013–2015 MacBooks) # - BCM4331 (2012, early 2013 MacBooks) -pci_info=$(lspci -nn) +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" -if (echo "$pci_info" | grep -q "14e4:43a0" || echo "$pci_info" | grep -q "14e4:4331"); then +if omarchy-pci-id 0x14e4 0x43a0 0x4331; then echo "BCM4360 / BCM4331 detected" omarchy-pkg-add broadcom-wl-dkms fi diff --git a/install/hardware/intel/fix-wifi7-eht.sh b/install/hardware/intel/fix-wifi7-eht.sh index 8d73095c29df..87a7c5a04a1f 100644 --- a/install/hardware/intel/fix-wifi7-eht.sh +++ b/install/hardware/intel/fix-wifi7-eht.sh @@ -5,7 +5,9 @@ # back to WiFi 6 (HE/802.11ax) which works at full speed. # This should be removed when Intel fixes the firmware/driver. -if lspci -nn | grep -qE '\[8086:(e440|272b)\]'; then +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" + +if omarchy-pci-id 0x8086 0xe440 0x272b; then mkdir -p /etc/modprobe.d cat > /etc/modprobe.d/iwlwifi-disable-eht.conf <<'EOF' # Temporary fix Dell XPS 14/16 on Panther lake diff --git a/install/hardware/nvidia.sh b/install/hardware/nvidia.sh index 0aa51d76ee6b..d03fff8d68d5 100644 --- a/install/hardware/nvidia.sh +++ b/install/hardware/nvidia.sh @@ -3,7 +3,7 @@ # system firmware and on the DKMS build, and there are no 32-bit libraries. if omarchy-hw-aarch64-n1x; then echo "NVIDIA N1x platform detected; GPU driver policy is owned by hardware/n1x.sh" -elif lspci | grep -qi 'nvidia'; then +elif omarchy-hw-nvidia; then # The 32-bit libraries come from multilib, which only x86_64 has. if omarchy-hw-nvidia-gsp; then PACKAGES=(nvidia-open-dkms nvidia-utils) diff --git a/install/hardware/pacman.sh b/install/hardware/pacman.sh index 7533d3f378cf..9cc6cc84f246 100644 --- a/install/hardware/pacman.sh +++ b/install/hardware/pacman.sh @@ -1,6 +1,8 @@ # Hardware-specific pacman repository extensions that must survive the final # pacman.conf restore. -if lspci -nn | grep "106b:180[12]" >/dev/null; then +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" + +if omarchy-pci-id 0x106b 0x1801 0x1802; then if ! grep -q '^\[arch-mact2\]' /etc/pacman.conf; then cat >> /etc/pacman.conf <<'EOF' diff --git a/install/hardware/vulkan.sh b/install/hardware/vulkan.sh index 2babffb6e6bb..29d07b799fe8 100644 --- a/install/hardware/vulkan.sh +++ b/install/hardware/vulkan.sh @@ -1,16 +1,18 @@ # Install Vulkan drivers matching detected GPU hardware # (NVIDIA Vulkan is handled by nvidia.sh via nvidia-utils) +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" + declare -A VULKAN_DRIVERS=( - [Intel]=vulkan-intel - [AMD]=vulkan-radeon - [Apple]=vulkan-asahi + [0x8086]=vulkan-intel + [0x1002]=vulkan-radeon + [0x106b]=vulkan-asahi ) PACKAGES=() for vendor in "${!VULKAN_DRIVERS[@]}"; do - if lspci | grep -iE "(VGA|Display).*$vendor" > /dev/null; then + if omarchy-pci-class-vendor 0x03 "$vendor"; then PACKAGES+=("${VULKAN_DRIVERS[$vendor]}") fi done diff --git a/install/helpers/pci-sysfs.sh b/install/helpers/pci-sysfs.sh new file mode 100644 index 000000000000..1fdf636bc2f0 --- /dev/null +++ b/install/helpers/pci-sysfs.sh @@ -0,0 +1,69 @@ +# Detect PCI devices from cached sysfs fields instead of lspci. +# +# lspci reads PCI config space, and the kernel resumes a runtime-suspended +# device to serve that read. On a hybrid laptop the discrete GPU idles in +# D3cold, so a bare lspci can take over a second waking it. The vendor, device, +# class, and subsystem IDs are served from cached sysfs fields that never touch +# config space, so nothing wakes. +# +# Each matcher walks /sys/bus/pci/devices once and returns 0 on the first match. +# Tests point OMARCHY_PCI_DEVICES_PATH at a fixture tree of the same layout. + +# Point the helpers at a fixture tree instead of the real sysfs in tests. +: "${OMARCHY_PCI_DEVICES_PATH:=/sys/bus/pci/devices}" + +# Each matcher walks the devices dir once and returns 0 on the first match. +shopt -s nullglob + +# First argument is a vendor ID; the remaining arguments are device IDs for that +# vendor to accept. Returns 0 if any device carries both. +omarchy-pci-id() { + local vendor="$1" + shift + local device id + for device in "$OMARCHY_PCI_DEVICES_PATH"/*; do + [[ $(<"$device/vendor") == "$vendor" ]] || continue + for id in "$@"; do + [[ $(<"$device/device") == "$id" ]] && return 0 + done + done + return 1 +} + +# First argument is a class prefix (e.g. 0x03 for a display controller); the +# second is a vendor ID. Returns 0 if any device's class begins with the prefix +# and its vendor matches. +omarchy-pci-class-vendor() { + local class="$1" vendor="$2" + local device + for device in "$OMARCHY_PCI_DEVICES_PATH"/*; do + [[ $(<"$device/class") == "${class}"* && $(<"$device/vendor") == "$vendor" ]] && return 0 + done + return 1 +} + +# First argument is a class prefix. Prints how many devices have a class that +# begins with it, regardless of vendor; for aggregation and count checks where +# a boolean matcher is not enough. +omarchy-pci-class-count() { + local class="$1" + local device + local count=0 + for device in "$OMARCHY_PCI_DEVICES_PATH"/*; do + [[ $(<"$device/class") == "${class}"* ]] && count=$((count + 1)) + done + printf '%s\n' "$count" +} + +# Returns 0 if any device is bound to the named driver, read from the bound +# driver symlink. +omarchy-pci-driver() { + local driver="$1" + local device bound + for device in "$OMARCHY_PCI_DEVICES_PATH"/*; do + [[ -L $device/driver ]] || continue + bound="$(readlink "$device/driver")" + [[ ${bound##*/} == "$driver" ]] && return 0 + done + return 1 +} diff --git a/install/user/hardware/fix-nouveau-cursor.sh b/install/user/hardware/fix-nouveau-cursor.sh index 3b819432db2c..ff599bedf472 100644 --- a/install/user/hardware/fix-nouveau-cursor.sh +++ b/install/user/hardware/fix-nouveau-cursor.sh @@ -4,11 +4,11 @@ # older NVIDIA GPUs, leaving the mouse pointer invisible under Hyprland. # Skip the fix when the proprietary driver was configured: supported GPUs can # still use nouveau during installation before switching drivers on reboot. +source "$OMARCHY_PATH/install/helpers/pci-sysfs.sh" + nvidia_config="${OMARCHY_NVIDIA_MODPROBE_CONFIG:-/etc/modprobe.d/nvidia.conf}" -if [[ ! -f $nvidia_config ]] && - omarchy-cmd-present lspci && - LC_ALL=C lspci -k | grep -qi 'Kernel driver in use: nouveau'; then +if [[ ! -f $nvidia_config ]] && omarchy-pci-driver nouveau; then looknfeel="$HOME/.config/hypr/looknfeel.lua" if [[ -f $looknfeel ]] && ! grep -q 'no_hardware_cursors' "$looknfeel"; then