@@ -92,7 +92,7 @@ void zpci_remove_reserved_devices(void)
9292 spin_unlock (& zpci_list_lock );
9393
9494 list_for_each_entry_safe (zdev , tmp , & remove , entry )
95- zpci_zdev_put (zdev );
95+ zpci_device_reserved (zdev );
9696}
9797
9898int pci_domain_nr (struct pci_bus * bus )
@@ -751,6 +751,14 @@ struct zpci_dev *zpci_create_device(u32 fid, u32 fh, enum zpci_state state)
751751 return ERR_PTR (rc );
752752}
753753
754+ bool zpci_is_device_configured (struct zpci_dev * zdev )
755+ {
756+ enum zpci_state state = zdev -> state ;
757+
758+ return state != ZPCI_FN_STATE_RESERVED &&
759+ state != ZPCI_FN_STATE_STANDBY ;
760+ }
761+
754762/**
755763 * zpci_scan_configured_device() - Scan a freshly configured zpci_dev
756764 * @zdev: The zpci_dev to be configured
@@ -822,6 +830,31 @@ int zpci_deconfigure_device(struct zpci_dev *zdev)
822830 return 0 ;
823831}
824832
833+ /**
834+ * zpci_device_reserved() - Mark device as resverved
835+ * @zdev: the zpci_dev that was reserved
836+ *
837+ * Handle the case that a given zPCI function was reserved by another system.
838+ * After a call to this function the zpci_dev can not be found via
839+ * get_zdev_by_fid() anymore but may still be accessible via existing
840+ * references though it will not be functional anymore.
841+ */
842+ void zpci_device_reserved (struct zpci_dev * zdev )
843+ {
844+ if (zdev -> has_hp_slot )
845+ zpci_exit_slot (zdev );
846+ /*
847+ * Remove device from zpci_list as it is going away. This also
848+ * makes sure we ignore subsequent zPCI events for this device.
849+ */
850+ spin_lock (& zpci_list_lock );
851+ list_del (& zdev -> entry );
852+ spin_unlock (& zpci_list_lock );
853+ zdev -> state = ZPCI_FN_STATE_RESERVED ;
854+ zpci_dbg (3 , "rsv fid:%x\n" , zdev -> fid );
855+ zpci_zdev_put (zdev );
856+ }
857+
825858void zpci_release_device (struct kref * kref )
826859{
827860 struct zpci_dev * zdev = container_of (kref , struct zpci_dev , kref );
@@ -843,6 +876,12 @@ void zpci_release_device(struct kref *kref)
843876 case ZPCI_FN_STATE_STANDBY :
844877 if (zdev -> has_hp_slot )
845878 zpci_exit_slot (zdev );
879+ spin_lock (& zpci_list_lock );
880+ list_del (& zdev -> entry );
881+ spin_unlock (& zpci_list_lock );
882+ zpci_dbg (3 , "rsv fid:%x\n" , zdev -> fid );
883+ fallthrough ;
884+ case ZPCI_FN_STATE_RESERVED :
846885 if (zdev -> has_resources )
847886 zpci_cleanup_bus_resources (zdev );
848887 zpci_bus_device_unregister (zdev );
@@ -851,10 +890,6 @@ void zpci_release_device(struct kref *kref)
851890 default :
852891 break ;
853892 }
854-
855- spin_lock (& zpci_list_lock );
856- list_del (& zdev -> entry );
857- spin_unlock (& zpci_list_lock );
858893 zpci_dbg (3 , "rem fid:%x\n" , zdev -> fid );
859894 kfree (zdev );
860895}
0 commit comments