mirror of
https://github.com/ipxe/ipxe
synced 2026-01-07 20:52:03 +03:00
Strip down i386 PCI configuration space I/O to the bare minimum. A
typical build will now include 880 bytes of PCI support code, compared to 2327 bytes in Etherboot 5.4. (There is a slight cost of around 5 extra bytes per access to a non-constant config space address; this should be an overall win. Driver-specific accesses will usually be to constant addresses, for which there is no additional cost.)
This commit is contained in:
126
src/arch/i386/include/pcidirect.h
Normal file
126
src/arch/i386/include/pcidirect.h
Normal file
@@ -0,0 +1,126 @@
|
||||
#ifndef _PCIDIRECT_H
|
||||
#define _PCIDIRECT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <io.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* PCI configuration space access via Type 1 accesses
|
||||
*
|
||||
*/
|
||||
|
||||
#define PCIDIRECT_CONFIG_ADDRESS 0xcf8
|
||||
#define PCIDIRECT_CONFIG_DATA 0xcfc
|
||||
|
||||
struct pci_device;
|
||||
|
||||
extern void pcidirect_prepare ( struct pci_device *pci, int where );
|
||||
|
||||
/**
|
||||
* Determine maximum PCI bus number within system
|
||||
*
|
||||
* @ret max_bus Maximum bus number
|
||||
*/
|
||||
static inline int pcidirect_max_bus ( void ) {
|
||||
/* No way to work this out via Type 1 accesses */
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read byte from PCI configuration space via Type 1 access
|
||||
*
|
||||
* @v pci PCI device
|
||||
* @v where Location within PCI configuration space
|
||||
* @v value Value read
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
pcidirect_read_config_byte ( struct pci_device *pci, unsigned int where,
|
||||
uint8_t *value ) {
|
||||
pcidirect_prepare ( pci, where );
|
||||
*value = inb ( PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read word from PCI configuration space via Type 1 access
|
||||
*
|
||||
* @v pci PCI device
|
||||
* @v where Location within PCI configuration space
|
||||
* @v value Value read
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
pcidirect_read_config_word ( struct pci_device *pci, unsigned int where,
|
||||
uint16_t *value ) {
|
||||
pcidirect_prepare ( pci, where );
|
||||
*value = inw ( PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read dword from PCI configuration space via Type 1 access
|
||||
*
|
||||
* @v pci PCI device
|
||||
* @v where Location within PCI configuration space
|
||||
* @v value Value read
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
pcidirect_read_config_dword ( struct pci_device *pci, unsigned int where,
|
||||
uint32_t *value ) {
|
||||
pcidirect_prepare ( pci, where );
|
||||
*value = inl ( PCIDIRECT_CONFIG_DATA + where );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write byte to PCI configuration space via Type 1 access
|
||||
*
|
||||
* @v pci PCI device
|
||||
* @v where Location within PCI configuration space
|
||||
* @v value Value to be written
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
pcidirect_write_config_byte ( struct pci_device *pci, unsigned int where,
|
||||
uint8_t value ) {
|
||||
pcidirect_prepare ( pci, where );
|
||||
outb ( value, PCIDIRECT_CONFIG_DATA + ( where & 3 ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write word to PCI configuration space via Type 1 access
|
||||
*
|
||||
* @v pci PCI device
|
||||
* @v where Location within PCI configuration space
|
||||
* @v value Value to be written
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
pcidirect_write_config_word ( struct pci_device *pci, unsigned int where,
|
||||
uint16_t value ) {
|
||||
pcidirect_prepare ( pci, where );
|
||||
outb ( value, PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write dword to PCI configuration space via Type 1 access
|
||||
*
|
||||
* @v pci PCI device
|
||||
* @v where Location within PCI configuration space
|
||||
* @v value Value to be written
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
pcidirect_write_config_dword ( struct pci_device *pci, unsigned int where,
|
||||
uint32_t value ) {
|
||||
pcidirect_prepare ( pci, where );
|
||||
outb ( value, PCIDIRECT_CONFIG_DATA + where );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* _PCIDIRECT_H */
|
||||
Reference in New Issue
Block a user