1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2009 Corbin Simpson
3bf215546Sopenharmony_ci * Copyright © 2015 Advanced Micro Devices, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
7bf215546Sopenharmony_ci * a copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16bf215546Sopenharmony_ci * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17bf215546Sopenharmony_ci * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
18bf215546Sopenharmony_ci * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
24bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
25bf215546Sopenharmony_ci * of the Software.
26bf215546Sopenharmony_ci */
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#ifndef AMDGPU_WINSYS_H
29bf215546Sopenharmony_ci#define AMDGPU_WINSYS_H
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "pipebuffer/pb_cache.h"
32bf215546Sopenharmony_ci#include "pipebuffer/pb_slab.h"
33bf215546Sopenharmony_ci#include "winsys/radeon_winsys.h"
34bf215546Sopenharmony_ci#include "util/simple_mtx.h"
35bf215546Sopenharmony_ci#include "util/u_queue.h"
36bf215546Sopenharmony_ci#include <amdgpu.h>
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistruct amdgpu_cs;
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci#define NUM_SLAB_ALLOCATORS 3
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistruct amdgpu_screen_winsys {
43bf215546Sopenharmony_ci   struct radeon_winsys base;
44bf215546Sopenharmony_ci   struct amdgpu_winsys *aws;
45bf215546Sopenharmony_ci   int fd;
46bf215546Sopenharmony_ci   struct pipe_reference reference;
47bf215546Sopenharmony_ci   struct amdgpu_screen_winsys *next;
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   /* Maps a BO to its KMS handle valid for this DRM file descriptor
50bf215546Sopenharmony_ci    * Protected by amdgpu_winsys::sws_list_lock
51bf215546Sopenharmony_ci    */
52bf215546Sopenharmony_ci   struct hash_table *kms_handles;
53bf215546Sopenharmony_ci};
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_cistruct amdgpu_winsys {
56bf215546Sopenharmony_ci   struct pipe_reference reference;
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci   /* File descriptor which was passed to amdgpu_device_initialize */
59bf215546Sopenharmony_ci   int fd;
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   struct pb_cache bo_cache;
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci   /* Each slab buffer can only contain suballocations of equal sizes, so we
64bf215546Sopenharmony_ci    * need to layer the allocators, so that we don't waste too much memory.
65bf215546Sopenharmony_ci    */
66bf215546Sopenharmony_ci   struct pb_slabs bo_slabs[NUM_SLAB_ALLOCATORS];
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci   amdgpu_device_handle dev;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   simple_mtx_t bo_fence_lock;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   int num_cs; /* The number of command streams created. */
73bf215546Sopenharmony_ci   unsigned num_total_rejected_cs;
74bf215546Sopenharmony_ci   uint32_t surf_index_color;
75bf215546Sopenharmony_ci   uint32_t surf_index_fmask;
76bf215546Sopenharmony_ci   uint32_t next_bo_unique_id;
77bf215546Sopenharmony_ci   uint64_t allocated_vram;
78bf215546Sopenharmony_ci   uint64_t allocated_gtt;
79bf215546Sopenharmony_ci   uint64_t mapped_vram;
80bf215546Sopenharmony_ci   uint64_t mapped_gtt;
81bf215546Sopenharmony_ci   uint64_t slab_wasted_vram;
82bf215546Sopenharmony_ci   uint64_t slab_wasted_gtt;
83bf215546Sopenharmony_ci   uint64_t buffer_wait_time; /* time spent in buffer_wait in ns */
84bf215546Sopenharmony_ci   uint64_t num_gfx_IBs;
85bf215546Sopenharmony_ci   uint64_t num_sdma_IBs;
86bf215546Sopenharmony_ci   uint64_t num_mapped_buffers;
87bf215546Sopenharmony_ci   uint64_t gfx_bo_list_counter;
88bf215546Sopenharmony_ci   uint64_t gfx_ib_size_counter;
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci   struct radeon_info info;
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci   /* multithreaded IB submission */
93bf215546Sopenharmony_ci   struct util_queue cs_queue;
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   struct ac_addrlib *addrlib;
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   bool check_vm;
98bf215546Sopenharmony_ci   bool noop_cs;
99bf215546Sopenharmony_ci   bool reserve_vmid;
100bf215546Sopenharmony_ci   bool zero_all_vram_allocs;
101bf215546Sopenharmony_ci#if DEBUG
102bf215546Sopenharmony_ci   bool debug_all_bos;
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci   /* List of all allocated buffers */
105bf215546Sopenharmony_ci   simple_mtx_t global_bo_list_lock;
106bf215546Sopenharmony_ci   struct list_head global_bo_list;
107bf215546Sopenharmony_ci   unsigned num_buffers;
108bf215546Sopenharmony_ci#endif
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   /* Single-linked list of all structs amdgpu_screen_winsys referencing this
111bf215546Sopenharmony_ci    * struct amdgpu_winsys
112bf215546Sopenharmony_ci    */
113bf215546Sopenharmony_ci   simple_mtx_t sws_list_lock;
114bf215546Sopenharmony_ci   struct amdgpu_screen_winsys *sws_list;
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci   /* For returning the same amdgpu_winsys_bo instance for exported
117bf215546Sopenharmony_ci    * and re-imported buffers. */
118bf215546Sopenharmony_ci   struct hash_table *bo_export_table;
119bf215546Sopenharmony_ci   simple_mtx_t bo_export_table_lock;
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci   /* Since most winsys functions require struct radeon_winsys *, dummy_ws.base is used
122bf215546Sopenharmony_ci    * for invoking them because sws_list can be NULL.
123bf215546Sopenharmony_ci    */
124bf215546Sopenharmony_ci   struct amdgpu_screen_winsys dummy_ws;
125bf215546Sopenharmony_ci};
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_cistatic inline struct amdgpu_screen_winsys *
128bf215546Sopenharmony_ciamdgpu_screen_winsys(struct radeon_winsys *base)
129bf215546Sopenharmony_ci{
130bf215546Sopenharmony_ci   return (struct amdgpu_screen_winsys*)base;
131bf215546Sopenharmony_ci}
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_cistatic inline struct amdgpu_winsys *
134bf215546Sopenharmony_ciamdgpu_winsys(struct radeon_winsys *base)
135bf215546Sopenharmony_ci{
136bf215546Sopenharmony_ci   return amdgpu_screen_winsys(base)->aws;
137bf215546Sopenharmony_ci}
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_civoid amdgpu_surface_init_functions(struct amdgpu_screen_winsys *ws);
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci#endif
142