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 v2+ 7 * 8 * SPDX-License-Identifier: GPL-2.0-or-later 9 */ 10 11 #include <sys/types.h> 12 #include <stddef.h> 13 14 #ifndef PCI_HAVE_Uxx_TYPES 15 16 #ifdef PCI_OS_WINDOWS 17 /* On Windows compilers, use <windows.h> */ 18 #include <windows.h> 19 typedef BYTE u8; 20 typedef WORD u16; 21 typedef DWORD u32; 22 typedef unsigned __int64 u64; 23 #define PCI_U64_FMT_X "I64x" 24 #define PCI_U64_FMT_U "I64u" 25 26 #else 27 /* Use standard types in C99 and newer */ 28 #include <stdint.h> 29 #include <inttypes.h> 30 typedef uint8_t u8; 31 typedef uint16_t u16; 32 typedef uint32_t u32; 33 typedef uint64_t u64; 34 #define PCI_U64_FMT_X PRIx64 35 #define PCI_U64_FMT_U PRIu64 36 #endif 37 38 #endif /* PCI_HAVE_Uxx_TYPES */ 39 40 #ifdef PCI_HAVE_64BIT_ADDRESS 41 typedef u64 pciaddr_t; 42 #define PCIADDR_T_FMT "%08" PCI_U64_FMT_X 43 #define PCIADDR_PORT_FMT "%04" PCI_U64_FMT_X 44 #else 45 typedef u32 pciaddr_t; 46 #define PCIADDR_T_FMT "%08x" 47 #define PCIADDR_PORT_FMT "%04x" 48 #endif 49 50 #ifdef PCI_ARCH_SPARC64 51 /* On sparc64 Linux the kernel reports remapped port addresses and IRQ numbers */ 52 #undef PCIADDR_PORT_FMT 53 #define PCIADDR_PORT_FMT PCIADDR_T_FMT 54 #define PCIIRQ_FMT "%08x" 55 #else 56 #define PCIIRQ_FMT "%d" 57 #endif 58 59 #if defined(__GNUC__) && __GNUC__ > 2 60 #define PCI_PRINTF(x,y) __attribute__((format(printf, x, y))) 61 #define PCI_NONRET __attribute((noreturn)) 62 #define PCI_PACKED __attribute((packed)) 63 #else 64 #define PCI_PRINTF(x,y) 65 #define PCI_NONRET 66 #define PCI_PACKED 67 #endif 68