2 * The PCI Utilities -- Decode bits and bit fields
4 * Copyright (c) 2023 Martin Mares <mj@ucw.cz>
5 * Copyright (c) 2023 KNS Group LLC (YADRO)
7 * Can be freely distributed and used under the terms of the GNU GPL v2+.
9 * SPDX-License-Identifier: GPL-2.0-or-later
16 #error Import only from pci.h
19 /* Useful macros for decoding of bits and bit fields */
21 #define FLAG(x, y) ((x & y) ? '+' : '-')
25 #define BIT(at) ((u64)1 << (at))
26 // Boundaries inclusive
27 #define MASK(h, l) ((((u64)1 << ((h) + 1)) - 1) & ~(((u64)1 << (l)) - 1))
29 // Get/set from register
31 #define BITS(x, at, width) (((x) >> (at)) & ((1 << (width)) - 1))
32 #define GET_REG_MASK(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
33 #define SET_REG_MASK(reg, mask, val) \
34 (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
36 #define TABLE(tab, x, buf) \
37 ((x) < sizeof(tab) / sizeof((tab)[0]) ? (tab)[x] : (sprintf((buf), "??%d", (x)), (buf)))