1 /* 2 * The PCI Library -- Types and Format Strings 3 * 4 * Copyright (c) 1997--2022 Martin Mares <[email protected]> 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 <windows.h> */ 15 #include <windows.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 #define PCI_U64_FMT_U "I64u" 22 23 #elif defined(PCI_HAVE_STDINT_H) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) 24 /* Use standard types in C99 and newer */ 25 #include <stdint.h> 26 #include <inttypes.h> 27 typedef uint8_t u8; 28 typedef uint16_t u16; 29 typedef uint32_t u32; 30 typedef uint64_t u64; 31 #define PCI_U64_FMT_X PRIx64 32 #define PCI_U64_FMT_U PRIu64 33 34 #else 35 /* Hope for POSIX types from <sys/types.h> */ 36 typedef u_int8_t u8; 37 typedef u_int16_t u16; 38 typedef u_int32_t u32; 39 40 /* u64 will be unsigned (long) long */ 41 #include <limits.h> 42 #if ULONG_MAX > 0xffffffff 43 typedef unsigned long u64; 44 #define PCI_U64_FMT_X "lx" 45 #define PCI_U64_FMT_U "lu" 46 #else 47 typedef unsigned long long u64; 48 #define PCI_U64_FMT_X "llx" 49 #define PCI_U64_FMT_U "llu" 50 #endif 51 52 #endif 53 54 #endif /* PCI_HAVE_Uxx_TYPES */ 55 56 #ifdef PCI_HAVE_64BIT_ADDRESS 57 typedef u64 pciaddr_t; 58 #define PCIADDR_T_FMT "%08" PCI_U64_FMT_X 59 #define PCIADDR_PORT_FMT "%04" PCI_U64_FMT_X 60 #else 61 typedef u32 pciaddr_t; 62 #define PCIADDR_T_FMT "%08x" 63 #define PCIADDR_PORT_FMT "%04x" 64 #endif 65 66 #ifdef PCI_ARCH_SPARC64 67 /* On sparc64 Linux the kernel reports remapped port addresses and IRQ numbers */ 68 #undef PCIADDR_PORT_FMT 69 #define PCIADDR_PORT_FMT PCIADDR_T_FMT 70 #define PCIIRQ_FMT "%08x" 71 #else 72 #define PCIIRQ_FMT "%d" 73 #endif 74 75 #if defined(__GNUC__) && __GNUC__ > 2 76 #define PCI_PRINTF(x,y) __attribute__((format(printf, x, y))) 77 #define PCI_NONRET __attribute((noreturn)) 78 #define PCI_PACKED __attribute((packed)) 79 #else 80 #define PCI_PRINTF(x,y) 81 #define PCI_NONRET 82 #define PCI_PACKED 83 #endif 84