2 * Copyright 2014 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.
23 #include <linux/module.h>
24 #include <linux/fdtable.h>
25 #include <linux/uaccess.h>
30 #include "radeon_kfd.h"
31 #include "radeon_ucode.h"
32 #include <linux/firmware.h>
33 #include "cik_structs.h"
35 #define CIK_PIPE_PER_MEC (4)
37 static const uint32_t watchRegs
[MAX_WATCH_ADDRESSES
* ADDRESS_WATCH_REG_MAX
] = {
38 TCP_WATCH0_ADDR_H
, TCP_WATCH0_ADDR_L
, TCP_WATCH0_CNTL
,
39 TCP_WATCH1_ADDR_H
, TCP_WATCH1_ADDR_L
, TCP_WATCH1_CNTL
,
40 TCP_WATCH2_ADDR_H
, TCP_WATCH2_ADDR_L
, TCP_WATCH2_CNTL
,
41 TCP_WATCH3_ADDR_H
, TCP_WATCH3_ADDR_L
, TCP_WATCH3_CNTL
51 static int alloc_gtt_mem(struct kgd_dev
*kgd
, size_t size
,
52 void **mem_obj
, uint64_t *gpu_addr
,
55 static void free_gtt_mem(struct kgd_dev
*kgd
, void *mem_obj
);
57 static uint64_t get_vmem_size(struct kgd_dev
*kgd
);
58 static uint64_t get_gpu_clock_counter(struct kgd_dev
*kgd
);
60 static uint32_t get_max_engine_clock_in_mhz(struct kgd_dev
*kgd
);
61 static uint16_t get_fw_version(struct kgd_dev
*kgd
, enum kgd_engine_type type
);
64 * Register access functions
67 static void kgd_program_sh_mem_settings(struct kgd_dev
*kgd
, uint32_t vmid
,
68 uint32_t sh_mem_config
, uint32_t sh_mem_ape1_base
,
69 uint32_t sh_mem_ape1_limit
, uint32_t sh_mem_bases
);
71 static int kgd_set_pasid_vmid_mapping(struct kgd_dev
*kgd
, unsigned int pasid
,
74 static int kgd_init_pipeline(struct kgd_dev
*kgd
, uint32_t pipe_id
,
75 uint32_t hpd_size
, uint64_t hpd_gpu_addr
);
76 static int kgd_init_interrupts(struct kgd_dev
*kgd
, uint32_t pipe_id
);
77 static int kgd_hqd_load(struct kgd_dev
*kgd
, void *mqd
, uint32_t pipe_id
,
78 uint32_t queue_id
, uint32_t __user
*wptr
);
79 static int kgd_hqd_sdma_load(struct kgd_dev
*kgd
, void *mqd
);
80 static bool kgd_hqd_is_occupied(struct kgd_dev
*kgd
, uint64_t queue_address
,
81 uint32_t pipe_id
, uint32_t queue_id
);
83 static int kgd_hqd_destroy(struct kgd_dev
*kgd
, uint32_t reset_type
,
84 unsigned int timeout
, uint32_t pipe_id
,
86 static bool kgd_hqd_sdma_is_occupied(struct kgd_dev
*kgd
, void *mqd
);
87 static int kgd_hqd_sdma_destroy(struct kgd_dev
*kgd
, void *mqd
,
88 unsigned int timeout
);
89 static int kgd_address_watch_disable(struct kgd_dev
*kgd
);
90 static int kgd_address_watch_execute(struct kgd_dev
*kgd
,
91 unsigned int watch_point_id
,
95 static int kgd_wave_control_execute(struct kgd_dev
*kgd
,
96 uint32_t gfx_index_val
,
98 static uint32_t kgd_address_watch_get_offset(struct kgd_dev
*kgd
,
99 unsigned int watch_point_id
,
100 unsigned int reg_offset
);
102 static bool get_atc_vmid_pasid_mapping_valid(struct kgd_dev
*kgd
, uint8_t vmid
);
103 static uint16_t get_atc_vmid_pasid_mapping_pasid(struct kgd_dev
*kgd
,
105 static void write_vmid_invalidate_request(struct kgd_dev
*kgd
, uint8_t vmid
);
107 static const struct kfd2kgd_calls kfd2kgd
= {
108 .init_gtt_mem_allocation
= alloc_gtt_mem
,
109 .free_gtt_mem
= free_gtt_mem
,
110 .get_vmem_size
= get_vmem_size
,
111 .get_gpu_clock_counter
= get_gpu_clock_counter
,
112 .get_max_engine_clock_in_mhz
= get_max_engine_clock_in_mhz
,
113 .program_sh_mem_settings
= kgd_program_sh_mem_settings
,
114 .set_pasid_vmid_mapping
= kgd_set_pasid_vmid_mapping
,
115 .init_pipeline
= kgd_init_pipeline
,
116 .init_interrupts
= kgd_init_interrupts
,
117 .hqd_load
= kgd_hqd_load
,
118 .hqd_sdma_load
= kgd_hqd_sdma_load
,
119 .hqd_is_occupied
= kgd_hqd_is_occupied
,
120 .hqd_sdma_is_occupied
= kgd_hqd_sdma_is_occupied
,
121 .hqd_destroy
= kgd_hqd_destroy
,
122 .hqd_sdma_destroy
= kgd_hqd_sdma_destroy
,
123 .address_watch_disable
= kgd_address_watch_disable
,
124 .address_watch_execute
= kgd_address_watch_execute
,
125 .wave_control_execute
= kgd_wave_control_execute
,
126 .address_watch_get_offset
= kgd_address_watch_get_offset
,
127 .get_atc_vmid_pasid_mapping_pasid
= get_atc_vmid_pasid_mapping_pasid
,
128 .get_atc_vmid_pasid_mapping_valid
= get_atc_vmid_pasid_mapping_valid
,
129 .write_vmid_invalidate_request
= write_vmid_invalidate_request
,
130 .get_fw_version
= get_fw_version
133 static const struct kgd2kfd_calls
*kgd2kfd
;
135 int radeon_kfd_init(void)
139 #if defined(CONFIG_HSA_AMD_MODULE)
140 int (*kgd2kfd_init_p
)(unsigned, const struct kgd2kfd_calls
**);
142 kgd2kfd_init_p
= symbol_request(kgd2kfd_init
);
144 if (kgd2kfd_init_p
== NULL
)
147 ret
= kgd2kfd_init_p(KFD_INTERFACE_VERSION
, &kgd2kfd
);
149 symbol_put(kgd2kfd_init
);
153 #elif defined(CONFIG_HSA_AMD)
154 ret
= kgd2kfd_init(KFD_INTERFACE_VERSION
, &kgd2kfd
);
165 void radeon_kfd_fini(void)
169 symbol_put(kgd2kfd_init
);
173 void radeon_kfd_device_probe(struct radeon_device
*rdev
)
176 rdev
->kfd
= kgd2kfd
->probe((struct kgd_dev
*)rdev
,
177 rdev
->pdev
, &kfd2kgd
);
180 void radeon_kfd_device_init(struct radeon_device
*rdev
)
182 int i
, queue
, pipe
, mec
;
185 struct kgd2kfd_shared_resources gpu_resources
= {
186 .compute_vmid_bitmap
= 0xFF00,
187 .num_pipe_per_mec
= 4,
188 .num_queue_per_pipe
= 8
191 bitmap_zero(gpu_resources
.queue_bitmap
, KGD_MAX_QUEUES
);
193 for (i
= 0; i
< KGD_MAX_QUEUES
; ++i
) {
194 queue
= i
% gpu_resources
.num_queue_per_pipe
;
195 pipe
= (i
/ gpu_resources
.num_queue_per_pipe
)
196 % gpu_resources
.num_pipe_per_mec
;
197 mec
= (i
/ gpu_resources
.num_queue_per_pipe
)
198 / gpu_resources
.num_pipe_per_mec
;
200 if (mec
== 0 && pipe
> 0)
201 set_bit(i
, gpu_resources
.queue_bitmap
);
204 radeon_doorbell_get_kfd_info(rdev
,
205 &gpu_resources
.doorbell_physical_address
,
206 &gpu_resources
.doorbell_aperture_size
,
207 &gpu_resources
.doorbell_start_offset
);
209 kgd2kfd
->device_init(rdev
->kfd
, &gpu_resources
);
213 void radeon_kfd_device_fini(struct radeon_device
*rdev
)
216 kgd2kfd
->device_exit(rdev
->kfd
);
221 void radeon_kfd_interrupt(struct radeon_device
*rdev
, const void *ih_ring_entry
)
224 kgd2kfd
->interrupt(rdev
->kfd
, ih_ring_entry
);
227 void radeon_kfd_suspend(struct radeon_device
*rdev
)
230 kgd2kfd
->suspend(rdev
->kfd
);
233 int radeon_kfd_resume(struct radeon_device
*rdev
)
238 r
= kgd2kfd
->resume(rdev
->kfd
);
243 static int alloc_gtt_mem(struct kgd_dev
*kgd
, size_t size
,
244 void **mem_obj
, uint64_t *gpu_addr
,
247 struct radeon_device
*rdev
= (struct radeon_device
*)kgd
;
248 struct kgd_mem
**mem
= (struct kgd_mem
**) mem_obj
;
252 BUG_ON(gpu_addr
== NULL
);
253 BUG_ON(cpu_ptr
== NULL
);
255 *mem
= kmalloc(sizeof(struct kgd_mem
), GFP_KERNEL
);
259 r
= radeon_bo_create(rdev
, size
, PAGE_SIZE
, true, RADEON_GEM_DOMAIN_GTT
,
260 RADEON_GEM_GTT_WC
, NULL
, NULL
, &(*mem
)->bo
);
263 "failed to allocate BO for amdkfd (%d)\n", r
);
268 r
= radeon_bo_reserve((*mem
)->bo
, true);
270 dev_err(rdev
->dev
, "(%d) failed to reserve bo for amdkfd\n", r
);
271 goto allocate_mem_reserve_bo_failed
;
274 r
= radeon_bo_pin((*mem
)->bo
, RADEON_GEM_DOMAIN_GTT
,
277 dev_err(rdev
->dev
, "(%d) failed to pin bo for amdkfd\n", r
);
278 goto allocate_mem_pin_bo_failed
;
280 *gpu_addr
= (*mem
)->gpu_addr
;
282 r
= radeon_bo_kmap((*mem
)->bo
, &(*mem
)->cpu_ptr
);
285 "(%d) failed to map bo to kernel for amdkfd\n", r
);
286 goto allocate_mem_kmap_bo_failed
;
288 *cpu_ptr
= (*mem
)->cpu_ptr
;
290 radeon_bo_unreserve((*mem
)->bo
);
294 allocate_mem_kmap_bo_failed
:
295 radeon_bo_unpin((*mem
)->bo
);
296 allocate_mem_pin_bo_failed
:
297 radeon_bo_unreserve((*mem
)->bo
);
298 allocate_mem_reserve_bo_failed
:
299 radeon_bo_unref(&(*mem
)->bo
);
304 static void free_gtt_mem(struct kgd_dev
*kgd
, void *mem_obj
)
306 struct kgd_mem
*mem
= (struct kgd_mem
*) mem_obj
;
310 radeon_bo_reserve(mem
->bo
, true);
311 radeon_bo_kunmap(mem
->bo
);
312 radeon_bo_unpin(mem
->bo
);
313 radeon_bo_unreserve(mem
->bo
);
314 radeon_bo_unref(&(mem
->bo
));
318 static uint64_t get_vmem_size(struct kgd_dev
*kgd
)
320 struct radeon_device
*rdev
= (struct radeon_device
*)kgd
;
324 return rdev
->mc
.real_vram_size
;
327 static uint64_t get_gpu_clock_counter(struct kgd_dev
*kgd
)
329 struct radeon_device
*rdev
= (struct radeon_device
*)kgd
;
331 return rdev
->asic
->get_gpu_clock_counter(rdev
);
334 static uint32_t get_max_engine_clock_in_mhz(struct kgd_dev
*kgd
)
336 struct radeon_device
*rdev
= (struct radeon_device
*)kgd
;
338 /* The sclk is in quantas of 10kHz */
339 return rdev
->pm
.dpm
.dyn_state
.max_clock_voltage_on_ac
.sclk
/ 100;
342 static inline struct radeon_device
*get_radeon_device(struct kgd_dev
*kgd
)
344 return (struct radeon_device
*)kgd
;
347 static void write_register(struct kgd_dev
*kgd
, uint32_t offset
, uint32_t value
)
349 struct radeon_device
*rdev
= get_radeon_device(kgd
);
351 writel(value
, (void __iomem
*)(rdev
->rmmio
+ offset
));
354 static uint32_t read_register(struct kgd_dev
*kgd
, uint32_t offset
)
356 struct radeon_device
*rdev
= get_radeon_device(kgd
);
358 return readl((void __iomem
*)(rdev
->rmmio
+ offset
));
361 static void lock_srbm(struct kgd_dev
*kgd
, uint32_t mec
, uint32_t pipe
,
362 uint32_t queue
, uint32_t vmid
)
364 struct radeon_device
*rdev
= get_radeon_device(kgd
);
365 uint32_t value
= PIPEID(pipe
) | MEID(mec
) | VMID(vmid
) | QUEUEID(queue
);
367 mutex_lock(&rdev
->srbm_mutex
);
368 write_register(kgd
, SRBM_GFX_CNTL
, value
);
371 static void unlock_srbm(struct kgd_dev
*kgd
)
373 struct radeon_device
*rdev
= get_radeon_device(kgd
);
375 write_register(kgd
, SRBM_GFX_CNTL
, 0);
376 mutex_unlock(&rdev
->srbm_mutex
);
379 static void acquire_queue(struct kgd_dev
*kgd
, uint32_t pipe_id
,
382 uint32_t mec
= (++pipe_id
/ CIK_PIPE_PER_MEC
) + 1;
383 uint32_t pipe
= (pipe_id
% CIK_PIPE_PER_MEC
);
385 lock_srbm(kgd
, mec
, pipe
, queue_id
, 0);
388 static void release_queue(struct kgd_dev
*kgd
)
393 static void kgd_program_sh_mem_settings(struct kgd_dev
*kgd
, uint32_t vmid
,
394 uint32_t sh_mem_config
,
395 uint32_t sh_mem_ape1_base
,
396 uint32_t sh_mem_ape1_limit
,
397 uint32_t sh_mem_bases
)
399 lock_srbm(kgd
, 0, 0, 0, vmid
);
401 write_register(kgd
, SH_MEM_CONFIG
, sh_mem_config
);
402 write_register(kgd
, SH_MEM_APE1_BASE
, sh_mem_ape1_base
);
403 write_register(kgd
, SH_MEM_APE1_LIMIT
, sh_mem_ape1_limit
);
404 write_register(kgd
, SH_MEM_BASES
, sh_mem_bases
);
409 static int kgd_set_pasid_vmid_mapping(struct kgd_dev
*kgd
, unsigned int pasid
,
413 * We have to assume that there is no outstanding mapping.
414 * The ATC_VMID_PASID_MAPPING_UPDATE_STATUS bit could be 0
415 * because a mapping is in progress or because a mapping finished and
417 * So the protocol is to always wait & clear.
419 uint32_t pasid_mapping
= (pasid
== 0) ? 0 : (uint32_t)pasid
|
420 ATC_VMID_PASID_MAPPING_VALID_MASK
;
422 write_register(kgd
, ATC_VMID0_PASID_MAPPING
+ vmid
*sizeof(uint32_t),
425 while (!(read_register(kgd
, ATC_VMID_PASID_MAPPING_UPDATE_STATUS
) &
428 write_register(kgd
, ATC_VMID_PASID_MAPPING_UPDATE_STATUS
, 1U << vmid
);
430 /* Mapping vmid to pasid also for IH block */
431 write_register(kgd
, IH_VMID_0_LUT
+ vmid
* sizeof(uint32_t),
437 static int kgd_init_pipeline(struct kgd_dev
*kgd
, uint32_t pipe_id
,
438 uint32_t hpd_size
, uint64_t hpd_gpu_addr
)
440 /* nothing to do here */
444 static int kgd_init_interrupts(struct kgd_dev
*kgd
, uint32_t pipe_id
)
449 mec
= (pipe_id
/ CIK_PIPE_PER_MEC
) + 1;
450 pipe
= (pipe_id
% CIK_PIPE_PER_MEC
);
452 lock_srbm(kgd
, mec
, pipe
, 0, 0);
454 write_register(kgd
, CPC_INT_CNTL
,
455 TIME_STAMP_INT_ENABLE
| OPCODE_ERROR_INT_ENABLE
);
462 static inline uint32_t get_sdma_base_addr(struct cik_sdma_rlc_registers
*m
)
466 retval
= m
->sdma_engine_id
* SDMA1_REGISTER_OFFSET
+
467 m
->sdma_queue_id
* KFD_CIK_SDMA_QUEUE_OFFSET
;
469 pr_debug("kfd: sdma base address: 0x%x\n", retval
);
474 static inline struct cik_mqd
*get_mqd(void *mqd
)
476 return (struct cik_mqd
*)mqd
;
479 static inline struct cik_sdma_rlc_registers
*get_sdma_mqd(void *mqd
)
481 return (struct cik_sdma_rlc_registers
*)mqd
;
484 static int kgd_hqd_load(struct kgd_dev
*kgd
, void *mqd
, uint32_t pipe_id
,
485 uint32_t queue_id
, uint32_t __user
*wptr
)
487 uint32_t wptr_shadow
, is_wptr_shadow_valid
;
492 is_wptr_shadow_valid
= !get_user(wptr_shadow
, wptr
);
494 acquire_queue(kgd
, pipe_id
, queue_id
);
495 write_register(kgd
, CP_MQD_BASE_ADDR
, m
->cp_mqd_base_addr_lo
);
496 write_register(kgd
, CP_MQD_BASE_ADDR_HI
, m
->cp_mqd_base_addr_hi
);
497 write_register(kgd
, CP_MQD_CONTROL
, m
->cp_mqd_control
);
499 write_register(kgd
, CP_HQD_PQ_BASE
, m
->cp_hqd_pq_base_lo
);
500 write_register(kgd
, CP_HQD_PQ_BASE_HI
, m
->cp_hqd_pq_base_hi
);
501 write_register(kgd
, CP_HQD_PQ_CONTROL
, m
->cp_hqd_pq_control
);
503 write_register(kgd
, CP_HQD_IB_CONTROL
, m
->cp_hqd_ib_control
);
504 write_register(kgd
, CP_HQD_IB_BASE_ADDR
, m
->cp_hqd_ib_base_addr_lo
);
505 write_register(kgd
, CP_HQD_IB_BASE_ADDR_HI
, m
->cp_hqd_ib_base_addr_hi
);
507 write_register(kgd
, CP_HQD_IB_RPTR
, m
->cp_hqd_ib_rptr
);
509 write_register(kgd
, CP_HQD_PERSISTENT_STATE
,
510 m
->cp_hqd_persistent_state
);
511 write_register(kgd
, CP_HQD_SEMA_CMD
, m
->cp_hqd_sema_cmd
);
512 write_register(kgd
, CP_HQD_MSG_TYPE
, m
->cp_hqd_msg_type
);
514 write_register(kgd
, CP_HQD_ATOMIC0_PREOP_LO
,
515 m
->cp_hqd_atomic0_preop_lo
);
517 write_register(kgd
, CP_HQD_ATOMIC0_PREOP_HI
,
518 m
->cp_hqd_atomic0_preop_hi
);
520 write_register(kgd
, CP_HQD_ATOMIC1_PREOP_LO
,
521 m
->cp_hqd_atomic1_preop_lo
);
523 write_register(kgd
, CP_HQD_ATOMIC1_PREOP_HI
,
524 m
->cp_hqd_atomic1_preop_hi
);
526 write_register(kgd
, CP_HQD_PQ_RPTR_REPORT_ADDR
,
527 m
->cp_hqd_pq_rptr_report_addr_lo
);
529 write_register(kgd
, CP_HQD_PQ_RPTR_REPORT_ADDR_HI
,
530 m
->cp_hqd_pq_rptr_report_addr_hi
);
532 write_register(kgd
, CP_HQD_PQ_RPTR
, m
->cp_hqd_pq_rptr
);
534 write_register(kgd
, CP_HQD_PQ_WPTR_POLL_ADDR
,
535 m
->cp_hqd_pq_wptr_poll_addr_lo
);
537 write_register(kgd
, CP_HQD_PQ_WPTR_POLL_ADDR_HI
,
538 m
->cp_hqd_pq_wptr_poll_addr_hi
);
540 write_register(kgd
, CP_HQD_PQ_DOORBELL_CONTROL
,
541 m
->cp_hqd_pq_doorbell_control
);
543 write_register(kgd
, CP_HQD_VMID
, m
->cp_hqd_vmid
);
545 write_register(kgd
, CP_HQD_QUANTUM
, m
->cp_hqd_quantum
);
547 write_register(kgd
, CP_HQD_PIPE_PRIORITY
, m
->cp_hqd_pipe_priority
);
548 write_register(kgd
, CP_HQD_QUEUE_PRIORITY
, m
->cp_hqd_queue_priority
);
550 write_register(kgd
, CP_HQD_IQ_RPTR
, m
->cp_hqd_iq_rptr
);
552 if (is_wptr_shadow_valid
)
553 write_register(kgd
, CP_HQD_PQ_WPTR
, wptr_shadow
);
555 write_register(kgd
, CP_HQD_ACTIVE
, m
->cp_hqd_active
);
561 static int kgd_hqd_sdma_load(struct kgd_dev
*kgd
, void *mqd
)
563 struct cik_sdma_rlc_registers
*m
;
564 uint32_t sdma_base_addr
;
566 m
= get_sdma_mqd(mqd
);
567 sdma_base_addr
= get_sdma_base_addr(m
);
570 sdma_base_addr
+ SDMA0_RLC0_VIRTUAL_ADDR
,
571 m
->sdma_rlc_virtual_addr
);
574 sdma_base_addr
+ SDMA0_RLC0_RB_BASE
,
575 m
->sdma_rlc_rb_base
);
578 sdma_base_addr
+ SDMA0_RLC0_RB_BASE_HI
,
579 m
->sdma_rlc_rb_base_hi
);
582 sdma_base_addr
+ SDMA0_RLC0_RB_RPTR_ADDR_LO
,
583 m
->sdma_rlc_rb_rptr_addr_lo
);
586 sdma_base_addr
+ SDMA0_RLC0_RB_RPTR_ADDR_HI
,
587 m
->sdma_rlc_rb_rptr_addr_hi
);
590 sdma_base_addr
+ SDMA0_RLC0_DOORBELL
,
591 m
->sdma_rlc_doorbell
);
594 sdma_base_addr
+ SDMA0_RLC0_RB_CNTL
,
595 m
->sdma_rlc_rb_cntl
);
600 static bool kgd_hqd_is_occupied(struct kgd_dev
*kgd
, uint64_t queue_address
,
601 uint32_t pipe_id
, uint32_t queue_id
)
607 acquire_queue(kgd
, pipe_id
, queue_id
);
608 act
= read_register(kgd
, CP_HQD_ACTIVE
);
610 low
= lower_32_bits(queue_address
>> 8);
611 high
= upper_32_bits(queue_address
>> 8);
613 if (low
== read_register(kgd
, CP_HQD_PQ_BASE
) &&
614 high
== read_register(kgd
, CP_HQD_PQ_BASE_HI
))
621 static bool kgd_hqd_sdma_is_occupied(struct kgd_dev
*kgd
, void *mqd
)
623 struct cik_sdma_rlc_registers
*m
;
624 uint32_t sdma_base_addr
;
625 uint32_t sdma_rlc_rb_cntl
;
627 m
= get_sdma_mqd(mqd
);
628 sdma_base_addr
= get_sdma_base_addr(m
);
630 sdma_rlc_rb_cntl
= read_register(kgd
,
631 sdma_base_addr
+ SDMA0_RLC0_RB_CNTL
);
633 if (sdma_rlc_rb_cntl
& SDMA_RB_ENABLE
)
639 static int kgd_hqd_destroy(struct kgd_dev
*kgd
, uint32_t reset_type
,
640 unsigned int timeout
, uint32_t pipe_id
,
645 acquire_queue(kgd
, pipe_id
, queue_id
);
646 write_register(kgd
, CP_HQD_PQ_DOORBELL_CONTROL
, 0);
648 write_register(kgd
, CP_HQD_DEQUEUE_REQUEST
, reset_type
);
651 temp
= read_register(kgd
, CP_HQD_ACTIVE
);
655 pr_err("kfd: cp queue preemption time out (%dms)\n",
668 static int kgd_hqd_sdma_destroy(struct kgd_dev
*kgd
, void *mqd
,
669 unsigned int timeout
)
671 struct cik_sdma_rlc_registers
*m
;
672 uint32_t sdma_base_addr
;
675 m
= get_sdma_mqd(mqd
);
676 sdma_base_addr
= get_sdma_base_addr(m
);
678 temp
= read_register(kgd
, sdma_base_addr
+ SDMA0_RLC0_RB_CNTL
);
679 temp
= temp
& ~SDMA_RB_ENABLE
;
680 write_register(kgd
, sdma_base_addr
+ SDMA0_RLC0_RB_CNTL
, temp
);
683 temp
= read_register(kgd
, sdma_base_addr
+
684 SDMA0_RLC0_CONTEXT_STATUS
);
685 if (temp
& SDMA_RLC_IDLE
)
693 write_register(kgd
, sdma_base_addr
+ SDMA0_RLC0_DOORBELL
, 0);
694 write_register(kgd
, sdma_base_addr
+ SDMA0_RLC0_RB_RPTR
, 0);
695 write_register(kgd
, sdma_base_addr
+ SDMA0_RLC0_RB_WPTR
, 0);
696 write_register(kgd
, sdma_base_addr
+ SDMA0_RLC0_RB_BASE
, 0);
701 static int kgd_address_watch_disable(struct kgd_dev
*kgd
)
703 union TCP_WATCH_CNTL_BITS cntl
;
708 cntl
.bitfields
.valid
= 0;
709 cntl
.bitfields
.mask
= ADDRESS_WATCH_REG_CNTL_DEFAULT_MASK
;
710 cntl
.bitfields
.atc
= 1;
712 /* Turning off this address until we set all the registers */
713 for (i
= 0; i
< MAX_WATCH_ADDRESSES
; i
++)
715 watchRegs
[i
* ADDRESS_WATCH_REG_MAX
+
716 ADDRESS_WATCH_REG_CNTL
],
722 static int kgd_address_watch_execute(struct kgd_dev
*kgd
,
723 unsigned int watch_point_id
,
728 union TCP_WATCH_CNTL_BITS cntl
;
730 cntl
.u32All
= cntl_val
;
732 /* Turning off this watch point until we set all the registers */
733 cntl
.bitfields
.valid
= 0;
735 watchRegs
[watch_point_id
* ADDRESS_WATCH_REG_MAX
+
736 ADDRESS_WATCH_REG_CNTL
],
740 watchRegs
[watch_point_id
* ADDRESS_WATCH_REG_MAX
+
741 ADDRESS_WATCH_REG_ADDR_HI
],
745 watchRegs
[watch_point_id
* ADDRESS_WATCH_REG_MAX
+
746 ADDRESS_WATCH_REG_ADDR_LO
],
749 /* Enable the watch point */
750 cntl
.bitfields
.valid
= 1;
753 watchRegs
[watch_point_id
* ADDRESS_WATCH_REG_MAX
+
754 ADDRESS_WATCH_REG_CNTL
],
760 static int kgd_wave_control_execute(struct kgd_dev
*kgd
,
761 uint32_t gfx_index_val
,
764 struct radeon_device
*rdev
= get_radeon_device(kgd
);
767 mutex_lock(&rdev
->grbm_idx_mutex
);
769 write_register(kgd
, GRBM_GFX_INDEX
, gfx_index_val
);
770 write_register(kgd
, SQ_CMD
, sq_cmd
);
772 /* Restore the GRBM_GFX_INDEX register */
774 data
= INSTANCE_BROADCAST_WRITES
| SH_BROADCAST_WRITES
|
777 write_register(kgd
, GRBM_GFX_INDEX
, data
);
779 mutex_unlock(&rdev
->grbm_idx_mutex
);
784 static uint32_t kgd_address_watch_get_offset(struct kgd_dev
*kgd
,
785 unsigned int watch_point_id
,
786 unsigned int reg_offset
)
788 return watchRegs
[watch_point_id
* ADDRESS_WATCH_REG_MAX
+ reg_offset
];
791 static bool get_atc_vmid_pasid_mapping_valid(struct kgd_dev
*kgd
, uint8_t vmid
)
794 struct radeon_device
*rdev
= (struct radeon_device
*) kgd
;
796 reg
= RREG32(ATC_VMID0_PASID_MAPPING
+ vmid
*4);
797 return reg
& ATC_VMID_PASID_MAPPING_VALID_MASK
;
800 static uint16_t get_atc_vmid_pasid_mapping_pasid(struct kgd_dev
*kgd
,
804 struct radeon_device
*rdev
= (struct radeon_device
*) kgd
;
806 reg
= RREG32(ATC_VMID0_PASID_MAPPING
+ vmid
*4);
807 return reg
& ATC_VMID_PASID_MAPPING_PASID_MASK
;
810 static void write_vmid_invalidate_request(struct kgd_dev
*kgd
, uint8_t vmid
)
812 struct radeon_device
*rdev
= (struct radeon_device
*) kgd
;
814 return WREG32(VM_INVALIDATE_REQUEST
, 1 << vmid
);
817 static uint16_t get_fw_version(struct kgd_dev
*kgd
, enum kgd_engine_type type
)
819 struct radeon_device
*rdev
= (struct radeon_device
*) kgd
;
820 const union radeon_firmware_header
*hdr
;
822 BUG_ON(kgd
== NULL
|| rdev
->mec_fw
== NULL
);
826 hdr
= (const union radeon_firmware_header
*) rdev
->pfp_fw
->data
;
830 hdr
= (const union radeon_firmware_header
*) rdev
->me_fw
->data
;
834 hdr
= (const union radeon_firmware_header
*) rdev
->ce_fw
->data
;
837 case KGD_ENGINE_MEC1
:
838 hdr
= (const union radeon_firmware_header
*) rdev
->mec_fw
->data
;
841 case KGD_ENGINE_MEC2
:
842 hdr
= (const union radeon_firmware_header
*)
847 hdr
= (const union radeon_firmware_header
*) rdev
->rlc_fw
->data
;
850 case KGD_ENGINE_SDMA1
:
851 case KGD_ENGINE_SDMA2
:
852 hdr
= (const union radeon_firmware_header
*)
863 /* Only 12 bit in use*/
864 return hdr
->common
.ucode_version
;