summaryrefslogtreecommitdiff
path: root/xserver/hw/xfree86/common/xf86platformBus.h
blob: 1e75e635229d837aaaab3deaa6391ccaa9a4e818 (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
/*
 * Copyright © 2012 Red Hat.
 *
 * 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 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.
 *
 * Author: Dave Airlie <airlied@redhat.com>
 */
#ifndef XF86_PLATFORM_BUS_H
#define XF86_PLATFORM_BUS_H

#include "hotplug.h"
#include "xf86MatchDrivers.h"

struct xf86_platform_device {
    struct OdevAttributes *attribs;
    /* for PCI devices */
    struct pci_device *pdev;
    int flags;
};

/* xf86_platform_device flags */
#define XF86_PDEV_UNOWNED       0x01
#define XF86_PDEV_SERVER_FD     0x02
#define XF86_PDEV_PAUSED        0x04

#ifdef XSERVER_PLATFORM_BUS
int xf86platformProbe(void);
int xf86platformProbeDev(DriverPtr drvp);
int xf86platformAddGPUDevices(DriverPtr drvp);
void xf86MergeOutputClassOptions(int entityIndex, void **options);

extern int xf86_num_platform_devices;
extern struct xf86_platform_device *xf86_platform_devices;

extern int
xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned);
extern int
xf86_remove_platform_device(int dev_index);
extern Bool
xf86_get_platform_device_unowned(int index);

extern int
xf86platformAddDevice(int index);
extern void
xf86platformRemoveDevice(int index);

static inline struct OdevAttributes *
xf86_platform_device_odev_attributes(struct xf86_platform_device *device)
{
    return device->attribs;
}

static inline struct OdevAttributes *
xf86_platform_odev_attributes(int index)
{
    struct xf86_platform_device *device = &xf86_platform_devices[index];

    return device->attribs;
}

#ifndef _XORG_CONFIG_H_
/*
 * Define the legacy API only for external builds
 */

/* path to kernel device node - Linux e.g. /dev/dri/card0 */
#define ODEV_ATTRIB_PATH        1
/* system device path - Linux e.g. /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card1 */
#define ODEV_ATTRIB_SYSPATH     2
/* DRI-style bus id */
#define ODEV_ATTRIB_BUSID       3
/* Server managed FD */
#define ODEV_ATTRIB_FD          4
/* Major number of the device node pointed to by ODEV_ATTRIB_PATH */
#define ODEV_ATTRIB_MAJOR       5
/* Minor number of the device node pointed to by ODEV_ATTRIB_PATH */
#define ODEV_ATTRIB_MINOR       6
/* kernel driver name */
#define ODEV_ATTRIB_DRIVER      7

/* Protect against a mismatch attribute type by generating a compiler
 * error using a negative array size when an incorrect attribute is
 * passed
 */

#define _ODEV_ATTRIB_IS_STRING(x)       ((x) == ODEV_ATTRIB_PATH ||     \
                                         (x) == ODEV_ATTRIB_SYSPATH ||  \
                                         (x) == ODEV_ATTRIB_BUSID ||    \
                                         (x) == ODEV_ATTRIB_DRIVER)

#define _ODEV_ATTRIB_STRING_CHECK(x)    ((int (*)[_ODEV_ATTRIB_IS_STRING(x)-1]) 0)

static inline char *
_xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0])
{
    switch (attrib) {
    case ODEV_ATTRIB_PATH:
        return xf86_platform_device_odev_attributes(device)->path;
    case ODEV_ATTRIB_SYSPATH:
        return xf86_platform_device_odev_attributes(device)->syspath;
    case ODEV_ATTRIB_BUSID:
        return xf86_platform_device_odev_attributes(device)->busid;
    case ODEV_ATTRIB_DRIVER:
        return xf86_platform_device_odev_attributes(device)->driver;
    default:
        assert(FALSE);
        return NULL;
    }
}

#define xf86_get_platform_device_attrib(device, attrib) _xf86_get_platform_device_attrib(device,attrib,_ODEV_ATTRIB_STRING_CHECK(attrib))

#define _ODEV_ATTRIB_IS_INT(x)                  ((x) == ODEV_ATTRIB_FD || (x) == ODEV_ATTRIB_MAJOR || (x) == ODEV_ATTRIB_MINOR)
#define _ODEV_ATTRIB_INT_DEFAULT(x)             ((x) == ODEV_ATTRIB_FD ? -1 : 0)
#define _ODEV_ATTRIB_DEFAULT_CHECK(x,def)       (_ODEV_ATTRIB_INT_DEFAULT(x) == (def))
#define _ODEV_ATTRIB_INT_CHECK(x,def)           ((int (*)[_ODEV_ATTRIB_IS_INT(x)*_ODEV_ATTRIB_DEFAULT_CHECK(x,def)-1]) 0)

static inline int
_xf86_get_platform_device_int_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0])
{
    switch (attrib) {
    case ODEV_ATTRIB_FD:
        return xf86_platform_device_odev_attributes(device)->fd;
    case ODEV_ATTRIB_MAJOR:
        return xf86_platform_device_odev_attributes(device)->major;
    case ODEV_ATTRIB_MINOR:
        return xf86_platform_device_odev_attributes(device)->minor;
    default:
        assert(FALSE);
        return 0;
    }
}

#define xf86_get_platform_device_int_attrib(device, attrib, def) _xf86_get_platform_device_int_attrib(device,attrib,_ODEV_ATTRIB_INT_CHECK(attrib,def))

#endif

extern _X_EXPORT Bool
xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid);

extern _X_EXPORT void
xf86PlatformMatchDriver(XF86MatchedDrivers *);

extern void xf86platformVTProbe(void);
extern void xf86platformPrimary(void);

#else

static inline int xf86platformAddGPUDevices(DriverPtr drvp) { return FALSE; }
static inline void xf86MergeOutputClassOptions(int index, void **options) {}

#endif

#endif