1ceeb50edSMonk Liu /*
2ceeb50edSMonk Liu  * Copyright 2016 Advanced Micro Devices, Inc.
3ceeb50edSMonk Liu  *
4ceeb50edSMonk Liu  * Permission is hereby granted, free of charge, to any person obtaining a
5ceeb50edSMonk Liu  * copy of this software and associated documentation files (the "Software"),
6ceeb50edSMonk Liu  * to deal in the Software without restriction, including without limitation
7ceeb50edSMonk Liu  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8ceeb50edSMonk Liu  * and/or sell copies of the Software, and to permit persons to whom the
9ceeb50edSMonk Liu  * Software is furnished to do so, subject to the following conditions:
10ceeb50edSMonk Liu  *
11ceeb50edSMonk Liu  * The above copyright notice and this permission notice shall be included in
12ceeb50edSMonk Liu  * all copies or substantial portions of the Software.
13ceeb50edSMonk Liu  *
14ceeb50edSMonk Liu  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15ceeb50edSMonk Liu  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16ceeb50edSMonk Liu  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17ceeb50edSMonk Liu  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18ceeb50edSMonk Liu  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ceeb50edSMonk Liu  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20ceeb50edSMonk Liu  * OTHER DEALINGS IN THE SOFTWARE.
21ceeb50edSMonk Liu  *
22ceeb50edSMonk Liu  * Author: Monk.liu@amd.com
23ceeb50edSMonk Liu  */
24ceeb50edSMonk Liu #ifndef AMDGPU_VIRT_H
25ceeb50edSMonk Liu #define AMDGPU_VIRT_H
26ceeb50edSMonk Liu 
27ceeb50edSMonk Liu #define AMDGPU_SRIOV_CAPS_SRIOV_VBIOS  (1 << 0) /* vBIOS is sr-iov ready */
28ceeb50edSMonk Liu #define AMDGPU_SRIOV_CAPS_ENABLE_IOV   (1 << 1) /* sr-iov is enabled on this GPU */
29ceeb50edSMonk Liu #define AMDGPU_SRIOV_CAPS_IS_VF        (1 << 2) /* this GPU is a virtual function */
30ceeb50edSMonk Liu #define AMDGPU_PASSTHROUGH_MODE        (1 << 3) /* thw whole GPU is pass through for VM */
31bd7de27dSMonk Liu 
32ceeb50edSMonk Liu /* GPU virtualization */
335a5099cbSXiangliang Yu struct amdgpu_virt {
345a5099cbSXiangliang Yu 	uint32_t caps;
35bd7de27dSMonk Liu 	struct amdgpu_bo *csa_obj;
36bd7de27dSMonk Liu 	uint64_t csa_vmid0_addr;
37880e87e3SXiangliang Yu 	uint32_t		reg_val_offs;
38ceeb50edSMonk Liu };
39ceeb50edSMonk Liu 
40bd7de27dSMonk Liu #define AMDGPU_CSA_SIZE    (8 * 1024)
41bd7de27dSMonk Liu #define AMDGPU_CSA_VADDR   (AMDGPU_VA_RESERVED_SIZE - AMDGPU_CSA_SIZE)
42bd7de27dSMonk Liu 
43ceeb50edSMonk Liu #define amdgpu_sriov_enabled(adev) \
445a5099cbSXiangliang Yu ((adev)->virt.caps & AMDGPU_SRIOV_CAPS_ENABLE_IOV)
45ceeb50edSMonk Liu 
46ceeb50edSMonk Liu #define amdgpu_sriov_vf(adev) \
475a5099cbSXiangliang Yu ((adev)->virt.caps & AMDGPU_SRIOV_CAPS_IS_VF)
48ceeb50edSMonk Liu 
49ceeb50edSMonk Liu #define amdgpu_sriov_bios(adev) \
505a5099cbSXiangliang Yu ((adev)->virt.caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS)
51ceeb50edSMonk Liu 
52ceeb50edSMonk Liu #define amdgpu_passthrough(adev) \
535a5099cbSXiangliang Yu ((adev)->virt.caps & AMDGPU_PASSTHROUGH_MODE)
54ceeb50edSMonk Liu 
55ceeb50edSMonk Liu static inline bool is_virtual_machine(void)
56ceeb50edSMonk Liu {
57ceeb50edSMonk Liu #ifdef CONFIG_X86
58ceeb50edSMonk Liu 	return boot_cpu_has(X86_FEATURE_HYPERVISOR);
59ceeb50edSMonk Liu #else
60ceeb50edSMonk Liu 	return false;
61ceeb50edSMonk Liu #endif
62ceeb50edSMonk Liu }
63ceeb50edSMonk Liu 
644e4bbe73SMonk Liu struct amdgpu_vm;
654e4bbe73SMonk Liu int amdgpu_allocate_static_csa(struct amdgpu_device *adev);
664e4bbe73SMonk Liu int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm);
674e4bbe73SMonk Liu 
68ceeb50edSMonk Liu #endif
69