summaryrefslogtreecommitdiff
path: root/src/cir_pcirename.h
blob: c1fb249366e9cf80fcca27f91a605c88a704f6ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * 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 
};

#include "xf86Module.h"

#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 12

#if (defined(__alpha__) || defined(__ia64__)) && defined (linux)
#define PCI_DOM_MASK    0x01fful
#else
#define PCI_DOM_MASK 0x0ffu
#endif

#ifndef PCI_DOM_MASK
# define PCI_DOM_MASK 0x0ffu
#endif
#define PCI_DOMBUS_MASK (((PCI_DOM_MASK) << 8) | 0x0ffu)

static inline uint32_t
pciTag(int busnum, int devnum, int funcnum)
{
	uint32_t tag;
	tag  = (busnum & (PCI_DOMBUS_MASK)) << 16;
	tag |= (devnum & 0x00001fu) << 11;
	tag |= (funcnum & 0x000007u) << 8;

	return tag;
}
#endif /* GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 12 */

#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 */

#ifndef _XF86_PCIINFO_H

#define PCI_VENDOR_CIRRUS		0x1013
/* Cirrus Logic */
#define PCI_CHIP_GD7548			0x0038
#define PCI_CHIP_GD7555			0x0040
#define PCI_CHIP_GD7556                 0x004C
#define PCI_CHIP_GD5430			0x00A0
#define PCI_CHIP_GD5434_4		0x00A4
#define PCI_CHIP_GD5434_8		0x00A8
#define PCI_CHIP_GD5436			0x00AC
#define PCI_CHIP_GD5446			0x00B8
#define PCI_CHIP_GD5480			0x00BC
#define PCI_CHIP_GD5462			0x00D0
#define PCI_CHIP_GD5464			0x00D4
#define PCI_CHIP_GD5464BD		0x00D5
#define PCI_CHIP_GD5465			0x00D6
#define PCI_CHIP_6729			0x1100
#define PCI_CHIP_6832			0x1110
#define PCI_CHIP_GD7542			0x1200
#define PCI_CHIP_GD7543			0x1202
#define PCI_CHIP_GD7541			0x1204

#endif
#endif /* CIRPCIRENAME_H */