Move probe_devices_from_device_sections,

add_matching_devices_to_configure_list, and check_for_matching_devices
from xf86Helper.c to xf86Init.c.  These functions are only called from
a single place in xf86Init.c, so it makes sense for them to live
there.  They were originally in xf86Helper.c because they evolved out
another function that was already in that file.
This commit is contained in:
Ian Romanick 2006-06-09 16:08:06 -07:00
parent 7810d87cd6
commit 8b6596b1e1
2 changed files with 193 additions and 186 deletions

View File

@ -1603,192 +1603,6 @@ struct Inst {
};
#define END_OF_MATCHES(m) \
(((m).vendor_id == 0) && ((m).device_id == 0) && ((m).subvendor_id == 0))
Bool
probe_devices_from_device_sections( DriverPtr drvp )
{
int i, j;
struct pci_device * pPci;
struct pci_device **ppPci;
Bool foundScreen = FALSE;
const struct pci_id_match * const devices = drvp->supported_devices;
GDevPtr *devList;
const unsigned numDevs = xf86MatchDevice( drvp->driverName, & devList );
for ( i = 0 ; i < numDevs ; i++ ) {
unsigned device_id;
/* Find the pciVideoRec associated with this device section.
*/
pPci = NULL;
for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
pPci = *ppPci;
if ( devList[i]->busID && *devList[i]->busID ) {
if (xf86ComparePciBusString(devList[i]->busID,
((pPci->domain << 8)
| pPci->bus),
pPci->dev,
pPci->func)) {
break;
}
}
else if ( xf86IsPrimaryPci( pPci ) ) {
break;
}
}
if ( pPci == NULL ) {
continue;
}
device_id = (devList[i]->chipID > 0)
? devList[i]->chipID : pPci->device_id;
/* Once the pciVideoRec is found, determine if the device is supported
* by the driver. If it is, probe it!
*/
for ( j = 0 ; ! END_OF_MATCHES( devices[j] ) ; j++ ) {
if ( PCI_ID_COMPARE( devices[j].vendor_id, pPci->vendor_id )
&& PCI_ID_COMPARE( devices[j].device_id, device_id )
&& ((devices[j].device_class_mask & pPci->device_class)
== devices[j].device_class) ) {
int entry;
/* Allow the same entity to be used more than once for
* devices with multiple screens per entity. This assumes
* implicitly that there will be a screen == 0 instance.
*
* FIXME Need to make sure that two different drivers don't
* FIXME claim the same screen > 0 instance.
*/
if ( (devList[i]->screen == 0) && !xf86CheckPciSlot( pPci ) )
continue;
#ifdef DEBUG
ErrorF("%s: card at %d:%d:%d is claimed by a Device section\n",
drvp->driverName, pPci->bus, pPci->device, pPci->func);
#endif
/* Allocate an entry in the lists to be returned */
entry = xf86ClaimPciSlot( pPci, drvp, device_id,
devList[i], devList[i]->active );
if ( (entry == -1) && (devList[i]->screen > 0) ) {
unsigned k;
for ( k = 0; k < xf86NumEntities; k++ ) {
EntityPtr pEnt = xf86Entities[k];
if (pEnt->busType != BUS_PCI)
continue;
if (pEnt->pciBusId.bus == PCI_MAKE_BUS( pPci->domain, pPci->bus ) &&
pEnt->pciBusId.device == pPci->dev &&
pEnt->pciBusId.func == pPci->func) {
entry = k;
xf86AddDevToEntity( k, devList[i] );
break;
}
}
}
if ( entry != -1 ) {
if ( (*drvp->PciProbe)( drvp, entry, pPci,
devices[j].match_data ) ) {
foundScreen = TRUE;
}
}
break;
}
}
}
return foundScreen;
}
Bool
add_matching_devices_to_configure_list( DriverPtr drvp )
{
const struct pci_id_match * const devices = drvp->supported_devices;
int j;
struct pci_device ** ppPci;
int numFound = 0;
for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
const struct pci_device * pPci = *ppPci;
/* Determine if this device is supported by the driver. If it is,
* add it to the list of devices to configure.
*/
for ( j = 0 ; ! END_OF_MATCHES( devices[j] ) ; j++ ) {
if ( PCI_ID_COMPARE( devices[j].vendor_id, pPci->vendor_id )
&& PCI_ID_COMPARE( devices[j].device_id, pPci->device_id )
&& ((devices[j].device_class_mask & pPci->device_class)
== devices[j].device_class) ) {
if ( xf86CheckPciSlot( pPci ) ) {
GDevPtr pGDev =
xf86AddDeviceToConfigure( drvp->driverName, pPci, -1 );
if ( pGDev != NULL ) {
/* After configure pass 1, chipID and chipRev are
* treated as over-rides, so clobber them here.
*/
pGDev->chipID = -1;
pGDev->chipRev = -1;
}
numFound++;
}
break;
}
}
}
return (numFound != 0);
}
Bool
check_for_matching_devices( DriverPtr drvp )
{
const struct pci_id_match * const devices = drvp->supported_devices;
int j;
struct pci_device ** ppPci;
for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
const struct pci_device * pPci = *ppPci;
/* Determine if this device is supported by the driver. If it is,
* add it to the list of devices to configure.
*/
for ( j = 0 ; ! END_OF_MATCHES( devices[j] ) ; j++ ) {
if ( PCI_ID_COMPARE( devices[j].vendor_id, pPci->vendor_id )
&& PCI_ID_COMPARE( devices[j].device_id, pPci->device_id )
&& ((devices[j].device_class_mask & pPci->device_class)
== devices[j].device_class) ) {
return TRUE;
}
}
}
return FALSE;
}
/**
* Find set of unclaimed devices matching a given vendor ID.
*

View File

@ -99,6 +99,9 @@
#include "dpmsproc.h"
#endif
#include <pciaccess.h>
#include "Pci.h"
#include "xf86Bus.h"
/* forward declarations */
@ -106,6 +109,10 @@ static void xf86PrintBanner(void);
static void xf86PrintMarkers(void);
static void xf86RunVtInit(void);
static Bool probe_devices_from_device_sections(DriverPtr drvp);
static Bool add_matching_devices_to_configure_list(DriverPtr drvp);
static Bool check_for_matching_devices(DriverPtr drvp);
#ifdef __UNIXOS2__
extern void os2ServerVideoAccess();
#endif
@ -261,6 +268,192 @@ PostConfigInit(void)
}
#define END_OF_MATCHES(m) \
(((m).vendor_id == 0) && ((m).device_id == 0) && ((m).subvendor_id == 0))
Bool
probe_devices_from_device_sections(DriverPtr drvp)
{
int i, j;
struct pci_device * pPci;
struct pci_device **ppPci;
Bool foundScreen = FALSE;
const struct pci_id_match * const devices = drvp->supported_devices;
GDevPtr *devList;
const unsigned numDevs = xf86MatchDevice( drvp->driverName, & devList );
for ( i = 0 ; i < numDevs ; i++ ) {
unsigned device_id;
/* Find the pciVideoRec associated with this device section.
*/
pPci = NULL;
for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
pPci = *ppPci;
if ( devList[i]->busID && *devList[i]->busID ) {
if (xf86ComparePciBusString(devList[i]->busID,
((pPci->domain << 8)
| pPci->bus),
pPci->dev,
pPci->func)) {
break;
}
}
else if ( xf86IsPrimaryPci( pPci ) ) {
break;
}
}
if ( pPci == NULL ) {
continue;
}
device_id = (devList[i]->chipID > 0)
? devList[i]->chipID : pPci->device_id;
/* Once the pciVideoRec is found, determine if the device is supported
* by the driver. If it is, probe it!
*/
for ( j = 0 ; ! END_OF_MATCHES( devices[j] ) ; j++ ) {
if ( PCI_ID_COMPARE( devices[j].vendor_id, pPci->vendor_id )
&& PCI_ID_COMPARE( devices[j].device_id, device_id )
&& ((devices[j].device_class_mask & pPci->device_class)
== devices[j].device_class) ) {
int entry;
/* Allow the same entity to be used more than once for
* devices with multiple screens per entity. This assumes
* implicitly that there will be a screen == 0 instance.
*
* FIXME Need to make sure that two different drivers don't
* FIXME claim the same screen > 0 instance.
*/
if ( (devList[i]->screen == 0) && !xf86CheckPciSlot( pPci ) )
continue;
#ifdef DEBUG
ErrorF("%s: card at %d:%d:%d is claimed by a Device section\n",
drvp->driverName, pPci->bus, pPci->device, pPci->func);
#endif
/* Allocate an entry in the lists to be returned */
entry = xf86ClaimPciSlot( pPci, drvp, device_id,
devList[i], devList[i]->active );
if ( (entry == -1) && (devList[i]->screen > 0) ) {
unsigned k;
for ( k = 0; k < xf86NumEntities; k++ ) {
EntityPtr pEnt = xf86Entities[k];
if (pEnt->busType != BUS_PCI)
continue;
if (pEnt->pciBusId.bus == PCI_MAKE_BUS( pPci->domain, pPci->bus ) &&
pEnt->pciBusId.device == pPci->dev &&
pEnt->pciBusId.func == pPci->func) {
entry = k;
xf86AddDevToEntity( k, devList[i] );
break;
}
}
}
if ( entry != -1 ) {
if ( (*drvp->PciProbe)( drvp, entry, pPci,
devices[j].match_data ) ) {
foundScreen = TRUE;
}
}
break;
}
}
}
return foundScreen;
}
Bool
add_matching_devices_to_configure_list(DriverPtr drvp)
{
const struct pci_id_match * const devices = drvp->supported_devices;
int j;
struct pci_device ** ppPci;
int numFound = 0;
for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
struct pci_device * const pPci = *ppPci;
/* Determine if this device is supported by the driver. If it is,
* add it to the list of devices to configure.
*/
for (j = 0 ; ! END_OF_MATCHES(devices[j]) ; j++) {
if ( PCI_ID_COMPARE( devices[j].vendor_id, pPci->vendor_id )
&& PCI_ID_COMPARE( devices[j].device_id, pPci->device_id )
&& ((devices[j].device_class_mask & pPci->device_class)
== devices[j].device_class) ) {
if (xf86CheckPciSlot(pPci)) {
GDevPtr pGDev =
xf86AddDeviceToConfigure(drvp->driverName, pPci, -1);
if (pGDev != NULL) {
/* After configure pass 1, chipID and chipRev are
* treated as over-rides, so clobber them here.
*/
pGDev->chipID = -1;
pGDev->chipRev = -1;
}
numFound++;
}
break;
}
}
}
return (numFound != 0);
}
Bool
check_for_matching_devices(DriverPtr drvp)
{
const struct pci_id_match * const devices = drvp->supported_devices;
int j;
struct pci_device ** ppPci;
for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) {
const struct pci_device * pPci = *ppPci;
/* Determine if this device is supported by the driver. If it is,
* add it to the list of devices to configure.
*/
for ( j = 0 ; ! END_OF_MATCHES( devices[j] ) ; j++ ) {
if ( PCI_ID_COMPARE( devices[j].vendor_id, pPci->vendor_id )
&& PCI_ID_COMPARE( devices[j].device_id, pPci->device_id )
&& ((devices[j].device_class_mask & pPci->device_class)
== devices[j].device_class) ) {
return TRUE;
}
}
}
return FALSE;
}
/**
* Call the driver's correct probe function.
*