1/**************************************************************************
2 *
3 * Copyright 2012 Francisco Jerez
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28/**
29 * \file Library that provides device enumeration and creation of
30 * winsys/pipe_screen instances.
31 */
32
33#ifndef PIPE_LOADER_H
34#define PIPE_LOADER_H
35
36#include "pipe/p_compiler.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42struct pipe_screen;
43
44enum pipe_loader_device_type {
45   PIPE_LOADER_DEVICE_SOFTWARE,
46   PIPE_LOADER_DEVICE_PCI,
47   NUM_PIPE_LOADER_DEVICE_TYPES
48};
49
50/**
51 * A device known to the pipe loader.
52 */
53struct pipe_loader_device {
54   enum pipe_loader_device_type type;
55
56   union {
57      struct {
58         int vendor_id;
59         int chip_id;
60      } pci;
61   } u; /**< Discriminated by \a type */
62
63   const char *driver_name;
64   const struct pipe_loader_ops *ops;
65};
66
67/**
68 * Get a list of known devices.
69 *
70 * \param devs Array that will be filled with pointers to the devices
71 *             available in the system.
72 * \param ndev Maximum number of devices to return.
73 * \return Number of devices available in the system.
74 */
75int
76pipe_loader_probe(struct pipe_loader_device **devs, int ndev);
77
78/**
79 * Create a pipe_screen for the specified device.
80 *
81 * \param dev Device the screen will be created for.
82 * \param library_paths Colon-separated list of filesystem paths that
83 *                      will be used to look for the pipe driver
84 *                      module that handles this device.
85 */
86struct pipe_screen *
87pipe_loader_create_screen(struct pipe_loader_device *dev,
88                          const char *library_paths);
89
90/**
91 * Release resources allocated for a list of devices.
92 *
93 * Should be called when the specified devices are no longer in use to
94 * release any resources allocated by pipe_loader_probe.
95 *
96 * \param devs Devices to release.
97 * \param ndev Number of devices to release.
98 */
99void
100pipe_loader_release(struct pipe_loader_device **devs, int ndev);
101
102#ifdef HAVE_PIPE_LOADER_SW
103
104/**
105 * Get a list of known software devices.
106 *
107 * This function is platform-specific.
108 *
109 * \sa pipe_loader_probe
110 */
111int
112pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev);
113
114#endif
115
116#ifdef HAVE_PIPE_LOADER_DRM
117
118/**
119 * Get a list of known DRM devices.
120 *
121 * This function is platform-specific.
122 *
123 * \sa pipe_loader_probe
124 */
125int
126pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev);
127
128/**
129 * Initialize a DRM device in an already opened fd.
130 *
131 * This function is platform-specific.
132 *
133 * \sa pipe_loader_probe
134 */
135boolean
136pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd);
137
138#endif
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif /* PIPE_LOADER_H */
145