xref: /openbmc/linux/arch/s390/kvm/pci.c (revision 6438e307)
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 <mjrosato@linux.ibm.com>
8  */
9 
10 #include <linux/kvm_host.h>
11 #include <linux/pci.h>
12 #include "pci.h"
13 
14 static int kvm_s390_pci_dev_open(struct zpci_dev *zdev)
15 {
16 	struct kvm_zdev *kzdev;
17 
18 	kzdev = kzalloc(sizeof(struct kvm_zdev), GFP_KERNEL);
19 	if (!kzdev)
20 		return -ENOMEM;
21 
22 	kzdev->zdev = zdev;
23 	zdev->kzdev = kzdev;
24 
25 	return 0;
26 }
27 
28 static void kvm_s390_pci_dev_release(struct zpci_dev *zdev)
29 {
30 	struct kvm_zdev *kzdev;
31 
32 	kzdev = zdev->kzdev;
33 	WARN_ON(kzdev->zdev != zdev);
34 	zdev->kzdev = NULL;
35 	kfree(kzdev);
36 }
37