10cc67336Smrg/*
20cc67336Smrg * Copyright 2007 George Sapountzis
30cc67336Smrg *
40cc67336Smrg * Permission is hereby granted, free of charge, to any person obtaining a
50cc67336Smrg * copy of this software and associated documentation files (the "Software"),
60cc67336Smrg * to deal in the Software without restriction, including without limitation
70cc67336Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
80cc67336Smrg * and/or sell copies of the Software, and to permit persons to whom the
90cc67336Smrg * Software is furnished to do so, subject to the following conditions:
100cc67336Smrg *
110cc67336Smrg * The above copyright notice and this permission notice (including the next
120cc67336Smrg * paragraph) shall be included in all copies or substantial portions of the
130cc67336Smrg * Software.
140cc67336Smrg *
150cc67336Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
160cc67336Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
170cc67336Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
180cc67336Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
190cc67336Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
200cc67336Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
210cc67336Smrg * SOFTWARE.
220cc67336Smrg */
230cc67336Smrg
240cc67336Smrg/**
250cc67336Smrg * Macros for porting drivers from legacy xfree86 PCI code to the pciaccess
260cc67336Smrg * library. The main purpose being to facilitate source code compatibility.
270cc67336Smrg */
280cc67336Smrg
290cc67336Smrg#ifndef I740PCIRENAME_H
300cc67336Smrg#define I740PCIRENAME_H
310cc67336Smrg
320cc67336Smrgenum region_type {
330cc67336Smrg    REGION_MEM,
340cc67336Smrg    REGION_IO
350cc67336Smrg};
360cc67336Smrg
370cc67336Smrg#ifndef XSERVER_LIBPCIACCESS
380cc67336Smrg
390cc67336Smrg/* pciVideoPtr */
400cc67336Smrg#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor)
410cc67336Smrg#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->chipType)
420cc67336Smrg#define PCI_DEV_REVISION(_pcidev)  ((_pcidev)->chipRev)
430cc67336Smrg
440cc67336Smrg#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subsysVendor)
450cc67336Smrg#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subsysCard)
460cc67336Smrg
470cc67336Smrg#define PCI_DEV_TAG(_pcidev) pciTag((_pcidev)->bus,    \
480cc67336Smrg                                    (_pcidev)->device, \
490cc67336Smrg                                    (_pcidev)->func)
500cc67336Smrg#define PCI_DEV_BUS(_pcidev)       ((_pcidev)->bus)
510cc67336Smrg#define PCI_DEV_DEV(_pcidev)       ((_pcidev)->device)
520cc67336Smrg#define PCI_DEV_FUNC(_pcidev)      ((_pcidev)->func)
530cc67336Smrg
540cc67336Smrg/* pciConfigPtr */
550cc67336Smrg#define PCI_CFG_TAG(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->tag)
560cc67336Smrg#define PCI_CFG_BUS(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->busnum)
570cc67336Smrg#define PCI_CFG_DEV(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->devnum)
580cc67336Smrg#define PCI_CFG_FUNC(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->funcnum)
590cc67336Smrg
600cc67336Smrg/* region addr: xfree86 uses different fields for memory regions and I/O ports */
610cc67336Smrg#define PCI_REGION_BASE(_pcidev, _b, _type)             \
620cc67336Smrg    (((_type) == REGION_MEM) ? (_pcidev)->memBase[(_b)] \
630cc67336Smrg                             : (_pcidev)->ioBase[(_b)])
640cc67336Smrg
650cc67336Smrg/* region size: xfree86 uses the log2 of the region size,
660cc67336Smrg * but with zero meaning no region, not size of one XXX */
670cc67336Smrg#define PCI_REGION_SIZE(_pcidev, _b) \
680cc67336Smrg    (((_pcidev)->size[(_b)] > 0) ? (1 << (_pcidev)->size[(_b)]) : 0)
690cc67336Smrg
700cc67336Smrg/* read/write PCI configuration space */
710cc67336Smrg#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \
720cc67336Smrg    *(_value_ptr) = pciReadByte(PCI_CFG_TAG(_pcidev), (_offset))
730cc67336Smrg
740cc67336Smrg#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
750cc67336Smrg    *(_value_ptr) = pciReadLong(PCI_CFG_TAG(_pcidev), (_offset))
760cc67336Smrg
770cc67336Smrg#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
780cc67336Smrg    pciWriteLong(PCI_CFG_TAG(_pcidev), (_offset), (_value))
790cc67336Smrg
800cc67336Smrg#else /* XSERVER_LIBPCIACCESS */
810cc67336Smrg
820cc67336Smrgtypedef struct pci_device *pciVideoPtr;
830cc67336Smrg
840cc67336Smrg#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor_id)
850cc67336Smrg#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->device_id)
860cc67336Smrg#define PCI_DEV_REVISION(_pcidev)  ((_pcidev)->revision)
870cc67336Smrg
880cc67336Smrg#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subvendor_id)
890cc67336Smrg#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subdevice_id)
900cc67336Smrg
910cc67336Smrg/* pci-rework functions take a 'pci_device' parameter instead of a tag */
920cc67336Smrg#define PCI_DEV_TAG(_pcidev)        (_pcidev)
930cc67336Smrg
940cc67336Smrg/* PCI_DEV macros, typically used in printf's, add domain ? XXX */
950cc67336Smrg#define PCI_DEV_BUS(_pcidev)       ((_pcidev)->bus)
960cc67336Smrg#define PCI_DEV_DEV(_pcidev)       ((_pcidev)->dev)
970cc67336Smrg#define PCI_DEV_FUNC(_pcidev)      ((_pcidev)->func)
980cc67336Smrg
990cc67336Smrg/* pci-rework functions take a 'pci_device' parameter instead of a tag */
1000cc67336Smrg#define PCI_CFG_TAG(_pcidev)        (_pcidev)
1010cc67336Smrg
1020cc67336Smrg/* PCI_CFG macros, typically used in DRI init, contain the domain */
1030cc67336Smrg#define PCI_CFG_BUS(_pcidev)      (((_pcidev)->domain << 8) | \
1040cc67336Smrg                                    (_pcidev)->bus)
1050cc67336Smrg#define PCI_CFG_DEV(_pcidev)       ((_pcidev)->dev)
1060cc67336Smrg#define PCI_CFG_FUNC(_pcidev)      ((_pcidev)->func)
1070cc67336Smrg
1080cc67336Smrg#define PCI_REGION_BASE(_pcidev, _b, _type) ((_pcidev)->regions[(_b)].base_addr)
1090cc67336Smrg#define PCI_REGION_SIZE(_pcidev, _b)        ((_pcidev)->regions[(_b)].size)
1100cc67336Smrg
1110cc67336Smrg#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \
1120cc67336Smrg    pci_device_cfg_read_u8((_pcidev), (_value_ptr), (_offset))
1130cc67336Smrg
1140cc67336Smrg#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
1150cc67336Smrg    pci_device_cfg_read_u32((_pcidev), (_value_ptr), (_offset))
1160cc67336Smrg
1170cc67336Smrg#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
1180cc67336Smrg    pci_device_cfg_write_u32((_pcidev), (_value), (_offset))
1190cc67336Smrg
1200cc67336Smrg#endif /* XSERVER_LIBPCIACCESS */
1210cc67336Smrg
1220cc67336Smrg#endif /* i740PCIRENAME_H */
123