This repository was archived by the owner on Apr 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathgim_drv.c
More file actions
204 lines (158 loc) · 4.9 KB
/
gim_drv.c
File metadata and controls
204 lines (158 loc) · 4.9 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Copyright (c) 2014-2017 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE
*/
#include <linux/cpu.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/mod_devicetable.h>
#include <linux/version.h>
#include "gim_adapter.h"
#include "gim_unwrapper.h"
#include "gim_pci.h"
#include "gim_interface.h"
#include "gim_config.h"
#include "gim_timer.h"
#include "gim_debug.h"
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include "gim_pci_config.h"
#define MAJ 1
#define MIN 0
#define BUILD 0
#define DRV_VERSION \
__stringify(MAJ) "." __stringify(MIN) "." __stringify(BUILD) "-k"
char gim_driver_name[] = "gim";
char gim_driver_version[] = DRV_VERSION;
static const char gim_driver_string[] =
"GPU IOV MODULE";
static const char gim_copyright[] =
"Copyright (c) 2014-2017 AMD Corporation.";
/* TBD: Tonga Device ID */
static const struct pci_device_id gim_pci_tbl[] = {
{ PCI_VDEVICE(ATI, 0x6929), 0 }, /* Tonga S7150 'Cloudy Quark' */
/* required last entry */
{0, }
};
#define MAX_BRIDGES 10
struct aer_item device_list[MAX_BRIDGES];
static ssize_t sriov_store(struct device_driver *drv, const char *buf,
size_t count)
{
call_interface_functions(buf, count);
return count;
}
static ssize_t sriov_show(struct device_driver *drv, char *buf)
{
return respond_interface_functions(buf);
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
static DRIVER_ATTR(sriov, (S_IWUSR | S_IRUSR), sriov_show, sriov_store);
#else
static DRIVER_ATTR_RW(sriov);
#endif
static int gim_probe(struct pci_dev *pdev,
const struct pci_device_id *ent)
{
set_new_adapter(pdev);
gim_info("AMD GIM probe: pf_count = %d\n", get_adapter_count());
return 0;
}
static void gim_remove(struct pci_dev *pdev)
{
gim_info("AMD GIM remvoe\n");
}
static void gim_shutdown(struct pci_dev *pdev)
{
gim_info("AMD GIM shutdown\n");
}
static pci_ers_result_t gim_io_error_detected(struct pci_dev *pdev,
pci_channel_state_t state)
{
gim_info("AMD GIM io error detected\n");
/* Request a slot slot reset. */
return PCI_ERS_RESULT_NEED_RESET;
}
static pci_ers_result_t gim_io_slot_reset(struct pci_dev *pdev)
{
gim_info("AMD GIM io slot reset\n");
return PCI_ERS_RESULT_RECOVERED;
}
static void gim_io_resume(struct pci_dev *pdev)
{
gim_info("AMD GIM io resume\n");
}
static struct pci_error_handlers gim_err_handler = {
.error_detected = gim_io_error_detected,
.slot_reset = gim_io_slot_reset,
.resume = gim_io_resume,
};
static struct pci_driver gim_driver = {
.name = gim_driver_name,
.id_table = NULL,
.probe = gim_probe,
.remove = gim_remove,
.shutdown = gim_shutdown,
.err_handler = &gim_err_handler
};
static int gim_init(void)
{
int ret = 0;
int pf_count;
struct pci_dev *pfDevices[MAX_ADAPTERS_IN_SYSTEM];
gim_info("Start AMD open source GIM initialization\n");
gim_info("%s - version %s\n",
gim_driver_string, gim_driver_version);
gim_info("%s\n", gim_copyright);
init_config();
pf_count = enumerate_all_pfs(gim_pci_tbl,
MAX_ADAPTERS_IN_SYSTEM, pfDevices);
if (pf_count > 0) {
int count;
for (count = 0 ; count < pf_count ; count++)
gim_probe(pfDevices[count], NULL);
}
ret = pci_register_driver(&gim_driver);
ret = driver_create_file(&gim_driver.driver,
&driver_attr_sriov);
gim_init_debug_interface();
#ifdef CONFIG_GIM_HEARTBEAT_TIMER
init_heartbeat_timer();
start_heartbeat_timer(10); /* 10 second delay */
#endif
return ret;
}
static void gim_exit(void)
{
gim_info("Exit AMD open source GIM!\n");
#ifdef CONFIG_GIM_HEARTBEAT_TIMER
delete_heartbeat_timer();
#endif
release_all_adapters();
driver_remove_file(&gim_driver.driver, &driver_attr_sriov);
pci_unregister_driver(&gim_driver);
gim_exit_debug_interface();
}
module_init(gim_init)
module_exit(gim_exit)
MODULE_VERSION(DRV_VERSION);
MODULE_AUTHOR("Advanced Micro Devices, Inc.");
MODULE_DESCRIPTION("GPU IOV MODULE");
MODULE_LICENSE("GPL and additional rights");