2 * Copyright (C) 2014 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
7 /* Perform extra checking */
11 #include <linux/types.h>
12 #include <linux/compat.h>
14 #include <fsl-mc/fsl_qbman_base.h>
16 #define QBMAN_CHECKING
18 /* Any time there is a register interface which we poll on, this provides a
19 * "break after x iterations" scheme for it. It's handy for debugging, eg.
20 * where you don't want millions of lines of log output from a polling loop
21 * that won't, because such things tend to drown out the earlier log output
22 * that might explain what caused the problem. (NB: put ";" after each macro!)
23 * TODO: we should probably remove this once we're done sanitising the
26 #define DBG_POLL_START(loopvar) (loopvar = 10)
27 #define DBG_POLL_CHECK(loopvar) \
28 do {if (!(loopvar--)) BUG_ON(NULL == "DBG_POLL_CHECK"); } while (0)
30 /* For CCSR or portal-CINH registers that contain fields at arbitrary offsets
31 * and widths, these macro-generated encode/decode/isolate/remove inlines can
34 * Eg. to "d"ecode a 14-bit field out of a register (into a "uint16_t" type),
35 * where the field is located 3 bits "up" from the least-significant bit of the
36 * register (ie. the field location within the 32-bit register corresponds to a
37 * mask of 0x0001fff8), you would do;
38 * uint16_t field = d32_uint16_t(3, 14, reg_value);
40 * Or to "e"ncode a 1-bit boolean value (input type is "int", zero is FALSE,
41 * non-zero is TRUE, so must convert all non-zero inputs to 1, hence the "!!"
42 * operator) into a register at bit location 0x00080000 (19 bits "in" from the
44 * reg_value |= e32_int(19, 1, !!field);
46 * If you wish to read-modify-write a register, such that you leave the 14-bit
47 * field as-is but have all other fields set to zero, then "i"solate the 14-bit
49 * reg_value = i32_uint16_t(3, 14, reg_value);
51 * Alternatively, you could "r"emove the 1-bit boolean field (setting it to
52 * zero) but leaving all other fields as-is;
53 * reg_val = r32_int(19, 1, reg_value);
56 #define MAKE_MASK32(width) (width == 32 ? 0xffffffff : \
57 (uint32_t)((1 << width) - 1))
58 #define DECLARE_CODEC32(t) \
59 static inline uint32_t e32_##t(uint32_t lsoffset, uint32_t width, t val) \
61 BUG_ON(width > (sizeof(t) * 8)); \
62 return ((uint32_t)val & MAKE_MASK32(width)) << lsoffset; \
64 static inline t d32_##t(uint32_t lsoffset, uint32_t width, uint32_t val) \
66 BUG_ON(width > (sizeof(t) * 8)); \
67 return (t)((val >> lsoffset) & MAKE_MASK32(width)); \
69 static inline uint32_t i32_##t(uint32_t lsoffset, uint32_t width, \
72 BUG_ON(width > (sizeof(t) * 8)); \
73 return e32_##t(lsoffset, width, d32_##t(lsoffset, width, val)); \
75 static inline uint32_t r32_##t(uint32_t lsoffset, uint32_t width, \
78 BUG_ON(width > (sizeof(t) * 8)); \
79 return ~(MAKE_MASK32(width) << lsoffset) & val; \
81 DECLARE_CODEC32(uint32_t)
82 DECLARE_CODEC32(uint16_t)
83 DECLARE_CODEC32(uint8_t)
86 /*********************/
87 /* Debugging assists */
88 /*********************/
90 static inline void __hexdump(unsigned long start, unsigned long end,
91 unsigned long p, size_t sz, const unsigned char *c)
98 pos += sprintf(buf + pos, "%08lx: ", start);
100 if ((start < p) || (start >= (p + sz)))
101 pos += sprintf(buf + pos, "..");
103 pos += sprintf(buf + pos, "%02x", *(c++));
104 if (!(++start & 15)) {
114 } while (start & 15);
121 static inline void hexdump(const void *ptr, size_t sz)
123 unsigned long p = (unsigned long)ptr;
124 unsigned long start = p & ~(unsigned long)15;
125 unsigned long end = (p + sz + 15) & ~(unsigned long)15;
126 const unsigned char *c = ptr;
128 __hexdump(start, end, p, sz, c);
131 #if defined(__BIG_ENDIAN)
132 #define DQRR_TOK_OFFSET 0
134 #define DQRR_TOK_OFFSET 24
137 /* Similarly-named functions */
138 #define upper32(a) upper_32_bits(a)
139 #define lower32(a) lower_32_bits(a)
145 static inline void dcbz(void *ptr)
148 BUG_ON((unsigned long)ptr & 63);
169 #include "qbman_sys.h"