atipcirename.h revision cd241713
1/* 2 * Copyright 2007 George Sapountzis 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 */ 23 24/** 25 * Macros for porting drivers from legacy xfree86 PCI code to the pciaccess 26 * library. The main purpose being to facilitate source code compatibility. 27 */ 28 29#ifndef ATIPCIRENAME_H 30#define ATIPCIRENAME_H 31 32enum region_type { 33 REGION_MEM, 34 REGION_IO 35}; 36 37#include <stdint.h> 38#include "xf86Module.h" 39 40#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 12 41 42#if (defined(__alpha__) || defined(__ia64__)) && defined (linux) 43#define PCI_DOM_MASK 0x01fful 44#else 45#define PCI_DOM_MASK 0x0ffu 46#endif 47 48#ifndef PCI_DOM_MASK 49# define PCI_DOM_MASK 0x0ffu 50#endif 51#define PCI_DOMBUS_MASK (((PCI_DOM_MASK) << 8) | 0x0ffu) 52 53static inline uint32_t 54pciTag(int busnum, int devnum, int funcnum) 55{ 56 uint32_t tag; 57 tag = (busnum & (PCI_DOMBUS_MASK)) << 16; 58 tag |= (devnum & 0x00001fu) << 11; 59 tag |= (funcnum & 0x000007u) << 8; 60 61 return tag; 62} 63#endif /* GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 12 */ 64 65#ifndef XSERVER_LIBPCIACCESS 66 67/* pciVideoPtr */ 68#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor) 69#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->chipType) 70#define PCI_DEV_REVISION(_pcidev) ((_pcidev)->chipRev) 71 72#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subsysVendor) 73#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subsysCard) 74 75#define PCI_DEV_TAG(_pcidev) pciTag((_pcidev)->bus, \ 76 (_pcidev)->device, \ 77 (_pcidev)->func) 78#define PCI_DEV_BUS(_pcidev) ((_pcidev)->bus) 79#define PCI_DEV_DEV(_pcidev) ((_pcidev)->device) 80#define PCI_DEV_FUNC(_pcidev) ((_pcidev)->func) 81 82/* pciConfigPtr */ 83#define PCI_CFG_TAG(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->tag) 84#define PCI_CFG_BUS(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->busnum) 85#define PCI_CFG_DEV(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->devnum) 86#define PCI_CFG_FUNC(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->funcnum) 87 88/* region addr: xfree86 uses different fields for memory regions and I/O ports */ 89#define PCI_REGION_BASE(_pcidev, _b, _type) \ 90 (((_type) == REGION_MEM) ? (_pcidev)->memBase[(_b)] \ 91 : (_pcidev)->ioBase[(_b)]) 92 93/* region size: xfree86 uses the log2 of the region size, 94 * but with zero meaning no region, not size of one XXX */ 95#define PCI_REGION_SIZE(_pcidev, _b) \ 96 (((_pcidev)->size[(_b)] > 0) ? (1 << (_pcidev)->size[(_b)]) : 0) 97 98/* read/write PCI configuration space */ 99#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \ 100 *(_value_ptr) = pciReadByte(PCI_CFG_TAG(_pcidev), (_offset)) 101 102#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \ 103 *(_value_ptr) = pciReadLong(PCI_CFG_TAG(_pcidev), (_offset)) 104 105#define PCI_WRITE_LONG(_pcidev, _value, _offset) \ 106 pciWriteLong(PCI_CFG_TAG(_pcidev), (_offset), (_value)) 107 108#else /* XSERVER_LIBPCIACCESS */ 109 110typedef struct pci_device *pciVideoPtr; 111 112#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor_id) 113#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->device_id) 114#define PCI_DEV_REVISION(_pcidev) ((_pcidev)->revision) 115 116#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subvendor_id) 117#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subdevice_id) 118 119/* pci-rework functions take a 'pci_device' parameter instead of a tag */ 120#define PCI_DEV_TAG(_pcidev) (_pcidev) 121 122/* PCI_DEV macros, typically used in printf's, add domain ? XXX */ 123#define PCI_DEV_BUS(_pcidev) ((_pcidev)->bus) 124#define PCI_DEV_DEV(_pcidev) ((_pcidev)->dev) 125#define PCI_DEV_FUNC(_pcidev) ((_pcidev)->func) 126 127/* pci-rework functions take a 'pci_device' parameter instead of a tag */ 128#define PCI_CFG_TAG(_pcidev) (_pcidev) 129 130/* PCI_CFG macros, typically used in DRI init, contain the domain */ 131#define PCI_CFG_BUS(_pcidev) (((_pcidev)->domain << 8) | \ 132 (_pcidev)->bus) 133#define PCI_CFG_DEV(_pcidev) ((_pcidev)->dev) 134#define PCI_CFG_FUNC(_pcidev) ((_pcidev)->func) 135 136#define PCI_REGION_BASE(_pcidev, _b, _type) ((_pcidev)->regions[(_b)].base_addr) 137#define PCI_REGION_SIZE(_pcidev, _b) ((_pcidev)->regions[(_b)].size) 138 139#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \ 140 pci_device_cfg_read_u8((_pcidev), (_value_ptr), (_offset)) 141 142#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \ 143 pci_device_cfg_read_u32((_pcidev), (_value_ptr), (_offset)) 144 145#define PCI_WRITE_LONG(_pcidev, _value, _offset) \ 146 pci_device_cfg_write_u32((_pcidev), (_value), (_offset)) 147 148#define ATI_DEVICE_MATCH(d, i) \ 149 { PCI_VENDOR_ATI, (d), PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, (i) } 150 151#endif /* XSERVER_LIBPCIACCESS */ 152 153#endif /* ATIPCIRENAME_H */ 154