-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdfv_gpu.c
More file actions
154 lines (134 loc) · 4.24 KB
/
dfv_gpu.c
File metadata and controls
154 lines (134 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Device File-based I/O Virtualization (DFV)
* File: dfv_gpu.c
*
* Copyright (c) 2014 Rice University, Houston, TX, USA
* All rights reserved.
*
* Authors: Ardalan Amiri Sani <arrdalan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/module.h>
#include <drm/drmP.h>
#include "dfv_pci.h"
#include "dfv_common.h"
#include "dfv_client.h"
static char device_file_name[32];
module_param_string(device_file_name, device_file_name,
sizeof(device_file_name), 0660);
static char ctl_dev_file_name[32];
module_param_string(ctl_dev_file_name, ctl_dev_file_name,
sizeof(ctl_dev_file_name), 0660);
static unsigned int funcnr;
module_param(funcnr, uint, 0660);
static unsigned int devnr;
module_param(devnr, uint, 0660);
static unsigned int busnr;
module_param(busnr, uint, 0660);
static unsigned int domainnr;
module_param(domainnr, uint, 0660);
static unsigned short vendor;
module_param(vendor, ushort, 0660);
static unsigned short device;
module_param(device, ushort, 0660);
static unsigned short subsystem_vendor;
module_param(subsystem_vendor, ushort, 0660);
static unsigned short subsystem_device;
module_param(subsystem_device, ushort, 0660);
static unsigned int class;
module_param(class, uint, 0660);
static char driver_name[32];
module_param_string(driver_name, driver_name, sizeof(driver_name), 0660);
#define CFG_SIZE 256
#define RESOURCE_SIZE 39
static unsigned int config[CFG_SIZE];
module_param_array(config, uint, NULL, 0660);
u8 input_config[CFG_SIZE];
static unsigned long resource[RESOURCE_SIZE];
module_param_array(resource, ulong, NULL, 0660);
static struct dfv_pci_info *pci_info;
static struct cdev cdev;
static dev_t devt;
static dev_t devt2;
int major_number, major_number2;
static int create_device_files(struct pci_dev *pdev)
{
int result, err;
devt = MKDEV(0, 0);
devt2 = MKDEV(0, 0);
result = alloc_chrdev_region(&devt, 0, 1, device_file_name);
major_number = MAJOR(devt);
if (result)
return result;
result = alloc_chrdev_region(&devt2, 0, 1, ctl_dev_file_name);
major_number2 = MAJOR(devt2);
if (result)
return result;
cdev_init(&cdev, &dfvfops);
cdev.owner = THIS_MODULE;
cdev.ops = &dfvfops;
err = cdev_add(&cdev, devt, 1);
err = cdev_add(&cdev, devt2, 1);
if (err) {
DFVPRINTK_ERR("Error: Failed adding device (err = %d)", err);
}
else {
device_create(drm_class, &pdev->dev, devt, NULL,
device_file_name);
device_create(drm_class, &pdev->dev, devt2, NULL,
ctl_dev_file_name);
}
return 0;
}
static int __init dfv_gpu_init(void)
{
static struct pci_dev *pdev;
int i;
pci_info = kmalloc(sizeof(*pci_info), GFP_KERNEL);
sprintf(pci_info->dev_name, "%s", device_file_name);
pci_info->funcnr = funcnr;
pci_info->devnr = devnr;
pci_info->busnr = busnr;
pci_info->domainnr = domainnr;
pci_info->vendor = vendor;
pci_info->device = device;
pci_info->subsystem_vendor = subsystem_vendor;
pci_info->subsystem_device = subsystem_device;
pci_info->class = class;
sprintf(pci_info->driver_name, "%s", driver_name);
for (i = 0; i < CFG_SIZE; i++) {
input_config[i] = (u8) config[i];
}
pci_info->config = input_config;
pci_info->cfg_size = CFG_SIZE;
pci_info->resource = resource;
pdev = register_to_dfv_pci(pci_info);
create_device_files(pdev);
return 0;
}
static void __exit dfv_gpu_exit(void)
{
device_destroy(drm_class, devt);
device_destroy(drm_class, devt2);
unregister_from_dfv_pci(pci_info);
kfree(pci_info);
cdev_del(&cdev);
unregister_chrdev_region(MKDEV(major_number, 0), 1);
unregister_chrdev_region(MKDEV(major_number2, 0), 1);
}
module_init(dfv_gpu_init);
module_exit(dfv_gpu_exit);
MODULE_AUTHOR("Ardalan Amiri Sani <arrdalan@gmail.com>");
MODULE_DESCRIPTION("GPU info module for Device File-based I/O Virtualization");
MODULE_LICENSE("GPL");