]> mj.ucw.cz Git - pciutils.git/blob - lib/internal.h
a591f5051b68eecea470b87daaf547fd5fffc021
[pciutils.git] / lib / internal.h
1 /*
2  *      The PCI Library -- Internal Include File
3  *
4  *      Copyright (c) 1997--2004 Martin Mares <mj@ucw.cz>
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL.
7  */
8
9 #include "pci.h"
10
11 #ifdef __GNUC__
12 #define UNUSED __attribute__((unused))
13 #else
14 #define UNUSED
15 #define inline
16 #endif
17
18 #ifdef HAVE_LINUX_BYTEORDER_H
19
20 #include <asm/byteorder.h>
21 #define cpu_to_le16 __cpu_to_le16
22 #define cpu_to_le32 __cpu_to_le32
23 #define le16_to_cpu __le16_to_cpu
24 #define le32_to_cpu __le32_to_cpu
25
26 #else
27
28 #ifdef OS_LINUX
29 #include <endian.h>
30 #define BYTE_ORDER __BYTE_ORDER
31 #define BIG_ENDIAN __BIG_ENDIAN
32 #endif
33
34 #ifdef OS_FREEBSD
35 #include <sys/types.h>
36 #endif
37
38 #ifdef OS_SUNOS
39 #include <sys/byteorder.h>
40 #define BIG_ENDIAN 4321
41 #ifdef _LITTLE_ENDIAN
42 #define BYTE_ORDER 1234
43 #else
44 #define BYTE_ORDER 4321
45 #endif
46 #endif
47
48 #ifdef OS_WINDOWS
49 #include <sys/param.h>
50 #endif
51
52 #if BYTE_ORDER == BIG_ENDIAN
53 #define cpu_to_le16 swab16
54 #define cpu_to_le32 swab32
55 #define le16_to_cpu swab16
56 #define le32_to_cpu swab32
57
58 static inline word swab16(word w)
59 {
60   return (w << 8) | ((w >> 8) & 0xff);
61 }
62
63 static inline u32 swab32(u32 w)
64 {
65   return ((w & 0xff000000) >> 24) |
66          ((w & 0x00ff0000) >> 8) |
67          ((w & 0x0000ff00) << 8)  |
68          ((w & 0x000000ff) << 24);
69 }
70 #else
71 #define cpu_to_le16(x) (x)
72 #define cpu_to_le32(x) (x)
73 #define le16_to_cpu(x) (x)
74 #define le32_to_cpu(x) (x)
75 #endif
76
77 #endif
78
79 struct pci_methods {
80   char *name;
81   void (*config)(struct pci_access *);
82   int (*detect)(struct pci_access *);
83   void (*init)(struct pci_access *);
84   void (*cleanup)(struct pci_access *);
85   void (*scan)(struct pci_access *);
86   int (*fill_info)(struct pci_dev *, int flags);
87   int (*read)(struct pci_dev *, int pos, byte *buf, int len);
88   int (*write)(struct pci_dev *, int pos, byte *buf, int len);
89   void (*init_dev)(struct pci_dev *);
90   void (*cleanup_dev)(struct pci_dev *);
91 };
92
93 void pci_generic_scan_bus(struct pci_access *, byte *busmap, int bus);
94 void pci_generic_scan(struct pci_access *);
95 int pci_generic_fill_info(struct pci_dev *, int flags);
96 int pci_generic_block_read(struct pci_dev *, int pos, byte *buf, int len);
97 int pci_generic_block_write(struct pci_dev *, int pos, byte *buf, int len);
98
99 void *pci_malloc(struct pci_access *, int);
100 void pci_mfree(void *);
101
102 struct pci_dev *pci_alloc_dev(struct pci_access *);
103 int pci_link_dev(struct pci_access *, struct pci_dev *);
104
105 extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc,
106   pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_dump, pm_linux_sysfs;