Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 49 additions & 25 deletions bin/xconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ error() { log "ERROR" "$@"; echo "Error: $*" >&2; }
# Detect X server implementation (XLibre vs Xorg)
detect_x_server() {
local x_server="unknown"

if command -v Xorg >/dev/null 2>&1; then
local version_output
version_output=$(Xorg -version 2>&1)
Expand All @@ -38,7 +37,6 @@ detect_x_server() {
x_server="xorg"
fi
fi

echo "$x_server"
}

Expand All @@ -52,27 +50,28 @@ check_environment() {
info "Starting $SCRIPT_NAME (PID: $$)"
info "Script directory: $SCRIPT_DIR"
info "Config directory: $CONFIG_DIR"

local x_server; x_server=$(detect_x_server)
info "Detected X server: $x_server"
}

# Apply external configuration file
apply_external_config() {
local config_name="$1"
local config_file="$CONFIG_DIR/XF86Config.$config_name"
if [ -f "$config_file" ]; then
info "Applying external configuration: $config_file"
backup_config
mkdir -p /etc/X11
cp "$config_file" "$XORG_CONF"
info "Applied $config_name configuration from external file"
return 0
else
error "External config file not found: $config_file"
error "Please ensure $config_file exists in $CONFIG_DIR"
return 1
fi
# Try model specific first, then generic
for cand in "$config_name" "kaveri" "r5"; do
local config_file="$CONFIG_DIR/XF86Config.$cand"
if [ -f "$config_file" ]; then
info "Applying external configuration: $config_file"
backup_config
mkdir -p /etc/X11
cp "$config_file" "$XORG_CONF"
info "Applied $cand configuration from external file"
return 0
fi
done
error "External config not found for $config_name (tried: $config_name, kaveri, r5)"
return 1
}

# Detect all GPUs on the system
Expand Down Expand Up @@ -187,10 +186,12 @@ classify_gpu() {
;;
0x8086) echo "intel" ;;
0x1002)
# Make Kaveri and common R5 ids explicit
local device_hex=${device_id#0x}
case "$device_hex" in
6[7-9a-f]*|7*) echo "amdgpu" ;;
*) echo "radeonkms" ;;
1304|1309|1313|1315|1316|1318) echo "radeonkms" ;;
6[7-9a-f]*|7*) echo "amdgpu" ;;
*) echo "radeonkms" ;;
esac
;;
0x15ad) echo "vmware" ;;
Expand Down Expand Up @@ -266,11 +267,11 @@ backup_config() {
# Ensure Linux compatibility for NVIDIA
ensure_linux_compatibility() {
if ! sysrc -n linux_enable 2>/dev/null | grep -q "YES"; then
info "Enabling Linux compatibility layer"; sysrc linux_enable="YES" || warn "Failed to enable Linux compatibility"
info "Enabling Linux compatibility layer"; sysrc linux_enable="YES" || warn "Failed to enable linux compatibility"
fi
if ! kldstat | grep -q "linux"; then
info "Loading Linux compatibility module"
kldload linux 2>/dev/null || kldload linux.ko 2>/dev/null || warn "Failed to load Linux module"
kldload linux 2>/dev/null || kldload linux.ko 2>/dev/null || warn "Failed to load linux module"
fi
}

Expand All @@ -280,7 +281,29 @@ append_kld_list() {
case " $cur " in *" $mod "*) : ;; *) sysrc kld_list="$cur $mod" >/dev/null ;; esac
}

# Load NVIDIA kernel module (idempotent; tolerate "already loaded" and busy unloads)
# Ensure loader.conf has module_load="YES" once
ensure_loader_module_load() {
local mod="$1"
local lc="/boot/loader.conf"
grep -Eq "^[[:space:]]*${mod}_load=\"YES\"" "$lc" 2>/dev/null || {
info "Adding ${mod}_load=\"YES\" to $lc"
printf '%s\n' "${mod}_load=\"YES\"" >> "$lc"
}
}

# AMD firmware helpers
need_amd_firmware_install() {
# return 0 if NOT installed, 1 if installed
pkg info -e gpu-firmware-amd-kmod >/dev/null 2>&1 && return 1 || return 0
}
install_amd_firmware() {
if need_amd_firmware_install; then
info "Installing AMD firmware package (gpu-firmware-amd-kmod)"
pkg install -y gpu-firmware-amd-kmod || warn "Firmware install failed; continuing"
fi
}

# Load NVIDIA kernel module (idempotent; tolerate already loaded and busy unloads)
load_nvidia_module() {
local module_name="$1"
info "Loading NVIDIA module: $module_name"
Expand Down Expand Up @@ -326,16 +349,13 @@ load_nvidia_module() {
# Install NVIDIA driver
install_nvidia_driver() {
local pkg_name="$1" actual_pkg_name x_server

# Detect X server and adjust package name if needed
x_server=$(detect_x_server)
if [ "$x_server" = "xlibre" ]; then
actual_pkg_name="xlibre-$pkg_name"
info "XLibre detected, using package: $actual_pkg_name"
else
actual_pkg_name="$pkg_name"
fi

if pkg info "$actual_pkg_name" >/dev/null 2>&1; then
info "NVIDIA driver $actual_pkg_name already installed"; return 0; fi
ensure_linux_compatibility
Expand Down Expand Up @@ -468,8 +488,13 @@ setup_amd() {
for mod in amdgpu radeonkms i915kms nvidia nvidia-modeset; do
if kldstat | grep -q "\\b$mod\\b"; then kldunload "$mod" 2>/dev/null || true; fi
done

# Ensure firmware package is present for older gens like Kaveri
install_amd_firmware

if kldload "$driver_type" >/dev/null 2>&1; then
append_kld_list "$driver_type"
ensure_loader_module_load "$driver_type"
info "AMD $driver_type module loaded successfully"
if apply_external_config "$driver_type"; then
return 0
Expand Down Expand Up @@ -732,4 +757,3 @@ main() {
}

main "$@"

7 changes: 6 additions & 1 deletion cardDetect/XF86Config.kaveri
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Xorg config for AMD Kaveri / Radeon R5 (using modesetting DDX)
# Minimal, modern configuration for radeonkms with DRI3 acceleration
# Path: cardDetect/XF86Config.kaveri

Section "Device"
Identifier "AMD Kaveri (modesetting)"
Driver "modesetting"
Option "AccelMethod" "glamor"
Option "DRI" "3"
# BusID "PCI:1:0:0"
# Optional: set BusID if X binds the wrong GPU
# BusID "PCI:1:0:0"
EndSection
104 changes: 25 additions & 79 deletions cardDetect/XF86Config.radeonkms
Original file line number Diff line number Diff line change
@@ -1,92 +1,38 @@
# AMD Radeon KMS graphics xorg.conf file for GhostBSD/FreeBSD
# For legacy AMD/ATI Radeon graphics cards with radeonkms kernel module

Section "ServerLayout"
Identifier "RadeonKMS Configured"
Screen 0 "Screen0" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
Option "AutoAddDevices" "Off"
EndSection

Section "Files"
ModulePath "/usr/local/lib/modules"
ModulePath "/usr/local/lib/xorg/modules"
FontPath "/usr/local/share/fonts/misc/"
FontPath "/usr/local/share/fonts/TTF/"
FontPath "/usr/local/share/fonts/Type1/"
FontPath "/usr/local/share/fonts/75dpi/"
FontPath "/usr/local/share/fonts/100dpi/"
FontPath "/usr/local/share/fonts/dejavu/"
FontPath "/usr/local/share/fonts/TrueType/"
EndSection

Section "Module"
Load "extmod"
Load "record"
Load "dbe"
Load "glx"
Load "dri"
Load "dri2"
EndSection

Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "Protocol" "standard"
Option "XkbRules" "xorg"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
EndSection

Section "InputDevice"
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/sysmouse"
Option "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
Identifier "Monitor0"
VendorName "Generic Monitor"
ModelName "AMD Radeon Monitor"
HorizSync 28.0 - 96.0
VertRefresh 50.0 - 75.0
Option "DPMS"
EndSection
# AMD Radeon KMS (radeonkms) — modern Xorg config for GhostBSD/FreeBSD
# Minimal, EDID-driven, DRI3 + TearFree, libinput for input

Section "Device"
Identifier "Card0"
Identifier "AMD Radeon (radeon DDX)"
Driver "radeon"
Option "AccelMethod" "glamor"
Option "DRI" "2"
Option "ColorTiling" "true"
# Acceleration & present
Option "AccelMethod" "glamor" # use glamor with KMS
Option "DRI" "3" # DRI3 improves latency
Option "TearFree" "on" # basic tear mitigation
Option "EnablePageFlip" "true"
Option "ColorTiling" "on"
# Optional: set BusID if X binds the wrong GPU (see pciconf -lv)
# BusID "PCI:1:0:0"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
Identifier "Screen0"
Device "AMD Radeon (radeon DDX)"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 16
Modes "1920x1080" "1680x1050" "1600x1200" "1400x1050" "1280x1024" "1024x768" "800x600"
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1920x1080" "1680x1050" "1600x1200" "1400x1050" "1280x1024" "1024x768" "800x600"
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 32
Modes "1920x1080" "1680x1050" "1600x1200" "1400x1050" "1280x1024" "1024x768" "800x600"
Depth 24
# Do NOT force modelines; let EDID pick native mode
EndSubSection
EndSection

Section "DRI"
Mode 0666
# libinput handles keyboards & mice (no legacy InputDevice stanzas)
Section "InputClass"
Identifier "libinput pointer"
MatchIsPointer "on"
Driver "libinput"
EndSection

Section "InputClass"
Identifier "libinput keyboard"
MatchIsKeyboard "on"
Driver "libinput"
EndSection