summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/arch/x86/include/ipxe/pcibios.h
blob: 7e1bcd814bb67056a934c03f1e378704cd51ca6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef _IPXE_PCIBIOS_H
#define _IPXE_PCIBIOS_H

#include <stdint.h>

/** @file
 *
 * PCI configuration space access via PCI BIOS
 *
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#ifdef PCIAPI_PCBIOS
#define PCIAPI_PREFIX_pcbios
#else
#define PCIAPI_PREFIX_pcbios __pcbios_
#endif

struct pci_device;

#define PCIBIOS_INSTALLATION_CHECK	0xb1010000
#define PCIBIOS_READ_CONFIG_BYTE	0xb1080000
#define PCIBIOS_READ_CONFIG_WORD	0xb1090000
#define PCIBIOS_READ_CONFIG_DWORD	0xb10a0000
#define PCIBIOS_WRITE_CONFIG_BYTE	0xb10b0000
#define PCIBIOS_WRITE_CONFIG_WORD	0xb10c0000
#define PCIBIOS_WRITE_CONFIG_DWORD	0xb10d0000

extern int pcibios_read ( struct pci_device *pci, uint32_t command,
			  uint32_t *value );
extern int pcibios_write ( struct pci_device *pci, uint32_t command,
			   uint32_t value );

/**
 * Read byte from PCI configuration space via PCI BIOS
 *
 * @v pci	PCI device
 * @v where	Location within PCI configuration space
 * @v value	Value read
 * @ret rc	Return status code
 */
static inline __always_inline int
PCIAPI_INLINE ( pcbios, pci_read_config_byte ) ( struct pci_device *pci,
						 unsigned int where,
						 uint8_t *value ) {
	uint32_t tmp;
	int rc;

	rc = pcibios_read ( pci, PCIBIOS_READ_CONFIG_BYTE | where, &tmp );
	*value = tmp;
	return rc;
}

/**
 * Read word from PCI configuration space via PCI BIOS
 *
 * @v pci	PCI device
 * @v where	Location within PCI configuration space
 * @v value	Value read
 * @ret rc	Return status code
 */
static inline __always_inline int
PCIAPI_INLINE ( pcbios, pci_read_config_word ) ( struct pci_device *pci,
						 unsigned int where,
						 uint16_t *value ) {
	uint32_t tmp;
	int rc;

	rc = pcibios_read ( pci, PCIBIOS_READ_CONFIG_WORD | where, &tmp );
	*value = tmp;
	return rc;
}

/**
 * Read dword from PCI configuration space via PCI BIOS
 *
 * @v pci	PCI device
 * @v where	Location within PCI configuration space
 * @v value	Value read
 * @ret rc	Return status code
 */
static inline __always_inline int
PCIAPI_INLINE ( pcbios, pci_read_config_dword ) ( struct pci_device *pci,
						  unsigned int where,
						  uint32_t *value ) {
	return pcibios_read ( pci, PCIBIOS_READ_CONFIG_DWORD | where, value );
}

/**
 * Write byte to PCI configuration space via PCI BIOS
 *
 * @v pci	PCI device
 * @v where	Location within PCI configuration space
 * @v value	Value to be written
 * @ret rc	Return status code
 */
static inline __always_inline int
PCIAPI_INLINE ( pcbios, pci_write_config_byte ) ( struct pci_device *pci,
						  unsigned int where,
						  uint8_t value ) {
	return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_BYTE | where, value );
}

/**
 * Write word to PCI configuration space via PCI BIOS
 *
 * @v pci	PCI device
 * @v where	Location within PCI configuration space
 * @v value	Value to be written
 * @ret rc	Return status code
 */
static inline __always_inline int
PCIAPI_INLINE ( pcbios, pci_write_config_word ) ( struct pci_device *pci,
						  unsigned int where,
						  uint16_t value ) {
	return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_WORD | where, value );
}

/**
 * Write dword to PCI configuration space via PCI BIOS
 *
 * @v pci	PCI device
 * @v where	Location within PCI configuration space
 * @v value	Value to be written
 * @ret rc	Return status code
 */
static inline __always_inline int
PCIAPI_INLINE ( pcbios, pci_write_config_dword ) ( struct pci_device *pci,
						   unsigned int where,
						   uint32_t value ) {
	return pcibios_write ( pci, PCIBIOS_WRITE_CONFIG_DWORD | where, value);
}

#endif /* _IPXE_PCIBIOS_H */