From c0e31708e0446b33240d3e1ba3e36c26a618544c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 25 Jul 2006 15:36:52 -0700 Subject: [PATCH] Add pci_device_get_bridge_buses, bump API version to 0.5.0. --- configure.ac | 2 +- include/pciaccess.h | 3 +++ src/Makefile.am | 2 +- src/common_bridge.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index a968291..998a4dc 100644 --- a/configure.ac +++ b/configure.ac @@ -41,7 +41,7 @@ dnl refers to ${prefix}. Thus we have to use `eval' twice. AC_PREREQ([2.57]) -AC_INIT(libpciaccess, 0.5.0, [none yet], libpciaccess) +AC_INIT(libpciaccess, 0.6.0, [none yet], libpciaccess) AM_INIT_AUTOMAKE([dist-bzip2]) AM_MAINTAINER_MODE diff --git a/include/pciaccess.h b/include/pciaccess.h index c9f46b6..4078f0f 100644 --- a/include/pciaccess.h +++ b/include/pciaccess.h @@ -57,6 +57,9 @@ const struct pci_bridge_info * pci_device_get_bridge_info( const struct pci_pcmcia_bridge_info * pci_device_get_pcmcia_bridge_info( struct pci_device * dev ); +int pci_device_get_bridge_buses(struct pci_device * dev, int *primary_bus, + int *secondary_bus, int *subordinate_bus); + int pci_system_init( void ); void pci_system_cleanup( void ); diff --git a/src/Makefile.am b/src/Makefile.am index ee4d7d2..6593f4c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,7 +35,7 @@ INCLUDES = -I$(top_srcdir)/include libpciaccess_la_LIBADD = @PCIACCESS_LIBS@ -libpciaccess_la_LDFLAGS = -version-number 0:5:0 -no-undefined +libpciaccess_la_LDFLAGS = -version-number 0:6:0 -no-undefined libpciaccessincludedir = $(includedir) libpciaccessinclude_HEADERS = \ diff --git a/src/common_bridge.c b/src/common_bridge.c index 19912d3..305228a 100644 --- a/src/common_bridge.c +++ b/src/common_bridge.c @@ -33,6 +33,7 @@ #include #include #include +#include #if defined(HAVE_STRING_H) # include @@ -211,3 +212,54 @@ pci_device_get_pcmcia_bridge_info( struct pci_device * dev ) return (priv->header_type == 2) ? priv->bridge.pcmcia : NULL; } + + +int +pci_device_get_bridge_buses(struct pci_device * dev, int *primary_bus, + int *secondary_bus, int *subordinate_bus) +{ + struct pci_device_private * priv = (struct pci_device_private *) dev; + + /* If the device isn't a bridge, return an error. + */ + + if (((dev->device_class >> 16) & 0x0ff) != 0x06) { + return ENODEV; + } + + if (priv->bridge.pci == NULL) { + read_bridge_info(priv); + } + + switch ((dev->device_class >> 8) & 0x0ff) { + case 0x00: + /* What to do for host bridges? I'm pretty sure this isn't right. + */ + *primary_bus = dev->bus; + *secondary_bus = -1; + *subordinate_bus = -1; + break; + + case 0x01: + case 0x02: + case 0x03: + *primary_bus = dev->bus; + *secondary_bus = -1; + *subordinate_bus = -1; + break; + + case 0x04: + *primary_bus = priv->bridge.pci->primary_bus; + *secondary_bus = priv->bridge.pci->secondary_bus; + *subordinate_bus = priv->bridge.pci->subordinate_bus; + break; + + case 0x07: + *primary_bus = priv->bridge.pcmcia->primary_bus; + *secondary_bus = priv->bridge.pcmcia->card_bus; + *subordinate_bus = priv->bridge.pcmcia->subordinate_bus; + break; + } + + return 0; +} -- 2.7.4