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