1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2012 Francisco Jerez
4848b8605Smrg * All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the
8848b8605Smrg * "Software"), to deal in the Software without restriction, including
9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
12848b8605Smrg * the following conditions:
13848b8605Smrg *
14848b8605Smrg * The above copyright notice and this permission notice (including the
15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
16848b8605Smrg * of the Software.
17848b8605Smrg *
18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25848b8605Smrg *
26848b8605Smrg **************************************************************************/
27848b8605Smrg
28848b8605Smrg/**
29848b8605Smrg * \file Library that provides device enumeration and creation of
30848b8605Smrg * winsys/pipe_screen instances.
31848b8605Smrg */
32848b8605Smrg
33848b8605Smrg#ifndef PIPE_LOADER_H
34848b8605Smrg#define PIPE_LOADER_H
35848b8605Smrg
36848b8605Smrg#include "pipe/p_compiler.h"
37848b8605Smrg#include "state_tracker/drm_driver.h"
38b8e80941Smrg#include "util/xmlconfig.h"
39848b8605Smrg
40848b8605Smrg#ifdef __cplusplus
41848b8605Smrgextern "C" {
42848b8605Smrg#endif
43848b8605Smrg
44848b8605Smrgstruct pipe_screen;
45848b8605Smrgstruct drisw_loader_funcs;
46848b8605Smrg
47848b8605Smrgenum pipe_loader_device_type {
48848b8605Smrg   PIPE_LOADER_DEVICE_SOFTWARE,
49848b8605Smrg   PIPE_LOADER_DEVICE_PCI,
50848b8605Smrg   PIPE_LOADER_DEVICE_PLATFORM,
51848b8605Smrg   NUM_PIPE_LOADER_DEVICE_TYPES
52848b8605Smrg};
53848b8605Smrg
54848b8605Smrg/**
55848b8605Smrg * A device known to the pipe loader.
56848b8605Smrg */
57848b8605Smrgstruct pipe_loader_device {
58848b8605Smrg   enum pipe_loader_device_type type;
59848b8605Smrg
60848b8605Smrg   union {
61848b8605Smrg      struct {
62848b8605Smrg         int vendor_id;
63848b8605Smrg         int chip_id;
64848b8605Smrg      } pci;
65848b8605Smrg   } u; /**< Discriminated by \a type */
66848b8605Smrg
67848b8605Smrg   char *driver_name;
68848b8605Smrg   const struct pipe_loader_ops *ops;
69b8e80941Smrg
70b8e80941Smrg   driOptionCache option_cache;
71b8e80941Smrg   driOptionCache option_info;
72848b8605Smrg};
73848b8605Smrg
74848b8605Smrg/**
75848b8605Smrg * Get a list of known devices.
76848b8605Smrg *
77848b8605Smrg * \param devs Array that will be filled with pointers to the devices
78848b8605Smrg *             available in the system.
79848b8605Smrg * \param ndev Maximum number of devices to return.
80848b8605Smrg * \return Number of devices available in the system.
81848b8605Smrg */
82848b8605Smrgint
83848b8605Smrgpipe_loader_probe(struct pipe_loader_device **devs, int ndev);
84848b8605Smrg
85848b8605Smrg/**
86848b8605Smrg * Create a pipe_screen for the specified device.
87848b8605Smrg *
88848b8605Smrg * \param dev Device the screen will be created for.
89848b8605Smrg */
90848b8605Smrgstruct pipe_screen *
91b8e80941Smrgpipe_loader_create_screen(struct pipe_loader_device *dev);
92b8e80941Smrg
93b8e80941Smrg/**
94b8e80941Smrg * Ensure that dev->option_cache is initialized appropriately for the driver.
95b8e80941Smrg *
96b8e80941Smrg * This function can be called multiple times.
97b8e80941Smrg *
98b8e80941Smrg * \param dev Device for which options should be loaded.
99b8e80941Smrg */
100b8e80941Smrgvoid
101b8e80941Smrgpipe_loader_load_options(struct pipe_loader_device *dev);
102848b8605Smrg
103848b8605Smrg/**
104b8e80941Smrg * Get the driinfo XML string used by the given driver.
105848b8605Smrg *
106b8e80941Smrg * The returned string is heap-allocated.
107848b8605Smrg */
108b8e80941Smrgchar *
109b8e80941Smrgpipe_loader_get_driinfo_xml(const char *driver_name);
110848b8605Smrg
111848b8605Smrg/**
112848b8605Smrg * Release resources allocated for a list of devices.
113848b8605Smrg *
114848b8605Smrg * Should be called when the specified devices are no longer in use to
115848b8605Smrg * release any resources allocated by pipe_loader_probe.
116848b8605Smrg *
117848b8605Smrg * \param devs Devices to release.
118848b8605Smrg * \param ndev Number of devices to release.
119848b8605Smrg */
120848b8605Smrgvoid
121848b8605Smrgpipe_loader_release(struct pipe_loader_device **devs, int ndev);
122848b8605Smrg
123848b8605Smrg/**
124b8e80941Smrg * Initialize sw dri device give the drisw_loader_funcs.
125848b8605Smrg *
126848b8605Smrg * This function is platform-specific.
127848b8605Smrg *
128b8e80941Smrg * Function does not take ownership of the fd, but duplicates it locally.
129b8e80941Smrg * The local fd is closed during pipe_loader_release.
130b8e80941Smrg *
131848b8605Smrg * \sa pipe_loader_probe
132848b8605Smrg */
133848b8605Smrgbool
134b8e80941Smrgpipe_loader_sw_probe_dri(struct pipe_loader_device **devs,
135b8e80941Smrg                         const struct drisw_loader_funcs *drisw_lf);
136848b8605Smrg
137848b8605Smrg/**
138b8e80941Smrg * Initialize a kms backed sw device given an fd.
139848b8605Smrg *
140848b8605Smrg * This function is platform-specific.
141848b8605Smrg *
142b8e80941Smrg * Function does not take ownership of the fd, but duplicates it locally.
143b8e80941Smrg * The local fd is closed during pipe_loader_release.
144b8e80941Smrg *
145848b8605Smrg * \sa pipe_loader_probe
146848b8605Smrg */
147848b8605Smrgbool
148b8e80941Smrgpipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd);
149848b8605Smrg
150848b8605Smrg/**
151848b8605Smrg * Initialize a null sw device.
152848b8605Smrg *
153848b8605Smrg * This function is platform-specific.
154848b8605Smrg *
155848b8605Smrg * \sa pipe_loader_probe
156848b8605Smrg */
157848b8605Smrgbool
158848b8605Smrgpipe_loader_sw_probe_null(struct pipe_loader_device **devs);
159848b8605Smrg
160848b8605Smrg/**
161848b8605Smrg * Get a list of known software devices.
162848b8605Smrg *
163848b8605Smrg * This function is platform-specific.
164848b8605Smrg *
165848b8605Smrg * \sa pipe_loader_probe
166848b8605Smrg */
167848b8605Smrgint
168848b8605Smrgpipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev);
169848b8605Smrg
170b8e80941Smrg/**
171b8e80941Smrg * Get a software device wrapped atop another device.
172b8e80941Smrg *
173b8e80941Smrg * This function is platform-specific.
174b8e80941Smrg *
175b8e80941Smrg * \sa pipe_loader_probe
176b8e80941Smrg */
177b8e80941Smrgboolean
178b8e80941Smrgpipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev,
179b8e80941Smrg                             struct pipe_screen *screen);
180848b8605Smrg
181848b8605Smrg/**
182848b8605Smrg * Get a list of known DRM devices.
183848b8605Smrg *
184848b8605Smrg * This function is platform-specific.
185848b8605Smrg *
186848b8605Smrg * \sa pipe_loader_probe
187848b8605Smrg */
188848b8605Smrgint
189848b8605Smrgpipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev);
190848b8605Smrg
191848b8605Smrg/**
192848b8605Smrg * Initialize a DRM device in an already opened fd.
193848b8605Smrg *
194848b8605Smrg * This function is platform-specific.
195848b8605Smrg *
196848b8605Smrg * \sa pipe_loader_probe
197848b8605Smrg */
198848b8605Smrgbool
199b8e80941Smrgpipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd);
200848b8605Smrg
201b8e80941Smrg/**
202b8e80941Smrg * Get the driinfo XML used for the DRM driver of the given name, if any.
203b8e80941Smrg *
204b8e80941Smrg * The returned string is heap-allocated.
205b8e80941Smrg */
206b8e80941Smrgchar *
207b8e80941Smrgpipe_loader_drm_get_driinfo_xml(const char *driver_name);
208b8e80941Smrg
209b8e80941Smrgextern const char gallium_driinfo_xml[];
210848b8605Smrg
211848b8605Smrg#ifdef __cplusplus
212848b8605Smrg}
213848b8605Smrg#endif
214848b8605Smrg
215848b8605Smrg#endif /* PIPE_LOADER_H */
216