xf86platformBus.h revision 35c4bbdf
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 29struct xf86_platform_device { 30 struct OdevAttributes *attribs; 31 /* for PCI devices */ 32 struct pci_device *pdev; 33 int flags; 34}; 35 36/* xf86_platform_device flags */ 37#define XF86_PDEV_UNOWNED 0x01 38#define XF86_PDEV_SERVER_FD 0x02 39#define XF86_PDEV_PAUSED 0x04 40 41#ifdef XSERVER_PLATFORM_BUS 42int xf86platformProbe(void); 43int xf86platformProbeDev(DriverPtr drvp); 44 45extern int xf86_num_platform_devices; 46extern struct xf86_platform_device *xf86_platform_devices; 47 48extern int 49xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned); 50extern int 51xf86_remove_platform_device(int dev_index); 52extern Bool 53xf86_get_platform_device_unowned(int index); 54 55extern int 56xf86platformAddDevice(int index); 57extern void 58xf86platformRemoveDevice(int index); 59 60static inline struct OdevAttributes * 61xf86_platform_device_odev_attributes(struct xf86_platform_device *device) 62{ 63 return device->attribs; 64} 65 66static inline struct OdevAttributes * 67xf86_platform_odev_attributes(int index) 68{ 69 struct xf86_platform_device *device = &xf86_platform_devices[index]; 70 71 return device->attribs; 72} 73 74#ifndef _XORG_CONFIG_H_ 75/* 76 * Define the legacy API only for external builds 77 */ 78 79/* path to kernel device node - Linux e.g. /dev/dri/card0 */ 80#define ODEV_ATTRIB_PATH 1 81/* system device path - Linux e.g. /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card1 */ 82#define ODEV_ATTRIB_SYSPATH 2 83/* DRI-style bus id */ 84#define ODEV_ATTRIB_BUSID 3 85/* Server managed FD */ 86#define ODEV_ATTRIB_FD 4 87/* Major number of the device node pointed to by ODEV_ATTRIB_PATH */ 88#define ODEV_ATTRIB_MAJOR 5 89/* Minor number of the device node pointed to by ODEV_ATTRIB_PATH */ 90#define ODEV_ATTRIB_MINOR 6 91/* kernel driver name */ 92#define ODEV_ATTRIB_DRIVER 7 93 94/* Protect against a mismatch attribute type by generating a compiler 95 * error using a negative array size when an incorrect attribute is 96 * passed 97 */ 98 99#define _ODEV_ATTRIB_IS_STRING(x) ((x) == ODEV_ATTRIB_PATH || \ 100 (x) == ODEV_ATTRIB_SYSPATH || \ 101 (x) == ODEV_ATTRIB_BUSID || \ 102 (x) == ODEV_ATTRIB_DRIVER) 103 104#define _ODEV_ATTRIB_STRING_CHECK(x) ((int (*)[_ODEV_ATTRIB_IS_STRING(x)-1]) 0) 105 106static inline char * 107_xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0]) 108{ 109 switch (attrib) { 110 case ODEV_ATTRIB_PATH: 111 return xf86_platform_device_odev_attributes(device)->path; 112 case ODEV_ATTRIB_SYSPATH: 113 return xf86_platform_device_odev_attributes(device)->syspath; 114 case ODEV_ATTRIB_BUSID: 115 return xf86_platform_device_odev_attributes(device)->busid; 116 case ODEV_ATTRIB_DRIVER: 117 return xf86_platform_device_odev_attributes(device)->driver; 118 default: 119 assert(FALSE); 120 return NULL; 121 } 122} 123 124#define xf86_get_platform_device_attrib(device, attrib) _xf86_get_platform_device_attrib(device,attrib,_ODEV_ATTRIB_STRING_CHECK(attrib)) 125 126#define _ODEV_ATTRIB_IS_INT(x) ((x) == ODEV_ATTRIB_FD || (x) == ODEV_ATTRIB_MAJOR || (x) == ODEV_ATTRIB_MINOR) 127#define _ODEV_ATTRIB_INT_DEFAULT(x) ((x) == ODEV_ATTRIB_FD ? -1 : 0) 128#define _ODEV_ATTRIB_DEFAULT_CHECK(x,def) (_ODEV_ATTRIB_INT_DEFAULT(x) == (def)) 129#define _ODEV_ATTRIB_INT_CHECK(x,def) ((int (*)[_ODEV_ATTRIB_IS_INT(x)*_ODEV_ATTRIB_DEFAULT_CHECK(x,def)-1]) 0) 130 131static inline int 132_xf86_get_platform_device_int_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0]) 133{ 134 switch (attrib) { 135 case ODEV_ATTRIB_FD: 136 return xf86_platform_device_odev_attributes(device)->fd; 137 case ODEV_ATTRIB_MAJOR: 138 return xf86_platform_device_odev_attributes(device)->major; 139 case ODEV_ATTRIB_MINOR: 140 return xf86_platform_device_odev_attributes(device)->minor; 141 default: 142 assert(FALSE); 143 return 0; 144 } 145} 146 147#define xf86_get_platform_device_int_attrib(device, attrib, def) _xf86_get_platform_device_int_attrib(device,attrib,_ODEV_ATTRIB_INT_CHECK(attrib,def)) 148 149#endif 150 151extern _X_EXPORT Bool 152xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid); 153 154extern _X_EXPORT int 155xf86PlatformMatchDriver(char *matches[], int nmatches); 156 157extern void xf86platformVTProbe(void); 158extern void xf86platformPrimary(void); 159#endif 160 161#endif 162