-
Notifications
You must be signed in to change notification settings - Fork 10
/
aclpci.h
executable file
·230 lines (184 loc) · 7.08 KB
/
aclpci.h
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
* Copyright (c) 2014, Altera Corporation.
* All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* BSD 3-Clause license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* - Neither Altera nor the names of its contributors may be
* used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 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.
*/
/* Global declarations shared by all files of this driver. */
#ifndef ACLPCI_H
#define ACLPCI_H
#include <linux/kobject.h>
#include <linux/kdev_t.h>
#include <linux/list.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/jiffies.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/uaccess.h>
#include <linux/sched.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
// (comment from David Castells-Rufas)
// in versions > 4.11 send_sig_info is in the following header file
#include <linux/sched/signal.h>
#endif
/* includes from opencl/include/pcie */
#include "hw_pcie_constants.h"
#include "pcie_linux_driver_exports.h"
/* Local includes */
#include "version.h"
#define USE_DMA 1
#include "aclpci_dma.h"
#define DRIVER_NAME "aclpci"
#define BOARD_NAME "acl"
#define ACLPCI_MAX_MINORS 16
/* Set to 1 to use Polling (instead of interrupts) to communicate
* with hal. HAL must be compiled in the same mode */
#define POLLING 0
/* Debugging defines */
#define VERBOSE_DEBUG 0
#define ACL_DEBUG(...) \
do { \
printk("%s (%d): ", __func__, __LINE__); \
printk(__VA_ARGS__); \
printk("\n"); \
} while (0)
#if VERBOSE_DEBUG
# define ACL_VERBOSE_DEBUG(...) ACL_DEBUG(__VA_ARGS__)
#else
# define ACL_VERBOSE_DEBUG(...)
#endif
/* Don't actually bring down the kernel on an error condition */
#define assert(expr) \
do { \
if (!(expr)) { \
printk(KERN_ERR "Assertion failed! %s, %s, %s, line %d\n", \
#expr, __FILE__, __func__, __LINE__); \
} \
} while (0)
/* Maximum size of driver buffer (allocated with kalloc()).
* Needed to copy data from user to kernel space, among other
* things. */
static const size_t BUF_SIZE = PAGE_SIZE;
/* Device data used by this driver. */
struct aclpci_dev {
/* the kernel pci device data structure */
struct pci_dev *pci_dev;
/* upstream root node */
struct pci_dev *upstream;
/* kernels virtual addr. for the mapped BARs */
void * __iomem bar[ACL_PCI_NUM_BARS];
/* length of each memory region. Used for error checking. */
size_t bar_length[ACL_PCI_NUM_BARS];
/* Controls which section of board's DDR maps to BAR */
u64 global_mem_segment;
/* Kernel irq - mustn't assume it's safe to enable kernel irq */
char saved_kernel_irq_mask;
/* Location of global_mem_segment value on the board. */
void *global_mem_segment_addr;
/* temporary buffer. If allocated, will be BUF_SIZE. */
char *buffer;
/* Mutex for this device. */
struct semaphore sem;
/* PID of process that called open() */
int user_pid;
/* Number of handles referencing this device */
int num_handles_open;
/* character device */
dev_t cdev_num;
struct cdev cdev;
struct class *my_class;
struct device *device;
/* signal sending structs */
// @dcr
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0)
struct kernel_siginfo signal_info;
struct kernel_siginfo signal_info_dma;
#else
struct siginfo signal_info;
struct siginfo signal_info_dma;
#endif
struct task_struct *user_task;
int user_filehandle;
/* 1 if doing core reconfig via PCIe.
* Ignore all interrupts when this is going on. */
int cvp_in_progress;
/* State of uncorrectable error mask register, AER ext capability.
* Saved during reprogramming */
u32 aer_uerr_mask_reg;
/* All the DMA data */
struct aclpci_dma dma_data;
/* Debug data */
/* number of hw interrupts handled. */
size_t num_handled_interrupts;
size_t num_undelivered_signals;
int pci_gen;
int pci_num_lanes;
};
/* aclpci_fileio.c funciton */
int aclpci_open(struct inode *inode, struct file *file);
int aclpci_close(struct inode *inode, struct file *file);
ssize_t aclpci_read(struct file *file, char __user *buf, size_t count, loff_t *pos);
ssize_t aclpci_write(struct file *file, const char __user *buf, size_t count, loff_t *pos);
void* aclpci_get_checked_addr (int bar_id, void *device_addr, size_t count,
struct aclpci_dev *aclpci, ssize_t *errno, int print_error_msg);
/* aclpci.c functions */
void load_signal_info (struct aclpci_dev *aclpci);
int init_irq (struct pci_dev *dev, void *dev_id);
void release_irq (struct pci_dev *dev, void *aclpci);
void unmask_kernel_irq(struct aclpci_dev *aclpci);
void mask_kernel_irq(struct aclpci_dev *aclpci);
/* aclpci_dma.c functions */
void aclpci_dma_init(struct aclpci_dev *aclpci);
void aclpci_dma_finish(struct aclpci_dev *aclpci);
void aclpci_dma_stop(struct aclpci_dev *aclpci);
int aclpci_dma_get_idle_status(struct aclpci_dev *aclpci);
ssize_t aclpci_dma_rw (struct aclpci_dev *aclpci, void *dev_addr, void __user* use_addr, ssize_t len, int reading);
irqreturn_t aclpci_dma_service_interrupt (struct aclpci_dev *aclpci);
int aclpci_dma_update(struct aclpci_dev *aclpci, int forced);
/* aclpci_cmd.c functions */
void retrain_gen2 (struct aclpci_dev *aclpci);
ssize_t aclpci_exec_cmd (struct aclpci_dev *aclpci, struct acl_cmd kcmd, size_t count);
int aclpci_get_user_pages(struct task_struct *target_task, unsigned long start_page, size_t num_pages, struct page **p);
void aclpci_release_user_pages(struct task_struct *target_task, struct page **p, size_t num_pages);
/* aclpci_cvp.c functions */
int aclpci_cvp (struct aclpci_dev *aclpci, void __user* core_bitstream, ssize_t len);
#endif /* ACLPCI_H */