diff --git a/zdev/Makefile b/zdev/Makefile index 2fc997c2..052741f6 100644 --- a/zdev/Makefile +++ b/zdev/Makefile @@ -7,6 +7,7 @@ all: install: all $(MAKE) -C src install $(MAKE) -C man install + $(MAKE) -C udev install $(MAKE) -C dracut install $(MAKE) -C initramfs install diff --git a/zdev/dracut/95zdev/module-setup.sh b/zdev/dracut/95zdev/module-setup.sh index a6d86116..e0cb9829 100644 --- a/zdev/dracut/95zdev/module-setup.sh +++ b/zdev/dracut/95zdev/module-setup.sh @@ -20,7 +20,7 @@ check() { [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1 # Ensure that required tools are available - require_binaries chzdev lszdev || return 1 + require_binaries chzdev lszdev /lib/s390-tools/zdev_id || return 1 return 0 } @@ -40,11 +40,14 @@ install() { local _tempfile # Ensure that required tools are available - inst_multiple chzdev lszdev vmcp + inst_multiple chzdev lszdev vmcp /lib/s390-tools/zdev_id # Hook to parse zdev kernel parameter inst_hook cmdline 95 "$moddir/parse-zdev.sh" + # Rule to automatically enable devices when running in DPM + inst_rules "81-dpm.rules" + # Obtain early + root device configuration _tempfile=$(mktemp --tmpdir dracut-zdev.XXXXXX) chzdev --export "$_tempfile" --persistent --by-path / --quiet \ diff --git a/zdev/dracut/95zdev/parse-zdev.sh b/zdev/dracut/95zdev/parse-zdev.sh index b70f5015..9077a0d4 100644 --- a/zdev/dracut/95zdev/parse-zdev.sh +++ b/zdev/dracut/95zdev/parse-zdev.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright IBM Corp. 2017 +# Copyright IBM Corp. 2017,2021 # # s390-tools is free software; you can redistribute it and/or modify # it under the terms of the MIT license. See LICENSE for details. @@ -15,11 +15,14 @@ # where # # no-auto: Indicates that firmware-provided I/O configuration data -# should not be applied. +# should not be applied. This also affects automatic +# activation of PCI and crypto devices when running in a DPM +# LPAR. # zdev_fw_file="/sys/firmware/sclp_sd/config/data" zdev_base_args="--force --yes --no-root-update --no-settle --auto-conf --quiet" +zdev_id="/lib/s390-tools/zdev_id" if [ -e "$zdev_fw_file" ] ; then zdev_auto=1 @@ -35,4 +38,22 @@ done if [ $zdev_auto -eq 1 ] ; then chzdev --import "$zdev_fw_file" $zdev_base_args + + # Get information about DPM environment + for line in $($zdev_id) ; do + eval "$line" + done + + if [ "$ZDEV_IS_DPM,$ZDEV_NEST_LEVEL,$ZDEV_HYPERVISOR_0" = "1,1,LPAR" ] ; then + # Manually iterate over existing PCI devices - there is a udev rule + # that handles this for PCI devices added at runtime but that doesn't + # work for PCI devices defined before boot because there is no coldplug + # trigger for /sys/bus/pci/slots + for slot in /sys/bus/pci/slots/* ; do + read power < "$slot/power" + if [ "$power" = "0" ] ; then + echo 1 > "$slot/power" + fi + done + fi fi diff --git a/zdev/initramfs/hooks/s390-tools-zdev b/zdev/initramfs/hooks/s390-tools-zdev index cc7d4966..89f230ab 100644 --- a/zdev/initramfs/hooks/s390-tools-zdev +++ b/zdev/initramfs/hooks/s390-tools-zdev @@ -38,6 +38,9 @@ done copy_exec /sbin/chzdev copy_exec /sbin/lszdev copy_exec /sbin/vmcp +copy_exec /lib/s390-tools/zdev_id + +cp -p /usr/lib/udev/rules.d/81-dpm.rules "$DESTDIR/usr/lib/udev/rules.d/" _tempfile=$(mktemp --tmpdir initramfs-zdev.XXXXXX) diff --git a/zdev/initramfs/scripts/init-top/s390-tools-zdev b/zdev/initramfs/scripts/init-top/s390-tools-zdev index f6b235fd..96e802fe 100644 --- a/zdev/initramfs/scripts/init-top/s390-tools-zdev +++ b/zdev/initramfs/scripts/init-top/s390-tools-zdev @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright IBM Corp. 2017 +# Copyright IBM Corp. 2017,2021 # # s390-tools is free software; you can redistribute it and/or modify # it under the terms of the MIT license. See LICENSE for details. @@ -15,7 +15,9 @@ # where # # no-auto: Indicates that firmware-provided I/O configuration data -# should not be applied. +# should not be applied. This also affects automatic +# activation of PCI and crypto devices when running in a DPM +# LPAR. # PREREQ="udev" @@ -36,6 +38,7 @@ esac zdev_fw_file="/sys/firmware/sclp_sd/config/data" zdev_base_args="--force --yes --no-root-update --no-settle --auto-conf --quiet" +zdev_id="/lib/s390-tools/zdev_id" if [ -e "$zdev_fw_file" ] ; then zdev_auto=1 @@ -64,4 +67,22 @@ if [ $zdev_auto -eq 1 ] ; then udevadm trigger --type=subsystems --action=add udevadm trigger --action=add udevadm settle || true + + # Get information about DPM environment + for line in $($zdev_id) ; do + eval "$line" + done + + if [ "$ZDEV_IS_DPM,$ZDEV_NEST_LEVEL,$ZDEV_HYPERVISOR_0" = "1,1,LPAR" ] ; then + # Manually iterate over existing PCI devices - there is a udev + # rule that handles this for PCI devices added at runtime but + # that doesn't work for PCI devices defined before boot because + # there is no coldplug trigger for /sys/bus/pci/slots + for slot in /sys/bus/pci/slots/* ; do + read power < "$slot/power" + if [ "$power" = "0" ] ; then + echo 1 > "$slot/power" + fi + done + fi fi diff --git a/zdev/udev/81-dpm.rules b/zdev/udev/81-dpm.rules new file mode 100644 index 00000000..4dbfbb29 --- /dev/null +++ b/zdev/udev/81-dpm.rules @@ -0,0 +1,40 @@ +# Automatically activate certain s390-specific device types that are attached +# in offline state when running in an LPAR managed by the Dynamic Partition +# Manager (DPM). +# +# Note that processing is restricted to DPM as there may be use cases for +# not enabling these device types in non-DPM mode. +# +# To deactivate this processing, specify the following on the kernel command +# line: +# +# rd.zdev=no-auto + +ACTION!="add", GOTO="end_dpm" + +# Handle newly added PCI devices in offline state +SUBSYSTEM=="slots", ATTR{power}=="0", GOTO="check_dpm" +# Handle newly added crypto devices in offline state +SUBSYSTEM=="ap", ENV{DEVTYPE}=="ap_card", ATTR{config}=="0", GOTO="check_dpm" + +GOTO="end_dpm" + +LABEL="check_dpm" + +IMPORT{program}="/lib/s390-tools/zdev_id" + +# Check for off-switch +ENV{ZDEV_NO_AUTO}=="1", GOTO="end_dpm" + +# Check for DPM LPAR +ENV{ZDEV_IS_DPM}!="1", GOTO="end_dpm" +ENV{ZDEV_NEST_LEVEL}!="1", GOTO="end_dpm" +ENV{ZDEV_HYPERVISOR_0}!="LPAR", GOTO="end_dpm" + +# Enable PCI device +SUBSYSTEM=="slots", ATTR{power}="1" +# Enable crypto device +SUBSYSTEM=="ap", ATTR{config}="1" + +# End of rule +LABEL="end_dpm" diff --git a/zdev/udev/Makefile b/zdev/udev/Makefile new file mode 100644 index 00000000..3372eee7 --- /dev/null +++ b/zdev/udev/Makefile @@ -0,0 +1,9 @@ +# Common definitions +include ../../common.mak + +UDEVDIR := /usr/lib/udev/rules.d/ +RULES := 81-dpm.rules + +install: + $(INSTALL) -m 755 -d $(DESTDIR)$(UDEVDIR) + $(INSTALL) -m 644 $(RULES) $(DESTDIR)$(UDEVDIR)/