-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathmodule.c
More file actions
111 lines (85 loc) · 3.05 KB
/
module.c
File metadata and controls
111 lines (85 loc) · 3.05 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
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/debugfs.h>
#include <linux/proc_fs.h>
#include <linux/version.h>
#include "chardev.h"
#include "enumerate.h"
#include "module.h"
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)
#error "tt-kmd requires Linux 5.4 or later"
#endif
#define TENSTORRENT_DRIVER_VERSION_STRING \
__stringify(TENSTORRENT_DRIVER_VERSION_MAJOR) "." \
__stringify(TENSTORRENT_DRIVER_VERSION_MINOR) "." \
__stringify(TENSTORRENT_DRIVER_VERSION_PATCH) \
TENSTORRENT_DRIVER_VERSION_SUFFIX
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Tenstorrent AI kernel driver");
MODULE_VERSION(TENSTORRENT_DRIVER_VERSION_STRING);
struct dentry *tt_debugfs_root;
struct proc_dir_entry *tt_procfs_root;
static uint max_devices = 32;
module_param(max_devices, uint, 0444);
MODULE_PARM_DESC(max_devices, "Maximum number of tenstorrent devices (chips) to support.");
uint dma_address_bits = 0;
module_param(dma_address_bits, uint, 0444);
MODULE_PARM_DESC(dma_address_bits, "DMA address bits, 0 for automatic.");
uint reset_limit = 10;
module_param(reset_limit, uint, 0444);
MODULE_PARM_DESC(reset_limit, "Maximum number of times to reset device during boot.");
unsigned char auto_reset_timeout = 10;
module_param(auto_reset_timeout, byte, 0444);
MODULE_PARM_DESC(auto_reset_timeout, "Timeout duration in seconds for M3 auto reset to occur.");
bool power_policy = true;
module_param(power_policy, bool, 0444);
MODULE_PARM_DESC(power_policy, "Enable power policy: low power at probe, re-aggregate on close (default=on).");
const struct pci_device_id tenstorrent_ids[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_TENSTORRENT, PCI_DEVICE_ID_GRAYSKULL),
.driver_data=(kernel_ulong_t)NULL}, // Deprecated
{ PCI_DEVICE(PCI_VENDOR_ID_TENSTORRENT, PCI_DEVICE_ID_WORMHOLE),
.driver_data=(kernel_ulong_t)&wormhole_class },
{ PCI_DEVICE(PCI_VENDOR_ID_TENSTORRENT, PCI_DEVICE_ID_BLACKHOLE),
.driver_data=(kernel_ulong_t)&blackhole_class },
{ 0 },
};
MODULE_DEVICE_TABLE(pci, tenstorrent_ids);
static int __init ttdriver_init(void)
{
int err = 0;
printk(KERN_INFO "Loading Tenstorrent AI driver module v%s.\n", TENSTORRENT_DRIVER_VERSION_STRING);
tt_debugfs_root = debugfs_create_dir("tenstorrent", NULL);
tt_procfs_root = proc_mkdir("driver/tenstorrent", NULL);
if (!tt_procfs_root) {
err = -ENOMEM;
goto fail_procfs;
}
err = init_char_driver(max_devices);
if (err != 0)
goto fail_char_driver;
err = tenstorrent_pci_register_driver();
if (err != 0)
goto fail_pci_register;
return 0;
fail_pci_register:
cleanup_char_driver();
fail_char_driver:
proc_remove(tt_procfs_root);
fail_procfs:
debugfs_remove(tt_debugfs_root);
return err;
}
static void __exit ttdriver_cleanup(void)
{
printk(KERN_INFO "Unloading Tenstorrent AI driver module.\n");
tenstorrent_pci_unregister_driver();
cleanup_char_driver();
debugfs_remove(tt_debugfs_root);
proc_remove(tt_procfs_root);
}
module_init(ttdriver_init);
module_exit(ttdriver_cleanup);