2
* Copyright 2007 George Sapountzis
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:
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
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
25
* Macros for porting drivers from legacy xfree86 PCI code to the pciaccess
26
* library. The main purpose being to facilitate source code compatibility.
29
#ifndef ATIPCIRENAME_H
30
#define ATIPCIRENAME_H
37
#ifndef XSERVER_LIBPCIACCESS
40
#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor)
41
#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->chipType)
42
#define PCI_DEV_REVISION(_pcidev) ((_pcidev)->chipRev)
44
#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subsysVendor)
45
#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subsysCard)
47
#define PCI_DEV_TAG(_pcidev) pciTag((_pcidev)->bus, \
50
#define PCI_DEV_BUS(_pcidev) ((_pcidev)->bus)
51
#define PCI_DEV_DEV(_pcidev) ((_pcidev)->device)
52
#define PCI_DEV_FUNC(_pcidev) ((_pcidev)->func)
55
#define PCI_CFG_TAG(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->tag)
56
#define PCI_CFG_BUS(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->busnum)
57
#define PCI_CFG_DEV(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->devnum)
58
#define PCI_CFG_FUNC(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->funcnum)
60
/* region addr: xfree86 uses different fields for memory regions and I/O ports */
61
#define PCI_REGION_BASE(_pcidev, _b, _type) \
62
(((_type) == REGION_MEM) ? (_pcidev)->memBase[(_b)] \
63
: (_pcidev)->ioBase[(_b)])
65
/* region size: xfree86 uses the log2 of the region size,
66
* but with zero meaning no region, not size of one XXX */
67
#define PCI_REGION_SIZE(_pcidev, _b) \
68
(((_pcidev)->size[(_b)] > 0) ? (1 << (_pcidev)->size[(_b)]) : 0)
70
/* read/write PCI configuration space */
71
#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \
72
*(_value_ptr) = pciReadByte(PCI_CFG_TAG(_pcidev), (_offset))
74
#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
75
*(_value_ptr) = pciReadLong(PCI_CFG_TAG(_pcidev), (_offset))
77
#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
78
pciWriteLong(PCI_CFG_TAG(_pcidev), (_offset), (_value))
80
#else /* XSERVER_LIBPCIACCESS */
82
typedef struct pci_device *pciVideoPtr;
84
#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor_id)
85
#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->device_id)
86
#define PCI_DEV_REVISION(_pcidev) ((_pcidev)->revision)
88
#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subvendor_id)
89
#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subdevice_id)
91
/* pci-rework functions take a 'pci_device' parameter instead of a tag */
92
#define PCI_DEV_TAG(_pcidev) (_pcidev)
94
/* PCI_DEV macros, typically used in printf's, add domain ? XXX */
95
#define PCI_DEV_BUS(_pcidev) ((_pcidev)->bus)
96
#define PCI_DEV_DEV(_pcidev) ((_pcidev)->dev)
97
#define PCI_DEV_FUNC(_pcidev) ((_pcidev)->func)
99
/* pci-rework functions take a 'pci_device' parameter instead of a tag */
100
#define PCI_CFG_TAG(_pcidev) (_pcidev)
102
/* PCI_CFG macros, typically used in DRI init, contain the domain */
103
#define PCI_CFG_BUS(_pcidev) (((_pcidev)->domain << 8) | \
105
#define PCI_CFG_DEV(_pcidev) ((_pcidev)->dev)
106
#define PCI_CFG_FUNC(_pcidev) ((_pcidev)->func)
108
#define PCI_REGION_BASE(_pcidev, _b, _type) ((_pcidev)->regions[(_b)].base_addr)
109
#define PCI_REGION_SIZE(_pcidev, _b) ((_pcidev)->regions[(_b)].size)
111
#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \
112
pci_device_cfg_read_u8((_pcidev), (_value_ptr), (_offset))
114
#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
115
pci_device_cfg_read_u32((_pcidev), (_value_ptr), (_offset))
117
#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
118
pci_device_cfg_write_u32((_pcidev), (_value), (_offset))
120
#define ATI_DEVICE_MATCH(d, i) \
121
{ PCI_VENDOR_ATI, (d), PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, (i) }
123
#endif /* XSERVER_LIBPCIACCESS */
125
#endif /* ATIPCIRENAME_H */