]> mj.ucw.cz Git - pciutils.git/blob - lib/types.h
update-pciids: Add support for xz compression
[pciutils.git] / lib / types.h
1 /*
2  *      The PCI Library -- Types and Format Strings
3  *
4  *      Copyright (c) 1997--2022 Martin Mares <mj@ucw.cz>
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL v2+
7  *
8  *      SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include <sys/types.h>
12
13 #ifndef PCI_HAVE_Uxx_TYPES
14
15 #ifdef PCI_OS_WINDOWS
16 /* On Windows compilers, use <windows.h> */
17 #include <windows.h>
18 typedef BYTE u8;
19 typedef WORD u16;
20 typedef DWORD u32;
21 typedef unsigned __int64 u64;
22 #define PCI_U64_FMT_X "I64x"
23 #define PCI_U64_FMT_U "I64u"
24
25 #elif defined(PCI_HAVE_STDINT_H) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
26 /* Use standard types in C99 and newer */
27 #include <stdint.h>
28 #include <inttypes.h>
29 typedef uint8_t u8;
30 typedef uint16_t u16;
31 typedef uint32_t u32;
32 typedef uint64_t u64;
33 #define PCI_U64_FMT_X PRIx64
34 #define PCI_U64_FMT_U PRIu64
35
36 #else
37 /* Hope for POSIX types from <sys/types.h> */
38 typedef u_int8_t u8;
39 typedef u_int16_t u16;
40 typedef u_int32_t u32;
41
42 /* u64 will be unsigned (long) long */
43 #include <limits.h>
44 #if ULONG_MAX > 0xffffffff
45 typedef unsigned long u64;
46 #define PCI_U64_FMT_X "lx"
47 #define PCI_U64_FMT_U "lu"
48 #else
49 typedef unsigned long long u64;
50 #define PCI_U64_FMT_X "llx"
51 #define PCI_U64_FMT_U "llu"
52 #endif
53
54 #endif
55
56 #endif  /* PCI_HAVE_Uxx_TYPES */
57
58 #ifdef PCI_HAVE_64BIT_ADDRESS
59 typedef u64 pciaddr_t;
60 #define PCIADDR_T_FMT "%08" PCI_U64_FMT_X
61 #define PCIADDR_PORT_FMT "%04" PCI_U64_FMT_X
62 #else
63 typedef u32 pciaddr_t;
64 #define PCIADDR_T_FMT "%08x"
65 #define PCIADDR_PORT_FMT "%04x"
66 #endif
67
68 #ifdef PCI_ARCH_SPARC64
69 /* On sparc64 Linux the kernel reports remapped port addresses and IRQ numbers */
70 #undef PCIADDR_PORT_FMT
71 #define PCIADDR_PORT_FMT PCIADDR_T_FMT
72 #define PCIIRQ_FMT "%08x"
73 #else
74 #define PCIIRQ_FMT "%d"
75 #endif
76
77 #if defined(__GNUC__) && __GNUC__ > 2
78 #define PCI_PRINTF(x,y) __attribute__((format(printf, x, y)))
79 #define PCI_NONRET __attribute((noreturn))
80 #define PCI_PACKED __attribute((packed))
81 #else
82 #define PCI_PRINTF(x,y)
83 #define PCI_NONRET
84 #define PCI_PACKED
85 #endif