1/* 2 * Copyright © 2012 Red Hat. 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 * 22 * Author: Dave Airlie <airlied@redhat.com> 23 */ 24#ifndef XF86_PLATFORM_BUS_H 25#define XF86_PLATFORM_BUS_H 26 27#include "hotplug.h" 28#include "xf86MatchDrivers.h" 29 30struct xf86_platform_device { 31 struct OdevAttributes *attribs; 32 /* for PCI devices */ 33 struct pci_device *pdev; 34 int flags; 35}; 36 37/* xf86_platform_device flags */ 38#define XF86_PDEV_UNOWNED 0x01 39#define XF86_PDEV_SERVER_FD 0x02 40#define XF86_PDEV_PAUSED 0x04 41 42#ifdef XSERVER_PLATFORM_BUS 43int xf86platformProbe(void); 44int xf86platformProbeDev(DriverPtr drvp); 45int xf86platformAddGPUDevices(DriverPtr drvp); 46void xf86MergeOutputClassOptions(int entityIndex, void **options); 47 48extern int xf86_num_platform_devices; 49extern struct xf86_platform_device *xf86_platform_devices; 50 51extern int 52xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned); 53extern int 54xf86_remove_platform_device(int dev_index); 55extern Bool 56xf86_get_platform_device_unowned(int index); 57 58extern int 59xf86platformAddDevice(int index); 60extern void 61xf86platformRemoveDevice(int index); 62 63static inline struct OdevAttributes * 64xf86_platform_device_odev_attributes(struct xf86_platform_device *device) 65{ 66 return device->attribs; 67} 68 69static inline struct OdevAttributes * 70xf86_platform_odev_attributes(int index) 71{ 72 struct xf86_platform_device *device = &xf86_platform_devices[index]; 73 74 return device->attribs; 75} 76 77#ifndef _XORG_CONFIG_H_ 78/* 79 * Define the legacy API only for external builds 80 */ 81 82/* path to kernel device node - Linux e.g. /dev/dri/card0 */ 83#define ODEV_ATTRIB_PATH 1 84/* system device path - Linux e.g. /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card1 */ 85#define ODEV_ATTRIB_SYSPATH 2 86/* DRI-style bus id */ 87#define ODEV_ATTRIB_BUSID 3 88/* Server managed FD */ 89#define ODEV_ATTRIB_FD 4 90/* Major number of the device node pointed to by ODEV_ATTRIB_PATH */ 91#define ODEV_ATTRIB_MAJOR 5 92/* Minor number of the device node pointed to by ODEV_ATTRIB_PATH */ 93#define ODEV_ATTRIB_MINOR 6 94/* kernel driver name */ 95#define ODEV_ATTRIB_DRIVER 7 96 97/* Protect against a mismatch attribute type by generating a compiler 98 * error using a negative array size when an incorrect attribute is 99 * passed 100 */ 101 102#define _ODEV_ATTRIB_IS_STRING(x) ((x) == ODEV_ATTRIB_PATH || \ 103 (x) == ODEV_ATTRIB_SYSPATH || \ 104 (x) == ODEV_ATTRIB_BUSID || \ 105 (x) == ODEV_ATTRIB_DRIVER) 106 107#define _ODEV_ATTRIB_STRING_CHECK(x) ((int (*)[_ODEV_ATTRIB_IS_STRING(x)-1]) 0) 108 109static inline char * 110_xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0]) 111{ 112 switch (attrib) { 113 case ODEV_ATTRIB_PATH: 114 return xf86_platform_device_odev_attributes(device)->path; 115 case ODEV_ATTRIB_SYSPATH: 116 return xf86_platform_device_odev_attributes(device)->syspath; 117 case ODEV_ATTRIB_BUSID: 118 return xf86_platform_device_odev_attributes(device)->busid; 119 case ODEV_ATTRIB_DRIVER: 120 return xf86_platform_device_odev_attributes(device)->driver; 121 default: 122 assert(FALSE); 123 return NULL; 124 } 125} 126 127#define xf86_get_platform_device_attrib(device, attrib) _xf86_get_platform_device_attrib(device,attrib,_ODEV_ATTRIB_STRING_CHECK(attrib)) 128 129#define _ODEV_ATTRIB_IS_INT(x) ((x) == ODEV_ATTRIB_FD || (x) == ODEV_ATTRIB_MAJOR || (x) == ODEV_ATTRIB_MINOR) 130#define _ODEV_ATTRIB_INT_DEFAULT(x) ((x) == ODEV_ATTRIB_FD ? -1 : 0) 131#define _ODEV_ATTRIB_DEFAULT_CHECK(x,def) (_ODEV_ATTRIB_INT_DEFAULT(x) == (def)) 132#define _ODEV_ATTRIB_INT_CHECK(x,def) ((int (*)[_ODEV_ATTRIB_IS_INT(x)*_ODEV_ATTRIB_DEFAULT_CHECK(x,def)-1]) 0) 133 134static inline int 135_xf86_get_platform_device_int_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0]) 136{ 137 switch (attrib) { 138 case ODEV_ATTRIB_FD: 139 return xf86_platform_device_odev_attributes(device)->fd; 140 case ODEV_ATTRIB_MAJOR: 141 return xf86_platform_device_odev_attributes(device)->major; 142 case ODEV_ATTRIB_MINOR: 143 return xf86_platform_device_odev_attributes(device)->minor; 144 default: 145 assert(FALSE); 146 return 0; 147 } 148} 149 150#define xf86_get_platform_device_int_attrib(device, attrib, def) _xf86_get_platform_device_int_attrib(device,attrib,_ODEV_ATTRIB_INT_CHECK(attrib,def)) 151 152#endif 153 154extern _X_EXPORT Bool 155xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid); 156 157extern _X_EXPORT void 158xf86PlatformMatchDriver(XF86MatchedDrivers *); 159 160extern void xf86platformVTProbe(void); 161extern void xf86platformPrimary(void); 162 163#else 164 165static inline int xf86platformAddGPUDevices(DriverPtr drvp) { return FALSE; } 166static inline void xf86MergeOutputClassOptions(int index, void **options) {} 167 168#endif 169 170#endif 171