162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2017-2020 Xilinx, Inc. All rights reserved. 462306a36Sopenharmony_ci * Copyright (C) 2022, Advanced Micro Devices, Inc. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef __DMA_XDMA_REGS_H 862306a36Sopenharmony_ci#define __DMA_XDMA_REGS_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci/* The length of register space exposed to host */ 1162306a36Sopenharmony_ci#define XDMA_REG_SPACE_LEN 65536 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* 1462306a36Sopenharmony_ci * maximum number of DMA channels for each direction: 1562306a36Sopenharmony_ci * Host to Card (H2C) or Card to Host (C2H) 1662306a36Sopenharmony_ci */ 1762306a36Sopenharmony_ci#define XDMA_MAX_CHANNELS 4 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* 2062306a36Sopenharmony_ci * macros to define the number of descriptor blocks can be used in one 2162306a36Sopenharmony_ci * DMA transfer request. 2262306a36Sopenharmony_ci * the DMA engine uses a linked list of descriptor blocks that specify the 2362306a36Sopenharmony_ci * source, destination, and length of the DMA transfers. 2462306a36Sopenharmony_ci */ 2562306a36Sopenharmony_ci#define XDMA_DESC_BLOCK_NUM BIT(7) 2662306a36Sopenharmony_ci#define XDMA_DESC_BLOCK_MASK (XDMA_DESC_BLOCK_NUM - 1) 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/* descriptor definitions */ 2962306a36Sopenharmony_ci#define XDMA_DESC_ADJACENT 32 3062306a36Sopenharmony_ci#define XDMA_DESC_ADJACENT_MASK (XDMA_DESC_ADJACENT - 1) 3162306a36Sopenharmony_ci#define XDMA_DESC_ADJACENT_BITS GENMASK(13, 8) 3262306a36Sopenharmony_ci#define XDMA_DESC_MAGIC 0xad4bUL 3362306a36Sopenharmony_ci#define XDMA_DESC_MAGIC_BITS GENMASK(31, 16) 3462306a36Sopenharmony_ci#define XDMA_DESC_FLAGS_BITS GENMASK(7, 0) 3562306a36Sopenharmony_ci#define XDMA_DESC_STOPPED BIT(0) 3662306a36Sopenharmony_ci#define XDMA_DESC_COMPLETED BIT(1) 3762306a36Sopenharmony_ci#define XDMA_DESC_BLEN_BITS 28 3862306a36Sopenharmony_ci#define XDMA_DESC_BLEN_MAX (BIT(XDMA_DESC_BLEN_BITS) - PAGE_SIZE) 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* macros to construct the descriptor control word */ 4162306a36Sopenharmony_ci#define XDMA_DESC_CONTROL(adjacent, flag) \ 4262306a36Sopenharmony_ci (FIELD_PREP(XDMA_DESC_MAGIC_BITS, XDMA_DESC_MAGIC) | \ 4362306a36Sopenharmony_ci FIELD_PREP(XDMA_DESC_ADJACENT_BITS, (adjacent) - 1) | \ 4462306a36Sopenharmony_ci FIELD_PREP(XDMA_DESC_FLAGS_BITS, (flag))) 4562306a36Sopenharmony_ci#define XDMA_DESC_CONTROL_LAST \ 4662306a36Sopenharmony_ci XDMA_DESC_CONTROL(1, XDMA_DESC_STOPPED | XDMA_DESC_COMPLETED) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* 4962306a36Sopenharmony_ci * Descriptor for a single contiguous memory block transfer. 5062306a36Sopenharmony_ci * 5162306a36Sopenharmony_ci * Multiple descriptors are linked by means of the next pointer. An additional 5262306a36Sopenharmony_ci * extra adjacent number gives the amount of extra contiguous descriptors. 5362306a36Sopenharmony_ci * 5462306a36Sopenharmony_ci * The descriptors are in root complex memory, and the bytes in the 32-bit 5562306a36Sopenharmony_ci * words must be in little-endian byte ordering. 5662306a36Sopenharmony_ci */ 5762306a36Sopenharmony_cistruct xdma_hw_desc { 5862306a36Sopenharmony_ci __le32 control; 5962306a36Sopenharmony_ci __le32 bytes; 6062306a36Sopenharmony_ci __le64 src_addr; 6162306a36Sopenharmony_ci __le64 dst_addr; 6262306a36Sopenharmony_ci __le64 next_desc; 6362306a36Sopenharmony_ci}; 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define XDMA_DESC_SIZE sizeof(struct xdma_hw_desc) 6662306a36Sopenharmony_ci#define XDMA_DESC_BLOCK_SIZE (XDMA_DESC_SIZE * XDMA_DESC_ADJACENT) 6762306a36Sopenharmony_ci#define XDMA_DESC_BLOCK_ALIGN 4096 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci/* 7062306a36Sopenharmony_ci * Channel registers 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci#define XDMA_CHAN_IDENTIFIER 0x0 7362306a36Sopenharmony_ci#define XDMA_CHAN_CONTROL 0x4 7462306a36Sopenharmony_ci#define XDMA_CHAN_CONTROL_W1S 0x8 7562306a36Sopenharmony_ci#define XDMA_CHAN_CONTROL_W1C 0xc 7662306a36Sopenharmony_ci#define XDMA_CHAN_STATUS 0x40 7762306a36Sopenharmony_ci#define XDMA_CHAN_COMPLETED_DESC 0x48 7862306a36Sopenharmony_ci#define XDMA_CHAN_ALIGNMENTS 0x4c 7962306a36Sopenharmony_ci#define XDMA_CHAN_INTR_ENABLE 0x90 8062306a36Sopenharmony_ci#define XDMA_CHAN_INTR_ENABLE_W1S 0x94 8162306a36Sopenharmony_ci#define XDMA_CHAN_INTR_ENABLE_W1C 0x9c 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#define XDMA_CHAN_STRIDE 0x100 8462306a36Sopenharmony_ci#define XDMA_CHAN_H2C_OFFSET 0x0 8562306a36Sopenharmony_ci#define XDMA_CHAN_C2H_OFFSET 0x1000 8662306a36Sopenharmony_ci#define XDMA_CHAN_H2C_TARGET 0x0 8762306a36Sopenharmony_ci#define XDMA_CHAN_C2H_TARGET 0x1 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/* macro to check if channel is available */ 9062306a36Sopenharmony_ci#define XDMA_CHAN_MAGIC 0x1fc0 9162306a36Sopenharmony_ci#define XDMA_CHAN_CHECK_TARGET(id, target) \ 9262306a36Sopenharmony_ci (((u32)(id) >> 16) == XDMA_CHAN_MAGIC + (target)) 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* bits of the channel control register */ 9562306a36Sopenharmony_ci#define CHAN_CTRL_RUN_STOP BIT(0) 9662306a36Sopenharmony_ci#define CHAN_CTRL_IE_DESC_STOPPED BIT(1) 9762306a36Sopenharmony_ci#define CHAN_CTRL_IE_DESC_COMPLETED BIT(2) 9862306a36Sopenharmony_ci#define CHAN_CTRL_IE_DESC_ALIGN_MISMATCH BIT(3) 9962306a36Sopenharmony_ci#define CHAN_CTRL_IE_MAGIC_STOPPED BIT(4) 10062306a36Sopenharmony_ci#define CHAN_CTRL_IE_IDLE_STOPPED BIT(6) 10162306a36Sopenharmony_ci#define CHAN_CTRL_IE_READ_ERROR GENMASK(13, 9) 10262306a36Sopenharmony_ci#define CHAN_CTRL_IE_DESC_ERROR GENMASK(23, 19) 10362306a36Sopenharmony_ci#define CHAN_CTRL_NON_INCR_ADDR BIT(25) 10462306a36Sopenharmony_ci#define CHAN_CTRL_POLL_MODE_WB BIT(26) 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci#define CHAN_CTRL_START (CHAN_CTRL_RUN_STOP | \ 10762306a36Sopenharmony_ci CHAN_CTRL_IE_DESC_STOPPED | \ 10862306a36Sopenharmony_ci CHAN_CTRL_IE_DESC_COMPLETED | \ 10962306a36Sopenharmony_ci CHAN_CTRL_IE_DESC_ALIGN_MISMATCH | \ 11062306a36Sopenharmony_ci CHAN_CTRL_IE_MAGIC_STOPPED | \ 11162306a36Sopenharmony_ci CHAN_CTRL_IE_READ_ERROR | \ 11262306a36Sopenharmony_ci CHAN_CTRL_IE_DESC_ERROR) 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* bits of the channel interrupt enable mask */ 11562306a36Sopenharmony_ci#define CHAN_IM_DESC_ERROR BIT(19) 11662306a36Sopenharmony_ci#define CHAN_IM_READ_ERROR BIT(9) 11762306a36Sopenharmony_ci#define CHAN_IM_IDLE_STOPPED BIT(6) 11862306a36Sopenharmony_ci#define CHAN_IM_MAGIC_STOPPED BIT(4) 11962306a36Sopenharmony_ci#define CHAN_IM_DESC_COMPLETED BIT(2) 12062306a36Sopenharmony_ci#define CHAN_IM_DESC_STOPPED BIT(1) 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci#define CHAN_IM_ALL (CHAN_IM_DESC_ERROR | CHAN_IM_READ_ERROR | \ 12362306a36Sopenharmony_ci CHAN_IM_IDLE_STOPPED | CHAN_IM_MAGIC_STOPPED | \ 12462306a36Sopenharmony_ci CHAN_IM_DESC_COMPLETED | CHAN_IM_DESC_STOPPED) 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci/* 12762306a36Sopenharmony_ci * Channel SGDMA registers 12862306a36Sopenharmony_ci */ 12962306a36Sopenharmony_ci#define XDMA_SGDMA_IDENTIFIER 0x4000 13062306a36Sopenharmony_ci#define XDMA_SGDMA_DESC_LO 0x4080 13162306a36Sopenharmony_ci#define XDMA_SGDMA_DESC_HI 0x4084 13262306a36Sopenharmony_ci#define XDMA_SGDMA_DESC_ADJ 0x4088 13362306a36Sopenharmony_ci#define XDMA_SGDMA_DESC_CREDIT 0x408c 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/* bits of the SG DMA control register */ 13662306a36Sopenharmony_ci#define XDMA_CTRL_RUN_STOP BIT(0) 13762306a36Sopenharmony_ci#define XDMA_CTRL_IE_DESC_STOPPED BIT(1) 13862306a36Sopenharmony_ci#define XDMA_CTRL_IE_DESC_COMPLETED BIT(2) 13962306a36Sopenharmony_ci#define XDMA_CTRL_IE_DESC_ALIGN_MISMATCH BIT(3) 14062306a36Sopenharmony_ci#define XDMA_CTRL_IE_MAGIC_STOPPED BIT(4) 14162306a36Sopenharmony_ci#define XDMA_CTRL_IE_IDLE_STOPPED BIT(6) 14262306a36Sopenharmony_ci#define XDMA_CTRL_IE_READ_ERROR GENMASK(13, 9) 14362306a36Sopenharmony_ci#define XDMA_CTRL_IE_DESC_ERROR GENMASK(23, 19) 14462306a36Sopenharmony_ci#define XDMA_CTRL_NON_INCR_ADDR BIT(25) 14562306a36Sopenharmony_ci#define XDMA_CTRL_POLL_MODE_WB BIT(26) 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci/* 14862306a36Sopenharmony_ci * interrupt registers 14962306a36Sopenharmony_ci */ 15062306a36Sopenharmony_ci#define XDMA_IRQ_IDENTIFIER 0x2000 15162306a36Sopenharmony_ci#define XDMA_IRQ_USER_INT_EN 0x2004 15262306a36Sopenharmony_ci#define XDMA_IRQ_USER_INT_EN_W1S 0x2008 15362306a36Sopenharmony_ci#define XDMA_IRQ_USER_INT_EN_W1C 0x200c 15462306a36Sopenharmony_ci#define XDMA_IRQ_CHAN_INT_EN 0x2010 15562306a36Sopenharmony_ci#define XDMA_IRQ_CHAN_INT_EN_W1S 0x2014 15662306a36Sopenharmony_ci#define XDMA_IRQ_CHAN_INT_EN_W1C 0x2018 15762306a36Sopenharmony_ci#define XDMA_IRQ_USER_INT_REQ 0x2040 15862306a36Sopenharmony_ci#define XDMA_IRQ_CHAN_INT_REQ 0x2044 15962306a36Sopenharmony_ci#define XDMA_IRQ_USER_INT_PEND 0x2048 16062306a36Sopenharmony_ci#define XDMA_IRQ_CHAN_INT_PEND 0x204c 16162306a36Sopenharmony_ci#define XDMA_IRQ_USER_VEC_NUM 0x2080 16262306a36Sopenharmony_ci#define XDMA_IRQ_CHAN_VEC_NUM 0x20a0 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci#define XDMA_IRQ_VEC_SHIFT 8 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci#endif /* __DMA_XDMA_REGS_H */ 167