iPXE
efi_pci_api.h
Go to the documentation of this file.
1 #ifndef _IPXE_EFI_PCI_API_H
2 #define _IPXE_EFI_PCI_API_H
3 
4 /** @file
5  *
6  * iPXE PCI I/O API for EFI
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #ifdef PCIAPI_EFI
13 #define PCIAPI_PREFIX_efi
14 #else
15 #define PCIAPI_PREFIX_efi __efi_
16 #endif
17 
18 /* EFI PCI width codes defined by EFI spec */
19 #define EFIPCI_WIDTH_BYTE 0
20 #define EFIPCI_WIDTH_WORD 1
21 #define EFIPCI_WIDTH_DWORD 2
22 
23 #define EFIPCI_LOCATION( _offset, _width ) \
24  ( (_offset) | ( (_width) << 16 ) )
25 #define EFIPCI_OFFSET( _location ) ( (_location) & 0xffff )
26 #define EFIPCI_WIDTH( _location ) ( (_location) >> 16 )
27 
28 struct pci_device;
29 
30 extern int efipci_read ( struct pci_device *pci, unsigned long location,
31  void *value );
32 extern int efipci_write ( struct pci_device *pci, unsigned long location,
33  unsigned long value );
34 
35 /**
36  * Determine number of PCI buses within system
37  *
38  * @ret num_bus Number of buses
39  */
40 static inline __always_inline int
41 PCIAPI_INLINE ( efi, pci_num_bus ) ( void ) {
42  /* EFI does not want us to scan the PCI bus ourselves */
43  return 0;
44 }
45 
46 /**
47  * Read byte from PCI configuration space via EFI
48  *
49  * @v pci PCI device
50  * @v where Location within PCI configuration space
51  * @v value Value read
52  * @ret rc Return status code
53  */
54 static inline __always_inline int
55 PCIAPI_INLINE ( efi, pci_read_config_byte ) ( struct pci_device *pci,
56  unsigned int where,
58  *value = 0xff;
59  return efipci_read ( pci,
61  value );
62 }
63 
64 /**
65  * Read word from PCI configuration space via EFI
66  *
67  * @v pci PCI device
68  * @v where Location within PCI configuration space
69  * @v value Value read
70  * @ret rc Return status code
71  */
72 static inline __always_inline int
73 PCIAPI_INLINE ( efi, pci_read_config_word ) ( struct pci_device *pci,
74  unsigned int where,
75  uint16_t *value ) {
76  *value = 0xffff;
77  return efipci_read ( pci,
79  value );
80 }
81 
82 /**
83  * Read dword from PCI configuration space via EFI
84  *
85  * @v pci PCI device
86  * @v where Location within PCI configuration space
87  * @v value Value read
88  * @ret rc Return status code
89  */
90 static inline __always_inline int
91 PCIAPI_INLINE ( efi, pci_read_config_dword ) ( struct pci_device *pci,
92  unsigned int where,
93  uint32_t *value ) {
94  *value = 0xffffffffUL;
95  return efipci_read ( pci,
97  value );
98 }
99 
100 /**
101  * Write byte to PCI configuration space via EFI
102  *
103  * @v pci PCI device
104  * @v where Location within PCI configuration space
105  * @v value Value to be written
106  * @ret rc Return status code
107  */
108 static inline __always_inline int
109 PCIAPI_INLINE ( efi, pci_write_config_byte ) ( struct pci_device *pci,
110  unsigned int where,
111  uint8_t value ) {
112  return efipci_write ( pci,
114  value );
115 }
116 
117 /**
118  * Write word to PCI configuration space via EFI
119  *
120  * @v pci PCI device
121  * @v where Location within PCI configuration space
122  * @v value Value to be written
123  * @ret rc Return status code
124  */
125 static inline __always_inline int
126 PCIAPI_INLINE ( efi, pci_write_config_word ) ( struct pci_device *pci,
127  unsigned int where,
128  uint16_t value ) {
129  return efipci_write ( pci,
131  value );
132 }
133 
134 /**
135  * Write dword to PCI configuration space via EFI
136  *
137  * @v pci PCI device
138  * @v where Location within PCI configuration space
139  * @v value Value to be written
140  * @ret rc Return status code
141  */
142 static inline __always_inline int
143 PCIAPI_INLINE ( efi, pci_write_config_dword ) ( struct pci_device *pci,
144  unsigned int where,
145  uint32_t value ) {
146  return efipci_write ( pci,
148  value );
149 }
150 
151 #endif /* _IPXE_EFI_PCI_API_H */
unsigned short uint16_t
Definition: stdint.h:11
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
#define EFIPCI_WIDTH_BYTE
Definition: efi_pci_api.h:19
int efipci_read(struct pci_device *pci, unsigned long location, void *value)
Read from PCI configuration space.
Definition: efi_pci.c:164
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
#define EFIPCI_WIDTH_DWORD
Definition: efi_pci_api.h:21
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
A PCI device.
Definition: pci.h:187
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
static __always_inline int unsigned int where
Definition: efi_pci_api.h:56
int pci_num_bus(void)
Determine number of PCI buses within system.
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define EFIPCI_LOCATION(_offset, _width)
Definition: efi_pci_api.h:23
#define EFIPCI_WIDTH_WORD
Definition: efi_pci_api.h:20
static __always_inline int PCIAPI_INLINE(efi, pci_num_bus)(void)
Determine number of PCI buses within system.
Definition: efi_pci_api.h:41
static __always_inline int unsigned int uint8_t * value
Definition: efi_pci_api.h:57
int efipci_write(struct pci_device *pci, unsigned long location, unsigned long value)
Write to PCI configuration space.
Definition: efi_pci.c:200
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.