Skip to content

Commit

Permalink
[pci] Formalise the PCI I/O API
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brown committed Oct 12, 2008
1 parent fd67452 commit 8a4cceb
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 81 deletions.
8 changes: 7 additions & 1 deletion src/arch/i386/core/pcidirect.c
Expand Up @@ -17,7 +17,6 @@
*/

#include <gpxe/pci.h>
#include <pcidirect.h>

/** @file
*
Expand All @@ -36,3 +35,10 @@ void pcidirect_prepare ( struct pci_device *pci, int where ) {
( where & ~3 ) ), PCIDIRECT_CONFIG_ADDRESS );
}

PROVIDE_PCIAPI_INLINE ( direct, pci_max_bus );
PROVIDE_PCIAPI_INLINE ( direct, pci_read_config_byte );
PROVIDE_PCIAPI_INLINE ( direct, pci_read_config_word );
PROVIDE_PCIAPI_INLINE ( direct, pci_read_config_dword );
PROVIDE_PCIAPI_INLINE ( direct, pci_write_config_byte );
PROVIDE_PCIAPI_INLINE ( direct, pci_write_config_word );
PROVIDE_PCIAPI_INLINE ( direct, pci_write_config_dword );
13 changes: 13 additions & 0 deletions src/arch/i386/include/bits/pci_io.h
@@ -0,0 +1,13 @@
#ifndef _BITS_PCI_IO_H
#define _BITS_PCI_IO_H

/** @file
*
* i386-specific PCI I/O API implementations
*
*/

#include <gpxe/pcibios.h>
#include <gpxe/pcidirect.h>

#endif /* _BITS_PCI_IO_H */
@@ -1,5 +1,5 @@
#ifndef _PCIBIOS_H
#define _PCIBIOS_H
#ifndef _GPXE_PCIBIOS_H
#define _GPXE_PCIBIOS_H

#include <stdint.h>

Expand All @@ -9,6 +9,12 @@
*
*/

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

struct pci_device;

#define PCIBIOS_INSTALLATION_CHECK 0xb1010000
Expand All @@ -19,7 +25,6 @@ struct pci_device;
#define PCIBIOS_WRITE_CONFIG_WORD 0xb10c0000
#define PCIBIOS_WRITE_CONFIG_DWORD 0xb10d0000

extern int pcibios_max_bus ( void );
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,
Expand All @@ -33,9 +38,10 @@ extern int pcibios_write ( struct pci_device *pci, uint32_t command,
* @v value Value read
* @ret rc Return status code
*/
static inline __attribute__ (( always_inline )) int
pcibios_read_config_byte ( struct pci_device *pci, unsigned int where,
uint8_t *value ) {
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;

Expand All @@ -52,9 +58,10 @@ pcibios_read_config_byte ( struct pci_device *pci, unsigned int where,
* @v value Value read
* @ret rc Return status code
*/
static inline __attribute__ (( always_inline )) int
pcibios_read_config_word ( struct pci_device *pci, unsigned int where,
uint16_t *value ) {
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;

Expand All @@ -71,9 +78,10 @@ pcibios_read_config_word ( struct pci_device *pci, unsigned int where,
* @v value Value read
* @ret rc Return status code
*/
static inline __attribute__ (( always_inline )) int
pcibios_read_config_dword ( struct pci_device *pci, unsigned int where,
uint32_t *value ) {
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 );
}

Expand All @@ -85,9 +93,10 @@ pcibios_read_config_dword ( struct pci_device *pci, unsigned int where,
* @v value Value to be written
* @ret rc Return status code
*/
static inline __attribute__ (( always_inline )) int
pcibios_write_config_byte ( struct pci_device *pci, unsigned int where,
uint8_t value ) {
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 );
}

Expand All @@ -99,9 +108,10 @@ pcibios_write_config_byte ( struct pci_device *pci, unsigned int where,
* @v value Value to be written
* @ret rc Return status code
*/
static inline __attribute__ (( always_inline )) int
pcibios_write_config_word ( struct pci_device *pci, unsigned int where,
uint16_t value ) {
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 );
}

Expand All @@ -113,10 +123,11 @@ pcibios_write_config_word ( struct pci_device *pci, unsigned int where,
* @v value Value to be written
* @ret rc Return status code
*/
static inline __attribute__ (( always_inline )) int
pcibios_write_config_dword ( struct pci_device *pci, unsigned int where,
uint32_t value ) {
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 /* _PCIBIOS_H */
#endif /* _GPXE_PCIBIOS_H */
Expand Up @@ -4,6 +4,12 @@
#include <stdint.h>
#include <gpxe/io.h>

#ifdef PCIAPI_DIRECT
#define PCIAPI_PREFIX_direct
#else
#define PCIAPI_PREFIX_direct __direct_
#endif

/** @file
*
* PCI configuration space access via Type 1 accesses
Expand All @@ -22,7 +28,8 @@ extern void pcidirect_prepare ( struct pci_device *pci, int where );
*
* @ret max_bus Maximum bus number
*/
static inline int pcidirect_max_bus ( void ) {
static inline __always_inline int
PCIAPI_INLINE ( direct, pci_max_bus ) ( void ) {
/* No way to work this out via Type 1 accesses */
return 0xff;
}
Expand All @@ -35,9 +42,10 @@ static inline int pcidirect_max_bus ( void ) {
* @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 ) {
static inline __always_inline int
PCIAPI_INLINE ( direct, pci_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;
Expand All @@ -51,9 +59,10 @@ pcidirect_read_config_byte ( struct pci_device *pci, unsigned int where,
* @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 ) {
static inline __always_inline int
PCIAPI_INLINE ( direct, pci_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;
Expand All @@ -67,9 +76,10 @@ pcidirect_read_config_word ( struct pci_device *pci, unsigned int where,
* @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 ) {
static inline __always_inline int
PCIAPI_INLINE ( direct, pci_read_config_dword ) ( struct pci_device *pci,
unsigned int where,
uint32_t *value ) {
pcidirect_prepare ( pci, where );
*value = inl ( PCIDIRECT_CONFIG_DATA );
return 0;
Expand All @@ -83,9 +93,10 @@ pcidirect_read_config_dword ( struct pci_device *pci, unsigned int where,
* @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 ) {
static inline __always_inline int
PCIAPI_INLINE ( direct, pci_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;
Expand All @@ -99,9 +110,10 @@ pcidirect_write_config_byte ( struct pci_device *pci, unsigned int where,
* @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 ) {
static inline __always_inline int
PCIAPI_INLINE ( direct, pci_write_config_word ) ( struct pci_device *pci,
unsigned int where,
uint16_t value ) {
pcidirect_prepare ( pci, where );
outw ( value, PCIDIRECT_CONFIG_DATA + ( where & 2 ) );
return 0;
Expand All @@ -115,9 +127,10 @@ pcidirect_write_config_word ( struct pci_device *pci, unsigned int where,
* @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 ) {
static inline __always_inline int
PCIAPI_INLINE ( direct, pci_write_config_dword ) ( struct pci_device *pci,
unsigned int where,
uint32_t value ) {
pcidirect_prepare ( pci, where );
outl ( value, PCIDIRECT_CONFIG_DATA );
return 0;
Expand Down
35 changes: 0 additions & 35 deletions src/arch/i386/include/pci_io.h

This file was deleted.

Expand Up @@ -18,7 +18,6 @@

#include <stdint.h>
#include <gpxe/pci.h>
#include <pcibios.h>
#include <realmode.h>

/** @file
Expand All @@ -32,7 +31,7 @@
*
* @ret max_bus Maximum bus number
*/
int pcibios_max_bus ( void ) {
static int pcibios_max_bus ( void ) {
int discard_a, discard_D;
uint8_t max_bus;

Expand Down Expand Up @@ -104,3 +103,11 @@ int pcibios_write ( struct pci_device *pci, uint32_t command, uint32_t value ){

return ( ( status >> 8 ) & 0xff );
}

PROVIDE_PCIAPI ( pcbios, pci_max_bus, pcibios_max_bus );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_byte );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_word );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_read_config_dword );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_byte );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_word );
PROVIDE_PCIAPI_INLINE ( pcbios, pci_write_config_dword );
2 changes: 1 addition & 1 deletion src/config/defaults/pcbios.h
Expand Up @@ -8,7 +8,7 @@
*/

#define IOAPI_X86

#define PCIAPI_PCBIOS
#define CONSOLE_PCBIOS

#endif /* CONFIG_DEFAULTS_PCBIOS_H */
3 changes: 3 additions & 0 deletions src/config/ioapi.h
Expand Up @@ -9,4 +9,7 @@

#include <config/defaults.h>

//#undef PCIAPI_PCBIOS /* Access via PCI BIOS */
//#define PCIAPI_DIRECT /* Direct access via Type 1 accesses */

#endif /* CONFIG_IOAPI_H */
2 changes: 1 addition & 1 deletion src/include/gpxe/pci.h
Expand Up @@ -19,7 +19,7 @@
#include <stdint.h>
#include <gpxe/device.h>
#include <gpxe/tables.h>
#include <pci_io.h>
#include <gpxe/pci_io.h>
#include "pci_ids.h"

/*
Expand Down

0 comments on commit 8a4cceb

Please sign in to comment.