aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu.h')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h153
1 files changed, 107 insertions, 46 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index baefa635169a..2fc58e658986 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -42,17 +42,19 @@
42#include <ttm/ttm_module.h> 42#include <ttm/ttm_module.h>
43#include <ttm/ttm_execbuf_util.h> 43#include <ttm/ttm_execbuf_util.h>
44 44
45#include <drm/drmP.h>
45#include <drm/drm_gem.h> 46#include <drm/drm_gem.h>
46#include <drm/amdgpu_drm.h> 47#include <drm/amdgpu_drm.h>
47 48
48#include "amd_shared.h" 49#include "amd_shared.h"
49#include "amdgpu_family.h"
50#include "amdgpu_mode.h" 50#include "amdgpu_mode.h"
51#include "amdgpu_ih.h" 51#include "amdgpu_ih.h"
52#include "amdgpu_irq.h" 52#include "amdgpu_irq.h"
53#include "amdgpu_ucode.h" 53#include "amdgpu_ucode.h"
54#include "amdgpu_gds.h" 54#include "amdgpu_gds.h"
55 55
56#include "gpu_scheduler.h"
57
56/* 58/*
57 * Modules parameters. 59 * Modules parameters.
58 */ 60 */
@@ -77,7 +79,11 @@ extern int amdgpu_bapm;
77extern int amdgpu_deep_color; 79extern int amdgpu_deep_color;
78extern int amdgpu_vm_size; 80extern int amdgpu_vm_size;
79extern int amdgpu_vm_block_size; 81extern int amdgpu_vm_block_size;
82extern int amdgpu_enable_scheduler;
83extern int amdgpu_sched_jobs;
84extern int amdgpu_sched_hw_submission;
80 85
86#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
81#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */ 87#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
82#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) 88#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
83/* AMDGPU_IB_POOL_SIZE must be a power of 2 */ 89/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
@@ -178,6 +184,7 @@ struct amdgpu_ring;
178struct amdgpu_semaphore; 184struct amdgpu_semaphore;
179struct amdgpu_cs_parser; 185struct amdgpu_cs_parser;
180struct amdgpu_irq_src; 186struct amdgpu_irq_src;
187struct amdgpu_fpriv;
181 188
182enum amdgpu_cp_irq { 189enum amdgpu_cp_irq {
183 AMDGPU_CP_IRQ_GFX_EOP = 0, 190 AMDGPU_CP_IRQ_GFX_EOP = 0,
@@ -381,10 +388,10 @@ struct amdgpu_fence_driver {
381 uint64_t sync_seq[AMDGPU_MAX_RINGS]; 388 uint64_t sync_seq[AMDGPU_MAX_RINGS];
382 atomic64_t last_seq; 389 atomic64_t last_seq;
383 bool initialized; 390 bool initialized;
384 bool delayed_irq;
385 struct amdgpu_irq_src *irq_src; 391 struct amdgpu_irq_src *irq_src;
386 unsigned irq_type; 392 unsigned irq_type;
387 struct delayed_work lockup_work; 393 struct delayed_work lockup_work;
394 wait_queue_head_t fence_queue;
388}; 395};
389 396
390/* some special values for the owner field */ 397/* some special values for the owner field */
@@ -423,20 +430,18 @@ void amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
423int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, 430int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
424 struct amdgpu_irq_src *irq_src, 431 struct amdgpu_irq_src *irq_src,
425 unsigned irq_type); 432 unsigned irq_type);
433void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
434void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
426int amdgpu_fence_emit(struct amdgpu_ring *ring, void *owner, 435int amdgpu_fence_emit(struct amdgpu_ring *ring, void *owner,
427 struct amdgpu_fence **fence); 436 struct amdgpu_fence **fence);
428int amdgpu_fence_recreate(struct amdgpu_ring *ring, void *owner,
429 uint64_t seq, struct amdgpu_fence **fence);
430void amdgpu_fence_process(struct amdgpu_ring *ring); 437void amdgpu_fence_process(struct amdgpu_ring *ring);
431int amdgpu_fence_wait_next(struct amdgpu_ring *ring); 438int amdgpu_fence_wait_next(struct amdgpu_ring *ring);
432int amdgpu_fence_wait_empty(struct amdgpu_ring *ring); 439int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
433unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring); 440unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
434 441
435bool amdgpu_fence_signaled(struct amdgpu_fence *fence); 442signed long amdgpu_fence_wait_any(struct amdgpu_device *adev,
436int amdgpu_fence_wait(struct amdgpu_fence *fence, bool interruptible);
437int amdgpu_fence_wait_any(struct amdgpu_device *adev,
438 struct amdgpu_fence **fences, 443 struct amdgpu_fence **fences,
439 bool intr); 444 bool intr, long t);
440struct amdgpu_fence *amdgpu_fence_ref(struct amdgpu_fence *fence); 445struct amdgpu_fence *amdgpu_fence_ref(struct amdgpu_fence *fence);
441void amdgpu_fence_unref(struct amdgpu_fence **fence); 446void amdgpu_fence_unref(struct amdgpu_fence **fence);
442 447
@@ -481,7 +486,7 @@ static inline bool amdgpu_fence_is_earlier(struct amdgpu_fence *a,
481 return a->seq < b->seq; 486 return a->seq < b->seq;
482} 487}
483 488
484int amdgpu_user_fence_emit(struct amdgpu_ring *ring, struct amdgpu_user_fence *user, 489int amdgpu_user_fence_emit(struct amdgpu_ring *ring, struct amdgpu_user_fence *user,
485 void *owner, struct amdgpu_fence **fence); 490 void *owner, struct amdgpu_fence **fence);
486 491
487/* 492/*
@@ -532,14 +537,16 @@ struct amdgpu_bo_va_mapping {
532struct amdgpu_bo_va { 537struct amdgpu_bo_va {
533 /* protected by bo being reserved */ 538 /* protected by bo being reserved */
534 struct list_head bo_list; 539 struct list_head bo_list;
535 uint64_t addr; 540 struct fence *last_pt_update;
536 struct amdgpu_fence *last_pt_update;
537 unsigned ref_count; 541 unsigned ref_count;
538 542
539 /* protected by vm mutex */ 543 /* protected by vm mutex and spinlock */
540 struct list_head mappings;
541 struct list_head vm_status; 544 struct list_head vm_status;
542 545
546 /* mappings for this bo_va */
547 struct list_head invalids;
548 struct list_head valids;
549
543 /* constant after initialization */ 550 /* constant after initialization */
544 struct amdgpu_vm *vm; 551 struct amdgpu_vm *vm;
545 struct amdgpu_bo *bo; 552 struct amdgpu_bo *bo;
@@ -697,8 +704,8 @@ struct amdgpu_sync {
697}; 704};
698 705
699void amdgpu_sync_create(struct amdgpu_sync *sync); 706void amdgpu_sync_create(struct amdgpu_sync *sync);
700void amdgpu_sync_fence(struct amdgpu_sync *sync, 707int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
701 struct amdgpu_fence *fence); 708 struct fence *f);
702int amdgpu_sync_resv(struct amdgpu_device *adev, 709int amdgpu_sync_resv(struct amdgpu_device *adev,
703 struct amdgpu_sync *sync, 710 struct amdgpu_sync *sync,
704 struct reservation_object *resv, 711 struct reservation_object *resv,
@@ -821,7 +828,9 @@ struct amdgpu_flip_work {
821 uint64_t base; 828 uint64_t base;
822 struct drm_pending_vblank_event *event; 829 struct drm_pending_vblank_event *event;
823 struct amdgpu_bo *old_rbo; 830 struct amdgpu_bo *old_rbo;
824 struct fence *fence; 831 struct fence *excl;
832 unsigned shared_count;
833 struct fence **shared;
825}; 834};
826 835
827 836
@@ -844,6 +853,8 @@ struct amdgpu_ib {
844 uint32_t gws_base, gws_size; 853 uint32_t gws_base, gws_size;
845 uint32_t oa_base, oa_size; 854 uint32_t oa_base, oa_size;
846 uint32_t flags; 855 uint32_t flags;
856 /* resulting sequence number */
857 uint64_t sequence;
847}; 858};
848 859
849enum amdgpu_ring_type { 860enum amdgpu_ring_type {
@@ -854,11 +865,23 @@ enum amdgpu_ring_type {
854 AMDGPU_RING_TYPE_VCE 865 AMDGPU_RING_TYPE_VCE
855}; 866};
856 867
868extern struct amd_sched_backend_ops amdgpu_sched_ops;
869
870int amdgpu_sched_ib_submit_kernel_helper(struct amdgpu_device *adev,
871 struct amdgpu_ring *ring,
872 struct amdgpu_ib *ibs,
873 unsigned num_ibs,
874 int (*free_job)(struct amdgpu_cs_parser *),
875 void *owner,
876 struct fence **fence);
877
857struct amdgpu_ring { 878struct amdgpu_ring {
858 struct amdgpu_device *adev; 879 struct amdgpu_device *adev;
859 const struct amdgpu_ring_funcs *funcs; 880 const struct amdgpu_ring_funcs *funcs;
860 struct amdgpu_fence_driver fence_drv; 881 struct amdgpu_fence_driver fence_drv;
882 struct amd_gpu_scheduler *scheduler;
861 883
884 spinlock_t fence_lock;
862 struct mutex *ring_lock; 885 struct mutex *ring_lock;
863 struct amdgpu_bo *ring_obj; 886 struct amdgpu_bo *ring_obj;
864 volatile uint32_t *ring; 887 volatile uint32_t *ring;
@@ -892,6 +915,7 @@ struct amdgpu_ring {
892 struct amdgpu_ctx *current_ctx; 915 struct amdgpu_ctx *current_ctx;
893 enum amdgpu_ring_type type; 916 enum amdgpu_ring_type type;
894 char name[16]; 917 char name[16];
918 bool is_pte_ring;
895}; 919};
896 920
897/* 921/*
@@ -943,18 +967,22 @@ struct amdgpu_vm {
943 967
944 struct rb_root va; 968 struct rb_root va;
945 969
946 /* protecting invalidated and freed */ 970 /* protecting invalidated */
947 spinlock_t status_lock; 971 spinlock_t status_lock;
948 972
949 /* BOs moved, but not yet updated in the PT */ 973 /* BOs moved, but not yet updated in the PT */
950 struct list_head invalidated; 974 struct list_head invalidated;
951 975
952 /* BOs freed, but not yet updated in the PT */ 976 /* BOs cleared in the PT because of a move */
977 struct list_head cleared;
978
979 /* BO mappings freed, but not yet updated in the PT */
953 struct list_head freed; 980 struct list_head freed;
954 981
955 /* contains the page directory */ 982 /* contains the page directory */
956 struct amdgpu_bo *page_directory; 983 struct amdgpu_bo *page_directory;
957 unsigned max_pde_used; 984 unsigned max_pde_used;
985 struct fence *page_directory_fence;
958 986
959 /* array of page tables, one for each page directory entry */ 987 /* array of page tables, one for each page directory entry */
960 struct amdgpu_vm_pt *page_tables; 988 struct amdgpu_vm_pt *page_tables;
@@ -983,27 +1011,47 @@ struct amdgpu_vm_manager {
983 * context related structures 1011 * context related structures
984 */ 1012 */
985 1013
986struct amdgpu_ctx_state { 1014#define AMDGPU_CTX_MAX_CS_PENDING 16
987 uint64_t flags; 1015
988 uint32_t hangs; 1016struct amdgpu_ctx_ring {
1017 uint64_t sequence;
1018 struct fence *fences[AMDGPU_CTX_MAX_CS_PENDING];
1019 struct amd_sched_entity entity;
989}; 1020};
990 1021
991struct amdgpu_ctx { 1022struct amdgpu_ctx {
992 /* call kref_get()before CS start and kref_put() after CS fence signaled */ 1023 struct kref refcount;
993 struct kref refcount; 1024 struct amdgpu_device *adev;
994 struct amdgpu_fpriv *fpriv; 1025 unsigned reset_counter;
995 struct amdgpu_ctx_state state; 1026 spinlock_t ring_lock;
996 uint32_t id; 1027 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
997 unsigned reset_counter;
998}; 1028};
999 1029
1000struct amdgpu_ctx_mgr { 1030struct amdgpu_ctx_mgr {
1001 struct amdgpu_device *adev; 1031 struct amdgpu_device *adev;
1002 struct idr ctx_handles; 1032 struct mutex lock;
1003 /* lock for IDR system */ 1033 /* protected by lock */
1004 struct mutex lock; 1034 struct idr ctx_handles;
1005}; 1035};
1006 1036
1037int amdgpu_ctx_init(struct amdgpu_device *adev, bool kernel,
1038 struct amdgpu_ctx *ctx);
1039void amdgpu_ctx_fini(struct amdgpu_ctx *ctx);
1040
1041struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
1042int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
1043
1044uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
1045 struct fence *fence, uint64_t queued_seq);
1046struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
1047 struct amdgpu_ring *ring, uint64_t seq);
1048
1049int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1050 struct drm_file *filp);
1051
1052void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
1053void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
1054
1007/* 1055/*
1008 * file private structure 1056 * file private structure
1009 */ 1057 */
@@ -1012,7 +1060,7 @@ struct amdgpu_fpriv {
1012 struct amdgpu_vm vm; 1060 struct amdgpu_vm vm;
1013 struct mutex bo_list_lock; 1061 struct mutex bo_list_lock;
1014 struct idr bo_list_handles; 1062 struct idr bo_list_handles;
1015 struct amdgpu_ctx_mgr ctx_mgr; 1063 struct amdgpu_ctx_mgr ctx_mgr;
1016}; 1064};
1017 1065
1018/* 1066/*
@@ -1030,6 +1078,8 @@ struct amdgpu_bo_list {
1030}; 1078};
1031 1079
1032struct amdgpu_bo_list * 1080struct amdgpu_bo_list *
1081amdgpu_bo_list_clone(struct amdgpu_bo_list *list);
1082struct amdgpu_bo_list *
1033amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id); 1083amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
1034void amdgpu_bo_list_put(struct amdgpu_bo_list *list); 1084void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1035void amdgpu_bo_list_free(struct amdgpu_bo_list *list); 1085void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
@@ -1205,6 +1255,14 @@ struct amdgpu_cs_parser {
1205 1255
1206 /* user fence */ 1256 /* user fence */
1207 struct amdgpu_user_fence uf; 1257 struct amdgpu_user_fence uf;
1258
1259 struct amdgpu_ring *ring;
1260 struct mutex job_lock;
1261 struct work_struct job_work;
1262 int (*prepare_job)(struct amdgpu_cs_parser *sched_job);
1263 int (*run_job)(struct amdgpu_cs_parser *sched_job);
1264 int (*free_job)(struct amdgpu_cs_parser *sched_job);
1265 struct amd_sched_fence *s_fence;
1208}; 1266};
1209 1267
1210static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, uint32_t ib_idx, int idx) 1268static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p, uint32_t ib_idx, int idx)
@@ -1849,17 +1907,12 @@ struct amdgpu_atcs {
1849 struct amdgpu_atcs_functions functions; 1907 struct amdgpu_atcs_functions functions;
1850}; 1908};
1851 1909
1852int amdgpu_ctx_alloc(struct amdgpu_device *adev,struct amdgpu_fpriv *fpriv, 1910/*
1853 uint32_t *id,uint32_t flags); 1911 * CGS
1854int amdgpu_ctx_free(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv, 1912 */
1855 uint32_t id); 1913void *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1856 1914void amdgpu_cgs_destroy_device(void *cgs_device);
1857void amdgpu_ctx_fini(struct amdgpu_fpriv *fpriv);
1858struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
1859int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
1860 1915
1861extern int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
1862 struct drm_file *filp);
1863 1916
1864/* 1917/*
1865 * Core structure, functions and helpers. 1918 * Core structure, functions and helpers.
@@ -1883,7 +1936,7 @@ struct amdgpu_device {
1883 struct rw_semaphore exclusive_lock; 1936 struct rw_semaphore exclusive_lock;
1884 1937
1885 /* ASIC */ 1938 /* ASIC */
1886 enum amdgpu_asic_type asic_type; 1939 enum amd_asic_type asic_type;
1887 uint32_t family; 1940 uint32_t family;
1888 uint32_t rev_id; 1941 uint32_t rev_id;
1889 uint32_t external_rev_id; 1942 uint32_t external_rev_id;
@@ -1976,7 +2029,6 @@ struct amdgpu_device {
1976 struct amdgpu_irq_src hpd_irq; 2029 struct amdgpu_irq_src hpd_irq;
1977 2030
1978 /* rings */ 2031 /* rings */
1979 wait_queue_head_t fence_queue;
1980 unsigned fence_context; 2032 unsigned fence_context;
1981 struct mutex ring_lock; 2033 struct mutex ring_lock;
1982 unsigned num_rings; 2034 unsigned num_rings;
@@ -2028,6 +2080,9 @@ struct amdgpu_device {
2028 2080
2029 /* amdkfd interface */ 2081 /* amdkfd interface */
2030 struct kfd_dev *kfd; 2082 struct kfd_dev *kfd;
2083
2084 /* kernel conext for IB submission */
2085 struct amdgpu_ctx kernel_ctx;
2031}; 2086};
2032 2087
2033bool amdgpu_device_is_px(struct drm_device *dev); 2088bool amdgpu_device_is_px(struct drm_device *dev);
@@ -2215,6 +2270,12 @@ void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2215bool amdgpu_card_posted(struct amdgpu_device *adev); 2270bool amdgpu_card_posted(struct amdgpu_device *adev);
2216void amdgpu_update_display_priority(struct amdgpu_device *adev); 2271void amdgpu_update_display_priority(struct amdgpu_device *adev);
2217bool amdgpu_boot_test_post_card(struct amdgpu_device *adev); 2272bool amdgpu_boot_test_post_card(struct amdgpu_device *adev);
2273struct amdgpu_cs_parser *amdgpu_cs_parser_create(struct amdgpu_device *adev,
2274 struct drm_file *filp,
2275 struct amdgpu_ctx *ctx,
2276 struct amdgpu_ib *ibs,
2277 uint32_t num_ibs);
2278
2218int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data); 2279int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2219int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type, 2280int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2220 u32 ip_instance, u32 ring, 2281 u32 ip_instance, u32 ring,
@@ -2278,8 +2339,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
2278struct amdgpu_bo_list_entry *amdgpu_vm_get_bos(struct amdgpu_device *adev, 2339struct amdgpu_bo_list_entry *amdgpu_vm_get_bos(struct amdgpu_device *adev,
2279 struct amdgpu_vm *vm, 2340 struct amdgpu_vm *vm,
2280 struct list_head *head); 2341 struct list_head *head);
2281struct amdgpu_fence *amdgpu_vm_grab_id(struct amdgpu_ring *ring, 2342int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
2282 struct amdgpu_vm *vm); 2343 struct amdgpu_sync *sync);
2283void amdgpu_vm_flush(struct amdgpu_ring *ring, 2344void amdgpu_vm_flush(struct amdgpu_ring *ring,
2284 struct amdgpu_vm *vm, 2345 struct amdgpu_vm *vm,
2285 struct amdgpu_fence *updates); 2346 struct amdgpu_fence *updates);