diff options
author | Dave Airlie <airlied@redhat.com> | 2008-03-10 12:08:10 +1000 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2008-03-10 12:08:10 +1000 |
commit | 8c31b2e40951c62d362e9a95d8a7b29018626ef2 (patch) | |
tree | 8fa53c9d092bfe9f8ba922175a4e45fc5852caf1 /src | |
parent | 870eb9fe825917b2bec48ec2b95ad794e585bf09 (diff) |
i740: pciaccess conversion
Diffstat (limited to 'src')
-rw-r--r-- | src/i740.h | 4 | ||||
-rw-r--r-- | src/i740_driver.c | 50 | ||||
-rw-r--r-- | src/i740_pcirename.h | 122 |
3 files changed, 171 insertions, 5 deletions
@@ -36,6 +36,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef _I740_H_ #define _I740_H_ +#include "i740_pcirename.h" + #include "xf86PciInfo.h" #include "xf86Pci.h" @@ -99,7 +101,9 @@ typedef struct _I740Rec { unsigned long MMIOAddr; EntityInfoPtr pEnt; pciVideoPtr PciInfo; +#ifndef XSERVER_LIBPCIACCESS PCITAG PciTag; +#endif int HasSGRAM; I740RegRec SavedReg; I740RegRec ModeReg; diff --git a/src/i740_driver.c b/src/i740_driver.c index 21651a2..ee25967 100644 --- a/src/i740_driver.c +++ b/src/i740_driver.c @@ -508,8 +508,10 @@ I740PreInit(ScrnInfoPtr pScrn, int flags) { if (!vgaHWGetHWRec(pScrn)) return FALSE; pI740->PciInfo = xf86GetPciInfoForEntity(pI740->pEnt->index); +#ifndef XSERVER_LIBPCIACCESS pI740->PciTag = pciTag(pI740->PciInfo->bus, pI740->PciInfo->device, pI740->PciInfo->func); +#endif if (xf86RegisterResources(pI740->pEnt->index, 0, ResNone)) return FALSE; @@ -598,7 +600,7 @@ I740PreInit(ScrnInfoPtr pScrn, int flags) { pI740->pEnt->device->chipID); } else { from = X_PROBED; - pScrn->chipset = (char *)xf86TokenToString(I740Chipsets, pI740->PciInfo->chipType); + pScrn->chipset = (char *)xf86TokenToString(I740Chipsets, PCI_DEV_DEVIE_ID(pI740->PciInfo)); } if (pI740->pEnt->device->chipRev >= 0) { xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n", @@ -611,8 +613,8 @@ I740PreInit(ScrnInfoPtr pScrn, int flags) { pI740->LinearAddr = pI740->pEnt->device->MemBase; from = X_CONFIG; } else { - if (pI740->PciInfo->memBase[1] != 0) { - pI740->LinearAddr = pI740->PciInfo->memBase[0]&0xFF000000; + if (PCI_REGION_BASE(pI740->PciInfo, 0, REGION_MEM) != 0) { + pI740->LinearAddr = PCI_REGION_BASE(pI740->PciInfo, 0, REGION_MEM)&0xFF000000; from = X_PROBED; } else { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, @@ -628,8 +630,8 @@ I740PreInit(ScrnInfoPtr pScrn, int flags) { pI740->MMIOAddr = pI740->pEnt->device->IOBase; from = X_CONFIG; } else { - if (pI740->PciInfo->memBase[1]) { - pI740->MMIOAddr = pI740->PciInfo->memBase[1]&0xFFF80000; + if (PCI_REGION_BASE(pI740->PciInfo, 1, REGION_MEM)) { + pI740->MMIOAddr = PCI_REGION_BASE(pI740->PciInfo, 1, REGION_MEM)&0xFFF80000; from = X_PROBED; } else { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, @@ -871,18 +873,48 @@ static Bool I740MapMem(ScrnInfoPtr pScrn) pI740 = I740PTR(pScrn); +#ifndef XSERVER_LIBPCIACCESS mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT; pI740->MMIOBase = xf86MapPciMem(pScrn->scrnIndex, mmioFlags, pI740->PciTag, pI740->MMIOAddr, 0x80000); +#else + { + void** result = (void**)&pI740->MMIOBase; + int err = pci_device_map_range(pI740->PciInfo, + pI740->MMIOAddr, + 0x80000, + PCI_DEV_MAP_FLAG_WRITABLE, + result); + + if (err) + return FALSE; + } + +#endif if (!pI740->MMIOBase) return FALSE; +#ifndef XSERVER_LIBPCIACCESS pI740->FbBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER, pI740->PciTag, pI740->LinearAddr, pI740->FbMapSize); +#else + { + void** result = (void**)&pI740->FbBase; + int err = pci_device_map_range(pI740->PciInfo, + pI740->LinearAddr, + pI740->FbMapSize, + PCI_DEV_MAP_FLAG_WRITABLE | + PCI_DEV_MAP_FLAG_WRITE_COMBINE, + result); + + if (err) + return FALSE; + } +#endif if (!pI740->FbBase) return FALSE; return TRUE; @@ -894,10 +926,18 @@ static Bool I740UnmapMem(ScrnInfoPtr pScrn) pI740 = I740PTR(pScrn); +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pI740->MMIOBase, 0x80000); +#else + pci_device_unmap_range(pI740->PciInfo, pI740->MMIOBase, 0x80000); +#endif pI740->MMIOBase=0; +#ifndef XSERVER_LIBPCIACCESS xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pI740->FbBase, pI740->FbMapSize); +#else + pci_device_unmap_range(pI740->PciInfo, pI740->FbBase, pI740->FbMapSize); +#endif pI740->FbBase = 0; return TRUE; } diff --git a/src/i740_pcirename.h b/src/i740_pcirename.h new file mode 100644 index 0000000..cbd3dcf --- /dev/null +++ b/src/i740_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 ASTPCIRENAME_H +#define ASTPCIRENAME_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 */ |