pci.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * s390 kvm PCI passthrough support
  4. *
  5. * Copyright IBM Corp. 2022
  6. *
  7. * Author(s): Matthew Rosato <[email protected]>
  8. */
  9. #ifndef __KVM_S390_PCI_H
  10. #define __KVM_S390_PCI_H
  11. #include <linux/kvm.h>
  12. #include <linux/kvm_host.h>
  13. #include <linux/mutex.h>
  14. #include <linux/pci.h>
  15. #include <asm/airq.h>
  16. #include <asm/cpu.h>
  17. struct kvm_zdev {
  18. struct zpci_dev *zdev;
  19. struct kvm *kvm;
  20. struct zpci_fib fib;
  21. struct list_head entry;
  22. };
  23. struct zpci_gaite {
  24. u32 gisa;
  25. u8 gisc;
  26. u8 count;
  27. u8 reserved;
  28. u8 aisbo;
  29. u64 aisb;
  30. };
  31. struct zpci_aift {
  32. struct zpci_gaite *gait;
  33. struct airq_iv *sbv;
  34. struct kvm_zdev **kzdev;
  35. spinlock_t gait_lock; /* Protects the gait, used during AEN forward */
  36. struct mutex aift_lock; /* Protects the other structures in aift */
  37. };
  38. extern struct zpci_aift *aift;
  39. static inline struct kvm *kvm_s390_pci_si_to_kvm(struct zpci_aift *aift,
  40. unsigned long si)
  41. {
  42. if (!IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM) || !aift->kzdev ||
  43. !aift->kzdev[si])
  44. return NULL;
  45. return aift->kzdev[si]->kvm;
  46. };
  47. int kvm_s390_pci_aen_init(u8 nisc);
  48. void kvm_s390_pci_aen_exit(void);
  49. void kvm_s390_pci_init_list(struct kvm *kvm);
  50. void kvm_s390_pci_clear_list(struct kvm *kvm);
  51. int kvm_s390_pci_zpci_op(struct kvm *kvm, struct kvm_s390_zpci_op *args);
  52. int kvm_s390_pci_init(void);
  53. void kvm_s390_pci_exit(void);
  54. static inline bool kvm_s390_pci_interp_allowed(void)
  55. {
  56. struct cpuid cpu_id;
  57. get_cpu_id(&cpu_id);
  58. switch (cpu_id.machine) {
  59. case 0x2817:
  60. case 0x2818:
  61. case 0x2827:
  62. case 0x2828:
  63. case 0x2964:
  64. case 0x2965:
  65. /* No SHM on certain machines */
  66. return false;
  67. default:
  68. return (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM) &&
  69. sclp.has_zpci_lsi && sclp.has_aeni && sclp.has_aisi &&
  70. sclp.has_aisii);
  71. }
  72. }
  73. #endif /* __KVM_S390_PCI_H */