Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/drivers/accel/amdxdna/amdxdna_pci_drv.h
26427 views
1
/* SPDX-License-Identifier: GPL-2.0 */
2
/*
3
* Copyright (C) 2022-2024, Advanced Micro Devices, Inc.
4
*/
5
6
#ifndef _AMDXDNA_PCI_DRV_H_
7
#define _AMDXDNA_PCI_DRV_H_
8
9
#include <linux/workqueue.h>
10
#include <linux/xarray.h>
11
12
#define XDNA_INFO(xdna, fmt, args...) drm_info(&(xdna)->ddev, fmt, ##args)
13
#define XDNA_WARN(xdna, fmt, args...) drm_warn(&(xdna)->ddev, "%s: "fmt, __func__, ##args)
14
#define XDNA_ERR(xdna, fmt, args...) drm_err(&(xdna)->ddev, "%s: "fmt, __func__, ##args)
15
#define XDNA_DBG(xdna, fmt, args...) drm_dbg(&(xdna)->ddev, fmt, ##args)
16
#define XDNA_INFO_ONCE(xdna, fmt, args...) drm_info_once(&(xdna)->ddev, fmt, ##args)
17
18
#define XDNA_MBZ_DBG(xdna, ptr, sz) \
19
({ \
20
int __i; \
21
int __ret = 0; \
22
u8 *__ptr = (u8 *)(ptr); \
23
for (__i = 0; __i < (sz); __i++) { \
24
if (__ptr[__i]) { \
25
XDNA_DBG(xdna, "MBZ check failed"); \
26
__ret = -EINVAL; \
27
break; \
28
} \
29
} \
30
__ret; \
31
})
32
33
#define to_xdna_dev(drm_dev) \
34
((struct amdxdna_dev *)container_of(drm_dev, struct amdxdna_dev, ddev))
35
36
extern const struct drm_driver amdxdna_drm_drv;
37
38
struct amdxdna_client;
39
struct amdxdna_dev;
40
struct amdxdna_drm_get_info;
41
struct amdxdna_drm_set_state;
42
struct amdxdna_gem_obj;
43
struct amdxdna_hwctx;
44
struct amdxdna_sched_job;
45
46
/*
47
* struct amdxdna_dev_ops - Device hardware operation callbacks
48
*/
49
struct amdxdna_dev_ops {
50
int (*init)(struct amdxdna_dev *xdna);
51
void (*fini)(struct amdxdna_dev *xdna);
52
int (*resume)(struct amdxdna_dev *xdna);
53
void (*suspend)(struct amdxdna_dev *xdna);
54
int (*hwctx_init)(struct amdxdna_hwctx *hwctx);
55
void (*hwctx_fini)(struct amdxdna_hwctx *hwctx);
56
int (*hwctx_config)(struct amdxdna_hwctx *hwctx, u32 type, u64 value, void *buf, u32 size);
57
void (*hmm_invalidate)(struct amdxdna_gem_obj *abo, unsigned long cur_seq);
58
void (*hwctx_suspend)(struct amdxdna_hwctx *hwctx);
59
void (*hwctx_resume)(struct amdxdna_hwctx *hwctx);
60
int (*cmd_submit)(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *job, u64 *seq);
61
int (*get_aie_info)(struct amdxdna_client *client, struct amdxdna_drm_get_info *args);
62
int (*set_aie_state)(struct amdxdna_client *client, struct amdxdna_drm_set_state *args);
63
};
64
65
/*
66
* struct amdxdna_dev_info - Device hardware information
67
* Record device static information, like reg, mbox, PSP, SMU bar index
68
*/
69
struct amdxdna_dev_info {
70
int reg_bar;
71
int mbox_bar;
72
int sram_bar;
73
int psp_bar;
74
int smu_bar;
75
int device_type;
76
int first_col;
77
u32 dev_mem_buf_shift;
78
u64 dev_mem_base;
79
size_t dev_mem_size;
80
char *vbnv;
81
const struct amdxdna_dev_priv *dev_priv;
82
const struct amdxdna_dev_ops *ops;
83
};
84
85
struct amdxdna_fw_ver {
86
u32 major;
87
u32 minor;
88
u32 sub;
89
u32 build;
90
};
91
92
struct amdxdna_dev {
93
struct drm_device ddev;
94
struct amdxdna_dev_hdl *dev_handle;
95
const struct amdxdna_dev_info *dev_info;
96
void *xrs_hdl;
97
98
struct mutex dev_lock; /* per device lock */
99
struct list_head client_list;
100
struct amdxdna_fw_ver fw_ver;
101
struct rw_semaphore notifier_lock; /* for mmu notifier*/
102
struct workqueue_struct *notifier_wq;
103
};
104
105
/*
106
* struct amdxdna_device_id - PCI device info
107
*/
108
struct amdxdna_device_id {
109
unsigned short device;
110
u8 revision;
111
const struct amdxdna_dev_info *dev_info;
112
};
113
114
/*
115
* struct amdxdna_client - amdxdna client
116
* A per fd data structure for managing context and other user process stuffs.
117
*/
118
struct amdxdna_client {
119
struct list_head node;
120
pid_t pid;
121
struct mutex hwctx_lock; /* protect hwctx */
122
/* do NOT wait this srcu when hwctx_lock is held */
123
struct srcu_struct hwctx_srcu;
124
struct xarray hwctx_xa;
125
u32 next_hwctxid;
126
struct amdxdna_dev *xdna;
127
struct drm_file *filp;
128
129
struct mutex mm_lock; /* protect memory related */
130
struct amdxdna_gem_obj *dev_heap;
131
132
struct iommu_sva *sva;
133
int pasid;
134
};
135
136
#define amdxdna_for_each_hwctx(client, hwctx_id, entry) \
137
xa_for_each(&(client)->hwctx_xa, hwctx_id, entry)
138
139
/* Add device info below */
140
extern const struct amdxdna_dev_info dev_npu1_info;
141
extern const struct amdxdna_dev_info dev_npu2_info;
142
extern const struct amdxdna_dev_info dev_npu4_info;
143
extern const struct amdxdna_dev_info dev_npu5_info;
144
extern const struct amdxdna_dev_info dev_npu6_info;
145
146
int amdxdna_sysfs_init(struct amdxdna_dev *xdna);
147
void amdxdna_sysfs_fini(struct amdxdna_dev *xdna);
148
149
#endif /* _AMDXDNA_PCI_DRV_H_ */
150
151