From 0c6c41b7b772f75cffbf189c8a84fa04b089fa71 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 27 Feb 2008 13:38:03 +1000 Subject: pciaccess conversion --- configure.ac | 14 ++++++ src/tga.h | 3 ++ src/tga_driver.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/tga_pcirename.h | 122 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 src/tga_pcirename.h diff --git a/configure.ac b/configure.ac index 2588294..b71fc9c 100644 --- a/configure.ac +++ b/configure.ac @@ -59,6 +59,20 @@ PKG_CHECK_MODULES(XORG, [xorg-server >= 1.0.99.901 xproto fontsproto $REQUIRED_M sdkdir=$(pkg-config --variable=sdkdir xorg-server) # Checks for libraries. +SAVE_CPPFLAGS="$CPPFLAGS" +CPPFLAGS="$CPPFLAGS $XORG_CFLAGS" +AC_CHECK_DECL(XSERVER_LIBPCIACCESS, + [XSERVER_LIBPCIACCESS=yes],[XSERVER_LIBPCIACCESS=no], + [#include "xorg-server.h"]) +AC_CHECK_HEADER(xf1bpp.h,[AC_DEFINE(HAVE_XF1BPP, 1, [Have 1bpp support])],[]) +AC_CHECK_HEADER(xf4bpp.h,[AC_DEFINE(HAVE_XF4BPP, 1, [Have 4bpp support])],[]) +CPPFLAGS="$SAVE_CPPFLAGS" + +if test "x$XSERVER_LIBPCIACCESS" = xyes; then + PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.8.0]) + XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS" +fi +AM_CONDITIONAL(XSERVER_LIBPCIACCESS, test "x$XSERVER_LIBPCIACCESS" = xyes) # Checks for header files. AC_HEADER_STDC diff --git a/src/tga.h b/src/tga.h index 7246511..59f9d1a 100644 --- a/src/tga.h +++ b/src/tga.h @@ -26,6 +26,7 @@ #ifndef _TGA_H_ #define _TGA_H_ +#include "tga_pcirename.h" #include "xaa.h" #include "xf86RamDac.h" @@ -38,7 +39,9 @@ typedef struct { typedef struct { pciVideoPtr PciInfo; +#ifndef XSERVER_LIBPCIACCESS PCITAG PciTag; +#endif int Chipset; RamDacHelperRecPtr RamDac; int ChipRev; diff --git a/src/tga_driver.c b/src/tga_driver.c index 3722a9a..acdf16b 100644 --- a/src/tga_driver.c +++ b/src/tga_driver.c @@ -371,6 +371,7 @@ TGAProbe(DriverPtr drv, int flags) * All of the cards this driver supports are PCI, so the "probing" just * amounts to checking the PCI data that the server has already collected. */ +#ifndef XSERVER_LIBPCIACCESS if (xf86GetPciVideoInfo() == NULL) { /* * We won't let anything in the config file override finding no @@ -378,6 +379,7 @@ TGAProbe(DriverPtr drv, int flags) */ return FALSE; } +#endif numUsed = xf86MatchPciInstances(TGA_NAME, PCI_VENDOR_DIGITAL, TGAChipsets, TGAPciChipsets, devSections, numDevSections, @@ -512,9 +514,11 @@ TGAPreInit(ScrnInfoPtr pScrn, int flags) if (pTga->pEnt->location.type == BUS_PCI) { pciPtr = xf86GetPciInfoForEntity(pTga->pEnt->index); pTga->PciInfo = pciPtr; +#ifndef XSERVER_LIBPCIACCESS pTga->PciTag = pciTag(pTga->PciInfo->bus, pTga->PciInfo->device, pTga->PciInfo->func); +#endif } else return FALSE; @@ -538,8 +542,10 @@ TGAPreInit(ScrnInfoPtr pScrn, int flags) from = X_PROBED; xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n", pScrn->chipset); +#ifndef XSERVER_LIBPCIACCESS pTga->PciTag = pciTag(pTga->PciInfo->bus, pTga->PciInfo->device, pTga->PciInfo->func); +#endif @@ -672,7 +678,7 @@ TGAPreInit(ScrnInfoPtr pScrn, int flags) pTga->CardAddress = pTga->pEnt->device->MemBase; from = X_CONFIG; } else { - pTga->CardAddress = pTga->PciInfo->memBase[0] & 0xFFC00000;/*??*/ + pTga->CardAddress = PCI_REGION_BASE(pTga->PciInfo, 0, REGION_MEM) & 0xFFC00000;/*??*/ } pTga->FbAddress = pTga->CardAddress; @@ -708,17 +714,53 @@ TGAPreInit(ScrnInfoPtr pScrn, int flags) switch (pTga->Chipset) { case PCI_CHIP_TGA2: +#ifndef XSERVER_LIBPCIACCESS Base = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO_32BIT, pTga->PciTag, pTga->IOAddress, 0x1000); + +#else + { + void** result = (void**)&Base; + int err = pci_device_map_range(pTga->PciInfo, + pTga->IOAddress, + 0x1000, + PCI_DEV_MAP_FLAG_WRITABLE, + result); + if (err) + return FALSE; + } +#endif pTga->CardType = (*(unsigned int *)((char *)Base+TGA_REVISION_REG) >> 21) & 0x3; pTga->CardType ^= (pTga->CardType == 1) ? 0 : 3; + +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, Base, 0x1000); +#else + pci_device_unmap_range(pTga->PciInfo, Base, 0x1000); +#endif break; case PCI_CHIP_DEC21030: +#ifndef XSERVER_LIBPCIACCESS Base = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO_32BIT, pTga->PciTag, pTga->FbAddress, 4); +#else + { + void** result = (void**)&Base; + int err = pci_device_map_range(pTga->PciInfo, + pTga->FbAddress, + 0x4, + PCI_DEV_MAP_FLAG_WRITABLE, + result); + if (err) + return FALSE; + } +#endif pTga->CardType = (*(unsigned int *)Base >> 12) & 0xf; +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, Base, 4); +#else + pci_device_unmap_range(pTga->PciInfo, Base, 4); +#endif break; } } @@ -1008,34 +1050,87 @@ TGAMapMem(ScrnInfoPtr pScrn) /* TGA doesn't need a sparse memory mapping, because all register accesses are doublewords */ - + +#ifndef XSERVER_LIBPCIACCESS pTga->IOBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO_32BIT, pTga->PciTag, pTga->IOAddress, 0x100000); +#else + { + void** result = (void**)&pTga->IOBase; + int err = pci_device_map_range(pTga->PciInfo, + pTga->IOAddress, + 0x100000, + PCI_DEV_MAP_FLAG_WRITABLE, + result); + if (err) + return FALSE; + } +#endif if (pTga->IOBase == NULL) return FALSE; +#ifndef XSERVER_LIBPCIACCESS pTga->FbBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER, pTga->PciTag, (unsigned long)pTga->FbAddress, pTga->FbMapSize); +#else + { + void** result = (void**)&pTga->FbBase; + int err = pci_device_map_range(pTga->PciInfo, + pTga->FbAddress, + pTga->FbMapSize, + PCI_DEV_MAP_FLAG_WRITABLE | + PCI_DEV_MAP_FLAG_WRITE_COMBINE, + result); + if (err) + return FALSE; + } +#endif if (pTga->FbBase == NULL) return FALSE; if (pTga->Chipset == PCI_CHIP_DEC21030) return TRUE; +#ifndef XSERVER_LIBPCIACCESS pTga->ClkBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO_32BIT, pTga->PciTag, (unsigned long)pTga->CardAddress + TGA2_CLOCK_OFFSET, 0x10000); +#else + { + void** result = (void**)&pTga->ClkBase; + int err = pci_device_map_range(pTga->PciInfo, + pTga->CardAddress + TGA2_CLOCK_OFFSET, + 0x10000, + PCI_DEV_MAP_FLAG_WRITABLE, + result); + if (err) + return FALSE; + } +#endif if (pTga->ClkBase == NULL) return FALSE; +#ifndef XSERVER_LIBPCIACCESS pTga->DACBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO_32BIT, pTga->PciTag, (unsigned long)pTga->CardAddress + TGA2_RAMDAC_OFFSET, 0x10000); +#else + { + void** result = (void**)&pTga->DACBase; + int err = pci_device_map_range(pTga->PciInfo, + pTga->CardAddress + TGA2_RAMDAC_OFFSET, + 0x10000, + PCI_DEV_MAP_FLAG_WRITABLE, + result); + if (err) + return FALSE; + } +#endif if (pTga->DACBase == NULL) return FALSE; @@ -1053,10 +1148,25 @@ TGAMapMem(ScrnInfoPtr pScrn) * framebuffer memory in front of the normal mmap to prevent * SEGVs from happening. */ +#ifndef XSERVER_LIBPCIACCESS pTga->HACKBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER, pTga->PciTag, (unsigned long)pTga->FbAddress - getpagesize(), getpagesize()); +#else + { + void** result = (void**)&pTga->DACBase; + int err = pci_device_map_range(pTga->PciInfo, + pTga->FbAddress - getpagesize(), + getpagesize(), + PCI_DEV_MAP_FLAG_WRITABLE | + PCI_DEV_MAP_FLAG_WRITE_COMBINE, + result); + if (err) + return FALSE; + } +#endif + if (pTga->HACKBase == NULL) return FALSE; @@ -1075,22 +1185,42 @@ TGAUnmapMem(ScrnInfoPtr pScrn) pTga = TGAPTR(pScrn); +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pTga->IOBase, 0x100000); +#else + pci_device_unmap_range(pTga->PciInfo, pTga->IOBase, 0x100000); +#endif pTga->IOBase = NULL; +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pTga->FbBase, pTga->FbMapSize); +#else + pci_device_unmap_range(pTga->PciInfo, pTga->FbBase, pTga->FbMapSize); +#endif pTga->FbBase = NULL; if (pTga->Chipset == PCI_CHIP_DEC21030) return TRUE; +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pTga->ClkBase, 0x10000); +#else + pci_device_unmap_range(pTga->PciInfo, pTga->ClkBase, 0x10000); +#endif pTga->ClkBase = NULL; +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pTga->DACBase, 0x10000); +#else + pci_device_unmap_range(pTga->PciInfo, pTga->DACBase, 0x10000); +#endif pTga->DACBase = NULL; +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pTga->HACKBase, getpagesize()); +#else + pci_device_unmap_range(pTga->PciInfo, pTga->HACKBase, getpagesize()); +#endif pTga->HACKBase = NULL; return TRUE; diff --git a/src/tga_pcirename.h b/src/tga_pcirename.h new file mode 100644 index 0000000..f0f5cf8 --- /dev/null +++ b/src/tga_pcirename.h @@ -0,0 +1,122 @@ +/* + * Copyright 2007 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Macros for porting drivers from legacy xfree86 PCI code to the pciaccess + * library. The main purpose being to facilitate source code compatibility. + */ + +#ifndef CIRPCIRENAME_H +#define CIRPCIRENAME_H + +enum region_type { + REGION_MEM, + REGION_IO +}; + +#ifndef XSERVER_LIBPCIACCESS + +/* pciVideoPtr */ +#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor) +#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->chipType) +#define PCI_DEV_REVISION(_pcidev) ((_pcidev)->chipRev) + +#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subsysVendor) +#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subsysCard) + +#define PCI_DEV_TAG(_pcidev) pciTag((_pcidev)->bus, \ + (_pcidev)->device, \ + (_pcidev)->func) +#define PCI_DEV_BUS(_pcidev) ((_pcidev)->bus) +#define PCI_DEV_DEV(_pcidev) ((_pcidev)->device) +#define PCI_DEV_FUNC(_pcidev) ((_pcidev)->func) + +/* pciConfigPtr */ +#define PCI_CFG_TAG(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->tag) +#define PCI_CFG_BUS(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->busnum) +#define PCI_CFG_DEV(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->devnum) +#define PCI_CFG_FUNC(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->funcnum) + +/* region addr: xfree86 uses different fields for memory regions and I/O ports */ +#define PCI_REGION_BASE(_pcidev, _b, _type) \ + (((_type) == REGION_MEM) ? (_pcidev)->memBase[(_b)] \ + : (_pcidev)->ioBase[(_b)]) + +/* region size: xfree86 uses the log2 of the region size, + * but with zero meaning no region, not size of one XXX */ +#define PCI_REGION_SIZE(_pcidev, _b) \ + (((_pcidev)->size[(_b)] > 0) ? (1 << (_pcidev)->size[(_b)]) : 0) + +/* read/write PCI configuration space */ +#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \ + *(_value_ptr) = pciReadByte(PCI_CFG_TAG(_pcidev), (_offset)) + +#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \ + *(_value_ptr) = pciReadLong(PCI_CFG_TAG(_pcidev), (_offset)) + +#define PCI_WRITE_LONG(_pcidev, _value, _offset) \ + pciWriteLong(PCI_CFG_TAG(_pcidev), (_offset), (_value)) + +#else /* XSERVER_LIBPCIACCESS */ + +typedef struct pci_device *pciVideoPtr; + +#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor_id) +#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->device_id) +#define PCI_DEV_REVISION(_pcidev) ((_pcidev)->revision) + +#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subvendor_id) +#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subdevice_id) + +/* pci-rework functions take a 'pci_device' parameter instead of a tag */ +#define PCI_DEV_TAG(_pcidev) (_pcidev) + +/* PCI_DEV macros, typically used in printf's, add domain ? XXX */ +#define PCI_DEV_BUS(_pcidev) ((_pcidev)->bus) +#define PCI_DEV_DEV(_pcidev) ((_pcidev)->dev) +#define PCI_DEV_FUNC(_pcidev) ((_pcidev)->func) + +/* pci-rework functions take a 'pci_device' parameter instead of a tag */ +#define PCI_CFG_TAG(_pcidev) (_pcidev) + +/* PCI_CFG macros, typically used in DRI init, contain the domain */ +#define PCI_CFG_BUS(_pcidev) (((_pcidev)->domain << 8) | \ + (_pcidev)->bus) +#define PCI_CFG_DEV(_pcidev) ((_pcidev)->dev) +#define PCI_CFG_FUNC(_pcidev) ((_pcidev)->func) + +#define PCI_REGION_BASE(_pcidev, _b, _type) ((_pcidev)->regions[(_b)].base_addr) +#define PCI_REGION_SIZE(_pcidev, _b) ((_pcidev)->regions[(_b)].size) + +#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \ + pci_device_cfg_read_u8((_pcidev), (_value_ptr), (_offset)) + +#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \ + pci_device_cfg_read_u32((_pcidev), (_value_ptr), (_offset)) + +#define PCI_WRITE_LONG(_pcidev, _value, _offset) \ + pci_device_cfg_write_u32((_pcidev), (_value), (_offset)) + +#endif /* XSERVER_LIBPCIACCESS */ + +#endif /* CIRPCIRENAME_H */ -- cgit v1.2.3