forked from tenstorrent/tt-kmd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.h
More file actions
97 lines (77 loc) · 3.17 KB
/
Copy pathdevice.h
File metadata and controls
97 lines (77 loc) · 3.17 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
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
// SPDX-License-Identifier: GPL-2.0-only
#ifndef TTDRIVER_DEVICE_H_INCLUDED
#define TTDRIVER_DEVICE_H_INCLUDED
#include <linux/types.h>
#include <linux/device.h>
#include <linux/pci.h>
#include <linux/cdev.h>
#include <linux/reboot.h>
#include <linux/kref.h>
#include <linux/rwsem.h>
#include <linux/wait.h>
#include "ioctl.h"
#include "hwmon.h"
#include "memory.h"
#define MAX_TLB_KINDS 4
struct tenstorrent_device_class;
struct tenstorrent_device {
struct kref kref;
struct device dev;
struct cdev chardev;
struct pci_dev *pdev;
const struct tenstorrent_device_class *dev_class;
bool detached; // No longer valid for hardware access
bool needs_hw_init;
atomic_long_t reset_gen; // Generation counter, incremented on reset
struct rw_semaphore reset_rwsem;
struct dentry *debugfs_root;
struct proc_dir_entry *procfs_root;
unsigned int ordinal;
bool dma_capable;
bool interrupt_enabled;
struct mutex chardev_mutex;
unsigned int chardev_open_count;
struct notifier_block reboot_notifier;
DECLARE_BITMAP(resource_lock, TENSTORRENT_RESOURCE_LOCK_COUNT);
wait_queue_head_t resource_lock_waitqueue;
struct tt_hwmon_context hwmon_context;
struct device *hwmon_dev;
struct list_head open_fds_list; // List of struct chardev_private, linked through open_fds field
DECLARE_BITMAP(tlbs, TENSTORRENT_MAX_INBOUND_TLBS);
u32 tlb_counts[MAX_TLB_KINDS]; // Per-device TLB counts (may differ from dev_class defaults)
struct mutex iatu_mutex;
struct tenstorrent_outbound_iatu_region outbound_iatus[TENSTORRENT_MAX_OUTBOUND_IATU_REGIONS];
struct attribute **telemetry_attrs;
struct attribute_group telemetry_group;
};
struct tlb_descriptor;
struct tenstorrent_device_class {
const char *name;
u32 instance_size;
u32 dma_address_bits;
u64 noc_dma_limit;
u64 noc_pcie_offset;
u32 tlb_kinds;
u32 tlb_counts[MAX_TLB_KINDS];
u64 tlb_sizes[MAX_TLB_KINDS];
bool (*reset)(struct tenstorrent_device *ttdev, u32 reset_flag);
bool (*init_device)(struct tenstorrent_device *ttdev);
bool (*init_hardware)(struct tenstorrent_device *ttdev);
bool (*init_telemetry)(struct tenstorrent_device *ttdev);
void (*cleanup_telemetry)(struct tenstorrent_device *ttdev);
void (*cleanup_hardware)(struct tenstorrent_device *ttdev);
void (*cleanup_device)(struct tenstorrent_device *ttdev);
void (*first_open_cb)(struct tenstorrent_device *ttdev);
void (*last_release_cb)(struct tenstorrent_device *ttdev);
void (*reboot)(struct tenstorrent_device *ttdev);
int (*configure_tlb)(struct tenstorrent_device *ttdev, int tlb, struct tenstorrent_noc_tlb_config *config);
int (*describe_tlb)(struct tenstorrent_device *ttdev, int tlb, struct tlb_descriptor *tlb_desc);
void (*save_reset_state)(struct tenstorrent_device *ttdev);
void (*restore_reset_state)(struct tenstorrent_device *ttdev);
int (*configure_outbound_atu)(struct tenstorrent_device *ttdev, u32 region, u64 base, u64 limit, u64 target);
void (*noc_write32)(struct tenstorrent_device *ttdev, u32 x, u32 y, u64 addr, u32 data, int noc);
int (*set_power_state)(struct tenstorrent_device *ttdev, struct tenstorrent_power_state *power_state);
};
void tenstorrent_device_put(struct tenstorrent_device *);
#endif