2 * Copyright 2022 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include <linux/xarray.h>
31 #define AMDGPU_XCP_MODE_NONE -1
32 #define AMDGPU_XCP_MODE_TRANS -2
34 #define AMDGPU_XCP_FL_NONE 0
35 #define AMDGPU_XCP_FL_LOCKED (1 << 0)
37 enum AMDGPU_XCP_IP_BLOCK {
45 enum AMDGPU_XCP_STATE {
46 AMDGPU_XCP_PREPARE_SUSPEND,
48 AMDGPU_XCP_PREPARE_RESUME,
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);
59 struct amdgpu_xcp_ip {
60 struct amdgpu_xcp_ip_funcs *ip_funcs;
63 enum AMDGPU_XCP_IP_BLOCK ip_id;
68 struct amdgpu_xcp_ip ip[AMDGPU_XCP_MAX_BLOCKS];
75 struct amdgpu_xcp_mgr {
76 struct amdgpu_device *adev;
77 struct mutex xcp_lock;
78 struct amdgpu_xcp_mgr_funcs *funcs;
80 struct amdgpu_xcp xcp[MAX_XCP];
85 struct amdgpu_xcp_mgr_funcs {
86 int (*switch_partition_mode)(struct amdgpu_xcp_mgr *xcp_mgr, int mode,
88 int (*query_partition_mode)(struct amdgpu_xcp_mgr *xcp_mgr);
89 int (*get_ip_details)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id,
90 enum AMDGPU_XCP_IP_BLOCK ip_id,
91 struct amdgpu_xcp_ip *ip);
93 int (*prepare_suspend)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
94 int (*suspend)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
95 int (*prepare_resume)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
96 int (*resume)(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
99 int amdgpu_xcp_prepare_suspend(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
100 int amdgpu_xcp_suspend(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
101 int amdgpu_xcp_prepare_resume(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
102 int amdgpu_xcp_resume(struct amdgpu_xcp_mgr *xcp_mgr, int xcp_id);
104 int amdgpu_xcp_mgr_init(struct amdgpu_device *adev, int init_mode,
105 int init_xcps, struct amdgpu_xcp_mgr_funcs *xcp_funcs);
106 int amdgpu_xcp_query_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, u32 flags);
107 int amdgpu_xcp_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, int mode);
108 int amdgpu_xcp_get_partition(struct amdgpu_xcp_mgr *xcp_mgr,
109 enum AMDGPU_XCP_IP_BLOCK ip, int instance);
111 int amdgpu_xcp_get_inst_details(struct amdgpu_xcp *xcp,
112 enum AMDGPU_XCP_IP_BLOCK ip,
113 uint32_t *inst_mask);
115 static inline int amdgpu_xcp_get_num_xcp(struct amdgpu_xcp_mgr *xcp_mgr)
120 return xcp_mgr->num_xcps;
123 static inline struct amdgpu_xcp *
124 amdgpu_get_next_xcp(struct amdgpu_xcp_mgr *xcp_mgr, int *from)
129 while (*from < MAX_XCP) {
130 if (xcp_mgr->xcp[*from].valid)
131 return &xcp_mgr->xcp[*from];
138 #define for_each_xcp(xcp_mgr, xcp, i) \
139 for (i = 0, xcp = amdgpu_get_next_xcp(xcp_mgr, &i); xcp; \
140 xcp = amdgpu_get_next_xcp(xcp_mgr, &i))