162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright 2014 Advanced Micro Devices, Inc. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 1262306a36Sopenharmony_ci * all copies or substantial portions of the Software. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 2162306a36Sopenharmony_ci * 2262306a36Sopenharmony_ci */ 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#ifndef __AMDGPU_IH_H__ 2562306a36Sopenharmony_ci#define __AMDGPU_IH_H__ 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* Maximum number of IVs processed at once */ 2862306a36Sopenharmony_ci#define AMDGPU_IH_MAX_NUM_IVS 32 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define IH_RING_SIZE (256 * 1024) 3162306a36Sopenharmony_ci#define IH_SW_RING_SIZE (16 * 1024) /* enough for 512 CAM entries */ 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_cistruct amdgpu_device; 3462306a36Sopenharmony_cistruct amdgpu_iv_entry; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistruct amdgpu_ih_regs { 3762306a36Sopenharmony_ci uint32_t ih_rb_base; 3862306a36Sopenharmony_ci uint32_t ih_rb_base_hi; 3962306a36Sopenharmony_ci uint32_t ih_rb_cntl; 4062306a36Sopenharmony_ci uint32_t ih_rb_wptr; 4162306a36Sopenharmony_ci uint32_t ih_rb_rptr; 4262306a36Sopenharmony_ci uint32_t ih_doorbell_rptr; 4362306a36Sopenharmony_ci uint32_t ih_rb_wptr_addr_lo; 4462306a36Sopenharmony_ci uint32_t ih_rb_wptr_addr_hi; 4562306a36Sopenharmony_ci uint32_t psp_reg_id; 4662306a36Sopenharmony_ci}; 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* 4962306a36Sopenharmony_ci * R6xx+ IH ring 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_cistruct amdgpu_ih_ring { 5262306a36Sopenharmony_ci unsigned ring_size; 5362306a36Sopenharmony_ci uint32_t ptr_mask; 5462306a36Sopenharmony_ci u32 doorbell_index; 5562306a36Sopenharmony_ci bool use_doorbell; 5662306a36Sopenharmony_ci bool use_bus_addr; 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci struct amdgpu_bo *ring_obj; 5962306a36Sopenharmony_ci volatile uint32_t *ring; 6062306a36Sopenharmony_ci uint64_t gpu_addr; 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci uint64_t wptr_addr; 6362306a36Sopenharmony_ci volatile uint32_t *wptr_cpu; 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci uint64_t rptr_addr; 6662306a36Sopenharmony_ci volatile uint32_t *rptr_cpu; 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci bool enabled; 6962306a36Sopenharmony_ci unsigned rptr; 7062306a36Sopenharmony_ci struct amdgpu_ih_regs ih_regs; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci /* For waiting on IH processing at checkpoint. */ 7362306a36Sopenharmony_ci wait_queue_head_t wait_process; 7462306a36Sopenharmony_ci uint64_t processed_timestamp; 7562306a36Sopenharmony_ci}; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* return true if time stamp t2 is after t1 with 48bit wrap around */ 7862306a36Sopenharmony_ci#define amdgpu_ih_ts_after(t1, t2) \ 7962306a36Sopenharmony_ci (((int64_t)((t2) << 16) - (int64_t)((t1) << 16)) > 0LL) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* provided by the ih block */ 8262306a36Sopenharmony_cistruct amdgpu_ih_funcs { 8362306a36Sopenharmony_ci /* ring read/write ptr handling, called from interrupt context */ 8462306a36Sopenharmony_ci u32 (*get_wptr)(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); 8562306a36Sopenharmony_ci void (*decode_iv)(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih, 8662306a36Sopenharmony_ci struct amdgpu_iv_entry *entry); 8762306a36Sopenharmony_ci uint64_t (*decode_iv_ts)(struct amdgpu_ih_ring *ih, u32 rptr, 8862306a36Sopenharmony_ci signed int offset); 8962306a36Sopenharmony_ci void (*set_rptr)(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); 9062306a36Sopenharmony_ci}; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#define amdgpu_ih_get_wptr(adev, ih) (adev)->irq.ih_funcs->get_wptr((adev), (ih)) 9362306a36Sopenharmony_ci#define amdgpu_ih_decode_iv(adev, iv) \ 9462306a36Sopenharmony_ci (adev)->irq.ih_funcs->decode_iv((adev), (ih), (iv)) 9562306a36Sopenharmony_ci#define amdgpu_ih_decode_iv_ts(adev, ih, rptr, offset) \ 9662306a36Sopenharmony_ci (WARN_ON_ONCE(!(adev)->irq.ih_funcs->decode_iv_ts) ? 0 : \ 9762306a36Sopenharmony_ci (adev)->irq.ih_funcs->decode_iv_ts((ih), (rptr), (offset))) 9862306a36Sopenharmony_ci#define amdgpu_ih_set_rptr(adev, ih) (adev)->irq.ih_funcs->set_rptr((adev), (ih)) 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ciint amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih, 10162306a36Sopenharmony_ci unsigned ring_size, bool use_bus_addr); 10262306a36Sopenharmony_civoid amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); 10362306a36Sopenharmony_civoid amdgpu_ih_ring_write(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih, 10462306a36Sopenharmony_ci const uint32_t *iv, unsigned int num_dw); 10562306a36Sopenharmony_ciint amdgpu_ih_wait_on_checkpoint_process_ts(struct amdgpu_device *adev, 10662306a36Sopenharmony_ci struct amdgpu_ih_ring *ih); 10762306a36Sopenharmony_ciint amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih); 10862306a36Sopenharmony_civoid amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev, 10962306a36Sopenharmony_ci struct amdgpu_ih_ring *ih, 11062306a36Sopenharmony_ci struct amdgpu_iv_entry *entry); 11162306a36Sopenharmony_ciuint64_t amdgpu_ih_decode_iv_ts_helper(struct amdgpu_ih_ring *ih, u32 rptr, 11262306a36Sopenharmony_ci signed int offset); 11362306a36Sopenharmony_ci#endif 114