xref: /openbmc/linux/arch/s390/kvm/pci.c (revision 6438e30714abd1bf7408356d3e86127d1fb379c0)
1*6438e307SMatthew Rosato // SPDX-License-Identifier: GPL-2.0
2*6438e307SMatthew Rosato /*
3*6438e307SMatthew Rosato  * s390 kvm PCI passthrough support
4*6438e307SMatthew Rosato  *
5*6438e307SMatthew Rosato  * Copyright IBM Corp. 2022
6*6438e307SMatthew Rosato  *
7*6438e307SMatthew Rosato  *    Author(s): Matthew Rosato <mjrosato@linux.ibm.com>
8*6438e307SMatthew Rosato  */
9*6438e307SMatthew Rosato 
10*6438e307SMatthew Rosato #include <linux/kvm_host.h>
11*6438e307SMatthew Rosato #include <linux/pci.h>
12*6438e307SMatthew Rosato #include "pci.h"
13*6438e307SMatthew Rosato 
14*6438e307SMatthew Rosato static int kvm_s390_pci_dev_open(struct zpci_dev *zdev)
15*6438e307SMatthew Rosato {
16*6438e307SMatthew Rosato 	struct kvm_zdev *kzdev;
17*6438e307SMatthew Rosato 
18*6438e307SMatthew Rosato 	kzdev = kzalloc(sizeof(struct kvm_zdev), GFP_KERNEL);
19*6438e307SMatthew Rosato 	if (!kzdev)
20*6438e307SMatthew Rosato 		return -ENOMEM;
21*6438e307SMatthew Rosato 
22*6438e307SMatthew Rosato 	kzdev->zdev = zdev;
23*6438e307SMatthew Rosato 	zdev->kzdev = kzdev;
24*6438e307SMatthew Rosato 
25*6438e307SMatthew Rosato 	return 0;
26*6438e307SMatthew Rosato }
27*6438e307SMatthew Rosato 
28*6438e307SMatthew Rosato static void kvm_s390_pci_dev_release(struct zpci_dev *zdev)
29*6438e307SMatthew Rosato {
30*6438e307SMatthew Rosato 	struct kvm_zdev *kzdev;
31*6438e307SMatthew Rosato 
32*6438e307SMatthew Rosato 	kzdev = zdev->kzdev;
33*6438e307SMatthew Rosato 	WARN_ON(kzdev->zdev != zdev);
34*6438e307SMatthew Rosato 	zdev->kzdev = NULL;
35*6438e307SMatthew Rosato 	kfree(kzdev);
36*6438e307SMatthew Rosato }
37