]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h
drm/amdkfd: Store xcp partition id to amdgpu bo
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_xcp.h
1 /*
2  * Copyright 2022 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23
24 #ifndef AMDGPU_XCP_H
25 #define AMDGPU_XCP_H
26
27 #include <linux/xarray.h>
28
29 #define MAX_XCP 8
30
31 #define AMDGPU_XCP_MODE_NONE -1
32 #define AMDGPU_XCP_MODE_TRANS -2
33
34 #define AMDGPU_XCP_FL_NONE 0
35 #define AMDGPU_XCP_FL_LOCKED (1 << 0)
36
37 enum AMDGPU_XCP_IP_BLOCK {
38         AMDGPU_XCP_GFXHUB,
39         AMDGPU_XCP_GFX,
40         AMDGPU_XCP_SDMA,
41         AMDGPU_XCP_VCN,
42         AMDGPU_XCP_MAX_BLOCKS
43 };
44
45 enum AMDGPU_XCP_STATE {
46         AMDGPU_XCP_PREPARE_SUSPEND,
47         AMDGPU_XCP_SUSPEND,
48         AMDGPU_XCP_PREPARE_RESUME,
49         AMDGPU_XCP_RESUME,
50 };
51
52 struct amdgpu_xcp_ip_funcs {
53         int (*prepare_suspend)(void *handle, uint32_t inst_mask);
54         int (*suspend)(void *handle, uint32_t inst_mask);
55         int (*prepare_resume)(void *handle, uint32_t inst_mask);
56         int (*resume)(void *handle, uint32_t inst_mask);
57 };
58
59 struct amdgpu_xcp_ip {
60         struct amdgpu_xcp_ip_funcs *ip_funcs;
61         uint32_t inst_mask;
62
63         enum AMDGPU_XCP_IP_BLOCK ip_id;
64         bool valid;
65 };
66
67 struct amdgpu_xcp {
68         struct amdgpu_xcp_ip ip[AMDGPU_XCP_MAX_BLOCKS];
69
70         uint8_t id;
71         uint8_t mem_id;
72         bool valid;
73         atomic_t        ref_cnt;
74         struct drm_device *ddev;
75         struct amdgpu_sched     gpu_sched[AMDGPU_HW_IP_NUM][AMDGPU_RING_PRIO_MAX];
76 };
77
78 struct amdgpu_xcp_mgr {
79         struct amdgpu_device *adev;
80         struct mutex xcp_lock;
81         struct amdgpu_xcp_mgr_funcs *funcs;
82
83         struct amdgpu_xcp xcp[MAX_XCP];
84         uint8_t num_xcps;
85         int8_t mode;
86
87          /* Used to determine KFD memory size limits per XCP */
88         unsigned int num_xcp_per_mem_partition;
89 };
90
91 struct amdgpu_xcp_mgr_funcs {
92         int (*switch_partition_mode)(struct amdgpu_xcp_mgr *xcp_mgr, int mode,
93                                      int *num_xcps);
94         int (*query_partition_mode)(struct amdgpu_xcp_mgr *xcp_mgr);
95         int (*get_ip_details)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id,
96                               enum AMDGPU_XCP_IP_BLOCK ip_id,
97                               struct amdgpu_xcp_ip *ip);
98         int (*get_xcp_mem_id)(struct amdgpu_xcp_mgr *xcp_mgr,
99                               struct amdgpu_xcp *xcp, uint8_t *mem_id);
100
101         int (*prepare_suspend)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
102         int (*suspend)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
103         int (*prepare_resume)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
104         int (*resume)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
105         int (*select_scheds)(struct amdgpu_device *adev,
106                                   u32 hw_ip, u32 hw_prio, struct amdgpu_fpriv *fpriv,
107                                   unsigned int *num_scheds, struct drm_gpu_scheduler ***scheds);
108         int (*update_partition_sched_list)(struct amdgpu_device *adev);
109 };
110
111 int amdgpu_xcp_prepare_suspend(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
112 int amdgpu_xcp_suspend(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
113 int amdgpu_xcp_prepare_resume(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
114 int amdgpu_xcp_resume(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
115
116 int amdgpu_xcp_mgr_init(struct amdgpu_device *adev, int init_mode,
117                         int init_xcps, struct amdgpu_xcp_mgr_funcs *xcp_funcs);
118 int amdgpu_xcp_init(struct amdgpu_xcp_mgr *xcp_mgr, int num_xcps, int mode);
119 int amdgpu_xcp_query_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, u32 flags);
120 int amdgpu_xcp_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, int mode);
121 int amdgpu_xcp_get_partition(struct amdgpu_xcp_mgr *xcp_mgr,
122                              enum AMDGPU_XCP_IP_BLOCK ip, int instance);
123
124 int amdgpu_xcp_get_inst_details(struct amdgpu_xcp *xcp,
125                                 enum AMDGPU_XCP_IP_BLOCK ip,
126                                 uint32_t *inst_mask);
127
128 int amdgpu_xcp_dev_register(struct amdgpu_device *adev,
129                                 const struct pci_device_id *ent);
130 void amdgpu_xcp_dev_unplug(struct amdgpu_device *adev);
131 int amdgpu_xcp_open_device(struct amdgpu_device *adev,
132                            struct amdgpu_fpriv *fpriv,
133                            struct drm_file *file_priv);
134 void amdgpu_xcp_release_sched(struct amdgpu_device *adev,
135                               struct amdgpu_ctx_entity *entity);
136
137 #define amdgpu_xcp_select_scheds(adev, e, c, d, x, y) \
138         ((adev)->xcp_mgr && (adev)->xcp_mgr->funcs && \
139         (adev)->xcp_mgr->funcs->select_scheds ? \
140         (adev)->xcp_mgr->funcs->select_scheds((adev), (e), (c), (d), (x), (y)) : -ENOENT)
141 #define amdgpu_xcp_update_partition_sched_list(adev) \
142         ((adev)->xcp_mgr && (adev)->xcp_mgr->funcs && \
143         (adev)->xcp_mgr->funcs->update_partition_sched_list ? \
144         (adev)->xcp_mgr->funcs->update_partition_sched_list(adev) : 0)
145
146 static inline int amdgpu_xcp_get_num_xcp(struct amdgpu_xcp_mgr *xcp_mgr)
147 {
148         if (!xcp_mgr)
149                 return 1;
150         else
151                 return xcp_mgr->num_xcps;
152 }
153
154 static inline struct amdgpu_xcp *
155 amdgpu_get_next_xcp(struct amdgpu_xcp_mgr *xcp_mgr, int *from)
156 {
157         if (!xcp_mgr)
158                 return NULL;
159
160         while (*from < MAX_XCP) {
161                 if (xcp_mgr->xcp[*from].valid)
162                         return &xcp_mgr->xcp[*from];
163                 ++(*from);
164         }
165
166         return NULL;
167 }
168
169 #define for_each_xcp(xcp_mgr, xcp, i)                            \
170         for (i = 0, xcp = amdgpu_get_next_xcp(xcp_mgr, &i); xcp; \
171              xcp = amdgpu_get_next_xcp(xcp_mgr, &i))
172
173 #endif
This page took 0.044453 seconds and 4 git commands to generate.