diff options
author | Ian Romanick <idr@localhost.localdomain> | 2006-06-07 14:09:02 -0700 |
---|---|---|
committer | Ian Romanick <idr@localhost.localdomain> | 2006-06-07 14:09:02 -0700 |
commit | 46f55f5dead5d70cdff30531d80a72f6be042315 (patch) | |
tree | 8b06abaed2a9c3908299620dd3595393a1d2766d /hw/xfree86 | |
parent | d00aa6b8559d3e5f70c6558ce0abd12f7d758491 (diff) |
Initial batch of changes for PCI rework. All future changes will be
tracked individually.
Diffstat (limited to 'hw/xfree86')
37 files changed, 1036 insertions, 3400 deletions
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am index 8665926f6..68579f423 100644 --- a/hw/xfree86/Makefile.am +++ b/hw/xfree86/Makefile.am @@ -6,12 +6,12 @@ DOC_SUBDIR = doc SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support parser rac \ ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp xf8_16bpp \ - xf8_32bpp loader scanpci dixmods exa \ + xf8_32bpp loader dixmods exa \ $(DRI_SUBDIR) utils $(DOC_SUBDIR) getconfig DIST_SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support \ parser rac ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp \ - xf8_16bpp xf8_32bpp loader scanpci dixmods dri exa \ + xf8_16bpp xf8_32bpp loader dixmods dri exa \ utils doc getconfig bin_PROGRAMS = Xorg diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am index 0fe8aff27..37cb9d174 100644 --- a/hw/xfree86/common/Makefile.am +++ b/hw/xfree86/common/Makefile.am @@ -47,7 +47,7 @@ libinit_a_SOURCES = xf86Build.h xf86Init.c INCLUDES = $(XORG_INCS) -I$(srcdir)/../ddc -I$(srcdir)/../i2c \ -I$(srcdir)/../loader -I$(srcdir)/../rac -I$(srcdir)/../parser \ - -I$(srcdir)/../scanpci -I$(srcdir)/../vbe -I$(srcdir)/../int10 \ + -I$(srcdir)/../vbe -I$(srcdir)/../int10 \ -I$(srcdir)/../vgahw -I$(srcdir)/../dixmods/extmod sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \ diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h index 3c416a0be..941b36b02 100644 --- a/hw/xfree86/common/xf86.h +++ b/hw/xfree86/common/xf86.h @@ -37,6 +37,8 @@ #ifndef _XF86_H #define _XF86_H +#include <pciaccess.h> + #include "xf86str.h" #include "xf86Opt.h" #include <X11/Xfuncproto.h> @@ -94,16 +96,13 @@ extern CARD32 xf86DummyVar3; /* xf86Bus.c */ -Bool xf86CheckPciSlot(int bus, int device, int func); -int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp, +Bool xf86CheckPciSlot( const struct pci_device * ); +int xf86ClaimPciSlot( struct pci_device *, DriverPtr drvp, int chipset, GDevPtr dev, Bool active); Bool xf86ParsePciBusString(const char *busID, int *bus, int *device, int *func); Bool xf86ComparePciBusString(const char *busID, int bus, int device, int func); void xf86FormatPciBusNumber(int busnum, char *buffer); -pciVideoPtr *xf86GetPciVideoInfo(void); -pciConfigPtr *xf86GetPciConfigInfo(void); -void xf86SetPciVideo(pciVideoPtr, resType); void xf86PrintResList(int verb, resPtr list); resPtr xf86AddRangesToList(resPtr list, resRange *pRange, int entityIndex); int xf86ClaimIsaSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active); @@ -114,7 +113,7 @@ int xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active); int xf86ClaimNoSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active); void xf86EnableAccess(ScrnInfoPtr pScrn); void xf86SetCurrentAccess(Bool Enable, ScrnInfoPtr pScrn); -Bool xf86IsPrimaryPci(pciVideoPtr pPci); +Bool xf86IsPrimaryPci(struct pci_device * pPci); Bool xf86IsPrimaryIsa(void); /* new RAC */ resPtr xf86AddResToList(resPtr rlist, resRange *Range, int entityIndex); @@ -130,19 +129,17 @@ int xf86GetNumEntityInstances(int entityIndex); GDevPtr xf86GetDevFromEntity(int entityIndex, int instance); void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex); EntityInfoPtr xf86GetEntityInfo(int entityIndex); -pciVideoPtr xf86GetPciInfoForEntity(int entityIndex); +struct pci_device * xf86GetPciInfoForEntity(int entityIndex); int xf86GetPciEntity(int bus, int dev, int func); Bool xf86SetEntityFuncs(int entityIndex, EntityProc init, EntityProc enter, EntityProc leave, pointer); void xf86DeallocateResourcesForEntity(int entityIndex, unsigned long type); resPtr xf86RegisterResources(int entityIndex, resList list, unsigned long Access); -Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base); +Bool xf86CheckPciMemBase(struct pci_device * pPci, memType base); void xf86SetAccessFuncs(EntityInfoPtr pEnt, xf86SetAccessFuncPtr funcs, xf86SetAccessFuncPtr oldFuncs); Bool xf86IsEntityPrimary(int entityIndex); -Bool xf86FixPciResource(int entityIndex, int prt, memType alignment, - unsigned long type); resPtr xf86ReallocatePciResources(int entityIndex, resPtr pRes); resPtr xf86SetOperatingState(resList list, int entityIndex, int mask); void xf86EnterServerState(xf86State state); @@ -153,17 +150,13 @@ resRange xf86GetSparse(unsigned long type, memType fixed_bits, memType decode_mask, memType address_mask, resPtr avoid); memType xf86ChkConflict(resRange *rgp, int entityIndex); -Bool xf86IsPciDevPresent(int bus, int dev, int func); ScrnInfoPtr xf86FindScreenForEntity(int entityIndex); Bool xf86NoSharedResources(int screenIndex, resType res); resPtr xf86FindIntersectOfLists(resPtr l1, resPtr l2); -pciVideoPtr xf86FindPciDeviceVendor(CARD16 vendorID, CARD16 deviceID, - char n, pciVideoPtr pvp_exclude); -pciVideoPtr xf86FindPciClass(CARD8 intf, CARD8 subClass, CARD16 class, - char n, pciVideoPtr pvp_exclude); -#ifdef INCLUDE_DEPRECATED -void xf86EnablePciBusMaster(pciVideoPtr pPci, Bool enable); -#endif +struct pci_device * xf86FindPciDeviceVendor(CARD16 vendorID, CARD16 deviceID, + char n, const struct pci_device * pvp_exclude); +struct pci_device * xf86FindPciClass(CARD8 intf, CARD8 subClass, CARD16 class, + char n, const struct pci_device * pvp_exclude); void xf86RegisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func, pointer arg); Bool xf86DeregisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func); #ifdef async @@ -185,8 +178,8 @@ DevUnion *xf86GetEntityPrivate(int entityIndex, int privIndex); /* xf86Configure.c */ GDevPtr xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int chipset); -GDevPtr xf86AddDeviceToConfigure(const char *driver, pciVideoPtr pVideo, - int chipset); +GDevPtr xf86AddDeviceToConfigure( const char *driver, + struct pci_device * pVideo, int chipset ); /* xf86Cursor.c */ diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c index be07ec9d4..5c8c82049 100644 --- a/hw/xfree86/common/xf86AutoConfig.c +++ b/hw/xfree86/common/xf86AutoConfig.c @@ -176,7 +176,8 @@ xf86AutoConfig(void) { const char **p; char buf[1024]; - pciVideoPtr *pciptr, info = NULL; + struct pci_device ** pciptr; + struct pci_device * info = NULL; char *driver = NULL; FILE *gp = NULL; ConfigStatus ret; @@ -267,8 +268,8 @@ xf86AutoConfig(void) } strcat(searchPath, GETCONFIG_DIR); - ErrorF("xf86AutoConfig: Primary PCI is %d:%d:%d\n", - info->bus, info->device, info->func); + ErrorF("xf86AutoConfig: Primary PCI is %u@%u:%u:%u\n", + info->domain, info->bus, info->dev, info->func); snprintf(buf, sizeof(buf), "%s" #ifdef DEBUG @@ -281,9 +282,9 @@ xf86AutoConfig(void) path, (unsigned int)xorgGetVersion(), searchPath, - info->vendor, info->chipType, info->chipRev, - info->subsysVendor, info->subsysCard, - info->class << 8 | info->subclass); + info->vendor_id, info->device_id, info->revision, + info->subvendor_id, info->subdevice_id, + info->device_class >> 8); ErrorF("Running \"%s\"\n", buf); gp = Popen(buf, "r"); if (gp) { @@ -365,4 +366,3 @@ xf86AutoConfig(void) return FALSE; } } - diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c index d93503723..2282e9a8f 100644 --- a/hw/xfree86/common/xf86Bus.c +++ b/hw/xfree86/common/xf86Bus.c @@ -53,6 +53,7 @@ #include "xf86_OSproc.h" #include "xf86RAC.h" +#include "Pci.h" /* Entity data */ EntityPtr *xf86Entities = NULL; /* Bus slots claimed by drivers */ @@ -1402,7 +1403,9 @@ xf86AddRangesToList(resPtr list, resRange *pRange, int entityIndex) void xf86ResourceBrokerInit(void) { +#if 0 resPtr resPci; +#endif osRes = NULL; @@ -1417,8 +1420,12 @@ xf86ResourceBrokerInit(void) xf86PrintResList(3, osRes); /* Bus dep initialization */ +#if 0 resPci = ResourceBrokerInitPci(&osRes); Acc = xf86JoinResLists(xf86DupResList(osRes), resPci); +#else + Acc = xf86DupResList( osRes ); +#endif xf86MsgVerb(X_INFO, 3, "All system resource ranges:\n"); xf86PrintResList(3, Acc); @@ -1806,7 +1813,7 @@ xf86GetResourcesImplicitly(int entityIndex) case BUS_SBUS: return NULL; case BUS_PCI: - return GetImplicitPciResources(entityIndex); + return NULL; case BUS_last: return NULL; } @@ -1888,31 +1895,32 @@ xf86RegisterResources(int entityIndex, resList list, unsigned long access) } static void -busTypeSpecific(EntityPtr pEnt, xf86State state, xf86AccessPtr *acc_mem, - xf86AccessPtr *acc_io, xf86AccessPtr *acc_mem_io) +busTypeSpecific( EntityPtr pEnt, xf86AccessPtr *acc_mem, + xf86AccessPtr *acc_io, xf86AccessPtr *acc_mem_io ) { - pciAccPtr *ppaccp; - switch (pEnt->bus.type) { case BUS_ISA: case BUS_SBUS: - *acc_mem = *acc_io = *acc_mem_io = &AccessNULL; - break; + *acc_mem = *acc_io = *acc_mem_io = &AccessNULL; break; - case BUS_PCI: - ppaccp = xf86PciAccInfo; - while (*ppaccp) { - if ((*ppaccp)->busnum == pEnt->pciBusId.bus - && (*ppaccp)->devnum == pEnt->pciBusId.device - && (*ppaccp)->funcnum == pEnt->pciBusId.func) { - *acc_io = &(*ppaccp)->ioAccess; - *acc_mem = &(*ppaccp)->memAccess; - *acc_mem_io = &(*ppaccp)->io_memAccess; - break; + case BUS_PCI: { + struct pci_device * dev = + pci_device_find_by_slot( PCI_DOM_FROM_BUS( pEnt->pciBusId.bus ), + PCI_BUS_NO_DOMAIN( pEnt->pciBusId.bus ), + pEnt->pciBusId.device, + pEnt->pciBusId.func ); + + if ( dev != NULL ) { + pciAccPtr paccp = (pciAccPtr) dev->user_data; + + if ( paccp != NULL ) { + *acc_io = & paccp->ioAccess; + *acc_mem = & paccp->memAccess; + *acc_mem_io = & paccp->io_memAccess; } - ppaccp++; } break; + } default: *acc_mem = *acc_io = *acc_mem_io = NULL; break; @@ -1928,7 +1936,7 @@ setAccess(EntityPtr pEnt, xf86State state) xf86AccessPtr org_mem = NULL, org_io = NULL, org_mem_io = NULL; int prop; - busTypeSpecific(pEnt,state,&acc_mem,&acc_io,&acc_mem_io); + busTypeSpecific( pEnt, &acc_mem, &acc_io, &acc_mem_io ); /* The replacement function needs to handle _all_ shared resources */ /* unless they are handeled locally and disabled otherwise */ @@ -2481,15 +2489,6 @@ xf86PostProbe(void) #endif } xf86FreeResList(acc); -#if !(defined(__alpha__) && defined(linux)) && \ - !(defined(__ia64__) && defined(linux)) && \ - !(defined(__sparc64__) && defined(__OpenBSD__)) - /* - * No need to validate on Alpha Linux or OpenBSD/sparc64, - * trust the kernel. - */ - ValidatePci(); -#endif xf86MsgVerb(X_INFO, 3, "resource ranges after probing:\n"); xf86PrintResList(3, Acc); diff --git a/hw/xfree86/common/xf86Bus.h b/hw/xfree86/common/xf86Bus.h index 96da6e6a9..42030c8de 100644 --- a/hw/xfree86/common/xf86Bus.h +++ b/hw/xfree86/common/xf86Bus.h @@ -124,7 +124,7 @@ typedef struct x_BusAccRec { struct { int bus; int primary_bus; - PCITAG acc; + struct pci_device * dev; pciBridgesSave save; } pci; } busdep; diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 4b9d418b9..907e94bcd 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -36,6 +36,8 @@ #include <fcntl.h> #include <X11/X.h> #include <X11/Xmd.h> +#include <pciaccess.h> +#include "Pci.h" #include "os.h" #ifdef XFree86LOADER #include "loaderProcs.h" @@ -44,7 +46,6 @@ #include "xf86Config.h" #include "xf86_OSlib.h" #include "xf86Priv.h" -#include "xf86PciData.h" #define IN_XSERVER #include "xf86Parser.h" #include "xf86tokens.h" @@ -59,7 +60,7 @@ typedef struct _DevToConfig { GDevRec GDev; - pciVideoPtr pVideo; + struct pci_device * pVideo; #if defined(__sparc__) && !defined(__OpenBSD__) sbusDevicePtr sVideo; #endif @@ -104,7 +105,7 @@ GDevPtr xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int chipset) { int i, j; - pciVideoPtr pVideo = NULL; + struct pci_device * pVideo = NULL; Bool isPrimary = FALSE; if (xf86DoProbe || !xf86DoConfigure || !xf86DoConfigurePass1) @@ -113,11 +114,12 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int /* Check for duplicates */ switch (bus) { case BUS_PCI: - pVideo = (pciVideoPtr) busData; + pVideo = (struct pci_device *) busData; for (i = 0; i < nDevToConfig; i++) if (DevToConfig[i].pVideo && + (DevToConfig[i].pVideo->domain == pVideo->domain) && (DevToConfig[i].pVideo->bus == pVideo->bus) && - (DevToConfig[i].pVideo->device == pVideo->device) && + (DevToConfig[i].pVideo->dev == pVideo->dev) && (DevToConfig[i].pVideo->func == pVideo->func)) return NULL; isPrimary = xf86IsPrimaryPci(pVideo); @@ -176,9 +178,9 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int char busnum[8]; NewDevice.pVideo = pVideo; - xf86FindPciNamesByDevice(pVideo->vendor, pVideo->chipType, - NOVENDOR, NOSUBSYS, - &VendorName, &CardName, NULL, NULL); + + VendorName = pci_device_get_vendor_name( pVideo ); + CardName = pci_device_get_device_name( pVideo ); if (!VendorName) { VendorName = xnfalloc(15); @@ -200,13 +202,13 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int NewDevice.GDev.busID = xnfalloc(16); xf86FormatPciBusNumber(pVideo->bus, busnum); sprintf(NewDevice.GDev.busID, "PCI:%s:%d:%d", - busnum, pVideo->device, pVideo->func); + busnum, pVideo->dev, pVideo->func); - NewDevice.GDev.chipID = pVideo->chipType; - NewDevice.GDev.chipRev = pVideo->chipRev; + NewDevice.GDev.chipID = pVideo->device_id; + NewDevice.GDev.chipRev = pVideo->revision; if (chipset < 0) - chipset = (pVideo->vendor << 16) | pVideo->chipType; + chipset = (pVideo->vendor_id << 16) | pVideo->device_id; } break; case BUS_ISA: @@ -252,7 +254,8 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int * Backwards compatibility */ _X_EXPORT GDevPtr -xf86AddDeviceToConfigure(const char *driver, pciVideoPtr pVideo, int chipset) +xf86AddDeviceToConfigure(const char *driver, struct pci_device * pVideo, + int chipset) { return xf86AddBusDeviceToConfigure(driver, pVideo ? BUS_PCI : BUS_ISA, pVideo, chipset); @@ -828,22 +831,20 @@ DoConfigure() /* Call all of the probe functions, reporting the results. */ for (CurrentDriver = 0; CurrentDriver < xf86NumDrivers; CurrentDriver++) { xorgHWFlags flags; - + Bool found_screen; + DriverRec * const drv = xf86DriverList[CurrentDriver]; + if (!xorgHWAccess) { - if (!xf86DriverList[CurrentDriver]->driverFunc - || !xf86DriverList[CurrentDriver]->driverFunc(NULL, - GET_REQUIRED_HW_INTERFACES, - &flags) + if (!drv->driverFunc + || !drv->driverFunc( NULL, GET_REQUIRED_HW_INTERFACES, &flags ) || NEED_IO_ENABLED(flags)) continue; } - if (xf86DriverList[CurrentDriver]->Probe == NULL) continue; - - if ((*xf86DriverList[CurrentDriver]->Probe)( - xf86DriverList[CurrentDriver], PROBE_DETECT) && - xf86DriverList[CurrentDriver]->Identify) - (*xf86DriverList[CurrentDriver]->Identify)(0); + found_screen = xf86CallDriverProbe( drv, TRUE ); + if ( found_screen && drv->Identify ) { + (*drv->Identify)(0); + } } if (nDevToConfig <= 0) { @@ -932,7 +933,7 @@ DoConfigure() oldNumScreens = xf86NumScreens; - (*xf86DriverList[i]->Probe)(xf86DriverList[i], 0); + xf86CallDriverProbe( xf86DriverList[i], FALSE ); /* reorder */ k = screennum > 0 ? screennum : 1; @@ -960,7 +961,6 @@ DoConfigure() } } } - xf86SetPciVideo(NULL,NONE); } xfree(driverProbed); } diff --git a/hw/xfree86/common/xf86DoProbe.c b/hw/xfree86/common/xf86DoProbe.c index b74f37e11..e76fd91d0 100644 --- a/hw/xfree86/common/xf86DoProbe.c +++ b/hw/xfree86/common/xf86DoProbe.c @@ -97,9 +97,7 @@ DoProbe() xf86MsgVerb(X_INFO, 3, "Probing in driver %s\n", drv->driverName); - if (drv->Probe == NULL) continue; - - probeResult = (*drv->Probe)( drv, PROBE_DETECT ); + probeResult = xf86CallDriverProbe( drv, TRUE ); if (!probeResult) { xf86ErrorF("Probe in driver `%s' returns FALSE\n", drv->driverName); diff --git a/hw/xfree86/common/xf86DoScanPci.c b/hw/xfree86/common/xf86DoScanPci.c index 9f8c15651..f08af2bb3 100644 --- a/hw/xfree86/common/xf86DoScanPci.c +++ b/hw/xfree86/common/xf86DoScanPci.c @@ -39,6 +39,7 @@ #include <stdlib.h> #include <X11/X.h> #include <X11/Xmd.h> +#include <pciaccess.h> #include "os.h" #ifdef XFree86LOADER #include "loaderProcs.h" @@ -46,17 +47,100 @@ #include "xf86.h" #include "xf86Priv.h" #include "xf86Pci.h" -#include "xf86ScanPci.h" + +static void ScanPciDisplayPCICardInfo( int verbosity ); + +void +ScanPciDisplayPCICardInfo(int verbosity) +{ + struct pci_id_match match; + pciConfigPtr pcrp, *pcrpp; + int i; + + xf86EnableIO(); + pcrpp = xf86scanpci(0); + + if (pcrpp == NULL) { + xf86MsgVerb(X_NONE,0,"No PCI info available\n"); + return; + } + xf86MsgVerb(X_NONE,0,"Probing for PCI devices (Bus:Device:Function)\n\n"); + for (i = 0; (pcrp = pcrpp[i]); i++) { + const char *svendorname = NULL, *subsysname = NULL; + const char *vendorname = NULL, *devicename = NULL; + Bool noCard = FALSE; + const char *prefix1 = "", *prefix2 = ""; + + xf86MsgVerb(X_NONE, -verbosity, "(%d:%d:%d) ", + pcrp->busnum, pcrp->devnum, pcrp->funcnum); + + /* + * Lookup as much as we can about the device. + */ + match.vendor_id = pcrp->pci_vendor; + match.device_id = pcrp->_pci_device; + match.subvendor_id = (pcrp->pci_subsys_vendor != 0) + ? pcrp->pci_subsys_vendor : PCI_MATCH_ANY; + match.subdevice_id = (pcrp->pci_subsys_card != 0) + ? pcrp->pci_subsys_card : PCI_MATCH_ANY; + match.device_class = 0; + match.device_class_mask = 0; + + pci_get_strings( & match, & vendorname, & devicename, + & svendorname, & subsysname); + + if (svendorname) + xf86MsgVerb(X_NONE, -verbosity, "%s ", svendorname); + if (subsysname) + xf86MsgVerb(X_NONE, -verbosity, "%s ", subsysname); + if (svendorname && !subsysname) { + if ( match.subdevice_id != PCI_MATCH_ANY ) { + xf86MsgVerb(X_NONE, -verbosity, "unknown card (0x%04x) ", + match.subdevice_id); + } else { + xf86MsgVerb(X_NONE, -verbosity, "card "); + } + } + if (!svendorname && !subsysname) { + /* + * We didn't find a text representation of the information + * about the card. + */ + if ( (match.subvendor_id != PCI_MATCH_ANY) + || (match.subdevice_id != PCI_MATCH_ANY) ) { + /* + * If there was information and we just couldn't interpret + * it, print it out as unknown, anyway. + */ + xf86MsgVerb(X_NONE, -verbosity, + "unknown card (0x%04x/0x%04x) ", + match.subvendor_id, match.subdevice_id); + } else + noCard = TRUE; + } + if (!noCard) { + prefix1 = "using a "; + prefix2 = "using an "; + } + if (vendorname && devicename) { + xf86MsgVerb(X_NONE, -verbosity,"%s%s %s\n", prefix1, vendorname, + devicename); + } else if (vendorname) { + xf86MsgVerb(X_NONE, -verbosity, + "%sunknown chip (DeviceId 0x%04x) from %s\n", + prefix2, match.device_id, vendorname); + } else { + xf86MsgVerb(X_NONE, -verbosity, + "%sunknown chipset(0x%04x/0x%04x)\n", + prefix2, match.vendor_id, match.device_id); + } + } +} void DoScanPci(int argc, char **argv, int i) { - int j,skip,globalVerbose,scanpciVerbose; - ScanPciSetupProcPtr PciSetup; - ScanPciDisplayCardInfoProcPtr DisplayPCICardInfo; -#ifdef XFree86LOADER - int errmaj, errmin; -#endif + int j,skip,globalVerbose; /* * first we need to finish setup of the OS so that we can call other @@ -90,37 +174,7 @@ void DoScanPci(int argc, char **argv, int i) * Setting scanpciVerbose to 0 will ensure that the output will go to * stderr for all reasonable default stderr verbosity levels. */ - scanpciVerbose = 0; - - /* - * now get the loader set up and load the scanpci module - */ -#ifdef XFree86LOADER - /* Initialise the loader */ - LoaderInit(); - /* Tell the loader the default module search path */ - LoaderSetPath(xf86ModulePath); - - if (!LoadModule("scanpci", NULL, NULL, NULL, NULL, NULL, - &errmaj, &errmin)) { - LoaderErrorMsg(NULL, "scanpci", errmaj, errmin); - exit(1); - } - if (LoaderCheckUnresolved(LD_RESOLV_IFDONE)) { - /* For now, just a warning */ - xf86Msg(X_WARNING, "Some symbols could not be resolved!\n"); - } - PciSetup = (ScanPciSetupProcPtr)LoaderSymbol("ScanPciSetupPciIds"); - DisplayPCICardInfo = - (ScanPciDisplayCardInfoProcPtr)LoaderSymbol("ScanPciDisplayPCICardInfo"); -#else - PciSetup = ScanPciSetupPciIds; - DisplayPCICardInfo = ScanPciDisplayPCICardInfo; -#endif - - if (!(*PciSetup)()) - FatalError("ScanPciSetupPciIds() failed\n"); - (*DisplayPCICardInfo)(scanpciVerbose); + ScanPciDisplayPCICardInfo( 0 ); /* * That's it; we really should clean things up, but a simple diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index 1e7742761..bfde44e63 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -40,6 +40,9 @@ #include <xorg-config.h> #endif +#include <pciaccess.h> +#include "Pci.h" + #include <X11/X.h> #include "os.h" #include "servermd.h" @@ -1591,7 +1594,7 @@ xf86MatchDevice(const char *drivername, GDevPtr **sectlist) } struct Inst { - pciVideoPtr pci; + struct pci_device * pci; GDevPtr dev; Bool foundHW; /* PCIid in list of supported chipsets */ Bool claimed; /* BusID matches with a device section */ @@ -1600,6 +1603,192 @@ 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. * @@ -1639,7 +1828,8 @@ xf86MatchPciInstances(const char *driverName, int vendorID, int **foundEntities) { int i,j; - pciVideoPtr pPci, *ppPci; + struct pci_device * pPci; + struct pci_device ** ppPci; struct Inst *instances = NULL; int numClaimedInstances = 0; int allocatedInstances = 0; @@ -1667,8 +1857,7 @@ xf86MatchPciInstances(const char *driverName, int vendorID, } for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) { - unsigned device_class = ((*ppPci)->class << 16) - | ((*ppPci)->subclass << 8) | ((*ppPci)->interface); + unsigned device_class = (*ppPci)->device_class; Bool foundVendor = FALSE; @@ -1698,7 +1887,7 @@ xf86MatchPciInstances(const char *driverName, int vendorID, const unsigned device_id = (id->PCIid & 0x0000FFFF); const unsigned match_class = 0x00030000 | id->PCIid; - if ( (vendor_id == pPci->vendor) + if ( (vendor_id == pPci->vendor_id) || ((vendorID == PCI_VENDOR_GENERIC) && (match_class == device_class)) ) { if ( !foundVendor && (instances != NULL) ) { ++allocatedInstances; @@ -1707,9 +1896,11 @@ xf86MatchPciInstances(const char *driverName, int vendorID, instances[allocatedInstances - 1].claimed = FALSE; instances[allocatedInstances - 1].foundHW = FALSE; instances[allocatedInstances - 1].screen = 0; - foundVendor = TRUE; } - if ( (device_id == pPci->chipType) + + foundVendor = TRUE; + + if ( (device_id == pPci->device_id) || ((vendorID == PCI_VENDOR_GENERIC) && (match_class == device_class)) ) { if ( instances != NULL ) { @@ -1719,8 +1910,7 @@ xf86MatchPciInstances(const char *driverName, int vendorID, if ( xf86DoConfigure && xf86DoConfigurePass1 ) { - if ( xf86CheckPciSlot(pPci->bus, pPci->device, - pPci->func) ) { + if ( xf86CheckPciSlot( pPci ) ) { GDevPtr pGDev = xf86AddDeviceToConfigure( drvp->driverName, pPci, -1 ); @@ -1783,8 +1973,9 @@ xf86MatchPciInstances(const char *driverName, int vendorID, && *devList[j]->busID) { for (i = 0; i < allocatedInstances; i++) { pPci = instances[i].pci; - if (xf86ComparePciBusString(devList[j]->busID, pPci->bus, - pPci->device, + if (xf86ComparePciBusString(devList[j]->busID, + PCI_MAKE_BUS( pPci->domain, pPci->bus ), + pPci->dev, pPci->func)) { allocatedInstances++; instances[allocatedInstances - 1] = instances[i]; @@ -1804,9 +1995,10 @@ xf86MatchPciInstances(const char *driverName, int vendorID, pPci = instances[i].pci; for (j = 0; j < numDevs; j++) { if (devList[j]->busID && *devList[j]->busID) { - if (xf86ComparePciBusString(devList[j]->busID, pPci->bus, - pPci->device, - pPci->func) && + if (xf86ComparePciBusString(devList[j]->busID, + PCI_MAKE_BUS( pPci->domain, pPci->bus ), + pPci->dev, + pPci->func) && devList[j]->screen == instances[i].screen) { if (devBus) @@ -1837,10 +2029,11 @@ xf86MatchPciInstances(const char *driverName, int vendorID, } if (devBus) dev = devBus; /* busID preferred */ if (!dev) { - if (xf86CheckPciSlot(pPci->bus, pPci->device, pPci->func)) { + if ( xf86CheckPciSlot( pPci ) ) { xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " - "for instance (BusID PCI:%i:%i:%i) found\n", - driverName, pPci->bus, pPci->device, pPci->func); + "for instance (BusID PCI:%u@%u:%u:%u) found\n", + driverName, pPci->domain, pPci->bus, pPci->dev, + pPci->func); } } else { numClaimedInstances++; @@ -1951,30 +2144,28 @@ xf86MatchPciInstances(const char *driverName, int vendorID, * XXX Need to make sure that two different drivers don't claim * the same screen > 0 instance. */ - if (instances[i].screen == 0 && - !xf86CheckPciSlot(pPci->bus, pPci->device, pPci->func)) + if (instances[i].screen == 0 && !xf86CheckPciSlot( pPci )) continue; #ifdef DEBUG ErrorF("%s: card at %d:%d:%d is claimed by a Device section\n", - driverName, pPci->bus, pPci->device, pPci->func); + driverName, pPci->bus, pPci->dev, pPci->func); #endif /* Allocate an entry in the lists to be returned */ numFound++; retEntities = xnfrealloc(retEntities, numFound * sizeof(int)); - retEntities[numFound - 1] - = xf86ClaimPciSlot(pPci->bus, pPci->device, - pPci->func,drvp, instances[i].chip, - instances[i].dev,instances[i].dev->active ? - TRUE : FALSE); + retEntities[numFound - 1] = xf86ClaimPciSlot( pPci, drvp, + instances[i].chip, + instances[i].dev, + instances[i].dev->active); if (retEntities[numFound - 1] == -1 && instances[i].screen > 0) { for (j = 0; j < xf86NumEntities; j++) { EntityPtr pEnt = xf86Entities[j]; if (pEnt->busType != BUS_PCI) continue; - if (pEnt->pciBusId.bus == pPci->bus && - pEnt->pciBusId.device == pPci->device && + if (pEnt->pciBusId.bus == PCI_MAKE_BUS( pPci->domain, pPci->bus ) && + pEnt->pciBusId.device == pPci->dev && pEnt->pciBusId.func == pPci->func) { retEntities[numFound - 1] = j; xf86AddDevToEntity(j, instances[i].dev); diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index 9bb2bf8b2..ae2ea79b0 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -1,5 +1,5 @@ /* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Init.c,v 3.212 2004/01/27 01:31:45 dawes Exp $ */ -/* $XdotOrg: xserver/xorg/hw/xfree86/common/xf86Init.c,v 1.36 2006/06/01 18:47:01 daniels Exp $ */ +/* $XdotOrg: xserver/xorg/hw/xfree86/common/xf86Init.c,v 1.37 2006/06/01 19:37:53 ajax Exp $ */ /* * Loosely based on code bearing the following copyright: @@ -114,13 +114,6 @@ extern void os2ServerVideoAccess(); void (*xf86OSPMClose)(void) = NULL; #endif -#ifdef XFree86LOADER -static char *baseModules[] = { - "pcidata", - NULL -}; -#endif - /* Common pixmap formats */ static PixmapFormatRec formats[MAXFORMATS] = { @@ -267,6 +260,53 @@ PostConfigInit(void) OsInitColors(); } + +/** + * Call the driver's correct probe function. + * + * If the driver implements the \c DriverRec::PciProbe entry-point and an + * appropriate PCI device (with matching Device section in the xorg.conf file) + * is found, it is called. If \c DriverRec::PciProbe or no devices can be + * successfully probed with it (e.g., only non-PCI devices are available), + * the driver's \c DriverRec::Probe function is called. + * + * \param drv Driver to probe + * + * \return + * If a device can be successfully probed by the driver, \c TRUE is + * returned. Otherwise, \c FALSE is returned. + */ +Bool +xf86CallDriverProbe( DriverPtr drv, Bool detect_only ) +{ + Bool foundScreen = FALSE; + + if ( drv->PciProbe != NULL ) { + if ( xf86DoProbe ) { + assert( detect_only ); + foundScreen = check_for_matching_devices( drv ); + } + else if ( xf86DoConfigure && xf86DoConfigurePass1 ) { + assert( detect_only ); + foundScreen = add_matching_devices_to_configure_list( drv ); + } + else { + assert( ! detect_only ); + foundScreen = probe_devices_from_device_sections( drv ); + } + } + + if ( ! foundScreen && (drv->Probe != NULL) ) { + xf86Msg( X_WARNING, "Falling back to old probe method for %s\n", + drv->driverName ); + foundScreen = (*drv->Probe)( drv, (detect_only) ? PROBE_DETECT + : PROBE_DEFAULT ); + } + + return foundScreen; +} + + void InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) { @@ -372,11 +412,6 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) LoaderFreeDirList(list); } #endif - - /* Force load mandatory base modules */ - if (!xf86LoadModules(baseModules, NULL)) - FatalError("Unable to load required base modules, Exiting...\n"); - #endif xf86OpenConsole(); @@ -501,16 +536,8 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) || NEED_IO_ENABLED(flags)) continue; } - - if (xf86DriverList[i]->Probe != NULL) - xf86DriverList[i]->Probe(xf86DriverList[i], PROBE_DEFAULT); - else { - xf86MsgVerb(X_WARNING, 0, - "Driver `%s' has no Probe function (ignoring)\n", - xf86DriverList[i]->driverName - ? xf86DriverList[i]->driverName : "noname"); - } - xf86SetPciVideo(NULL,NONE); + + xf86CallDriverProbe( xf86DriverList[i], FALSE ); } /* diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h index 0794de777..f40a217f5 100644 --- a/hw/xfree86/common/xf86Priv.h +++ b/hw/xfree86/common/xf86Priv.h @@ -37,6 +37,8 @@ #ifndef _XF86PRIV_H #define _XF86PRIV_H +#include <pciaccess.h> + #include "xf86Privstr.h" #include "propertyst.h" @@ -107,7 +109,7 @@ extern Bool xf86Resetting; extern Bool xf86Initialising; extern Bool xf86ProbeFailed; extern int xf86NumScreens; -extern pciVideoPtr *xf86PciVideoInfo; +extern struct pci_device ** xf86PciVideoInfo; extern xf86CurrentAccessRec xf86CurrentAccess; extern const char *xf86VisualNames[]; extern int xf86Verbose; /* verbosity level */ @@ -154,9 +156,6 @@ void xf86ClearEntityListForScreen(int scrnIndex); void xf86AddDevToEntity(int entityIndex, GDevPtr dev); extern void xf86PostPreInit(void); extern void xf86PostScreenInit(void); -extern memType getValidBIOSBase(PCITAG tag, int num); -extern memType getEmptyPciRange(PCITAG tag, int base_reg); -extern int pciTestMultiDeviceCard(int bus, int dev, int func, PCITAG** pTag); /* xf86Config.c */ @@ -197,6 +196,7 @@ void xf86CloseLog(void); Bool xf86LoadModules(char **list, pointer *optlist); int xf86SetVerbosity(int verb); int xf86SetLogVerbosity(int verb); +Bool xf86CallDriverProbe( struct _DriverRec * drv, Bool detect_only ); /* xf86Io.c */ diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c index 4d587a13f..fa88e74ca 100644 --- a/hw/xfree86/common/xf86pciBus.c +++ b/hw/xfree86/common/xf86pciBus.c @@ -29,8 +29,6 @@ /* * This file contains the interfaces to the bus-specific code */ -#define INCLUDE_DEPRECATED 1 - #ifdef HAVE_XORG_CONFIG_H #include <xorg-config.h> #endif @@ -39,6 +37,7 @@ #include <stdlib.h> #include <unistd.h> #include <X11/X.h> +#include <pciaccess.h> #include "os.h" #include "Pci.h" #include "xf86.h" @@ -46,8 +45,6 @@ #include "xf86Resources.h" /* Bus-specific headers */ -#include "xf86PciData.h" - #include "xf86Bus.h" #define XF86_OS_PRIVS @@ -58,67 +55,56 @@ /* Bus-specific globals */ Bool pciSlotClaimed = FALSE; -pciConfigPtr *xf86PciInfo = NULL; /* Full PCI probe info */ -pciVideoPtr *xf86PciVideoInfo = NULL; /* PCI probe for video hw */ -pciAccPtr * xf86PciAccInfo = NULL; /* PCI access related */ - -/* pcidata globals */ -ScanPciSetupProcPtr xf86SetupPciIds = NULL; -ScanPciCloseProcPtr xf86ClosePciIds = NULL; -ScanPciFindByDeviceProcPtr xf86FindPciNamesByDevice = NULL; -ScanPciFindBySubsysProcPtr xf86FindPciNamesBySubsys = NULL; - -static resPtr pciAvoidRes = NULL; +static pciConfigPtr *xf86PciInfo = NULL; /* Full PCI probe info */ +struct pci_device ** xf86PciVideoInfo = NULL; /* PCI probe for video hw */ /* PCI buses */ static PciBusPtr xf86PciBus = NULL; /* Bus-specific probe/sorting functions */ /* PCI classes that get included in xf86PciVideoInfo */ -#define PCIINFOCLASSES(b,s) \ - (((b) == PCI_CLASS_PREHISTORIC) || \ - ((b) == PCI_CLASS_DISPLAY) || \ - ((b) == PCI_CLASS_MULTIMEDIA && (s) == PCI_SUBCLASS_MULTIMEDIA_VIDEO) || \ - ((b) == PCI_CLASS_PROCESSOR && (s) == PCI_SUBCLASS_PROCESSOR_COPROC)) +#define PCIINFOCLASSES(c) \ + ( (((c) & 0x00ff0000) == (PCI_CLASS_PREHISTORIC << 16)) \ + || (((c) & 0x00ff0000) == (PCI_CLASS_DISPLAY << 16)) \ + || ((((c) & 0x00ffff00) \ + == ((PCI_CLASS_MULTIMEDIA << 16) | (PCI_SUBCLASS_MULTIMEDIA_VIDEO << 8)))) \ + || ((((c) & 0x00ffff00) \ + == ((PCI_CLASS_PROCESSOR << 16) | (PCI_SUBCLASS_PROCESSOR_COPROC << 8)))) ) /* * PCI classes that have messages printed always. The others are only * have a message printed when the vendor/dev IDs are recognised. */ -#define PCIALWAYSPRINTCLASSES(b,s) \ - (((b) == PCI_CLASS_PREHISTORIC && (s) == PCI_SUBCLASS_PREHISTORIC_VGA) || \ - ((b) == PCI_CLASS_DISPLAY) || \ - ((b) == PCI_CLASS_MULTIMEDIA && (s) == PCI_SUBCLASS_MULTIMEDIA_VIDEO)) - +#define PCIALWAYSPRINTCLASSES(c) \ + ( (((c) & 0x00ffff00) \ + == ((PCI_CLASS_PREHISTORIC << 16) | (PCI_SUBCLASS_PREHISTORIC_VGA << 8))) \ + || (((c) & 0x00ff0000) == (PCI_CLASS_DISPLAY << 16)) \ + || ((((c) & 0x00ffff00) \ + == ((PCI_CLASS_MULTIMEDIA << 16) | (PCI_SUBCLASS_MULTIMEDIA_VIDEO << 8)))) ) + +#define IS_VGA(c) \ + (((c) & 0x00ffff00) \ + == ((PCI_CLASS_DISPLAY << 16) | (PCI_SUBCLASS_DISPLAY_VGA << 8))) + /* * PCI classes for which potentially destructive checking of the map sizes * may be done. Any classes where this may be unsafe should be omitted * from this list. */ -#define PCINONSYSTEMCLASSES(b,s) PCIALWAYSPRINTCLASSES(b,s) +#define PCINONSYSTEMCLASSES(c) PCIALWAYSPRINTCLASSES(c) /* * PCI classes that use RAC */ -#define PCISHAREDIOCLASSES(b,s) \ - (((b) == PCI_CLASS_PREHISTORIC && (s) == PCI_SUBCLASS_PREHISTORIC_VGA) || \ - ((b) == PCI_CLASS_DISPLAY && (s) == PCI_SUBCLASS_DISPLAY_VGA)) +#define PCISHAREDIOCLASSES(c) \ + ( (((c) & 0x00ffff00) \ + == ((PCI_CLASS_PREHISTORIC << 16) | (PCI_SUBCLASS_PREHISTORIC_VGA << 8))) \ + || IS_VGA(c) ) -#define PCI_MEM32_LENGTH_MAX 0xFFFFFFFF #define B2M(tag,base) pciBusAddrToHostAddr(tag,PCI_MEM,base) #define B2I(tag,base) pciBusAddrToHostAddr(tag,PCI_IO,base) -#define B2H(tag,base,type) (((type & ResPhysMask) == ResMem) ? \ - B2M(tag, base) : B2I(tag, base)) -#define M2B(tag,base) pciHostAddrToBusAddr(tag,PCI_MEM,base) -#define I2B(tag,base) pciHostAddrToBusAddr(tag,PCI_IO,base) -#define H2B(tag,base,type) (((type & ResPhysMask) == ResMem) ? \ - M2B(tag, base) : I2B(tag, base)) -#define TAG(pvp) (pciTag(pvp->bus,pvp->device,pvp->func)) -#define SIZE(size) ((1 << size) - 1) -#define PCI_SIZE(type,tag,size) (((type & ResPhysMask) == ResMem) \ - ? pciBusAddrToHostAddr(tag,PCI_MEM_SIZE,size) \ - : pciBusAddrToHostAddr(tag,PCI_IO_SIZE,size)) + #define PCI_M_RANGE(range,tag,begin,end,type) \ { \ RANGE(range, B2M(tag, begin), B2M(tag, end), \ @@ -129,24 +115,7 @@ static PciBusPtr xf86PciBus = NULL; RANGE(range, B2I(tag, begin), B2I(tag, end), \ RANGE_TYPE(type, xf86GetPciDomain(tag))); \ } -#define PCI_X_RANGE(range,tag,begin,end,type) \ -{ if ((type & ResPhysMask) == ResMem) PCI_M_RANGE(range,tag,begin,end,type); \ - else PCI_I_RANGE(range,tag,begin,end,type); } -#define P_M_RANGE(range,tag,begin,size,type) \ - PCI_M_RANGE(range,tag,begin,(begin + SIZE(size)),type) -#define P_I_RANGE(range,tag,begin,size,type) \ - PCI_I_RANGE(range,tag,begin,(begin + SIZE(size)),type) -#define P_X_RANGE(range,tag,begin,size,type) \ -{ if ((type & ResPhysMask) == ResMem) P_M_RANGE(range,tag,begin,size,type); \ - else P_I_RANGE(range,tag,begin,size,type); } -#define PV_M_RANGE(range,pvp,i,type) \ - P_M_RANGE(range,TAG(pvp),pvp->memBase[i],pvp->size[i],type) -#define PV_B_RANGE(range,pvp,type) \ - P_M_RANGE(range,TAG(pvp),pvp->biosBase,pvp->biosSize,type) -#define PV_I_RANGE(range,pvp,i,type) \ - P_I_RANGE(range,TAG(pvp),pvp->ioBase[i],pvp->size[i],type) - -static void pciConvertListToHost(int bus, int dev, int func, resPtr list); + static PciBusPtr xf86GetPciBridgeInfo(void); _X_EXPORT void @@ -159,92 +128,64 @@ xf86FormatPciBusNumber(int busnum, char *buffer) sprintf(buffer, "%d@%d", busnum & 0x00ff, busnum >> 8); } -static Bool -IsBaseUnassigned(CARD32 base) -{ - CARD32 mask; - - if (base & PCI_MAP_IO) - mask = ~PCI_MAP_IO_ATTR_MASK; - else - mask = ~PCI_MAP_MEMORY_ATTR_MASK; - - base &= mask; - return (!base || (base == mask)); -} - -static Bool -IsBaseUnassigned64(CARD32 base0, CARD32 base1) -{ - base0 &= ~PCI_MAP_MEMORY_ATTR_MASK; - base1 &= 0xffffffff; - - return ((!base0 && !base1) - || ((base0 == ~PCI_MAP_MEMORY_ATTR_MASK) - && (base1 == 0xffffffff))); -} - static void FindPCIVideoInfo(void) { - pciConfigPtr pcrp, *pcrpp; int i = 0, j, k; int num = 0; - pciVideoPtr info; - int DoIsolateDeviceCheck = 0; + struct pci_device * info; + struct pci_slot_match m; + struct pci_device_iterator * iter; - if (xf86IsolateDevice.bus || xf86IsolateDevice.device || xf86IsolateDevice.func) - DoIsolateDeviceCheck = 1; - pcrpp = xf86PciInfo = xf86scanpci(0); - - if (pcrpp == NULL) { + xf86PciInfo = xf86scanpci(0); + + if (xf86PciInfo == NULL) { xf86PciVideoInfo = NULL; return; } + xf86PciBus = xf86GetPciBridgeInfo(); - while ((pcrp = pcrpp[i])) { - const int baseclass = pcrp->pci_base_class; - const int subclass = pcrp->pci_sub_class; - - if ( PCIINFOCLASSES(baseclass, subclass) && - (!DoIsolateDeviceCheck || - (xf86IsolateDevice.bus == pcrp->busnum && - xf86IsolateDevice.device == pcrp->devnum && - xf86IsolateDevice.func == pcrp->funcnum)) ) { + if ( (xf86IsolateDevice.bus != 0) + || (xf86IsolateDevice.device != 0) + || (xf86IsolateDevice.func != 0) ) { + m.domain = PCI_DOM_FROM_BUS( xf86IsolateDevice.bus ); + m.bus = PCI_BUS_NO_DOMAIN( xf86IsolateDevice.bus ); + m.dev = xf86IsolateDevice.device; + m.func = xf86IsolateDevice.func; + } + else { + m.domain = PCI_MATCH_ANY; + m.bus = PCI_MATCH_ANY; + m.dev = PCI_MATCH_ANY; + m.func = PCI_MATCH_ANY; + } + + iter = pci_slot_match_iterator_create( & m ); + + while ( (info = pci_device_next( iter )) != NULL ) { + if ( PCIINFOCLASSES( info->device_class ) ) { num++; - xf86PciVideoInfo = xnfrealloc(xf86PciVideoInfo, - sizeof(pciVideoPtr) * (num + 1)); + xf86PciVideoInfo = xnfrealloc( xf86PciVideoInfo, + (sizeof( struct pci_device * ) + * (num + 1)) ); xf86PciVideoInfo[num] = NULL; - info = xf86PciVideoInfo[num - 1] = xnfalloc(sizeof(pciVideoRec)); - info->validSize = FALSE; - info->vendor = pcrp->pci_vendor; - info->chipType = pcrp->pci_device; - info->chipRev = pcrp->pci_rev_id; - info->subsysVendor = pcrp->pci_subsys_vendor; - info->subsysCard = pcrp->pci_subsys_card; - info->bus = pcrp->busnum; - info->device = pcrp->devnum; - info->func = pcrp->funcnum; - info->class = baseclass; - info->subclass = pcrp->pci_sub_class; - info->interface = pcrp->pci_prog_if; - info->biosBase = PCIGETROM(pcrp->pci_baserom); - info->biosSize = pciGetBaseSize(pcrp->tag, 6, TRUE, NULL); - info->thisCard = pcrp; - info->validate = FALSE; -#ifdef INCLUDE_XF86_NO_DOMAIN - if ((PCISHAREDIOCLASSES(baseclass, subclass)) - && (pcrp->pci_command & PCI_CMD_IO_ENABLE) && - (pcrp->pci_prog_if == 0)) { + xf86PciVideoInfo[num - 1] = info; + + pci_device_probe(info); + info->user_data = 0; +#if 0 && defined(INCLUDE_XF86_NO_DOMAIN) + if ((PCISHAREDIOCLASSES( info->device_class )) + && (pcrp->pci_command & PCI_CMD_IO_ENABLE) + && (pcrp->pci_prog_if == 0)) { /* * Attempt to ensure that VGA is actually routed to this * adapter on entry. This needs to be fixed when we finally * grok host bridges (and multiple bus trees). */ - j = info->bus; + j = pcrp->busnum; while (TRUE) { PciBusPtr pBus = xf86PciBus; while (pBus && j != pBus->secondary) @@ -269,102 +210,25 @@ FindPCIVideoInfo(void) } } #endif - - for (j = 0; j < 6; j++) { - info->memBase[j] = 0; - info->ioBase[j] = 0; - if (PCINONSYSTEMCLASSES(baseclass, subclass)) { - info->size[j] = - pciGetBaseSize(pcrp->tag, j, TRUE, &info->validSize); - pcrp->minBasesize = info->validSize; - } else { - info->size[j] = pcrp->basesize[j]; - info->validSize = pcrp->minBasesize; - } - info->type[j] = 0; - } - - if (PCINONSYSTEMCLASSES(baseclass, subclass)) { - /* - * Check of a PCI base is unassigned. If so - * attempt to fix it. Validation will determine - * if the value was correct later on. - */ - CARD32 *base = &pcrp->pci_base0; - - for (j = 0; j < 6; j++) { - if (!PCI_MAP_IS64BITMEM(base[j])) { - if (info->size[j] && IsBaseUnassigned(base[j])) - base[j] = pciCheckForBrokenBase(pcrp->tag, j); - } else { - if (j == 5) /* bail out */ - break; - if (info->size[j] - && IsBaseUnassigned64(base[j],base[j+1])) { - base[j] = pciCheckForBrokenBase(pcrp->tag, j); - j++; - base[j] = pciCheckForBrokenBase(pcrp->tag, j); - } - } - } - } - - /* - * 64-bit base addresses are checked for and avoided on 32-bit - * platforms. - */ - for (j = 0; j < 6; ++j) { - CARD32 bar = (&pcrp->pci_base0)[j]; - - if (bar != 0) { - if (bar & PCI_MAP_IO) { - info->ioBase[j] = (memType)PCIGETIO(bar); - info->type[j] = bar & PCI_MAP_IO_ATTR_MASK; - } else { - info->type[j] = bar & PCI_MAP_MEMORY_ATTR_MASK; - info->memBase[j] = (memType)PCIGETMEMORY(bar); - if (PCI_MAP_IS64BITMEM(bar)) { - if (j == 5) { - xf86MsgVerb(X_WARNING, 0, - "****BAR5 specified as 64-bit wide, " - "which is not possible. " - "Ignoring BAR5.****\n"); - info->memBase[j] = 0; - } else { - CARD32 bar_hi = PCIGETMEMORY64HIGH((&pcrp->pci_base0)[j]); -#if defined(LONG64) || defined(WORD64) - /* 64 bit architecture */ - info->memBase[j] |= - (memType)bar_hi << 32; -#else - if (bar_hi != 0) - info->memBase[j] = 0; -#endif - ++j; /* Step over the next BAR */ - } - } - } - } - } } - i++; } + /* If we haven't found a primary device try a different heuristic */ if (primaryBus.type == BUS_NONE && num) { for (i = 0; i < num; i++) { + uint16_t command; + info = xf86PciVideoInfo[i]; - pcrp = info->thisCard; - - if ((pcrp->pci_command & PCI_CMD_MEM_ENABLE) && - (num == 1 || - ((info->class == PCI_CLASS_DISPLAY) && - (info->subclass == PCI_SUBCLASS_DISPLAY_VGA)))) { + pci_device_cfg_read_u16( info, & command, 4 ); + + if ( (command & PCI_CMD_MEM_ENABLE) + && ((num == 1) || IS_VGA( info->device_class )) ) { if (primaryBus.type == BUS_NONE) { primaryBus.type = BUS_PCI; - primaryBus.id.pci.bus = pcrp->busnum; - primaryBus.id.pci.device = pcrp->devnum; - primaryBus.id.pci.func = pcrp->funcnum; + primaryBus.id.pci.bus = PCI_MAKE_BUS( info->domain, info->bus ); + primaryBus.id.pci.device = info->dev; + primaryBus.id.pci.func = info->func; } else { xf86Msg(X_NOTICE, "More than one possible primary device found\n"); @@ -378,141 +242,71 @@ FindPCIVideoInfo(void) for (k = 0; k < num; k++) { const char *vendorname = NULL, *chipname = NULL; const char *prim = " "; - char busnum[8]; Bool memdone = FALSE, iodone = FALSE; - i = 0; + info = xf86PciVideoInfo[k]; - xf86FormatPciBusNumber(info->bus, busnum); - xf86FindPciNamesByDevice(info->vendor, info->chipType, - NOVENDOR, NOSUBSYS, - &vendorname, &chipname, NULL, NULL); + + vendorname = pci_device_get_vendor_name( info ); + chipname = pci_device_get_device_name( info ); + if ((!vendorname || !chipname) && - !PCIALWAYSPRINTCLASSES(info->class, info->subclass)) + !PCIALWAYSPRINTCLASSES( info->device_class )) continue; + if (xf86IsPrimaryPci(info)) prim = "*"; - xf86Msg(X_PROBED, "PCI:%s(%s:%d:%d) ", prim, busnum, info->device, - info->func); + xf86Msg( X_PROBED, "PCI:%s(%u@%u:%u:%u) ", prim, info->domain, + info->bus, info->dev, info->func ); + if (vendorname) xf86ErrorF("%s ", vendorname); else - xf86ErrorF("unknown vendor (0x%04x) ", info->vendor); + xf86ErrorF("unknown vendor (0x%04x) ", info->vendor_id); + if (chipname) xf86ErrorF("%s ", chipname); else - xf86ErrorF("unknown chipset (0x%04x) ", info->chipType); - xf86ErrorF("rev %d", info->chipRev); + xf86ErrorF("unknown chipset (0x%04x) ", info->device_id); + + xf86ErrorF("rev %d", info->revision); + for (i = 0; i < 6; i++) { - if (info->memBase[i] && - (info->memBase[i] < (memType)(-1 << info->size[i]))) { + struct pci_mem_region * r = & info->regions[i]; + + if ( r->size && ! r->is_IO ) { if (!memdone) { xf86ErrorF(", Mem @ "); memdone = TRUE; } else xf86ErrorF(", "); - xf86ErrorF("0x%08lx/%d", info->memBase[i], info->size[i]); + xf86ErrorF("0x%08lx/%ld", r->base_addr, r->size); } } + for (i = 0; i < 6; i++) { - if (info->ioBase[i] && - (info->ioBase[i] < (memType)(-1 << info->size[i]))) { + struct pci_mem_region * r = & info->regions[i]; + + if ( r->size && r->is_IO ) { if (!iodone) { xf86ErrorF(", I/O @ "); iodone = TRUE; } else xf86ErrorF(", "); - xf86ErrorF("0x%04lx/%d", info->ioBase[i], info->size[i]); + xf86ErrorF("0x%08lx/%ld", r->base_addr, r->size); } } - if (info->biosBase && - (info->biosBase < (memType)(-1 << info->biosSize))) - xf86ErrorF(", BIOS @ 0x%08lx/%d", info->biosBase, info->biosSize); - xf86ErrorF("\n"); - } -} - -/* - * fixPciSizeInfo() -- fix pci size info by testing it destructively - * (if not already done), fix pciVideoInfo and entry in the resource - * list. - */ -/* - * Note: once we have OS support to read the sizes GetBaseSize() will - * have to be wrapped by the OS layer. fixPciSizeInfo() should also - * be wrapped by the OS layer to do nothing if the size is always - * returned correctly by GetBaseSize(). It should however set validate - * in pciVideoRec if validation is required. ValidatePci() also needs - * to be wrapped by the OS layer. This may do nothing if the OS has - * already taken care of validation. fixPciResource() may be moved to - * OS layer with minimal changes. Once the wrapping layer is in place - * the common level and drivers should not reference these functions - * directly but thru the OS layer. - */ - -static void -fixPciSizeInfo(int entityIndex) -{ - pciVideoPtr pvp; - resPtr pAcc; - PCITAG tag; - int j; - - if (! (pvp = xf86GetPciInfoForEntity(entityIndex))) return; - if (pvp->validSize) return; - tag = pciTag(pvp->bus,pvp->device,pvp->func); - - for (j = 0; j < 6; j++) { - pAcc = Acc; - if (pvp->memBase[j]) - while (pAcc) { - if (((pAcc->res_type & (ResPhysMask | ResBlock)) - == (ResMem | ResBlock)) - && (pAcc->block_begin == B2M(TAG(pvp),pvp->memBase[j])) - && (pAcc->block_end == B2M(TAG(pvp),pvp->memBase[j] - + SIZE(pvp->size[j])))) break; - pAcc = pAcc->next; - } - else if (pvp->ioBase[j]) - while (pAcc) { - if (((pAcc->res_type & (ResPhysMask | ResBlock)) == - (ResIo | ResBlock)) - && (pAcc->block_begin == B2I(TAG(pvp),pvp->ioBase[j])) - && (pAcc->block_end == B2I(TAG(pvp),pvp->ioBase[j] - + SIZE(pvp->size[j])))) break; - pAcc = pAcc->next; - } - else continue; - pvp->size[j] = pciGetBaseSize(tag, j, TRUE, &pvp->validSize); - if (pAcc) { - pAcc->block_end = pvp->memBase[j] ? - B2M(TAG(pvp),pvp->memBase[j] + SIZE(pvp->size[j])) - : B2I(TAG(pvp),pvp->ioBase[j] + SIZE(pvp->size[j])); - pAcc->res_type &= ~ResEstimated; - pAcc->res_type |= ResBios; - } - } - if (pvp->biosBase) { - pAcc = Acc; - while (pAcc) { - if (((pAcc->res_type & (ResPhysMask | ResBlock)) == - (ResMem | ResBlock)) - && (pAcc->block_begin == B2M(TAG(pvp),pvp->biosBase)) - && (pAcc->block_end == B2M(TAG(pvp),pvp->biosBase - + SIZE(pvp->biosSize)))) break; - pAcc = pAcc->next; - } - pvp->biosSize = pciGetBaseSize(tag, 6, TRUE, &pvp->validSize); - if (pAcc) { - pAcc->block_end = B2M(TAG(pvp),pvp->biosBase+SIZE(pvp->biosSize)); - pAcc->res_type &= ~ResEstimated; - pAcc->res_type |= ResBios; + if ( info->rom_size ) { + xf86ErrorF(", BIOS @ 0x\?\?\?\?\?\?\?\?/%ld", info->rom_size); } + + xf86ErrorF("\n"); } } + /* * IO enable/disable related routines for PCI */ @@ -525,7 +319,7 @@ pciIoAccessEnable(void* arg) ErrorF("pciIoAccessEnable: 0x%05lx\n", *(PCITAG *)arg); #endif pArg->ctrl |= SETBITS | PCI_CMD_MASTER_ENABLE; - pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl); + pci_device_cfg_write_u32( pArg->dev, & pArg->ctrl, PCI_CMD_STAT_REG ); } static void @@ -535,7 +329,7 @@ pciIoAccessDisable(void* arg) ErrorF("pciIoAccessDisable: 0x%05lx\n", *(PCITAG *)arg); #endif pArg->ctrl &= ~SETBITS; - pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl); + pci_device_cfg_write_u32( pArg->dev, & pArg->ctrl, PCI_CMD_STAT_REG ); } #undef SETBITS @@ -547,7 +341,7 @@ pciIo_MemAccessEnable(void* arg) ErrorF("pciIo_MemAccessEnable: 0x%05lx\n", *(PCITAG *)arg); #endif pArg->ctrl |= SETBITS | PCI_CMD_MASTER_ENABLE; - pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl); + pci_device_cfg_write_u32( pArg->dev, & pArg->ctrl, PCI_CMD_STAT_REG ); } static void @@ -557,7 +351,7 @@ pciIo_MemAccessDisable(void* arg) ErrorF("pciIo_MemAccessDisable: 0x%05lx\n", *(PCITAG *)arg); #endif pArg->ctrl &= ~SETBITS; - pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl); + pci_device_cfg_write_u32( pArg->dev, & pArg->ctrl, PCI_CMD_STAT_REG ); } #undef SETBITS @@ -569,7 +363,7 @@ pciMemAccessEnable(void* arg) ErrorF("pciMemAccessEnable: 0x%05lx\n", *(PCITAG *)arg); #endif pArg->ctrl |= SETBITS | PCI_CMD_MASTER_ENABLE; - pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl); + pci_device_cfg_write_u32( pArg->dev, & pArg->ctrl, PCI_CMD_STAT_REG ); } static void @@ -579,7 +373,7 @@ pciMemAccessDisable(void* arg) ErrorF("pciMemAccessDisable: 0x%05lx\n", *(PCITAG *)arg); #endif pArg->ctrl &= ~SETBITS; - pciWriteLong(pArg->tag, PCI_CMD_STAT_REG, pArg->ctrl); + pci_device_cfg_write_u32( pArg->dev, & pArg->ctrl, PCI_CMD_STAT_REG ); } #undef SETBITS #undef pArg @@ -590,17 +384,17 @@ pciMemAccessDisable(void* arg) static void pciBusAccessEnable(BusAccPtr ptr) { - PCITAG tag = ptr->busdep.pci.acc; - CARD16 ctrl; + struct pci_device * const dev = ptr->busdep.pci.dev; + uint16_t ctrl; #ifdef DEBUG ErrorF("pciBusAccessEnable: bus=%d\n", ptr->busdep.pci.bus); #endif - ctrl = pciReadWord(tag, PCI_PCI_BRIDGE_CONTROL_REG); + pci_device_cfg_read_u16( dev, & ctrl, PCI_PCI_BRIDGE_CONTROL_REG ); if ((ctrl & MASKBITS) != PCI_PCI_BRIDGE_VGA_EN) { ctrl = (ctrl | PCI_PCI_BRIDGE_VGA_EN) & ~(PCI_PCI_BRIDGE_MASTER_ABORT_EN | PCI_PCI_BRIDGE_SECONDARY_RESET); - pciWriteWord(tag, PCI_PCI_BRIDGE_CONTROL_REG, ctrl); + pci_device_cfg_write_u16( dev, & ctrl, PCI_PCI_BRIDGE_CONTROL_REG ); } } @@ -608,16 +402,16 @@ pciBusAccessEnable(BusAccPtr ptr) static void pciBusAccessDisable(BusAccPtr ptr) { - PCITAG tag = ptr->busdep.pci.acc; - CARD16 ctrl; + struct pci_device * const dev = ptr->busdep.pci.dev; + uint16_t ctrl; #ifdef DEBUG ErrorF("pciBusAccessDisable: bus=%d\n", ptr->busdep.pci.bus); #endif - ctrl = pciReadWord(tag, PCI_PCI_BRIDGE_CONTROL_REG); + pci_device_cfg_read_u16( dev, & ctrl, PCI_PCI_BRIDGE_CONTROL_REG ); if (ctrl & MASKBITS) { ctrl &= ~(MASKBITS | PCI_PCI_BRIDGE_SECONDARY_RESET); - pciWriteWord(tag, PCI_PCI_BRIDGE_CONTROL_REG, ctrl); + pci_device_cfg_write_u16( dev, & ctrl, PCI_PCI_BRIDGE_CONTROL_REG ); } } #undef MASKBITS @@ -679,44 +473,55 @@ pciSetBusAccess(BusAccPtr ptr) /* move to OS layer */ static void -savePciState(PCITAG tag, pciSavePtr ptr) +savePciState( struct pci_device * dev, pciSavePtr ptr ) { int i; - - ptr->command = pciReadLong(tag, PCI_CMD_STAT_REG); - for (i=0; i < 6; i++) - ptr->base[i] = pciReadLong(tag, PCI_CMD_BASE_REG + i*4); - ptr->biosBase = pciReadLong(tag, PCI_CMD_BIOS_REG); + + pci_device_cfg_read_u32( dev, & ptr->command, PCI_CMD_STAT_REG ); + + for ( i = 0; i < 6; i++ ) { + pci_device_cfg_read_u32( dev, & ptr->base[i], + PCI_CMD_BASE_REG + (i * 4) ); + } + + pci_device_cfg_read_u32( dev, & ptr->biosBase, PCI_CMD_BIOS_REG ); } /* move to OS layer */ static void -restorePciState(PCITAG tag, pciSavePtr ptr) +restorePciState( struct pci_device * dev, pciSavePtr ptr) { int i; /* disable card before setting anything */ - pciSetBitsLong(tag, PCI_CMD_STAT_REG, - PCI_CMD_MEM_ENABLE | PCI_CMD_IO_ENABLE , 0); - pciWriteLong(tag,PCI_CMD_BIOS_REG, ptr->biosBase); - for (i=0; i<6; i++) - pciWriteLong(tag, PCI_CMD_BASE_REG + i*4, ptr->base[i]); - pciWriteLong(tag, PCI_CMD_STAT_REG, ptr->command); + pci_device_cfg_write_bits( dev, PCI_CMD_MEM_ENABLE | PCI_CMD_IO_ENABLE, 0, + PCI_CMD_STAT_REG ); + + pci_device_cfg_write_u32( dev, & ptr->biosBase, PCI_CMD_BIOS_REG ); + + for ( i = 0; i < 6; i++ ) { + pci_device_cfg_write_u32( dev, & ptr->base[i], + PCI_CMD_BASE_REG + (i * 4) ); + } + + pci_device_cfg_write_u32( dev, & ptr->command, PCI_CMD_STAT_REG ); } /* move to OS layer */ static void savePciBusState(BusAccPtr ptr) { - PCITAG tag = ptr->busdep.pci.acc; + struct pci_device * const dev = ptr->busdep.pci.dev; + uint16_t temp; + + pci_device_cfg_read_u16( dev, & temp, PCI_PCI_BRIDGE_CONTROL_REG ); + ptr->busdep.pci.save.control = temp & ~PCI_PCI_BRIDGE_SECONDARY_RESET; - ptr->busdep.pci.save.control = - pciReadWord(tag, PCI_PCI_BRIDGE_CONTROL_REG) & - ~PCI_PCI_BRIDGE_SECONDARY_RESET; /* Allow master aborts to complete normally on non-root buses */ - if (ptr->busdep.pci.save.control & PCI_PCI_BRIDGE_MASTER_ABORT_EN) - pciWriteWord(tag, PCI_PCI_BRIDGE_CONTROL_REG, - ptr->busdep.pci.save.control & ~PCI_PCI_BRIDGE_MASTER_ABORT_EN); + if ( ptr->busdep.pci.save.control & PCI_PCI_BRIDGE_MASTER_ABORT_EN ) { + temp = ptr->busdep.pci.save.control & ~PCI_PCI_BRIDGE_MASTER_ABORT_EN; + pci_device_cfg_read_u16( dev, & temp, PCI_PCI_BRIDGE_CONTROL_REG ); + } } /* move to OS layer */ @@ -724,15 +529,16 @@ savePciBusState(BusAccPtr ptr) static void restorePciBusState(BusAccPtr ptr) { - PCITAG tag = ptr->busdep.pci.acc; - CARD16 ctrl; + struct pci_device * const dev = ptr->busdep.pci.dev; + uint16_t ctrl; /* Only restore the bits we've changed (and don't cause resets) */ - ctrl = pciReadWord(tag, PCI_PCI_BRIDGE_CONTROL_REG); + pci_device_cfg_read_u16( dev, & ctrl, PCI_PCI_BRIDGE_CONTROL_REG ); + if ((ctrl ^ ptr->busdep.pci.save.control) & MASKBITS) { ctrl &= ~(MASKBITS | PCI_PCI_BRIDGE_SECONDARY_RESET); ctrl |= ptr->busdep.pci.save.control & MASKBITS; - pciWriteWord(tag, PCI_PCI_BRIDGE_CONTROL_REG, ctrl); + pci_device_cfg_write_u16( dev, & ctrl, PCI_PCI_BRIDGE_CONTROL_REG ); } } #undef MASKBITS @@ -763,922 +569,12 @@ restorePciDrvBusState(BusAccPtr ptr) static void -disablePciBios(PCITAG tag) -{ - pciSetBitsLong(tag, PCI_CMD_BIOS_REG, PCI_CMD_BIOS_ENABLE, 0); -} - -/* ????? */ -static void -correctPciSize(memType base, memType oldsize, memType newsize, - unsigned long type) -{ - pciConfigPtr pcrp, *pcrpp; - pciVideoPtr pvp, *pvpp; - CARD32 *basep; - int i; - int old_bits = 0, new_bits = 0; - - if (oldsize + 1) while (oldsize & 1) { - old_bits ++; - oldsize >>= 1; - } - if (newsize + 1) while (newsize & 1) { - new_bits ++; - newsize >>= 1; - } - - for (pcrpp = xf86PciInfo, pcrp = *pcrpp; pcrp; pcrp = *++(pcrpp)) { - - /* Only process devices with type 0 headers */ - if ((pcrp->pci_header_type & 0x7f) != 0) - continue; - - basep = &pcrp->pci_base0; - for (i = 0; i < 6; i++) { - if (basep[i] && (pcrp->basesize[i] == old_bits)) { - if ((((type & ResPhysMask) == ResIo) && - PCI_MAP_IS_IO(basep[i]) && - B2I(pcrp->tag,PCIGETIO(basep[i]) == base)) || - (((type & ResPhysMask) == ResMem) && - PCI_MAP_IS_MEM(basep[i]) && - (((!PCI_MAP_IS64BITMEM(basep[i])) && - (B2M(pcrp->tag,PCIGETMEMORY(basep[i])) == base)) -#if defined(LONG64) || defined(WORD64) - || - (B2M(pcrp->tag,PCIGETMEMORY64(basep[i])) == base) -#else - || - (!basep[i+1] - && (B2M(pcrp->tag,PCIGETMEMORY(basep[i])) == base)) -#endif - ))) { - pcrp->basesize[i] = new_bits; - break; /* to next device */ - } - } - if (PCI_MAP_IS64BITMEM(basep[i])) i++; - } - } - - if (xf86PciVideoInfo) { - for (pvpp = xf86PciVideoInfo, pvp = *pvpp; pvp; pvp = *(++pvpp)) { - - for (i = 0; i < 6; i++) { - if (pvp->size[i] == old_bits) { - if ((((type & ResPhysMask) == ResIo) && pvp->ioBase[i] - && (B2I(TAG(pvp),pvp->ioBase[i]) == base)) || - (((type & ResPhysMask) == ResMem) && pvp->memBase[i] - && (B2M(TAG(pvp),pvp->memBase[i]) == base))) { - pvp->size[i] = new_bits; - break; /* to next device */ - } - } - } - } - } -} - -/* ????? */ -static void -removeOverlapsWithBridges(int busIndex, resPtr target) -{ - PciBusPtr pbp; - resPtr tmp,bridgeRes = NULL; - resRange range; - - if (!target) - return; - - if (!ResCanOverlap(&target->val)) - return; - - range = target->val; - - for (pbp=xf86PciBus; pbp; pbp = pbp->next) { - if (pbp->primary == busIndex) { - tmp = xf86DupResList(pbp->preferred_io); - bridgeRes = xf86JoinResLists(tmp,bridgeRes); - tmp = xf86DupResList(pbp->preferred_mem); - bridgeRes = xf86JoinResLists(tmp,bridgeRes); - tmp = xf86DupResList(pbp->preferred_pmem); - bridgeRes = xf86JoinResLists(tmp,bridgeRes); - } - } - - RemoveOverlaps(target, bridgeRes, TRUE, TRUE); - if (range.rEnd > target->block_end) { - correctPciSize(range.rBegin, range.rEnd - range.rBegin, - target->block_end - target->block_begin, - target->res_type); - xf86MsgVerb(X_INFO, 3, - "PCI %s resource overlap reduced 0x%08lx from 0x%08lx to 0x%08lx\n", - ((target->res_type & ResPhysMask) == ResMem) ? "Memory" : "I/O", - range.rBegin, range.rEnd, target->block_end); - } - xf86FreeResList(bridgeRes); -} - -/* ????? */ -static void -xf86GetPciRes(resPtr *activeRes, resPtr *inactiveRes) -{ - pciConfigPtr pcrp, *pcrpp; - pciVideoPtr pvp, *pvpp; - CARD32 *basep; - int i; - resPtr pRes, tmp; - resRange range; - long resMisc; - - if (activeRes) - *activeRes = NULL; - if (inactiveRes) - *inactiveRes = NULL; - - if (!activeRes || !inactiveRes || !xf86PciInfo) - return; - - if (xf86PciVideoInfo) - for (pvpp = xf86PciVideoInfo, pvp = *pvpp; pvp; pvp = *(++pvpp)) { - resPtr *res; - - if (PCINONSYSTEMCLASSES(pvp->class, pvp->subclass)) - resMisc = ResBios; - else - resMisc = 0; - - if (((pciConfigPtr)pvp->thisCard)->pci_command - & (PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE)) - res = activeRes; - else - res = inactiveRes; - - if (!pvp->validSize) - resMisc |= ResEstimated; - - for (i = 0; i < 6; i++) { - if (pvp->ioBase[i] && - (pvp->ioBase[i] < (memType)(-1 << pvp->size[i]))) { - PV_I_RANGE(range,pvp,i,ResExcIoBlock | resMisc); - tmp = xf86AddResToList(NULL, &range, -1); - removeOverlapsWithBridges(pvp->bus,tmp); - *res = xf86JoinResLists(tmp,*res); - } else if (pvp->memBase[i] && - (pvp->memBase[i] < (memType)(-1 << pvp->size[i]))) { - PV_M_RANGE(range, pvp,i, ResExcMemBlock | resMisc); - tmp = xf86AddResToList(NULL, &range, -1); - removeOverlapsWithBridges(pvp->bus,tmp); - *res = xf86JoinResLists(tmp,*res); - } - } - /* FIXME!!!: Don't use BIOS resources for overlap - * checking but reserve them! - */ - if (pvp->biosBase && - (pvp->biosBase < (memType)(-1 << pvp->biosSize))) { - PV_B_RANGE(range, pvp, ResExcMemBlock | resMisc); - tmp = xf86AddResToList(NULL, &range, -1); - removeOverlapsWithBridges(pvp->bus,tmp); - *res = xf86JoinResLists(tmp,*res); - } - } - - for (pcrpp = xf86PciInfo, pcrp = *pcrpp; pcrp; pcrp = *++(pcrpp)) { - resPtr *res; - const CARD8 baseclass = pcrp->pci_base_class; - const CARD8 subclass = pcrp->pci_sub_class; - - - if (PCIINFOCLASSES(baseclass, subclass)) - continue; - - /* Only process devices with type 0 headers */ - if ((pcrp->pci_header_type & 0x7f) != 0) - continue; - - if (!pcrp->minBasesize) - resMisc = ResEstimated; - else - resMisc = 0; - - /* - * Allow resources allocated to host bridges to overlap. Perhaps, this - * needs to be specific to AGP-capable chipsets. AGP "memory" - * sometimes gets allocated within the range routed to the AGP bus. - */ - if ((baseclass == PCI_CLASS_BRIDGE) && - (subclass == PCI_SUBCLASS_BRIDGE_HOST)) - resMisc |= ResOverlap; - - basep = &pcrp->pci_base0; - for (i = 0; i < 6; i++) { - if (basep[i]) { - if (PCI_MAP_IS_IO(basep[i])) { - if (pcrp->pci_command & PCI_CMD_IO_ENABLE) - res = activeRes; - else - res = inactiveRes; - P_I_RANGE(range, pcrp->tag, PCIGETIO(basep[i]), - pcrp->basesize[i], ResExcIoBlock | resMisc) - } else if (!PCI_MAP_IS64BITMEM(basep[i])) { - if (pcrp->pci_command & PCI_CMD_MEM_ENABLE) - res = activeRes; - else - res = inactiveRes; - P_M_RANGE(range, pcrp->tag, PCIGETMEMORY(basep[i]), - pcrp->basesize[i], ResExcMemBlock | resMisc) - } else { - i++; -#if defined(LONG64) || defined(WORD64) - P_M_RANGE(range,pcrp->tag,PCIGETMEMORY64(basep[i - 1]), - pcrp->basesize[i - 1], ResExcMemBlock | resMisc) -#else - if (basep[i]) - continue; - P_M_RANGE(range, pcrp->tag, PCIGETMEMORY(basep[i - 1]), - pcrp->basesize[i - 1], ResExcMemBlock | resMisc) -#endif - if (pcrp->pci_command & PCI_CMD_MEM_ENABLE) - res = activeRes; - else - res = inactiveRes; - } - if (range.rBegin) { /* catch cases where PCI base is unset */ - tmp = xf86AddResToList(NULL, &range, -1); - removeOverlapsWithBridges(pcrp->busnum,tmp); - *res = xf86JoinResLists(tmp,*res); - } - } - } - - /* Ignore disabled non-video ROMs */ - if ((pcrp->pci_command & PCI_CMD_MEM_ENABLE) && - (pcrp->pci_baserom & PCI_MAP_ROM_DECODE_ENABLE)) { - P_M_RANGE(range,pcrp->tag,PCIGETROM(pcrp->pci_baserom), - pcrp->basesize[6], ResExcMemBlock | resMisc); - if (range.rBegin) { - tmp = xf86AddResToList(NULL, &range, -1); - removeOverlapsWithBridges(pcrp->busnum, tmp); - *activeRes = xf86JoinResLists(tmp, *activeRes); - } - } - } - - if (*activeRes) { - xf86MsgVerb(X_INFO, 3, "Active PCI resource ranges:\n"); - xf86PrintResList(3, *activeRes); - } - if (*inactiveRes) { - xf86MsgVerb(X_INFO, 3, "Inactive PCI resource ranges:\n"); - xf86PrintResList(3, *inactiveRes); - } - - /* - * Adjust ranges based on the assumption that there are no real - * overlaps in the PCI base allocations. This assumption should be - * reasonable in most cases. It may be possible to refine the - * approximated PCI base sizes by considering bus mapping information - * from PCI-PCI bridges. - */ - - if (*activeRes) { - /* Check for overlaps */ - for (pRes = *activeRes; pRes; pRes = pRes->next) { - if (ResCanOverlap(&pRes->val)) { - range = pRes->val; - - RemoveOverlaps(pRes, *activeRes, TRUE, TRUE); - RemoveOverlaps(pRes, *inactiveRes, TRUE, - (xf86Info.estimateSizesAggressively > 0)); - - if (range.rEnd > pRes->block_end) { - correctPciSize(range.rBegin, range.rEnd - range.rBegin, - pRes->block_end - pRes->block_begin, - pRes->res_type); - xf86MsgVerb(X_INFO, 3, - "PCI %s resource overlap reduced 0x%08lx" - " from 0x%08lx to 0x%08lx\n", - ((pRes->res_type & ResPhysMask) == ResMem) ? - "Memory" : "I/O", - range.rBegin, range.rEnd, pRes->block_end); - } - } - } - xf86MsgVerb(X_INFO, 3, - "Active PCI resource ranges after removing overlaps:\n"); - xf86PrintResList(3, *activeRes); - } - - if (*inactiveRes) { - /* Check for overlaps */ - for (pRes = *inactiveRes; pRes; pRes = pRes->next) { - if (ResCanOverlap(&pRes->val)) { - range = pRes->val; - - RemoveOverlaps(pRes, *activeRes, TRUE, - (xf86Info.estimateSizesAggressively > 1)); - RemoveOverlaps(pRes, *inactiveRes, TRUE, - (xf86Info.estimateSizesAggressively > 1)); - - if (range.rEnd > pRes->block_end) { - correctPciSize(range.rBegin, range.rEnd - range.rBegin, - pRes->block_end - pRes->block_begin, - pRes->res_type); - xf86MsgVerb(X_INFO, 3, - "PCI %s resource overlap reduced 0x%08lx" - " from 0x%08lx to 0x%08lx\n", - ((pRes->res_type & ResPhysMask) == ResMem) ? - "Memory" : "I/O", - range.rBegin, range.rEnd, pRes->block_end); - } - - } - } - xf86MsgVerb(X_INFO, 3, - "Inactive PCI resource ranges after removing overlaps:\n"); - xf86PrintResList(3, *inactiveRes); - } -} - -resPtr -ResourceBrokerInitPci(resPtr *osRes) -{ - resPtr activeRes, inactiveRes; - resPtr tmp; - - /* Get bus-specific system resources (PCI) */ - xf86GetPciRes(&activeRes, &inactiveRes); - - /* - * Adjust OS-reported resource ranges based on the assumption that there - * are no overlaps with the PCI base allocations. This should be a good - * assumption because writes to PCI address space won't be routed directly - * to host memory. - */ - - for (tmp = *osRes; tmp; tmp = tmp->next) - RemoveOverlaps(tmp, activeRes, FALSE, TRUE); - - xf86MsgVerb(X_INFO, 3, "OS-reported resource ranges after removing" - " overlaps with PCI:\n"); - xf86PrintResList(3, *osRes); - - pciAvoidRes = xf86AddRangesToList(pciAvoidRes,PciAvoid,-1); - for (tmp = pciAvoidRes; tmp; tmp = tmp->next) - RemoveOverlaps(tmp, activeRes, FALSE, TRUE); - tmp = xf86DupResList(*osRes); - pciAvoidRes = xf86JoinResLists(pciAvoidRes,tmp); - - return (xf86JoinResLists(activeRes,inactiveRes)); -} - - -/* - * PCI Resource modification - */ -static Bool -fixPciResource(int prt, memType alignment, pciVideoPtr pvp, unsigned long type) -{ - int res_n; - memType *p_base; - int *p_size; - unsigned char p_type; - resPtr AccTmp = NULL; - resPtr orgAcc = NULL; - resPtr *pAcc = &AccTmp; - resPtr avoid = NULL; - resRange range; - resPtr resSize = NULL; - resPtr w_tmp, w = NULL, w_2nd = NULL; - PCITAG tag; - PciBusPtr pbp = xf86PciBus; - pciConfigPtr pcp; - resPtr tmp; - - if (!pvp) return FALSE; - tag = pciTag(pvp->bus,pvp->device,pvp->func); - pcp = pvp->thisCard; - - type &= ResAccMask; - if (!type) type = ResShared; - if (prt < 6) { - if (pvp->memBase[prt]) { - type |= ResMem; - res_n = prt; - p_base = &(pvp->memBase[res_n]); - p_size = &(pvp->size[res_n]); - p_type = pvp->type[res_n]; - if (!PCI_MAP_IS64BITMEM(pvp->type[res_n])) { - PCI_M_RANGE(range,tag,0,0xffffffff,ResExcMemBlock); - resSize = xf86AddResToList(resSize,&range,-1); - } - } else if (pvp->ioBase[prt]){ - type |= ResIo; - res_n = prt; - p_base = &(pvp->ioBase[res_n]); - p_size = &(pvp->size[res_n]); - p_type = pvp->type[res_n]; - PCI_I_RANGE(range, tag, 0, 0xffffffff, ResExcIoBlock); - resSize = xf86AddResToList(resSize, &range, -1); - } else return FALSE; - } else if (prt == 6) { - type |= ResMem; - res_n = 0xff; /* special flag for bios rom */ - p_base = &(pvp->biosBase); - p_size = &(pvp->biosSize); - /* XXX This should also include the PCI_MAP_MEMORY_TYPE_MASK part */ - p_type = 0; - PCI_M_RANGE(range,tag,0,0xffffffff,ResExcMemBlock); - resSize = xf86AddResToList(resSize,&range,-1); - } else return FALSE; - - if (! *p_base) return FALSE; - - type |= (range.type & ResDomain) | ResBlock; - - /* setup avoid: PciAvoid is bus range: convert later */ - avoid = xf86DupResList(pciAvoidRes); - - while (pbp) { - if (pbp->secondary == pvp->bus) { - if ((type & ResPhysMask) == ResMem) { - if (((p_type & PCI_MAP_MEMORY_CACHABLE) -#if 0 /*EE*/ - || (res_n == 0xff)/* bios should also be prefetchable */ -#endif - )) { - if (pbp->preferred_pmem) - w = xf86FindIntersectOfLists(pbp->preferred_pmem, - ResRange); - else if (pbp->pmem) - w = xf86FindIntersectOfLists(pbp->pmem,ResRange); - - if (pbp->preferred_mem) - w_2nd = xf86FindIntersectOfLists(pbp->preferred_mem, - ResRange); - else if (pbp->mem) - w_2nd = xf86FindIntersectOfLists(pbp->mem, - ResRange); - } else { - if (pbp->preferred_mem) - w = xf86FindIntersectOfLists(pbp->preferred_mem, - ResRange); - else if (pbp->mem) - w = xf86FindIntersectOfLists(pbp->mem,ResRange); - } - } else { - if (pbp->preferred_io) - w = xf86FindIntersectOfLists(pbp->preferred_io,ResRange); - if (pbp->io) - w = xf86FindIntersectOfLists(pbp->io,ResRange); - } - } else if (pbp->primary == pvp->bus) { - if ((type & ResPhysMask) == ResMem) { - tmp = xf86DupResList(pbp->preferred_pmem); - avoid = xf86JoinResLists(avoid, tmp); - tmp = xf86DupResList(pbp->preferred_mem); - avoid = xf86JoinResLists(avoid, tmp); - } else { - tmp = xf86DupResList(pbp->preferred_io); - avoid = xf86JoinResLists(avoid, tmp); - } - } - pbp = pbp->next; - } - - /* convert bus based entries in avoid list to host base */ - pciConvertListToHost(pvp->bus,pvp->device,pvp->func, avoid); - - if (!w) - w = xf86DupResList(ResRange); - xf86MsgVerb(X_INFO, 3, "window:\n"); - xf86PrintResList(3, w); - xf86MsgVerb(X_INFO, 3, "resSize:\n"); - xf86PrintResList(3, resSize); - - if (resSize) { - w_tmp = w; - w = xf86FindIntersectOfLists(w,resSize); - xf86FreeResList(w_tmp); - if (w_2nd) { - w_tmp = w_2nd; - w_2nd = xf86FindIntersectOfLists(w_2nd,resSize); - xf86FreeResList(w_tmp); - } - xf86FreeResList(resSize); - } - xf86MsgVerb(X_INFO, 3, "window fixed:\n"); - xf86PrintResList(3, w); - - if (!alignment) - alignment = (1 << (*p_size)) - 1; - - /* Access list holds bios resources -- remove this one */ -#ifdef NOTYET - AccTmp = xf86DupResList(Acc); - while ((*pAcc)) { - if ((((*pAcc)->res_type & (type & ~ResAccMask)) - == (type & ~ResAccMask)) - && ((*pAcc)->block_begin == (B2H(tag,(*p_base),type))) - && ((*pAcc)->block_end == (B2H(tag, - (*p_base)+SIZE(*p_size),type)))) { - resPtr acc_tmp = (*pAcc)->next; - xfree((*pAcc)); - (*pAcc) = acc_tmp; - break; - } else - pAcc = &((*pAcc)->next); - } - /* check if we really need to fix anything */ - P_X_RANGE(range,tag,(*p_base),(*p_base) + SIZE((*p_size)),type); - if (!ChkConflict(&range,avoid,SETUP) - && !ChkConflict(&range,AccTmp,SETUP) - && ((B2H(tag,(*p_base),type) & PCI_SIZE(type,tag,alignment) - == range->block_begin) - && ((xf86IsSubsetOf(range,w) - || (w_2nd && xf86IsSubsetOf(range,w_2n))))) { -#ifdef DEBUG - ErrorF("nothing to fix\n"); -#endif - xf86FreeResList(AccTmp); - xf86FreeResList(w); - xf86FreeResList(w_2nd); - xf86FreeResList(avoid); - return TRUE; - } -#ifdef DEBUG - ErrorF("removing old resource\n"); -#endif - orgAcc = Acc; - Acc = AccTmp; -#else - orgAcc = xf86DupResList(Acc); - pAcc = &Acc; - while (*pAcc) { - if ((((*pAcc)->res_type & (ResTypeMask|ResExtMask)) == - (type & ~ResAccMask)) - && ((*pAcc)->block_begin == B2H(tag,(*p_base),type)) - && ((*pAcc)->block_end == B2H(tag,(*p_base) + SIZE(*p_size), - type))) { -#ifdef DEBUG - ErrorF("removing old resource\n"); -#endif - tmp = *pAcc; - *pAcc = (*pAcc)->next; - tmp->next = NULL; - xf86FreeResList(tmp); - break; - } else - pAcc = &((*pAcc)->next); - } -#endif - -#ifdef DEBUG - ErrorF("base: 0x%lx alignment: 0x%lx host alignment: 0x%lx size[bit]: 0x%x\n", - (*p_base),alignment,PCI_SIZE(type,tag,alignment),(*p_size)); - xf86MsgVerb(X_INFO, 3, "window:\n"); - xf86PrintResList(3, w); - if (w_2nd) - xf86MsgVerb(X_INFO, 3, "2nd window:\n"); - xf86PrintResList(3, w_2nd); - xf86ErrorFVerb(3,"avoid:\n"); - xf86PrintResList(3,avoid); -#endif - w_tmp = w; - while (w) { - if ((type & ResTypeMask) == (w->res_type & ResTypeMask)) { -#ifdef DEBUG - ErrorF("block_begin: 0x%lx block_end: 0x%lx\n",w->block_begin, - w->block_end); -#endif - range = xf86GetBlock(type,PCI_SIZE(type,tag,alignment + 1), - w->block_begin, w->block_end, - PCI_SIZE(type,tag,alignment),avoid); - if (range.type != ResEnd) - break; - } - w = w->next; - } - xf86FreeResList(w_tmp); - /* if unsuccessful and memory prefetchable try non-prefetchable */ - if (range.type == ResEnd && w_2nd) { - w_tmp = w_2nd; - while (w_2nd) { - if ((type & ResTypeMask) == (w_2nd->res_type & ResTypeMask)) { -#ifdef DEBUG - ErrorF("block_begin: 0x%lx block_end: 0x%lx\n",w_2nd->block_begin, - w_2nd->block_end); -#endif - range = xf86GetBlock(type,PCI_SIZE(type,tag,alignment + 1), - w_2nd->block_begin, w_2nd->block_end, - PCI_SIZE(type,tag,alignment),avoid); - if (range.type != ResEnd) - break; - } - w_2nd = w_2nd->next; - } - xf86FreeResList(w_tmp); - } - xf86FreeResList(avoid); - - if (range.type == ResEnd) { - xf86MsgVerb(X_ERROR,3,"Cannot find a replacement memory range\n"); - xf86FreeResList(Acc); - Acc = orgAcc; - return FALSE; - } - xf86FreeResList(orgAcc); -#ifdef DEBUG - ErrorF("begin: 0x%lx, end: 0x%lx\n",range.a,range.b); -#endif - - (*p_size) = 0; - while (alignment >> (*p_size)) - (*p_size)++; - (*p_base) = H2B(tag,range.rBegin,type); -#ifdef DEBUG - ErrorF("New PCI res %i base: 0x%lx, size: 0x%lx, type %s\n", - res_n,(*p_base),(1 << (*p_size)), - ((type & ResPhysMask) == ResMem) ? "Mem" : "Io"); -#endif - if (res_n != 0xff) { - if ((type & ResPhysMask) == ResMem) - pvp->memBase[prt] = range.rBegin; - else - pvp->ioBase[prt] = range.rBegin; - ((CARD32 *)(&(pcp->pci_base0)))[res_n] = - (CARD32)(*p_base) | (CARD32)(p_type); - pciWriteLong(tag, PCI_CMD_BASE_REG + res_n * sizeof(CARD32), - ((CARD32 *)(&(pcp->pci_base0)))[res_n]); - if (PCI_MAP_IS64BITMEM(p_type)) { -#if defined(LONG64) || defined(WORD64) - ((CARD32 *)(&(pcp->pci_base0)))[res_n + 1] = - (CARD32)(*p_base >> 32); - pciWriteLong(tag, PCI_CMD_BASE_REG + (res_n + 1) * sizeof(CARD32), - ((CARD32 *)(&(pcp->pci_base0)))[res_n + 1]); -#else - ((CARD32 *)(&(pcp->pci_base0)))[res_n + 1] = 0; - pciWriteLong(tag, PCI_CMD_BASE_REG + (res_n + 1) * sizeof(CARD32), - 0); -#endif - } - } else { - pvp->biosBase = range.rBegin; - pcp->pci_baserom = (pciReadLong(tag,PCI_CMD_BIOS_REG) & 0x01) | - (CARD32)(*p_base); - pciWriteLong(tag, PCI_CMD_BIOS_REG, pcp->pci_baserom); - } - /* @@@ fake BIOS allocated resource */ - range.type |= ResBios; - Acc = xf86AddResToList(Acc, &range,-1); - - return TRUE; - -} - -_X_EXPORT Bool -xf86FixPciResource(int entityIndex, int prt, memType alignment, - unsigned long type) -{ - pciVideoPtr pvp = xf86GetPciInfoForEntity(entityIndex); - return fixPciResource(prt, alignment, pvp, type); -} - -_X_EXPORT resPtr -xf86ReallocatePciResources(int entityIndex, resPtr pRes) -{ - pciVideoPtr pvp = xf86GetPciInfoForEntity(entityIndex); - resPtr pBad = NULL,pResTmp; - unsigned int prt = 0; - int i; - - if (!pvp) return pRes; - - while (pRes) { - switch (pRes->res_type & ResPhysMask) { - case ResMem: - if (pRes->block_begin == B2M(TAG(pvp),pvp->biosBase) && - pRes->block_end == B2M(TAG(pvp),pvp->biosBase - + SIZE(pvp->biosSize))) - prt = 6; - else for (i = 0 ; i < 6; i++) - if ((pRes->block_begin == B2M(TAG(pvp),pvp->memBase[i])) - && (pRes->block_end == B2M(TAG(pvp),pvp->memBase[i] - + SIZE(pvp->size[i])))) { - prt = i; - break; - } - break; - case ResIo: - for (i = 0 ; i < 6; i++) - if (pRes->block_begin == B2I(TAG(pvp),pvp->ioBase[i]) - && pRes->block_end == B2I(TAG(pvp),pvp->ioBase[i] - + SIZE(pvp->size[i]))) { - prt = i; - break; - } - break; - } - - if (!prt) return pRes; - - pResTmp = pRes->next; - if (! fixPciResource(prt, 0, pvp, pRes->res_type)) { - pRes->next = pBad; - pBad = pRes; - } else - xfree(pRes); - - pRes = pResTmp; - } - return pBad; -} - -/* - * BIOS releated - */ -static resPtr -getOwnResources(pciVideoPtr pvp, resPtr mem) -{ - resRange range; - int i; - /* Make sure we don't conflict with our own mem resources */ - for (i = 0; i < 6; i++) { - if (!pvp->memBase[i]) - continue; - P_M_RANGE(range,TAG(pvp),pvp->memBase[i],pvp->size[i], - ResExcMemBlock); - mem = xf86AddResToList(mem,&range,-1); - } - return mem; -} - -static void -getPciRangesForMapping(pciVideoPtr pvp, resPtr *map, resPtr *avoid) +disablePciBios(struct pci_device * dev) { - PciBusPtr pbp; - resPtr tmp; - - *avoid = xf86DupResList(pciAvoidRes); - - pbp = xf86PciBus; - while (pbp) { - if (pbp->secondary == pvp->bus) { - if (pbp->preferred_pmem) - tmp = xf86DupResList(pbp->preferred_pmem); - else - tmp = xf86DupResList(pbp->pmem); - *map = xf86JoinResLists(*map,tmp); - if (pbp->preferred_mem) - tmp = xf86DupResList(pbp->preferred_mem); - else - tmp = xf86DupResList(pbp->mem); - *map = xf86JoinResLists(*map,tmp); - tmp = *map; - while (tmp) { - tmp->block_end = min(tmp->block_end,PCI_MEM32_LENGTH_MAX); - tmp = tmp->next; - } - } else if ((pbp->primary == pvp->bus) && - (pbp->secondary >= 0) && - (pbp->primary != pbp->secondary)) { - tmp = xf86DupResList(pbp->preferred_pmem); - *avoid = xf86JoinResLists(*avoid, tmp); - tmp = xf86DupResList(pbp->pmem); - *avoid = xf86JoinResLists(*avoid, tmp); - tmp = xf86DupResList(pbp->preferred_mem); - *avoid = xf86JoinResLists(*avoid, tmp); - tmp = xf86DupResList(pbp->mem); - *avoid = xf86JoinResLists(*avoid, tmp); - } - pbp = pbp->next; - } - pciConvertListToHost(pvp->bus,pvp->device,pvp->func, *avoid); - pciConvertListToHost(pvp->bus,pvp->device,pvp->func, *map); -} - -static memType -findPciRange(PCITAG tag, resPtr m, resPtr avoid, CARD32 size) -{ - resRange range; - CARD32 alignment = (1 << size) - 1; - - while (m) { - range = xf86GetBlock(RANGE_TYPE(ResExcMemBlock, xf86GetPciDomain(tag)), - PCI_SIZE(ResMem, tag, 1 << size), - m->block_begin, m->block_end, - PCI_SIZE(ResMem, tag, alignment), - avoid); - if (range.type != ResEnd) { - return M2B(tag, range.rBase); - } - m = m->next; - } - return 0; + pci_device_cfg_write_bits(dev, PCI_CMD_BIOS_ENABLE, 0, + PCI_CMD_BIOS_REG); } -pciVideoPtr -getPciVideoPtr(tag) -{ - int n = 0; - - pciVideoPtr pvp = NULL; - if (!xf86PciVideoInfo) return 0; - - while ((pvp = xf86PciVideoInfo[n++])) { - if (pciTag(pvp->bus,pvp->device,pvp->func) == tag) - return pvp; - } - return NULL; -} - -memType -getValidBIOSBase(PCITAG tag, int num) -{ - pciVideoPtr pvp = NULL; - memType ret; - CARD32 biosSize; - resPtr mem = NULL; - resPtr avoid = NULL, m = NULL; - resRange range; - - pvp = getPciVideoPtr(tag); - - if (!pvp) return 0; - - biosSize = pvp->biosSize; - - if (biosSize > 24) - biosSize = 24; - - switch ((romBaseSource)num) { - case ROM_BASE_PRESET: - return 0; /* This should not happen */ - case ROM_BASE_BIOS: - /* In some cases the BIOS base register contains the size mask */ - if ((memType)(-1 << biosSize) == PCIGETROM(pvp->biosBase)) - return 0; - mem = getOwnResources(pvp,mem); - P_M_RANGE(range, tag, pvp->biosBase,biosSize,ResExcMemBlock); - ret = pvp->biosBase; - break; - case ROM_BASE_MEM0: - case ROM_BASE_MEM1: - case ROM_BASE_MEM2: - case ROM_BASE_MEM3: - case ROM_BASE_MEM4: - case ROM_BASE_MEM5: - if (!pvp->memBase[num] || (pvp->size[num] < biosSize)) - return 0; - P_M_RANGE(range, tag ,pvp->memBase[num],biosSize, - ResExcMemBlock); - ret = pvp->memBase[num]; - break; - case ROM_BASE_FIND: - ret = 0; - break; - default: - return 0; /* This should not happen */ - } - - /* Now find the ranges for validation */ - getPciRangesForMapping(pvp,&m,&avoid); - - if (!ret) { - /* Return a possible window */ - ret = findPciRange(tag,m,avoid,biosSize); - } else { -#if !defined(__ia64__) /* on ia64, trust the kernel, don't look for overlaps */ - if (mem) - pciConvertListToHost(pvp->bus,pvp->device,pvp->func, mem); - if (!xf86IsSubsetOf(range, m) || - ChkConflict(&range, avoid, SETUP) - || (mem && ChkConflict(&range, mem, SETUP))) - ret = 0; -#endif - } - - xf86FreeResList(avoid); - xf86FreeResList(m); - return ret; -} - -memType -getEmptyPciRange(PCITAG tag, int base_reg) -{ - resPtr avoid = NULL, m = NULL; - memType ret; - - pciVideoPtr pvp = getPciVideoPtr(tag); - if (!pvp) return 0; - getPciRangesForMapping(pvp,&m,&avoid); - ret = findPciRange(tag,m,avoid,pvp->size[base_reg]); - xf86FreeResList(avoid); - xf86FreeResList(m); - - return ret; -} /* * xf86Bus.c interface @@ -1687,26 +583,6 @@ getEmptyPciRange(PCITAG tag, int base_reg) void xf86PciProbe(void) { - /* - * Initialise the pcidata entry points. - */ -#ifdef XFree86LOADER - xf86SetupPciIds = (ScanPciSetupProcPtr)LoaderSymbol("ScanPciSetupPciIds"); - xf86ClosePciIds = (ScanPciCloseProcPtr)LoaderSymbol("ScanPciClosePciIds"); - xf86FindPciNamesByDevice = - (ScanPciFindByDeviceProcPtr)LoaderSymbol("ScanPciFindPciNamesByDevice"); - xf86FindPciNamesBySubsys = - (ScanPciFindBySubsysProcPtr)LoaderSymbol("ScanPciFindPciNamesBySubsys"); -#else - xf86SetupPciIds = ScanPciSetupPciIds; - xf86ClosePciIds = ScanPciClosePciIds; - xf86FindPciNamesByDevice = ScanPciFindPciNamesByDevice; - xf86FindPciNamesBySubsys = ScanPciFindPciNamesBySubsys; -#endif - - if (!xf86SetupPciIds()) - FatalError("xf86SetupPciIds() failed\n"); - FindPCIVideoInfo(); } @@ -1766,8 +642,14 @@ xf86GetPciBridgeInfo(void) /* Add each bridge */ for (pcrpp = xf86PciInfo, pcrp = *pcrpp; pcrp; pcrp = *(++pcrpp)) { + struct pci_device * const dev = + pci_device_find_by_slot( PCI_DOM_FROM_BUS( pcrp->busnum ), + PCI_BUS_NO_DOMAIN( pcrp->busnum ), + pcrp->devnum, pcrp->funcnum ); + if (pcrp->busnum > MaxBus) MaxBus = pcrp->busnum; + if ( pcrp->pci_base_class == PCI_CLASS_BRIDGE ) { const int sub_class = pcrp->pci_sub_class; @@ -1818,6 +700,7 @@ xf86GetPciBridgeInfo(void) *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec)); pnPciBus = &PciBus->next; + PciBus->dev = dev; PciBus->primary = primary; PciBus->secondary = secondary; PciBus->subordinate = subordinate; @@ -1831,7 +714,7 @@ xf86GetPciBridgeInfo(void) /* The Intel bridges don't report as transparent but guess what they are - from Linux kernel - airlied */ if ((pcrp->pci_vendor == PCI_VENDOR_INTEL) && - ((pcrp->pci_device & 0xff00) == 0x2400)) { + ((pcrp->_pci_device & 0xff00) == 0x2400)) { xf86MsgVerb(X_INFO, 3, "Intel Bridge workaround enabled\n"); PciBus->interface = PCI_IF_BRIDGE_PCI_SUBTRACTIVE; } else { @@ -1967,6 +850,7 @@ xf86GetPciBridgeInfo(void) *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec)); pnPciBus = &PciBus->next; + PciBus->dev = dev; PciBus->primary = primary; PciBus->secondary = secondary; PciBus->subordinate = subordinate; @@ -2096,6 +980,7 @@ xf86GetPciBridgeInfo(void) case PCI_SUBCLASS_BRIDGE_MC: *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec)); pnPciBus = &PciBus->next; + PciBus->dev = dev; PciBus->primary = pcrp->busnum; PciBus->secondary = PciBus->subordinate = -1; PciBus->brbus = pcrp->busnum; @@ -2130,7 +1015,7 @@ xf86GetPciBridgeInfo(void) *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec)); pnPciBus = &PciBus->next; - + PciBus->dev = dev; PciBus->primary = PciBus->secondary = secondary; PciBus->subordinate = pciNumBuses - 1; @@ -2188,16 +1073,20 @@ xf86GetPciBridgeInfo(void) * Find the 'smallest' free HOST-PCI bridge, where 'small' is in * the order of pciTag(). */ - PCITAG minTag = 0xFFFFFFFF, tag; + PCITAG minTag = 0xFFFFFFFF; PciBusPtr PciBusFound = NULL; - for (PciBus = PciBusBase; PciBus; PciBus = PciBus->next) + + for (PciBus = PciBusBase; PciBus; PciBus = PciBus->next) { + const PCITAG tag = pciTag( PciBus->brbus, PciBus->brdev, + PciBus->brfunc ); if ((PciBus->subclass == PCI_SUBCLASS_BRIDGE_HOST) && (PciBus->secondary == -1) && - ((tag = pciTag(PciBus->brbus,PciBus->brdev,PciBus->brfunc)) - < minTag) ) { + (tag < minTag) ) { minTag = tag; PciBusFound = PciBus; } + } + if (PciBusFound) PciBusFound->secondary = i; else { /* if nothing found it may not be visible: create new */ @@ -2211,6 +1100,11 @@ xf86GetPciBridgeInfo(void) } *pnPciBus = PciBus = xnfcalloc(1, sizeof(PciBusRec)); pnPciBus = &PciBus->next; + + PciBus->dev = pci_device_find_by_slot( PCI_DOM_FROM_BUS( pcrp->busnum ), + PCI_BUS_NO_DOMAIN( pcrp->busnum ), + pcrp->devnum, + pcrp->funcnum ); PciBus->primary = PciBus->secondary = i; PciBus->subclass = PCI_SUBCLASS_BRIDGE_HOST; PciBus->brcontrol = PCI_PCI_BRIDGE_VGA_EN; @@ -2314,352 +1208,41 @@ alignBridgeRanges(PciBusPtr PciBusBase, PciBusPtr primary) } void -ValidatePci(void) -{ - pciVideoPtr pvp, pvp1; - PciBusPtr pbp; - pciConfigPtr pcrp, *pcrpp; - CARD32 *basep; - resPtr Sys; - resRange range; - int n = 0, m, i; - - if (!xf86PciVideoInfo) return; - - /* - * Mark all pciInfoRecs that need to be validated. These are - * the ones which have been assigned to a screen. - */ - Sys = xf86DupResList(osRes); - /* Only validate graphics devices in use */ - for (i=0; i<xf86NumScreens; i++) { - for (m = 0; m < xf86Screens[i]->numEntities; m++) - if ((pvp = xf86GetPciInfoForEntity(xf86Screens[i]->entityList[m]))) - pvp->validate = TRUE; - } - - /* - * Collect all background PCI resources we need to validate against. - * These are all resources which don't belong to PCINONSYSTEMCLASSES - * and which have not been assigned to an entity. - */ - /* First get the PCIINFOCLASSES */ - m = 0; - while ((pvp = xf86PciVideoInfo[m++])) { - /* is it a PCINONSYSTEMCLASS? */ - if (PCINONSYSTEMCLASSES(pvp->class, pvp->subclass)) - continue; - /* has it an Entity assigned to it? */ - for (i=0; i<xf86NumEntities; i++) { - EntityPtr p = xf86Entities[i]; - if (p->busType != BUS_PCI) - continue; - if (p->pciBusId.bus == pvp->bus - && p->pciBusId.device == pvp->device - && p->pciBusId.func == pvp->func) - break; - } - if (i != xf86NumEntities) /* found an Entity for this one */ - continue; - - for (i = 0; i<6; i++) { - if (pvp->ioBase[i]) { - PV_I_RANGE(range,pvp,i,ResExcIoBlock); - Sys = xf86AddResToList(Sys,&range,-1); - } else if (pvp->memBase[i]) { - PV_M_RANGE(range,pvp,i,ResExcMemBlock); - Sys = xf86AddResToList(Sys,&range,-1); - } - } - } - for (pcrpp = xf86PciInfo, pcrp = *pcrpp; pcrp; pcrp = *++(pcrpp)) { - - /* These were handled above */ - if (PCIINFOCLASSES(pcrp->pci_base_class, pcrp->pci_sub_class)) - continue; - - if ((pcrp->pci_header_type & 0x7f) || - !(pcrp->pci_command & (PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE))) - continue; - - basep = &pcrp->pci_base0; - for (i = 0; i < 6; i++) { - if (basep[i]) { - if (PCI_MAP_IS_IO(basep[i])) { - if (!(pcrp->pci_command & PCI_CMD_IO_ENABLE)) - continue; - P_I_RANGE(range, pcrp->tag, PCIGETIO(basep[i]), - pcrp->basesize[i], ResExcIoBlock) - } else if (!PCI_MAP_IS64BITMEM(basep[i])) { - if (!(pcrp->pci_command & PCI_CMD_MEM_ENABLE)) - continue; - P_M_RANGE(range, pcrp->tag, PCIGETMEMORY(basep[i]), - pcrp->basesize[i], ResExcMemBlock) - } else { - i++; - if (!(pcrp->pci_command & PCI_CMD_MEM_ENABLE)) - continue; -#if defined(LONG64) || defined(WORD64) - P_M_RANGE(range, pcrp->tag, PCIGETMEMORY64(basep[i-1]), - pcrp->basesize[i-1], ResExcMemBlock) -#else - if (basep[i]) - continue; - P_M_RANGE(range, pcrp->tag, PCIGETMEMORY(basep[i-1]), - pcrp->basesize[i-1], ResExcMemBlock) -#endif - } - Sys = xf86AddResToList(Sys, &range, -1); - } - } - if ((pcrp->pci_baserom) && - (pcrp->pci_command & PCI_CMD_MEM_ENABLE) && - (pcrp->pci_baserom & PCI_MAP_ROM_DECODE_ENABLE)) { - P_M_RANGE(range,pcrp->tag,PCIGETROM(pcrp->pci_baserom), - pcrp->basesize[6],ResExcMemBlock); - Sys = xf86AddResToList(Sys, &range, -1); - } - } -#ifdef DEBUG - xf86MsgVerb(X_INFO, 3,"Sys:\n"); - xf86PrintResList(3,Sys); -#endif - - /* - * The order the video devices are listed in is - * just right: the lower buses come first. - * This way we attempt to fix a conflict of - * a lower bus device with a higher bus device - * where we have more room to find different - * resources. - */ - while ((pvp = xf86PciVideoInfo[n++])) { - resPtr res_mp = NULL, res_m_io = NULL; - resPtr NonSys; - resPtr tmp, avoid = NULL; - - if (!pvp->validate) continue; - NonSys = xf86DupResList(Sys); - m = n; - while ((pvp1 = xf86PciVideoInfo[m++])) { - if (!pvp1->validate) continue; - for (i = 0; i<6; i++) { - if (pvp1->ioBase[i]) { - PV_I_RANGE(range,pvp1,i,ResExcIoBlock); - NonSys = xf86AddResToList(NonSys,&range,-1); - } else if (pvp1->memBase[i]) { - PV_M_RANGE(range,pvp1,i,ResExcMemBlock); - NonSys = xf86AddResToList(NonSys,&range,-1); - } - } - } -#ifdef DEBUG - xf86MsgVerb(X_INFO, 3,"NonSys:\n"); - xf86PrintResList(3,NonSys); -#endif - pbp = xf86PciBus; - while (pbp) { - if (pbp->secondary == pvp->bus) { - if (pbp->preferred_pmem) { - /* keep prefetchable separate */ - res_mp = - xf86FindIntersectOfLists(pbp->preferred_pmem, ResRange); - } - if (pbp->pmem) { - res_mp = xf86FindIntersectOfLists(pbp->pmem, ResRange); - } - if (pbp->preferred_mem) { - res_m_io = - xf86FindIntersectOfLists(pbp->preferred_mem, ResRange); - } - if (pbp->mem) { - res_m_io = xf86FindIntersectOfLists(pbp->mem, ResRange); - } - if (pbp->preferred_io) { - res_m_io = xf86JoinResLists(res_m_io, - xf86FindIntersectOfLists(pbp->preferred_io, ResRange)); - } - if (pbp->io) { - res_m_io = xf86JoinResLists(res_m_io, - xf86FindIntersectOfLists(pbp->preferred_io, ResRange)); - } - } else if ((pbp->primary == pvp->bus) && - (pbp->secondary >= 0) && - (pbp->primary != pbp->secondary)) { - tmp = xf86DupResList(pbp->preferred_pmem); - avoid = xf86JoinResLists(avoid, tmp); - tmp = xf86DupResList(pbp->preferred_mem); - avoid = xf86JoinResLists(avoid, tmp); - tmp = xf86DupResList(pbp->preferred_io); - avoid = xf86JoinResLists(avoid, tmp); - } - pbp = pbp->next; - } - if (res_m_io == NULL) - res_m_io = xf86DupResList(ResRange); - - pciConvertListToHost(pvp->bus,pvp->device,pvp->func, avoid); - -#ifdef DEBUG - xf86MsgVerb(X_INFO, 3,"avoid:\n"); - xf86PrintResList(3,avoid); - xf86MsgVerb(X_INFO, 3,"prefetchable Memory:\n"); - xf86PrintResList(3,res_mp); - xf86MsgVerb(X_INFO, 3,"MEM/IO:\n"); - xf86PrintResList(3,res_m_io); -#endif - for (i = 0; i < 6; i++) { - int j; - resPtr own = NULL; - for (j = i+1; j < 6; j++) { - if (pvp->ioBase[j]) { - PV_I_RANGE(range,pvp,j,ResExcIoBlock); - own = xf86AddResToList(own,&range,-1); - } else if (pvp->memBase[j]) { - PV_M_RANGE(range,pvp,j,ResExcMemBlock); - own = xf86AddResToList(own,&range,-1); - } - } -#ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "own:\n"); - xf86PrintResList(3, own); -#endif - if (pvp->ioBase[i]) { - PV_I_RANGE(range,pvp,i,ResExcIoBlock); - if (xf86IsSubsetOf(range,res_m_io) - && ! ChkConflict(&range,own,SETUP) - && ! ChkConflict(&range,avoid,SETUP) - && ! ChkConflict(&range,NonSys,SETUP)) { - xf86FreeResList(own); - continue; - } - xf86MsgVerb(X_WARNING, 0, - "****INVALID IO ALLOCATION**** b: 0x%lx e: 0x%lx " - "correcting\a\n", range.rBegin,range.rEnd); -#ifdef DEBUG - sleep(2); -#endif - fixPciResource(i, 0, pvp, range.type); - } else if (pvp->memBase[i]) { - PV_M_RANGE(range,pvp,i,ResExcMemBlock); - if (pvp->type[i] & PCI_MAP_MEMORY_CACHABLE) { - if (xf86IsSubsetOf(range,res_mp) - && ! ChkConflict(&range,own,SETUP) - && ! ChkConflict(&range,avoid,SETUP) - && ! ChkConflict(&range,NonSys,SETUP)) { - xf86FreeResList(own); - continue; - } - } - if (xf86IsSubsetOf(range,res_m_io) - && ! ChkConflict(&range,own,SETUP) - && ! ChkConflict(&range,avoid,SETUP) - && ! ChkConflict(&range,NonSys,SETUP)) { - xf86FreeResList(own); - continue; - } - xf86MsgVerb(X_WARNING, 0, - "****INVALID MEM ALLOCATION**** b: 0x%lx e: 0x%lx " - "correcting\a\n", range.rBegin,range.rEnd); - if (ChkConflict(&range,own,SETUP)) { - xf86MsgVerb(X_INFO,3,"own\n"); - xf86PrintResList(3,own); - } - if (ChkConflict(&range,avoid,SETUP)) { - xf86MsgVerb(X_INFO,3,"avoid\n"); - xf86PrintResList(3,avoid); - } - if (ChkConflict(&range,NonSys,SETUP)) { - xf86MsgVerb(X_INFO,3,"NonSys\n"); - xf86PrintResList(3,NonSys); - } - -#ifdef DEBUG - sleep(2); -#endif - fixPciResource(i, 0, pvp, range.type); - } - xf86FreeResList(own); - } - xf86FreeResList(avoid); - xf86FreeResList(NonSys); - xf86FreeResList(res_mp); - xf86FreeResList(res_m_io); - } - xf86FreeResList(Sys); -} - -resList -GetImplicitPciResources(int entityIndex) -{ - pciVideoPtr pvp; - int i; - resList list = NULL; - int num = 0; - - if (! (pvp = xf86GetPciInfoForEntity(entityIndex))) return NULL; - - for (i = 0; i < 6; i++) { - if (pvp->ioBase[i]) { - list = xnfrealloc(list,sizeof(resRange) * (++num)); - PV_I_RANGE(list[num - 1],pvp,i,ResShrIoBlock | ResBios); - } else if (pvp->memBase[i]) { - list = xnfrealloc(list,sizeof(resRange) * (++num)); - PV_M_RANGE(list[num - 1],pvp,i,ResShrMemBlock | ResBios); - } - } -#if 0 - if (pvp->biosBase) { - list = xnfrealloc(list,sizeof(resRange) * (++num)); - PV_B_RANGE(list[num - 1],pvp,ResShrMemBlock | ResBios); - } -#endif - list = xnfrealloc(list,sizeof(resRange) * (++num)); - list[num - 1].type = ResEnd; - - return list; -} - -void initPciState(void) { - int i = 0; - int j = 0; - pciVideoPtr pvp; + unsigned i; pciAccPtr pcaccp; - if (xf86PciAccInfo != NULL) - return; - - if (xf86PciVideoInfo == NULL) + if (xf86PciVideoInfo == NULL) { return; + } + + for (i = 0 ; xf86PciVideoInfo[i] != NULL ; i++) { + struct pci_device * const pvp = xf86PciVideoInfo[i]; - while ((pvp = xf86PciVideoInfo[i]) != NULL) { - i++; - j++; - xf86PciAccInfo = xnfrealloc(xf86PciAccInfo, - sizeof(pciAccPtr) * (j + 1)); - xf86PciAccInfo[j] = NULL; - pcaccp = xf86PciAccInfo[j - 1] = xnfalloc(sizeof(pciAccRec)); - pcaccp->busnum = pvp->bus; - pcaccp->devnum = pvp->device; - pcaccp->funcnum = pvp->func; - pcaccp->arg.tag = pciTag(pvp->bus, pvp->device, pvp->func); - pcaccp->ioAccess.AccessDisable = pciIoAccessDisable; - pcaccp->ioAccess.AccessEnable = pciIoAccessEnable; - pcaccp->ioAccess.arg = &pcaccp->arg; + if (pvp->user_data == 0) { + pcaccp = xnfalloc( sizeof( pciAccRec ) ); + pvp->user_data = (intptr_t) pcaccp; + + pcaccp->busnum = PCI_MAKE_BUS(pvp->domain, pvp->bus); + pcaccp->devnum = pvp->dev; + pcaccp->funcnum = pvp->func; + pcaccp->arg.dev = pvp; + pcaccp->ioAccess.AccessDisable = pciIoAccessDisable; + pcaccp->ioAccess.AccessEnable = pciIoAccessEnable; + pcaccp->ioAccess.arg = &pcaccp->arg; pcaccp->io_memAccess.AccessDisable = pciIo_MemAccessDisable; pcaccp->io_memAccess.AccessEnable = pciIo_MemAccessEnable; pcaccp->io_memAccess.arg = &pcaccp->arg; pcaccp->memAccess.AccessDisable = pciMemAccessDisable; pcaccp->memAccess.AccessEnable = pciMemAccessEnable; pcaccp->memAccess.arg = &pcaccp->arg; - if (PCISHAREDIOCLASSES(pvp->class, pvp->subclass)) - pcaccp->ctrl = TRUE; - else - pcaccp->ctrl = FALSE; - savePciState(pcaccp->arg.tag, &pcaccp->save); + + pcaccp->ctrl = PCISHAREDIOCLASSES(pvp->device_class); + + savePciState(pvp, &pcaccp->save); pcaccp->arg.ctrl = pcaccp->save.command; + } } } @@ -2695,7 +1278,7 @@ initPciBusState(void) pbap->busdep.pci.bus = pbp->secondary; pbap->busdep.pci.primary_bus = pbp->primary; pbap->busdep_type = BUS_PCI; - pbap->busdep.pci.acc = PCITAG_SPECIAL; + pbap->busdep.pci.dev = NULL; if ((pbp->secondary >= 0) && (pbp->secondary < pciNumBuses) && (pBusInfo = pciBusInfo[pbp->secondary]) && @@ -2720,7 +1303,10 @@ initPciBusState(void) pbap->set_f = pciSetBusAccess; pbap->enable_f = pciBusAccessEnable; pbap->disable_f = pciBusAccessDisable; - pbap->busdep.pci.acc = pciTag(pbp->brbus,pbp->brdev,pbp->brfunc); + pbap->busdep.pci.dev = pci_device_find_by_slot(PCI_DOM_FROM_BUS(pbp->brbus), + PCI_BUS_NO_DOMAIN(pbp->brbus), + pbp->brdev, + pbp->brfunc); savePciBusState(pbap); break; case PCI_SUBCLASS_BRIDGE_ISA: @@ -2761,19 +1347,19 @@ initPciBusState(void) void PciStateEnter(void) { - pciAccPtr paccp; - int i = 0; - - if (xf86PciAccInfo == NULL) + unsigned i; + + if (xf86PciVideoInfo == NULL) return; - while ((paccp = xf86PciAccInfo[i]) != NULL) { - i++; - if (!paccp->ctrl) - continue; - savePciState(paccp->arg.tag, &paccp->save); - restorePciState(paccp->arg.tag, &paccp->restore); - paccp->arg.ctrl = paccp->restore.command; + for ( i = 0 ; xf86PciVideoInfo[i] != NULL ; i++ ) { + pciAccPtr paccp = (pciAccPtr) xf86PciVideoInfo[i]->user_data; + + if ( (paccp != NULL) && paccp->ctrl ) { + savePciState(paccp->arg.dev, &paccp->save); + restorePciState(paccp->arg.dev, &paccp->restore); + paccp->arg.ctrl = paccp->restore.command; + } } } @@ -2792,18 +1378,18 @@ PciBusStateEnter(void) void PciStateLeave(void) { - pciAccPtr paccp; - int i = 0; + unsigned i; - if (xf86PciAccInfo == NULL) + if (xf86PciVideoInfo == NULL) return; - while ((paccp = xf86PciAccInfo[i]) != NULL) { - i++; - if (!paccp->ctrl) - continue; - savePciState(paccp->arg.tag, &paccp->restore); - restorePciState(paccp->arg.tag, &paccp->save); + for ( i = 0 ; xf86PciVideoInfo[i] != NULL ; i++ ) { + pciAccPtr paccp = (pciAccPtr) xf86PciVideoInfo[i]->user_data; + + if ( (paccp != NULL) && paccp->ctrl ) { + savePciState(paccp->arg.dev, &paccp->restore); + restorePciState(paccp->arg.dev, &paccp->save); + } } } @@ -2822,16 +1408,17 @@ PciBusStateLeave(void) void DisablePciAccess(void) { - int i = 0; - pciAccPtr paccp; - if (xf86PciAccInfo == NULL) + unsigned i; + + if (xf86PciVideoInfo == NULL) return; - while ((paccp = xf86PciAccInfo[i]) != NULL) { - i++; - if (!paccp->ctrl) /* disable devices that are under control initially*/ - continue; - pciIo_MemAccessDisable(paccp->io_memAccess.arg); + for ( i = 0 ; xf86PciVideoInfo[i] != NULL ; i++ ) { + pciAccPtr paccp = (pciAccPtr) xf86PciVideoInfo[i]->user_data; + + if ( (paccp != NULL) && paccp->ctrl ) { + pciIo_MemAccessDisable(paccp->io_memAccess.arg); + } } } @@ -2850,67 +1437,42 @@ DisablePciBusAccess(void) } /* - * Public functions - */ - -_X_EXPORT Bool -xf86IsPciDevPresent(int bus, int dev, int func) -{ - int i = 0; - pciConfigPtr pcp; - - while ((pcp = xf86PciInfo[i]) != NULL) { - if ((pcp->busnum == bus) - && (pcp->devnum == dev) - && (pcp->funcnum == func)) - return TRUE; - i++; - } - return FALSE; -} - -/* * If the slot requested is already in use, return -1. * Otherwise, claim the slot for the screen requesting it. */ _X_EXPORT int -xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp, +xf86ClaimPciSlot(struct pci_device * d, DriverPtr drvp, int chipset, GDevPtr dev, Bool active) { EntityPtr p = NULL; - pciAccPtr *ppaccp = xf86PciAccInfo; + pciAccPtr paccp = (pciAccPtr) d->user_data; BusAccPtr pbap = xf86BusAccInfo; + const unsigned bus = PCI_MAKE_BUS(d->domain, d->bus); int num; - if (xf86CheckPciSlot(bus, device, func)) { + if (xf86CheckPciSlot(d)) { num = xf86AllocateEntity(); p = xf86Entities[num]; p->driver = drvp; p->chipset = chipset; p->busType = BUS_PCI; p->pciBusId.bus = bus; - p->pciBusId.device = device; - p->pciBusId.func = func; + p->pciBusId.device = d->dev; + p->pciBusId.func = d->func; p->active = active; p->inUse = FALSE; if (dev) xf86AddDevToEntity(num, dev); /* Here we initialize the access structure */ p->access = xnfcalloc(1,sizeof(EntityAccessRec)); - while (ppaccp && *ppaccp) { - if ((*ppaccp)->busnum == bus - && (*ppaccp)->devnum == device - && (*ppaccp)->funcnum == func) { - p->access->fallback = &(*ppaccp)->io_memAccess; - p->access->pAccess = &(*ppaccp)->io_memAccess; - (*ppaccp)->ctrl = TRUE; /* mark control if not already */ - break; - } - ppaccp++; + if (paccp != NULL) { + p->access->fallback = & paccp->io_memAccess; + p->access->pAccess = & paccp->io_memAccess; + paccp->ctrl = TRUE; /* mark control if not already */ } - if (!ppaccp || !*ppaccp) { + else { p->access->fallback = &AccessNULL; p->access->pAccess = &AccessNULL; } @@ -2921,16 +1483,16 @@ xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp, p->busAcc = pbap; pbap = pbap->next; } - fixPciSizeInfo(num); /* in case bios is enabled disable it */ - disablePciBios(pciTag(bus,device,func)); + disablePciBios( d ); pciSlotClaimed = TRUE; if (active) { /* Map in this domain's I/O space */ p->domainIO = xf86MapDomainIO(-1, VIDMEM_MMIO, - pciTag(bus, device, func), 0, 1); + pciTag(bus, d->dev, d->func), + 0, 1); } return num; @@ -2939,138 +1501,6 @@ xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp, } /* - * Get xf86PciVideoInfo for a driver. - */ -_X_EXPORT pciVideoPtr * -xf86GetPciVideoInfo(void) -{ - return xf86PciVideoInfo; -} - -/* --- Used by ATI driver, but also more generally useful */ - -/* - * Get the full xf86scanpci data. - */ -_X_EXPORT pciConfigPtr * -xf86GetPciConfigInfo(void) -{ - return xf86PciInfo; -} - -/* - * Enable a device and route VGA to it. This is intended for a driver's - * Probe(), before creating EntityRec's. Only one device can be thus enabled - * at any one time, and should be disabled when the driver is done with it. - * - * The following special calls are also available: - * - * pvp == NULL && rt == NONE disable previously enabled device - * pvp != NULL && rt == NONE ensure device is disabled - * pvp == NULL && rt != NONE disable >all< subsequent calls to this function - * (done from xf86PostProbe()) - * The last combination has been removed! To do this cleanly we have - * to implement stages and need to test at each stage dependent function - * if it is allowed to execute. - * - * The device represented by pvp may not have been previously claimed. - */ -_X_EXPORT void -xf86SetPciVideo(pciVideoPtr pvp, resType rt) -{ - static BusAccPtr pbap = NULL; - static xf86AccessPtr pAcc = NULL; - static Bool DoneProbes = FALSE; - pciAccPtr pcaccp; - int i; - - if (DoneProbes) - return; - - /* Disable previous access */ - if (pAcc) { - if (pAcc->AccessDisable) - (*pAcc->AccessDisable)(pAcc->arg); - pAcc = NULL; - } - if (pbap) { - while (pbap->primary) { - if (pbap->disable_f) - (*pbap->disable_f)(pbap); - pbap->primary->current = NULL; - pbap = pbap->primary; - } - pbap = NULL; - } - - /* Check for xf86PostProbe's magic combo */ - if (!pvp) { - if (rt != NONE) - DoneProbes = TRUE; - return; - } - - /* Validate device */ - if (!xf86PciVideoInfo || !xf86PciAccInfo || !xf86BusAccInfo) - return; - - for (i = 0; pvp != xf86PciVideoInfo[i]; i++) - if (!xf86PciVideoInfo[i]) - return; - - /* Ignore request for claimed adapters */ - if (!xf86CheckPciSlot(pvp->bus, pvp->device, pvp->func)) - return; - - /* Find pciAccRec structure */ - for (i = 0; ; i++) { - if (!(pcaccp = xf86PciAccInfo[i])) - return; - if ((pvp->bus == pcaccp->busnum) && - (pvp->device == pcaccp->devnum) && - (pvp->func == pcaccp->funcnum)) - break; - } - - if (rt == NONE) { - /* This is a call to ensure the adapter is disabled */ - if (pcaccp->io_memAccess.AccessDisable) - (*pcaccp->io_memAccess.AccessDisable)(pcaccp->io_memAccess.arg); - return; - } - - /* Find BusAccRec structure */ - for (pbap = xf86BusAccInfo; ; pbap = pbap->next) { - if (!pbap) - return; - if (pvp->bus == pbap->busdep.pci.bus) - break; - } - - /* Route VGA */ - if (pbap->set_f) - (*pbap->set_f)(pbap); - - /* Enable device */ - switch (rt) { - case IO: - pAcc = &pcaccp->ioAccess; - break; - case MEM_IO: - pAcc = &pcaccp->io_memAccess; - break; - case MEM: - pAcc = &pcaccp->memAccess; - break; - default: /* no compiler noise */ - break; - } - - if (pAcc && pAcc->AccessEnable) - (*pAcc->AccessEnable)(pAcc->arg); -} - -/* * Parse a BUS ID string, and return the PCI bus parameters if it was * in the correct format for a PCI bus id. */ @@ -3167,36 +1597,42 @@ xf86ComparePciBusString(const char *busID, int bus, int device, int func) */ _X_EXPORT Bool -xf86IsPrimaryPci(pciVideoPtr pPci) +xf86IsPrimaryPci( struct pci_device * pPci ) { - if (primaryBus.type != BUS_PCI) return FALSE; - return (pPci->bus == primaryBus.id.pci.bus && - pPci->device == primaryBus.id.pci.device && - pPci->func == primaryBus.id.pci.func); + const unsigned busnum = PCI_MAKE_BUS( pPci->domain, pPci->bus ); + + return ((primaryBus.type == BUS_PCI) + && (busnum == primaryBus.id.pci.bus) + && (pPci->dev == primaryBus.id.pci.device) + && (pPci->func == primaryBus.id.pci.func)); } /* * xf86GetPciInfoForEntity() -- Get the pciVideoRec of entity. */ -_X_EXPORT pciVideoPtr +_X_EXPORT struct pci_device * xf86GetPciInfoForEntity(int entityIndex) { - pciVideoPtr *ppPci; EntityPtr p; if (entityIndex >= xf86NumEntities) return NULL; p = xf86Entities[entityIndex]; - if (p->busType != BUS_PCI) - return NULL; - - for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) { - if (p->pciBusId.bus == (*ppPci)->bus && - p->pciBusId.device == (*ppPci)->device && - p->pciBusId.func == (*ppPci)->func) - return (*ppPci); + if (p->busType == BUS_PCI) { + const unsigned domain = PCI_DOM_FROM_BUS(p->pciBusId.bus); + const unsigned bus = PCI_BUS_NO_DOMAIN(p->pciBusId.bus); + struct pci_device ** ppPci; + + for (ppPci = xf86PciVideoInfo; *ppPci != NULL; ppPci++) { + if (domain == (*ppPci)->domain && + bus == (*ppPci)->bus && + p->pciBusId.device == (*ppPci)->dev && + p->pciBusId.func == (*ppPci)->func) + return (*ppPci); + } } + return NULL; } @@ -3222,12 +1658,12 @@ xf86GetPciEntity(int bus, int dev, int func) * PCI base address register values for the given PCI device. */ _X_EXPORT Bool -xf86CheckPciMemBase(pciVideoPtr pPci, memType base) +xf86CheckPciMemBase( struct pci_device * pPci, memType base ) { int i; for (i = 0; i < 6; i++) - if (base == pPci->memBase[i]) + if (base == pPci->regions[i].base_addr) return TRUE; return FALSE; } @@ -3237,16 +1673,17 @@ xf86CheckPciMemBase(pciVideoPtr pPci, memType base) */ _X_EXPORT Bool -xf86CheckPciSlot(int bus, int device, int func) +xf86CheckPciSlot( const struct pci_device * d ) { int i; EntityPtr p; + const unsigned busnum = PCI_MAKE_BUS(d->domain, d->bus); for (i = 0; i < xf86NumEntities; i++) { p = xf86Entities[i]; /* Check if this PCI slot is taken */ - if (p->busType == BUS_PCI && p->pciBusId.bus == bus && - p->pciBusId.device == device && p->pciBusId.func == func) + if (p->busType == BUS_PCI && p->pciBusId.bus == busnum && + p->pciBusId.device == d->dev && p->pciBusId.func == d->func) return FALSE; } @@ -3261,125 +1698,43 @@ xf86CheckPciSlot(int bus, int device, int func) * so by setting pvp_exclude one pci device can be explicitely * _excluded if required. */ -_X_EXPORT pciVideoPtr -xf86FindPciDeviceVendor(CARD16 vendorID, CARD16 deviceID, - char n, pciVideoPtr pvp_exclude) +_X_EXPORT struct pci_device * +xf86FindPciDeviceVendor( CARD16 vendorID, CARD16 deviceID, + char n, const struct pci_device * exclude ) { - pciVideoPtr pvp, *ppvp; + struct pci_device * pvp; + struct pci_device ** ppvp; + n++; for (ppvp = xf86PciVideoInfo, pvp =*ppvp; pvp ; pvp = *(++ppvp)) { - if (pvp == pvp_exclude) continue; - if ((pvp->vendor == vendorID) && (pvp->chipType == deviceID)) { + if ( (pvp != exclude) && (pvp->vendor_id == vendorID) + && (pvp->device_id == deviceID) ) { if (!(--n)) break; } } + return pvp; } -_X_EXPORT pciVideoPtr -xf86FindPciClass(CARD8 intf, CARD8 subClass, CARD16 class, - char n, pciVideoPtr pvp_exclude) +_X_EXPORT struct pci_device * +xf86FindPciClass(CARD8 intf, CARD8 subClass, CARD16 _class, + char n, const struct pci_device * exclude) { - pciVideoPtr pvp, *ppvp; + struct pci_device * pvp; + struct pci_device ** ppvp; + const uint32_t device_class = ( ((uint32_t)_class) << 16) + | ( ((uint32_t)subClass) << 8) | intf; + n++; for (ppvp = xf86PciVideoInfo, pvp =*ppvp; pvp ; pvp = *(++ppvp)) { - if (pvp == pvp_exclude) continue; - if ((pvp->interface == intf) && (pvp->subclass == subClass) - && (pvp->class == class)) { + if ( (pvp != exclude) && (pvp->device_class == device_class) ) { if (!(--n)) break; } } - return pvp; -} -/* - * This attempts to detect a multi-device card and sets up a list - * of pci tags of the devices of this card. On some of these - * cards the BIOS is not visible from all chipsets. We therefore - * need to use the BIOS from a chipset where it is visible. - * We do the following heuristics: - * If we detect only identical pci devices on a bus we assume it's - * a multi-device card. This assumption isn't true always, however. - * One might just use identical cards on a bus. We therefore don't - * detect this situation when we set up the PCI video info. Instead - * we wait until an attempt to read the BIOS fails. - */ -int -pciTestMultiDeviceCard(int bus, int dev, int func, PCITAG** pTag) -{ - pciConfigPtr *ppcrp = xf86PciInfo; - pciConfigPtr pcrp = NULL; - int i,j; - Bool multicard = FALSE; - Bool multifunc = FALSE; - char str[256]; - char *str1; - - str1 = str; - if (!pTag) - return 0; - - *pTag = NULL; - - for (i=0; i < 8; i++) { - j = 0; - - while (ppcrp[j]) { - if (ppcrp[j]->busnum == bus && ppcrp[j]->funcnum == i) { - pcrp = ppcrp[j]; - break; - } - j++; - } - - if (!pcrp) return 0; - - /* - * we check all functions here: since multifunc devices need - * to implement func 0 we catch all devices on the bus when - * i = 0 - */ - if (pcrp->pci_header_type &0x80) - multifunc = TRUE; - - j = 0; - - while (ppcrp[j]) { - if (ppcrp[j]->busnum == bus && ppcrp[j]->funcnum == i - && ppcrp[j]->devnum != pcrp->devnum) { - /* don't test subsys ID here. It might be set by POST - - however some cards might not have been POSTed */ - if (ppcrp[j]->pci_device_vendor != pcrp->pci_device_vendor - || ppcrp[j]->pci_header_type != pcrp->pci_header_type ) - return 0; - else - multicard = TRUE; - } - j++; - } - if (!multifunc) - break; - } - - if (!multicard) - return 0; - - j = 0; - i = 0; - while (ppcrp[i]) { - if (ppcrp[i]->busnum == bus && ppcrp[i]->funcnum == func) { - str1 += sprintf(str1,"[%x:%x:%x]",ppcrp[i]->busnum, - ppcrp[i]->devnum,ppcrp[i]->funcnum); - *pTag = xnfrealloc(*pTag,sizeof(PCITAG) * (j + 1)); - (*pTag)[j++] = pciTag(ppcrp[i]->busnum, - ppcrp[i]->devnum,ppcrp[i]->funcnum); - } - i++; - } - xf86MsgVerb(X_INFO,3,"Multi Device Card detected: %s\n",str); - return j; + return pvp; } static void @@ -3424,60 +1779,14 @@ pciTagConvertRange2Host(PCITAG tag, resRange *pRange) pRange->type |= xf86GetPciDomain(tag) << 24; } -static void -pciConvertListToHost(int bus, int dev, int func, resPtr list) -{ - PCITAG tag = pciTag(bus,dev,func); - while (list) { - pciTagConvertRange2Host(tag, &list->val); - list = list->next; - } -} - -static void -updateAccessInfoStatusControlInfo(PCITAG tag, CARD32 ctrl) -{ - int i; - - if (!xf86PciAccInfo) - return; - - for (i = 0; xf86PciAccInfo[i] != NULL; i++) { - if (xf86PciAccInfo[i]->arg.tag == tag) - xf86PciAccInfo[i]->arg.ctrl = ctrl; - } -} - void pciConvertRange2Host(int entityIndex, resRange *pRange) { - PCITAG tag; - pciVideoPtr pvp; - - pvp = xf86GetPciInfoForEntity(entityIndex); - if (!pvp) return; - tag = TAG(pvp); - pciTagConvertRange2Host(tag, pRange); -} + const struct pci_device * const pvp = xf86GetPciInfoForEntity(entityIndex); - -#ifdef INCLUDE_DEPRECATED -_X_EXPORT void -xf86EnablePciBusMaster(pciVideoPtr pPci, Bool enable) -{ - CARD32 temp; - PCITAG tag; - - if (!pPci) return; - - tag = pciTag(pPci->bus, pPci->device, pPci->func); - temp = pciReadLong(tag, PCI_CMD_STAT_REG); - if (enable) { - updateAccessInfoStatusControlInfo(tag, temp | PCI_CMD_MASTER_ENABLE); - pciWriteLong(tag, PCI_CMD_STAT_REG, temp | PCI_CMD_MASTER_ENABLE); - } else { - updateAccessInfoStatusControlInfo(tag, temp & ~PCI_CMD_MASTER_ENABLE); - pciWriteLong(tag, PCI_CMD_STAT_REG, temp & ~PCI_CMD_MASTER_ENABLE); + if ( pvp != NULL ) { + const PCITAG tag = PCI_MAKE_TAG( PCI_MAKE_BUS( pvp->domain, pvp->bus ), + pvp->dev, pvp->func ); + pciTagConvertRange2Host(tag, pRange); } } -#endif /* INCLUDE_DEPRECATED */ diff --git a/hw/xfree86/common/xf86pciBus.h b/hw/xfree86/common/xf86pciBus.h index 75d82fbcf..277d6ddee 100644 --- a/hw/xfree86/common/xf86pciBus.h +++ b/hw/xfree86/common/xf86pciBus.h @@ -43,7 +43,7 @@ typedef struct { } pciSave, *pciSavePtr; typedef struct { - PCITAG tag; + struct pci_device * dev; CARD32 ctrl; } pciArg; @@ -69,6 +69,7 @@ typedef struct pciBusRec { int primary, secondary, subordinate; int subclass; /* bridge type */ int interface; + struct pci_device * dev; resPtr preferred_io; /* I/O range */ resPtr preferred_mem; /* non-prefetchable memory range */ resPtr preferred_pmem; /* prefetchable memory range */ @@ -80,8 +81,6 @@ typedef struct pciBusRec { } PciBusRec, *PciBusPtr; void xf86PciProbe(void); -void ValidatePci(void); -resList GetImplicitPciResources(int entityIndex); void initPciState(void); void initPciBusState(void); void DisablePciAccess(void); @@ -90,10 +89,7 @@ void PciStateEnter(void); void PciBusStateEnter(void); void PciStateLeave(void); void PciBusStateLeave(void); -resPtr ResourceBrokerInitPci(resPtr *osRes); void pciConvertRange2Host(int entityIndex, resRange *pRange); void isaConvertRange2Host(resRange *pRange); -extern pciAccPtr * xf86PciAccInfo; - #endif /* _XF86_PCI_BUS_H */ diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h index 590bf4cd0..324be10a3 100644 --- a/hw/xfree86/common/xf86str.h +++ b/hw/xfree86/common/xf86str.h @@ -44,6 +44,8 @@ #include "xf86Opt.h" #include "xf86Pci.h" +#include <pciaccess.h> + /* * memType is of the size of the addressable memory (machine size) * usually unsigned long. @@ -301,6 +303,9 @@ typedef struct { int refCount; } DriverRec1; +struct _SymTabRec; +struct _PciChipsets; + typedef struct _DriverRec { int driverVersion; char * driverName; @@ -310,6 +315,10 @@ typedef struct _DriverRec { pointer module; int refCount; xorgDriverFuncProc *driverFunc; + + const struct pci_id_match * supported_devices; + Bool (*PciProbe)( struct _DriverRec * drv, int entity_num, + struct pci_device * dev, intptr_t match_data ); } DriverRec, *DriverPtr; /* @@ -427,29 +436,6 @@ typedef struct { } IDevRec, *IDevPtr; typedef struct { - int vendor; - int chipType; - int chipRev; - int subsysVendor; - int subsysCard; - int bus; - int device; - int func; - int class; - int subclass; - int interface; - memType memBase[6]; - memType ioBase[6]; - int size[6]; - unsigned char type[6]; - memType biosBase; - int biosSize; - pointer thisCard; - Bool validSize; - Bool validate; -} pciVideoRec, *pciVideoPtr; - -typedef struct { int frameX0; int frameY0; int virtualX; @@ -731,7 +717,7 @@ typedef struct { resRange *resList; } IsaChipsets; -typedef struct { +typedef struct _PciChipsets { /** * Key used to match this device with its name in an array of * \c SymTabRec. @@ -1060,7 +1046,7 @@ typedef struct { ); } DGAFunctionRec, *DGAFunctionPtr; -typedef struct { +typedef struct _SymTabRec { int token; /* id of the token */ const char * name; /* token name */ } SymTabRec, *SymTabPtr; diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c index b58b670a2..cbd4e60e9 100644 --- a/hw/xfree86/dri/dri.c +++ b/hw/xfree86/dri/dri.c @@ -2066,19 +2066,16 @@ DRIMoveBuffersHelper( } char * -DRICreatePCIBusID(pciVideoPtr PciInfo) +DRICreatePCIBusID(const struct pci_device * dev) { char *busID; - int domain; - PCITAG tag; busID = xalloc(20); if (busID == NULL) return NULL; - tag = pciTag(PciInfo->bus, PciInfo->device, PciInfo->func); - domain = xf86GetPciDomain(tag); - snprintf(busID, 20, "pci:%04x:%02x:%02x.%d", domain, PciInfo->bus, - PciInfo->device, PciInfo->func); + snprintf(busID, 20, "pci:%04x:%02x:%02x.%d", dev->domain, dev->bus, + dev->dev, dev->func); + return busID; } diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h index 312e8a8bb..bc7cca6fa 100644 --- a/hw/xfree86/dri/dri.h +++ b/hw/xfree86/dri/dri.h @@ -36,6 +36,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef _DRI_H_ +#include <pciaccess.h> + #include "scrnintstr.h" #include "xf86dri.h" @@ -338,7 +340,7 @@ extern void DRIMoveBuffersHelper(ScreenPtr pScreen, int *ydir, RegionPtr reg); -extern char *DRICreatePCIBusID(pciVideoPtr PciInfo); +extern char *DRICreatePCIBusID(const struct pci_device *PciInfo); #define _DRI_H_ diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c index 70bed620b..277b5daea 100644 --- a/hw/xfree86/fbdevhw/fbdevhw.c +++ b/hw/xfree86/fbdevhw/fbdevhw.c @@ -268,53 +268,99 @@ fbdev2xfree_timing(struct fb_var_screeninfo *var, DisplayModePtr mode) /* -------------------------------------------------------------------- */ /* open correct framebuffer device */ -/* try to find the framebuffer device for a given PCI device */ +/** + * Try to find the framebuffer device for a given PCI device + */ static int -fbdev_open_pci(pciVideoPtr pPci, char **namep) -{ - struct fb_fix_screeninfo fix; - char filename[16]; - int fd,i,j; - memType res_start, res_end; - - for (i = 0; i < 8; i++) { - sprintf(filename,"/dev/fb%d",i); - if (-1 == (fd = open(filename,O_RDWR,0))) { - xf86DrvMsg(-1, X_WARNING, - "open %s: %s\n", filename, strerror(errno)); - continue; +fbdev_open_pci(struct pci_device * pPci, char **namep) +{ + struct fb_fix_screeninfo fix; + char filename[256]; + int fd,i,j; + + + /* There are two ways to that we can determine which fb device is + * associated with this PCI device. The more modern way is to look in + * the sysfs directory for the PCI device for a file named + * "graphics:fb*" + */ + + for (i = 0; i < 8; i++) { + sprintf(filename, + "/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics:fb%d", + pPci->domain, pPci->bus, pPci->dev, pPci->func, i); + + fd = open(filename, O_RDONLY, 0); + if (fd != -1) { + close(fd); + sprintf(filename, "/dev/fb%d", i); + + fd = open(filename, O_RDWR, 0); + if (fd != -1) { + if (ioctl(fd, FBIOGET_FSCREENINFO, (void*) & fix) != -1) { + if (namep) { + *namep = xnfalloc(16); + strncpy(*namep,fix.id,16); + } + + return fd; } - if (-1 == ioctl(fd,FBIOGET_FSCREENINFO,(void*)&fix)) { - close(fd); - continue; - } - for (j = 0; j < 6; j++) { - res_start = pPci->memBase[j]; - res_end = res_start+pPci->size[j]; - if ((0 != fix.smem_len && - (memType) fix.smem_start >= res_start && - (memType) fix.smem_start < res_end) || - (0 != fix.mmio_len && - (memType) fix.mmio_start >= res_start && - (memType) fix.mmio_start < res_end)) - break; - } - if (j == 6) { - close(fd); - continue; - } - if (namep) { - *namep = xnfalloc(16); - strncpy(*namep,fix.id,16); - } - return fd; + } } - if (namep) - *namep = NULL; - xf86DrvMsg(-1, X_ERROR, - "Unable to find a valid framebuffer device\n"); - return -1; + close(fd); + } + + + /* The other way is to examine the resources associated with each fb + * device and see if there is a match with the PCI device. This technique + * has some problems on certain mixed 64-bit / 32-bit architectures. + * There is a flaw in the fb_fix_screeninfo structure in that it only + * returns the low 32-bits of the address of the resources associated with + * a device. However, on a mixed architecture the base addresses of PCI + * devices, even for 32-bit applications, may be higher than 0x0f0000000. + */ + + for (i = 0; i < 8; i++) { + sprintf(filename,"/dev/fb%d",i); + if (-1 == (fd = open(filename,O_RDWR,0))) { + xf86DrvMsg(-1, X_WARNING, + "open %s: %s\n", filename, strerror(errno)); + continue; + } + if (-1 == ioctl(fd,FBIOGET_FSCREENINFO,(void*)&fix)) { + close(fd); + continue; + } + for (j = 0; j < 6; j++) { + const pciaddr_t res_start = pPci->regions[j].base_addr; + const pciaddr_t res_end = res_start + pPci->regions[j].size; + + if ((0 != fix.smem_len && + (pciaddr_t) fix.smem_start >= res_start && + (pciaddr_t) fix.smem_start < res_end) || + (0 != fix.mmio_len && + (pciaddr_t) fix.mmio_start >= res_start && + (pciaddr_t) fix.mmio_start < res_end)) + break; + } + if (j == 6) { + close(fd); + continue; + } + if (namep) { + *namep = xnfalloc(16); + strncpy(*namep,fix.id,16); + } + return fd; + } + + if (namep) + *namep = NULL; + + xf86DrvMsg(-1, X_ERROR, + "Unable to find a valid framebuffer device\n"); + return -1; } static int @@ -359,7 +405,7 @@ fbdev_open(int scrnIndex, char *dev, char** namep) /* -------------------------------------------------------------------- */ Bool -fbdevHWProbe(pciVideoPtr pPci, char *device,char **namep) +fbdevHWProbe(struct pci_device * pPci, char *device,char **namep) { int fd; @@ -375,7 +421,7 @@ fbdevHWProbe(pciVideoPtr pPci, char *device,char **namep) } Bool -fbdevHWInit(ScrnInfoPtr pScrn, pciVideoPtr pPci, char *device) +fbdevHWInit(ScrnInfoPtr pScrn, struct pci_device * pPci, char *device) { fbdevHWPtr fPtr; diff --git a/hw/xfree86/fbdevhw/fbdevhw.h b/hw/xfree86/fbdevhw/fbdevhw.h index cfc3fcdb6..3c482d709 100644 --- a/hw/xfree86/fbdevhw/fbdevhw.h +++ b/hw/xfree86/fbdevhw/fbdevhw.h @@ -6,6 +6,8 @@ #include "xf86str.h" #include "colormapst.h" +#include <pciaccess.h> + #define FBDEVHW_PACKED_PIXELS 0 /* Packed Pixels */ #define FBDEVHW_PLANES 1 /* Non interleaved planes */ #define FBDEVHW_INTERLEAVED_PLANES 2 /* Interleaved planes */ @@ -15,8 +17,8 @@ Bool fbdevHWGetRec(ScrnInfoPtr pScrn); void fbdevHWFreeRec(ScrnInfoPtr pScrn); -Bool fbdevHWProbe(pciVideoPtr pPci, char *device, char **namep); -Bool fbdevHWInit(ScrnInfoPtr pScrn, pciVideoPtr pPci, char *device); +Bool fbdevHWProbe(struct pci_device * pPci, char *device, char **namep); +Bool fbdevHWInit(ScrnInfoPtr pScrn, struct pci_device * pPci, char *device); char* fbdevHWGetName(ScrnInfoPtr pScrn); int fbdevHWGetDepth(ScrnInfoPtr pScrn, int *fbbpp); diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c index 69596d48e..0c3f2878c 100644 --- a/hw/xfree86/int10/generic.c +++ b/hw/xfree86/int10/generic.c @@ -17,6 +17,7 @@ #define _INT10_PRIVATE #include "xf86int10.h" #include "int10Defines.h" +#include "Pci.h" #define ALLOC_ENTRIES(x) ((V_RAM / x) - 1) @@ -75,7 +76,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags) void* base = 0; void* vbiosMem = 0; void* options = NULL; - pciVideoPtr pvp; + struct pci_device * pvp; int screen; legacyVGARec vga; xf86int10BiosLocation bios; @@ -105,7 +106,10 @@ xf86ExtendedInitInt10(int entityIndex, int Flags) base = INTPriv(pInt)->base = xnfalloc(SYS_BIOS); pvp = xf86GetPciInfoForEntity(entityIndex); - if (pvp) pInt->Tag = ((pciConfigPtr)(pvp->thisCard))->tag; + if (pvp != NULL) { + pInt->Tag = PCI_MAKE_TAG(PCI_MAKE_BUS(pvp->domain, pvp->bus), + pvp->dev, pvp->func); + } /* * we need to map video RAM MMIO as some chipsets map mmio @@ -288,16 +292,18 @@ xf86ExtendedInitInt10(int entityIndex, int Flags) vbiosMem = (char *)base + V_BIOS; (void)memset(vbiosMem, 0, 2 * V_BIOS_SIZE); if (xf86ReadDomainMemory(pInt->Tag, V_BIOS, V_BIOS_SIZE, vbiosMem) < - V_BIOS_SIZE) + V_BIOS_SIZE) { xf86DrvMsg(screen, X_WARNING, - "Unable to retrieve all of segment 0x0C0000.\n"); + "Unable to retrieve all of segment 0x0C0000.\n"); + } else if ((((unsigned char *)vbiosMem)[0] == 0x55) && (((unsigned char *)vbiosMem)[1] == 0xAA) && - (((unsigned char *)vbiosMem)[2] > 0x80)) - if (xf86ReadDomainMemory(pInt->Tag, V_BIOS + V_BIOS_SIZE, V_BIOS_SIZE, - (unsigned char *)vbiosMem + V_BIOS_SIZE) < V_BIOS_SIZE) - xf86DrvMsg(screen, X_WARNING, - "Unable to retrieve all of segment 0x0D0000.\n"); + (((unsigned char *)vbiosMem)[2] > 0x80)) { + if (xf86ReadDomainMemory(pInt->Tag, V_BIOS + V_BIOS_SIZE, V_BIOS_SIZE, + (unsigned char *)vbiosMem + V_BIOS_SIZE) < V_BIOS_SIZE) + xf86DrvMsg(screen, X_WARNING, + "Unable to retrieve all of segment 0x0D0000.\n"); + } /* * If this adapter is the primary, use its post-init BIOS (if we can find diff --git a/hw/xfree86/int10/helper_exec.c b/hw/xfree86/int10/helper_exec.c index 1809e2d95..320392e11 100644 --- a/hw/xfree86/int10/helper_exec.c +++ b/hw/xfree86/int10/helper_exec.c @@ -472,6 +472,8 @@ static CARD32 PciCfg1Addr = 0; #define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00) #define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff) +#define _BUS(x) (((x) >> 16) & 0x0ff) +#define _DEV(x) (((x) >> 8) & 0x0ff) static int pciCfg1in(CARD16 addr, CARD32 *val) @@ -481,7 +483,12 @@ pciCfg1in(CARD16 addr, CARD32 *val) return 1; } if (addr == 0xCFC) { - *val = pciReadLong(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr)); + struct pci_device * dev = pci_device_find_by_slot(0, + _BUS(PciCfg1Addr), + _DEV(PciCfg1Addr), + 0); + + pci_device_cfg_read_u32(dev, val, OFFSET(PciCfg1Addr)); return 1; } return 0; @@ -495,7 +502,12 @@ pciCfg1out(CARD16 addr, CARD32 val) return 1; } if (addr == 0xCFC) { - pciWriteLong(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr), val); + struct pci_device * dev = pci_device_find_by_slot(0, + _BUS(PciCfg1Addr), + _DEV(PciCfg1Addr), + 0); + + pci_device_cfg_write_u32(dev, & val, OFFSET(PciCfg1Addr)); return 1; } return 0; @@ -504,7 +516,7 @@ pciCfg1out(CARD16 addr, CARD32 val) static int pciCfg1inw(CARD16 addr, CARD16 *val) { - int offset, shift; + int shift; if ((addr >= 0xCF8) && (addr <= 0xCFB)) { shift = (addr - 0xCF8) * 8; @@ -512,8 +524,13 @@ pciCfg1inw(CARD16 addr, CARD16 *val) return 1; } if ((addr >= 0xCFC) && (addr <= 0xCFF)) { - offset = addr - 0xCFC; - *val = pciReadWord(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr) + offset); + const unsigned offset = addr - 0xCFC; + struct pci_device * dev = pci_device_find_by_slot(0, + _BUS(PciCfg1Addr), + _DEV(PciCfg1Addr), + 0); + + pci_device_cfg_read_u16(dev, val, OFFSET(PciCfg1Addr) + offset); return 1; } return 0; @@ -522,7 +539,7 @@ pciCfg1inw(CARD16 addr, CARD16 *val) static int pciCfg1outw(CARD16 addr, CARD16 val) { - int offset, shift; + int shift; if ((addr >= 0xCF8) && (addr <= 0xCFB)) { shift = (addr - 0xCF8) * 8; @@ -531,8 +548,13 @@ pciCfg1outw(CARD16 addr, CARD16 val) return 1; } if ((addr >= 0xCFC) && (addr <= 0xCFF)) { - offset = addr - 0xCFC; - pciWriteWord(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr) + offset, val); + const unsigned offset = addr - 0xCFC; + struct pci_device * dev = pci_device_find_by_slot(0, + _BUS(PciCfg1Addr), + _DEV(PciCfg1Addr), + 0); + + pci_device_cfg_write_u16(dev, & val, OFFSET(PciCfg1Addr) + offset); return 1; } return 0; @@ -541,7 +563,7 @@ pciCfg1outw(CARD16 addr, CARD16 val) static int pciCfg1inb(CARD16 addr, CARD8 *val) { - int offset, shift; + int shift; if ((addr >= 0xCF8) && (addr <= 0xCFB)) { shift = (addr - 0xCF8) * 8; @@ -549,8 +571,13 @@ pciCfg1inb(CARD16 addr, CARD8 *val) return 1; } if ((addr >= 0xCFC) && (addr <= 0xCFF)) { - offset = addr - 0xCFC; - *val = pciReadByte(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr) + offset); + const unsigned offset = addr - 0xCFC; + struct pci_device * dev = pci_device_find_by_slot(0, + _BUS(PciCfg1Addr), + _DEV(PciCfg1Addr), + 0); + + pci_device_cfg_read_u8(dev, val, OFFSET(PciCfg1Addr) + offset); return 1; } return 0; @@ -559,7 +586,7 @@ pciCfg1inb(CARD16 addr, CARD8 *val) static int pciCfg1outb(CARD16 addr, CARD8 val) { - int offset, shift; + int shift; if ((addr >= 0xCF8) && (addr <= 0xCFB)) { shift = (addr - 0xCF8) * 8; @@ -568,8 +595,13 @@ pciCfg1outb(CARD16 addr, CARD8 val) return 1; } if ((addr >= 0xCFC) && (addr <= 0xCFF)) { - offset = addr - 0xCFC; - pciWriteByte(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr) + offset, val); + const unsigned offset = addr - 0xCFC; + struct pci_device * dev = pci_device_find_by_slot(0, + _BUS(PciCfg1Addr), + _DEV(PciCfg1Addr), + 0); + + pci_device_cfg_write_u8(dev, & val, OFFSET(PciCfg1Addr) + offset); return 1; } return 0; diff --git a/hw/xfree86/int10/pci.c b/hw/xfree86/int10/pci.c index 520df1495..d5758e720 100644 --- a/hw/xfree86/int10/pci.c +++ b/hw/xfree86/int10/pci.c @@ -19,11 +19,8 @@ int mapPciRom(int pciEntity, unsigned char * address) { - PCITAG tag; - unsigned char *mem, *ptr; - int length; - - pciVideoPtr pvp = xf86GetPciInfoForEntity(pciEntity); + struct pci_device * pvp = xf86GetPciInfoForEntity(pciEntity); + int err; if (pvp == NULL) { #ifdef DEBUG @@ -32,19 +29,11 @@ mapPciRom(int pciEntity, unsigned char * address) return 0; } - tag = pciTag(pvp->bus,pvp->device,pvp->func); - length = 1 << pvp->biosSize; - /* Read in entire PCI ROM */ - mem = ptr = xnfcalloc(length, 1); - length = xf86ReadPciBIOS(0, tag, -1, ptr, length); - if (length > 0) - memcpy(address, ptr, length); - /* unmap/close/disable PCI bios mem */ - xfree(mem); + err = pci_device_read_rom( pvp, address ); #ifdef DEBUG - if (!length) + if ( err != 0 ) ErrorF("mapPciRom: no BIOS found\n"); #ifdef PRINT_PCI else @@ -52,5 +41,5 @@ mapPciRom(int pciEntity, unsigned char * address) #endif #endif - return length; + return pvp->rom_size; } diff --git a/hw/xfree86/int10/xf86int10.c b/hw/xfree86/int10/xf86int10.c index 303cf8925..e19bfbc97 100644 --- a/hw/xfree86/int10/xf86int10.c +++ b/hw/xfree86/int10/xf86int10.c @@ -24,8 +24,9 @@ static int int1A_handler(xf86Int10InfoPtr pInt); static int int42_handler(xf86Int10InfoPtr pInt); #endif static int intE6_handler(xf86Int10InfoPtr pInt); -static PCITAG findPci(xf86Int10InfoPtr pInt, unsigned short bx); -static CARD32 pciSlotBX(pciVideoPtr pvp); +static struct pci_device * findPci( xf86Int10InfoPtr pInt, + unsigned short bx ); +static CARD32 pciSlotBX( const struct pci_device * pvp ); int int_handler(xf86Int10InfoPtr pInt) @@ -597,7 +598,8 @@ static int int1A_handler(xf86Int10InfoPtr pInt) { PCITAG tag; - pciVideoPtr pvp; + struct pci_device * pvp; + struct pci_device * dev; if (!(pvp = xf86GetPciInfoForEntity(pInt->entityIndex))) return 0; /* oops */ @@ -620,7 +622,9 @@ int1A_handler(xf86Int10InfoPtr pInt) #endif return 1; case 0xb102: - if (X86_DX == pvp->vendor && X86_CX == pvp->chipType && X86_ESI == 0) { + if ( (X86_DX == pvp->vendor_id) + && (X86_CX == pvp->device_id) + && (X86_ESI == 0) ) { X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */ X86_EBX = pciSlotBX(pvp); @@ -642,9 +646,7 @@ int1A_handler(xf86Int10InfoPtr pInt) #endif return 1; case 0xb103: - if (X86_CL == pvp->interface && - X86_CH == pvp->subclass && - ((X86_ECX & 0xFFFF0000) >> 16) == pvp->class) { + if ( (X86_ECX & 0x00FFFFFF) == pvp->device_class ) { X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EBX = pciSlotBX(pvp); X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */ @@ -667,8 +669,8 @@ int1A_handler(xf86Int10InfoPtr pInt) #endif return 1; case 0xb108: - if ((tag = findPci(pInt, X86_EBX)) != PCI_NOT_FOUND) { - X86_CL = pciReadByte(tag, X86_EDI); + if ((dev = findPci(pInt, X86_EBX)) != NULL) { + pci_device_cfg_read_u8( dev, & X86_CL, X86_EDI ); X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */ } else { @@ -680,8 +682,8 @@ int1A_handler(xf86Int10InfoPtr pInt) #endif return 1; case 0xb109: - if ((tag = findPci(pInt, X86_EBX)) != PCI_NOT_FOUND) { - X86_CX = pciReadWord(tag, X86_EDI); + if ((dev = findPci(pInt, X86_EBX)) != NULL) { + pci_device_cfg_read_u16( dev, & X86_CX, X86_EDI ); X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */ } else { @@ -693,8 +695,8 @@ int1A_handler(xf86Int10InfoPtr pInt) #endif return 1; case 0xb10a: - if ((tag = findPci(pInt, X86_EBX)) != PCI_NOT_FOUND) { - X86_ECX = pciReadLong(tag, X86_EDI); + if ((dev = findPci(pInt, X86_EBX)) != NULL) { + pci_device_cfg_read_u32( dev, & X86_ECX, X86_EDI ); X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */ } else { @@ -706,8 +708,8 @@ int1A_handler(xf86Int10InfoPtr pInt) #endif return 1; case 0xb10b: - if ((tag = findPci(pInt, X86_EBX)) != PCI_NOT_FOUND) { - pciWriteByte(tag, X86_EDI, X86_CL); + if ((dev = findPci(pInt, X86_EBX)) != NULL) { + pci_device_cfg_write_u8( dev, & X86_CL, X86_EDI ); X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */ } else { @@ -719,8 +721,8 @@ int1A_handler(xf86Int10InfoPtr pInt) #endif return 1; case 0xb10c: - if ((tag = findPci(pInt, X86_EBX)) != PCI_NOT_FOUND) { - pciWriteWord(tag, X86_EDI, X86_CX); + if ((dev = findPci(pInt, X86_EBX)) != NULL) { + pci_device_cfg_write_u16( dev, & X86_CX, X86_EDI ); X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */ } else { @@ -732,8 +734,8 @@ int1A_handler(xf86Int10InfoPtr pInt) #endif return 1; case 0xb10d: - if ((tag = findPci(pInt, X86_EBX)) != PCI_NOT_FOUND) { - pciWriteLong(tag, X86_EDI, X86_ECX); + if ((dev = findPci(pInt, X86_EBX)) != NULL) { + pci_device_cfg_write_u32( dev, & X86_ECX, X86_EDI ); X86_EAX = X86_AL | (SUCCESSFUL << 8); X86_EFLAGS &= ~((unsigned long)0x01); /* clear carry flag */ } else { @@ -754,21 +756,21 @@ int1A_handler(xf86Int10InfoPtr pInt) } } -static PCITAG +static struct pci_device * findPci(xf86Int10InfoPtr pInt, unsigned short bx) { - int bus = ((pInt->Tag >> 16) & ~0x00FF) | ((bx >> 8) & 0x00FF); - int dev = (bx >> 3) & 0x1F; - int func = bx & 0x7; - if (xf86IsPciDevPresent(bus, dev, func)) - return pciTag(bus, dev, func); - return PCI_NOT_FOUND; + const unsigned domain = PCI_DOM_FROM_TAG( pInt->Tag ); + const unsigned bus = (bx >> 8) & 0x00FF; + const unsigned dev = (bx >> 3) & 0x001F; + const unsigned func = (bx ) & 0x0007; + + return pci_device_find_by_slot( domain, bus, dev, func ); } static CARD32 -pciSlotBX(pciVideoPtr pvp) +pciSlotBX(const struct pci_device * pvp) { - return ((pvp->bus << 8) & 0x00FF00) | (pvp->device << 3) | (pvp->func); + return ((pvp->bus << 8) & 0x00FF00) | (pvp->dev << 3) | (pvp->func); } /* @@ -777,10 +779,10 @@ pciSlotBX(pciVideoPtr pvp) static int intE6_handler(xf86Int10InfoPtr pInt) { - pciVideoPtr pvp; + struct pci_device * pvp; if ((pvp = xf86GetPciInfoForEntity(pInt->entityIndex))) - X86_AX = (pvp->bus << 8) | (pvp->device << 3) | (pvp->func & 0x7); + X86_AX = (pvp->bus << 8) | (pvp->dev << 3) | (pvp->func & 0x7); pushw(pInt, X86_CS); pushw(pInt, X86_IP); X86_CS = pInt->BIOSseg; diff --git a/hw/xfree86/loader/Makefile.am b/hw/xfree86/loader/Makefile.am index 684087eae..01c62e92e 100644 --- a/hw/xfree86/loader/Makefile.am +++ b/hw/xfree86/loader/Makefile.am @@ -1,7 +1,7 @@ noinst_LIBRARIES = libloader.a INCLUDES = $(XORG_INCS) -I$(srcdir)/../parser -I$(srcdir)/../vbe \ -I$(srcdir)/../ddc -I$(srcdir)/../int10 -I$(srcdir)/../i2c \ - -I$(srcdir)/../fbdevhw -I$(srcdir)/../scanpci -I$(srcdir)/../xaa \ + -I$(srcdir)/../fbdevhw -I$(srcdir)/../xaa \ -I$(srcdir)/../vgahw -I$(srcdir)/../ramdac -I$(srcdir)/../shadowfb \ -I$(srcdir)/../dixmods/extmod -I$(srcdir)/../../../miext/cw \ -I$(srcdir)/../../../miext/damage diff --git a/hw/xfree86/loader/xf86sym.c b/hw/xfree86/loader/xf86sym.c index 32fe012ad..a65fe8a79 100644 --- a/hw/xfree86/loader/xf86sym.c +++ b/hw/xfree86/loader/xf86sym.c @@ -49,8 +49,6 @@ * authorization from the copyright holder(s) and author(s). */ -#define INCLUDE_DEPRECATED 1 - #ifdef HAVE_XORG_CONFIG_H #include <xorg-config.h> #endif @@ -308,10 +306,7 @@ LOOKUP xfree86LookupTab[] = { /* xf86Bus.c */ SYMFUNC(xf86CheckPciSlot) SYMFUNC(xf86ClaimPciSlot) - SYMFUNC(xf86GetPciVideoInfo) SYMFUNC(xf86GetPciEntity) - SYMFUNC(xf86GetPciConfigInfo) - SYMFUNC(xf86SetPciVideo) SYMFUNC(xf86ClaimIsaSlot) SYMFUNC(xf86ClaimFbSlot) SYMFUNC(xf86ClaimNoSlot) @@ -342,20 +337,14 @@ LOOKUP xfree86LookupTab[] = { SYMFUNC(xf86CheckPciMemBase) SYMFUNC(xf86SetAccessFuncs) SYMFUNC(xf86IsEntityPrimary) - SYMFUNC(xf86FixPciResource) SYMFUNC(xf86SetOperatingState) SYMFUNC(xf86EnterServerState) SYMFUNC(xf86GetBlock) SYMFUNC(xf86GetSparse) - SYMFUNC(xf86ReallocatePciResources) SYMFUNC(xf86ChkConflict) - SYMFUNC(xf86IsPciDevPresent) SYMFUNC(xf86FindScreenForEntity) SYMFUNC(xf86FindPciDeviceVendor) SYMFUNC(xf86FindPciClass) -#ifdef INCLUDE_DEPRECATED - SYMFUNC(xf86EnablePciBusMaster) -#endif SYMFUNC(xf86RegisterStateChangeNotificationCallback) SYMFUNC(xf86DeregisterStateChangeNotificationCallback) SYMFUNC(xf86NoSharedResources) @@ -729,21 +718,10 @@ LOOKUP xfree86LookupTab[] = { SYMFUNC(xf86STimestamp) #endif - SYMFUNC(pciFindFirst) - SYMFUNC(pciFindNext) - SYMFUNC(pciWriteByte) - SYMFUNC(pciWriteWord) - SYMFUNC(pciWriteLong) - SYMFUNC(pciReadByte) - SYMFUNC(pciReadWord) - SYMFUNC(pciReadLong) - SYMFUNC(pciSetBitsLong) SYMFUNC(pciTag) SYMFUNC(pciBusAddrToHostAddr) SYMFUNC(pciHostAddrToBusAddr) - SYMFUNC(xf86MapPciMem) SYMFUNC(xf86scanpci) - SYMFUNC(xf86ReadPciBIOS) /* Loader functions */ SYMFUNC(LoaderDefaultFunc) diff --git a/hw/xfree86/os-support/bus/Pci.c b/hw/xfree86/os-support/bus/Pci.c index 15006e179..39994d93d 100644 --- a/hw/xfree86/os-support/bus/Pci.c +++ b/hw/xfree86/os-support/bus/Pci.c @@ -9,8 +9,6 @@ * All of the public PCI access functions exported to the other parts of * the server are declared in Pci.h and defined herein. These include: * pciInit() - Initialize PCI access functions - * pciFindFirst() - Find a PCI device by dev/vend id - * pciFindNext() - Find another PCI device by dev/vend id * pciReadLong() - Read a 32 bit value from a device's cfg space * pciReadWord() - Read a 16 bit value from a device's cfg space * pciReadByte() - Read an 8 bit value from a device's cfg space @@ -23,13 +21,6 @@ * function * pciBusAddrToHostAddr() - Convert a PCI address to a host address * pciHostAddrToBusAddr() - Convert a host address to a PCI address - * pciGetBaseSize() - Returns the number of bits in a PCI base - * addr mapping - * xf86MapPciMem() - Like xf86MapVidMem() except function expects - * a PCI address and a PCITAG that identifies - * a PCI device - * xf86ReadPciBIOS() - Like xf86ReadBIOS() but can handle PCI/host - * address translation and BIOS decode enabling * xf86scanpci() - Return info about all PCI devices * xf86GetPciDomain() - Return domain number from a PCITAG * xf86MapDomainMemory() - Like xf86MapPciMem() but can handle @@ -209,22 +200,22 @@ #include "xf86_OSproc.h" #include "Pci.h" +#include <pciaccess.h> + +#if 0 +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + #define PCI_MFDEV_SUPPORT 1 /* Include PCI multifunction device support */ #define PCI_BRIDGE_SUPPORT 1 /* Include support for PCI-to-PCI bridges */ /* * Global data */ -static int pciInitialized = 0; - -CARD32 pciDevid; /* Requested device/vendor ID (after mask) */ -CARD32 pciDevidMask; /* Bit mask applied (AND) before comparison */ - /* of real devid's with requested */ - -int pciBusNum; /* Bus Number of current device */ -int pciDevNum; /* Device number of current device */ -int pciFuncNum; /* Function number of current device */ -PCITAG pciDeviceTag; /* Tag for current device */ pciBusInfo_t *pciBusInfo[MAX_PCI_BUSES] = { NULL, }; _X_EXPORT int pciNumBuses = 0; /* Actual number of PCI buses */ @@ -236,234 +227,34 @@ static pciConfigPtr pci_devp[MAX_PCI_DEVICES + 1] = {NULL, }; static int readPciBios( PCITAG Tag, CARD8* tmp, ADDRESS hostbase, unsigned char * buf, int len, PciBiosType BiosType ); -static int (*pciOSHandleBIOS)(PCITAG Tag, int basereg, unsigned char *buf, int len); - -int xf86MaxPciDevs = MAX_PCI_DEVICES; - -/* - * Platform specific PCI function pointers. - * - * NOTE: A platform/OS specific pci init procedure can override these defaults - * by setting them to the appropriate platform dependent functions. - */ -PCITAG (*pciFindFirstFP)(void) = pciGenFindFirst; -PCITAG (*pciFindNextFP)(void) = pciGenFindNext; /* * pciInit - choose correct platform/OS specific PCI init routine */ -void -pciInit() +static void +pciInit(void) { - if (pciInitialized) - return; + static int pciInitialized = 0; + if (!pciInitialized) { pciInitialized = 1; /* XXX */ #if defined(DEBUGPCI) - if (DEBUGPCI >= xf86Verbose) - xf86Verbose = DEBUGPCI; + if (DEBUGPCI >= xf86Verbose) { + xf86Verbose = DEBUGPCI; + } #endif ARCH_PCI_INIT(); #if defined(ARCH_PCI_OS_INIT) - if (pciNumBuses <= 0) + if (pciNumBuses <= 0) { ARCH_PCI_OS_INIT(); + } #endif -} - -void pciSetOSBIOSPtr(int (*bios_fn)(PCITAG Tag, int basereg, unsigned char * buf, int len)) -{ - pciOSHandleBIOS = bios_fn; -} - -_X_EXPORT PCITAG -pciFindFirst(CARD32 id, CARD32 mask) -{ -#ifdef DEBUGPCI - ErrorF("pciFindFirst(0x%lx, 0x%lx), pciInit = %d\n", id, mask, pciInitialized); -#endif - pciInit(); - - pciDevid = id & mask; - pciDevidMask = mask; - - return((*pciFindFirstFP)()); -} - -_X_EXPORT PCITAG -pciFindNext(void) -{ -#ifdef DEBUGPCI - ErrorF("pciFindNext(), pciInit = %d\n", pciInitialized); -#endif - pciInit(); - - return((*pciFindNextFP)()); -} - -_X_EXPORT CARD32 -pciReadLong(PCITAG tag, int offset) -{ - int bus = PCI_BUS_FROM_TAG(tag); - -#ifdef DEBUGPCI - ErrorF("pciReadLong(0x%lx, %d)\n", tag, offset); -#endif - pciInit(); - - if ((bus >= 0) && ((bus < pciNumBuses) || inProbe) && pciBusInfo[bus] && - pciBusInfo[bus]->funcs->pciReadLong) { - CARD32 rv = (*pciBusInfo[bus]->funcs->pciReadLong)(tag, offset); - - PCITRACE(1, ("pciReadLong: tag=0x%x [b=%d,d=%d,f=%d] returns 0x%08x\n", - tag, bus, PCI_DEV_FROM_TAG(tag), PCI_FUNC_FROM_TAG(tag), rv)); - return(rv); - } - - return(PCI_NOT_FOUND); -} - -_X_EXPORT CARD16 -pciReadWord(PCITAG tag, int offset) -{ - CARD32 tmp; - int shift = (offset & 3) * 8; - int aligned_offset = offset & ~3; - int bus = PCI_BUS_FROM_TAG(tag); - - if (shift != 0 && shift != 16) - FatalError("pciReadWord: Alignment error: Cannot read 16 bits " - "at offset %d\n", offset); - - pciInit(); - - if ((bus >= 0) && ((bus < pciNumBuses) || inProbe) && pciBusInfo[bus] && - pciBusInfo[bus]->funcs->pciReadWord) { - CARD32 rv = (*pciBusInfo[bus]->funcs->pciReadWord)(tag, offset); - - return(rv); - } else { - tmp = pciReadLong(tag, aligned_offset); - - return((CARD16)((tmp >> shift) & 0xffff)); - } -} - -_X_EXPORT CARD8 -pciReadByte(PCITAG tag, int offset) -{ - CARD32 tmp; - int shift = (offset & 3) * 8; - int aligned_offset = offset & ~3; - int bus = PCI_BUS_FROM_TAG(tag); - - pciInit(); - - if ((bus >= 0) && ((bus < pciNumBuses) || inProbe) && pciBusInfo[bus] && - pciBusInfo[bus]->funcs->pciReadByte) { - CARD8 rv = (*pciBusInfo[bus]->funcs->pciReadByte)(tag, offset); - - return(rv); - } else { - tmp = pciReadLong(tag, aligned_offset); - - return((CARD8)((tmp >> shift) & 0xff)); - } -} - -_X_EXPORT void -pciWriteLong(PCITAG tag, int offset, CARD32 val) -{ - int bus = PCI_BUS_FROM_TAG(tag); - - pciInit(); - - if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] && - pciBusInfo[bus]->funcs->pciWriteLong) - (*pciBusInfo[bus]->funcs->pciWriteLong)(tag, offset, val); -} - -_X_EXPORT void -pciWriteWord(PCITAG tag, int offset, CARD16 val) -{ - CARD32 tmp; - int aligned_offset = offset & ~3; - int shift = (offset & 3) * 8; - int bus = PCI_BUS_FROM_TAG(tag); - - if (shift != 0 && shift != 16) - FatalError("pciWriteWord: Alignment Error: Cannot read 16 bits " - "from offset %d\n", offset); - - pciInit(); - - if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] && - pciBusInfo[bus]->funcs->pciWriteWord) { - (*pciBusInfo[bus]->funcs->pciWriteWord)(tag, offset, val); - } else { - tmp = pciReadLong(tag, aligned_offset); - - tmp &= ~(0xffffL << shift); - tmp |= (((CARD32)val) << shift); - - pciWriteLong(tag, aligned_offset, tmp); - } -} - -_X_EXPORT void -pciWriteByte(PCITAG tag, int offset, CARD8 val) -{ - CARD32 tmp; - int aligned_offset = offset & ~3; - int shift = (offset & 3) *8 ; - int bus = PCI_BUS_FROM_TAG(tag); - - pciInit(); - - if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] && - pciBusInfo[bus]->funcs->pciWriteByte) { - (*pciBusInfo[bus]->funcs->pciWriteByte)(tag, offset, val); - } else { - - tmp = pciReadLong(tag, aligned_offset); - - tmp &= ~(0xffL << shift); - tmp |= (((CARD32)val) << shift); - - pciWriteLong(tag, aligned_offset, tmp); - } -} - -_X_EXPORT void -pciSetBitsLong(PCITAG tag, int offset, CARD32 mask, CARD32 val) -{ - int bus = PCI_BUS_FROM_TAG(tag); - -#ifdef DEBUGPCI - ErrorF("pciReadLong(0x%lx, %d)\n", tag, offset); -#endif - pciInit(); - - if ((bus >= 0) && (bus < pciNumBuses) && pciBusInfo[bus] && - pciBusInfo[bus]->funcs->pciSetBitsLong) { - (*pciBusInfo[bus]->funcs->pciSetBitsLong)(tag, offset, mask, val); } } -void -pciSetBitsByte(PCITAG tag, int offset, CARD8 mask, CARD8 val) -{ - CARD32 tmp_mask, tmp_val; - int aligned_offset = offset & ~3; - int shift = (offset & 3) *8 ; - - tmp_mask = mask << shift; - tmp_val = val << shift; - pciSetBitsLong(tag, aligned_offset, tmp_mask, tmp_val); -} - _X_EXPORT ADDRESS pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr) { @@ -492,393 +283,12 @@ pciHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr) return(addr); } -/* - * pciGetBaseSize() returns the size of a PCI base address mapping in bits. - * The index identifies the base register: 0-5 are the six standard registers, - * and 6 is the ROM base register. If destructive is TRUE, it will write - * to the base address register to get an accurate result. Otherwise it - * makes a conservative guess based on the alignment of the already allocated - * address. If the result is accurate (ie, not an over-estimate), this is - * indicated by setting *min to TRUE (when min is non-NULL). This happens - * when either the destructive flag is set, the information is supplied by - * the OS if the OS supports this. - */ - -int -pciGetBaseSize(PCITAG tag, int index, Bool destructive, Bool *min) -{ - int offset; - CARD32 addr1; - CARD32 addr2; - CARD32 mask1; - CARD32 mask2; - int bits = 0; - - /* - * Eventually a function for this should be added to pciBusFuncs_t, but for - * now we'll just use a simple method based on the alignment of the already - * allocated address. - */ - - /* - * silently ignore bogus index values. Valid values are 0-6. 0-5 are - * the 6 base address registers, and 6 is the ROM base address register. - */ - if (index < 0 || index > 6) - return 0; - - pciInit(); - - if (xf86GetPciSizeFromOS(tag, index, &bits)) { - if (min) - *min = TRUE; - return bits; - } - - if (min) - *min = destructive; - - /* Get the PCI offset */ - if (index == 6) - offset = PCI_MAP_ROM_REG; - else - offset = PCI_MAP_REG_START + (index << 2); - - addr1 = pciReadLong(tag, offset); - /* - * Check if this is the second part of a 64 bit address. - * XXX need to check how endianness affects 64 bit addresses. - */ - if (index > 0 && index < 6) { - addr2 = pciReadLong(tag, offset - 4); - if (PCI_MAP_IS_MEM(addr2) && PCI_MAP_IS64BITMEM(addr2)) - return 0; - } - - if (destructive) { - pciWriteLong(tag, offset, 0xffffffff); - mask1 = pciReadLong(tag, offset); - pciWriteLong(tag, offset, addr1); - } else { - mask1 = addr1; - } - - /* Check if this is the first part of a 64 bit address. */ - if (index < 5 && PCI_MAP_IS_MEM(mask1) && PCI_MAP_IS64BITMEM(mask1)) { - if (PCIGETMEMORY(mask1) == 0) { - addr2 = pciReadLong(tag, offset + 4); - if (destructive) { - pciWriteLong(tag, offset + 4, 0xffffffff); - mask2 = pciReadLong(tag, offset + 4); - pciWriteLong(tag, offset + 4, addr2); - } else { - mask2 = addr2; - } - if (mask2 == 0) - return 0; - bits = 32; - while ((mask2 & 1) == 0) { - bits++; - mask2 >>= 1; - } - if (bits > 32) - return bits; - } - } - if (index < 6) - if (PCI_MAP_IS_MEM(mask1)) - mask1 = PCIGETMEMORY(mask1); - else - mask1 = PCIGETIO(mask1); - else - mask1 = PCIGETROM(mask1); - if (mask1 == 0) - return 0; - bits = 0; - while ((mask1 & 1) == 0) { - bits++; - mask1 >>= 1; - } - /* I/O maps can be no larger than 8 bits */ - - if ((index < 6) && PCI_MAP_IS_IO(addr1) && bits > 8) - bits = 8; - /* ROM maps can be no larger than 24 bits */ - if (index == 6 && bits > 24) - bits = 24; - return bits; -} - _X_EXPORT PCITAG pciTag(int busnum, int devnum, int funcnum) { return(PCI_MAKE_TAG(busnum,devnum,funcnum)); } -#if defined(PCI_MFDEV_SUPPORT) - -Bool -pciMfDev(int busnum, int devnum) -{ - PCITAG tag0, tag1; - CARD32 id0, id1, val; - - /* Detect a multi-function device that complies to the PCI 2.0 spec */ - - tag0 = PCI_MAKE_TAG(busnum, devnum, 0); - id0 = pciReadLong(tag0, PCI_ID_REG); - if ((CARD16)(id0 + 1) <= (CARD16)1UL) - return FALSE; - - val = pciReadLong(tag0, PCI_HEADER_MISC) & 0x00ff0000; - if ((val != 0x00ff0000) && (val & PCI_HEADER_MULTIFUNCTION)) - return TRUE; - - /* - * Now, to find non-compliant devices... - * If there is a valid ID for function 1 and the ID for func 0 and 1 - * are different, or the base0 values of func 0 and 1 are differend, - * then assume there is a multi-function device. - */ - tag1 = PCI_MAKE_TAG(busnum, devnum, 1); - id1 = pciReadLong(tag1, PCI_ID_REG); - if ((CARD16)(id1 + 1) <= (CARD16)1UL) - return FALSE; - - /* Vendor IDs should match */ - if ((id0 ^ id1) & 0x0000ffff) - return FALSE; - - if ((id0 != id1) || - /* Note the following test is valid for header types 0, 1 and 2 */ - (pciReadLong(tag0, PCI_MAP_REG_START) != - pciReadLong(tag1, PCI_MAP_REG_START))) - return TRUE; - - return FALSE; -} - -#endif - -/* - * Generic find/read/write functions - */ -PCITAG -pciGenFindNext(void) -{ - CARD32 devid, tmp; - int sec_bus, pri_bus; - static int previousBus = 0; - Bool speculativeProbe = FALSE; - unsigned char base_class, sub_class; - -#ifdef DEBUGPCI - ErrorF("pciGenFindNext\n"); -#endif - - for (;;) { - -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: pciBusNum %d\n", pciBusNum); -#endif - if (pciBusNum == -1) { - /* - * Start at top of the order - */ - if (pciNumBuses <= 0) - return(PCI_NOT_FOUND); - - /* Skip ahead to the first bus defined by pciInit() */ - for (pciBusNum = 0; !pciBusInfo[pciBusNum]; ++pciBusNum); - pciFuncNum = 0; - pciDevNum = 0; - previousBus = pciBusNum; /* make sure previousBus exists */ - } else { -#ifdef PCI_MFDEV_SUPPORT -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: pciFuncNum %d\n", pciFuncNum); -#endif - /* - * Somewhere in middle of order. Determine who's - * next up - */ - if (pciFuncNum == 0) { - /* - * Is current dev a multifunction device? - */ - if (!speculativeProbe && pciMfDev(pciBusNum, pciDevNum)) - /* Probe for other functions */ - pciFuncNum = 1; - else - /* - * No more functions this device. Next - * device please - */ - pciDevNum ++; - } else if (++pciFuncNum >= 8) { - /* No more functions for this device. Next device please */ - pciFuncNum = 0; - pciDevNum ++; - } -#else - pciDevNum ++; -#endif - if (pciDevNum >= 32 || - !pciBusInfo[pciBusNum] || - pciDevNum >= pciBusInfo[pciBusNum]->numDevices) { -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: next bus\n"); -#endif - /* - * No more devices for this bus. Next bus please - */ - if (speculativeProbe) { - NextSpeculativeBus: - xfree(pciBusInfo[pciBusNum]); - pciBusInfo[pciBusNum] = NULL; - speculativeProbe = FALSE; - } - - if (++pciBusNum >= pciMaxBusNum) { -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: out of buses\n"); -#endif - /* No more buses. All done for now */ - return(PCI_NOT_FOUND); - } - - pciDevNum = 0; - } - } - -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: pciBusInfo[%d] = 0x%lx\n", pciBusNum, pciBusInfo[pciBusNum]); -#endif - if (!pciBusInfo[pciBusNum]) { - pciBusInfo[pciBusNum] = xnfalloc(sizeof(pciBusInfo_t)); - *pciBusInfo[pciBusNum] = *pciBusInfo[previousBus]; - - speculativeProbe = TRUE; - } - - /* - * At this point, pciBusNum, pciDevNum, and pciFuncNum have been - * advanced to the next device. Compute the tag, and read the - * device/vendor ID field. - */ -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: [%d, %d, %d]\n", pciBusNum, pciDevNum, pciFuncNum); -#endif - pciDeviceTag = PCI_MAKE_TAG(pciBusNum, pciDevNum, pciFuncNum); - inProbe = TRUE; - devid = pciReadLong(pciDeviceTag, PCI_ID_REG); - inProbe = FALSE; -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: pciDeviceTag = 0x%lx, devid = 0x%lx\n", pciDeviceTag, devid); -#endif - if ((CARD16)(devid + 1U) <= (CARD16)1UL) - continue; /* Nobody home. Next device please */ - - /* - * Some devices mis-decode configuration cycles in such a way as to - * create phantom buses. - */ - if (speculativeProbe && (pciDevNum == 0) && (pciFuncNum == 0) && - (PCI_BUS_NO_DOMAIN(pciBusNum) > 0)) { - for (;;) { - if (++pciDevNum >= pciBusInfo[pciBusNum]->numDevices) - goto NextSpeculativeBus; - if (devid != - pciReadLong(PCI_MAKE_TAG(pciBusNum, pciDevNum, 0), - PCI_ID_REG)) - break; - } - - pciDevNum = 0; - } - - if (pciNumBuses <= pciBusNum) - pciNumBuses = pciBusNum + 1; - - speculativeProbe = FALSE; - previousBus = pciBusNum; - -#ifdef PCI_BRIDGE_SUPPORT - /* - * Before checking for a specific devid, look for enabled - * PCI to PCI bridge devices. If one is found, create and - * initialize a bus info record (if one does not already exist). - */ - tmp = pciReadLong(pciDeviceTag, PCI_CLASS_REG); - base_class = PCI_CLASS_EXTRACT(tmp); - sub_class = PCI_SUBCLASS_EXTRACT(tmp); - if ((base_class == PCI_CLASS_BRIDGE) && - ((sub_class == PCI_SUBCLASS_BRIDGE_PCI) || - (sub_class == PCI_SUBCLASS_BRIDGE_CARDBUS))) { - tmp = pciReadLong(pciDeviceTag, PCI_PCI_BRIDGE_BUS_REG); - sec_bus = PCI_SECONDARY_BUS_EXTRACT(tmp, pciDeviceTag); - pri_bus = PCI_PRIMARY_BUS_EXTRACT(tmp, pciDeviceTag); -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: pri_bus %d sec_bus %d\n", - pri_bus, sec_bus); -#endif - if (pciBusNum != pri_bus) { - /* Some bridges do not implement the primary bus register */ - if ((PCI_BUS_NO_DOMAIN(pri_bus) != 0) || - (sub_class != PCI_SUBCLASS_BRIDGE_CARDBUS)) - xf86Msg(X_WARNING, - "pciGenFindNext: primary bus mismatch on PCI" - " bridge 0x%08lx (0x%02x, 0x%02x)\n", - pciDeviceTag, pciBusNum, pri_bus); - pri_bus = pciBusNum; - } - if ((pri_bus < sec_bus) && (sec_bus < pciMaxBusNum) && - pciBusInfo[pri_bus]) { - /* - * Found a secondary PCI bus - */ - if (!pciBusInfo[sec_bus]) { - pciBusInfo[sec_bus] = xnfalloc(sizeof(pciBusInfo_t)); - - /* Copy parents settings... */ - *pciBusInfo[sec_bus] = *pciBusInfo[pri_bus]; - } - - /* ...but not everything same as parent */ - pciBusInfo[sec_bus]->primary_bus = pri_bus; - pciBusInfo[sec_bus]->secondary = TRUE; - pciBusInfo[sec_bus]->numDevices = 32; - - if (pciNumBuses <= sec_bus) - pciNumBuses = sec_bus + 1; - } - } -#endif - - /* - * Does this device match the requested devid after - * applying mask? - */ -#ifdef DEBUGPCI - ErrorF("pciGenFindNext: pciDevidMask = 0x%lx, pciDevid = 0x%lx\n", pciDevidMask, pciDevid); -#endif - if ((devid & pciDevidMask) == pciDevid) - /* Yes - Return it. Otherwise, next device */ - return(pciDeviceTag); /* got a match */ - - } /* for */ - /*NOTREACHED*/ -} - -PCITAG -pciGenFindFirst(void) -{ - /* Reset PCI bus number to start from top */ - pciBusNum = -1; - - return pciGenFindNext(); -} - CARD32 pciByteSwap(CARD32 u) { @@ -889,7 +299,7 @@ pciByteSwap(CARD32 u) #else /* !BIG_ENDIAN */ return(u); - + #endif } @@ -905,7 +315,8 @@ xf86scanpci(int flags) pciConfigPtr devp; pciBusInfo_t *busp; int idx = 0, i; - PCITAG tag; + struct pci_device * dev; + struct pci_device_iterator * iter; static Bool done = FALSE; /* @@ -918,29 +329,28 @@ xf86scanpci(int flags) done = TRUE; + pci_system_init(); pciInit(); #ifdef XF86SCANPCI_WRAPPER XF86SCANPCI_WRAPPER(SCANPCI_INIT); #endif - tag = pciFindFirst(0,0); /* 0 mask means match any valid device */ + iter = pci_slot_match_iterator_create(NULL); + dev = pci_device_next(iter); + /* Check if no devices, return now */ - if (tag == PCI_NOT_FOUND) { + if (dev == NULL) { #ifdef XF86SCANPCI_WRAPPER XF86SCANPCI_WRAPPER(SCANPCI_TERM); #endif return NULL; } -#ifdef DEBUGPCI - ErrorF("xf86scanpci: tag = 0x%lx\n", tag); -#endif -#ifndef OLD_FORMAT - xf86MsgVerb(X_INFO, 2, "PCI: PCI scan (all values are in hex)\n"); -#endif - while (idx < xf86MaxPciDevs && tag != PCI_NOT_FOUND) { + while ((idx < MAX_PCI_DEVICES) && (dev != NULL)) { + pci_device_probe(dev); + devp = xcalloc(1, sizeof(pciDevice)); if (!devp) { xf86Msg(X_ERROR, @@ -949,14 +359,17 @@ xf86scanpci(int flags) } /* Identify pci device by bus, dev, func, and tag */ - devp->tag = tag; - devp->busnum = PCI_BUS_FROM_TAG(tag); - devp->devnum = PCI_DEV_FROM_TAG(tag); - devp->funcnum = PCI_FUNC_FROM_TAG(tag); + devp->dev = dev; + devp->busnum = PCI_MAKE_BUS(dev->domain, dev->bus); + devp->devnum = dev->dev; + devp->funcnum = dev->func; + devp->tag = PCI_MAKE_TAG(devp->busnum, dev->dev, dev->func); /* Read config space for this device */ - for (i = 0; i < 17; i++) /* PCI hdr plus 1st dev spec dword */ - devp->cfgspc.dwords[i] = pciReadLong(tag, i * sizeof(CARD32)); + for (i = 0; i < 17; i++) { /* PCI hdr plus 1st dev spec dword */ + pci_device_cfg_read_u32(dev, & devp->cfgspc.dwords[i], + i * sizeof(CARD32)); + } /* Some broken devices don't implement this field... */ if (devp->pci_header_type == 0xff) @@ -964,52 +377,37 @@ xf86scanpci(int flags) switch (devp->pci_header_type & 0x7f) { case 0: - /* Get base address sizes for type 0 headers */ - for (i = 0; i < 7; i++) - devp->basesize[i] = - pciGetBaseSize(tag, i, FALSE, &devp->minBasesize); break; case 1: - case 2: + case 2: { + const uint8_t control = devp->pci_bridge_control & + ~(PCI_PCI_BRIDGE_MASTER_ABORT_EN | + PCI_PCI_BRIDGE_SECONDARY_RESET); + /* Allow master aborts to complete normally on secondary buses */ if (!(devp->pci_bridge_control & PCI_PCI_BRIDGE_MASTER_ABORT_EN)) break; - pciWriteByte(tag, PCI_PCI_BRIDGE_CONTROL_REG, - devp->pci_bridge_control & - ~(PCI_PCI_BRIDGE_MASTER_ABORT_EN | - PCI_PCI_BRIDGE_SECONDARY_RESET)); - break; + pci_device_cfg_write_u8(dev, & control, + PCI_PCI_BRIDGE_CONTROL_REG); + break; + } default: break; } -#ifdef OLD_FORMAT - xf86MsgVerb(X_INFO, 2, "PCI: BusID 0x%.2x,0x%02x,0x%1x " - "ID 0x%04x,0x%04x Rev 0x%02x Class 0x%02x,0x%02x\n", - devp->busnum, devp->devnum, devp->funcnum, - devp->pci_vendor, devp->pci_device, devp->pci_rev_id, - devp->pci_base_class, devp->pci_sub_class); -#else xf86MsgVerb(X_INFO, 2, "PCI: %.2x:%02x:%1x: chip %04x,%04x" " card %04x,%04x rev %02x class %02x,%02x,%02x hdr %02x\n", devp->busnum, devp->devnum, devp->funcnum, - devp->pci_vendor, devp->pci_device, + devp->pci_vendor, devp->_pci_device, devp->pci_subsys_vendor, devp->pci_subsys_card, devp->pci_rev_id, devp->pci_base_class, devp->pci_sub_class, devp->pci_prog_if, devp->pci_header_type); -#endif pci_devp[idx++] = devp; - if (idx == xf86MaxPciDevs) - break; - tag = pciFindNext(); - -#ifdef DEBUGPCI - ErrorF("xf86scanpci: tag = pciFindNext = 0x%lx\n", tag); -#endif + dev = pci_device_next(iter); } /* Restore modified data (in reverse order), and link buses */ @@ -1025,7 +423,9 @@ xf86scanpci(int flags) break; case 1: - case 2: + case 2: { + uint8_t control; + i = PCI_SECONDARY_BUS_EXTRACT(devp->pci_pp_bus_register, devp->tag); if (i > devp->busnum) { if (pciBusInfo[i]) { @@ -1042,9 +442,11 @@ xf86scanpci(int flags) } if (!(devp->pci_bridge_control & PCI_PCI_BRIDGE_MASTER_ABORT_EN)) break; - pciWriteByte(devp->tag, PCI_PCI_BRIDGE_CONTROL_REG, - devp->pci_bridge_control & ~PCI_PCI_BRIDGE_SECONDARY_RESET); + control = devp->pci_bridge_control & ~PCI_PCI_BRIDGE_SECONDARY_RESET; + pci_device_cfg_write_u8(devp->dev, & control, + PCI_PCI_BRIDGE_CONTROL_REG); break; + } default: break; @@ -1065,9 +467,7 @@ xf86scanpci(int flags) devp->businfo = busp; } -#ifndef OLD_FORMAT xf86MsgVerb(X_INFO, 2, "PCI: End of PCI scan\n"); -#endif return pci_devp; } @@ -1086,273 +486,6 @@ xf86GetPciConfigFromTag(PCITAG Tag) return NULL; /* Bad data */ } -CARD32 -pciCheckForBrokenBase(PCITAG Tag,int basereg) -{ - pciWriteLong(Tag, PCI_MAP_REG_START + (basereg << 2), 0xffffffff); - return pciReadLong(Tag, PCI_MAP_REG_START + (basereg << 2)); -} - -#if defined(INCLUDE_XF86_MAP_PCI_MEM) - -_X_EXPORT pointer -xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag, ADDRESS Base, - unsigned long Size) -{ - ADDRESS hostbase = pciBusAddrToHostAddr(Tag, PCI_MEM,Base); - pointer base; - CARD32 save = 0; - - /* - * If there are possible read side-effects, disable memory while - * doing the mapping. - */ - if (Flags & VIDMEM_READSIDEEFFECT) { - save = pciReadLong(Tag, PCI_CMD_STAT_REG); - pciWriteLong(Tag, PCI_CMD_STAT_REG, - save & ~PCI_CMD_MEM_ENABLE); - } - base = xf86MapDomainMemory(ScreenNum, Flags, Tag, hostbase, Size); - if (!base) { - FatalError("xf86MapPciMem: Could not mmap PCI memory " - "[base=0x%lx,hostbase=0x%lx,size=%lx] (%s)\n", - Base, hostbase, Size, strerror(errno)); - } - /* - * If read side-effects, do whatever might be needed to prevent - * unintended reads, then restore PCI_CMD_STAT_REG. - */ - if (Flags & VIDMEM_READSIDEEFFECT) { - xf86MapReadSideEffects(ScreenNum, Flags, base, Size); - pciWriteLong(Tag, PCI_CMD_STAT_REG, save); - } - return((pointer)base); -} - -static int -handlePciBIOS( PCITAG Tag, int basereg, unsigned char * buf, int len ) -{ - CARD32 romsave = 0; - int i; - romBaseSource b_reg; - ADDRESS hostbase; - CARD8 tmp[64]; - int ret = 0; - - romsave = pciReadLong(Tag, PCI_MAP_ROM_REG); - - for (i = ROM_BASE_PRESET; i <= ROM_BASE_FIND; i++) { - memType savebase = 0, newbase, romaddr; - - switch (i) { - case ROM_BASE_PRESET: - /* Does the driver have a preference? */ - if (basereg > ROM_BASE_PRESET && basereg <= ROM_BASE_FIND) - b_reg = basereg; - else - b_reg = ++i; - break; - case ROM_BASE_FIND: - /* - * If we have something that looks like a valid address - * in romsave, it's probably not going to help to try - * to guess a new address and reprogram it. - */ - if (PCIGETROM(romsave)) { - pciWriteLong(Tag, PCI_MAP_ROM_REG, PCI_MAP_ROM_ADDRESS_MASK); - if (romsave != pciReadLong(Tag, PCI_MAP_ROM_REG)) { - pciWriteLong(Tag, PCI_MAP_ROM_REG, romsave); - continue; - } - } - default: - b_reg = i; - } - - if (!(newbase = getValidBIOSBase(Tag, b_reg))) - continue; /* no valid address found */ - - romaddr = PCIGETROM(newbase); - - /* if we use a mem base save it and move it out of the way */ - if (b_reg >= 0 && b_reg <= 5) { - memType emptybase; - savebase = pciReadLong(Tag, PCI_MAP_REG_START+(b_reg<<2)); - xf86MsgVerb(X_INFO,5,"xf86ReadPciBios: modifying membase[%i]" - " for device %i:%i:%i\n", basereg, - (int)PCI_BUS_FROM_TAG(Tag), (int)PCI_DEV_FROM_TAG(Tag), - (int)PCI_FUNC_FROM_TAG(Tag)); - if (!(emptybase = getEmptyPciRange(Tag,b_reg))) { - xf86Msg(X_ERROR,"Cannot find empty range to map base to\n"); - return 0; - } - pciWriteLong(Tag, PCI_MAP_REG_START + (b_reg << 2), - emptybase); - } - /* Set ROM base address and enable ROM address decoding */ - pciWriteLong(Tag, PCI_MAP_ROM_REG, romaddr - | PCI_MAP_ROM_DECODE_ENABLE); - - hostbase = pciBusAddrToHostAddr(Tag, PCI_MEM, PCIGETROM(romaddr)); - - if ((xf86ReadDomainMemory(Tag, hostbase, sizeof(tmp), tmp) != - sizeof(tmp)) || - (tmp[0] != 0x55) || (tmp[1] != 0xaa) || !tmp[2] ) { - /* Restore the base registers if they were changed. */ - pciWriteLong(Tag, PCI_MAP_ROM_REG, romsave); - if (savebase) pciWriteLong(Tag, PCI_MAP_REG_START + (b_reg << 2), - (CARD32) savebase); - - /* No BIOS found: try another address */ - continue; - } - - ret = readPciBios( Tag, tmp, hostbase, buf, len, PCI_BIOS_PC ); - - /* Restore the base register if it was changed. */ - if (savebase) pciWriteLong(Tag, PCI_MAP_REG_START + (b_reg << 2), - (CARD32) savebase); - /* Restore ROM address decoding */ - pciWriteLong(Tag, PCI_MAP_ROM_REG, romsave); - - return ret; - } - /* Restore ROM address decoding */ - pciWriteLong(Tag, PCI_MAP_ROM_REG, romsave); - return 0; -} - - -static int -readPciBios(PCITAG Tag, CARD8* tmp, ADDRESS hostbase, unsigned char * buf, - int len, PciBiosType bios_type ) -{ - unsigned int image_length = 0; - int ret; - - /* We found a PCI BIOS Image. Now we look for the correct type */ - while ((tmp[0] == 0x55) && (tmp[1] == 0xAA)) { - unsigned short data_off = tmp[0x18] | (tmp[0x19] << 8); - unsigned char data[0x18]; - unsigned char type; - - if ((xf86ReadDomainMemory(Tag, hostbase + data_off, sizeof(data), data) - != sizeof(data)) || - (data[0] != 'P') || - (data[1] != 'C') || - (data[2] != 'I') || - (data[3] != 'R')) - break; - - type = data[0x14]; -#ifdef PRINT_PCI - ErrorF("data segment in BIOS: 0x%x, type: 0x%x\n", data_off, type); -#endif - if (type != bios_type) { /* not correct image: find next one */ - const unsigned char indicator = data[0x15]; - unsigned int i_length; - - if (indicator & 0x80) /* last image */ - break; - - i_length = (data[0x10] | (data[0x11] << 8)) << 9; - -#ifdef PRINT_PCI - ErrorF( "data image length: 0x%x, ind: 0x%x\n", i_length, indicator ); -#endif - hostbase += i_length; - if (xf86ReadDomainMemory(Tag, hostbase, sizeof(tmp), tmp) - != sizeof(tmp)) - break; - continue; - } - /* OK, we have a PCI BIOS Image of the correct type */ - - if ( bios_type == PCI_BIOS_PC ) - image_length = tmp[2] << 9; - else - image_length = (data[0x10] | (data[0x11] << 8)) << 9; -#ifdef PRINT_PCI - ErrorF("BIOS length: 0x%x\n", image_length); -#endif - break; - } - - ret = 0; - if (image_length) { - - /* If no length is given return the full length. Beware: Area pointed to - * by Buf must be large enough! - */ - if (len == 0) { - len = image_length; - } - else if ( len > image_length ) { - len = image_length; - xf86MsgVerb( X_INFO, 3, "Truncating PCI BIOS Length to %i\n", - len ); - } - - /* Read BIOS */ - ret = xf86ReadDomainMemory( Tag, hostbase, len, buf ); - } - - return ret; -} - - -static int -HandlePciBios(PCITAG Tag, int basereg, unsigned char * buf, int len) -{ - int n, num; - CARD32 Acc1, Acc2; - PCITAG *pTag; - int i; - - /* fall back to the old code if the OS code fails */ - if (pciOSHandleBIOS) { - n = pciOSHandleBIOS(Tag, basereg, buf, len); - if (n) - return n; - } - - n = handlePciBIOS( Tag, basereg, buf, len ); - if (n) - return n; - - num = pciTestMultiDeviceCard(PCI_BUS_FROM_TAG(Tag), - PCI_DEV_FROM_TAG(Tag), - PCI_FUNC_FROM_TAG(Tag),&pTag); - - if (!num) return 0; - -#define PCI_ENA (PCI_CMD_MEM_ENABLE | PCI_CMD_IO_ENABLE) - Acc1 = pciReadLong(Tag, PCI_CMD_STAT_REG); - pciWriteLong(Tag, PCI_CMD_STAT_REG, (Acc1 & ~PCI_ENA)); - - for (i = 0; i < num; i++) { - Acc2 = pciReadLong(pTag[i], PCI_CMD_STAT_REG); - pciWriteLong(pTag[i], PCI_CMD_STAT_REG, (Acc2 | PCI_ENA)); - - n = handlePciBIOS( pTag[i], 0, buf, len ); - - pciWriteLong(pTag[i], PCI_CMD_STAT_REG, Acc2); - if (n) - break; - } - pciWriteLong(Tag, PCI_CMD_STAT_REG, Acc1); - return n; -} - -_X_EXPORT int -xf86ReadPciBIOS(unsigned long Offset, PCITAG Tag, int basereg, - unsigned char *Buf, int Len) -{ - return HandlePciBios(Tag, basereg, Buf, Len); -} - -#endif /* INCLUDE_XF86_MAP_PCI_MEM */ - #ifdef INCLUDE_XF86_NO_DOMAIN _X_EXPORT int diff --git a/hw/xfree86/os-support/bus/Pci.h b/hw/xfree86/os-support/bus/Pci.h index a91c6b27d..a9958e435 100644 --- a/hw/xfree86/os-support/bus/Pci.h +++ b/hw/xfree86/os-support/bus/Pci.h @@ -422,25 +422,10 @@ void pciCfgMech1Write(PCITAG tag, int offset, CARD32 val); void pciCfgMech1SetBits(PCITAG tag, int offset, CARD32 mask, CARD32 val); CARD32 pciByteSwap(CARD32); -Bool pciMfDev(int, int); ADDRESS pciAddrNOOP(PCITAG tag, PciAddrType type, ADDRESS); -extern void pciSetOSBIOSPtr(int (*bios_fn)(PCITAG Tag, int basereg, unsigned char * buf, int len)); -extern PCITAG (*pciFindFirstFP)(void); -extern PCITAG (*pciFindNextFP)(void); - -extern CARD32 pciDevid; -extern CARD32 pciDevidMask; - extern int pciMaxBusNum; -extern int pciBusNum; -extern int pciDevNum; -extern int pciFuncNum; -extern PCITAG pciDeviceTag; - -extern int xf86MaxPciDevs; - extern pciBusInfo_t *pciBusInfo[]; #endif /* _PCI_H */ diff --git a/hw/xfree86/os-support/bus/axpPci.c b/hw/xfree86/os-support/bus/axpPci.c index 660f008e1..99c451fd5 100644 --- a/hw/xfree86/os-support/bus/axpPci.c +++ b/hw/xfree86/os-support/bus/axpPci.c @@ -229,9 +229,6 @@ axpPciInit() pciNumBuses = bus + 1; } - - pciFindFirstFP = pciGenFindFirst; - pciFindNextFP = pciGenFindNext; } /* diff --git a/hw/xfree86/os-support/bus/freebsdPci.c b/hw/xfree86/os-support/bus/freebsdPci.c index 2868dafa7..bfac398c9 100644 --- a/hw/xfree86/os-support/bus/freebsdPci.c +++ b/hw/xfree86/os-support/bus/freebsdPci.c @@ -125,8 +125,6 @@ freebsdPciInit() pciNumBuses = 1; pciBusInfo[0] = &freebsdPci0; - pciFindFirstFP = pciGenFindFirst; - pciFindNextFP = pciGenFindNext; } static CARD32 diff --git a/hw/xfree86/os-support/bus/ix86Pci.c b/hw/xfree86/os-support/bus/ix86Pci.c index b091ec425..80f1bb32a 100644 --- a/hw/xfree86/os-support/bus/ix86Pci.c +++ b/hw/xfree86/os-support/bus/ix86Pci.c @@ -688,8 +688,6 @@ ix86PciInit() /* Initialize pciBusInfo[] array and function pointers */ pciNumBuses = 1; pciBusInfo[0] = &ix86Pci0; - pciFindFirstFP = pciGenFindFirst; - pciFindNextFP = pciGenFindNext; /* Make sure that there is a PCI bus present. */ ix86PciSelectCfgmech(); diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c index 0714c9cea..84ec8ad82 100644 --- a/hw/xfree86/os-support/bus/linuxPci.c +++ b/hw/xfree86/os-support/bus/linuxPci.c @@ -73,7 +73,6 @@ static CARD8 linuxPciCfgReadByte(PCITAG tag, int off); static void linuxPciCfgWriteByte(PCITAG tag, int off, CARD8 val); static CARD16 linuxPciCfgReadWord(PCITAG tag, int off); static void linuxPciCfgWriteWord(PCITAG tag, int off, CARD16 val); -static int linuxPciHandleBIOS(PCITAG Tag, int basereg, unsigned char *buf, int len); static pciBusFuncs_t linuxFuncs0 = { /* pciReadLong */ linuxPciCfgRead, @@ -123,10 +122,6 @@ linuxPciInit() } pciNumBuses = 1; pciBusInfo[0] = &linuxPci0; - pciFindFirstFP = pciGenFindFirst; - pciFindNextFP = pciGenFindNext; - pciSetOSBIOSPtr(linuxPciHandleBIOS); - xf86MaxPciDevs = lnxPciInit(); } static int @@ -458,9 +453,9 @@ linuxGetIOSize(PCITAG Tag) continue; if (pPCI->pci_vendor < pciControllerSizes[i].vendor) break; - if (pPCI->pci_device > pciControllerSizes[i].device) + if (pPCI->_pci_device > pciControllerSizes[i].device) continue; - if (pPCI->pci_device < pciControllerSizes[i].device) + if (pPCI->_pci_device < pciControllerSizes[i].device) break; return pciControllerSizes[i].io_size; } @@ -486,9 +481,9 @@ linuxGetSizes(PCITAG Tag, unsigned long *io_size, unsigned long *mem_size) continue; if (pPCI->pci_vendor < pciControllerSizes[i].vendor) break; - if (pPCI->pci_device > pciControllerSizes[i].device) + if (pPCI->_pci_device > pciControllerSizes[i].device) continue; - if (pPCI->pci_device < pciControllerSizes[i].device) + if (pPCI->_pci_device < pciControllerSizes[i].device) break; *io_size = pciControllerSizes[i].io_size; *mem_size = pciControllerSizes[i].mem_size; @@ -907,44 +902,3 @@ xf86AccResFromOS(resPtr pRes) } #endif /* !INCLUDE_XF86_NO_DOMAIN */ - -int linuxPciHandleBIOS(PCITAG Tag, int basereg, unsigned char *buf, int len) -{ - unsigned int dom, bus, dev, func; - unsigned int fd; - char file[256]; - struct stat st; - int ret; - int sofar = 0; - - dom = PCI_DOM_FROM_TAG(Tag); - bus = PCI_BUS_FROM_TAG(Tag); - dev = PCI_DEV_FROM_TAG(Tag); - func = PCI_FUNC_FROM_TAG(Tag); - sprintf(file, "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/rom", - dom, bus, dev, func); - - if (stat(file, &st) == 0) - { - if ((fd = open(file, O_RDWR))) - basereg = 0x0; - - /* enable the ROM first */ - write(fd, "1", 2); - lseek(fd, 0, SEEK_SET); - do { - /* copy the ROM until we hit Len, EOF or read error */ - ret = read(fd, buf+sofar, len-sofar); - if (ret <= 0) - break; - sofar += ret; - } while (sofar < len); - - write(fd, "0", 2); - close(fd); - if (sofar < len) - xf86MsgVerb(X_INFO, 3, "Attempted to read BIOS %dKB from %s: got %dKB\n", len/1024, file, sofar/1024); - return sofar; - } - return 0; -} diff --git a/hw/xfree86/os-support/bus/netbsdPci.c b/hw/xfree86/os-support/bus/netbsdPci.c index 7dbbfdec7..df116c429 100644 --- a/hw/xfree86/os-support/bus/netbsdPci.c +++ b/hw/xfree86/os-support/bus/netbsdPci.c @@ -80,8 +80,6 @@ netbsdPciInit() pciNumBuses = 1; pciBusInfo[0] = &netbsdPci0; - pciFindFirstFP = pciGenFindFirst; - pciFindNextFP = pciGenFindNext; /* use businfo to get the number of devs */ if (ioctl(devpci, PCI_IOC_BUSINFO, &pci_businfo) != 0) FatalError("netbsdPciInit: not a PCI bus device"); diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h index 69254ce8c..a79d5f58e 100644 --- a/hw/xfree86/os-support/bus/xf86Pci.h +++ b/hw/xfree86/os-support/bus/xf86Pci.h @@ -651,7 +651,7 @@ typedef union pci_cfg_spc { * Data structure returned by xf86scanpci including contents of * PCI config space header */ -typedef struct pci_device { +typedef struct { PCITAG tag; int busnum; int devnum; @@ -661,6 +661,7 @@ typedef struct pci_device { Bool minBasesize; pointer businfo; /* pointer to secondary's bus info structure */ Bool fakeDevice; /* Device added by system chipset support */ + struct pci_device * dev; } pciDevice, *pciConfigPtr; typedef enum { @@ -676,7 +677,7 @@ typedef enum { #define pci_device_vendor cfgspc.regs.dv_id.device_vendor #define pci_vendor cfgspc.regs.dv_id.dv.vendor -#define pci_device cfgspc.regs.dv_id.dv.device +#define _pci_device cfgspc.regs.dv_id.dv.device #define pci_status_command cfgspc.regs.stat_cmd.status_command #define pci_command cfgspc.regs.stat_cmd.sc.command #define pci_status cfgspc.regs.stat_cmd.sc.status @@ -753,26 +754,10 @@ typedef enum { } PciBiosType; /* Public PCI access functions */ -void pciInit(void); -PCITAG pciFindFirst(CARD32 id, CARD32 mask); -PCITAG pciFindNext(void); -CARD32 pciReadLong(PCITAG tag, int offset); -CARD16 pciReadWord(PCITAG tag, int offset); -CARD8 pciReadByte(PCITAG tag, int offset); -void pciWriteLong(PCITAG tag, int offset, CARD32 val); -void pciWriteWord(PCITAG tag, int offset, CARD16 val); -void pciWriteByte(PCITAG tag, int offset, CARD8 val); -void pciSetBitsLong(PCITAG tag, int offset, CARD32 mask, CARD32 val); -void pciSetBitsByte(PCITAG tag, int offset, CARD8 mask, CARD8 val); ADDRESS pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr); ADDRESS pciHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr); PCITAG pciTag(int busnum, int devnum, int funcnum); int pciGetBaseSize(PCITAG tag, int indx, Bool destructive, Bool *min); -CARD32 pciCheckForBrokenBase(PCITAG tag,int basereg); -pointer xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag, - ADDRESS Base, unsigned long Size); -int xf86ReadPciBIOS(unsigned long Offset, PCITAG Tag, int basereg, - unsigned char *Buf, int Len); pciConfigPtr *xf86scanpci(int flags); pciConfigPtr xf86GetPciConfigFromTag(PCITAG Tag); diff --git a/hw/xfree86/os-support/bus/zx1PCI.c b/hw/xfree86/os-support/bus/zx1PCI.c index b6a33d27c..542bcc67b 100644 --- a/hw/xfree86/os-support/bus/zx1PCI.c +++ b/hw/xfree86/os-support/bus/zx1PCI.c @@ -1074,13 +1074,13 @@ xf86PostScanZX1(void) xf86MsgVerb(X_INFO, 2, "PCI: BusID 0x%.2x,0x%02x,0x%1x " "ID 0x%04x,0x%04x Rev 0x%02x Class 0x%02x,0x%02x\n", pPCI->busnum, pPCI->devnum, pPCI->funcnum, - pPCI->pci_vendor, pPCI->pci_device, pPCI->pci_rev_id, + pPCI->pci_vendor, pPCI->_pci_device, pPCI->pci_rev_id, pPCI->pci_base_class, pPCI->pci_sub_class); #else xf86MsgVerb(X_INFO, 2, "PCI: %.2x:%02x:%1x: chip %04x,%04x" " card %04x,%04x rev %02x class %02x,%02x,%02x hdr %02x\n", pPCI->busnum, pPCI->devnum, pPCI->funcnum, - pPCI->pci_vendor, pPCI->pci_device, + pPCI->pci_vendor, pPCI->_pci_device, pPCI->pci_subsys_vendor, pPCI->pci_subsys_card, pPCI->pci_rev_id, pPCI->pci_base_class, pPCI->pci_sub_class, pPCI->pci_prog_if, @@ -1123,13 +1123,13 @@ xf86PostScanZX1(void) xf86MsgVerb(X_INFO, 2, "PCI: BusID 0x%.2x,0x%02x,0x%1x " "ID 0x%04x,0x%04x Rev 0x%02x Class 0x%02x,0x%02x\n", pPCI->busnum, pPCI->devnum, pPCI->funcnum, - pPCI->pci_vendor, pPCI->pci_device, pPCI->pci_rev_id, + pPCI->pci_vendor, pPCI->_pci_device, pPCI->pci_rev_id, pPCI->pci_base_class, pPCI->pci_sub_class); #else xf86MsgVerb(X_INFO, 2, "PCI: %.2x:%02x:%1x: chip %04x,%04x" " card %04x,%04x rev %02x class %02x,%02x,%02x hdr %02x\n", pPCI->busnum, pPCI->devnum, pPCI->funcnum, - pPCI->pci_vendor, pPCI->pci_device, + pPCI->pci_vendor, pPCI->_pci_device, pPCI->pci_subsys_vendor, pPCI->pci_subsys_card, pPCI->pci_rev_id, pPCI->pci_base_class, pPCI->pci_sub_class, pPCI->pci_prog_if, diff --git a/hw/xfree86/utils/Makefile.am b/hw/xfree86/utils/Makefile.am index 38f90b4ae..e3e7a6177 100644 --- a/hw/xfree86/utils/Makefile.am +++ b/hw/xfree86/utils/Makefile.am @@ -3,7 +3,5 @@ SUBDIRS = \ cvt \ ioport \ kbd_mode \ - pcitweak \ - scanpci \ xorgcfg \ xorgconfig diff --git a/hw/xfree86/utils/xorgcfg/loadmod.c b/hw/xfree86/utils/xorgcfg/loadmod.c index 8f970cb72..950a17624 100644 --- a/hw/xfree86/utils/xorgcfg/loadmod.c +++ b/hw/xfree86/utils/xorgcfg/loadmod.c @@ -70,15 +70,13 @@ void xf86Msg(int, const char*, ...); void xf86MsgVerb(int, int, const char*, ...); void xf86PrintChipsets(const char*, const char*, SymTabPtr); void xf86ErrorFVerb(int verb, const char *format, ...); -pciVideoPtr *xf86GetPciVideoInfo(void); int xf86MatchDevice(const char*, GDevPtr**); int xf86MatchPciInstances(const char*, int, SymTabPtr, PciChipsets*, GDevPtr*, int, DriverPtr,int**); int xf86MatchIsaInstances(const char*, SymTabPtr, pointer*, DriverPtr, pointer, GDevPtr*, int, int**); void *xf86LoadDrvSubModule(DriverPtr drv, const char*); void xf86DrvMsg(int, int, const char*, ...); -pciConfigPtr *xf86GetPciConfigInfo(void); Bool xf86IsPrimaryPci(pcVideoPtr*); -Bool xf86CheckPciSlot(int bus, int device, int func); +Bool xf86CheckPciSlot( const struct pci_device * ); #endif extern char *loaderPath, **loaderList, **ploaderList; @@ -307,14 +305,12 @@ LOOKUP xfree86LookupTab[] = { SYMFUNC(ErrorF) SYMFUNC(xf86PrintChipsets) SYMFUNC(xf86ErrorFVerb) - SYMFUNC(xf86GetPciVideoInfo) SYMFUNC(xf86MatchDevice) SYMFUNC(xf86MatchPciInstances) SYMFUNC(xf86MatchIsaInstances) SYMFUNC(Xfree) SYMFUNC(xf86LoadDrvSubModule) SYMFUNC(xf86DrvMsg) - SYMFUNC(xf86GetPciConfigInfo) SYMFUNC(xf86IsPrimaryPci) SYMFUNC(xf86CheckPciSlot) SYMFUNC(XNFalloc) @@ -608,17 +604,6 @@ xf86PrintChipsets(const char *name, const char *msg, SymTabPtr chipsets) chips = chipsets; } -_X_EXPORT pciVideoPtr * -xf86GetPciVideoInfo(void) -{ - static pciVideoRec pci_video; - static pciVideoPtr pci_video_ptr[2] = { &pci_video }; - - memset(&pci_video, 0, sizeof(pciVideoRec)); - - return (pci_video_ptr); -} - _X_EXPORT int xf86MatchDevice(const char *name, GDevPtr **gdev) { @@ -662,12 +647,6 @@ xf86LoadDrvSubModule(DriverPtr drv, const char *name) return (ret); } -_X_EXPORT pciConfigPtr * -xf86GetPciConfigInfo(void) -{ - return (NULL); -} - _X_EXPORT Bool xf86IsPrimaryPci(pciVideoPtr pPci) { @@ -675,8 +654,9 @@ xf86IsPrimaryPci(pciVideoPtr pPci) } _X_EXPORT Bool -xf86CheckPciSlot(int bus, int device, int func) +xf86CheckPciSlot( const struct pci_device * d ) { + (void) d; return (False); } #endif diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c index 6df7dee18..ec62d637f 100644 --- a/hw/xfree86/vgahw/vgaHW.c +++ b/hw/xfree86/vgahw/vgaHW.c @@ -31,6 +31,8 @@ #include "xf86cmap.h" +#include "Pci.h" + #ifndef SAVE_FONT1 #define SAVE_FONT1 1 #endif @@ -1637,7 +1639,7 @@ vgaHWGetHWRec(ScrnInfoPtr scrp) { vgaRegPtr regp; vgaHWPtr hwp; - pciVideoPtr pvp; + struct pci_device * pvp; int i; /* @@ -1724,7 +1726,8 @@ vgaHWGetHWRec(ScrnInfoPtr scrp) hwp->PIOOffset = scrp->domainIOBase; if ((pvp = xf86GetPciInfoForEntity(scrp->entityList[0]))) - hwp->Tag = pciTag(pvp->bus, pvp->device, pvp->func); + hwp->Tag = pciTag( PCI_MAKE_BUS( pvp->domain, pvp->bus ), + pvp->dev, pvp->func ); return TRUE; } |