135c4bbdfSmrg/*
235c4bbdfSmrg * Copyright © 2012 Red Hat.
335c4bbdfSmrg *
435c4bbdfSmrg * Permission is hereby granted, free of charge, to any person obtaining a
535c4bbdfSmrg * copy of this software and associated documentation files (the "Software"),
635c4bbdfSmrg * to deal in the Software without restriction, including without limitation
735c4bbdfSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
835c4bbdfSmrg * and/or sell copies of the Software, and to permit persons to whom the
935c4bbdfSmrg * Software is furnished to do so, subject to the following conditions:
1035c4bbdfSmrg *
1135c4bbdfSmrg * The above copyright notice and this permission notice shall be included in
1235c4bbdfSmrg * all copies or substantial portions of the Software.
1335c4bbdfSmrg *
1435c4bbdfSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1535c4bbdfSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1635c4bbdfSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1735c4bbdfSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1835c4bbdfSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1935c4bbdfSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2035c4bbdfSmrg * DEALINGS IN THE SOFTWARE.
2135c4bbdfSmrg *
2235c4bbdfSmrg * Author: Dave Airlie <airlied@redhat.com>
2335c4bbdfSmrg */
2435c4bbdfSmrg#ifndef XF86_PLATFORM_BUS_H
2535c4bbdfSmrg#define XF86_PLATFORM_BUS_H
2635c4bbdfSmrg
2735c4bbdfSmrg#include "hotplug.h"
281b5d61b8Smrg#include "xf86MatchDrivers.h"
2935c4bbdfSmrg
3035c4bbdfSmrgstruct xf86_platform_device {
3135c4bbdfSmrg    struct OdevAttributes *attribs;
3235c4bbdfSmrg    /* for PCI devices */
3335c4bbdfSmrg    struct pci_device *pdev;
3435c4bbdfSmrg    int flags;
3535c4bbdfSmrg};
3635c4bbdfSmrg
3735c4bbdfSmrg/* xf86_platform_device flags */
3835c4bbdfSmrg#define XF86_PDEV_UNOWNED       0x01
3935c4bbdfSmrg#define XF86_PDEV_SERVER_FD     0x02
4035c4bbdfSmrg#define XF86_PDEV_PAUSED        0x04
4135c4bbdfSmrg
4235c4bbdfSmrg#ifdef XSERVER_PLATFORM_BUS
4335c4bbdfSmrgint xf86platformProbe(void);
4435c4bbdfSmrgint xf86platformProbeDev(DriverPtr drvp);
451b5d61b8Smrgint xf86platformAddGPUDevices(DriverPtr drvp);
461b5d61b8Smrgvoid xf86MergeOutputClassOptions(int entityIndex, void **options);
4735c4bbdfSmrg
4835c4bbdfSmrgextern int xf86_num_platform_devices;
4935c4bbdfSmrgextern struct xf86_platform_device *xf86_platform_devices;
5035c4bbdfSmrg
5135c4bbdfSmrgextern int
5235c4bbdfSmrgxf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned);
5335c4bbdfSmrgextern int
5435c4bbdfSmrgxf86_remove_platform_device(int dev_index);
5535c4bbdfSmrgextern Bool
5635c4bbdfSmrgxf86_get_platform_device_unowned(int index);
5735c4bbdfSmrg
5835c4bbdfSmrgextern int
5935c4bbdfSmrgxf86platformAddDevice(int index);
6035c4bbdfSmrgextern void
6135c4bbdfSmrgxf86platformRemoveDevice(int index);
6235c4bbdfSmrg
6335c4bbdfSmrgstatic inline struct OdevAttributes *
6435c4bbdfSmrgxf86_platform_device_odev_attributes(struct xf86_platform_device *device)
6535c4bbdfSmrg{
6635c4bbdfSmrg    return device->attribs;
6735c4bbdfSmrg}
6835c4bbdfSmrg
6935c4bbdfSmrgstatic inline struct OdevAttributes *
7035c4bbdfSmrgxf86_platform_odev_attributes(int index)
7135c4bbdfSmrg{
7235c4bbdfSmrg    struct xf86_platform_device *device = &xf86_platform_devices[index];
7335c4bbdfSmrg
7435c4bbdfSmrg    return device->attribs;
7535c4bbdfSmrg}
7635c4bbdfSmrg
7735c4bbdfSmrg#ifndef _XORG_CONFIG_H_
7835c4bbdfSmrg/*
7935c4bbdfSmrg * Define the legacy API only for external builds
8035c4bbdfSmrg */
8135c4bbdfSmrg
8235c4bbdfSmrg/* path to kernel device node - Linux e.g. /dev/dri/card0 */
8335c4bbdfSmrg#define ODEV_ATTRIB_PATH        1
8435c4bbdfSmrg/* system device path - Linux e.g. /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card1 */
8535c4bbdfSmrg#define ODEV_ATTRIB_SYSPATH     2
8635c4bbdfSmrg/* DRI-style bus id */
8735c4bbdfSmrg#define ODEV_ATTRIB_BUSID       3
8835c4bbdfSmrg/* Server managed FD */
8935c4bbdfSmrg#define ODEV_ATTRIB_FD          4
9035c4bbdfSmrg/* Major number of the device node pointed to by ODEV_ATTRIB_PATH */
9135c4bbdfSmrg#define ODEV_ATTRIB_MAJOR       5
9235c4bbdfSmrg/* Minor number of the device node pointed to by ODEV_ATTRIB_PATH */
9335c4bbdfSmrg#define ODEV_ATTRIB_MINOR       6
9435c4bbdfSmrg/* kernel driver name */
9535c4bbdfSmrg#define ODEV_ATTRIB_DRIVER      7
9635c4bbdfSmrg
9735c4bbdfSmrg/* Protect against a mismatch attribute type by generating a compiler
9835c4bbdfSmrg * error using a negative array size when an incorrect attribute is
9935c4bbdfSmrg * passed
10035c4bbdfSmrg */
10135c4bbdfSmrg
10235c4bbdfSmrg#define _ODEV_ATTRIB_IS_STRING(x)       ((x) == ODEV_ATTRIB_PATH ||     \
10335c4bbdfSmrg                                         (x) == ODEV_ATTRIB_SYSPATH ||  \
10435c4bbdfSmrg                                         (x) == ODEV_ATTRIB_BUSID ||    \
10535c4bbdfSmrg                                         (x) == ODEV_ATTRIB_DRIVER)
10635c4bbdfSmrg
10735c4bbdfSmrg#define _ODEV_ATTRIB_STRING_CHECK(x)    ((int (*)[_ODEV_ATTRIB_IS_STRING(x)-1]) 0)
10835c4bbdfSmrg
10935c4bbdfSmrgstatic inline char *
11035c4bbdfSmrg_xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0])
11135c4bbdfSmrg{
11235c4bbdfSmrg    switch (attrib) {
11335c4bbdfSmrg    case ODEV_ATTRIB_PATH:
11435c4bbdfSmrg        return xf86_platform_device_odev_attributes(device)->path;
11535c4bbdfSmrg    case ODEV_ATTRIB_SYSPATH:
11635c4bbdfSmrg        return xf86_platform_device_odev_attributes(device)->syspath;
11735c4bbdfSmrg    case ODEV_ATTRIB_BUSID:
11835c4bbdfSmrg        return xf86_platform_device_odev_attributes(device)->busid;
11935c4bbdfSmrg    case ODEV_ATTRIB_DRIVER:
12035c4bbdfSmrg        return xf86_platform_device_odev_attributes(device)->driver;
12135c4bbdfSmrg    default:
12235c4bbdfSmrg        assert(FALSE);
12335c4bbdfSmrg        return NULL;
12435c4bbdfSmrg    }
12535c4bbdfSmrg}
12635c4bbdfSmrg
12735c4bbdfSmrg#define xf86_get_platform_device_attrib(device, attrib) _xf86_get_platform_device_attrib(device,attrib,_ODEV_ATTRIB_STRING_CHECK(attrib))
12835c4bbdfSmrg
12935c4bbdfSmrg#define _ODEV_ATTRIB_IS_INT(x)                  ((x) == ODEV_ATTRIB_FD || (x) == ODEV_ATTRIB_MAJOR || (x) == ODEV_ATTRIB_MINOR)
13035c4bbdfSmrg#define _ODEV_ATTRIB_INT_DEFAULT(x)             ((x) == ODEV_ATTRIB_FD ? -1 : 0)
13135c4bbdfSmrg#define _ODEV_ATTRIB_DEFAULT_CHECK(x,def)       (_ODEV_ATTRIB_INT_DEFAULT(x) == (def))
13235c4bbdfSmrg#define _ODEV_ATTRIB_INT_CHECK(x,def)           ((int (*)[_ODEV_ATTRIB_IS_INT(x)*_ODEV_ATTRIB_DEFAULT_CHECK(x,def)-1]) 0)
13335c4bbdfSmrg
13435c4bbdfSmrgstatic inline int
13535c4bbdfSmrg_xf86_get_platform_device_int_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0])
13635c4bbdfSmrg{
13735c4bbdfSmrg    switch (attrib) {
13835c4bbdfSmrg    case ODEV_ATTRIB_FD:
13935c4bbdfSmrg        return xf86_platform_device_odev_attributes(device)->fd;
14035c4bbdfSmrg    case ODEV_ATTRIB_MAJOR:
14135c4bbdfSmrg        return xf86_platform_device_odev_attributes(device)->major;
14235c4bbdfSmrg    case ODEV_ATTRIB_MINOR:
14335c4bbdfSmrg        return xf86_platform_device_odev_attributes(device)->minor;
14435c4bbdfSmrg    default:
14535c4bbdfSmrg        assert(FALSE);
14635c4bbdfSmrg        return 0;
14735c4bbdfSmrg    }
14835c4bbdfSmrg}
14935c4bbdfSmrg
15035c4bbdfSmrg#define xf86_get_platform_device_int_attrib(device, attrib, def) _xf86_get_platform_device_int_attrib(device,attrib,_ODEV_ATTRIB_INT_CHECK(attrib,def))
15135c4bbdfSmrg
15235c4bbdfSmrg#endif
15335c4bbdfSmrg
15435c4bbdfSmrgextern _X_EXPORT Bool
15535c4bbdfSmrgxf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid);
15635c4bbdfSmrg
1571b5d61b8Smrgextern _X_EXPORT void
1581b5d61b8Smrgxf86PlatformMatchDriver(XF86MatchedDrivers *);
15935c4bbdfSmrg
16035c4bbdfSmrgextern void xf86platformVTProbe(void);
16135c4bbdfSmrgextern void xf86platformPrimary(void);
1621b5d61b8Smrg
1631b5d61b8Smrg#else
1641b5d61b8Smrg
1651b5d61b8Smrgstatic inline int xf86platformAddGPUDevices(DriverPtr drvp) { return FALSE; }
1661b5d61b8Smrgstatic inline void xf86MergeOutputClassOptions(int index, void **options) {}
1671b5d61b8Smrg
16835c4bbdfSmrg#endif
16935c4bbdfSmrg
17035c4bbdfSmrg#endif
171