2015-06-13 02:38:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2018-12-08 06:07:20 +08:00
|
|
|
#include <linux/mmu_context.h>
|
2019-06-10 06:07:56 +08:00
|
|
|
|
2015-06-13 02:38:22 +08:00
|
|
|
#include "amdgpu.h"
|
|
|
|
#include "amdgpu_amdkfd.h"
|
|
|
|
#include "cikd.h"
|
|
|
|
#include "cik_sdma.h"
|
2017-02-02 05:37:42 +08:00
|
|
|
#include "gfx_v7_0.h"
|
2015-06-13 02:38:22 +08:00
|
|
|
#include "gca/gfx_7_2_d.h"
|
|
|
|
#include "gca/gfx_7_2_enum.h"
|
|
|
|
#include "gca/gfx_7_2_sh_mask.h"
|
|
|
|
#include "oss/oss_2_0_d.h"
|
|
|
|
#include "oss/oss_2_0_sh_mask.h"
|
|
|
|
#include "gmc/gmc_7_1_d.h"
|
|
|
|
#include "gmc/gmc_7_1_sh_mask.h"
|
|
|
|
#include "cik_structs.h"
|
|
|
|
|
2017-08-16 11:00:17 +08:00
|
|
|
enum hqd_dequeue_request_type {
|
|
|
|
NO_ACTION = 0,
|
|
|
|
DRAIN_PIPE,
|
|
|
|
RESET_WAVES
|
|
|
|
};
|
|
|
|
|
2015-06-13 02:38:22 +08:00
|
|
|
enum {
|
|
|
|
MAX_TRAPID = 8, /* 3 bits in the bitfield. */
|
|
|
|
MAX_WATCH_ADDRESSES = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ADDRESS_WATCH_REG_ADDR_HI = 0,
|
|
|
|
ADDRESS_WATCH_REG_ADDR_LO,
|
|
|
|
ADDRESS_WATCH_REG_CNTL,
|
|
|
|
ADDRESS_WATCH_REG_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
/* not defined in the CI/KV reg file */
|
|
|
|
enum {
|
|
|
|
ADDRESS_WATCH_REG_CNTL_ATC_BIT = 0x10000000UL,
|
|
|
|
ADDRESS_WATCH_REG_CNTL_DEFAULT_MASK = 0x00FFFFFF,
|
|
|
|
ADDRESS_WATCH_REG_ADDLOW_MASK_EXTENSION = 0x03000000,
|
|
|
|
/* extend the mask to 26 bits to match the low address field */
|
|
|
|
ADDRESS_WATCH_REG_ADDLOW_SHIFT = 6,
|
|
|
|
ADDRESS_WATCH_REG_ADDHIGH_MASK = 0xFFFF
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint32_t watchRegs[MAX_WATCH_ADDRESSES * ADDRESS_WATCH_REG_MAX] = {
|
|
|
|
mmTCP_WATCH0_ADDR_H, mmTCP_WATCH0_ADDR_L, mmTCP_WATCH0_CNTL,
|
|
|
|
mmTCP_WATCH1_ADDR_H, mmTCP_WATCH1_ADDR_L, mmTCP_WATCH1_CNTL,
|
|
|
|
mmTCP_WATCH2_ADDR_H, mmTCP_WATCH2_ADDR_L, mmTCP_WATCH2_CNTL,
|
|
|
|
mmTCP_WATCH3_ADDR_H, mmTCP_WATCH3_ADDR_L, mmTCP_WATCH3_CNTL
|
|
|
|
};
|
|
|
|
|
|
|
|
union TCP_WATCH_CNTL_BITS {
|
|
|
|
struct {
|
|
|
|
uint32_t mask:24;
|
|
|
|
uint32_t vmid:4;
|
|
|
|
uint32_t atc:1;
|
|
|
|
uint32_t mode:2;
|
|
|
|
uint32_t valid:1;
|
|
|
|
} bitfields, bits;
|
|
|
|
uint32_t u32All;
|
|
|
|
signed int i32All;
|
|
|
|
float f32All;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct amdgpu_device *get_amdgpu_device(struct kgd_dev *kgd)
|
|
|
|
{
|
|
|
|
return (struct amdgpu_device *)kgd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lock_srbm(struct kgd_dev *kgd, uint32_t mec, uint32_t pipe,
|
|
|
|
uint32_t queue, uint32_t vmid)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
uint32_t value = PIPEID(pipe) | MEID(mec) | VMID(vmid) | QUEUEID(queue);
|
|
|
|
|
|
|
|
mutex_lock(&adev->srbm_mutex);
|
|
|
|
WREG32(mmSRBM_GFX_CNTL, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unlock_srbm(struct kgd_dev *kgd)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
|
|
|
|
WREG32(mmSRBM_GFX_CNTL, 0);
|
|
|
|
mutex_unlock(&adev->srbm_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void acquire_queue(struct kgd_dev *kgd, uint32_t pipe_id,
|
|
|
|
uint32_t queue_id)
|
|
|
|
{
|
2017-02-03 04:14:14 +08:00
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
|
2017-08-16 11:00:03 +08:00
|
|
|
uint32_t mec = (pipe_id / adev->gfx.mec.num_pipe_per_mec) + 1;
|
2017-02-03 04:14:14 +08:00
|
|
|
uint32_t pipe = (pipe_id % adev->gfx.mec.num_pipe_per_mec);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
lock_srbm(kgd, mec, pipe, queue_id, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_queue(struct kgd_dev *kgd)
|
|
|
|
{
|
|
|
|
unlock_srbm(kgd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kgd_program_sh_mem_settings(struct kgd_dev *kgd, uint32_t vmid,
|
|
|
|
uint32_t sh_mem_config,
|
|
|
|
uint32_t sh_mem_ape1_base,
|
|
|
|
uint32_t sh_mem_ape1_limit,
|
|
|
|
uint32_t sh_mem_bases)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
|
|
|
|
lock_srbm(kgd, 0, 0, 0, vmid);
|
|
|
|
|
|
|
|
WREG32(mmSH_MEM_CONFIG, sh_mem_config);
|
|
|
|
WREG32(mmSH_MEM_APE1_BASE, sh_mem_ape1_base);
|
|
|
|
WREG32(mmSH_MEM_APE1_LIMIT, sh_mem_ape1_limit);
|
|
|
|
WREG32(mmSH_MEM_BASES, sh_mem_bases);
|
|
|
|
|
|
|
|
unlock_srbm(kgd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kgd_set_pasid_vmid_mapping(struct kgd_dev *kgd, unsigned int pasid,
|
|
|
|
unsigned int vmid)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to assume that there is no outstanding mapping.
|
|
|
|
* The ATC_VMID_PASID_MAPPING_UPDATE_STATUS bit could be 0 because
|
|
|
|
* a mapping is in progress or because a mapping finished and the
|
|
|
|
* SW cleared it. So the protocol is to always wait & clear.
|
|
|
|
*/
|
|
|
|
uint32_t pasid_mapping = (pasid == 0) ? 0 : (uint32_t)pasid |
|
|
|
|
ATC_VMID0_PASID_MAPPING__VALID_MASK;
|
|
|
|
|
|
|
|
WREG32(mmATC_VMID0_PASID_MAPPING + vmid, pasid_mapping);
|
|
|
|
|
|
|
|
while (!(RREG32(mmATC_VMID_PASID_MAPPING_UPDATE_STATUS) & (1U << vmid)))
|
|
|
|
cpu_relax();
|
|
|
|
WREG32(mmATC_VMID_PASID_MAPPING_UPDATE_STATUS, 1U << vmid);
|
|
|
|
|
|
|
|
/* Mapping vmid to pasid also for IH block */
|
|
|
|
WREG32(mmIH_VMID_0_LUT + vmid, pasid_mapping);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kgd_init_interrupts(struct kgd_dev *kgd, uint32_t pipe_id)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
uint32_t mec;
|
|
|
|
uint32_t pipe;
|
|
|
|
|
2017-02-03 04:14:14 +08:00
|
|
|
mec = (pipe_id / adev->gfx.mec.num_pipe_per_mec) + 1;
|
|
|
|
pipe = (pipe_id % adev->gfx.mec.num_pipe_per_mec);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
lock_srbm(kgd, mec, pipe, 0, 0);
|
|
|
|
|
|
|
|
WREG32(mmCPC_INT_CNTL, CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK |
|
|
|
|
CP_INT_CNTL_RING0__OPCODE_ERROR_INT_ENABLE_MASK);
|
|
|
|
|
|
|
|
unlock_srbm(kgd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-22 05:46:03 +08:00
|
|
|
static inline uint32_t get_sdma_rlc_reg_offset(struct cik_sdma_rlc_registers *m)
|
2015-06-13 02:38:22 +08:00
|
|
|
{
|
|
|
|
uint32_t retval;
|
|
|
|
|
|
|
|
retval = m->sdma_engine_id * SDMA1_REGISTER_OFFSET +
|
|
|
|
m->sdma_queue_id * KFD_CIK_SDMA_QUEUE_OFFSET;
|
|
|
|
|
2019-09-22 05:46:03 +08:00
|
|
|
pr_debug("RLC register offset for SDMA%d RLC%d: 0x%x\n",
|
|
|
|
m->sdma_engine_id, m->sdma_queue_id, retval);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct cik_mqd *get_mqd(void *mqd)
|
|
|
|
{
|
|
|
|
return (struct cik_mqd *)mqd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct cik_sdma_rlc_registers *get_sdma_mqd(void *mqd)
|
|
|
|
{
|
|
|
|
return (struct cik_sdma_rlc_registers *)mqd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kgd_hqd_load(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id,
|
2017-08-16 11:00:17 +08:00
|
|
|
uint32_t queue_id, uint32_t __user *wptr,
|
|
|
|
uint32_t wptr_shift, uint32_t wptr_mask,
|
|
|
|
struct mm_struct *mm)
|
2015-06-13 02:38:22 +08:00
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
struct cik_mqd *m;
|
2017-08-16 11:00:17 +08:00
|
|
|
uint32_t *mqd_hqd;
|
|
|
|
uint32_t reg, wptr_val, data;
|
2017-09-28 05:53:12 +08:00
|
|
|
bool valid_wptr = false;
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
m = get_mqd(mqd);
|
|
|
|
|
2017-02-02 05:37:42 +08:00
|
|
|
acquire_queue(kgd, pipe_id, queue_id);
|
2017-08-16 11:00:17 +08:00
|
|
|
|
|
|
|
/* HQD registers extend from CP_MQD_BASE_ADDR to CP_MQD_CONTROL. */
|
|
|
|
mqd_hqd = &m->cp_mqd_base_addr_lo;
|
|
|
|
|
|
|
|
for (reg = mmCP_MQD_BASE_ADDR; reg <= mmCP_MQD_CONTROL; reg++)
|
|
|
|
WREG32(reg, mqd_hqd[reg - mmCP_MQD_BASE_ADDR]);
|
|
|
|
|
|
|
|
/* Copy userspace write pointer value to register.
|
|
|
|
* Activate doorbell logic to monitor subsequent changes.
|
|
|
|
*/
|
|
|
|
data = REG_SET_FIELD(m->cp_hqd_pq_doorbell_control,
|
|
|
|
CP_HQD_PQ_DOORBELL_CONTROL, DOORBELL_EN, 1);
|
|
|
|
WREG32(mmCP_HQD_PQ_DOORBELL_CONTROL, data);
|
|
|
|
|
2017-09-28 05:53:12 +08:00
|
|
|
/* read_user_ptr may take the mm->mmap_sem.
|
|
|
|
* release srbm_mutex to avoid circular dependency between
|
|
|
|
* srbm_mutex->mm_sem->reservation_ww_class_mutex->srbm_mutex.
|
|
|
|
*/
|
|
|
|
release_queue(kgd);
|
|
|
|
valid_wptr = read_user_wptr(mm, wptr, wptr_val);
|
|
|
|
acquire_queue(kgd, pipe_id, queue_id);
|
|
|
|
if (valid_wptr)
|
2017-08-16 11:00:17 +08:00
|
|
|
WREG32(mmCP_HQD_PQ_WPTR, (wptr_val << wptr_shift) & wptr_mask);
|
|
|
|
|
|
|
|
data = REG_SET_FIELD(m->cp_hqd_active, CP_HQD_ACTIVE, ACTIVE, 1);
|
|
|
|
WREG32(mmCP_HQD_ACTIVE, data);
|
|
|
|
|
2015-06-13 02:38:22 +08:00
|
|
|
release_queue(kgd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-28 07:29:48 +08:00
|
|
|
static int kgd_hqd_dump(struct kgd_dev *kgd,
|
|
|
|
uint32_t pipe_id, uint32_t queue_id,
|
|
|
|
uint32_t (**dump)[2], uint32_t *n_regs)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
uint32_t i = 0, reg;
|
|
|
|
#define HQD_N_REGS (35+4)
|
|
|
|
#define DUMP_REG(addr) do { \
|
|
|
|
if (WARN_ON_ONCE(i >= HQD_N_REGS)) \
|
|
|
|
break; \
|
|
|
|
(*dump)[i][0] = (addr) << 2; \
|
|
|
|
(*dump)[i++][1] = RREG32(addr); \
|
|
|
|
} while (0)
|
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:55:00 +08:00
|
|
|
*dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
|
2017-11-28 07:29:48 +08:00
|
|
|
if (*dump == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
acquire_queue(kgd, pipe_id, queue_id);
|
|
|
|
|
|
|
|
DUMP_REG(mmCOMPUTE_STATIC_THREAD_MGMT_SE0);
|
|
|
|
DUMP_REG(mmCOMPUTE_STATIC_THREAD_MGMT_SE1);
|
|
|
|
DUMP_REG(mmCOMPUTE_STATIC_THREAD_MGMT_SE2);
|
|
|
|
DUMP_REG(mmCOMPUTE_STATIC_THREAD_MGMT_SE3);
|
|
|
|
|
|
|
|
for (reg = mmCP_MQD_BASE_ADDR; reg <= mmCP_MQD_CONTROL; reg++)
|
|
|
|
DUMP_REG(reg);
|
|
|
|
|
|
|
|
release_queue(kgd);
|
|
|
|
|
|
|
|
WARN_ON_ONCE(i != HQD_N_REGS);
|
|
|
|
*n_regs = i;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-02 07:21:58 +08:00
|
|
|
static int kgd_hqd_sdma_load(struct kgd_dev *kgd, void *mqd,
|
|
|
|
uint32_t __user *wptr, struct mm_struct *mm)
|
2015-06-13 02:38:22 +08:00
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
struct cik_sdma_rlc_registers *m;
|
2017-11-02 07:21:55 +08:00
|
|
|
unsigned long end_jiffies;
|
2019-09-22 05:46:03 +08:00
|
|
|
uint32_t sdma_rlc_reg_offset;
|
2017-11-02 07:21:55 +08:00
|
|
|
uint32_t data;
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
m = get_sdma_mqd(mqd);
|
2019-09-22 05:46:03 +08:00
|
|
|
sdma_rlc_reg_offset = get_sdma_rlc_reg_offset(m);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_CNTL,
|
2017-11-02 07:21:55 +08:00
|
|
|
m->sdma_rlc_rb_cntl & (~SDMA0_RLC0_RB_CNTL__RB_ENABLE_MASK));
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2017-11-02 07:21:55 +08:00
|
|
|
end_jiffies = msecs_to_jiffies(2000) + jiffies;
|
|
|
|
while (true) {
|
2019-09-22 05:46:03 +08:00
|
|
|
data = RREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_CONTEXT_STATUS);
|
2017-11-02 07:21:55 +08:00
|
|
|
if (data & SDMA0_RLC0_CONTEXT_STATUS__IDLE_MASK)
|
|
|
|
break;
|
2019-09-20 00:42:34 +08:00
|
|
|
if (time_after(jiffies, end_jiffies)) {
|
|
|
|
pr_err("SDMA RLC not idle in %s\n", __func__);
|
2017-11-02 07:21:55 +08:00
|
|
|
return -ETIME;
|
2019-09-20 00:42:34 +08:00
|
|
|
}
|
2017-11-02 07:21:55 +08:00
|
|
|
usleep_range(500, 1000);
|
|
|
|
}
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2017-11-02 07:21:59 +08:00
|
|
|
data = REG_SET_FIELD(m->sdma_rlc_doorbell, SDMA0_RLC0_DOORBELL,
|
|
|
|
ENABLE, 1);
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_DOORBELL, data);
|
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_RPTR,
|
|
|
|
m->sdma_rlc_rb_rptr);
|
2017-11-02 07:21:59 +08:00
|
|
|
|
|
|
|
if (read_user_wptr(mm, wptr, data))
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_WPTR, data);
|
2017-11-02 07:21:59 +08:00
|
|
|
else
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_WPTR,
|
2017-11-02 07:21:59 +08:00
|
|
|
m->sdma_rlc_rb_rptr);
|
|
|
|
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_VIRTUAL_ADDR,
|
2017-11-02 07:21:55 +08:00
|
|
|
m->sdma_rlc_virtual_addr);
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_BASE, m->sdma_rlc_rb_base);
|
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_BASE_HI,
|
2015-06-13 02:38:22 +08:00
|
|
|
m->sdma_rlc_rb_base_hi);
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_RPTR_ADDR_LO,
|
2015-06-13 02:38:22 +08:00
|
|
|
m->sdma_rlc_rb_rptr_addr_lo);
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_RPTR_ADDR_HI,
|
2015-06-13 02:38:22 +08:00
|
|
|
m->sdma_rlc_rb_rptr_addr_hi);
|
2017-11-02 07:21:59 +08:00
|
|
|
|
|
|
|
data = REG_SET_FIELD(m->sdma_rlc_rb_cntl, SDMA0_RLC0_RB_CNTL,
|
|
|
|
RB_ENABLE, 1);
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_CNTL, data);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-28 07:29:48 +08:00
|
|
|
static int kgd_hqd_sdma_dump(struct kgd_dev *kgd,
|
|
|
|
uint32_t engine_id, uint32_t queue_id,
|
|
|
|
uint32_t (**dump)[2], uint32_t *n_regs)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
uint32_t sdma_offset = engine_id * SDMA1_REGISTER_OFFSET +
|
|
|
|
queue_id * KFD_CIK_SDMA_QUEUE_OFFSET;
|
|
|
|
uint32_t i = 0, reg;
|
|
|
|
#undef HQD_N_REGS
|
|
|
|
#define HQD_N_REGS (19+4)
|
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:55:00 +08:00
|
|
|
*dump = kmalloc_array(HQD_N_REGS * 2, sizeof(uint32_t), GFP_KERNEL);
|
2017-11-28 07:29:48 +08:00
|
|
|
if (*dump == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (reg = mmSDMA0_RLC0_RB_CNTL; reg <= mmSDMA0_RLC0_DOORBELL; reg++)
|
|
|
|
DUMP_REG(sdma_offset + reg);
|
|
|
|
for (reg = mmSDMA0_RLC0_VIRTUAL_ADDR; reg <= mmSDMA0_RLC0_WATERMARK;
|
|
|
|
reg++)
|
|
|
|
DUMP_REG(sdma_offset + reg);
|
|
|
|
|
|
|
|
WARN_ON_ONCE(i != HQD_N_REGS);
|
|
|
|
*n_regs = i;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-13 02:38:22 +08:00
|
|
|
static bool kgd_hqd_is_occupied(struct kgd_dev *kgd, uint64_t queue_address,
|
|
|
|
uint32_t pipe_id, uint32_t queue_id)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
uint32_t act;
|
|
|
|
bool retval = false;
|
|
|
|
uint32_t low, high;
|
|
|
|
|
|
|
|
acquire_queue(kgd, pipe_id, queue_id);
|
|
|
|
act = RREG32(mmCP_HQD_ACTIVE);
|
|
|
|
if (act) {
|
|
|
|
low = lower_32_bits(queue_address >> 8);
|
|
|
|
high = upper_32_bits(queue_address >> 8);
|
|
|
|
|
|
|
|
if (low == RREG32(mmCP_HQD_PQ_BASE) &&
|
|
|
|
high == RREG32(mmCP_HQD_PQ_BASE_HI))
|
|
|
|
retval = true;
|
|
|
|
}
|
|
|
|
release_queue(kgd);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool kgd_hqd_sdma_is_occupied(struct kgd_dev *kgd, void *mqd)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
struct cik_sdma_rlc_registers *m;
|
2019-09-22 05:46:03 +08:00
|
|
|
uint32_t sdma_rlc_reg_offset;
|
2015-06-13 02:38:22 +08:00
|
|
|
uint32_t sdma_rlc_rb_cntl;
|
|
|
|
|
|
|
|
m = get_sdma_mqd(mqd);
|
2019-09-22 05:46:03 +08:00
|
|
|
sdma_rlc_reg_offset = get_sdma_rlc_reg_offset(m);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2019-09-22 05:46:03 +08:00
|
|
|
sdma_rlc_rb_cntl = RREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_CNTL);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
if (sdma_rlc_rb_cntl & SDMA0_RLC0_RB_CNTL__RB_ENABLE_MASK)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-16 11:00:17 +08:00
|
|
|
static int kgd_hqd_destroy(struct kgd_dev *kgd, void *mqd,
|
|
|
|
enum kfd_preempt_type reset_type,
|
2016-09-17 13:01:43 +08:00
|
|
|
unsigned int utimeout, uint32_t pipe_id,
|
2015-06-13 02:38:22 +08:00
|
|
|
uint32_t queue_id)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
uint32_t temp;
|
2017-08-16 11:00:17 +08:00
|
|
|
enum hqd_dequeue_request_type type;
|
|
|
|
unsigned long flags, end_jiffies;
|
|
|
|
int retry;
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2018-07-12 10:33:03 +08:00
|
|
|
if (adev->in_gpu_reset)
|
|
|
|
return -EIO;
|
|
|
|
|
2015-06-13 02:38:22 +08:00
|
|
|
acquire_queue(kgd, pipe_id, queue_id);
|
|
|
|
WREG32(mmCP_HQD_PQ_DOORBELL_CONTROL, 0);
|
|
|
|
|
2017-08-16 11:00:17 +08:00
|
|
|
switch (reset_type) {
|
|
|
|
case KFD_PREEMPT_TYPE_WAVEFRONT_DRAIN:
|
|
|
|
type = DRAIN_PIPE;
|
|
|
|
break;
|
|
|
|
case KFD_PREEMPT_TYPE_WAVEFRONT_RESET:
|
|
|
|
type = RESET_WAVES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = DRAIN_PIPE;
|
|
|
|
break;
|
|
|
|
}
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2017-08-16 11:00:17 +08:00
|
|
|
/* Workaround: If IQ timer is active and the wait time is close to or
|
|
|
|
* equal to 0, dequeueing is not safe. Wait until either the wait time
|
|
|
|
* is larger or timer is cleared. Also, ensure that IQ_REQ_PEND is
|
|
|
|
* cleared before continuing. Also, ensure wait times are set to at
|
|
|
|
* least 0x3.
|
|
|
|
*/
|
|
|
|
local_irq_save(flags);
|
|
|
|
preempt_disable();
|
|
|
|
retry = 5000; /* wait for 500 usecs at maximum */
|
|
|
|
while (true) {
|
|
|
|
temp = RREG32(mmCP_HQD_IQ_TIMER);
|
|
|
|
if (REG_GET_FIELD(temp, CP_HQD_IQ_TIMER, PROCESSING_IQ)) {
|
|
|
|
pr_debug("HW is processing IQ\n");
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
if (REG_GET_FIELD(temp, CP_HQD_IQ_TIMER, ACTIVE)) {
|
|
|
|
if (REG_GET_FIELD(temp, CP_HQD_IQ_TIMER, RETRY_TYPE)
|
|
|
|
== 3) /* SEM-rearm is safe */
|
|
|
|
break;
|
|
|
|
/* Wait time 3 is safe for CP, but our MMIO read/write
|
|
|
|
* time is close to 1 microsecond, so check for 10 to
|
|
|
|
* leave more buffer room
|
|
|
|
*/
|
|
|
|
if (REG_GET_FIELD(temp, CP_HQD_IQ_TIMER, WAIT_TIME)
|
|
|
|
>= 10)
|
|
|
|
break;
|
|
|
|
pr_debug("IQ timer is active\n");
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
loop:
|
|
|
|
if (!retry) {
|
|
|
|
pr_err("CP HQD IQ timer status time out\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ndelay(100);
|
|
|
|
--retry;
|
|
|
|
}
|
|
|
|
retry = 1000;
|
|
|
|
while (true) {
|
|
|
|
temp = RREG32(mmCP_HQD_DEQUEUE_REQUEST);
|
|
|
|
if (!(temp & CP_HQD_DEQUEUE_REQUEST__IQ_REQ_PEND_MASK))
|
|
|
|
break;
|
|
|
|
pr_debug("Dequeue request is pending\n");
|
|
|
|
|
|
|
|
if (!retry) {
|
|
|
|
pr_err("CP HQD dequeue request time out\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ndelay(100);
|
|
|
|
--retry;
|
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
preempt_enable();
|
|
|
|
|
|
|
|
WREG32(mmCP_HQD_DEQUEUE_REQUEST, type);
|
|
|
|
|
|
|
|
end_jiffies = (utimeout * HZ / 1000) + jiffies;
|
2015-06-13 02:38:22 +08:00
|
|
|
while (true) {
|
|
|
|
temp = RREG32(mmCP_HQD_ACTIVE);
|
2017-08-16 11:00:17 +08:00
|
|
|
if (!(temp & CP_HQD_ACTIVE__ACTIVE_MASK))
|
2015-06-13 02:38:22 +08:00
|
|
|
break;
|
2017-08-16 11:00:17 +08:00
|
|
|
if (time_after(jiffies, end_jiffies)) {
|
|
|
|
pr_err("cp queue preemption time out\n");
|
2015-06-13 02:38:22 +08:00
|
|
|
release_queue(kgd);
|
|
|
|
return -ETIME;
|
|
|
|
}
|
2017-08-16 11:00:17 +08:00
|
|
|
usleep_range(500, 1000);
|
2015-06-13 02:38:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
release_queue(kgd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd,
|
2016-09-17 13:01:43 +08:00
|
|
|
unsigned int utimeout)
|
2015-06-13 02:38:22 +08:00
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
struct cik_sdma_rlc_registers *m;
|
2019-09-22 05:46:03 +08:00
|
|
|
uint32_t sdma_rlc_reg_offset;
|
2015-06-13 02:38:22 +08:00
|
|
|
uint32_t temp;
|
2017-11-02 07:21:59 +08:00
|
|
|
unsigned long end_jiffies = (utimeout * HZ / 1000) + jiffies;
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
m = get_sdma_mqd(mqd);
|
2019-09-22 05:46:03 +08:00
|
|
|
sdma_rlc_reg_offset = get_sdma_rlc_reg_offset(m);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2019-09-22 05:46:03 +08:00
|
|
|
temp = RREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_CNTL);
|
2015-06-13 02:38:22 +08:00
|
|
|
temp = temp & ~SDMA0_RLC0_RB_CNTL__RB_ENABLE_MASK;
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_CNTL, temp);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
|
|
|
while (true) {
|
2019-09-22 05:46:03 +08:00
|
|
|
temp = RREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_CONTEXT_STATUS);
|
2018-09-13 09:42:18 +08:00
|
|
|
if (temp & SDMA0_RLC0_CONTEXT_STATUS__IDLE_MASK)
|
2015-06-13 02:38:22 +08:00
|
|
|
break;
|
2019-09-20 00:42:34 +08:00
|
|
|
if (time_after(jiffies, end_jiffies)) {
|
|
|
|
pr_err("SDMA RLC not idle in %s\n", __func__);
|
2015-06-13 02:38:22 +08:00
|
|
|
return -ETIME;
|
2019-09-20 00:42:34 +08:00
|
|
|
}
|
2017-11-02 07:21:59 +08:00
|
|
|
usleep_range(500, 1000);
|
2015-06-13 02:38:22 +08:00
|
|
|
}
|
|
|
|
|
2019-09-22 05:46:03 +08:00
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_DOORBELL, 0);
|
|
|
|
WREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_CNTL,
|
|
|
|
RREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_CNTL) |
|
2017-11-02 07:21:55 +08:00
|
|
|
SDMA0_RLC0_RB_CNTL__RB_ENABLE_MASK);
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2019-09-22 05:46:03 +08:00
|
|
|
m->sdma_rlc_rb_rptr = RREG32(sdma_rlc_reg_offset + mmSDMA0_RLC0_RB_RPTR);
|
2017-11-02 07:21:59 +08:00
|
|
|
|
2015-06-13 02:38:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kgd_address_watch_disable(struct kgd_dev *kgd)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
union TCP_WATCH_CNTL_BITS cntl;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
cntl.u32All = 0;
|
|
|
|
|
|
|
|
cntl.bitfields.valid = 0;
|
|
|
|
cntl.bitfields.mask = ADDRESS_WATCH_REG_CNTL_DEFAULT_MASK;
|
|
|
|
cntl.bitfields.atc = 1;
|
|
|
|
|
|
|
|
/* Turning off this address until we set all the registers */
|
|
|
|
for (i = 0; i < MAX_WATCH_ADDRESSES; i++)
|
|
|
|
WREG32(watchRegs[i * ADDRESS_WATCH_REG_MAX +
|
|
|
|
ADDRESS_WATCH_REG_CNTL], cntl.u32All);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kgd_address_watch_execute(struct kgd_dev *kgd,
|
|
|
|
unsigned int watch_point_id,
|
|
|
|
uint32_t cntl_val,
|
|
|
|
uint32_t addr_hi,
|
|
|
|
uint32_t addr_lo)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
union TCP_WATCH_CNTL_BITS cntl;
|
|
|
|
|
|
|
|
cntl.u32All = cntl_val;
|
|
|
|
|
|
|
|
/* Turning off this watch point until we set all the registers */
|
|
|
|
cntl.bitfields.valid = 0;
|
|
|
|
WREG32(watchRegs[watch_point_id * ADDRESS_WATCH_REG_MAX +
|
|
|
|
ADDRESS_WATCH_REG_CNTL], cntl.u32All);
|
|
|
|
|
|
|
|
WREG32(watchRegs[watch_point_id * ADDRESS_WATCH_REG_MAX +
|
|
|
|
ADDRESS_WATCH_REG_ADDR_HI], addr_hi);
|
|
|
|
|
|
|
|
WREG32(watchRegs[watch_point_id * ADDRESS_WATCH_REG_MAX +
|
|
|
|
ADDRESS_WATCH_REG_ADDR_LO], addr_lo);
|
|
|
|
|
|
|
|
/* Enable the watch point */
|
|
|
|
cntl.bitfields.valid = 1;
|
|
|
|
|
|
|
|
WREG32(watchRegs[watch_point_id * ADDRESS_WATCH_REG_MAX +
|
|
|
|
ADDRESS_WATCH_REG_CNTL], cntl.u32All);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kgd_wave_control_execute(struct kgd_dev *kgd,
|
|
|
|
uint32_t gfx_index_val,
|
|
|
|
uint32_t sq_cmd)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
uint32_t data;
|
|
|
|
|
|
|
|
mutex_lock(&adev->grbm_idx_mutex);
|
|
|
|
|
|
|
|
WREG32(mmGRBM_GFX_INDEX, gfx_index_val);
|
|
|
|
WREG32(mmSQ_CMD, sq_cmd);
|
|
|
|
|
|
|
|
/* Restore the GRBM_GFX_INDEX register */
|
|
|
|
|
|
|
|
data = GRBM_GFX_INDEX__INSTANCE_BROADCAST_WRITES_MASK |
|
|
|
|
GRBM_GFX_INDEX__SH_BROADCAST_WRITES_MASK |
|
|
|
|
GRBM_GFX_INDEX__SE_BROADCAST_WRITES_MASK;
|
|
|
|
|
|
|
|
WREG32(mmGRBM_GFX_INDEX, data);
|
|
|
|
|
|
|
|
mutex_unlock(&adev->grbm_idx_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t kgd_address_watch_get_offset(struct kgd_dev *kgd,
|
|
|
|
unsigned int watch_point_id,
|
|
|
|
unsigned int reg_offset)
|
|
|
|
{
|
|
|
|
return watchRegs[watch_point_id * ADDRESS_WATCH_REG_MAX + reg_offset];
|
|
|
|
}
|
|
|
|
|
2019-09-26 11:57:30 +08:00
|
|
|
static bool get_atc_vmid_pasid_mapping_info(struct kgd_dev *kgd,
|
|
|
|
uint8_t vmid, uint16_t *p_pasid)
|
2015-06-13 02:38:22 +08:00
|
|
|
{
|
2019-09-26 11:57:30 +08:00
|
|
|
uint32_t value;
|
2015-06-13 02:38:22 +08:00
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *) kgd;
|
|
|
|
|
2019-09-26 11:57:30 +08:00
|
|
|
value = RREG32(mmATC_VMID0_PASID_MAPPING + vmid);
|
|
|
|
*p_pasid = value & ATC_VMID0_PASID_MAPPING__PASID_MASK;
|
2015-06-13 02:38:22 +08:00
|
|
|
|
2019-09-26 11:57:30 +08:00
|
|
|
return !!(value & ATC_VMID0_PASID_MAPPING__VALID_MASK);
|
2015-06-13 02:38:22 +08:00
|
|
|
}
|
|
|
|
|
2017-08-16 11:00:19 +08:00
|
|
|
static void set_scratch_backing_va(struct kgd_dev *kgd,
|
|
|
|
uint64_t va, uint32_t vmid)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = (struct amdgpu_device *) kgd;
|
|
|
|
|
|
|
|
lock_srbm(kgd, 0, 0, 0, vmid);
|
|
|
|
WREG32(mmSH_HIDDEN_PRIVATE_BASE_VMID, va);
|
|
|
|
unlock_srbm(kgd);
|
|
|
|
}
|
|
|
|
|
2018-02-07 09:32:38 +08:00
|
|
|
static void set_vm_context_page_table_base(struct kgd_dev *kgd, uint32_t vmid,
|
2018-03-14 05:44:09 +08:00
|
|
|
uint64_t page_table_base)
|
2018-02-07 09:32:38 +08:00
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
|
|
|
|
if (!amdgpu_amdkfd_is_kfd_vmid(adev, vmid)) {
|
|
|
|
pr_err("trying to set page table base for wrong VMID\n");
|
|
|
|
return;
|
|
|
|
}
|
2018-03-14 05:44:09 +08:00
|
|
|
WREG32(mmVM_CONTEXT8_PAGE_TABLE_BASE_ADDR + vmid - 8,
|
|
|
|
lower_32_bits(page_table_base));
|
2018-02-07 09:32:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-12 10:32:51 +08:00
|
|
|
/**
|
|
|
|
* read_vmid_from_vmfault_reg - read vmid from register
|
|
|
|
*
|
|
|
|
* adev: amdgpu_device pointer
|
|
|
|
* @vmid: vmid pointer
|
|
|
|
* read vmid from register (CIK).
|
|
|
|
*/
|
|
|
|
static uint32_t read_vmid_from_vmfault_reg(struct kgd_dev *kgd)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = get_amdgpu_device(kgd);
|
|
|
|
|
|
|
|
uint32_t status = RREG32(mmVM_CONTEXT1_PROTECTION_FAULT_STATUS);
|
|
|
|
|
|
|
|
return REG_GET_FIELD(status, VM_CONTEXT1_PROTECTION_FAULT_STATUS, VMID);
|
|
|
|
}
|
2019-09-28 09:22:07 +08:00
|
|
|
|
2019-09-28 10:03:42 +08:00
|
|
|
const struct kfd2kgd_calls gfx_v7_kfd2kgd = {
|
2019-09-28 09:22:07 +08:00
|
|
|
.program_sh_mem_settings = kgd_program_sh_mem_settings,
|
|
|
|
.set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping,
|
|
|
|
.init_interrupts = kgd_init_interrupts,
|
|
|
|
.hqd_load = kgd_hqd_load,
|
|
|
|
.hqd_sdma_load = kgd_hqd_sdma_load,
|
|
|
|
.hqd_dump = kgd_hqd_dump,
|
|
|
|
.hqd_sdma_dump = kgd_hqd_sdma_dump,
|
|
|
|
.hqd_is_occupied = kgd_hqd_is_occupied,
|
|
|
|
.hqd_sdma_is_occupied = kgd_hqd_sdma_is_occupied,
|
|
|
|
.hqd_destroy = kgd_hqd_destroy,
|
|
|
|
.hqd_sdma_destroy = kgd_hqd_sdma_destroy,
|
|
|
|
.address_watch_disable = kgd_address_watch_disable,
|
|
|
|
.address_watch_execute = kgd_address_watch_execute,
|
|
|
|
.wave_control_execute = kgd_wave_control_execute,
|
|
|
|
.address_watch_get_offset = kgd_address_watch_get_offset,
|
|
|
|
.get_atc_vmid_pasid_mapping_info = get_atc_vmid_pasid_mapping_info,
|
|
|
|
.set_scratch_backing_va = set_scratch_backing_va,
|
|
|
|
.set_vm_context_page_table_base = set_vm_context_page_table_base,
|
|
|
|
.read_vmid_from_vmfault_reg = read_vmid_from_vmfault_reg,
|
|
|
|
};
|