Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.0 205 lines 5.0 kB view raw
1/* 2 * caam descriptor construction helper functions 3 * 4 * Copyright 2008-2011 Freescale Semiconductor, Inc. 5 */ 6 7#include "desc.h" 8 9#define IMMEDIATE (1 << 23) 10#define CAAM_CMD_SZ sizeof(u32) 11#define CAAM_PTR_SZ sizeof(dma_addr_t) 12#define CAAM_DESC_BYTES_MAX (CAAM_CMD_SZ * 64) 13 14#ifdef DEBUG 15#define PRINT_POS do { printk(KERN_DEBUG "%02d: %s\n", desc_len(desc),\ 16 &__func__[sizeof("append")]); } while (0) 17#else 18#define PRINT_POS 19#endif 20 21#define DISABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \ 22 LDST_SRCDST_WORD_DECOCTRL | \ 23 (LDOFF_DISABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT)) 24#define ENABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \ 25 LDST_SRCDST_WORD_DECOCTRL | \ 26 (LDOFF_ENABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT)) 27 28static inline int desc_len(u32 *desc) 29{ 30 return *desc & HDR_DESCLEN_MASK; 31} 32 33static inline int desc_bytes(void *desc) 34{ 35 return desc_len(desc) * CAAM_CMD_SZ; 36} 37 38static inline u32 *desc_end(u32 *desc) 39{ 40 return desc + desc_len(desc); 41} 42 43static inline void *sh_desc_pdb(u32 *desc) 44{ 45 return desc + 1; 46} 47 48static inline void init_desc(u32 *desc, u32 options) 49{ 50 *desc = options | HDR_ONE | 1; 51} 52 53static inline void init_sh_desc(u32 *desc, u32 options) 54{ 55 PRINT_POS; 56 init_desc(desc, CMD_SHARED_DESC_HDR | options); 57} 58 59static inline void init_sh_desc_pdb(u32 *desc, u32 options, size_t pdb_bytes) 60{ 61 u32 pdb_len = pdb_bytes / CAAM_CMD_SZ + 1; 62 63 init_sh_desc(desc, ((pdb_len << HDR_START_IDX_SHIFT) + pdb_len) | 64 options); 65} 66 67static inline void init_job_desc(u32 *desc, u32 options) 68{ 69 init_desc(desc, CMD_DESC_HDR | options); 70} 71 72static inline void append_ptr(u32 *desc, dma_addr_t ptr) 73{ 74 dma_addr_t *offset = (dma_addr_t *)desc_end(desc); 75 76 *offset = ptr; 77 78 (*desc) += CAAM_PTR_SZ / CAAM_CMD_SZ; 79} 80 81static inline void init_job_desc_shared(u32 *desc, dma_addr_t ptr, int len, 82 u32 options) 83{ 84 PRINT_POS; 85 init_job_desc(desc, HDR_SHARED | options | 86 (len << HDR_START_IDX_SHIFT)); 87 append_ptr(desc, ptr); 88} 89 90static inline void append_data(u32 *desc, void *data, int len) 91{ 92 u32 *offset = desc_end(desc); 93 94 if (len) /* avoid sparse warning: memcpy with byte count of 0 */ 95 memcpy(offset, data, len); 96 97 (*desc) += (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ; 98} 99 100static inline void append_cmd(u32 *desc, u32 command) 101{ 102 u32 *cmd = desc_end(desc); 103 104 *cmd = command; 105 106 (*desc)++; 107} 108 109static inline void append_cmd_ptr(u32 *desc, dma_addr_t ptr, int len, 110 u32 command) 111{ 112 append_cmd(desc, command | len); 113 append_ptr(desc, ptr); 114} 115 116static inline void append_cmd_data(u32 *desc, void *data, int len, 117 u32 command) 118{ 119 append_cmd(desc, command | IMMEDIATE | len); 120 append_data(desc, data, len); 121} 122 123static inline u32 *append_jump(u32 *desc, u32 options) 124{ 125 u32 *cmd = desc_end(desc); 126 127 PRINT_POS; 128 append_cmd(desc, CMD_JUMP | options); 129 130 return cmd; 131} 132 133static inline void set_jump_tgt_here(u32 *desc, u32 *jump_cmd) 134{ 135 *jump_cmd = *jump_cmd | (desc_len(desc) - (jump_cmd - desc)); 136} 137 138#define APPEND_CMD(cmd, op) \ 139static inline void append_##cmd(u32 *desc, u32 options) \ 140{ \ 141 PRINT_POS; \ 142 append_cmd(desc, CMD_##op | options); \ 143} 144APPEND_CMD(operation, OPERATION) 145APPEND_CMD(move, MOVE) 146 147#define APPEND_CMD_LEN(cmd, op) \ 148static inline void append_##cmd(u32 *desc, unsigned int len, u32 options) \ 149{ \ 150 PRINT_POS; \ 151 append_cmd(desc, CMD_##op | len | options); \ 152} 153APPEND_CMD_LEN(seq_store, SEQ_STORE) 154APPEND_CMD_LEN(seq_fifo_load, SEQ_FIFO_LOAD) 155APPEND_CMD_LEN(seq_fifo_store, SEQ_FIFO_STORE) 156 157#define APPEND_CMD_PTR(cmd, op) \ 158static inline void append_##cmd(u32 *desc, dma_addr_t ptr, unsigned int len, \ 159 u32 options) \ 160{ \ 161 PRINT_POS; \ 162 append_cmd_ptr(desc, ptr, len, CMD_##op | options); \ 163} 164APPEND_CMD_PTR(key, KEY) 165APPEND_CMD_PTR(seq_in_ptr, SEQ_IN_PTR) 166APPEND_CMD_PTR(seq_out_ptr, SEQ_OUT_PTR) 167APPEND_CMD_PTR(load, LOAD) 168APPEND_CMD_PTR(store, STORE) 169APPEND_CMD_PTR(fifo_load, FIFO_LOAD) 170APPEND_CMD_PTR(fifo_store, FIFO_STORE) 171 172#define APPEND_CMD_PTR_TO_IMM(cmd, op) \ 173static inline void append_##cmd##_as_imm(u32 *desc, void *data, \ 174 unsigned int len, u32 options) \ 175{ \ 176 PRINT_POS; \ 177 append_cmd_data(desc, data, len, CMD_##op | options); \ 178} 179APPEND_CMD_PTR_TO_IMM(load, LOAD); 180APPEND_CMD_PTR_TO_IMM(fifo_load, FIFO_LOAD); 181 182/* 183 * 2nd variant for commands whose specified immediate length differs 184 * from length of immediate data provided, e.g., split keys 185 */ 186#define APPEND_CMD_PTR_TO_IMM2(cmd, op) \ 187static inline void append_##cmd##_as_imm(u32 *desc, void *data, \ 188 unsigned int data_len, \ 189 unsigned int len, u32 options) \ 190{ \ 191 PRINT_POS; \ 192 append_cmd(desc, CMD_##op | IMMEDIATE | len | options); \ 193 append_data(desc, data, data_len); \ 194} 195APPEND_CMD_PTR_TO_IMM2(key, KEY); 196 197#define APPEND_CMD_RAW_IMM(cmd, op, type) \ 198static inline void append_##cmd##_imm_##type(u32 *desc, type immediate, \ 199 u32 options) \ 200{ \ 201 PRINT_POS; \ 202 append_cmd(desc, CMD_##op | IMMEDIATE | options | sizeof(type)); \ 203 append_cmd(desc, immediate); \ 204} 205APPEND_CMD_RAW_IMM(load, LOAD, u32);